Commit cf5b4869 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: s390: Use "new" memslot instead of userspace memory region

Get the gfn, size, and hva from the new memslot instead of the userspace
memory region when preparing/committing memory region changes.  This will
allow a future commit to drop the @mem param.

Note, this has a subtle functional change as KVM would previously reject
DELETE if userspace provided a garbage userspace_addr or guest_phys_addr,
whereas KVM zeros those fields in the "new" memslot when deleting an
existing memslot.  Arguably the old behavior is more correct, but there's
zero benefit into requiring userspace to provide sane values for hva and
gfn.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarMaciej S. Szmigiero <maciej.szmigiero@oracle.com>
Message-Id: <917ed131c06a4c7b35dd7fb7ed7955be899ad8cc.1638817639.git.maciej.szmigiero@oracle.com>
parent eaaaed13
...@@ -5012,18 +5012,20 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, ...@@ -5012,18 +5012,20 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
struct kvm_memory_slot *new, struct kvm_memory_slot *new,
enum kvm_mr_change change) enum kvm_mr_change change)
{ {
gpa_t size = new->npages * PAGE_SIZE;
/* A few sanity checks. We can have memory slots which have to be /* A few sanity checks. We can have memory slots which have to be
located/ended at a segment boundary (1MB). The memory in userland is located/ended at a segment boundary (1MB). The memory in userland is
ok to be fragmented into various different vmas. It is okay to mmap() ok to be fragmented into various different vmas. It is okay to mmap()
and munmap() stuff in this slot after doing this call at any time */ and munmap() stuff in this slot after doing this call at any time */
if (mem->userspace_addr & 0xffffful) if (new->userspace_addr & 0xffffful)
return -EINVAL; return -EINVAL;
if (mem->memory_size & 0xffffful) if (size & 0xffffful)
return -EINVAL; return -EINVAL;
if (mem->guest_phys_addr + mem->memory_size > kvm->arch.mem_limit) if ((new->base_gfn * PAGE_SIZE) + size > kvm->arch.mem_limit)
return -EINVAL; return -EINVAL;
/* When we are protected, we should not change the memory slots */ /* When we are protected, we should not change the memory slots */
...@@ -5052,8 +5054,9 @@ void kvm_arch_commit_memory_region(struct kvm *kvm, ...@@ -5052,8 +5054,9 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
break; break;
fallthrough; fallthrough;
case KVM_MR_CREATE: case KVM_MR_CREATE:
rc = gmap_map_segment(kvm->arch.gmap, mem->userspace_addr, rc = gmap_map_segment(kvm->arch.gmap, new->userspace_addr,
mem->guest_phys_addr, mem->memory_size); new->base_gfn * PAGE_SIZE,
new->npages * PAGE_SIZE);
break; break;
case KVM_MR_FLAGS_ONLY: case KVM_MR_FLAGS_ONLY:
break; break;
......
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