summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshurd <shurd@FreeBSD.org>2018-04-18 18:45:04 +0000
committershurd <shurd@FreeBSD.org>2018-04-18 18:45:04 +0000
commitc4642292bc00ef62b477d6f9395cfcc717abb691 (patch)
tree785b07f1a5cabd866a5e77960ad3fda13165a96c
parentbcf7cda8c01ea1703330102003ddff5f9fa2fa44 (diff)
downloadFreeBSD-src-c4642292bc00ef62b477d6f9395cfcc717abb691.zip
FreeBSD-src-c4642292bc00ef62b477d6f9395cfcc717abb691.tar.gz
MFC r332388:
Make BPF global lock an SX This allows NIC drivers to sleep on polling config operations. PR: 323477 Submitted by: Matthew Macy <mmacy@mattmacy.io> Reviewed by: shurd Sponsored by: Limelight Networks Differential Revision: https://reviews.freebsd.org/D14982
-rw-r--r--sys/kern/subr_witness.c2
-rw-r--r--sys/net/bpf.c7
-rw-r--r--sys/net/bpfdesc.h3
3 files changed, 6 insertions, 6 deletions
diff --git a/sys/kern/subr_witness.c b/sys/kern/subr_witness.c
index be3ca31..d054fec 100644
--- a/sys/kern/subr_witness.c
+++ b/sys/kern/subr_witness.c
@@ -567,7 +567,7 @@ static struct witness_order_list_entry order_lists[] = {
/*
* BPF
*/
- { "bpf global lock", &lock_class_mtx_sleep },
+ { "bpf global lock", &lock_class_sx },
{ "bpf interface lock", &lock_class_rw },
{ "bpf cdev lock", &lock_class_mtx_sleep },
{ NULL, NULL },
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index 8675e00..f455213 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -157,6 +157,9 @@ struct bpf_dltlist32 {
#define BIOCSETFNR32 _IOW('B', 130, struct bpf_program32)
#endif
+#define BPF_LOCK() sx_xlock(&bpf_sx)
+#define BPF_UNLOCK() sx_xunlock(&bpf_sx)
+#define BPF_LOCK_ASSERT() sx_assert(&bpf_sx, SA_XLOCKED)
/*
* bpf_iflist is a list of BPF interface structures, each corresponding to a
* specific DLT. The same network interface might have several BPF interface
@@ -164,7 +167,7 @@ struct bpf_dltlist32 {
* frames, ethernet frames, etc).
*/
static LIST_HEAD(, bpf_if) bpf_iflist, bpf_freelist;
-static struct mtx bpf_mtx; /* bpf global lock */
+static struct sx bpf_sx; /* bpf global lock */
static int bpf_bpfd_cnt;
static void bpf_attachd(struct bpf_d *, struct bpf_if *);
@@ -2800,7 +2803,7 @@ bpf_drvinit(void *unused)
{
struct cdev *dev;
- mtx_init(&bpf_mtx, "bpf global lock", NULL, MTX_DEF);
+ sx_init(&bpf_sx, "bpf global lock");
LIST_INIT(&bpf_iflist);
LIST_INIT(&bpf_freelist);
diff --git a/sys/net/bpfdesc.h b/sys/net/bpfdesc.h
index 496f0b3..3fa8dfb 100644
--- a/sys/net/bpfdesc.h
+++ b/sys/net/bpfdesc.h
@@ -115,9 +115,6 @@ struct bpf_d {
#define BPF_PID_REFRESH(bd, td) (bd)->bd_pid = (td)->td_proc->p_pid
#define BPF_PID_REFRESH_CUR(bd) (bd)->bd_pid = curthread->td_proc->p_pid
-#define BPF_LOCK() mtx_lock(&bpf_mtx)
-#define BPF_UNLOCK() mtx_unlock(&bpf_mtx)
-#define BPF_LOCK_ASSERT() mtx_assert(&bpf_mtx, MA_OWNED)
/*
* External representation of the bpf descriptor
*/
OpenPOWER on IntegriCloud