From 5875b94c74935affb47c7e059011f80ee2f6bf67 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Tue, 18 Jan 2022 03:39:05 +0200 Subject: [PATCH] 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;