From patchwork Mon Apr 29 03:10:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Zhang X-Patchwork-Id: 10921095 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D6E9F912 for ; Mon, 29 Apr 2019 03:11:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C600028739 for ; Mon, 29 Apr 2019 03:11:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA20E2873D; Mon, 29 Apr 2019 03:11:26 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 4799F28739 for ; Mon, 29 Apr 2019 03:11:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D599C89124; Mon, 29 Apr 2019 03:11:25 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 043D189100; Mon, 29 Apr 2019 03:11:23 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Apr 2019 20:11:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,408,1549958400"; d="scan'208";a="146648192" Received: from xzhan34-mobl3.bj.intel.com ([10.238.154.121]) by fmsmga007.fm.intel.com with ESMTP; 28 Apr 2019 20:11:21 -0700 From: Xiaolin Zhang To: intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Date: Mon, 29 Apr 2019 11:10:51 +0800 Message-Id: <1556507458-24684-2-git-send-email-xiaolin.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> References: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> Subject: [Intel-gfx] [PATCH v5 1/8] drm/i915: introduced vgpu pv capability 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" X-Virus-Scanned: ClamAV using ClamSMTP pv capability for vgpu was introduced by pv_caps in struct i915_virtual_gpu and a new pv_caps register for host GVT was defined in struct vgt_if for vgpu pv optimization. both of them are used to control different feature pv optimization supported and implemented by both guest and host. These fields are default zero, no any pv feature enabled. it also adds VGT_CAPS_PV capability BIT for guest to check GVTg can support PV feature or not. v0: RFC, introudced enable_pvmmio module parameter. v1: addressed RFC comment to remove enable_pvmmio module parameter by pv capability check. v2: rebase v3: distinct pv caps from guest and host. renamed enable_pvmmio to pvmmio_caps which is used for host pv caps. v4: consolidated all pv related functons into a single file i915_vgpu.c and renamed pvmmio to pv_caps. v5: rebase Signed-off-by: Xiaolin Zhang --- drivers/gpu/drm/i915/i915_drv.h | 2 ++ drivers/gpu/drm/i915/i915_pvinfo.h | 5 ++++- drivers/gpu/drm/i915/i915_vgpu.c | 45 +++++++++++++++++++++++++++++++++++++- drivers/gpu/drm/i915/i915_vgpu.h | 8 +++++++ 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 5c77bf5..91a16b35 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -89,6 +89,7 @@ #include "i915_vma.h" #include "intel_gvt.h" +#include "i915_pvinfo.h" /* General customization: */ @@ -1242,6 +1243,7 @@ struct i915_frontbuffer_tracking { struct i915_virtual_gpu { bool active; u32 caps; + u32 pv_caps; }; /* used in computing the new watermarks state */ diff --git a/drivers/gpu/drm/i915/i915_pvinfo.h b/drivers/gpu/drm/i915/i915_pvinfo.h index 969e514..619305a 100644 --- a/drivers/gpu/drm/i915/i915_pvinfo.h +++ b/drivers/gpu/drm/i915/i915_pvinfo.h @@ -55,6 +55,7 @@ enum vgt_g2v_type { #define VGT_CAPS_FULL_PPGTT BIT(2) #define VGT_CAPS_HWSP_EMULATION BIT(3) #define VGT_CAPS_HUGE_GTT BIT(4) +#define VGT_CAPS_PV BIT(5) struct vgt_if { u64 magic; /* VGT_MAGIC */ @@ -107,7 +108,9 @@ struct vgt_if { u32 execlist_context_descriptor_lo; u32 execlist_context_descriptor_hi; - u32 rsv7[0x200 - 24]; /* pad to one page */ + u32 pv_caps; + + u32 rsv7[0x200 - 25]; /* pad to one page */ } __packed; #define vgtif_reg(x) \ diff --git a/drivers/gpu/drm/i915/i915_vgpu.c b/drivers/gpu/drm/i915/i915_vgpu.c index 94d3992..7329f5a 100644 --- a/drivers/gpu/drm/i915/i915_vgpu.c +++ b/drivers/gpu/drm/i915/i915_vgpu.c @@ -79,7 +79,14 @@ void i915_check_vgpu(struct drm_i915_private *dev_priv) dev_priv->vgpu.caps = __raw_uncore_read32(uncore, vgtif_reg(vgt_caps)); dev_priv->vgpu.active = true; - DRM_INFO("Virtual GPU for Intel GVT-g detected.\n"); + + if (!intel_vgpu_check_pv_caps(dev_priv)) { + DRM_INFO("Virtual GPU for Intel GVT-g detected.\n"); + return; + } + + DRM_INFO("Virtual GPU for Intel GVT-g detected with pv_caps 0x%x.\n", + dev_priv->vgpu.pv_caps); } bool intel_vgpu_has_full_ppgtt(struct drm_i915_private *dev_priv) @@ -274,3 +281,39 @@ int intel_vgt_balloon(struct drm_i915_private *dev_priv) DRM_ERROR("VGT balloon fail\n"); return ret; } + +/* + * i915 vgpu PV support for Linux + */ + +/** + * intel_vgpu_check_pv_caps - detect virtual GPU PV capabilities + * @dev_priv: i915 device private + * + * This function is called at the initialization stage, to detect VGPU + * PV capabilities + * + * If guest wants to enable pv_caps, it needs to config it explicitly + * through vgt_if interface from gvt layer. + */ +bool intel_vgpu_check_pv_caps(struct drm_i915_private *dev_priv) +{ + struct intel_uncore *uncore = &dev_priv->uncore; + u32 gvt_pvcaps; + u32 pvcaps; + + if (!intel_vgpu_has_pv_caps(dev_priv)) + return false; + + /* PV capability negotiation between PV guest and GVT */ + gvt_pvcaps = __raw_uncore_read32(uncore, vgtif_reg(pv_caps)); + pvcaps = dev_priv->vgpu.pv_caps & gvt_pvcaps; + dev_priv->vgpu.pv_caps = pvcaps; + + if (!pvcaps) + return false; + + __raw_uncore_write32(uncore, vgtif_reg(pv_caps), pvcaps); + + return true; +} diff --git a/drivers/gpu/drm/i915/i915_vgpu.h b/drivers/gpu/drm/i915/i915_vgpu.h index ebe1b7b..91010fc 100644 --- a/drivers/gpu/drm/i915/i915_vgpu.h +++ b/drivers/gpu/drm/i915/i915_vgpu.h @@ -42,7 +42,15 @@ intel_vgpu_has_huge_gtt(struct drm_i915_private *dev_priv) return dev_priv->vgpu.caps & VGT_CAPS_HUGE_GTT; } +static inline bool +intel_vgpu_has_pv_caps(struct drm_i915_private *dev_priv) +{ + return dev_priv->vgpu.caps & VGT_CAPS_PV; +} + int intel_vgt_balloon(struct drm_i915_private *dev_priv); void intel_vgt_deballoon(struct drm_i915_private *dev_priv); +/* i915 vgpu pv related functions */ +bool intel_vgpu_check_pv_caps(struct drm_i915_private *dev_priv); #endif /* _I915_VGPU_H_ */ From patchwork Mon Apr 29 03:10:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Zhang X-Patchwork-Id: 10921097 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C60A11395 for ; Mon, 29 Apr 2019 03:11:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5E2728739 for ; Mon, 29 Apr 2019 03:11:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA08A2873D; Mon, 29 Apr 2019 03:11:31 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 3DB2728739 for ; Mon, 29 Apr 2019 03:11:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BEE5E8911F; Mon, 29 Apr 2019 03:11:30 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7224C8911F; Mon, 29 Apr 2019 03:11:29 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Apr 2019 20:11:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,408,1549958400"; d="scan'208";a="146648210" Received: from xzhan34-mobl3.bj.intel.com ([10.238.154.121]) by fmsmga007.fm.intel.com with ESMTP; 28 Apr 2019 20:11:26 -0700 From: Xiaolin Zhang To: intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Date: Mon, 29 Apr 2019 11:10:52 +0800 Message-Id: <1556507458-24684-3-git-send-email-xiaolin.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> References: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> Subject: [Intel-gfx] [PATCH v5 2/8] 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Xiaolin Zhang --- drivers/gpu/drm/i915/i915_drv.h | 4 +++- drivers/gpu/drm/i915/i915_pvinfo.h | 5 ++++- drivers/gpu/drm/i915/i915_vgpu.c | 40 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_vgpu.h | 20 +++++++++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 91a16b35..acf9035 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -1244,7 +1244,9 @@ struct i915_virtual_gpu { bool active; u32 caps; u32 pv_caps; -}; + spinlock_t shared_page_lock[I915_NUM_ENGINES]; + struct gvt_shared_page *shared_page; +} __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 619305a..4657bf7 100644 --- a/drivers/gpu/drm/i915/i915_pvinfo.h +++ b/drivers/gpu/drm/i915/i915_pvinfo.h @@ -46,6 +46,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, }; @@ -110,7 +111,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_reg(x) \ diff --git a/drivers/gpu/drm/i915/i915_vgpu.c b/drivers/gpu/drm/i915/i915_vgpu.c index 7329f5a..da439b1 100644 --- a/drivers/gpu/drm/i915/i915_vgpu.c +++ b/drivers/gpu/drm/i915/i915_vgpu.c @@ -135,6 +135,9 @@ void intel_vgt_deballoon(struct drm_i915_private *dev_priv) for (i = 0; i < 4; i++) vgt_deballoon_space(&dev_priv->ggtt, &bl_info.space[i]); + + if (dev_priv->vgpu.shared_page) + free_page((unsigned long)dev_priv->vgpu.shared_page); } static int vgt_balloon_space(struct i915_ggtt *ggtt, @@ -286,6 +289,38 @@ int intel_vgt_balloon(struct drm_i915_private *dev_priv) * 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) +{ + struct intel_uncore *uncore = &dev_priv->uncore; + u64 gpa; + int i; + + dev_priv->vgpu.shared_page = (struct gvt_shared_page *) + get_zeroed_page(GFP_KERNEL); + if (!dev_priv->vgpu.shared_page) { + DRM_ERROR("out of memory for shared page memory\n"); + return -ENOMEM; + } + + /* pass guest memory pa address to GVT and then read back to verify */ + gpa = __pa(dev_priv->vgpu.shared_page); + __raw_uncore_write64(uncore, vgtif_reg(shared_page_gpa), gpa); + if (gpa != __raw_uncore_read64(uncore, vgtif_reg(shared_page_gpa))) { + DRM_ERROR("vgpu: passed shared_page_gpa failed\n"); + free_page((unsigned long)dev_priv->vgpu.shared_page); + return -EIO; + } + __raw_uncore_write32(uncore, vgtif_reg(g2v_notify), + VGT_G2V_SHARED_PAGE_SETUP); + for (i = 0; i < I915_NUM_ENGINES; i++) + spin_lock_init(&dev_priv->vgpu.shared_page_lock[i]); + + return 0; +} + /** * intel_vgpu_check_pv_caps - detect virtual GPU PV capabilities * @dev_priv: i915 device private @@ -313,6 +348,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)) { + dev_priv->vgpu.pv_caps = 0; + return false; + } + __raw_uncore_write32(uncore, vgtif_reg(pv_caps), pvcaps); return true; diff --git a/drivers/gpu/drm/i915/i915_vgpu.h b/drivers/gpu/drm/i915/i915_vgpu.h index 91010fc..697c426 100644 --- a/drivers/gpu/drm/i915/i915_vgpu.h +++ b/drivers/gpu/drm/i915/i915_vgpu.h @@ -26,6 +26,26 @@ #include "i915_pvinfo.h" +/* + * A shared page(4KB) between gvt and VM, could be allocated by guest driver + * or a fixed location in PCI bar 0 region + */ +struct pv_ppgtt_update { + u64 pdp; + u64 start; + u64 length; + u32 cache_level; +}; + +struct pv_submission { + u64 descs[EXECLIST_MAX_PORTS]; +}; + +struct gvt_shared_page { + struct pv_ppgtt_update pv_ppgtt; + struct pv_submission pv_elsp[I915_NUM_ENGINES]; +}; + void i915_check_vgpu(struct drm_i915_private *dev_priv); bool intel_vgpu_has_full_ppgtt(struct drm_i915_private *dev_priv); From patchwork Mon Apr 29 03:10:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Zhang X-Patchwork-Id: 10921099 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D5D461395 for ; Mon, 29 Apr 2019 03:11:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C313F28739 for ; Mon, 29 Apr 2019 03:11:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5B7E2873D; Mon, 29 Apr 2019 03:11:36 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 1BE3528739 for ; Mon, 29 Apr 2019 03:11:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B0E8A8912B; Mon, 29 Apr 2019 03:11:35 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 486BB89125; Mon, 29 Apr 2019 03:11:34 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Apr 2019 20:11:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,408,1549958400"; d="scan'208";a="146648222" Received: from xzhan34-mobl3.bj.intel.com ([10.238.154.121]) by fmsmga007.fm.intel.com with ESMTP; 28 Apr 2019 20:11:30 -0700 From: Xiaolin Zhang To: intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Date: Mon, 29 Apr 2019 11:10:53 +0800 Message-Id: <1556507458-24684-4-git-send-email-xiaolin.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> References: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> Subject: [Intel-gfx] [PATCH v5 3/8] drm/i915: vgpu ppgtt update 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" X-Virus-Scanned: ClamAV using ClamSMTP This patch extends vgpu ppgtt g2v notification to notify host GVT-g of ppgtt update from guest including alloc_4lvl, clear_4lv4 and insert_4lvl. These updates use the shared memory page to pass struct pv_ppgtt_update from guest to GVT which is used for pv optimiation implemeation within host GVT side. This patch also add one new pv_caps level to control ppgtt update. Use PV_PPGTT_UPDATE to control this level of pv optimization. v0: RFC v1: rebased v2: added pv callbacks for vm.{allocate_va_range, insert_entries, clear_range} within ppgtt. v3: rebased, disable huge page ppgtt support when using PVMMIO ppgtt update due to complex and performance impact. v4: moved alloc/insert/clear_4lvl pv callbacks into i915_vgpu_pv.c and added a single intel_vgpu_config_pv_caps() for vgpu pv callbacks setup. v5: rebase Signed-off-by: Xiaolin Zhang --- drivers/gpu/drm/i915/i915_gem.c | 3 +- drivers/gpu/drm/i915/i915_gem_gtt.c | 9 ++-- drivers/gpu/drm/i915/i915_gem_gtt.h | 8 ++++ drivers/gpu/drm/i915/i915_pvinfo.h | 3 ++ drivers/gpu/drm/i915/i915_vgpu.c | 84 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_vgpu.h | 17 ++++++++ 6 files changed, 120 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 54f27ca..3028807 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -4470,7 +4470,8 @@ int i915_gem_init(struct drm_i915_private *dev_priv) int ret; /* We need to fallback to 4K pages if host doesn't support huge gtt. */ - if (intel_vgpu_active(dev_priv) && !intel_vgpu_has_huge_gtt(dev_priv)) + if ((intel_vgpu_active(dev_priv) && !intel_vgpu_has_huge_gtt(dev_priv)) + || intel_vgpu_enabled_pv_caps(dev_priv, PV_PPGTT_UPDATE)) mkwrite_device_info(dev_priv)->page_sizes = I915_GTT_PAGE_SIZE_4K; diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c index 8f5db78..efb705d 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c @@ -922,7 +922,7 @@ static void gen8_ppgtt_set_pml4e(struct i915_pml4 *pml4, * This is the top-level structure in 4-level page tables used on gen8+. * Empty entries are always scratch pml4e. */ -static void gen8_ppgtt_clear_4lvl(struct i915_address_space *vm, +void gen8_ppgtt_clear_4lvl(struct i915_address_space *vm, u64 start, u64 length) { struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vm); @@ -1161,7 +1161,7 @@ static void gen8_ppgtt_insert_huge_entries(struct i915_vma *vma, } while (iter->sg); } -static void gen8_ppgtt_insert_4lvl(struct i915_address_space *vm, +void gen8_ppgtt_insert_4lvl(struct i915_address_space *vm, struct i915_vma *vma, enum i915_cache_level cache_level, u32 flags) @@ -1443,7 +1443,7 @@ static int gen8_ppgtt_alloc_3lvl(struct i915_address_space *vm, &i915_vm_to_ppgtt(vm)->pdp, start, length); } -static int gen8_ppgtt_alloc_4lvl(struct i915_address_space *vm, +int gen8_ppgtt_alloc_4lvl(struct i915_address_space *vm, u64 start, u64 length) { struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vm); @@ -1575,6 +1575,9 @@ static struct i915_hw_ppgtt *gen8_ppgtt_create(struct drm_i915_private *i915) ppgtt->vm.allocate_va_range = gen8_ppgtt_alloc_4lvl; ppgtt->vm.insert_entries = gen8_ppgtt_insert_4lvl; ppgtt->vm.clear_range = gen8_ppgtt_clear_4lvl; + + if (intel_vgpu_active(i915)) + intel_vgpu_config_pv_caps(i915, PV_PPGTT_UPDATE, ppgtt); } else { err = __pdp_init(&ppgtt->vm, &ppgtt->pdp); if (err) diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h index f85b75d..cccd1e5 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.h +++ b/drivers/gpu/drm/i915/i915_gem_gtt.h @@ -626,6 +626,14 @@ int gen6_ppgtt_pin(struct i915_hw_ppgtt *base); void gen6_ppgtt_unpin(struct i915_hw_ppgtt *base); void gen6_ppgtt_unpin_all(struct i915_hw_ppgtt *base); +void gen8_ppgtt_clear_4lvl(struct i915_address_space *vm, + u64 start, u64 length); +void gen8_ppgtt_insert_4lvl(struct i915_address_space *vm, + struct i915_vma *vma, + enum i915_cache_level cache_level, u32 flags); +int gen8_ppgtt_alloc_4lvl(struct i915_address_space *vm, + u64 start, u64 length); + void i915_check_and_clear_faults(struct drm_i915_private *dev_priv); void i915_gem_suspend_gtt_mappings(struct drm_i915_private *dev_priv); void i915_gem_restore_gtt_mappings(struct drm_i915_private *dev_priv); diff --git a/drivers/gpu/drm/i915/i915_pvinfo.h b/drivers/gpu/drm/i915/i915_pvinfo.h index 4657bf7..2408a9d 100644 --- a/drivers/gpu/drm/i915/i915_pvinfo.h +++ b/drivers/gpu/drm/i915/i915_pvinfo.h @@ -47,6 +47,9 @@ enum vgt_g2v_type { VGT_G2V_EXECLIST_CONTEXT_CREATE, VGT_G2V_EXECLIST_CONTEXT_DESTROY, VGT_G2V_SHARED_PAGE_SETUP, + VGT_G2V_PPGTT_L4_ALLOC, + VGT_G2V_PPGTT_L4_CLEAR, + VGT_G2V_PPGTT_L4_INSERT, VGT_G2V_MAX, }; diff --git a/drivers/gpu/drm/i915/i915_vgpu.c b/drivers/gpu/drm/i915/i915_vgpu.c index da439b1..23814cd 100644 --- a/drivers/gpu/drm/i915/i915_vgpu.c +++ b/drivers/gpu/drm/i915/i915_vgpu.c @@ -80,6 +80,9 @@ void i915_check_vgpu(struct drm_i915_private *dev_priv) dev_priv->vgpu.active = true; + /* guest driver PV capability */ + dev_priv->vgpu.pv_caps = PV_PPGTT_UPDATE; + if (!intel_vgpu_check_pv_caps(dev_priv)) { DRM_INFO("Virtual GPU for Intel GVT-g detected.\n"); return; @@ -289,6 +292,87 @@ int intel_vgt_balloon(struct drm_i915_private *dev_priv) * i915 vgpu PV support for Linux */ +static void gen8_ppgtt_clear_4lvl_pv(struct i915_address_space *vm, + u64 start, u64 length) +{ + struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vm); + struct i915_pml4 *pml4 = &ppgtt->pml4; + struct drm_i915_private *dev_priv = vm->i915; + struct pv_ppgtt_update *pv_ppgtt = + &dev_priv->vgpu.shared_page->pv_ppgtt; + u64 orig_start = start; + u64 orig_length = length; + + gen8_ppgtt_clear_4lvl(vm, start, length); + + pv_ppgtt->pdp = px_dma(pml4); + pv_ppgtt->start = orig_start; + pv_ppgtt->length = orig_length; + I915_WRITE(vgtif_reg(g2v_notify), VGT_G2V_PPGTT_L4_CLEAR); +} + +static void gen8_ppgtt_insert_4lvl_pv(struct i915_address_space *vm, + struct i915_vma *vma, + enum i915_cache_level cache_level, + u32 flags) +{ + struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vm); + struct drm_i915_private *dev_priv = vm->i915; + struct pv_ppgtt_update *pv_ppgtt = + &dev_priv->vgpu.shared_page->pv_ppgtt; + + gen8_ppgtt_insert_4lvl(vm, vma, cache_level, flags); + + pv_ppgtt->pdp = px_dma(&ppgtt->pml4); + pv_ppgtt->start = vma->node.start; + pv_ppgtt->length = vma->node.size; + pv_ppgtt->cache_level = cache_level; + I915_WRITE(vgtif_reg(g2v_notify), VGT_G2V_PPGTT_L4_INSERT); +} + +static int gen8_ppgtt_alloc_4lvl_pv(struct i915_address_space *vm, + u64 start, u64 length) +{ + struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vm); + struct i915_pml4 *pml4 = &ppgtt->pml4; + struct drm_i915_private *dev_priv = vm->i915; + struct pv_ppgtt_update *pv_ppgtt = + &dev_priv->vgpu.shared_page->pv_ppgtt; + int ret; + u64 orig_start = start; + u64 orig_length = length; + + ret = gen8_ppgtt_alloc_4lvl(vm, start, length); + if (ret) + return ret; + + pv_ppgtt->pdp = px_dma(pml4); + pv_ppgtt->start = orig_start; + pv_ppgtt->length = orig_length; + I915_WRITE(vgtif_reg(g2v_notify), VGT_G2V_PPGTT_L4_ALLOC); + + return 0; +} + +/* + * config guest driver PV ops for different PV features + */ +void intel_vgpu_config_pv_caps(struct drm_i915_private *dev_priv, + enum pv_caps cap, void *data) +{ + struct i915_hw_ppgtt *ppgtt; + + if (!intel_vgpu_enabled_pv_caps(dev_priv, cap)) + return; + + if (cap == PV_PPGTT_UPDATE) { + ppgtt = (struct i915_hw_ppgtt *)data; + ppgtt->vm.allocate_va_range = gen8_ppgtt_alloc_4lvl_pv; + ppgtt->vm.insert_entries = gen8_ppgtt_insert_4lvl_pv; + ppgtt->vm.clear_range = gen8_ppgtt_clear_4lvl_pv; + } +} + /* * shared_page setup for VGPU PV features */ diff --git a/drivers/gpu/drm/i915/i915_vgpu.h b/drivers/gpu/drm/i915/i915_vgpu.h index 697c426..6bce8a5 100644 --- a/drivers/gpu/drm/i915/i915_vgpu.h +++ b/drivers/gpu/drm/i915/i915_vgpu.h @@ -27,6 +27,13 @@ #include "i915_pvinfo.h" /* + * define different capabilities of PV optimization + */ +enum pv_caps { + PV_PPGTT_UPDATE = 0x1, +}; + +/* * A shared page(4KB) between gvt and VM, could be allocated by guest driver * or a fixed location in PCI bar 0 region */ @@ -68,9 +75,19 @@ intel_vgpu_has_pv_caps(struct drm_i915_private *dev_priv) return dev_priv->vgpu.caps & VGT_CAPS_PV; } +static inline bool +intel_vgpu_enabled_pv_caps(struct drm_i915_private *dev_priv, + enum pv_caps cap) +{ + return intel_vgpu_active(dev_priv) && intel_vgpu_has_pv_caps(dev_priv) + && (dev_priv->vgpu.pv_caps & cap); +} + int intel_vgt_balloon(struct drm_i915_private *dev_priv); void intel_vgt_deballoon(struct drm_i915_private *dev_priv); /* i915 vgpu pv related functions */ bool intel_vgpu_check_pv_caps(struct drm_i915_private *dev_priv); +void intel_vgpu_config_pv_caps(struct drm_i915_private *dev_priv, + enum pv_caps cap, void *data); #endif /* _I915_VGPU_H_ */ From patchwork Mon Apr 29 03:10:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xiaolin Zhang X-Patchwork-Id: 10921101 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9BCFC912 for ; Mon, 29 Apr 2019 03:11:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A33A28739 for ; Mon, 29 Apr 2019 03:11:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E29C2873D; Mon, 29 Apr 2019 03:11:41 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 CDF5A28739 for ; Mon, 29 Apr 2019 03:11:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 618D489142; Mon, 29 Apr 2019 03:11:40 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9812789142; Mon, 29 Apr 2019 03:11:37 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Apr 2019 20:11:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,408,1549958400"; d="scan'208";a="146648231" Received: from xzhan34-mobl3.bj.intel.com ([10.238.154.121]) by fmsmga007.fm.intel.com with ESMTP; 28 Apr 2019 20:11:35 -0700 From: Xiaolin Zhang To: intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Date: Mon, 29 Apr 2019 11:10:54 +0800 Message-Id: <1556507458-24684-5-git-send-email-xiaolin.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> References: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v5 4/8] drm/i915: vgpu context submission 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 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP It is performance optimization to override the actual submisison backend in order to eliminate execlists csb process and reduce mmio trap numbers for workload submission without context switch interrupt by talking with GVT via PV submisison notification mechanism between guest and GVT. Use PV_SUBMISSION to control this level of pv optimization. v0: RFC v1: rebase v2: added pv ops for pv context submission. to maximize code resuse, introduced 2 more ops (submit_ports & preempt_context) instead of 1 op (set_default_submission) in engine structure. pv version of submit_ports and preempt_context implemented. v3: 1. to reduce more code duplication, code refactor and replaced 2 ops "submit_ports & preempt_contex" from v2 by 1 ops "write_desc" in engine structure. pv version of write_des implemented. 2. added VGT_G2V_ELSP_SUBMIT for g2v pv notification. v4: implemented pv elsp submission tasklet as the backend workload submisison by talking to GVT with PV notificaiton mechanism and renamed VGT_G2V_ELSP_SUBMIT to VGT_G2V_PV_SUBMISIION. v5: addressed v4 comments from Chris, intel_pv_submission.c added. Signed-off-by: Xiaolin Zhang --- drivers/gpu/drm/i915/Makefile | 2 +- drivers/gpu/drm/i915/gt/intel_lrc.c | 8 +- drivers/gpu/drm/i915/i915_pvinfo.h | 1 + drivers/gpu/drm/i915/i915_vgpu.c | 8 +- drivers/gpu/drm/i915/i915_vgpu.h | 3 + drivers/gpu/drm/i915/intel_pv_submission.c | 177 +++++++++++++++++++++++++++++ 6 files changed, 195 insertions(+), 4 deletions(-) create mode 100644 drivers/gpu/drm/i915/intel_pv_submission.c diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile index dd8d923..27873c7 100644 --- a/drivers/gpu/drm/i915/Makefile +++ b/drivers/gpu/drm/i915/Makefile @@ -198,7 +198,7 @@ i915-$(CONFIG_DRM_I915_SELFTEST) += \ selftests/igt_spinner.o # virtual gpu code -i915-y += i915_vgpu.o +i915-y += i915_vgpu.o intel_pv_submission.o # perf code i915-y += i915_perf.o \ diff --git a/drivers/gpu/drm/i915/gt/intel_lrc.c b/drivers/gpu/drm/i915/gt/intel_lrc.c index d17c08e..d31a98b 100644 --- a/drivers/gpu/drm/i915/gt/intel_lrc.c +++ b/drivers/gpu/drm/i915/gt/intel_lrc.c @@ -2380,11 +2380,15 @@ void intel_execlists_set_default_submission(struct intel_engine_cs *engine) engine->unpark = NULL; engine->flags |= I915_ENGINE_SUPPORTS_STATS; - if (!intel_vgpu_active(engine->i915)) - engine->flags |= I915_ENGINE_HAS_SEMAPHORES; + engine->flags |= I915_ENGINE_HAS_SEMAPHORES; if (engine->preempt_context && HAS_LOGICAL_RING_PREEMPTION(engine->i915)) engine->flags |= I915_ENGINE_HAS_PREEMPTION; + + if (intel_vgpu_active(engine->i915)) { + engine->flags &= ~I915_ENGINE_HAS_SEMAPHORES; + intel_vgpu_config_pv_caps(engine->i915, PV_SUBMISSION, engine); + } } static void diff --git a/drivers/gpu/drm/i915/i915_pvinfo.h b/drivers/gpu/drm/i915/i915_pvinfo.h index 2408a9d..362d898 100644 --- a/drivers/gpu/drm/i915/i915_pvinfo.h +++ b/drivers/gpu/drm/i915/i915_pvinfo.h @@ -50,6 +50,7 @@ enum vgt_g2v_type { VGT_G2V_PPGTT_L4_ALLOC, VGT_G2V_PPGTT_L4_CLEAR, VGT_G2V_PPGTT_L4_INSERT, + VGT_G2V_PV_SUBMISSION, VGT_G2V_MAX, }; diff --git a/drivers/gpu/drm/i915/i915_vgpu.c b/drivers/gpu/drm/i915/i915_vgpu.c index 23814cd..8dea0b7 100644 --- a/drivers/gpu/drm/i915/i915_vgpu.c +++ b/drivers/gpu/drm/i915/i915_vgpu.c @@ -81,7 +81,7 @@ void i915_check_vgpu(struct drm_i915_private *dev_priv) dev_priv->vgpu.active = true; /* guest driver PV capability */ - dev_priv->vgpu.pv_caps = PV_PPGTT_UPDATE; + dev_priv->vgpu.pv_caps = PV_PPGTT_UPDATE | PV_SUBMISSION; if (!intel_vgpu_check_pv_caps(dev_priv)) { DRM_INFO("Virtual GPU for Intel GVT-g detected.\n"); @@ -361,6 +361,7 @@ void intel_vgpu_config_pv_caps(struct drm_i915_private *dev_priv, enum pv_caps cap, void *data) { struct i915_hw_ppgtt *ppgtt; + struct intel_engine_cs *engine; if (!intel_vgpu_enabled_pv_caps(dev_priv, cap)) return; @@ -371,6 +372,11 @@ void intel_vgpu_config_pv_caps(struct drm_i915_private *dev_priv, ppgtt->vm.insert_entries = gen8_ppgtt_insert_4lvl_pv; ppgtt->vm.clear_range = gen8_ppgtt_clear_4lvl_pv; } + + if (cap == PV_SUBMISSION) { + engine = (struct intel_engine_cs *)data; + vgpu_set_pv_submission(engine); + } } /* diff --git a/drivers/gpu/drm/i915/i915_vgpu.h b/drivers/gpu/drm/i915/i915_vgpu.h index 6bce8a5..f4e8a1e 100644 --- a/drivers/gpu/drm/i915/i915_vgpu.h +++ b/drivers/gpu/drm/i915/i915_vgpu.h @@ -31,6 +31,7 @@ */ enum pv_caps { PV_PPGTT_UPDATE = 0x1, + PV_SUBMISSION = 0x2, }; /* @@ -90,4 +91,6 @@ void intel_vgt_deballoon(struct drm_i915_private *dev_priv); bool intel_vgpu_check_pv_caps(struct drm_i915_private *dev_priv); void intel_vgpu_config_pv_caps(struct drm_i915_private *dev_priv, enum pv_caps cap, void *data); +void vgpu_set_pv_submission(struct intel_engine_cs *engine); + #endif /* _I915_VGPU_H_ */ diff --git a/drivers/gpu/drm/i915/intel_pv_submission.c b/drivers/gpu/drm/i915/intel_pv_submission.c new file mode 100644 index 0000000..3ba9c82 --- /dev/null +++ b/drivers/gpu/drm/i915/intel_pv_submission.c @@ -0,0 +1,177 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright © 2018 Intel Corporation + */ + +#include "intel_drv.h" +#include "i915_vgpu.h" +#include "gt/intel_lrc_reg.h" + +static u64 execlists_update_context(struct i915_request *rq) +{ + struct intel_context *ce = rq->hw_context; + u32 *reg_state = ce->lrc_reg_state; + + reg_state[CTX_RING_TAIL+1] = intel_ring_set_tail(rq->ring, rq->tail); + + return ce->lrc_desc; +} + +static inline struct i915_priolist *to_priolist(struct rb_node *rb) +{ + return rb_entry(rb, struct i915_priolist, node); +} + +static void pv_submit(struct intel_engine_cs *engine) +{ + struct intel_engine_execlists * const execlists = &engine->execlists; + struct execlist_port *port = execlists->port; + unsigned int n; + struct gvt_shared_page *shared_page = engine->i915->vgpu.shared_page; + u64 descs[2]; + + for (n = 0; n < execlists_num_ports(execlists); n++) { + struct i915_request *rq; + unsigned int count = 0; + + descs[n] = 0; + rq = port_unpack(&port[n], &count); + if (rq && count == 0) { + port_set(&port[n], port_pack(rq, ++count)); + descs[n] = execlists_update_context(rq); + } + } + + spin_lock(&engine->i915->vgpu.shared_page_lock[engine->id]); + for (n = 0; n < execlists_num_ports(execlists); n++) + shared_page->pv_elsp[engine->id].descs[n] = descs[n]; + + writel(VGT_G2V_PV_SUBMISSION, execlists->submit_reg); + spin_unlock(&engine->i915->vgpu.shared_page_lock[engine->id]); +} + +static inline int rq_prio(const struct i915_request *rq) +{ + return rq->sched.attr.priority; +} + +static inline int port_prio(const struct execlist_port *port) +{ + return rq_prio(port_request(port)) | __NO_PREEMPTION; +} + +static void pv_dequeue(struct intel_engine_cs *engine) +{ + struct intel_engine_execlists * const execlists = &engine->execlists; + struct execlist_port *port = execlists->port; + struct i915_request *last = NULL; + bool submit = false; + struct rb_node *rb; + + lockdep_assert_held(&engine->timeline.lock); + + while ((rb = rb_first_cached(&execlists->queue))) { + struct i915_priolist *p = to_priolist(rb); + struct i915_request *rq, *rn; + int i; + + priolist_for_each_request_consume(rq, rn, p, i) { + if (last && rq->hw_context != last->hw_context) + goto done; + + list_del_init(&rq->sched.link); + + __i915_request_submit(rq); + trace_i915_request_in(rq, port_index(port, execlists)); + + last = rq; + submit = true; + } + + rb_erase_cached(&p->node, &execlists->queue); + i915_priolist_free(p); + } +done: + execlists->queue_priority_hint = + rb ? to_priolist(rb)->priority : INT_MIN; + if (submit) { + port_set(port, i915_request_get(last)); + pv_submit(engine); + } + if (last) + execlists_user_begin(execlists, execlists->port); + + /* We must always keep the beast fed if we have work piled up */ + GEM_BUG_ON(port_isset(execlists->port) && + !execlists_is_active(execlists, EXECLISTS_ACTIVE_USER)); + GEM_BUG_ON(rb_first_cached(&execlists->queue) && + !port_isset(execlists->port)); +} + +static void vgpu_pv_submission_tasklet(unsigned long data) +{ + struct intel_engine_cs * const engine = (struct intel_engine_cs *)data; + struct intel_engine_execlists * const execlists = &engine->execlists; + struct execlist_port *port = execlists->port; + struct i915_request *rq; + unsigned long flags; + bool rq_finished = false; + + spin_lock_irqsave(&engine->timeline.lock, flags); + + rq = port_request(port); + while (rq && i915_request_completed(rq)) { + trace_i915_request_out(rq); + rq_finished = true; + i915_request_put(rq); + + port = execlists_port_complete(execlists, port); + if (port_isset(port)) { + rq_finished = false; + execlists_user_begin(execlists, port); + rq = port_request(port); + } else { + execlists_user_end(execlists); + rq = NULL; + } + } + + if (rq_finished || !rq) + pv_dequeue(engine); + + spin_unlock_irqrestore(&engine->timeline.lock, flags); +} + +static void vgpu_pv_submission_park(struct intel_engine_cs *engine) +{ + intel_engine_unpin_breadcrumbs_irq(engine); + engine->flags &= ~I915_ENGINE_NEEDS_BREADCRUMB_TASKLET; +} + +static void vgpu_pv_submission_unpark(struct intel_engine_cs *engine) +{ + engine->flags |= I915_ENGINE_NEEDS_BREADCRUMB_TASKLET; + intel_engine_pin_breadcrumbs_irq(engine); +} + +void vgpu_set_pv_submission(struct intel_engine_cs *engine) +{ + /* + * We inherit a bunch of functions from execlists that we'd like + * to keep using: + * + * engine->submit_request = execlists_submit_request; + * engine->cancel_requests = execlists_cancel_requests; + * engine->schedule = execlists_schedule; + * + * But we need to override the actual submission backend in order + * to talk to the GVT with PV notification message. + */ + + engine->execlists.tasklet.func = vgpu_pv_submission_tasklet; + + engine->park = vgpu_pv_submission_park; + engine->unpark = vgpu_pv_submission_unpark; + + engine->flags &= ~I915_ENGINE_HAS_PREEMPTION; +} From patchwork Mon Apr 29 03:10:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Zhang X-Patchwork-Id: 10921103 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06DCE1395 for ; Mon, 29 Apr 2019 03:11:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB1F528739 for ; Mon, 29 Apr 2019 03:11:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFAFA2873D; Mon, 29 Apr 2019 03:11:43 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 91A4628739 for ; Mon, 29 Apr 2019 03:11:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1D77F89141; Mon, 29 Apr 2019 03:11:43 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 92D3389141; Mon, 29 Apr 2019 03:11:41 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Apr 2019 20:11:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,408,1549958400"; d="scan'208";a="146648244" Received: from xzhan34-mobl3.bj.intel.com ([10.238.154.121]) by fmsmga007.fm.intel.com with ESMTP; 28 Apr 2019 20:11:38 -0700 From: Xiaolin Zhang To: intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Date: Mon, 29 Apr 2019 11:10:55 +0800 Message-Id: <1556507458-24684-6-git-send-email-xiaolin.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> References: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> Subject: [Intel-gfx] [PATCH v5 5/8] drm/i915/gvt: GVTg handle pv_caps PVINFO register 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" X-Virus-Scanned: ClamAV using ClamSMTP implement pv_caps PVINFO register handler in GVTg to control different level pv optimization within guest. report VGT_CAPS_PV capability in pvinfo page for guest. v0: RFC v1: rebase v2: rebase v3: renamed enable_pvmmio to pvmmio_caps which is used for host pv caps. v4: renamed pvmmio_caps to pv_caps v5: rebase Signed-off-by: Xiaolin Zhang --- drivers/gpu/drm/i915/gvt/handlers.c | 4 ++++ drivers/gpu/drm/i915/gvt/vgpu.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/drivers/gpu/drm/i915/gvt/handlers.c b/drivers/gpu/drm/i915/gvt/handlers.c index 18f01ee..f7ecd4e 100644 --- a/drivers/gpu/drm/i915/gvt/handlers.c +++ b/drivers/gpu/drm/i915/gvt/handlers.c @@ -1192,6 +1192,7 @@ static int pvinfo_mmio_read(struct intel_vgpu *vgpu, unsigned int offset, break; case 0x78010: /* vgt_caps */ case 0x7881c: + case _vgtif_reg(pv_caps): break; default: invalid_read = true; @@ -1265,6 +1266,9 @@ static int pvinfo_mmio_write(struct intel_vgpu *vgpu, unsigned int offset, case _vgtif_reg(g2v_notify): ret = handle_g2v_notification(vgpu, data); break; + case _vgtif_reg(pv_caps): + DRM_INFO("vgpu id=%d pv caps =0x%x\n", vgpu->id, data); + break; /* add xhot and yhot to handled list to avoid error log */ case _vgtif_reg(cursor_x_hot): case _vgtif_reg(cursor_y_hot): diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c index 44ce3c2..3ecc45a 100644 --- a/drivers/gpu/drm/i915/gvt/vgpu.c +++ b/drivers/gpu/drm/i915/gvt/vgpu.c @@ -47,6 +47,7 @@ void populate_pvinfo_page(struct intel_vgpu *vgpu) vgpu_vreg_t(vgpu, vgtif_reg(vgt_caps)) = VGT_CAPS_FULL_PPGTT; vgpu_vreg_t(vgpu, vgtif_reg(vgt_caps)) |= VGT_CAPS_HWSP_EMULATION; vgpu_vreg_t(vgpu, vgtif_reg(vgt_caps)) |= VGT_CAPS_HUGE_GTT; + vgpu_vreg_t(vgpu, vgtif_reg(vgt_caps)) |= VGT_CAPS_PV; vgpu_vreg_t(vgpu, vgtif_reg(avail_rs.mappable_gmadr.base)) = vgpu_aperture_gmadr_base(vgpu); @@ -531,6 +532,7 @@ void intel_gvt_reset_vgpu_locked(struct intel_vgpu *vgpu, bool dmlr, struct intel_gvt *gvt = vgpu->gvt; struct intel_gvt_workload_scheduler *scheduler = &gvt->scheduler; intel_engine_mask_t resetting_eng = dmlr ? ALL_ENGINES : engine_mask; + int pv_caps = vgpu_vreg_t(vgpu, vgtif_reg(pv_caps)); gvt_dbg_core("------------------------------------------\n"); gvt_dbg_core("resseting vgpu%d, dmlr %d, engine_mask %08x\n", @@ -562,6 +564,7 @@ void intel_gvt_reset_vgpu_locked(struct intel_vgpu *vgpu, bool dmlr, intel_vgpu_reset_mmio(vgpu, dmlr); populate_pvinfo_page(vgpu); + vgpu_vreg_t(vgpu, vgtif_reg(pv_caps)) = pv_caps; intel_vgpu_reset_display(vgpu); if (dmlr) { From patchwork Mon Apr 29 03:10:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Zhang X-Patchwork-Id: 10921105 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 74DF31395 for ; Mon, 29 Apr 2019 03:11:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64DE128739 for ; Mon, 29 Apr 2019 03:11:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 595CF2873D; Mon, 29 Apr 2019 03:11:48 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 E7F6028739 for ; Mon, 29 Apr 2019 03:11:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 72F9489139; Mon, 29 Apr 2019 03:11:47 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 03A7189150; Mon, 29 Apr 2019 03:11:45 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Apr 2019 20:11:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,408,1549958400"; d="scan'208";a="146648254" Received: from xzhan34-mobl3.bj.intel.com ([10.238.154.121]) by fmsmga007.fm.intel.com with ESMTP; 28 Apr 2019 20:11:42 -0700 From: Xiaolin Zhang To: intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Date: Mon, 29 Apr 2019 11:10:56 +0800 Message-Id: <1556507458-24684-7-git-send-email-xiaolin.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> References: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> Subject: [Intel-gfx] [PATCH v5 6/8] drm/i915/gvt: GVTg handle shared_page setup 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" X-Virus-Scanned: ClamAV using ClamSMTP GVTg implemented shared_page setup operation and read_shared_page functionality based on hypervisor_read_gpa(). the shared_page_gpa was passed from guest driver through PVINFO shared_page_gpa register. v0: RFC v1: rebase v2: rebase v3: added shared_page_gpa check and if read_gpa failure, return zero memory and handle VGT_G2V_SHARED_PAGE_SETUP g2v notification v4: rebase v5: rebase Signed-off-by: Xiaolin Zhang --- drivers/gpu/drm/i915/gvt/gvt.h | 6 +++++- drivers/gpu/drm/i915/gvt/handlers.c | 15 +++++++++++++++ drivers/gpu/drm/i915/gvt/vgpu.c | 24 ++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h index f5a328b..6dbe30b 100644 --- a/drivers/gpu/drm/i915/gvt/gvt.h +++ b/drivers/gpu/drm/i915/gvt/gvt.h @@ -49,6 +49,7 @@ #include "fb_decoder.h" #include "dmabuf.h" #include "page_track.h" +#include "i915_vgpu.h" #define GVT_MAX_VGPU 8 @@ -229,6 +230,8 @@ struct intel_vgpu { struct completion vblank_done; u32 scan_nonprivbb; + u64 shared_page_gpa; + bool shared_page_enabled; }; /* validating GM healthy status*/ @@ -686,7 +689,8 @@ int intel_gvt_debugfs_add_vgpu(struct intel_vgpu *vgpu); void intel_gvt_debugfs_remove_vgpu(struct intel_vgpu *vgpu); int intel_gvt_debugfs_init(struct intel_gvt *gvt); void intel_gvt_debugfs_clean(struct intel_gvt *gvt); - +int intel_gvt_read_shared_page(struct intel_vgpu *vgpu, + unsigned int offset, void *buf, unsigned long len); #include "trace.h" #include "mpt.h" diff --git a/drivers/gpu/drm/i915/gvt/handlers.c b/drivers/gpu/drm/i915/gvt/handlers.c index f7ecd4e..3f94263 100644 --- a/drivers/gpu/drm/i915/gvt/handlers.c +++ b/drivers/gpu/drm/i915/gvt/handlers.c @@ -1193,6 +1193,8 @@ static int pvinfo_mmio_read(struct intel_vgpu *vgpu, unsigned int offset, case 0x78010: /* vgt_caps */ case 0x7881c: case _vgtif_reg(pv_caps): + case _vgtif_reg(shared_page_gpa): + case _vgtif_reg(shared_page_gpa) + 4: break; default: invalid_read = true; @@ -1210,6 +1212,7 @@ static int handle_g2v_notification(struct intel_vgpu *vgpu, int notification) intel_gvt_gtt_type_t root_entry_type = GTT_TYPE_PPGTT_ROOT_L4_ENTRY; struct intel_vgpu_mm *mm; u64 *pdps; + unsigned long gpa, gfn; pdps = (u64 *)&vgpu_vreg64_t(vgpu, vgtif_reg(pdp[0])); @@ -1223,6 +1226,16 @@ static int handle_g2v_notification(struct intel_vgpu *vgpu, int notification) case VGT_G2V_PPGTT_L3_PAGE_TABLE_DESTROY: case VGT_G2V_PPGTT_L4_PAGE_TABLE_DESTROY: return intel_vgpu_put_ppgtt_mm(vgpu, pdps); + case VGT_G2V_SHARED_PAGE_SETUP: + gpa = vgpu_vreg64_t(vgpu, vgtif_reg(shared_page_gpa)); + gfn = gpa >> PAGE_SHIFT; + if (!intel_gvt_hypervisor_is_valid_gfn(vgpu, gfn)) { + vgpu_vreg_t(vgpu, vgtif_reg(pv_caps)) = 0; + return 0; + } + vgpu->shared_page_gpa = gpa; + vgpu->shared_page_enabled = true; + break; case VGT_G2V_EXECLIST_CONTEXT_CREATE: case VGT_G2V_EXECLIST_CONTEXT_DESTROY: case 1: /* Remove this in guest driver. */ @@ -1282,6 +1295,8 @@ static int pvinfo_mmio_write(struct intel_vgpu *vgpu, unsigned int offset, case _vgtif_reg(pdp[3].hi): case _vgtif_reg(execlist_context_descriptor_lo): case _vgtif_reg(execlist_context_descriptor_hi): + case _vgtif_reg(shared_page_gpa): + case _vgtif_reg(shared_page_gpa) + 4: break; case _vgtif_reg(rsv5[0])..._vgtif_reg(rsv5[3]): enter_failsafe_mode(vgpu, GVT_FAILSAFE_INSUFFICIENT_RESOURCE); diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c index 3ecc45a..0663b3e 100644 --- a/drivers/gpu/drm/i915/gvt/vgpu.c +++ b/drivers/gpu/drm/i915/gvt/vgpu.c @@ -63,6 +63,8 @@ void populate_pvinfo_page(struct intel_vgpu *vgpu) vgpu_vreg_t(vgpu, vgtif_reg(cursor_x_hot)) = UINT_MAX; vgpu_vreg_t(vgpu, vgtif_reg(cursor_y_hot)) = UINT_MAX; + vgpu_vreg64_t(vgpu, vgtif_reg(shared_page_gpa)) = 0; + gvt_dbg_core("Populate PVINFO PAGE for vGPU %d\n", vgpu->id); gvt_dbg_core("aperture base [GMADR] 0x%llx size 0x%llx\n", vgpu_aperture_gmadr_base(vgpu), vgpu_aperture_sz(vgpu)); @@ -593,3 +595,25 @@ void intel_gvt_reset_vgpu(struct intel_vgpu *vgpu) intel_gvt_reset_vgpu_locked(vgpu, true, 0); mutex_unlock(&vgpu->vgpu_lock); } + +/** + * intel_gvt_read_shared_page - read content from shared page + */ +int intel_gvt_read_shared_page(struct intel_vgpu *vgpu, + unsigned int offset, void *buf, unsigned long len) +{ + int ret = -EINVAL; + unsigned long gpa; + + if (offset >= sizeof(struct gvt_shared_page)) + goto err; + + gpa = vgpu->shared_page_gpa + offset; + ret = intel_gvt_hypervisor_read_gpa(vgpu, gpa, buf, len); + if (!ret) + return ret; +err: + gvt_vgpu_err("read shared page (offset %x) failed", offset); + memset(buf, 0, len); + return ret; +} From patchwork Mon Apr 29 03:10:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Zhang X-Patchwork-Id: 10921107 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DF448912 for ; Mon, 29 Apr 2019 03:11:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDDE328739 for ; Mon, 29 Apr 2019 03:11:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C25642873D; Mon, 29 Apr 2019 03:11:52 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 DDE4F28739 for ; Mon, 29 Apr 2019 03:11:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6FE3089150; Mon, 29 Apr 2019 03:11:51 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7DF9989160; Mon, 29 Apr 2019 03:11:49 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Apr 2019 20:11:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,408,1549958400"; d="scan'208";a="146648268" Received: from xzhan34-mobl3.bj.intel.com ([10.238.154.121]) by fmsmga007.fm.intel.com with ESMTP; 28 Apr 2019 20:11:47 -0700 From: Xiaolin Zhang To: intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Date: Mon, 29 Apr 2019 11:10:57 +0800 Message-Id: <1556507458-24684-8-git-send-email-xiaolin.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> References: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> Subject: [Intel-gfx] [PATCH v5 7/8] drm/i915/gvt: GVTg support ppgtt 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" X-Virus-Scanned: ClamAV using ClamSMTP This patch handles ppgtt update from g2v notification. It read out ppgtt pte entries from guest pte tables page and convert them to host pfns. It creates local ppgtt tables and insert the content pages into the local ppgtt tables directly, which does not track the usage of guest page table and removes the cost of write protection from the original shadow page mechansim. v0: RFC v1: rebase v2: rebase v3: report pv pggtt cap to guest v4: renamed VGPU_PVMMIO with VGPU_PVCAP for name consistance, no PV support if gfx vtd enabled. v5: rebase Signed-off-by: Xiaolin Zhang --- drivers/gpu/drm/i915/gvt/gtt.c | 317 ++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/gvt/gtt.h | 9 + drivers/gpu/drm/i915/gvt/gvt.h | 4 + drivers/gpu/drm/i915/gvt/handlers.c | 12 +- drivers/gpu/drm/i915/gvt/vgpu.c | 3 + 5 files changed, 344 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c index c2f7d20..52a0042 100644 --- a/drivers/gpu/drm/i915/gvt/gtt.c +++ b/drivers/gpu/drm/i915/gvt/gtt.c @@ -1750,6 +1750,25 @@ static int ppgtt_handle_guest_write_page_table_bytes( return 0; } +static void invalidate_mm_pv(struct intel_vgpu_mm *mm) +{ + struct intel_vgpu *vgpu = mm->vgpu; + struct intel_gvt *gvt = vgpu->gvt; + struct intel_gvt_gtt *gtt = &gvt->gtt; + struct intel_gvt_gtt_pte_ops *ops = gtt->pte_ops; + struct intel_gvt_gtt_entry se; + + i915_ppgtt_put(mm->ppgtt); + + ppgtt_get_shadow_root_entry(mm, &se, 0); + if (!ops->test_present(&se)) + return; + se.val64 = 0; + ppgtt_set_shadow_root_entry(mm, &se, 0); + + mm->ppgtt_mm.shadowed = false; +} + static void invalidate_ppgtt_mm(struct intel_vgpu_mm *mm) { struct intel_vgpu *vgpu = mm->vgpu; @@ -1762,6 +1781,11 @@ static void invalidate_ppgtt_mm(struct intel_vgpu_mm *mm) if (!mm->ppgtt_mm.shadowed) return; + if (VGPU_PVCAP(mm->vgpu, PV_PPGTT_UPDATE)) { + invalidate_mm_pv(mm); + return; + } + for (index = 0; index < ARRAY_SIZE(mm->ppgtt_mm.shadow_pdps); index++) { ppgtt_get_shadow_root_entry(mm, &se, index); @@ -1779,6 +1803,26 @@ static void invalidate_ppgtt_mm(struct intel_vgpu_mm *mm) mm->ppgtt_mm.shadowed = false; } +static int shadow_mm_pv(struct intel_vgpu_mm *mm) +{ + struct intel_vgpu *vgpu = mm->vgpu; + struct intel_gvt *gvt = vgpu->gvt; + struct intel_gvt_gtt_entry se; + + mm->ppgtt = i915_ppgtt_create(gvt->dev_priv); + if (IS_ERR(mm->ppgtt)) { + gvt_vgpu_err("fail to create ppgtt for pdp 0x%llx\n", + px_dma(&mm->ppgtt->pml4)); + return PTR_ERR(mm->ppgtt); + } + + se.type = GTT_TYPE_PPGTT_ROOT_L4_ENTRY; + se.val64 = px_dma(&mm->ppgtt->pml4); + ppgtt_set_shadow_root_entry(mm, &se, 0); + mm->ppgtt_mm.shadowed = true; + + return 0; +} static int shadow_ppgtt_mm(struct intel_vgpu_mm *mm) { @@ -1793,6 +1837,9 @@ static int shadow_ppgtt_mm(struct intel_vgpu_mm *mm) if (mm->ppgtt_mm.shadowed) return 0; + if (VGPU_PVCAP(mm->vgpu, PV_PPGTT_UPDATE)) + return shadow_mm_pv(mm); + mm->ppgtt_mm.shadowed = true; for (index = 0; index < ARRAY_SIZE(mm->ppgtt_mm.guest_pdps); index++) { @@ -2793,3 +2840,273 @@ void intel_vgpu_reset_gtt(struct intel_vgpu *vgpu) intel_vgpu_destroy_all_ppgtt_mm(vgpu); intel_vgpu_reset_ggtt(vgpu, true); } + +int intel_vgpu_g2v_pv_ppgtt_alloc_4lvl(struct intel_vgpu *vgpu, + u64 pdps[]) +{ + struct intel_vgpu_mm *mm; + int ret = 0; + u32 offset; + struct pv_ppgtt_update pv_ppgtt; + + offset = offsetof(struct gvt_shared_page, pv_ppgtt); + intel_gvt_read_shared_page(vgpu, offset, &pv_ppgtt, sizeof(pv_ppgtt)); + + mm = intel_vgpu_find_ppgtt_mm(vgpu, &pv_ppgtt.pdp); + if (!mm) { + gvt_vgpu_err("failed to find pdp 0x%llx\n", pv_ppgtt.pdp); + ret = -EINVAL; + } else { + ret = mm->ppgtt->vm.allocate_va_range(&mm->ppgtt->vm, + pv_ppgtt.start, pv_ppgtt.length); + if (ret) + gvt_vgpu_err("failed to alloc %llx\n", pv_ppgtt.pdp); + } + + return ret; +} + +int intel_vgpu_g2v_pv_ppgtt_clear_4lvl(struct intel_vgpu *vgpu, + u64 pdps[]) +{ + struct intel_vgpu_mm *mm; + int ret = 0; + u32 offset; + struct pv_ppgtt_update pv_ppgtt; + + offset = offsetof(struct gvt_shared_page, pv_ppgtt); + intel_gvt_read_shared_page(vgpu, offset, &pv_ppgtt, sizeof(pv_ppgtt)); + mm = intel_vgpu_find_ppgtt_mm(vgpu, &pv_ppgtt.pdp); + if (!mm) { + gvt_vgpu_err("failed to find pdp 0x%llx\n", pv_ppgtt.pdp); + ret = -EINVAL; + } else { + mm->ppgtt->vm.clear_range(&mm->ppgtt->vm, + pv_ppgtt.start, pv_ppgtt.length); + } + + return ret; +} + +#define GEN8_PML4E_SIZE (1UL << GEN8_PML4E_SHIFT) +#define GEN8_PML4E_SIZE_MASK (~(GEN8_PML4E_SIZE - 1)) +#define GEN8_PDPE_SIZE (1UL << GEN8_PDPE_SHIFT) +#define GEN8_PDPE_SIZE_MASK (~(GEN8_PDPE_SIZE - 1)) +#define GEN8_PDE_SIZE (1UL << GEN8_PDE_SHIFT) +#define GEN8_PDE_SIZE_MASK (~(GEN8_PDE_SIZE - 1)) + +#define pml4_addr_end(addr, end) \ +({ unsigned long __boundary = \ + ((addr) + GEN8_PML4E_SIZE) & GEN8_PML4E_SIZE_MASK; \ + (__boundary < (end)) ? __boundary : (end); \ +}) + +#define pdp_addr_end(addr, end) \ +({ unsigned long __boundary = \ + ((addr) + GEN8_PDPE_SIZE) & GEN8_PDPE_SIZE_MASK; \ + (__boundary < (end)) ? __boundary : (end); \ +}) + +#define pd_addr_end(addr, end) \ +({ unsigned long __boundary = \ + ((addr) + GEN8_PDE_SIZE) & GEN8_PDE_SIZE_MASK; \ + (__boundary < (end)) ? __boundary : (end); \ +}) + +struct ppgtt_walk { + unsigned long *mfns; + int mfn_index; + unsigned long *pt; +}; + +static int walk_pt_range(struct intel_vgpu *vgpu, u64 pt, + u64 start, u64 end, struct ppgtt_walk *walk) +{ + const struct intel_gvt_device_info *info = &vgpu->gvt->device_info; + struct intel_gvt_gtt_gma_ops *gma_ops = vgpu->gvt->gtt.gma_ops; + unsigned long start_index, end_index; + int ret; + int i; + unsigned long mfn, gfn; + + start_index = gma_ops->gma_to_pte_index(start); + end_index = ((end - start) >> PAGE_SHIFT) + start_index; + + ret = intel_gvt_hypervisor_read_gpa(vgpu, + (pt & PAGE_MASK) + (start_index << info->gtt_entry_size_shift), + walk->pt + start_index, + (end_index - start_index) << info->gtt_entry_size_shift); + if (ret) { + gvt_vgpu_err("fail to read gpa %llx\n", pt); + return ret; + } + + for (i = start_index; i < end_index; i++) { + gfn = walk->pt[i] >> PAGE_SHIFT; + mfn = intel_gvt_hypervisor_gfn_to_mfn(vgpu, gfn); + if (mfn == INTEL_GVT_INVALID_ADDR) { + gvt_vgpu_err("fail to translate gfn: 0x%lx\n", gfn); + return -ENXIO; + } + walk->mfns[walk->mfn_index++] = mfn << PAGE_SHIFT; + } + + return 0; +} + + +static int walk_pd_range(struct intel_vgpu *vgpu, u64 pd, + u64 start, u64 end, struct ppgtt_walk *walk) +{ + const struct intel_gvt_device_info *info = &vgpu->gvt->device_info; + struct intel_gvt_gtt_gma_ops *gma_ops = vgpu->gvt->gtt.gma_ops; + unsigned long index; + u64 pt, next; + int ret = 0; + + do { + index = gma_ops->gma_to_pde_index(start); + + ret = intel_gvt_hypervisor_read_gpa(vgpu, + (pd & PAGE_MASK) + (index << + info->gtt_entry_size_shift), &pt, 8); + if (ret) + return ret; + next = pd_addr_end(start, end); + walk_pt_range(vgpu, pt, start, next, walk); + + start = next; + } while (start != end); + + return ret; +} + + +static int walk_pdp_range(struct intel_vgpu *vgpu, u64 pdp, + u64 start, u64 end, struct ppgtt_walk *walk) +{ + const struct intel_gvt_device_info *info = &vgpu->gvt->device_info; + struct intel_gvt_gtt_gma_ops *gma_ops = vgpu->gvt->gtt.gma_ops; + unsigned long index; + u64 pd, next; + int ret = 0; + + do { + index = gma_ops->gma_to_l4_pdp_index(start); + + ret = intel_gvt_hypervisor_read_gpa(vgpu, + (pdp & PAGE_MASK) + (index << + info->gtt_entry_size_shift), &pd, 8); + if (ret) + return ret; + next = pdp_addr_end(start, end); + walk_pd_range(vgpu, pd, start, next, walk); + start = next; + } while (start != end); + + return ret; +} + + +static int walk_pml4_range(struct intel_vgpu *vgpu, u64 pml4, + u64 start, u64 end, struct ppgtt_walk *walk) +{ + const struct intel_gvt_device_info *info = &vgpu->gvt->device_info; + struct intel_gvt_gtt_gma_ops *gma_ops = vgpu->gvt->gtt.gma_ops; + unsigned long index; + u64 pdp, next; + int ret = 0; + + do { + index = gma_ops->gma_to_pml4_index(start); + ret = intel_gvt_hypervisor_read_gpa(vgpu, + (pml4 & PAGE_MASK) + (index << + info->gtt_entry_size_shift), &pdp, 8); + if (ret) + return ret; + next = pml4_addr_end(start, end); + walk_pdp_range(vgpu, pdp, start, next, walk); + start = next; + } while (start != end); + + return ret; +} + +int intel_vgpu_g2v_pv_ppgtt_insert_4lvl(struct intel_vgpu *vgpu, + u64 pdps[]) +{ + struct intel_vgpu_mm *mm; + u64 pml4, start, length; + u32 cache_level; + int ret = 0; + struct sg_table st; + struct scatterlist *sg = NULL; + int num_pages; + struct i915_vma vma; + struct ppgtt_walk walk; + int i; + u32 offset; + struct pv_ppgtt_update pv_ppgtt; + + offset = offsetof(struct gvt_shared_page, pv_ppgtt); + intel_gvt_read_shared_page(vgpu, offset, &pv_ppgtt, sizeof(pv_ppgtt)); + pml4 = pv_ppgtt.pdp; + start = pv_ppgtt.start; + length = pv_ppgtt.length; + cache_level = pv_ppgtt.cache_level; + num_pages = length >> PAGE_SHIFT; + + mm = intel_vgpu_find_ppgtt_mm(vgpu, &pml4); + if (!mm) { + gvt_vgpu_err("fail to find mm for pml4 0x%llx\n", pml4); + return -EINVAL; + } + + walk.mfn_index = 0; + walk.mfns = NULL; + walk.pt = NULL; + + walk.mfns = kmalloc_array(num_pages, + sizeof(unsigned long), GFP_KERNEL); + if (!walk.mfns) { + ret = -ENOMEM; + goto fail; + } + + walk.pt = (unsigned long *)__get_free_pages(GFP_KERNEL, 0); + if (!walk.pt) { + ret = -ENOMEM; + goto fail; + } + + if (sg_alloc_table(&st, num_pages, GFP_KERNEL)) { + ret = -ENOMEM; + goto fail; + } + + ret = walk_pml4_range(vgpu, pml4, start, start + length, &walk); + if (ret) + goto fail_free_sg; + + WARN_ON(num_pages != walk.mfn_index); + + for_each_sg(st.sgl, sg, num_pages, i) { + sg->offset = 0; + sg->length = PAGE_SIZE; + sg_dma_address(sg) = walk.mfns[i]; + sg_dma_len(sg) = PAGE_SIZE; + } + + memset(&vma, 0, sizeof(vma)); + vma.node.start = start; + vma.pages = &st; + mm->ppgtt->vm.insert_entries(&mm->ppgtt->vm, &vma, cache_level, 0); + +fail_free_sg: + sg_free_table(&st); +fail: + kfree(walk.mfns); + free_page((unsigned long)walk.pt); + + return ret; +} diff --git a/drivers/gpu/drm/i915/gvt/gtt.h b/drivers/gpu/drm/i915/gvt/gtt.h index 32c573a..571a5c4 100644 --- a/drivers/gpu/drm/i915/gvt/gtt.h +++ b/drivers/gpu/drm/i915/gvt/gtt.h @@ -141,6 +141,7 @@ struct intel_gvt_partial_pte { struct intel_vgpu_mm { enum intel_gvt_mm_type type; + struct i915_hw_ppgtt *ppgtt; struct intel_vgpu *vgpu; struct kref ref; @@ -277,4 +278,12 @@ int intel_vgpu_emulate_ggtt_mmio_read(struct intel_vgpu *vgpu, int intel_vgpu_emulate_ggtt_mmio_write(struct intel_vgpu *vgpu, unsigned int off, void *p_data, unsigned int bytes); +int intel_vgpu_g2v_pv_ppgtt_alloc_4lvl(struct intel_vgpu *vgpu, + u64 pdps[]); + +int intel_vgpu_g2v_pv_ppgtt_clear_4lvl(struct intel_vgpu *vgpu, + u64 pdps[]); + +int intel_vgpu_g2v_pv_ppgtt_insert_4lvl(struct intel_vgpu *vgpu, + u64 pdps[]); #endif /* _GVT_GTT_H_ */ diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h index 6dbe30b..71015a0 100644 --- a/drivers/gpu/drm/i915/gvt/gvt.h +++ b/drivers/gpu/drm/i915/gvt/gvt.h @@ -53,6 +53,10 @@ #define GVT_MAX_VGPU 8 +#define VGPU_PVCAP(vgpu, cap) \ + ((vgpu_vreg_t(vgpu, vgtif_reg(pv_caps)) & (cap)) \ + && vgpu->shared_page_enabled) + struct intel_gvt_host { struct device *dev; bool initialized; diff --git a/drivers/gpu/drm/i915/gvt/handlers.c b/drivers/gpu/drm/i915/gvt/handlers.c index 3f94263..4648d17 100644 --- a/drivers/gpu/drm/i915/gvt/handlers.c +++ b/drivers/gpu/drm/i915/gvt/handlers.c @@ -1213,6 +1213,7 @@ static int handle_g2v_notification(struct intel_vgpu *vgpu, int notification) struct intel_vgpu_mm *mm; u64 *pdps; unsigned long gpa, gfn; + int ret = 0; pdps = (u64 *)&vgpu_vreg64_t(vgpu, vgtif_reg(pdp[0])); @@ -1236,6 +1237,15 @@ static int handle_g2v_notification(struct intel_vgpu *vgpu, int notification) vgpu->shared_page_gpa = gpa; vgpu->shared_page_enabled = true; break; + case VGT_G2V_PPGTT_L4_ALLOC: + ret = intel_vgpu_g2v_pv_ppgtt_alloc_4lvl(vgpu, pdps); + break; + case VGT_G2V_PPGTT_L4_INSERT: + ret = intel_vgpu_g2v_pv_ppgtt_insert_4lvl(vgpu, pdps); + break; + case VGT_G2V_PPGTT_L4_CLEAR: + ret = intel_vgpu_g2v_pv_ppgtt_clear_4lvl(vgpu, pdps); + break; case VGT_G2V_EXECLIST_CONTEXT_CREATE: case VGT_G2V_EXECLIST_CONTEXT_DESTROY: case 1: /* Remove this in guest driver. */ @@ -1243,7 +1253,7 @@ static int handle_g2v_notification(struct intel_vgpu *vgpu, int notification) default: gvt_vgpu_err("Invalid PV notification %d\n", notification); } - return 0; + return ret; } static int send_display_ready_uevent(struct intel_vgpu *vgpu, int ready) diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c index 0663b3e..dd89c12 100644 --- a/drivers/gpu/drm/i915/gvt/vgpu.c +++ b/drivers/gpu/drm/i915/gvt/vgpu.c @@ -49,6 +49,9 @@ void populate_pvinfo_page(struct intel_vgpu *vgpu) vgpu_vreg_t(vgpu, vgtif_reg(vgt_caps)) |= VGT_CAPS_HUGE_GTT; vgpu_vreg_t(vgpu, vgtif_reg(vgt_caps)) |= VGT_CAPS_PV; + if (!intel_vtd_active()) + vgpu_vreg_t(vgpu, vgtif_reg(pv_caps)) = PV_PPGTT_UPDATE; + vgpu_vreg_t(vgpu, vgtif_reg(avail_rs.mappable_gmadr.base)) = vgpu_aperture_gmadr_base(vgpu); vgpu_vreg_t(vgpu, vgtif_reg(avail_rs.mappable_gmadr.size)) = From patchwork Mon Apr 29 03:10:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Zhang X-Patchwork-Id: 10921109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 62C3E912 for ; Mon, 29 Apr 2019 03:11:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5214528739 for ; Mon, 29 Apr 2019 03:11:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 464252873D; Mon, 29 Apr 2019 03:11:55 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 DDF3428739 for ; Mon, 29 Apr 2019 03:11:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7D51F8916B; Mon, 29 Apr 2019 03:11:54 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id DEAC989160; Mon, 29 Apr 2019 03:11:52 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Apr 2019 20:11:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,408,1549958400"; d="scan'208";a="146648277" Received: from xzhan34-mobl3.bj.intel.com ([10.238.154.121]) by fmsmga007.fm.intel.com with ESMTP; 28 Apr 2019 20:11:50 -0700 From: Xiaolin Zhang To: intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Date: Mon, 29 Apr 2019 11:10:58 +0800 Message-Id: <1556507458-24684-9-git-send-email-xiaolin.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> References: <1556507458-24684-1-git-send-email-xiaolin.zhang@intel.com> Subject: [Intel-gfx] [PATCH v5 8/8] drm/i915/gvt: GVTg support context submission 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" X-Virus-Scanned: ClamAV using ClamSMTP implemented context submission pv optimizaiton within GVTg. GVTg to read context submission data (elsp_data) from the shared_page directly without trap cost and eliminate execlist HW behavior emulation without injecting context switch interrupt to guest under PV submisison mechanism. v0: RFC v1: rebase v2: rebase v3: report pv context submission cap and handle VGT_G2V_ELSP_SUBMIT g2v pv notification. v4: eliminate execlist HW emulation and don't inject context switch interrupt to guest under PV submisison mechanism. v5: rebase Signed-off-by: Xiaolin Zhang --- drivers/gpu/drm/i915/gvt/execlist.c | 6 ++++++ drivers/gpu/drm/i915/gvt/handlers.c | 12 ++++++++++++ drivers/gpu/drm/i915/gvt/vgpu.c | 1 + 3 files changed, 19 insertions(+) diff --git a/drivers/gpu/drm/i915/gvt/execlist.c b/drivers/gpu/drm/i915/gvt/execlist.c index f21b8fb..e52bfd6 100644 --- a/drivers/gpu/drm/i915/gvt/execlist.c +++ b/drivers/gpu/drm/i915/gvt/execlist.c @@ -382,6 +382,9 @@ static int prepare_execlist_workload(struct intel_vgpu_workload *workload) int ring_id = workload->ring_id; int ret; + if (VGPU_PVCAP(vgpu, PV_SUBMISSION)) + return 0; + if (!workload->emulate_schedule_in) return 0; @@ -429,6 +432,9 @@ static int complete_execlist_workload(struct intel_vgpu_workload *workload) goto out; } + if (VGPU_PVCAP(vgpu, PV_SUBMISSION)) + goto out; + ret = emulate_execlist_ctx_schedule_out(execlist, &workload->ctx_desc); out: intel_vgpu_unpin_mm(workload->shadow_mm); diff --git a/drivers/gpu/drm/i915/gvt/handlers.c b/drivers/gpu/drm/i915/gvt/handlers.c index 4648d17..1e5f109 100644 --- a/drivers/gpu/drm/i915/gvt/handlers.c +++ b/drivers/gpu/drm/i915/gvt/handlers.c @@ -1712,6 +1712,18 @@ static int elsp_mmio_write(struct intel_vgpu *vgpu, unsigned int offset, return -EINVAL; execlist = &vgpu->submission.execlist[ring_id]; + if (VGPU_PVCAP(vgpu, PV_SUBMISSION) && VGT_G2V_PV_SUBMISSION == data) { + struct pv_submission pv_elsp[I915_NUM_ENGINES]; + u32 pv_elsp_off = offsetof(struct gvt_shared_page, pv_elsp); + + if (intel_gvt_read_shared_page(vgpu, pv_elsp_off, &pv_elsp, + I915_NUM_ENGINES * sizeof(struct pv_submission))) + return ret; + + memcpy(&execlist->elsp_dwords.data, pv_elsp[ring_id].descs, + 8 * EXECLIST_MAX_PORTS); + return intel_vgpu_submit_execlist(vgpu, ring_id); + } execlist->elsp_dwords.data[3 - execlist->elsp_dwords.index] = data; if (execlist->elsp_dwords.index == 3) { diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c index dd89c12..47dd29e 100644 --- a/drivers/gpu/drm/i915/gvt/vgpu.c +++ b/drivers/gpu/drm/i915/gvt/vgpu.c @@ -51,6 +51,7 @@ void populate_pvinfo_page(struct intel_vgpu *vgpu) if (!intel_vtd_active()) vgpu_vreg_t(vgpu, vgtif_reg(pv_caps)) = PV_PPGTT_UPDATE; + vgpu_vreg_t(vgpu, vgtif_reg(pv_caps)) |= PV_SUBMISSION; vgpu_vreg_t(vgpu, vgtif_reg(avail_rs.mappable_gmadr.base)) = vgpu_aperture_gmadr_base(vgpu);