Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178387756
D62491.1796644200.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None
D62491.1796644200.diff
View Options
diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c
--- a/sys/net/if_bridge.c
+++ b/sys/net/if_bridge.c
@@ -128,6 +128,7 @@
#if defined(INET) || defined(INET6)
#include <netinet/ip_carp.h>
#endif
+#include <machine/atomic.h>
#include <machine/in_cksum.h>
#include <netinet/if_ether.h>
#include <net/bridgestp.h>
@@ -260,6 +261,7 @@
ether_vlanid_t bif_pvid; /* port vlan id */
ifbvlan_set_t bif_vlan_set; /* if allowed tagged vlans */
uint16_t bif_vlanproto; /* vlan protocol */
+ bool bif_lro_blocked; /* owns member's LRO gate/ref */
};
/*
@@ -1233,6 +1235,12 @@
bif = __containerof(ctx, struct bridge_iflist, bif_epoch_ctx);
+ /* Span entries don't own an LRO or an interface ref. */
+ if (bif->bif_lro_blocked) {
+ atomic_store_rel_int(&bif->bif_ifp->if_lro_blocked, 0);
+ if_rele(bif->bif_ifp);
+ }
+
free(bif, M_DEVBUF);
}
@@ -1503,6 +1511,41 @@
if (sc->sc_flags & IFBRF_DEFQINQ)
bif->bif_flags |= IFBIF_QINQ;
+ /*
+ * Reserve the member and prohibit soft LRO before publishing bridge
+ * membership. Other bridges must not attach it during the grace
+ * period or while a prev membership is awaiting its deletion
+ * callback.
+ *
+ * LRO flush and the native Eth/Vlan input path run inside NET_EPOCH;
+ * NETESR_ETHER uses direct dispatch. Thus old-policy aggr and sync
+ * input finish before membership becomes visible. LRO may retain
+ * unmerged packets across epochs; tcp_lro_flush() rechecks the gate
+ * and delivers those packets individually. Don't flush a driver's
+ * lro_ctrl here: receive queues have their own serialization.
+ *
+ * BRIDGE_LOCK is an sx lock, and bridge input doesn't acquire it.
+ */
+
+ MPASS(!in_epoch(net_epoch_preempt));
+ if (!atomic_cmpset_int(&ifs->if_lro_blocked, 0, 1)) {
+ free(bif, M_DEVBUF);
+ return (EXTERROR(EBUSY,
+ "Interface bridge transaction in progress"));
+ }
+ if_ref(ifs);
+ bif->bif_lro_blocked = true;
+ /* Publish the bypass gate before starting the reader grace period. */
+ atomic_thread_fence_seq_cst();
+ NET_EPOCH_WAIT();
+ if ((ifs->if_flags & IFF_DYING) != 0 || ifs->if_vnet != curvnet) {
+ atomic_store_rel_int(&ifs->if_lro_blocked, 0);
+ if_rele(ifs);
+ free(bif, M_DEVBUF);
+ return (EXTERROR(ENXIO,
+ "Interface departed during bridge attachment"));
+ }
+
/*
* Assign the interface's MAC address to the bridge if it's the first
* member and the MAC address of the bridge has not been changed from
diff --git a/sys/net/if_private.h b/sys/net/if_private.h
--- a/sys/net/if_private.h
+++ b/sys/net/if_private.h
@@ -185,12 +185,14 @@
struct debugnet_methods *if_debugnet_methods;
struct epoch_context if_epoch_ctx;
+ /* Atomic bridge admission gate for soft LRO, incl transitions. */
+ u_int if_lro_blocked;
/*
* Spare fields to be added before branching a stable branch, so
* that structure can be enhanced without changing the kernel
* binary interface.
*/
- int if_ispare[4]; /* general use */
+ int if_ispare[3]; /* general use */
};
#define IF_LLADDR(ifp) \
diff --git a/sys/netinet/tcp_lro.c b/sys/netinet/tcp_lro.c
--- a/sys/netinet/tcp_lro.c
+++ b/sys/netinet/tcp_lro.c
@@ -57,6 +57,7 @@
#include <net/if_types.h>
#include <net/infiniband.h>
#include <net/if_lagg.h>
+#include <net/if_vlan_var.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
@@ -77,6 +78,7 @@
#include <netinet6/ip6_var.h>
#include <machine/in_cksum.h>
+#include <machine/atomic.h>
static MALLOC_DEFINE(M_LRO, "LRO", "LRO control structures");
@@ -84,6 +86,8 @@
static int tcp_lro_rx_common(struct lro_ctrl *lc, struct mbuf *m,
uint32_t csum, bool use_hash);
static void tcp_lro_flush(struct lro_ctrl *lc, struct lro_entry *le);
+static bool tcp_lro_rx_bridged(struct ifnet *ifp, const struct mbuf *m,
+ const struct lro_parser *outer);
SYSCTL_NODE(_net_inet_tcp, OID_AUTO, lro, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
"TCP LRO");
@@ -1120,13 +1124,69 @@
}
}
+/*
+ * LRO runs before lagg and Vlan input. A bridge can disable LRO on a Vlan
+ * member w/o disabling it on the physical receive interface. Don't aggr
+ * traffic for that member: a forwarded aggr can exceed the outgoing
+ * interface's MTU.
+ *
+ * Bridge attachment publishes if_lro_blocked before waiting for old-policy
+ * epoch readers and making membership visible. Check this gate, not just
+ * membership, so no new aggr starts during that wait. Entries that survive
+ * the wait are checked again before merging in tcp_lro_flush().
+ *
+ * Use the outer Vlan, including hardware-stripped tags. Vlan lookup and
+ * lagg port lifetime are protected by the caller's network epoch.
+ * Don't cache the result across receive batches or interface reconfiguration.
+ */
+static bool
+tcp_lro_rx_bridged(struct ifnet *ifp, const struct mbuf *m,
+ const struct lro_parser *outer)
+{
+ const struct ether_header *eh;
+ struct lagg_port *lp;
+ struct ifnet *vif;
+
+ NET_EPOCH_ASSERT();
+ for (;;) {
+ if (atomic_load_acq_int(&ifp->if_lro_blocked) != 0 ||
+ ifp->if_bridge != NULL)
+ return (true);
+ lp = ifp->if_lagg;
+ if (lp == NULL)
+ break;
+ if (lp->lp_detaching != 0)
+ return (true);
+ ifp = lp->lp_softc->sc_ifp;
+ }
+
+ /* VID zero alone cannot distinguish untagged from priority-tagged. */
+ eh = mtod(m, const struct ether_header *);
+ if ((m->m_flags & M_VLANTAG) == 0 &&
+ eh->ether_type != htons(ETHERTYPE_VLAN))
+ return (false);
+ vif = VLAN_DEVAT(ifp, ntohs(outer->data.vlan_id));
+ return (vif != NULL &&
+ (atomic_load_acq_int(&vif->if_lro_blocked) != 0 ||
+ vif->if_bridge != NULL));
+}
+
static void
tcp_lro_flush(struct lro_ctrl *lc, struct lro_entry *le)
{
+ struct mbuf *m, *next;
/* Only optimise if there are multiple packets waiting. */
NET_EPOCH_ASSERT();
- if (tcp_lro_flush_tcphpts == NULL ||
+ /* Recheck entries queued before their interface joined a bridge. */
+ if (tcp_lro_rx_bridged(lc->ifp, le->m_head, &le->outer)) {
+ for (m = le->m_head; m != NULL; m = next) {
+ next = m->m_nextpkt;
+ m->m_nextpkt = NULL;
+ lc->lro_queued++;
+ (*lc->ifp->if_input)(lc->ifp, m);
+ }
+ } else if (tcp_lro_flush_tcphpts == NULL ||
tcp_lro_flush_tcphpts(lc, le) != 0) {
tcp_lro_condense(lc, le);
tcp_flush_out_entry(lc, le);
@@ -1310,6 +1370,8 @@
pa = tcp_lro_parser(m, &po, &pi, true);
if (__predict_false(pa == NULL))
return (TCP_LRO_NOT_SUPPORTED);
+ if (__predict_false(tcp_lro_rx_bridged(lc->ifp, m, &po)))
+ return (TCP_LRO_CANNOT);
/* We don't expect any padding. */
error = tcp_lro_trim_mbuf_chain(m, pa);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 7, 11:50 AM (21 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42267524
Default Alt Text
D62491.1796644200.diff (6 KB)
Attached To
Mode
D62491: tcp_lro: bypass aggregation for bridged VLAN traffic
Attached
Detach File
Event Timeline