summaryrefslogtreecommitdiffstats
path: root/sys/net/netisr.c
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2008-07-04 00:21:38 +0000
committerrwatson <rwatson@FreeBSD.org>2008-07-04 00:21:38 +0000
commit482bfeab4715003445dbf838bbdcce673740ff7d (patch)
tree6451e086126a6c85a8ad3c6c83f9ee58188778e2 /sys/net/netisr.c
parent240825654b391ec4881cb7faaeaae4ec983bb980 (diff)
downloadFreeBSD-src-482bfeab4715003445dbf838bbdcce673740ff7d.zip
FreeBSD-src-482bfeab4715003445dbf838bbdcce673740ff7d.tar.gz
Remove NETISR_MPSAFE, which allows specific netisr handlers to be directly
dispatched without Giant, and add NETISR_FORCEQUEUE, which allows specific netisr handlers to always be dispatched via a queue (deferred). Mark the usb and if_ppp netisr handlers as NETISR_FORCEQUEUE, and explicitly acquire Giant in those handlers. Previously, any netisr handler not marked NETISR_MPSAFE would necessarily run deferred and with Giant acquired. This change removes Giant scaffolding from the netisr infrastructure, but NETISR_FORCEQUEUE allows non-MPSAFE handlers to continue to force deferred dispatch so as to avoid lock order reversals between their acqusition of Giant and any calling context. It is likely we will be able to remove NETISR_FORCEQUEUE once IFF_NEEDSGIANT is removed, as non-MPSAFE usb and if_ppp drivers will no longer be supported. Reviewed by: bz MFC after: 1 month X-MFC note: We can't remove NETISR_MPSAFE from stable/7 for KPI reasons, but the rest can go back.
Diffstat (limited to 'sys/net/netisr.c')
-rw-r--r--sys/net/netisr.c46
1 files changed, 15 insertions, 31 deletions
diff --git a/sys/net/netisr.c b/sys/net/netisr.c
index 9307b53..ed5466c 100644
--- a/sys/net/netisr.c
+++ b/sys/net/netisr.c
@@ -77,6 +77,8 @@ netisr_register(int num, netisr_t *handler, struct ifqueue *inq, int flags)
KASSERT(!(num < 0 || num >= (sizeof(netisrs)/sizeof(*netisrs))),
("bad isr %d", num));
+ KASSERT(flags == 0 || flags == NETISR_FORCEQUEUE,
+ ("netisr_register: bad flags 0x%x\n", flags));
netisrs[num].ni_handler = handler;
netisrs[num].ni_queue = inq;
netisrs[num].ni_flags = flags;
@@ -161,27 +163,18 @@ netisr_dispatch(int num, struct mbuf *m)
m_freem(m);
return;
}
+
/*
- * Do direct dispatch only for MPSAFE netisrs (and
- * only when enabled). Note that when a netisr is
- * marked MPSAFE we permit multiple concurrent instances
- * to run. We guarantee only the order in which
- * packets are processed for each "dispatch point" in
- * the system (i.e. call to netisr_dispatch or
- * netisr_queue). This insures ordering of packets
- * from an interface but does not guarantee ordering
- * between multiple places in the system (e.g. IP
- * dispatched from interfaces vs. IP queued from IPSec).
+ * Unless NETISR_FORCEQUEUE is set on the netisr (generally
+ * indicating that the handler still requires Giant, which cannot be
+ * acquired in arbitrary order with respect to a caller), directly
+ * dispatch handling of this packet. Source ordering is maintained
+ * by virtue of callers consistently calling one of queued or direct
+ * dispatch, and the forcequeue flag being immutable after
+ * registration.
*/
- if (netisr_direct && (ni->ni_flags & NETISR_MPSAFE)) {
+ if (netisr_direct && !(ni->ni_flags & NETISR_FORCEQUEUE)) {
isrstat.isrs_directed++;
- /*
- * NB: We used to drain the queue before handling
- * the packet but now do not. Doing so here will
- * not preserve ordering so instead we fallback to
- * guaranteeing order only from dispatch points
- * in the system (see above).
- */
ni->ni_handler(m);
} else {
isrstat.isrs_deferred++;
@@ -242,19 +235,10 @@ swi_net(void *dummy)
printf("swi_net: unregistered isr %d.\n", i);
continue;
}
- if ((ni->ni_flags & NETISR_MPSAFE) == 0) {
- mtx_lock(&Giant);
- if (ni->ni_queue == NULL)
- ni->ni_handler(NULL);
- else
- netisr_processqueue(ni);
- mtx_unlock(&Giant);
- } else {
- if (ni->ni_queue == NULL)
- ni->ni_handler(NULL);
- else
- netisr_processqueue(ni);
- }
+ if (ni->ni_queue == NULL)
+ ni->ni_handler(NULL);
+ else
+ netisr_processqueue(ni);
}
} while (polling);
}
OpenPOWER on IntegriCloud