From patchwork Tue Apr 25 10:34:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Xiong Y" X-Patchwork-Id: 9697833 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1D5F460224 for ; Tue, 25 Apr 2017 10:27:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0626F205D1 for ; Tue, 25 Apr 2017 10:27:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EED8324560; Tue, 25 Apr 2017 10:27:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 536F3205D1 for ; Tue, 25 Apr 2017 10:27:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0C8F56E30F; Tue, 25 Apr 2017 10:27:23 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id D26B76E30E; Tue, 25 Apr 2017 10:27:21 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Apr 2017 03:27:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,249,1488873600"; d="scan'208";a="253176257" Received: from panda-dev.bj.intel.com ([10.238.135.63]) by fmsmga004.fm.intel.com with ESMTP; 25 Apr 2017 03:27:19 -0700 From: Xiong Zhang To: joonas.lahtinen@linux.intel.com, kevin.tian@intel.com, daniel.vetter@intel.com, zhenyuw@linux.intel.com, jani.nikula@linux.intel.com, alex.williamson@redhat.com Date: Tue, 25 Apr 2017 18:34:45 +0800 Message-Id: <1493116501-29327-1-git-send-email-xiong.y.zhang@intel.com> X-Mailer: git-send-email 1.9.1 Cc: intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, stable@vger.kernel.org Subject: [Intel-gfx] [PATCH V6] drm/i915: Disable stolen memory when i915 runs in guest vm X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Stolen memory isn't a standard pci resource and exists in RMRR which has identity mapping in iommu table when host boot up, so 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. Stolen memory exists in kernel for a long time, and 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 later. 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) v6:Handle real ISA bridge assigned to guest also (Joonas) Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=99025 Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=99028 Signed-off-by: Xiong Zhang Cc: stable@vger.kernel.org # 4.5+ --- drivers/gpu/drm/i915/i915_drv.c | 39 +++++++++++++++++++++++++++------- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_gem_stolen.c | 4 ++-- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c index cc7393e..c0e8968 100644 --- a/drivers/gpu/drm/i915/i915_drv.c +++ b/drivers/gpu/drm/i915/i915_drv.c @@ -164,31 +164,42 @@ static void intel_detect_pch(struct drm_i915_private *dev_priv) * * In some virtualized environments (e.g. XEN), there is irrelevant * ISA bridge in the system. To work reliably, we should scan trhough - * all the ISA bridge devices and check for the first match, instead + * all the ISA bridge devices and check for all the match, instead * of only checking the first one. + * + * If both the real ISA bridge and IGD are assigned to one guest, this + * guest will have two matched ISA bridges: real and emulatated. We + * couldn't guarantee which one is detected first, so we scan all the + * match, instead of only checking the first match. Real one take + * precedence over emulated to set pch_type and pch_id.Emulated one is + * used to disable stolen memory.Finally pci_get_class() will return + * NULL to exit loop and deference the last matched pch. */ while ((pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, pch))) { if (pch->vendor == PCI_VENDOR_ID_INTEL) { unsigned short id = pch->device & INTEL_PCH_DEVICE_ID_MASK; - dev_priv->pch_id = id; if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) { dev_priv->pch_type = PCH_IBX; + dev_priv->pch_id = id; DRM_DEBUG_KMS("Found Ibex Peak PCH\n"); WARN_ON(!IS_GEN5(dev_priv)); } else if (id == INTEL_PCH_CPT_DEVICE_ID_TYPE) { dev_priv->pch_type = PCH_CPT; + dev_priv->pch_id = id; DRM_DEBUG_KMS("Found CougarPoint PCH\n"); WARN_ON(!(IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))); } else if (id == INTEL_PCH_PPT_DEVICE_ID_TYPE) { /* PantherPoint is CPT compatible */ dev_priv->pch_type = PCH_CPT; + dev_priv->pch_id = id; DRM_DEBUG_KMS("Found PantherPoint PCH\n"); WARN_ON(!(IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))); } else if (id == INTEL_PCH_LPT_DEVICE_ID_TYPE) { dev_priv->pch_type = PCH_LPT; + dev_priv->pch_id = id; DRM_DEBUG_KMS("Found LynxPoint PCH\n"); WARN_ON(!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)); @@ -196,6 +207,7 @@ static void intel_detect_pch(struct drm_i915_private *dev_priv) IS_BDW_ULT(dev_priv)); } else if (id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { dev_priv->pch_type = PCH_LPT; + dev_priv->pch_id = id; DRM_DEBUG_KMS("Found LynxPoint LP PCH\n"); WARN_ON(!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)); @@ -203,16 +215,19 @@ static void intel_detect_pch(struct drm_i915_private *dev_priv) !IS_BDW_ULT(dev_priv)); } else if (id == INTEL_PCH_SPT_DEVICE_ID_TYPE) { dev_priv->pch_type = PCH_SPT; + dev_priv->pch_id = id; DRM_DEBUG_KMS("Found SunrisePoint PCH\n"); WARN_ON(!IS_SKYLAKE(dev_priv) && !IS_KABYLAKE(dev_priv)); } else if (id == INTEL_PCH_SPT_LP_DEVICE_ID_TYPE) { dev_priv->pch_type = PCH_SPT; + dev_priv->pch_id = id; DRM_DEBUG_KMS("Found SunrisePoint LP PCH\n"); WARN_ON(!IS_SKYLAKE(dev_priv) && !IS_KABYLAKE(dev_priv)); } else if (id == INTEL_PCH_KBP_DEVICE_ID_TYPE) { dev_priv->pch_type = PCH_KBP; + dev_priv->pch_id = id; DRM_DEBUG_KMS("Found KabyPoint PCH\n"); WARN_ON(!IS_SKYLAKE(dev_priv) && !IS_KABYLAKE(dev_priv)); @@ -223,18 +238,26 @@ static void intel_detect_pch(struct drm_i915_private *dev_priv) PCI_SUBVENDOR_ID_REDHAT_QUMRANET && pch->subsystem_device == PCI_SUBDEVICE_ID_QEMU)) { - dev_priv->pch_type = - intel_virt_detect_pch(dev_priv); + /* + * P2X is used for VMware, exclude it + */ + if (id != INTEL_PCH_P2X_DEVICE_ID_TYPE) + dev_priv->disable_stolen = true; + /* + * Real PCH still hasn't been detected + */ + if (!HAS_PCH_SPLIT(dev_priv)) { + dev_priv->pch_type = + intel_virt_detect_pch(dev_priv); + dev_priv->pch_id = id; + } } else continue; - break; } } - if (!pch) + if (!HAS_PCH_SPLIT(dev_priv)) DRM_DEBUG_KMS("No PCH found.\n"); - - pci_dev_put(pch); } static int i915_getparam(struct drm_device *dev, void *data, diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 357b6c6..3b8e067 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2132,6 +2132,7 @@ struct drm_i915_private { struct intel_uncore uncore; struct i915_virtual_gpu vgpu; + bool disable_stolen; 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..bffeae7 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->disable_stolen || intel_vgpu_active(dev_priv)) { + DRM_INFO("Running in guest, disabling use of stolen memory\n"); return 0; }