From: Christoffer Dall <christoffer.dall@linaro.org>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
magnus.karlsson@avagotech.com, m.smarduch@samsung.com,
kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org,
marc.zyngier@arm.com
Subject: Re: [PATCH 2/2] kvm: fix kvm_is_mmio_pfn() and rename to kvm_is_reserved_pfn()
Date: Sat, 22 Nov 2014 11:16:30 +0100 [thread overview]
Message-ID: <20141122101630.GI3401@cbox> (raw)
In-Reply-To: <546F8602.3010800@redhat.com>
On Fri, Nov 21, 2014 at 07:35:46PM +0100, Paolo Bonzini wrote:
>
>
> On 10/11/2014 09:33, Ard Biesheuvel wrote:
> > This reverts commit 85c8555ff0 ("KVM: check for !is_zero_pfn() in
> > kvm_is_mmio_pfn()") and renames the function to kvm_is_reserved_pfn.
> >
> > The problem being addressed by the patch above was that some ARM code
> > based the memory mapping attributes of a pfn on the return value of
> > kvm_is_mmio_pfn(), whose name indeed suggests that such pfns should
> > be mapped as device memory.
> >
> > However, kvm_is_mmio_pfn() doesn't do quite what it says on the tin,
> > and the existing non-ARM users were already using it in a way which
> > suggests that its name should probably have been 'kvm_is_reserved_pfn'
> > from the beginning, e.g., whether or not to call get_page/put_page on
> > it etc. This means that returning false for the zero page is a mistake
> > and the patch above should be reverted.
> >
> > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > ---
> > arch/ia64/kvm/kvm-ia64.c | 2 +-
> > arch/x86/kvm/mmu.c | 6 +++---
> > include/linux/kvm_host.h | 2 +-
> > virt/kvm/kvm_main.c | 16 ++++++++--------
> > 4 files changed, 13 insertions(+), 13 deletions(-)
> >
> > diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c
> > index ec6b9acb6bea..dbe46f43884d 100644
> > --- a/arch/ia64/kvm/kvm-ia64.c
> > +++ b/arch/ia64/kvm/kvm-ia64.c
> > @@ -1563,7 +1563,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
> >
> > for (i = 0; i < npages; i++) {
> > pfn = gfn_to_pfn(kvm, base_gfn + i);
> > - if (!kvm_is_mmio_pfn(pfn)) {
> > + if (!kvm_is_reserved_pfn(pfn)) {
> > kvm_set_pmt_entry(kvm, base_gfn + i,
> > pfn << PAGE_SHIFT,
> > _PAGE_AR_RWX | _PAGE_MA_WB);
> > diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> > index ac1c4de3a484..978f402006ee 100644
> > --- a/arch/x86/kvm/mmu.c
> > +++ b/arch/x86/kvm/mmu.c
> > @@ -630,7 +630,7 @@ static int mmu_spte_clear_track_bits(u64 *sptep)
> > * kvm mmu, before reclaiming the page, we should
> > * unmap it from mmu first.
> > */
> > - WARN_ON(!kvm_is_mmio_pfn(pfn) && !page_count(pfn_to_page(pfn)));
> > + WARN_ON(!kvm_is_reserved_pfn(pfn) && !page_count(pfn_to_page(pfn)));
> >
> > if (!shadow_accessed_mask || old_spte & shadow_accessed_mask)
> > kvm_set_pfn_accessed(pfn);
> > @@ -2461,7 +2461,7 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
> > spte |= PT_PAGE_SIZE_MASK;
> > if (tdp_enabled)
> > spte |= kvm_x86_ops->get_mt_mask(vcpu, gfn,
> > - kvm_is_mmio_pfn(pfn));
> > + kvm_is_reserved_pfn(pfn));
> >
> > if (host_writable)
> > spte |= SPTE_HOST_WRITEABLE;
> > @@ -2737,7 +2737,7 @@ static void transparent_hugepage_adjust(struct kvm_vcpu *vcpu,
> > * PT_PAGE_TABLE_LEVEL and there would be no adjustment done
> > * here.
> > */
> > - if (!is_error_noslot_pfn(pfn) && !kvm_is_mmio_pfn(pfn) &&
> > + if (!is_error_noslot_pfn(pfn) && !kvm_is_reserved_pfn(pfn) &&
> > level == PT_PAGE_TABLE_LEVEL &&
> > PageTransCompound(pfn_to_page(pfn)) &&
> > !has_wrprotected_page(vcpu->kvm, gfn, PT_DIRECTORY_LEVEL)) {
> > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> > index ea53b04993f2..a6059bdf7b03 100644
> > --- a/include/linux/kvm_host.h
> > +++ b/include/linux/kvm_host.h
> > @@ -703,7 +703,7 @@ void kvm_arch_sync_events(struct kvm *kvm);
> > int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu);
> > void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
> >
> > -bool kvm_is_mmio_pfn(pfn_t pfn);
> > +bool kvm_is_reserved_pfn(pfn_t pfn);
> >
> > struct kvm_irq_ack_notifier {
> > struct hlist_node link;
> > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> > index 25ffac9e947d..3cee7b167052 100644
> > --- a/virt/kvm/kvm_main.c
> > +++ b/virt/kvm/kvm_main.c
> > @@ -107,10 +107,10 @@ EXPORT_SYMBOL_GPL(kvm_rebooting);
> >
> > static bool largepages_enabled = true;
> >
> > -bool kvm_is_mmio_pfn(pfn_t pfn)
> > +bool kvm_is_reserved_pfn(pfn_t pfn)
> > {
> > if (pfn_valid(pfn))
> > - return !is_zero_pfn(pfn) && PageReserved(pfn_to_page(pfn));
> > + return PageReserved(pfn_to_page(pfn));
> >
> > return true;
> > }
> > @@ -1321,7 +1321,7 @@ static pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async,
> > else if ((vma->vm_flags & VM_PFNMAP)) {
> > pfn = ((addr - vma->vm_start) >> PAGE_SHIFT) +
> > vma->vm_pgoff;
> > - BUG_ON(!kvm_is_mmio_pfn(pfn));
> > + BUG_ON(!kvm_is_reserved_pfn(pfn));
> > } else {
> > if (async && vma_is_valid(vma, write_fault))
> > *async = true;
> > @@ -1427,7 +1427,7 @@ static struct page *kvm_pfn_to_page(pfn_t pfn)
> > if (is_error_noslot_pfn(pfn))
> > return KVM_ERR_PTR_BAD_PAGE;
> >
> > - if (kvm_is_mmio_pfn(pfn)) {
> > + if (kvm_is_reserved_pfn(pfn)) {
> > WARN_ON(1);
> > return KVM_ERR_PTR_BAD_PAGE;
> > }
> > @@ -1456,7 +1456,7 @@ EXPORT_SYMBOL_GPL(kvm_release_page_clean);
> >
> > void kvm_release_pfn_clean(pfn_t pfn)
> > {
> > - if (!is_error_noslot_pfn(pfn) && !kvm_is_mmio_pfn(pfn))
> > + if (!is_error_noslot_pfn(pfn) && !kvm_is_reserved_pfn(pfn))
> > put_page(pfn_to_page(pfn));
> > }
> > EXPORT_SYMBOL_GPL(kvm_release_pfn_clean);
> > @@ -1477,7 +1477,7 @@ static void kvm_release_pfn_dirty(pfn_t pfn)
> >
> > void kvm_set_pfn_dirty(pfn_t pfn)
> > {
> > - if (!kvm_is_mmio_pfn(pfn)) {
> > + if (!kvm_is_reserved_pfn(pfn)) {
> > struct page *page = pfn_to_page(pfn);
> > if (!PageReserved(page))
> > SetPageDirty(page);
> > @@ -1487,14 +1487,14 @@ EXPORT_SYMBOL_GPL(kvm_set_pfn_dirty);
> >
> > void kvm_set_pfn_accessed(pfn_t pfn)
> > {
> > - if (!kvm_is_mmio_pfn(pfn))
> > + if (!kvm_is_reserved_pfn(pfn))
> > mark_page_accessed(pfn_to_page(pfn));
> > }
> > EXPORT_SYMBOL_GPL(kvm_set_pfn_accessed);
> >
> > void kvm_get_pfn(pfn_t pfn)
> > {
> > - if (!kvm_is_mmio_pfn(pfn))
> > + if (!kvm_is_reserved_pfn(pfn))
> > get_page(pfn_to_page(pfn));
> > }
> > EXPORT_SYMBOL_GPL(kvm_get_pfn);
> >
>
> Acked-by: Paolo Bonzini <pbonzini@redhat.com>
>
> Since this is in practice ARM only, I'll apply these for 3.18.
>
Thanks Paolo!
-Christoffer
next prev parent reply other threads:[~2014-11-22 10:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-10 8:33 [PATCH 1/2] arm/arm64: kvm: drop inappropriate use of kvm_is_mmio_pfn() Ard Biesheuvel
2014-11-10 8:33 ` [PATCH 2/2] kvm: fix kvm_is_mmio_pfn() and rename to kvm_is_reserved_pfn() Ard Biesheuvel
2014-11-10 10:53 ` Christoffer Dall
2014-11-10 11:05 ` Ard Biesheuvel
2014-11-10 11:11 ` Christoffer Dall
2014-11-21 11:30 ` Ard Biesheuvel
2014-11-21 11:46 ` Christoffer Dall
2014-11-21 13:06 ` Paolo Bonzini
2014-11-21 13:18 ` Christoffer Dall
2014-11-21 18:37 ` Paolo Bonzini
2014-11-21 18:35 ` Paolo Bonzini
2014-11-22 10:16 ` Christoffer Dall [this message]
2014-11-10 10:57 ` [PATCH 1/2] arm/arm64: kvm: drop inappropriate use of kvm_is_mmio_pfn() Christoffer Dall
2014-11-10 11:15 ` Ard Biesheuvel
2014-11-21 11:24 ` Christoffer Dall
2014-12-01 9:16 ` Ard Biesheuvel
2014-12-01 9:54 ` Paolo Bonzini
2014-12-01 12:23 ` Christoffer Dall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141122101630.GI3401@cbox \
--to=christoffer.dall@linaro.org \
--cc=ard.biesheuvel@linaro.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=m.smarduch@samsung.com \
--cc=magnus.karlsson@avagotech.com \
--cc=marc.zyngier@arm.com \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.