From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com ([209.132.183.28]:52164 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754684AbdDLSCH (ORCPT ); Wed, 12 Apr 2017 14:02:07 -0400 Date: Wed, 12 Apr 2017 12:01:59 -0600 From: Alex Williamson To: Xiong Zhang Cc: joonas.lahtinen@linux.intel.com, daniel@ffwll.ch, zhenyuw@linux.intel.com, jani.nikula@linux.intel.com, intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, stable@vger.kernel.org Subject: Re: [Intel-gfx] [PATCH V5] drm/i915: Disable stolen memory when i915 runs on qemu Message-ID: <20170412120159.03765ea7@t450s.home> In-Reply-To: <1491999600-4406-1-git-send-email-xiong.y.zhang@intel.com> References: <1491358106-26329-1-git-send-email-xiong.y.zhang@intel.com> <1491999600-4406-1-git-send-email-xiong.y.zhang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: stable-owner@vger.kernel.org List-ID: On Wed, 12 Apr 2017 20:20:00 +0800 Xiong Zhang wrote: > Stolen memory isn't a standard pci resource and exists in RMRR which has > identity mapping in iommu table, IGD could access stolen memory in host OS. > While according to 'commit c875d2c1b808 ("iommu/vt-d: Exclude devices using > RMRRs from IOMMU API domains")',RMRR isn't supported by kvm, then both EPT > and guest iommu domain table lack of maaping for stolen memory in kvm IGD > passthrough environment. If IGD access stolen memory in such environment, > many iommu exceptions exist in host dmesg and gpu hang exists also. > DMAR: [DMA Read] Request device [00:02.0] fault addr da012000 > [fault reason 05] PTE Write access is not set > DMAR: [DMA Read] Request device [00:02.0] fault addr da2df000 > [fault reason 06] PTE Read access is not set > > So stolen memory should be disabled in KVM IGD passthrough environment, > this patch detects such environment through the existence of qemu emulated > isa bridge. > > When the real ISA bridge is also passed through to guest, guest will have > two isa bridges: emulated and real. Qemu guarantees the busnum:devnum. > funcnum of emulated isa bridge is always less than the real one. Then > emulated isa bridge is always detected first by pci_get_class(ISA). So > stolen memory will be disabled in this case also. Where does QEMU make this guarantee or any sort of guarantee wrt the ISA bridge? Thanks, Alex > Stolen memory exists in kernel for a long time, but this patch depends > on INTEL_PCH_QEMU_DEVICE_ID_TYPE which was introduced in v4.5 kernel, > so this patch should be backported into v4.5 kernel and above. > > v2:GVT-g may run in non qemu (Zhenyu) > v3:Make commit message clear (Daniel) > v4:Fix typo > v5:Exclude P2X as it is used for VMware (Joonas) > > Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=99028 > > Signed-off-by: Xiong Zhang > Reviewed-by: Zhenyu Wang > Reviewed-by: Daniel Vetter > Cc: stable@vger.kernel.org > --- > drivers/gpu/drm/i915/i915_drv.c | 5 +++++ > drivers/gpu/drm/i915/i915_drv.h | 1 + > drivers/gpu/drm/i915/i915_gem_stolen.c | 4 ++-- > 3 files changed, 8 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c > index 6d9944a..0d3c395 100644 > --- a/drivers/gpu/drm/i915/i915_drv.c > +++ b/drivers/gpu/drm/i915/i915_drv.c > @@ -223,6 +223,11 @@ static void intel_detect_pch(struct drm_i915_private *dev_priv) > PCI_SUBVENDOR_ID_REDHAT_QUMRANET && > pch->subsystem_device == > PCI_SUBDEVICE_ID_QEMU)) { > + /* > + * P2X is used for VMware, exclude it > + */ > + if (id != INTEL_PCH_P2X_DEVICE_ID_TYPE) > + dev_priv->run_on_qemu = true; > dev_priv->pch_type = > intel_virt_detect_pch(dev_priv); > } else > diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h > index 2911c49..c87150e 100644 > --- a/drivers/gpu/drm/i915/i915_drv.h > +++ b/drivers/gpu/drm/i915/i915_drv.h > @@ -2152,6 +2152,7 @@ struct drm_i915_private { > struct intel_uncore uncore; > > struct i915_virtual_gpu vgpu; > + bool run_on_qemu; > > struct intel_gvt *gvt; > > diff --git a/drivers/gpu/drm/i915/i915_gem_stolen.c b/drivers/gpu/drm/i915/i915_gem_stolen.c > index f3abdc2..6a011b0 100644 > --- a/drivers/gpu/drm/i915/i915_gem_stolen.c > +++ b/drivers/gpu/drm/i915/i915_gem_stolen.c > @@ -409,8 +409,8 @@ int i915_gem_init_stolen(struct drm_i915_private *dev_priv) > > mutex_init(&dev_priv->mm.stolen_lock); > > - if (intel_vgpu_active(dev_priv)) { > - DRM_INFO("iGVT-g active, disabling use of stolen memory\n"); > + if (dev_priv->run_on_qemu || intel_vgpu_active(dev_priv)) { > + DRM_INFO("Running in guest, disabling use of stolen memory\n"); > return 0; > } >