git: 1fb00c8f1060 - main - buf_alloc(): Stop using LK_NOWAIT, use LK_NOWITNESS

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Sun, 06 Mar 2022 15:43:47 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=1fb00c8f1060e18fed621f13d31db7b336d2267e

commit 1fb00c8f1060e18fed621f13d31db7b336d2267e
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-02-16 15:30:17 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-03-06 15:29:31 +0000

    buf_alloc(): Stop using LK_NOWAIT, use LK_NOWITNESS
    
    Despite the buffer taken from cache or free list, it still can be
    locked, due to 'lockless lookup' in getblkx() potentially operating on
    the freed buffers.  The lock is transient, but prevents the use of
    LK_NOWAIT there for the goal of neutralizing WITNESS.
    
    Just use LK_NOWITNESS.
    
    Reported and tested by: pho
    Sponsored by:   The FreeBSD Foundation
    MFC after:      3 days
---
 sys/kern/vfs_bio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c
index 5c42f00809b8..9082147b6034 100644
--- a/sys/kern/vfs_bio.c
+++ b/sys/kern/vfs_bio.c
@@ -1722,7 +1722,7 @@ buf_alloc(struct bufdomain *bd)
 	if (freebufs == bd->bd_lofreebuffers)
 		bufspace_daemon_wakeup(bd);
 
-	error = BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL);
+	error = BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWITNESS, NULL);
 	KASSERT(error == 0, ("%s: BUF_LOCK on free buf %p: %d.", __func__, bp,
 	    error));
 	(void)error;