mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 13:11:40 +00:00
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 <michael.roth@amd.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
564429a6bd
commit
78c4293372
@ -59,6 +59,7 @@ static int kvm_gmem_prepare_folio(struct inode *inode, pgoff_t index, struct fol
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Returns a locked folio on success. */
|
||||
static struct folio *kvm_gmem_get_folio(struct inode *inode, pgoff_t index, bool prepare)
|
||||
{
|
||||
struct folio *folio;
|
||||
@ -551,6 +552,7 @@ void kvm_gmem_unbind(struct kvm_memory_slot *slot)
|
||||
fput(file);
|
||||
}
|
||||
|
||||
/* Returns a locked folio on success. */
|
||||
static struct folio *
|
||||
__kvm_gmem_get_pfn(struct file *file, struct kvm_memory_slot *slot,
|
||||
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,
|
||||
if (max_order)
|
||||
*max_order = 0;
|
||||
|
||||
folio_unlock(folio);
|
||||
return folio;
|
||||
}
|
||||
|
||||
@ -602,6 +603,7 @@ int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot,
|
||||
if (IS_ERR(folio))
|
||||
return PTR_ERR(folio);
|
||||
|
||||
folio_unlock(folio);
|
||||
return 0;
|
||||
}
|
||||
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
|
||||
break;
|
||||
}
|
||||
|
||||
folio_unlock(folio);
|
||||
if (!IS_ALIGNED(gfn, (1 << max_order)) ||
|
||||
(npages - i) < (1 << max_order))
|
||||
max_order = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user