lkml.org 
[lkml]   [2020]   [Jan]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 04/14] KVM: Play nice with read-only memslots when querying host page size
From
Date
On 08/01/20 21:24, Sean Christopherson wrote:
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 5f7f06824c2b..d9aced677ddd 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -1418,15 +1418,23 @@ EXPORT_SYMBOL_GPL(kvm_is_visible_gfn);
>
> unsigned long kvm_host_page_size(struct kvm_vcpu *vcpu, gfn_t gfn)
> {
> + struct kvm_memory_slot *slot;
> struct vm_area_struct *vma;
> unsigned long addr, size;
>
> size = PAGE_SIZE;
>
> - addr = kvm_vcpu_gfn_to_hva(vcpu, gfn);
> - if (kvm_is_error_hva(addr))
> + /*
> + * Manually do the equivalent of kvm_vcpu_gfn_to_hva() to avoid the
> + * "writable" check in __gfn_to_hva_many(), which will always fail on
> + * read-only memslots due to gfn_to_hva() assuming writes.
> + */
> + slot = kvm_vcpu_gfn_to_memslot(vcpu, gfn);
> + if (!slot || slot->flags & KVM_MEMSLOT_INVALID)
> return PAGE_SIZE;
>
> + addr = __gfn_to_hva_memslot(slot, gfn);
> +
> down_read(&current->mm->mmap_sem);
> vma = find_vma(current->mm, addr);
> if (!vma)
>

Even simpler: use kvm_vcpu_gfn_to_hva_prot

- addr = kvm_vcpu_gfn_to_hva(vcpu, gfn);
+ addr = kvm_vcpu_gfn_to_hva_prot(vcpu, gfn, NULL);

"You are in a maze of twisty little functions, all alike".

Paolo

\
 
 \ /
  Last update: 2020-01-21 15:25    [W:0.132 / U:0.532 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site