From patchwork Tue Aug 20 05:46:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Xiong Y" X-Patchwork-Id: 11102929 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 721D81395 for ; Tue, 20 Aug 2019 05:41:22 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5B2E6214DA for ; Tue, 20 Aug 2019 05:41:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5B2E6214DA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DC1CE6E5D9; Tue, 20 Aug 2019 05:41:20 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6E5C46E5D9; Tue, 20 Aug 2019 05:41:20 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Aug 2019 22:41:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,407,1559545200"; d="scan'208";a="207243533" Received: from test-optiplex-7040.bj.intel.com ([10.238.154.166]) by fmsmga002.fm.intel.com with ESMTP; 19 Aug 2019 22:41:19 -0700 From: Xiong Zhang To: intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org Date: Tue, 20 Aug 2019 13:46:17 +0800 Message-Id: <1566279978-9659-1-git-send-email-xiong.y.zhang@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [Intel-gfx] [PATCH 1/2] drm/i915: Don't deballoon unused ggtt drm_mm_node in linux guest X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: stable@vger.kernel.org MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" The following call trace may exist in linux guest dmesg when guest i915 driver is unloaded. [ 90.776610] [drm:vgt_deballoon_space.isra.0 [i915]] deballoon space: range [0x0 - 0x0] 0 KiB. [ 90.776621] BUG: unable to handle kernel NULL pointer dereference at 00000000000000c0 [ 90.776691] IP: drm_mm_remove_node+0x4d/0x320 [drm] [ 90.776718] PGD 800000012c7d0067 P4D 800000012c7d0067 PUD 138e4c067 PMD 0 [ 90.777091] task: ffff9adab60f2f00 task.stack: ffffaf39c0fe0000 [ 90.777142] RIP: 0010:drm_mm_remove_node+0x4d/0x320 [drm] [ 90.777573] Call Trace: [ 90.777653] intel_vgt_deballoon+0x4c/0x60 [i915] [ 90.777729] i915_ggtt_cleanup_hw+0x121/0x190 [i915] [ 90.777792] i915_driver_unload+0x145/0x180 [i915] [ 90.777856] i915_pci_remove+0x15/0x20 [i915] [ 90.777890] pci_device_remove+0x3b/0xc0 [ 90.777916] device_release_driver_internal+0x157/0x220 [ 90.777945] driver_detach+0x39/0x70 [ 90.777967] bus_remove_driver+0x51/0xd0 [ 90.777990] pci_unregister_driver+0x23/0x90 [ 90.778019] SyS_delete_module+0x1da/0x240 [ 90.778045] entry_SYSCALL_64_fastpath+0x24/0x87 [ 90.778072] RIP: 0033:0x7f34312af067 [ 90.778092] RSP: 002b:00007ffdea3da0d8 EFLAGS: 00000206 [ 90.778297] RIP: drm_mm_remove_node+0x4d/0x320 [drm] RSP: ffffaf39c0fe3dc0 [ 90.778344] ---[ end trace f4b1bc8305fc59dd ]--- Four drm_mm_node are used to reserve guest ggtt space, but some of them may be skipped and not initialised due to space constraints in intel_vgt_balloon(). If drm_mm_remove_node() is called with uninitialized drm_mm_node, the above call trace occurs. This patch check drm_mm_node's validity before calling drm_mm_remove_node(). Fixes: ff8f797557c7("drm/i915: return the correct usable aperture size under gvt environment") Cc: stable@vger.kernel.org Signed-off-by: Xiong Zhang Acked-by: Zhenyu Wang --- drivers/gpu/drm/i915/i915_vgpu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_vgpu.c b/drivers/gpu/drm/i915/i915_vgpu.c index bf2b837..d2fd66f 100644 --- a/drivers/gpu/drm/i915/i915_vgpu.c +++ b/drivers/gpu/drm/i915/i915_vgpu.c @@ -119,6 +119,9 @@ static struct _balloon_info_ bl_info; static void vgt_deballoon_space(struct i915_ggtt *ggtt, struct drm_mm_node *node) { + if (!node->allocated) + return; + DRM_DEBUG_DRIVER("deballoon space: range [0x%llx - 0x%llx] %llu KiB.\n", node->start, node->start + node->size, From patchwork Tue Aug 20 05:46:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Xiong Y" X-Patchwork-Id: 11102931 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D781C1399 for ; Tue, 20 Aug 2019 05:41:24 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C0B17214DA for ; Tue, 20 Aug 2019 05:41:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C0B17214DA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0A5496E5DC; Tue, 20 Aug 2019 05:41:24 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id A0D626E5DA; Tue, 20 Aug 2019 05:41:22 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Aug 2019 22:41:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,407,1559545200"; d="scan'208";a="207243548" Received: from test-optiplex-7040.bj.intel.com ([10.238.154.166]) by fmsmga002.fm.intel.com with ESMTP; 19 Aug 2019 22:41:21 -0700 From: Xiong Zhang To: intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org Date: Tue, 20 Aug 2019 13:46:18 +0800 Message-Id: <1566279978-9659-2-git-send-email-xiong.y.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1566279978-9659-1-git-send-email-xiong.y.zhang@intel.com> References: <1566279978-9659-1-git-send-email-xiong.y.zhang@intel.com> Subject: [Intel-gfx] [PATCH 2/2] drm/i915: Move vgpu balloon info into i915_virtual_gpu struct X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 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" vgpu ballon info consists of four drm_mm_node which is used to reserve ggtt space, then linux guest won't use these reserved ggtt space. Each vgpu has its own ballon info, so move ballon info into i915_virtual_gpu structure. Signed-off-by: Xiong Zhang --- drivers/gpu/drm/i915/i915_drv.h | 14 ++++++++++++ drivers/gpu/drm/i915/i915_vgpu.c | 49 ++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 18be8b2..9c14095 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -1024,6 +1024,20 @@ struct i915_frontbuffer_tracking { struct i915_virtual_gpu { bool active; u32 caps; + + struct balloon_info { + /* + * There are up to 2 regions per mappable/unmappable graphic + * memory that might be ballooned. Here, index 0/1 is for + * mappable graphic memory, 2/3 for unmappable graphic memory. + */ +#define VGPU_MAPPABLE_BALLOON_LOW 0 +#define VGPU_MAPPABLE_BALLOON_HIGH 1 +#define VGPU_UNMAPPABLE_BALLOON_LOW 2 +#define VGPU_UNMAPPABLE_BALLOON_HIGH 3 +#define VGPU_MAX_BALLOON_NUM 4 + struct drm_mm_node space[VGPU_MAX_BALLOON_NUM]; + } bl_info; }; /* used in computing the new watermarks state */ diff --git a/drivers/gpu/drm/i915/i915_vgpu.c b/drivers/gpu/drm/i915/i915_vgpu.c index d2fd66f..3cc53e6 100644 --- a/drivers/gpu/drm/i915/i915_vgpu.c +++ b/drivers/gpu/drm/i915/i915_vgpu.c @@ -105,17 +105,6 @@ bool intel_vgpu_has_full_ppgtt(struct drm_i915_private *dev_priv) return dev_priv->vgpu.caps & VGT_CAPS_FULL_PPGTT; } -struct _balloon_info_ { - /* - * There are up to 2 regions per mappable/unmappable graphic - * memory that might be ballooned. Here, index 0/1 is for mappable - * graphic memory, 2/3 for unmappable graphic memory. - */ - struct drm_mm_node space[4]; -}; - -static struct _balloon_info_ bl_info; - static void vgt_deballoon_space(struct i915_ggtt *ggtt, struct drm_mm_node *node) { @@ -140,15 +129,16 @@ static void vgt_deballoon_space(struct i915_ggtt *ggtt, */ void intel_vgt_deballoon(struct i915_ggtt *ggtt) { + struct drm_i915_private *dev_priv = ggtt->vm.i915; int i; - if (!intel_vgpu_active(ggtt->vm.i915)) + if (!intel_vgpu_active(dev_priv)) return; DRM_DEBUG("VGT deballoon.\n"); - for (i = 0; i < 4; i++) - vgt_deballoon_space(ggtt, &bl_info.space[i]); + for (i = 0; i < VGPU_MAX_BALLOON_NUM; i++) + vgt_deballoon_space(ggtt, &dev_priv->vgpu.bl_info.space[i]); } static int vgt_balloon_space(struct i915_ggtt *ggtt, @@ -219,6 +209,7 @@ static int vgt_balloon_space(struct i915_ggtt *ggtt, int intel_vgt_balloon(struct i915_ggtt *ggtt) { struct intel_uncore *uncore = &ggtt->vm.i915->uncore; + struct balloon_info *bl_info; unsigned long ggtt_end = ggtt->vm.total; unsigned long mappable_base, mappable_size, mappable_end; @@ -253,34 +244,39 @@ int intel_vgt_balloon(struct i915_ggtt *ggtt) return -EINVAL; } + bl_info = &ggtt->vm.i915->vgpu.bl_info; /* Unmappable graphic memory ballooning */ if (unmappable_base > ggtt->mappable_end) { - ret = vgt_balloon_space(ggtt, &bl_info.space[2], - ggtt->mappable_end, unmappable_base); + ret = vgt_balloon_space(ggtt, + &bl_info->space[VGPU_UNMAPPABLE_BALLOON_LOW], + ggtt->mappable_end, unmappable_base); if (ret) goto err; } if (unmappable_end < ggtt_end) { - ret = vgt_balloon_space(ggtt, &bl_info.space[3], - unmappable_end, ggtt_end); + ret = vgt_balloon_space(ggtt, + &bl_info->space[VGPU_UNMAPPABLE_BALLOON_HIGH], + unmappable_end, ggtt_end); if (ret) goto err_upon_mappable; } /* Mappable graphic memory ballooning */ if (mappable_base) { - ret = vgt_balloon_space(ggtt, &bl_info.space[0], - 0, mappable_base); + ret = vgt_balloon_space(ggtt, + &bl_info->space[VGPU_MAPPABLE_BALLOON_LOW], + 0, mappable_base); if (ret) goto err_upon_unmappable; } if (mappable_end < ggtt->mappable_end) { - ret = vgt_balloon_space(ggtt, &bl_info.space[1], - mappable_end, ggtt->mappable_end); + ret = vgt_balloon_space(ggtt, + &bl_info->space[VGPU_MAPPABLE_BALLOON_HIGH], + mappable_end, ggtt->mappable_end); if (ret) goto err_below_mappable; @@ -290,11 +286,14 @@ int intel_vgt_balloon(struct i915_ggtt *ggtt) return 0; err_below_mappable: - vgt_deballoon_space(ggtt, &bl_info.space[0]); + vgt_deballoon_space(ggtt, + &bl_info->space[VGPU_MAPPABLE_BALLOON_LOW]); err_upon_unmappable: - vgt_deballoon_space(ggtt, &bl_info.space[3]); + vgt_deballoon_space(ggtt, + &bl_info->space[VGPU_UNMAPPABLE_BALLOON_HIGH]); err_upon_mappable: - vgt_deballoon_space(ggtt, &bl_info.space[2]); + vgt_deballoon_space(ggtt, + &bl_info->space[VGPU_UNMAPPABLE_BALLOON_LOW]); err: DRM_ERROR("VGT balloon fail\n"); return ret;