[RFC PATCH 13/18] KVM: Add atomic parameter to __gfn_to_hva_many

From: James Houghton
Date: Wed Jul 10 2024 - 19:46:31 EST


Atomic translations cannot wait for userspace to resolve a userfault.
Add an atomic parameter for later use with KVM Userfault.

Signed-off-by: James Houghton <jthoughton@xxxxxxxxxx>
---
virt/kvm/kvm_main.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 77eb9f0de02d..4ac018cac704 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2679,7 +2679,7 @@ static bool memslot_is_readonly(const struct kvm_memory_slot *slot)
}

static unsigned long __gfn_to_hva_many(const struct kvm_memory_slot *slot, gfn_t gfn,
- gfn_t *nr_pages, bool write)
+ gfn_t *nr_pages, bool write, bool atomic)
{
if (!slot || slot->flags & KVM_MEMSLOT_INVALID)
return KVM_HVA_ERR_BAD;
@@ -2699,7 +2699,7 @@ static unsigned long __gfn_to_hva_many(const struct kvm_memory_slot *slot, gfn_t
static unsigned long gfn_to_hva_many(struct kvm_memory_slot *slot, gfn_t gfn,
gfn_t *nr_pages)
{
- return __gfn_to_hva_many(slot, gfn, nr_pages, true);
+ return __gfn_to_hva_many(slot, gfn, nr_pages, true, false);
}

unsigned long gfn_to_hva_memslot(struct kvm_memory_slot *slot,
@@ -2732,7 +2732,7 @@ EXPORT_SYMBOL_GPL(kvm_vcpu_gfn_to_hva);
unsigned long gfn_to_hva_memslot_prot(struct kvm_memory_slot *slot,
gfn_t gfn, bool *writable)
{
- unsigned long hva = __gfn_to_hva_many(slot, gfn, NULL, false);
+ unsigned long hva = __gfn_to_hva_many(slot, gfn, NULL, false, false);

if (!kvm_is_error_hva(hva) && writable)
*writable = !memslot_is_readonly(slot);
@@ -3002,7 +3002,8 @@ kvm_pfn_t __gfn_to_pfn_memslot(const struct kvm_memory_slot *slot, gfn_t gfn,
bool atomic, bool interruptible, bool *async,
bool write_fault, bool *writable, hva_t *hva)
{
- unsigned long addr = __gfn_to_hva_many(slot, gfn, NULL, write_fault);
+ unsigned long addr = __gfn_to_hva_many(slot, gfn, NULL, write_fault,
+ atomic);

if (hva)
*hva = addr;
@@ -3074,7 +3075,7 @@ int gfn_to_page_many_atomic(struct kvm_memory_slot *slot, gfn_t gfn,
unsigned long addr;
gfn_t entry = 0;

- addr = gfn_to_hva_many(slot, gfn, &entry);
+ addr = __gfn_to_hva_many(slot, gfn, &entry, true, true);
if (kvm_is_error_hva(addr))
return -1;

--
2.45.2.993.g49e7a77208-goog