Process all address spaces when deleting a KVM-internal memslot, i.e. try
to delete the SMM memslot (if SMM is enabled) even if there is no non-SMM
memslot. This will allow retrying deletion when inhibiting the APIC access
page (the only scenario where KVM deletes memslots while the VM is alive).
Fixes: 9da0e4d5ac96 ("KVM: x86: work on all available address spaces")
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/x86.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 326f8a9a5d18..0b94f981a2e1 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10011,6 +10011,9 @@ static int x86_set_internal_memslot(struct kvm *kvm, int id, int as_id,
{
struct kvm_userspace_memory_region2 m;
+ if (!size && !id_to_memslot(__kvm_memslots(kvm, as_id), id))
+ return 0;
+
m.slot = id | (as_id << 16);
m.flags = 0;
m.guest_phys_addr = gpa;@@ -10044,8 +10047,6 @@ static int x86_set_internal_memslot(struct kvm *kvm, int id, int as_id,
void __user * __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa,
u32 size)
{
- struct kvm_memslots *slots = kvm_memslots(kvm);
- struct kvm_memory_slot *slot;
unsigned long hva;
int i, r;
@@ -10054,11 +10055,10 @@ void __user * __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa,
if (WARN_ON(id >= KVM_MEM_SLOTS_NUM))
return ERR_PTR_USR(-EINVAL);
- slot = id_to_memslot(slots, id);
+ if (size && id_to_memslot(kvm_memslots(kvm), id))
+ return ERR_PTR_USR(-EEXIST);
+
if (size) {
- if (slot)
- return ERR_PTR_USR(-EEXIST);
-
/*
* MAP_SHARED to prevent internal slot pages from being moved
* by fork()/COW.@@ -10068,9 +10068,6 @@ void __user * __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa,
if (IS_ERR_VALUE(hva))
return (void __user *)hva;
} else {
- if (!slot)
- return NULL;
-
hva = 0;
}
--
2.56.0.385.gac671c819a-goog