From e651a5b2336c44b0ca52d119b0ebccc2737a05a6 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Tue, 22 Sep 2020 19:05:52 -0400 Subject: [PATCH] Fix a logic bug in the FreeBSD getpages VOP In commit cd32b4f5b79c ("Fix a deadlock in the FreeBSD getpages VOP") I introduced a bug while porting the patch originally committed to FreeBSD: the rangelock pointer may be NULL if the try operation failed, so we must avoid calling zfs_rangelock_unlock() in that case. Reviewed-by: Allan Jude Reviewed-by: Ryan Moeller Reviewed-by: Matt Macy Reported-by: Steve Wills Signed-off-by: Mark Johnston Closes #10519 Closes #10960 --- module/os/freebsd/zfs/zfs_vnops.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/module/os/freebsd/zfs/zfs_vnops.c b/module/os/freebsd/zfs/zfs_vnops.c index 2dde5b1f9..79202b60a 100644 --- a/module/os/freebsd/zfs/zfs_vnops.c +++ b/module/os/freebsd/zfs/zfs_vnops.c @@ -4859,7 +4859,8 @@ zfs_getpages(struct vnode *vp, vm_page_t *ma, int count, int *rbehind, obj_size = object->un_pager.vnp.vnp_size; zfs_vmobject_wunlock(object); if (IDX_TO_OFF(ma[count - 1]->pindex) >= obj_size) { - zfs_rangelock_exit(lr); + if (lr != NULL) + zfs_rangelock_exit(lr); ZFS_EXIT(zfsvfs); return (zfs_vm_pagerret_bad); } @@ -4887,7 +4888,8 @@ zfs_getpages(struct vnode *vp, vm_page_t *ma, int count, int *rbehind, error = dmu_read_pages(os, zp->z_id, ma, count, &pgsin_b, &pgsin_a, MIN(end, obj_size) - (end - PAGE_SIZE)); - zfs_rangelock_exit(lr); + if (lr != NULL) + zfs_rangelock_exit(lr); ZFS_ACCESSTIME_STAMP(zfsvfs, zp); ZFS_EXIT(zfsvfs);