From: David Stevens <stevensd@chromium.org>
To: Marc Zyngier <maz@kernel.org>,
Huacai Chen <chenhuacai@kernel.org>,
Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>,
Paul Mackerras <paulus@ozlabs.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Zhenyu Wang <zhenyuw@linux.intel.com>,
Zhi Wang <zhi.a.wang@intel.com>
Cc: James Morse <james.morse@arm.com>,
Alexandru Elisei <alexandru.elisei@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Will Deacon <will@kernel.org>,
Sean Christopherson <seanjc@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
linux-arm-kernel@lists.infradead.org,
kvmarm@lists.cs.columbia.edu,
open list <linux-kernel@vger.kernel.org>,
linux-mips@vger.kernel.org, kvm@vger.kernel.org,
kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
intel-gvt-dev@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org,
ML dri-devel <dri-devel@lists.freedesktop.org>,
David Stevens <stevensd@google.com>
Subject: Re: [PATCH 6/6] drm/i915/gvt: use gfn_to_pfn's page instead of pfn
Date: Thu, 24 Jun 2021 13:28:23 +0900 [thread overview]
Message-ID: <CAD=HUj6C455sDhBUdQ_Kev=DPpdLRDDycumqfh8kjvredGh=hw@mail.gmail.com> (raw)
In-Reply-To: <20210624035749.4054934-7-stevensd@google.com>
Please ignore this last patch. It was put together as an afterthought
and wasn't properly tested.
-David
On Thu, Jun 24, 2021 at 12:59 PM David Stevens <stevensd@chromium.org> wrote:
>
> Return struct page instead of pfn from gfn_to_mfn. This function is only
> used to determine if the page is a transparent hugepage, to enable 2MB
> huge gtt shadowing. Returning the page directly avoids the risk of
> calling pfn_to_page on a VM_IO|VM_PFNMAP pfn.
>
> This change also properly releases the reference on the page returned by
> gfn_to_pfn.
>
> Signed-off-by: David Stevens <stevensd@google.com>
> ---
> drivers/gpu/drm/i915/gvt/gtt.c | 12 ++++++++----
> drivers/gpu/drm/i915/gvt/hypercall.h | 3 ++-
> drivers/gpu/drm/i915/gvt/kvmgt.c | 12 ++++--------
> drivers/gpu/drm/i915/gvt/mpt.h | 8 ++++----
> 4 files changed, 18 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c
> index 9478c132d7b6..b2951c560582 100644
> --- a/drivers/gpu/drm/i915/gvt/gtt.c
> +++ b/drivers/gpu/drm/i915/gvt/gtt.c
> @@ -1160,16 +1160,20 @@ static int is_2MB_gtt_possible(struct intel_vgpu *vgpu,
> struct intel_gvt_gtt_entry *entry)
> {
> struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops;
> - unsigned long pfn;
> + struct page *page;
> + bool is_trans_huge;
>
> if (!HAS_PAGE_SIZES(vgpu->gvt->gt->i915, I915_GTT_PAGE_SIZE_2M))
> return 0;
>
> - pfn = intel_gvt_hypervisor_gfn_to_mfn(vgpu, ops->get_pfn(entry));
> - if (pfn == INTEL_GVT_INVALID_ADDR)
> + page = intel_gvt_hypervisor_gfn_to_mfn_page(vgpu, ops->get_pfn(entry));
> + if (!page)
> return -EINVAL;
>
> - return PageTransHuge(pfn_to_page(pfn));
> + is_trans_huge = PageTransHuge(page);
> + put_page(page);
> +
> + return is_trans_huge;
> }
>
> static int split_2MB_gtt_entry(struct intel_vgpu *vgpu,
> diff --git a/drivers/gpu/drm/i915/gvt/hypercall.h b/drivers/gpu/drm/i915/gvt/hypercall.h
> index b79da5124f83..017190ff52d5 100644
> --- a/drivers/gpu/drm/i915/gvt/hypercall.h
> +++ b/drivers/gpu/drm/i915/gvt/hypercall.h
> @@ -60,7 +60,8 @@ struct intel_gvt_mpt {
> unsigned long len);
> int (*write_gpa)(unsigned long handle, unsigned long gpa, void *buf,
> unsigned long len);
> - unsigned long (*gfn_to_mfn)(unsigned long handle, unsigned long gfn);
> + struct page *(*gfn_to_mfn_page)(unsigned long handle,
> + unsigned long gfn);
>
> int (*dma_map_guest_page)(unsigned long handle, unsigned long gfn,
> unsigned long size, dma_addr_t *dma_addr);
> diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
> index b829ff67e3d9..1e97ae813ed0 100644
> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
> +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
> @@ -1928,21 +1928,17 @@ static int kvmgt_inject_msi(unsigned long handle, u32 addr, u16 data)
> return -EFAULT;
> }
>
> -static unsigned long kvmgt_gfn_to_pfn(unsigned long handle, unsigned long gfn)
> +static struct page *kvmgt_gfn_to_page(unsigned long handle, unsigned long gfn)
> {
> struct kvmgt_guest_info *info;
> kvm_pfn_t pfn;
>
> if (!handle_valid(handle))
> - return INTEL_GVT_INVALID_ADDR;
> + return NULL;
>
> info = (struct kvmgt_guest_info *)handle;
>
> - pfn = kvm_pfn_page_unwrap(gfn_to_pfn(info->kvm, gfn));
> - if (is_error_noslot_pfn(pfn))
> - return INTEL_GVT_INVALID_ADDR;
> -
> - return pfn;
> + return gfn_to_pfn(info->kvm, gfn).page;
> }
>
> static int kvmgt_dma_map_guest_page(unsigned long handle, unsigned long gfn,
> @@ -2112,7 +2108,7 @@ static const struct intel_gvt_mpt kvmgt_mpt = {
> .disable_page_track = kvmgt_page_track_remove,
> .read_gpa = kvmgt_read_gpa,
> .write_gpa = kvmgt_write_gpa,
> - .gfn_to_mfn = kvmgt_gfn_to_pfn,
> + .gfn_to_mfn_page = kvmgt_gfn_to_page,
> .dma_map_guest_page = kvmgt_dma_map_guest_page,
> .dma_unmap_guest_page = kvmgt_dma_unmap_guest_page,
> .dma_pin_guest_page = kvmgt_dma_pin_guest_page,
> diff --git a/drivers/gpu/drm/i915/gvt/mpt.h b/drivers/gpu/drm/i915/gvt/mpt.h
> index 550a456e936f..9169b83cf0f6 100644
> --- a/drivers/gpu/drm/i915/gvt/mpt.h
> +++ b/drivers/gpu/drm/i915/gvt/mpt.h
> @@ -214,17 +214,17 @@ static inline int intel_gvt_hypervisor_write_gpa(struct intel_vgpu *vgpu,
> }
>
> /**
> - * intel_gvt_hypervisor_gfn_to_mfn - translate a GFN to MFN
> + * intel_gvt_hypervisor_gfn_to_mfn_page - translate a GFN to MFN page
> * @vgpu: a vGPU
> * @gpfn: guest pfn
> *
> * Returns:
> - * MFN on success, INTEL_GVT_INVALID_ADDR if failed.
> + * struct page* on success, NULL if failed.
> */
> -static inline unsigned long intel_gvt_hypervisor_gfn_to_mfn(
> +static inline unsigned long intel_gvt_hypervisor_gfn_to_mfn_page(
> struct intel_vgpu *vgpu, unsigned long gfn)
> {
> - return intel_gvt_host.mpt->gfn_to_mfn(vgpu->handle, gfn);
> + return intel_gvt_host.mpt->gfn_to_mfn_page(vgpu->handle, gfn);
> }
>
> /**
> --
> 2.32.0.93.g670b81a890-goog
>
next prev parent reply other threads:[~2021-06-24 4:28 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-24 3:57 [PATCH 0/6] KVM: Remove uses of struct page from x86 and arm64 MMU David Stevens
2021-06-24 3:57 ` [PATCH 1/6] KVM: x86/mmu: release audited pfns David Stevens
2021-06-24 8:43 ` Nicholas Piggin
2021-06-24 9:43 ` Paolo Bonzini
2021-06-24 15:36 ` Sean Christopherson
2021-06-24 3:57 ` [PATCH 2/6] KVM: mmu: also return page from gfn_to_pfn David Stevens
2021-06-24 8:52 ` Nicholas Piggin
2021-06-24 9:42 ` Paolo Bonzini
2021-06-24 9:57 ` Nicholas Piggin
2021-06-24 10:13 ` Paolo Bonzini
2021-06-24 10:17 ` Nicholas Piggin
2021-06-24 10:21 ` Paolo Bonzini
2021-06-24 10:42 ` Nicholas Piggin
2021-06-24 9:40 ` Marc Zyngier
2021-06-24 3:57 ` [PATCH 3/6] KVM: x86/mmu: avoid struct page in MMU David Stevens
2021-06-24 7:31 ` Paolo Bonzini
2021-06-24 8:58 ` Nicholas Piggin
2021-06-24 10:06 ` Marc Zyngier
2021-06-24 10:17 ` Paolo Bonzini
2021-06-24 10:43 ` Nicholas Piggin
2021-06-24 3:57 ` [PATCH 4/6] KVM: arm64/mmu: " David Stevens
2021-06-24 10:43 ` Marc Zyngier
2021-06-24 3:57 ` [PATCH 5/6] KVM: mmu: remove over-aggressive warnings David Stevens
2021-06-24 3:57 ` [PATCH 6/6] drm/i915/gvt: use gfn_to_pfn's page instead of pfn David Stevens
2021-06-24 4:28 ` David Stevens [this message]
2021-06-24 6:57 ` [PATCH 0/6] KVM: Remove uses of struct page from x86 and arm64 MMU Paolo Bonzini
2021-06-24 10:34 ` Nicholas Piggin
2021-06-24 11:42 ` Nicholas Piggin
2021-06-24 12:00 ` Paolo Bonzini
2021-06-24 12:41 ` Paolo Bonzini
2021-06-24 12:57 ` Nicholas Piggin
2021-06-24 15:35 ` Paolo Bonzini
2021-06-25 0:20 ` Nicholas Piggin
2021-06-25 7:44 ` Christian Borntraeger
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='CAD=HUj6C455sDhBUdQ_Kev=DPpdLRDDycumqfh8kjvredGh=hw@mail.gmail.com' \
--to=stevensd@chromium.org \
--cc=aleksandar.qemu.devel@gmail.com \
--cc=alexandru.elisei@arm.com \
--cc=chenhuacai@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-gvt-dev@lists.freedesktop.org \
--cc=james.morse@arm.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maz@kernel.org \
--cc=paulus@ozlabs.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=stevensd@google.com \
--cc=suzuki.poulose@arm.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=will@kernel.org \
--cc=zhenyuw@linux.intel.com \
--cc=zhi.a.wang@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).