git: 5875b94c7493 - main - buf_alloc(): lock the buffer with LK_NOWAIT

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Mon, 31 Jan 2022 02:46:54 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=5875b94c74935affb47c7e059011f80ee2f6bf67

commit 5875b94c74935affb47c7e059011f80ee2f6bf67
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-01-18 01:39:05 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-01-31 02:46:21 +0000

    buf_alloc(): lock the buffer with LK_NOWAIT
    
    The buffer must not be accessed by any other thread, it is freshly
    allocated.  As such, LK_NOWAIT should be nop but also it prevents
    recording the order between the buffer lock and any other locks we might
    own in the call to getnewbuf().  In particular, if we own FFS snap lock,
    it should avoid triggering false positive warning.
    
    Reviewed by:    markj, mckusick
    Tested by:      pho
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D34072
---
 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 0cf02a95729c..cdb080688874 100644
--- a/sys/kern/vfs_bio.c
+++ b/sys/kern/vfs_bio.c
@@ -1718,7 +1718,7 @@ buf_alloc(struct bufdomain *bd)
 	if (freebufs == bd->bd_lofreebuffers)
 		bufspace_daemon_wakeup(bd);
 
-	error = BUF_LOCK(bp, LK_EXCLUSIVE, NULL);
+	error = BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL);
 	KASSERT(error == 0, ("%s: BUF_LOCK on free buf %p: %d.", __func__, bp,
 	    error));
 	(void)error;