Module Name:    src
Committed By:   riastradh
Date:           Wed Feb 22 21:44:21 UTC 2023

Modified Files:
        src/sys/kern: vfs_vnode.c

Log Message:
_vstate_assert: Use atomic_load/store_relaxed.  Omit membar_enter.

Can't find anything this is supposed to pair with.  Pretty sure this
is just an optimistic unlocked test, not actually reliant on memory
ordering.  But as it is unlocked, it needs to be coordinated with
atomic_load/store_relaxed, not ordinary loads or stores, if for no
other reason than to pacify sanitizers.

No need in vnalloc_marker or vcache_alloc because these still have
exclusive access to the vnode at that point.

XXX Should deduplicate the logic in vstate_assert_change and
vstate_change.


To generate a diff of this commit:
cvs rdiff -u -r1.147 -r1.148 src/sys/kern/vfs_vnode.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_vnode.c
diff -u src/sys/kern/vfs_vnode.c:1.147 src/sys/kern/vfs_vnode.c:1.148
--- src/sys/kern/vfs_vnode.c:1.147	Wed Oct 26 23:40:08 2022
+++ src/sys/kern/vfs_vnode.c	Wed Feb 22 21:44:21 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnode.c,v 1.147 2022/10/26 23:40:08 riastradh Exp $	*/
+/*	$NetBSD: vfs_vnode.c,v 1.148 2023/02/22 21:44:21 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011, 2019, 2020 The NetBSD Foundation, Inc.
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.147 2022/10/26 23:40:08 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.148 2023/02/22 21:44:21 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pax.h"
@@ -269,17 +269,12 @@ _vstate_assert(vnode_t *vp, enum vnode_s
 	int refcnt = vrefcnt(vp);
 
 	if (!has_lock) {
-		/*
-		 * Prevent predictive loads from the CPU, but check the state
-		 * without loooking first.
-		 *
-		 * XXX what does this pair with?
-		 */
-		membar_enter();
+		enum vnode_state vstate = atomic_load_relaxed(&vip->vi_state);
+
 		if (state == VS_ACTIVE && refcnt > 0 &&
-		    (vip->vi_state == VS_LOADED || vip->vi_state == VS_BLOCKED))
+		    (vstate == VS_LOADED || vstate == VS_BLOCKED))
 			return;
-		if (vip->vi_state == state)
+		if (vstate == state)
 			return;
 		mutex_enter((vp)->v_interlock);
 	}
@@ -363,7 +358,7 @@ vstate_assert_change(vnode_t *vp, enum v
 		atomic_and_uint(&vp->v_usecount, ~VUSECOUNT_GATE);
 	}
 
-	vip->vi_state = to;
+	atomic_store_relaxed(&vip->vi_state, to);
 	if (from == VS_LOADING)
 		cv_broadcast(&vcache_cv);
 	if (to == VS_LOADED || to == VS_RECLAIMED)
@@ -409,7 +404,7 @@ vstate_change(vnode_t *vp, enum vnode_st
 		atomic_and_uint(&vp->v_usecount, ~VUSECOUNT_GATE);
 	}
 
-	vip->vi_state = to;
+	atomic_store_relaxed(&vip->vi_state, to);
 	if (from == VS_LOADING)
 		cv_broadcast(&vcache_cv);
 	if (to == VS_LOADED || to == VS_RECLAIMED)

Reply via email to