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: Sean Christopherson <seanjc@google.com> Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com> Message-Id: <917ed131c06a4c7b35dd7fb7ed7955be899ad8cc.1638817639.git.maciej.szmigiero@oracle.com>
This commit is contained in:
Родитель
eaaaed137e
Коммит
cf5b486922
|
@ -5012,18 +5012,20 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
|
|||
struct kvm_memory_slot *new,
|
||||
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
|
||||
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()
|
||||
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;
|
||||
|
||||
if (mem->memory_size & 0xffffful)
|
||||
if (size & 0xffffful)
|
||||
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;
|
||||
|
||||
/* When we are protected, we should not change the memory slots */
|
||||
|
@ -5052,8 +5054,9 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
|
|||
break;
|
||||
fallthrough;
|
||||
case KVM_MR_CREATE:
|
||||
rc = gmap_map_segment(kvm->arch.gmap, mem->userspace_addr,
|
||||
mem->guest_phys_addr, mem->memory_size);
|
||||
rc = gmap_map_segment(kvm->arch.gmap, new->userspace_addr,
|
||||
new->base_gfn * PAGE_SIZE,
|
||||
new->npages * PAGE_SIZE);
|
||||
break;
|
||||
case KVM_MR_FLAGS_ONLY:
|
||||
break;
|
||||
|
|
Загрузка…
Ссылка в новой задаче