From patchwork Sat Oct 12 02:40:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13833770 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 CE8BFD1A431 for ; Sat, 12 Oct 2024 03:09:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C49D510E2EC; Sat, 12 Oct 2024 03:09:37 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="ZgQOSMFK"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id 45B0B10E12D; Sat, 12 Oct 2024 03:09:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1728702576; x=1760238576; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pQNMKXIhNUvqskCGGddSIwZWuzf8Xr6bq3qxHY1VKO4=; b=ZgQOSMFK9c1fq25sguONzyzxivt5uWtRzJe2D8bokOZOki6bDsI9m0lu JiIxlvE+i5nr7foD5+h2czPJe4J+iFCCctI18Yhy2Yey+uwf2WLo3nzfj U++eQBRsEPTj6pm3E1nZ9wMg4oXCKDm5YkhJ5CeBkHacqn/oYvkc3GfRr 9mv6ZrMDsORWTC+5srnBh//U8M7AuieIVCFRizrIEhgh9+P8iQ016YJMt +bHhSsM9TmsVeHDpJhyxbAUbSWDshQjMTzHXFZ+2qbdGfnabOzvR0vbps biVsl39hCLF6iOIZHW97F6YKo3caBaTQ9xFtPf3HXisjndmR/Cujm0Rbr A==; X-CSE-ConnectionGUID: lWMD6aDkT6a+BbHqyJLOWw== X-CSE-MsgGUID: c4SyR3GVReef1eaYp3MXhw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="38687316" X-IronPort-AV: E=Sophos;i="6.11,197,1725346800"; d="scan'208";a="38687316" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2024 20:09:35 -0700 X-CSE-ConnectionGUID: 3tn12sxdR+u8jy3DVPIi0Q== X-CSE-MsgGUID: TYNtCv92QCKIIykql8TfUg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,197,1725346800"; d="scan'208";a="77278458" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2024 20:09:36 -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 v1 1/5] PCI/P2PDMA: Don't enforce ACS check for functions of same device Date: Fri, 11 Oct 2024 19:40:23 -0700 Message-ID: <20241012024524.1377836-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241012024524.1377836-1-vivek.kasireddy@intel.com> References: <20241012024524.1377836-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 same_pci_device_functions() to determine if the provider and client belong to the same device and facilitate P2P DMA between them by not enforcing the ACS check. Cc: Bjorn Helgaas Cc: Logan Gunthorpe Cc: Signed-off-by: Vivek Kasireddy --- drivers/pci/p2pdma.c | 12 ++++++++++-- include/linux/pci.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 4f47a13cb500..34bee1ac94f2 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -535,6 +535,12 @@ static unsigned long map_types_idx(struct pci_dev *client) return (pci_domain_nr(client->bus) << 16) | pci_dev_id(client); } +static bool same_pci_device_functions(struct pci_dev *provider, + struct pci_dev *client) +{ + return pci_physfn(provider) == pci_physfn(client); +} + /* * Calculate the P2PDMA mapping type and distance between two PCI devices. * @@ -634,7 +640,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 || same_pci_device_functions(provider, client)) { map_type = PCI_P2PDMA_MAP_BUS_ADDR; goto done; } @@ -696,7 +702,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]) || dev_is_vf(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], diff --git a/include/linux/pci.h b/include/linux/pci.h index 573b4c4c2be6..a9b07a15f5aa 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1183,6 +1183,7 @@ void pcibios_setup_bridge(struct pci_bus *bus, unsigned long type); void pci_sort_breadthfirst(void); #define dev_is_pci(d) ((d)->bus == &pci_bus_type) #define dev_is_pf(d) ((dev_is_pci(d) ? to_pci_dev(d)->is_physfn : false)) +#define dev_is_vf(d) ((dev_is_pci(d) ? to_pci_dev(d)->is_virtfn : false)) /* Generic PCI functions exported to card drivers */ From patchwork Sat Oct 12 02:40:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13833768 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 750F3D1A42C for ; Sat, 12 Oct 2024 03:09:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E623710E2E9; Sat, 12 Oct 2024 03:09:36 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="TiX5Fbfa"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id 68D2110E03B; Sat, 12 Oct 2024 03:09:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1728702576; x=1760238576; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sCLXIH+f41dp6R34CT4MxqUaL5J7BMa4OgN8f/KYKjs=; b=TiX5Fbfae8Dp4TQ/EVLWbqozzw8f9oiSNGUI5D9C8V/ABcSRO4N02fdc vZrkA0fcEu6/A8Wudipl+FBeGGaxL2KyzmdfJ+d8+uoWO9IadrNxFPJ+9 hw5Tu0XBMU7GsyALhj587NW9Rxl5QHAb8fQKUJuBsCA6SCXOQJWUeQZaV XIkJF5M8T7acsi63X4nKFoM90C6TG3Cykk1O5rcqpIFpQZx5oNEC4jQVI pe9KqSnZfWf6lg4v+i1qQbXeyN8cVDYQB/dNDRsWGcd2cHjYjjvn2cf4b 2f4S7/MHw7OfUvC/IQyb/GKoAy/pOyuUt/syEEe3d/O02zswZHMOazVGa w==; X-CSE-ConnectionGUID: 8HxCUVhSTum6v5+8hVj4Lw== X-CSE-MsgGUID: Kdh4RfKUQA6cSUmd3i83aQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="38687318" X-IronPort-AV: E=Sophos;i="6.11,197,1725346800"; d="scan'208";a="38687318" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2024 20:09:36 -0700 X-CSE-ConnectionGUID: QDUZkImSQzW/qXI7cIQZMQ== X-CSE-MsgGUID: +KVn5d4hR1WGMnRVGP4FLQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,197,1725346800"; d="scan'208";a="77278461" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2024 20:09:36 -0700 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: Vivek Kasireddy Subject: [PATCH v1 2/5] drm/xe/dmabuf: Don't migrate BO to System RAM while running in VF mode Date: Fri, 11 Oct 2024 19:40:24 -0700 Message-ID: <20241012024524.1377836-3-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241012024524.1377836-1-vivek.kasireddy@intel.com> References: <20241012024524.1377836-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 Sat Oct 12 02:40:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13833771 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 5C16BD1A42D for ; Sat, 12 Oct 2024 03:09:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EBF0D10E2F5; Sat, 12 Oct 2024 03:09:37 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="BqCWAj++"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8AFB210E12D; Sat, 12 Oct 2024 03:09:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1728702576; x=1760238576; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eDYn9CA15hgY4hqNjoe/pPWJsBfriIPOsrPKZd/YuUw=; b=BqCWAj++49exPjOzoZGUz02zghbKFDyGKFLyI9XwTVN5GaxvwzqHsTma ZbVSz8o3ZXUgwEmdEFzPsY0y6FUgOS5dmiqsqcTezimn/OP+/Q3JbPnXB kN/M+daW/uh42FfDJAV+id9WGDrTnkpPTLevNblXWciN13h4ikJ155UcG 9o0M/YxqAidqOFfVQuT0cBhzORIrXxirW4sFNXMZV7oobD8yzdkCg+vVT mHTAdkuz+8wIzIwV67n+qhdWiRySu8niAPdXnrz4aDuwe/olAlzG3XOaW uo4kKEKaIv9yGwFInCGiw2Do2lEdxvDeyKBCtXAI8WiJs3r8UiaZg9vy+ A==; X-CSE-ConnectionGUID: GTODDr05TG2xEjZj1o/CYA== X-CSE-MsgGUID: n4aZ3/L1Qn2lOy3zMuct0Q== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="38687321" X-IronPort-AV: E=Sophos;i="6.11,197,1725346800"; d="scan'208";a="38687321" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2024 20:09:36 -0700 X-CSE-ConnectionGUID: H/e6jO5sTgyglego/Br+HQ== X-CSE-MsgGUID: LEwcwPawScG+PfijhdjDyw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,197,1725346800"; d="scan'208";a="77278464" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2024 20:09:36 -0700 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: Vivek Kasireddy Subject: [PATCH v1 3/5] drm/xe/pf: Add a helper function to get a VF's starting address in LMEM Date: Fri, 11 Oct 2024 19:40:25 -0700 Message-ID: <20241012024524.1377836-4-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241012024524.1377836-1-vivek.kasireddy@intel.com> References: <20241012024524.1377836-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 region starts. The function introduced in this patch does just that by returning the DPA associated with the BO that backs the VF's region in LMEM. 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..b1da329244d0 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_addr - Get VF's LMEM starting addr. + * @gt: the &xe_gt + * @vfid: the VF identifier + * + * This function can only be called on PF. + * + * Return: VF's starting address in LMEM. + */ +dma_addr_t xe_gt_sriov_pf_config_get_lmem_addr(struct xe_gt *gt, + unsigned int vfid) +{ + struct xe_gt_sriov_config *config; + dma_addr_t addr; + + mutex_lock(xe_gt_sriov_pf_master_mutex(gt)); + config = pf_pick_vf_config(gt, vfid); + addr = xe_bo_addr(config->lmem_obj, 0, PAGE_SIZE); + mutex_unlock(xe_gt_sriov_pf_master_mutex(gt)); + + return addr; +} + /** * 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..af9995f094a9 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); +dma_addr_t xe_gt_sriov_pf_config_get_lmem_addr(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 Sat Oct 12 02:40:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13833772 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 893D4D1A42C for ; Sat, 12 Oct 2024 03:09:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1AF4010EB5D; Sat, 12 Oct 2024 03:09:38 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="WNOGValn"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id AD6AA10E03B; Sat, 12 Oct 2024 03:09:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1728702576; x=1760238576; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PFza0TtHaC3abrubGqSXztrJzNM2pxqj1Fc30IEbi90=; b=WNOGValnMv6fCStvePHFjYZIy4S7DU7CtKrfnzc5ni5I90b1P210QI4m Ggqzty/bdE+zqqY+aDfpocDkq5jrnvRchJdDs0Lmdixlk5Q7dqocvk80j ldvGng2n8K+1jRDMphr9icwHdnwSwWPJcXcvQ9sMa+ABbkpC1gMYurTPQ VPasj/rCc4AMHFGoq+xsT13aZSLzk8tPoorocJpRZ6+fx9gNgEsHz2ty6 cXC7BOflkI0jfaUsYsqesonxHZd/ZWcpo+p811duRqL0+aE6MHaXTEkXa kWHx51ph68XYEEjJmKGMrwislbvvh+OqM8oBzaL1znTZ0XTn1JFLzaV42 w==; X-CSE-ConnectionGUID: mLT5thl6TFmZZXKDRAIIog== X-CSE-MsgGUID: zk/MUiJmQKaiG5Kb2KaE0Q== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="38687322" X-IronPort-AV: E=Sophos;i="6.11,197,1725346800"; d="scan'208";a="38687322" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2024 20:09:36 -0700 X-CSE-ConnectionGUID: O2U/C1z7QdOBev1tClqUlw== X-CSE-MsgGUID: yRUn/J0MRwKXWMvKIUpxWQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,197,1725346800"; d="scan'208";a="77278467" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2024 20:09:36 -0700 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: Vivek Kasireddy Subject: [PATCH v1 4/5] drm/xe/bo: Create a new sg for dmabuf BOs that are associated with a VF Date: Fri, 11 Oct 2024 19:40:26 -0700 Message-ID: <20241012024524.1377836-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241012024524.1377836-1-vivek.kasireddy@intel.com> References: <20241012024524.1377836-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 device. After we confirm that they belong to a VF, we convert the DMA addresses (IOVAs in this case) to DPAs and create a new sg and populate it with the new addresses. Signed-off-by: Vivek Kasireddy --- drivers/gpu/drm/xe/xe_bo.c | 108 ++++++++++++++++++++++++++++++- drivers/gpu/drm/xe/xe_bo_types.h | 6 ++ 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index c74c121ea7bb..64efe1b21f19 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,102 @@ 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 xe_device *xe, + struct sg_table *sg, + struct sg_table *new_sg, + struct pci_dev *pdev) +{ + resource_size_t io_start = pci_resource_start(pdev, LMEM_BAR); + struct xe_gt *gt = xe_root_mmio_gt(xe); + struct scatterlist *sgl, *new_sgl; + int i, vfid = pci_iov_vf_id(pdev); + dma_addr_t new_addr, bo_addr; + struct iommu_domain *domain; + phys_addr_t phys; + u64 offset; + + bo_addr = xe_gt_sriov_pf_config_get_lmem_addr(gt, ++vfid); + domain = iommu_get_domain_for_dev(xe->drm.dev); + + new_sgl = new_sg->sgl; + for_each_sgtable_dma_sg(sg, sgl, i) { + phys = domain ? iommu_iova_to_phys(domain, sg_dma_address(sgl)) : + sg_dma_address(sgl); + offset = phys - io_start; + new_addr = bo_addr + offset; + + sg_set_page(new_sgl, NULL, sg_dma_len(sgl), 0); + sg_dma_address(new_sgl) = new_addr; + sg_dma_len(new_sgl) = sg_dma_len(sgl); + + new_sgl = sg_next(new_sgl); + } +} + +static struct sg_table *xe_bo_create_new_sg(struct sg_table *sg, + struct xe_bo *bo) +{ + struct xe_device *xe = xe_bo_device(bo); + struct iommu_domain *domain; + struct sg_table *new_sg; + struct pci_dev *pdev; + phys_addr_t phys; + int vfid; + + if (!IS_SRIOV_PF(xe)) + return sg; + + domain = iommu_get_domain_for_dev(xe->drm.dev); + phys = domain ? iommu_iova_to_phys(domain, sg_dma_address(sg->sgl)) : + sg_dma_address(sg->sgl); + + if (page_is_ram(PFN_DOWN(phys))) + return sg; + + pdev = xe_find_vf_dev(xe, phys); + if (!pdev) + return sg; + + vfid = pci_iov_vf_id(pdev); + if (vfid < 0) + return sg; + + new_sg = kzalloc(sizeof(*new_sg), GFP_KERNEL); + if (!new_sg) + return sg; + + if (sg_alloc_table(new_sg, sg->nents, GFP_KERNEL)) { + kfree(new_sg); + return sg; + } + + bo->is_devmem_external = true; + xe_bo_translate_iova_to_dpa(xe, sg, new_sg, pdev); + + return new_sg; +} + /* * The dma-buf map_attachment() / unmap_attachment() is hooked up here. * Note that unmapping the attachment is deferred to the next @@ -577,7 +677,7 @@ static int xe_bo_move_dmabuf(struct ttm_buffer_object *ttm_bo, return PTR_ERR(sg); ttm_bo->sg = sg; - xe_tt->sg = sg; + xe_tt->sg = xe_bo_create_new_sg(sg, ttm_to_xe_bo(ttm_bo)); out: ttm_bo_move_null(ttm_bo, new_res); @@ -1066,6 +1166,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 +1181,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 && xe_tt->sg != ttm_bo->sg) { + sg_free_table(xe_tt->sg); + kfree(xe_tt->sg); + } 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 8b9201775081..0fe619bc436d 100644 --- a/drivers/gpu/drm/xe/xe_bo_types.h +++ b/drivers/gpu/drm/xe/xe_bo_types.h @@ -67,6 +67,12 @@ struct xe_bo { /** @ccs_cleared */ bool ccs_cleared; + /** + * @is_devmem_external: Whether this BO is an imported dma-buf that + * has a backing store in VRAM. + */ + bool is_devmem_external; + /** * @cpu_caching: CPU caching mode. Currently only used for userspace * objects. Exceptions are system memory on DGFX, which is always From patchwork Sat Oct 12 02:40:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13833773 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 9BDA9D1A427 for ; Sat, 12 Oct 2024 03:09:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8DB5A10EB64; Sat, 12 Oct 2024 03:09:41 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="UVbDujtJ"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id D046310E12D; Sat, 12 Oct 2024 03:09:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1728702576; x=1760238576; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ebo1SegaNMj89+yiH94zvaeAmGSEGTceF7n5dRd9dfM=; b=UVbDujtJZQaaobEKe+ml+CZ+P0Db3szF5y0GI/8hW2Yv3bREkNfcr+mi a7QXxrJdNRyqE5zVjROZyu9yYyhuhV7zA06peynnBx5hiy7BKl+TRcWuD ktpEBn02CR+WkG0q0EXkUv5a2qC8+8aK32xPoa8K58VXmfrfkpXweuBOz w/x0QquyF1Ci28/d19CUkxutAHujyX/GluX+OOoVR75WyZ6xEAYJiQeVR ZrTFTeVB0qlYsct0zciurXmp+d4WKrDSXl/9smwXJmo0OP+molho3lLZa v7poe59/8108jEfqu5IJvDwW+3ZCbsJufTmsF7pOfL+l9zC5qwUTQL0k4 A==; X-CSE-ConnectionGUID: H4qW9KXkRo6GDmkhvJ70jw== X-CSE-MsgGUID: JWX5yfGySo+Bg8+8PbbApQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="38687323" X-IronPort-AV: E=Sophos;i="6.11,197,1725346800"; d="scan'208";a="38687323" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2024 20:09:36 -0700 X-CSE-ConnectionGUID: 2IdKiDezTVCJBdRBsDXTKw== X-CSE-MsgGUID: I2IIRz82T4acY+quH5+Nvg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,197,1725346800"; d="scan'208";a="77278470" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2024 20:09:36 -0700 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: Vivek Kasireddy Subject: [PATCH v1 5/5] drm/xe/pt: Add an additional check for dmabuf BOs while updating PTEs Date: Fri, 11 Oct 2024 19:40:27 -0700 Message-ID: <20241012024524.1377836-6-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241012024524.1377836-1-vivek.kasireddy@intel.com> References: <20241012024524.1377836-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. Signed-off-by: Vivek Kasireddy --- drivers/gpu/drm/xe/xe_pt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_pt.c b/drivers/gpu/drm/xe/xe_pt.c index f27f579f4d85..909e5b96d518 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));