From patchwork Tue Sep 17 05:48:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Zhang X-Patchwork-Id: 11148063 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 84A6513BD for ; Tue, 17 Sep 2019 05:48:47 +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 6CE6E21848 for ; Tue, 17 Sep 2019 05:48:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6CE6E21848 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 1A6A86E10F; Tue, 17 Sep 2019 05:48:47 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by gabe.freedesktop.org (Postfix) with ESMTPS id 22C4E6E10F; Tue, 17 Sep 2019 05:48:46 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Sep 2019 22:48:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,515,1559545200"; d="scan'208";a="386441197" Received: from xzhan34-mobl3.bj.intel.com ([10.238.154.70]) by fmsmga005.fm.intel.com with ESMTP; 16 Sep 2019 22:48:44 -0700 From: Xiaolin Zhang To: intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Date: Tue, 17 Sep 2019 13:48:13 +0800 Message-Id: <1568699301-2799-3-git-send-email-xiaolin.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1568699301-2799-1-git-send-email-xiaolin.zhang@intel.com> References: <1568699301-2799-1-git-send-email-xiaolin.zhang@intel.com> Subject: [Intel-gfx] [PATCH v10 2/9] drm/i915: vgpu shared memory setup for pv optimization 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: zhenyu.z.wang@intel.com, hang.yuan@intel.com, zhiyuan.lv@intel.com MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" To enable vgpu pv features, we need to setup a shared memory page which will be used for data exchange directly accessed between both guest and backend i915 driver to avoid emulation trap cost. guest i915 will allocate this page memory and then pass it's physical address to backend i915 driver through PVINFO register so that backend i915 driver can access this shared page meory without any trap cost with the help form hyperviser's read guest gpa functionality. guest i915 will send VGT_G2V_SHARED_PAGE_SETUP notification to host GVT once shared memory setup finished. the layout of the shared_page also defined as well in this patch which is used for pv features implementation. v0: RFC. v1: addressed RFC comment to move both shared_page_lock and shared_page to i915_virtual_gpu structure. v2: packed i915_virtual_gpu structure. v3: added SHARED_PAGE_SETUP g2v notification for pv shared_page setup v4: added intel_vgpu_setup_shared_page() in i915_vgpu_pv.c. v5: per engine desc data in shared memory. v6: added version support in shared memory (Zhenyu). v7: added new function i915_destroy_vgpu to free shared memory. Signed-off-by: Xiaolin Zhang --- drivers/gpu/drm/i915/i915_drv.c | 2 + drivers/gpu/drm/i915/i915_drv.h | 4 +- drivers/gpu/drm/i915/i915_pvinfo.h | 5 +- drivers/gpu/drm/i915/i915_vgpu.c | 95 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_vgpu.h | 18 ++++++++ 5 files changed, 122 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c index 0dfcb40..b1f95d0 100644 --- a/drivers/gpu/drm/i915/i915_drv.c +++ b/drivers/gpu/drm/i915/i915_drv.c @@ -1637,6 +1637,8 @@ static void i915_driver_release(struct drm_device *dev) disable_rpm_wakeref_asserts(rpm); + i915_destroy_vgpu(dev_priv); + i915_gem_driver_release(dev_priv); i915_ggtt_driver_release(dev_priv); diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 19fbbef..b3c0849 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -973,7 +973,9 @@ struct i915_virtual_gpu { bool active; u32 caps; u32 pv_caps; -}; + + struct i915_virtual_gpu_pv *pv; +} __packed; /* used in computing the new watermarks state */ struct intel_wm_config { diff --git a/drivers/gpu/drm/i915/i915_pvinfo.h b/drivers/gpu/drm/i915/i915_pvinfo.h index ad398b4..3c63603 100644 --- a/drivers/gpu/drm/i915/i915_pvinfo.h +++ b/drivers/gpu/drm/i915/i915_pvinfo.h @@ -48,6 +48,7 @@ enum vgt_g2v_type { VGT_G2V_PPGTT_L4_PAGE_TABLE_DESTROY, VGT_G2V_EXECLIST_CONTEXT_CREATE, VGT_G2V_EXECLIST_CONTEXT_DESTROY, + VGT_G2V_SHARED_PAGE_SETUP, VGT_G2V_MAX, }; @@ -112,7 +113,9 @@ struct vgt_if { u32 pv_caps; - u32 rsv7[0x200 - 25]; /* pad to one page */ + u64 shared_page_gpa; + + u32 rsv7[0x200 - 27]; /* pad to one page */ } __packed; #define vgtif_offset(x) (offsetof(struct vgt_if, x)) diff --git a/drivers/gpu/drm/i915/i915_vgpu.c b/drivers/gpu/drm/i915/i915_vgpu.c index 981959b..68fecfd 100644 --- a/drivers/gpu/drm/i915/i915_vgpu.c +++ b/drivers/gpu/drm/i915/i915_vgpu.c @@ -107,6 +107,17 @@ void i915_detect_vgpu(struct drm_i915_private *dev_priv) pci_iounmap(pdev, shared_area); } +void i915_destroy_vgpu(struct drm_i915_private *dev_priv) +{ + struct i915_virtual_gpu_pv *pv = dev_priv->vgpu.pv; + + if (!intel_vgpu_active(dev_priv) || !pv) + return; + + __free_page(virt_to_page(pv->shared_page)); + kfree(pv); +} + bool intel_vgpu_has_full_ppgtt(struct drm_i915_private *dev_priv) { return dev_priv->vgpu.caps & VGT_CAPS_FULL_PPGTT; @@ -311,6 +322,84 @@ int intel_vgt_balloon(struct i915_ggtt *ggtt) * i915 vgpu PV support for Linux */ +/* + * shared_page setup for VGPU PV features + */ +static int intel_vgpu_setup_shared_page(struct drm_i915_private *dev_priv, + void __iomem *shared_area) +{ + void __iomem *addr; + struct i915_virtual_gpu_pv *pv; + struct gvt_shared_page *base; + u64 gpa; + u16 ver_maj, ver_min; + int ret = 0; + + /* We allocate 1 page shared between guest and GVT for data exchange. + * ___________..................... + * |head | | + * |___________|.................. PAGE/8 + * |PV ELSP | + * :___________....................PAGE/4 + * |desc (SEND) | + * | | + * :_______________________________PAGE/2 + * |cmds (SEND) | + * | | + * | | + * | | + * | | + * |_______________________________| + * + * 0 offset: PV version area + * PAGE/8 offset: per engine workload submission data area + * PAGE/4 offset: PV command buffer command descriptor area + * PAGE/2 offset: PV command buffer command data area + */ + + base = (struct gvt_shared_page *)get_zeroed_page(GFP_KERNEL); + if (!base) { + dev_info(dev_priv->drm.dev, "out of memory for shared memory\n"); + return -ENOMEM; + } + + /* pass guest memory pa address to GVT and then read back to verify */ + gpa = __pa(base); + addr = shared_area + vgtif_offset(shared_page_gpa); + writeq(gpa, addr); + if (gpa != readq(addr)) { + dev_info(dev_priv->drm.dev, "passed shared_page_gpa failed\n"); + ret = -EIO; + goto err; + } + + addr = shared_area + vgtif_offset(g2v_notify); + writel(VGT_G2V_SHARED_PAGE_SETUP, addr); + + ver_maj = base->ver_major; + ver_min = base->ver_minor; + if (ver_maj != PV_MAJOR || ver_min != PV_MINOR) { + dev_info(dev_priv->drm.dev, "VGPU PV version incompatible\n"); + ret = -EIO; + goto err; + } + + pv = kzalloc(sizeof(struct i915_virtual_gpu_pv), GFP_KERNEL); + if (!pv) { + ret = -ENOMEM; + goto err; + } + + DRM_INFO("vgpu PV ver major %d and minor %d\n", ver_maj, ver_min); + dev_priv->vgpu.pv = pv; + pv->shared_page = base; + pv->enabled = true; + return ret; +err: + __free_page(virt_to_page(base)); + return ret; +} + /** * intel_vgpu_check_pv_caps - detect virtual GPU PV capabilities * @dev_priv: i915 device private @@ -339,5 +428,11 @@ bool intel_vgpu_check_pv_caps(struct drm_i915_private *dev_priv, if (!pvcaps) return false; + if (intel_vgpu_setup_shared_page(dev_priv, shared_area)) { + dev_priv->vgpu.pv_caps = 0; + writel(0, shared_area + vgtif_offset(pv_caps)); + return false; + } + return true; } diff --git a/drivers/gpu/drm/i915/i915_vgpu.h b/drivers/gpu/drm/i915/i915_vgpu.h index bbe56b5..401af24 100644 --- a/drivers/gpu/drm/i915/i915_vgpu.h +++ b/drivers/gpu/drm/i915/i915_vgpu.h @@ -27,7 +27,25 @@ #include "i915_drv.h" #include "i915_pvinfo.h" +#define PV_MAJOR 1 +#define PV_MINOR 0 + +/* + * A shared page(4KB) between gvt and VM, could be allocated by guest driver + * or a fixed location in PCI bar 0 region + */ +struct gvt_shared_page { + u16 ver_major; + u16 ver_minor; +}; + +struct i915_virtual_gpu_pv { + struct gvt_shared_page *shared_page; + bool enabled; +}; + void i915_detect_vgpu(struct drm_i915_private *dev_priv); +void i915_destroy_vgpu(struct drm_i915_private *dev_priv); bool intel_vgpu_has_full_ppgtt(struct drm_i915_private *dev_priv);