Skip to content

Commit 78c4293

Browse files
committed
KVM: guest_memfd: return locked folio from __kvm_gmem_get_pfn
Allow testing the up-to-date flag in the caller without taking the lock again. Reviewed-by: Michael Roth <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 564429a commit 78c4293

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

virt/kvm/guest_memfd.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static int kvm_gmem_prepare_folio(struct inode *inode, pgoff_t index, struct fol
5959
return 0;
6060
}
6161

62+
/* Returns a locked folio on success. */
6263
static struct folio *kvm_gmem_get_folio(struct inode *inode, pgoff_t index, bool prepare)
6364
{
6465
struct folio *folio;
@@ -551,6 +552,7 @@ void kvm_gmem_unbind(struct kvm_memory_slot *slot)
551552
fput(file);
552553
}
553554

555+
/* Returns a locked folio on success. */
554556
static struct folio *
555557
__kvm_gmem_get_pfn(struct file *file, struct kvm_memory_slot *slot,
556558
gfn_t gfn, kvm_pfn_t *pfn, int *max_order, bool prepare)
@@ -584,7 +586,6 @@ __kvm_gmem_get_pfn(struct file *file, struct kvm_memory_slot *slot,
584586
if (max_order)
585587
*max_order = 0;
586588

587-
folio_unlock(folio);
588589
return folio;
589590
}
590591

@@ -602,6 +603,7 @@ int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot,
602603
if (IS_ERR(folio))
603604
return PTR_ERR(folio);
604605

606+
folio_unlock(folio);
605607
return 0;
606608
}
607609
EXPORT_SYMBOL_GPL(kvm_gmem_get_pfn);
@@ -647,6 +649,7 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src, long
647649
break;
648650
}
649651

652+
folio_unlock(folio);
650653
if (!IS_ALIGNED(gfn, (1 << max_order)) ||
651654
(npages - i) < (1 << max_order))
652655
max_order = 0;

0 commit comments

Comments
 (0)