From d129e0eba0b50c24382b79578e9df8c6834c01ab Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Thu, 2 Jul 2020 12:54:50 +0000 Subject: [PATCH] cache: fix misplaced fence in cache_ncp_invalidate The intent was to mark the entry as invalid before cache_zap starts messing with it. While here add some comments. --- sys/kern/vfs_cache.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index 79b2a370438a..555f833f7783 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -147,6 +147,27 @@ struct namecache_ts { #define NCF_HOTNEGATIVE 0x40 #define NCF_INVALID 0x80 +/* + * Mark an entry as invalid. + * + * This is called before it starts getting deconstructed. + */ +static void +cache_ncp_invalidate(struct namecache *ncp) +{ + + KASSERT((ncp->nc_flag & NCF_INVALID) == 0, + ("%s: entry %p already invalid", __func__, ncp)); + ncp->nc_flag |= NCF_INVALID; + atomic_thread_fence_rel(); +} + +/* + * Verify validity of an entry. + * + * All places which elide locks are supposed to call this after they are + * done with reading from an entry. + */ static bool cache_ncp_invalid(struct namecache *ncp) { @@ -155,16 +176,6 @@ cache_ncp_invalid(struct namecache *ncp) return ((ncp->nc_flag & NCF_INVALID) != 0); } -static void -cache_ncp_invalidate(struct namecache *ncp) -{ - - atomic_thread_fence_rel(); - KASSERT((ncp->nc_flag & NCF_INVALID) == 0, - ("%s: entry %p already invalid", __func__, ncp)); - ncp->nc_flag |= NCF_INVALID; -} - /* * Name caching works as follows: *