Source-Changes-HG archive

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

[src/trunk]: src/sys/net/npf npf(4): Use atomic_store_release and atomic_load...



details:   https://anonhg.NetBSD.org/src/rev/d16ca8ac9df6
branches:  trunk
changeset: 361552:d16ca8ac9df6
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Feb 13 19:20:11 2022 +0000

description:
npf(4): Use atomic_store_release and atomic_load_consume for config.

...or atomic_load_relaxed, when the config is locked.  (Not necessary
to use atomic_* at all in NetBSD, but in C11 it will be cheaper to
say atomic_load_relaxed explicitly so an _Atomic-qualified object
doesn't cause the load to be surrounded by unnecessary membars.)

No need for store-before-load ordering here, so no need to
membar_sync.

diffstat:

 sys/net/npf/npf_conf.c   |  13 ++++++-------
 sys/net/npf/npf_ifaddr.c |   6 ++++--
 2 files changed, 10 insertions(+), 9 deletions(-)

diffs (83 lines):

diff -r 9a42be8fcd07 -r d16ca8ac9df6 sys/net/npf/npf_conf.c
--- a/sys/net/npf/npf_conf.c    Sun Feb 13 19:07:38 2022 +0000
+++ b/sys/net/npf/npf_conf.c    Sun Feb 13 19:20:11 2022 +0000
@@ -47,7 +47,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_conf.c,v 1.17 2020/05/30 14:16:56 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_conf.c,v 1.18 2022/02/13 19:20:11 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -153,8 +153,7 @@
        /*
         * Set the new config and release the lock.
         */
-       membar_sync();
-       atomic_store_relaxed(&npf->config, nc);
+       atomic_store_release(&npf->config, nc);
        if (onc == NULL) {
                /* Initial load, done. */
                npf_ifmap_flush(npf);
@@ -247,7 +246,7 @@
 npf_ruleset_t *
 npf_config_ruleset(npf_t *npf)
 {
-       npf_config_t *config = atomic_load_relaxed(&npf->config);
+       npf_config_t *config = atomic_load_consume(&npf->config);
        KASSERT(npf_config_locked_p(npf) || npf_ebr_incrit_p(npf->ebr));
        return config->ruleset;
 }
@@ -255,7 +254,7 @@
 npf_ruleset_t *
 npf_config_natset(npf_t *npf)
 {
-       npf_config_t *config = atomic_load_relaxed(&npf->config);
+       npf_config_t *config = atomic_load_consume(&npf->config);
        KASSERT(npf_config_locked_p(npf) || npf_ebr_incrit_p(npf->ebr));
        return config->nat_ruleset;
 }
@@ -263,7 +262,7 @@
 npf_tableset_t *
 npf_config_tableset(npf_t *npf)
 {
-       npf_config_t *config = atomic_load_relaxed(&npf->config);
+       npf_config_t *config = atomic_load_consume(&npf->config);
        KASSERT(npf_config_locked_p(npf) || npf_ebr_incrit_p(npf->ebr));
        return config->tableset;
 }
@@ -271,7 +270,7 @@
 bool
 npf_default_pass(npf_t *npf)
 {
-       npf_config_t *config = atomic_load_relaxed(&npf->config);
+       npf_config_t *config = atomic_load_consume(&npf->config);
        KASSERT(npf_config_locked_p(npf) || npf_ebr_incrit_p(npf->ebr));
        return config->default_pass;
 }
diff -r 9a42be8fcd07 -r d16ca8ac9df6 sys/net/npf/npf_ifaddr.c
--- a/sys/net/npf/npf_ifaddr.c  Sun Feb 13 19:07:38 2022 +0000
+++ b/sys/net/npf/npf_ifaddr.c  Sun Feb 13 19:20:11 2022 +0000
@@ -33,7 +33,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_ifaddr.c,v 1.7 2020/05/30 14:16:56 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_ifaddr.c,v 1.8 2022/02/13 19:20:11 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -87,9 +87,11 @@
 static void
 replace_ifnet_table(npf_t *npf, npf_table_t *newt)
 {
-       npf_tableset_t *ts = npf->config->tableset;
+       npf_tableset_t *ts = atomic_load_relaxed(&npf->config)->tableset;
        npf_table_t *oldt;
 
+       KASSERT(npf_config_locked_p(npf));
+
        KERNEL_UNLOCK_ONE(NULL);
 
        /*



Home | Main Index | Thread Index | Old Index