Skip to content

Commit

Permalink
Use store-release, load-consume operations. (#128)
Browse files Browse the repository at this point in the history
Co-authored-by: Taylor R Campbell <[email protected]>
  • Loading branch information
riastradh and Taylor R Campbell authored Jan 23, 2023
1 parent 52dbeac commit 2efbe28
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
11 changes: 5 additions & 6 deletions src/kern/npf_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ npf_config_load(npf_t *npf, npf_config_t *nc, npf_conndb_t *conns, bool flush)
/*
* 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);
Expand Down Expand Up @@ -225,31 +224,31 @@ npf_config_read_exit(npf_t *npf, int s)
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;
}

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;
}

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;
}

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;
}
9 changes: 4 additions & 5 deletions src/kern/npf_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ npf_conn_load(npf_t *npf, npf_conndb_t *ndb, bool track)
KASSERT(atomic_load_relaxed(&npf->conn_tracking)
== CONN_TRACKING_OFF);
odb = atomic_load_relaxed(&npf->conn_db);
membar_sync();
atomic_store_relaxed(&npf->conn_db, ndb);
atomic_store_release(&npf->conn_db, ndb);
}
if (track) {
/* After this point lookups start flying in. */
Expand Down Expand Up @@ -470,7 +469,7 @@ npf_conn_establish(npf_cache_t *npc, const unsigned di, bool global)
* the connection later.
*/
mutex_enter(&con->c_lock);
conn_db = atomic_load_relaxed(&npf->conn_db);
conn_db = atomic_load_consume(&npf->conn_db);
if (!npf_conndb_insert(conn_db, fw, con, NPF_FLOW_FORW)) {
error = EISCONN;
goto err;
Expand Down Expand Up @@ -575,7 +574,7 @@ npf_conn_setnat(const npf_cache_t *npc, npf_conn_t *con,
}

/* Remove the "backwards" key. */
conn_db = atomic_load_relaxed(&npf->conn_db);
conn_db = atomic_load_consume(&npf->conn_db);
bk = npf_conn_getbackkey(con, con->c_alen);
ret = npf_conndb_remove(conn_db, bk);
KASSERT(ret == con);
Expand Down Expand Up @@ -740,7 +739,7 @@ npf_conn_remove(npf_conndb_t *cd, npf_conn_t *con)
void
npf_conn_worker(npf_t *npf)
{
npf_conndb_t *conn_db = atomic_load_relaxed(&npf->conn_db);
npf_conndb_t *conn_db = atomic_load_consume(&npf->conn_db);
npf_conndb_gc(npf, conn_db, false, true);
}

Expand Down
4 changes: 3 additions & 1 deletion src/kern/npf_ifaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ lookup_ifnet_table(npf_t *npf, ifnet_t *ifp)
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);

/*
Expand Down
2 changes: 2 additions & 0 deletions src/kern/stand/npf_stand.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ npfkern_atomic_swap_ptr(volatile void *ptr, void *newval)

#define atomic_load_acquire(x) \
atomic_load_explicit((x), memory_order_acquire)
#define atomic_load_consume(x) \
atomic_load_explicit((x), memory_order_consume)
#define atomic_store_release(x, y) \
atomic_store_explicit((x), (y), memory_order_release)

Expand Down

0 comments on commit 2efbe28

Please sign in to comment.