Commit 78c42933 authored by Paolo Bonzini's avatar Paolo Bonzini

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: default avatarMichael Roth <michael.roth@amd.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 564429a6
...@@ -59,6 +59,7 @@ static int kvm_gmem_prepare_folio(struct inode *inode, pgoff_t index, struct fol ...@@ -59,6 +59,7 @@ static int kvm_gmem_prepare_folio(struct inode *inode, pgoff_t index, struct fol
return 0; return 0;
} }
/* Returns a locked folio on success. */
static struct folio *kvm_gmem_get_folio(struct inode *inode, pgoff_t index, bool prepare) static struct folio *kvm_gmem_get_folio(struct inode *inode, pgoff_t index, bool prepare)
{ {
struct folio *folio; struct folio *folio;
...@@ -551,6 +552,7 @@ void kvm_gmem_unbind(struct kvm_memory_slot *slot) ...@@ -551,6 +552,7 @@ void kvm_gmem_unbind(struct kvm_memory_slot *slot)
fput(file); fput(file);
} }
/* Returns a locked folio on success. */
static struct folio * static struct folio *
__kvm_gmem_get_pfn(struct file *file, struct kvm_memory_slot *slot, __kvm_gmem_get_pfn(struct file *file, struct kvm_memory_slot *slot,
gfn_t gfn, kvm_pfn_t *pfn, int *max_order, bool prepare) 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, ...@@ -584,7 +586,6 @@ __kvm_gmem_get_pfn(struct file *file, struct kvm_memory_slot *slot,
if (max_order) if (max_order)
*max_order = 0; *max_order = 0;
folio_unlock(folio);
return folio; return folio;
} }
...@@ -602,6 +603,7 @@ int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, ...@@ -602,6 +603,7 @@ int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot,
if (IS_ERR(folio)) if (IS_ERR(folio))
return PTR_ERR(folio); return PTR_ERR(folio);
folio_unlock(folio);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(kvm_gmem_get_pfn); 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 ...@@ -647,6 +649,7 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src, long
break; break;
} }
folio_unlock(folio);
if (!IS_ALIGNED(gfn, (1 << max_order)) || if (!IS_ALIGNED(gfn, (1 << max_order)) ||
(npages - i) < (1 << max_order)) (npages - i) < (1 << max_order))
max_order = 0; max_order = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment