git: 3a98b98be504 - stable/13 - swap_pager: lock vnode in swapdev_strategy()

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Thu, 02 Dec 2021 02:31:53 UTC
The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=3a98b98be504e5ba3faf0fdf58271681d9eee5a1

commit 3a98b98be504e5ba3faf0fdf58271681d9eee5a1
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-11-24 11:26:46 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-12-02 02:21:15 +0000

    swap_pager: lock vnode in swapdev_strategy()
    
    (cherry picked from commit b19740f4ce7a542783f87de2fee48476a7801d86)
---
 sys/vm/swap_pager.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c
index 8363dce52683..78533c9fb5e6 100644
--- a/sys/vm/swap_pager.c
+++ b/sys/vm/swap_pager.c
@@ -3036,16 +3036,19 @@ swapdev_strategy(struct buf *bp, struct swdevt *sp)
 	vp2 = sp->sw_id;
 	vhold(vp2);
 	if (bp->b_iocmd == BIO_WRITE) {
+		vn_lock(vp2, LK_EXCLUSIVE | LK_RETRY);
 		if (bp->b_bufobj)
 			bufobj_wdrop(bp->b_bufobj);
 		bufobj_wref(&vp2->v_bufobj);
+	} else {
+		vn_lock(vp2, LK_SHARED | LK_RETRY);
 	}
 	if (bp->b_bufobj != &vp2->v_bufobj)
 		bp->b_bufobj = &vp2->v_bufobj;
 	bp->b_vp = vp2;
 	bp->b_iooffset = dbtob(bp->b_blkno);
 	bstrategy(bp);
-	return;
+	VOP_UNLOCK(vp2);
 }
 
 static void