Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Fix wrong memory order and switch bpf to atomic_load...



details:   https://anonhg.NetBSD.org/src/rev/4a20942c8e1f
branches:  trunk
changeset: 1006940:4a20942c8e1f
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat Feb 01 02:54:02 2020 +0000

description:
Fix wrong memory order and switch bpf to atomic_load/store_*.

diffstat:

 sys/net/bpf.c    |  27 ++++++++++-----------------
 sys/net/bpfjit.c |  11 +++++------
 2 files changed, 15 insertions(+), 23 deletions(-)

diffs (110 lines):

diff -r 05106637897c -r 4a20942c8e1f sys/net/bpf.c
--- a/sys/net/bpf.c     Sat Feb 01 02:33:08 2020 +0000
+++ b/sys/net/bpf.c     Sat Feb 01 02:54:02 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bpf.c,v 1.233 2020/01/19 05:07:22 thorpej Exp $        */
+/*     $NetBSD: bpf.c,v 1.234 2020/02/01 02:54:02 riastradh Exp $      */
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.233 2020/01/19 05:07:22 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.234 2020/02/01 02:54:02 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_bpf.h"
@@ -301,10 +301,13 @@
 bpfjit_func_t
 bpf_jit_generate(bpf_ctx_t *bc, void *code, size_t size)
 {
+       struct bpfjit_ops *ops = &bpfjit_module_ops;
+       bpfjit_func_t (*generate_code)(const bpf_ctx_t *,
+           const struct bpf_insn *, size_t);
 
-       membar_consumer();
-       if (bpfjit_module_ops.bj_generate_code != NULL) {
-               return bpfjit_module_ops.bj_generate_code(bc, code, size);
+       generate_code = atomic_load_acquire(&ops->bj_generate_code);
+       if (generate_code != NULL) {
+               return generate_code(bc, code, size);
        }
        return NULL;
 }
@@ -1289,7 +1292,6 @@
                        kmem_free(fcode, size);
                        return EINVAL;
                }
-               membar_consumer();
                if (bpf_jit)
                        jcode = bpf_jit_generate(NULL, fcode, flen);
        } else {
@@ -1306,8 +1308,7 @@
        mutex_enter(&bpf_mtx);
        mutex_enter(d->bd_mtx);
        oldf = d->bd_filter;
-       d->bd_filter = newf;
-       membar_producer();
+       atomic_store_release(&d->bd_filter, newf);
        reset_d(d);
        pserialize_perform(bpf_psz);
        mutex_exit(d->bd_mtx);
@@ -1607,8 +1608,7 @@
                atomic_inc_ulong(&d->bd_rcount);
                BPF_STATINC(recv);
 
-               filter = d->bd_filter;
-               membar_datadep_consumer();
+               filter = atomic_load_consume(&d->bd_filter);
                if (filter != NULL) {
                        if (filter->bf_jitcode != NULL)
                                slen = filter->bf_jitcode(NULL, &args);
@@ -2308,13 +2308,6 @@
                return error;
 
        bpf_jit = newval;
-
-       /*
-        * Do a full sync to publish new bpf_jit value and
-        * update bpfjit_module_ops.bj_generate_code variable.
-        */
-       membar_sync();
-
        if (newval && bpfjit_module_ops.bj_generate_code == NULL) {
                printf("JIT compilation is postponed "
                    "until after bpfjit module is loaded\n");
diff -r 05106637897c -r 4a20942c8e1f sys/net/bpfjit.c
--- a/sys/net/bpfjit.c  Sat Feb 01 02:33:08 2020 +0000
+++ b/sys/net/bpfjit.c  Sat Feb 01 02:54:02 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bpfjit.c,v 1.47 2019/01/20 23:36:57 alnsn Exp $        */
+/*     $NetBSD: bpfjit.c,v 1.48 2020/02/01 02:54:02 riastradh Exp $    */
 
 /*-
  * Copyright (c) 2011-2015 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include <sys/cdefs.h>
 #ifdef _KERNEL
-__KERNEL_RCSID(0, "$NetBSD: bpfjit.c,v 1.47 2019/01/20 23:36:57 alnsn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpfjit.c,v 1.48 2020/02/01 02:54:02 riastradh Exp $");
 #else
-__RCSID("$NetBSD: bpfjit.c,v 1.47 2019/01/20 23:36:57 alnsn Exp $");
+__RCSID("$NetBSD: bpfjit.c,v 1.48 2020/02/01 02:54:02 riastradh Exp $");
 #endif
 
 #include <sys/types.h>
@@ -231,9 +231,8 @@
        switch (cmd) {
        case MODULE_CMD_INIT:
                bpfjit_module_ops.bj_free_code = &bpfjit_free_code;
-               membar_producer();
-               bpfjit_module_ops.bj_generate_code = &bpfjit_generate_code;
-               membar_producer();
+               atomic_store_release(&bpfjit_module_ops.bj_generate_code,
+                   &bpfjit_generate_code);
                return 0;
 
        case MODULE_CMD_FINI:



Home | Main Index | Thread Index | Old Index