From patchwork Mon Oct 21 05:21:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13843577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 897EDD3C93E for ; Mon, 21 Oct 2024 05:46:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ACD0C10E282; Mon, 21 Oct 2024 05:46:07 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="EeglAzui"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id E82A710E0A1; Mon, 21 Oct 2024 05:46:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729489568; x=1761025568; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uV5snUpY10mY+ieUbO0PLEKGL0amDrpA0hEcIDbiYHY=; b=EeglAzuiNVpbvlwWacQ/9cxOm0lXxy+Dd1gjxa8XhGeE9LYhNqtJiHdx QkPhZkQiDz8qn9qh0Tt4MgVbbqri+shD/sfsRZM1hfQivo/Ux45Es1Oh4 HlGVLUnKxxydzVEJ++Affw2s10zMPVDcuEZnkE8YKz4fYCepqejrjbJEB Ix/SCXBRR+F5hYTWBG5QmDB/QS0iW57/shlB3OjovejEH43BBCiL5uKEG lSyoNer8N2oW2iOq+zBJoEJr5MGYWy9pzWgOKQAN9T0TGUEhXpljFK9i/ pv9C5Unt6mXjXCGwzDWBavFwtk8L+CAxko9AJMmXnqDAsvTiIHvHCMWj/ w==; X-CSE-ConnectionGUID: a5uH6u7CT/+2v/f1pOCZfg== X-CSE-MsgGUID: Q8c8ePuQQ2W8tcAbHzzlbg== X-IronPort-AV: E=McAfee;i="6700,10204,11231"; a="40345940" X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="40345940" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2024 22:46:06 -0700 X-CSE-ConnectionGUID: UcI3brXwTsOUey9oPpOkNQ== X-CSE-MsgGUID: ER72puDBRjKLn/Fy7mxSSA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="110180207" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2024 22:46:05 -0700 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: Vivek Kasireddy , Bjorn Helgaas , Logan Gunthorpe , linux-pci@vger.kernel.org Subject: [PATCH v2 1/5] PCI/P2PDMA: Don't enforce ACS check for functions of same device Date: Sun, 20 Oct 2024 22:21:29 -0700 Message-ID: <20241021052236.1820329-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241021052236.1820329-1-vivek.kasireddy@intel.com> References: <20241021052236.1820329-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Functions of the same PCI device (such as a PF and a VF) share the same bus and have a common root port and typically, the PF provisions resources for the VF. Therefore, they can be considered compatible as far as P2P access is considered. Currently, although the distance (2) is correctly calculated for functions of the same device, an ACS check failure prevents P2P DMA access between them. Therefore, introduce a small function named pci_devs_are_p2pdma_compatible() to determine if the provider and client belong to the same device and facilitate P2P DMA between them by not enforcing the ACS check. v2: - Relax the enforcment of ACS check only for Intel GPU functions as they are P2PDMA compatible given the way the PF provisions the resources among multiple VFs. Cc: Bjorn Helgaas Cc: Logan Gunthorpe Cc: Signed-off-by: Vivek Kasireddy --- drivers/pci/p2pdma.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 4f47a13cb500..a230e661f939 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -535,6 +535,17 @@ static unsigned long map_types_idx(struct pci_dev *client) return (pci_domain_nr(client->bus) << 16) | pci_dev_id(client); } +static bool pci_devs_are_p2pdma_compatible(struct pci_dev *provider, + struct pci_dev *client) +{ + if (provider->vendor == PCI_VENDOR_ID_INTEL) { + if (pci_is_vga(provider) && pci_is_vga(client)) + return pci_physfn(provider) == pci_physfn(client); + } + + return false; +} + /* * Calculate the P2PDMA mapping type and distance between two PCI devices. * @@ -634,7 +645,7 @@ calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client, *dist = dist_a + dist_b; - if (!acs_cnt) { + if (!acs_cnt || pci_devs_are_p2pdma_compatible(provider, client)) { map_type = PCI_P2PDMA_MAP_BUS_ADDR; goto done; } @@ -696,7 +707,9 @@ int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients, return -1; for (i = 0; i < num_clients; i++) { - pci_client = find_parent_pci_dev(clients[i]); + pci_client = dev_is_pf(clients[i]) ? + pci_dev_get(to_pci_dev(clients[i])) : + find_parent_pci_dev(clients[i]); if (!pci_client) { if (verbose) dev_warn(clients[i], From patchwork Mon Oct 21 05:21:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13843579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id BC58FD3C546 for ; Mon, 21 Oct 2024 05:46:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4E55910E2D0; Mon, 21 Oct 2024 05:46:08 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="aE2uvBm4"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1844710E087; Mon, 21 Oct 2024 05:46:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729489568; x=1761025568; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sCLXIH+f41dp6R34CT4MxqUaL5J7BMa4OgN8f/KYKjs=; b=aE2uvBm49b0hpkw9aYle2SEMegtZttn/NKu3MeKEwRrL/uGLyeyuBPpE Z+Tltz/+DbwQz0iZo/onOJNak2wsMd1ODzkijPUaGTrJmfJk1o+7f9I/U n8/Ut6x1aesTDAbU50ymdcWFvRNQ9cv9JZrNULtbtrhRrL9CKRzYfOPaA 4FPBGGgbkiBrauioM/epRugFkn2vIFk/99Hy+dIRU8AkiCTxvRqEUSBmA nNDKuZlr0T5PU9q1vb43XeZy2s/VPKfBI0q9bIvb1pxAc8zCQUPi8GCep usRmpr+k3JS2Umuk84aF9G3be8y0am+RG9uHkRjlMrwackARE0mWEOmJD w==; X-CSE-ConnectionGUID: cFAZTxNeRzuEsZF882kGfQ== X-CSE-MsgGUID: 0qgCGTuHT9K0MTa5n0UN+Q== X-IronPort-AV: E=McAfee;i="6700,10204,11231"; a="40345941" X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="40345941" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2024 22:46:07 -0700 X-CSE-ConnectionGUID: IDhJF0GmQqOWk25fJ0TXtA== X-CSE-MsgGUID: Igy66gfWRe+PEeD+EhpLdg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="110180210" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2024 22:46:05 -0700 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: Vivek Kasireddy Subject: [PATCH v2 2/5] drm/xe/dmabuf: Don't migrate BO to System RAM while running in VF mode Date: Sun, 20 Oct 2024 22:21:30 -0700 Message-ID: <20241021052236.1820329-3-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241021052236.1820329-1-vivek.kasireddy@intel.com> References: <20241021052236.1820329-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" If the importer has allow_peer2peer set to true, then we can expect that it would be able to handle VRAM addresses. Therefore, in this specific case and only while running in VF mode, do not migrate the BO to System RAM before exporting it. Signed-off-by: Vivek Kasireddy --- drivers/gpu/drm/xe/xe_dma_buf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_buf.c index 68f309f5e981..a90c9368d265 100644 --- a/drivers/gpu/drm/xe/xe_dma_buf.c +++ b/drivers/gpu/drm/xe/xe_dma_buf.c @@ -17,6 +17,7 @@ #include "xe_bo.h" #include "xe_device.h" #include "xe_pm.h" +#include "xe_sriov.h" #include "xe_ttm_vram_mgr.h" #include "xe_vm.h" @@ -26,8 +27,11 @@ static int xe_dma_buf_attach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) { struct drm_gem_object *obj = attach->dmabuf->priv; + struct xe_bo *bo = gem_to_xe_bo(obj); + struct xe_device *xe = xe_bo_device(bo); if (attach->peer2peer && + !IS_SRIOV_VF(xe) && pci_p2pdma_distance(to_pci_dev(obj->dev->dev), attach->dev, false) < 0) attach->peer2peer = false; @@ -51,7 +55,7 @@ static int xe_dma_buf_pin(struct dma_buf_attachment *attach) struct drm_gem_object *obj = attach->dmabuf->priv; struct xe_bo *bo = gem_to_xe_bo(obj); struct xe_device *xe = xe_bo_device(bo); - int ret; + int ret = 0; /* * For now only support pinning in TT memory, for two reasons: @@ -63,7 +67,8 @@ static int xe_dma_buf_pin(struct dma_buf_attachment *attach) return -EINVAL; } - ret = xe_bo_migrate(bo, XE_PL_TT); + if (!IS_SRIOV_VF(xe) || !attach->peer2peer) + ret = xe_bo_migrate(bo, XE_PL_TT); if (ret) { if (ret != -EINTR && ret != -ERESTARTSYS) drm_dbg(&xe->drm, From patchwork Mon Oct 21 05:21:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13843580 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 0C739D3DEA1 for ; Mon, 21 Oct 2024 05:46:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2C4AB10E405; Mon, 21 Oct 2024 05:46:10 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Iu695Xly"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 252A910E0A1; Mon, 21 Oct 2024 05:46:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729489568; x=1761025568; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WvVNhqh7Bwb6iLfqs+U77vNGCodYNky0QU/wAp4qxm4=; b=Iu695XlyLDqqz+4vafVbPVQM9Ib+dAVnx2SbJ+ibnD9icmIvV2MOwe+n J0cv+pe3yI4GHdmKhL6OJayQAn1ONi6HL+er4z8SdtyAbf68FipRuMJmv peOfA73wq3EwmXw5PSfPAx+2G1yJCZYo28qYxx5BQHE47Pva5A8+WumWy BbpbP/LgziAdVmrigQ5xwwDZTajK9aHIWyoLA4LBke03DS3/Y3ZGzsTCp EuwkzWEAL6PYme/kKBg3gjk3QOpA51VrdqzBm58eOIr1zkltXHTjZwBok WiCZvkQ51InXmYVB8pj9mB9ZjqvV2kSkroI1cCGvUZqOS1sv46aurpW7q Q==; X-CSE-ConnectionGUID: Ffhx4qthTou9y57r8o+G5w== X-CSE-MsgGUID: eYKGE5wYTJ2chcZCpxyY3A== X-IronPort-AV: E=McAfee;i="6700,10204,11231"; a="40345942" X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="40345942" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2024 22:46:07 -0700 X-CSE-ConnectionGUID: CP45vE/mTEWzbuu7lFCDCw== X-CSE-MsgGUID: ixgAtctART+or2VjFpQD0Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="110180214" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2024 22:46:05 -0700 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: Vivek Kasireddy Subject: [PATCH v2 3/5] drm/xe/pf: Add a helper function to get a VF's backing object in LMEM Date: Sun, 20 Oct 2024 22:21:31 -0700 Message-ID: <20241021052236.1820329-4-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241021052236.1820329-1-vivek.kasireddy@intel.com> References: <20241021052236.1820329-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To properly import a dmabuf that is associated with a VF (or that originates in a Guest VM that includes a VF), we need to know where in LMEM the VF's allocated regions exist. Therefore, introduce a new helper to return the object that backs the VF's regions in LMEM. v2: - Make the helper return the LMEM object instead of the start address. Signed-off-by: Vivek Kasireddy --- drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 23 ++++++++++++++++++++++ drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h | 1 + 2 files changed, 24 insertions(+) diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c index a863e50b756e..8a5df3d76533 100644 --- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c +++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c @@ -1455,6 +1455,29 @@ u64 xe_gt_sriov_pf_config_get_lmem(struct xe_gt *gt, unsigned int vfid) return size; } +/** + * xe_gt_sriov_pf_config_get_lmem_obj - Get VF's LMEM BO. + * @gt: the &xe_gt + * @vfid: the VF identifier + * + * This function can only be called on PF. + * + * Return: BO that is backing VF's quota in LMEM. + */ +struct xe_bo *xe_gt_sriov_pf_config_get_lmem_obj(struct xe_gt *gt, + unsigned int vfid) +{ + struct xe_gt_sriov_config *config; + struct xe_bo *lmem_obj; + + mutex_lock(xe_gt_sriov_pf_master_mutex(gt)); + config = pf_pick_vf_config(gt, vfid); + lmem_obj = config->lmem_obj; + mutex_unlock(xe_gt_sriov_pf_master_mutex(gt)); + + return lmem_obj; +} + /** * xe_gt_sriov_pf_config_set_lmem - Provision VF with LMEM. * @gt: the &xe_gt (can't be media) diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h index b74ec38baa18..7779dc9f9c8d 100644 --- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h +++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h @@ -31,6 +31,7 @@ int xe_gt_sriov_pf_config_set_fair_dbs(struct xe_gt *gt, unsigned int vfid, unsi int xe_gt_sriov_pf_config_bulk_set_dbs(struct xe_gt *gt, unsigned int vfid, unsigned int num_vfs, u32 num_dbs); +struct xe_bo *xe_gt_sriov_pf_config_get_lmem_obj(struct xe_gt *gt, unsigned int vfid); u64 xe_gt_sriov_pf_config_get_lmem(struct xe_gt *gt, unsigned int vfid); int xe_gt_sriov_pf_config_set_lmem(struct xe_gt *gt, unsigned int vfid, u64 size); int xe_gt_sriov_pf_config_set_fair_lmem(struct xe_gt *gt, unsigned int vfid, unsigned int num_vfs); From patchwork Mon Oct 21 05:21:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13843578 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 64578D3C53F for ; Mon, 21 Oct 2024 05:46:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 376DF10E2CF; Mon, 21 Oct 2024 05:46:08 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="X6LoQN9b"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2A1CD10E282; Mon, 21 Oct 2024 05:46:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729489568; x=1761025568; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8XWLiBEU7K7TxvavInh4Ggaazz1BEyz1cNNbHNSVdNc=; b=X6LoQN9bSIAZ7+aBPkWqURVue3ew8g/y8wM+s/lTauqhQujtWkpDqqMe H0MEwWCiGtiJ3DtAcb9tZ0XwLQ2G6G0NL7ra5nzwG+pqsP7MZJFOT3R4b fTi+HTpiG3NWLOojxBT+by7wRSssseGC3ulTpd1I/vIdqPSRCSEzX4euR tuZL7a+WIq3NZFZrS0cqIzDxdxuFuuRcv9IMANR7ZcLpQZ++NDll+QOtC zlOMIhiP1HLVm8gbLysIhexb6LVbVbBnm4CfjWdpq9otLHJJus4k6lXc6 QNI0DQNME8zOuoZbkvUonHriVuthZ31rORh9HcDRGvrUbIgsP14ubNMbg A==; X-CSE-ConnectionGUID: JGEv9QK2Ro6U9wtFLio2AA== X-CSE-MsgGUID: P57tTV8xTxOUBza8GL4kGw== X-IronPort-AV: E=McAfee;i="6700,10204,11231"; a="40345943" X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="40345943" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2024 22:46:07 -0700 X-CSE-ConnectionGUID: XViG+FOZTGaQaPll6pP1pw== X-CSE-MsgGUID: 3VhXmuujRxKnZ3+Mkf4nmQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="110180217" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2024 22:46:06 -0700 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: Vivek Kasireddy , Matthew Brost , =?utf-8?q?Thomas_Hellstr=C3=B6m?= Subject: [PATCH v2 4/5] drm/xe/bo: Create new dma_addr array for dmabuf BOs associated with VFs Date: Sun, 20 Oct 2024 22:21:32 -0700 Message-ID: <20241021052236.1820329-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241021052236.1820329-1-vivek.kasireddy@intel.com> References: <20241021052236.1820329-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" For BOs of type ttm_bo_type_sg, that are backed by PCI BAR addresses associated with a VF, we need to adjust and translate these addresses to LMEM addresses to make the BOs usable by the PF. Otherwise, the BOs (i.e, PCI BAR addresses) are only accessible by the CPU and not by the GPU. In order to do the above, we first need to identify if the DMA addresses associated with an imported BO (type ttm_bo_type_sg) belong to System RAM or a VF or other PCI devices. After we confirm that they belong to a VF, we convert the DMA addresses (IOVAs in this case) to DPAs and create a new dma_addr array (of type drm_pagemap_dma_addr) and populate it with the new addresses along with the segment sizes. v2: - Use dma_addr array instead of sg table to store translated addresses (Matt) Cc: Matthew Brost Cc: Thomas Hellström Signed-off-by: Vivek Kasireddy --- drivers/gpu/drm/xe/xe_bo.c | 116 +++++++++++++++++++++++++++++-- drivers/gpu/drm/xe/xe_bo_types.h | 11 ++- 2 files changed, 120 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index 5b232f2951b1..81a2f8c8031a 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -6,6 +6,7 @@ #include "xe_bo.h" #include +#include #include #include @@ -15,16 +16,19 @@ #include #include +#include "regs/xe_bars.h" #include "xe_device.h" #include "xe_dma_buf.h" #include "xe_drm_client.h" #include "xe_ggtt.h" #include "xe_gt.h" +#include "xe_gt_sriov_pf_config.h" #include "xe_map.h" #include "xe_migrate.h" #include "xe_pm.h" #include "xe_preempt_fence.h" #include "xe_res_cursor.h" +#include "xe_sriov_pf_helpers.h" #include "xe_trace_bo.h" #include "xe_ttm_stolen_mgr.h" #include "xe_vm.h" @@ -543,6 +547,94 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo, return ret; } +static struct pci_dev *xe_find_vf_dev(struct xe_device *xe, + phys_addr_t phys) +{ + struct pci_dev *pdev, *pf_pdev = to_pci_dev(xe->drm.dev); + resource_size_t io_start, io_size; + + list_for_each_entry(pdev, &pf_pdev->bus->devices, bus_list) { + if (pdev->is_physfn) + continue; + + io_start = pci_resource_start(pdev, LMEM_BAR); + io_size = pci_resource_len(pdev, LMEM_BAR); + + if (phys >= io_start && + phys < (io_start + io_size - PAGE_SIZE)) + return pdev; + } + + return NULL; +} + + +static void xe_bo_translate_iova_to_dpa(struct iommu_domain *domain, + struct xe_bo *bo, struct sg_table *sg, + resource_size_t io_start, int vfid) +{ + struct xe_device *xe = xe_bo_device(bo); + struct xe_gt *gt = xe_root_mmio_gt(xe); + struct scatterlist *sgl; + struct xe_bo *lmem_bo; + phys_addr_t phys; + dma_addr_t addr; + u64 offset, i; + + lmem_bo = xe_gt_sriov_pf_config_get_lmem_obj(gt, ++vfid); + + for_each_sgtable_dma_sg(sg, sgl, i) { + phys = iommu_iova_to_phys(domain, sg_dma_address(sgl)); + offset = phys - io_start; + addr = xe_bo_addr(lmem_bo, offset, sg_dma_len(sgl)); + + bo->dma_addr[i] = drm_pagemap_dma_addr_encode(addr, + DRM_INTERCONNECT_DRIVER, + get_order(sg_dma_len(sgl)), + DMA_BIDIRECTIONAL); + } +} + +static int xe_bo_sg_to_dma_addr_array(struct sg_table *sg, struct xe_bo *bo) +{ + struct xe_device *xe = xe_bo_device(bo); + struct iommu_domain *domain; + resource_size_t io_start; + struct pci_dev *pdev; + phys_addr_t phys; + int vfid; + + if (!IS_SRIOV_PF(xe)) + return 0; + + domain = iommu_get_domain_for_dev(xe->drm.dev); + if (!domain) + return 0; + + phys = iommu_iova_to_phys(domain, sg_dma_address(sg->sgl)); + if (page_is_ram(PFN_DOWN(phys))) + return 0; + + pdev = xe_find_vf_dev(xe, phys); + if (!pdev) + return 0; + + vfid = pci_iov_vf_id(pdev); + if (vfid < 0) + return 0; + + bo->dma_addr = kmalloc_array(sg->nents, sizeof(*bo->dma_addr), + GFP_KERNEL); + if (!bo->dma_addr) + return -ENOMEM; + + bo->is_devmem_external = true; + io_start = pci_resource_start(pdev, LMEM_BAR); + xe_bo_translate_iova_to_dpa(domain, bo, sg, io_start, vfid); + + return 0; +} + /* * The dma-buf map_attachment() / unmap_attachment() is hooked up here. * Note that unmapping the attachment is deferred to the next @@ -560,12 +652,15 @@ static int xe_bo_move_dmabuf(struct ttm_buffer_object *ttm_bo, ttm); struct xe_device *xe = ttm_to_xe_device(ttm_bo->bdev); struct sg_table *sg; + int ret; xe_assert(xe, attach); xe_assert(xe, ttm_bo->ttm); - if (new_res->mem_type == XE_PL_SYSTEM) - goto out; + if (new_res->mem_type == XE_PL_SYSTEM) { + ttm_bo_move_null(ttm_bo, new_res); + return 0; + } if (ttm_bo->sg) { dma_buf_unmap_attachment(attach, ttm_bo->sg, DMA_BIDIRECTIONAL); @@ -576,13 +671,16 @@ static int xe_bo_move_dmabuf(struct ttm_buffer_object *ttm_bo, if (IS_ERR(sg)) return PTR_ERR(sg); + ret = xe_bo_sg_to_dma_addr_array(sg, ttm_to_xe_bo(ttm_bo)); + if (ret < 0) { + dma_buf_unmap_attachment(attach, sg, DMA_BIDIRECTIONAL); + return ret; + } + ttm_bo->sg = sg; xe_tt->sg = sg; -out: - ttm_bo_move_null(ttm_bo, new_res); - - return 0; + return ret; } /** @@ -1066,6 +1164,8 @@ static void xe_ttm_bo_release_notify(struct ttm_buffer_object *ttm_bo) static void xe_ttm_bo_delete_mem_notify(struct ttm_buffer_object *ttm_bo) { + struct xe_bo *bo = ttm_to_xe_bo(ttm_bo); + if (!xe_bo_is_xe_bo(ttm_bo)) return; @@ -1079,6 +1179,10 @@ static void xe_ttm_bo_delete_mem_notify(struct ttm_buffer_object *ttm_bo) dma_buf_unmap_attachment(ttm_bo->base.import_attach, ttm_bo->sg, DMA_BIDIRECTIONAL); + + if (bo->is_devmem_external) { + kfree(bo->dma_addr); + } ttm_bo->sg = NULL; xe_tt->sg = NULL; } diff --git a/drivers/gpu/drm/xe/xe_bo_types.h b/drivers/gpu/drm/xe/xe_bo_types.h index 13c6d8a69e91..f74876be3f8d 100644 --- a/drivers/gpu/drm/xe/xe_bo_types.h +++ b/drivers/gpu/drm/xe/xe_bo_types.h @@ -66,7 +66,16 @@ struct xe_bo { /** @ccs_cleared */ bool ccs_cleared; - + /** + * @is_devmem_external: Whether this BO is an imported dma-buf that + * is LMEM based. + */ + bool is_devmem_external; + /** + * @dma_addr: An array to store DMA addresses (DPAs) for imported + * dmabuf BOs that are LMEM based. + */ + struct drm_pagemap_dma_addr *dma_addr; /** * @cpu_caching: CPU caching mode. Currently only used for userspace * objects. Exceptions are system memory on DGFX, which is always From patchwork Mon Oct 21 05:21:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13843581 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id EEC0CD3C93E for ; Mon, 21 Oct 2024 05:46:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D484C10E403; Mon, 21 Oct 2024 05:46:10 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="kddZtKhN"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4A82E10E2B4; Mon, 21 Oct 2024 05:46:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729489568; x=1761025568; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F/EwoI+BvPXjVFIzZu/y+MNj+V6sPmr35F9RA9m36Ag=; b=kddZtKhNLAMiodknJucik5XxEw8sMLR47HFMz/NSa+M+vS8ZWpduXGcA 1X+ExsWNKiyXpNZoZBVO1n/WMdrG5VEVbAb2doU2uGYTsVfAf3Hb91MSo DHLyrzg72J7K4DHNzg9EzOAl6BE6ytZCutmqBWZj9klcqq5RAaahw4S0+ CvpSpvzZgNzRu97CXBMQamakHi2rC2iXUluupSEzY0VEQibyLExF9lA4t uPd71T4Af+lmFsqrtETa48DJXiZmzS0iqqtlpCZI0jolDD+AK3Mx5XE70 s1RibWmLFLgsOUgIaiNIgzPDxw75ck9EER3mekWnYbD8FUf73za+lFnt0 A==; X-CSE-ConnectionGUID: OBqQIRs6QwGw5/3Z9Od0Gg== X-CSE-MsgGUID: BuvTmF8eQCOo+kHkZEtijw== X-IronPort-AV: E=McAfee;i="6700,10204,11231"; a="40345944" X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="40345944" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2024 22:46:07 -0700 X-CSE-ConnectionGUID: 6MjquqNLSuW1nSLkZ7q0fg== X-CSE-MsgGUID: LJfOjRWMQCKxIuiVGBtMBg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="110180220" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2024 22:46:06 -0700 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: Vivek Kasireddy Subject: [PATCH v2 5/5] drm/xe/pt: Add an additional check for dmabuf BOs while updating PTEs Date: Sun, 20 Oct 2024 22:21:33 -0700 Message-ID: <20241021052236.1820329-6-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241021052236.1820329-1-vivek.kasireddy@intel.com> References: <20241021052236.1820329-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" If a BO's is_devmem_external flag is set, it means that it is an imported dmabuf BO that has a backing store in VRAM. Therefore, we need to add XE_PPGTT_PTE_DM to the PTE flags as part of vm_bind. v2: - Use a cursor to iterate over the entries in the dma_addr array instead of relying on SG iterator (Matt) Signed-off-by: Vivek Kasireddy --- drivers/gpu/drm/xe/xe_pt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_pt.c b/drivers/gpu/drm/xe/xe_pt.c index f27f579f4d85..cfa11acbf525 100644 --- a/drivers/gpu/drm/xe/xe_pt.c +++ b/drivers/gpu/drm/xe/xe_pt.c @@ -660,10 +660,11 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma, xe_walk.default_pte &= ~XE_USM_PPGTT_PTE_AE; } - if (is_devmem) { + if (is_devmem || bo->is_devmem_external) xe_walk.default_pte |= XE_PPGTT_PTE_DM; + + if (is_devmem) xe_walk.dma_offset = vram_region_gpu_offset(bo->ttm.resource); - } if (!xe_vma_has_no_bo(vma) && xe_bo_is_stolen(bo)) xe_walk.dma_offset = xe_ttm_stolen_gpu_offset(xe_bo_device(bo)); @@ -677,6 +678,9 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma, else if (xe_bo_is_vram(bo) || xe_bo_is_stolen(bo)) xe_res_first(bo->ttm.resource, xe_vma_bo_offset(vma), xe_vma_size(vma), &curs); + else if (bo->is_devmem_external) + xe_res_first_dma(bo->dma_addr, xe_vma_bo_offset(vma), + xe_vma_size(vma), &curs); else xe_res_first_sg(xe_bo_sg(bo), xe_vma_bo_offset(vma), xe_vma_size(vma), &curs);