From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.201.30 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796108921; b=gzrs+rd5LclAbfOLfkUig4fopvy+NHPeOo7ux1fKYVC1AO110IGH7m7AeSfByOGBuaYE LzAElgZGbutB83K7KU9yAfoMBpHpH3fzPinEZanG5oLwHJgJfFx/OLM91rJ2snR+2p5kG +F2QKtApetZVc0sCGvj0KeMZkiAYQZMmq6oyJpEyvOpV/6sHw5lpnQuUHBH2zBH5qAV1S 6PEawTa7AZ3hTS5HnWkGeyXKvEwYAUUaC+CNsbrXKAuyiORuNUdvm0RSZCsfssTD9psvu A7EDo0rtFa8qAFPE0gFSAIcgh32yJ0T1A0syYAQQHvzXhz+cWCZuTPpefXHp6kyTv2g== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796108921; h=DMARC-Filter:DKIM-Signature:Received:Received:From:Date:Subject: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature:X-Developer-Key: X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=Ky7FGlQMwPzgEYpdmwHfv+gfsW6UicVzLedgyTDBo3s=; b=UWOrGIuZpYZTs27maxaPx/0rqf6dvH382BYatfwBxjDWjgCRYxY35aqn2kVUQUmHAg5D 1HRM9J6xKSQ8U/z3JYe9EVwP9W2E5EnXiYOGl/mEpLWKDOcNmg6HfeUTXexutKToX5d+i 7AXJsenIM8JqK5gYeAXR3XLsSMXEGU0gwEcaMxCm+sa8JIAiYKF6LKd+8OruTscWnC8oO 18M1eymsq/PwnJ7W6jzWau/W8M2mGUqUWVLQue0ikP8xjRQIjwkD4DUl2idroqYtN58Uw SOqE1moaO1yvKRFal6DMH0q5WDPq3IK5FwFhX3Aa4myFVKwjDP2qD2ODlnKYyj/q51w== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=K5JsnnLB; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.201.30 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013030.outbound.protection.outlook.com [40.93.201.30]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20E40606A6A0; Tue, 1 Dec 2026 07:08:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 20E40606A6A0 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=K5JsnnLB ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Y0ETC+8ZKQ1LtlENx/tLyOuVqdBs2bXW62fe0M9Rq411gJbXSeL/5QIEypP3+oT6X4xOwMfrEb+5SKIv0+A4V+jRhXu/gGanzxW5n8prbuv4C+dS4G29pJFL69CKgL1emNF/LPZNfBR7DlFrteDJe/UKAjfjSCAATYlNTWv0kGWmLLVS+eI7LBLF16P6+8EOMadhsF/0Mo1MMn8r2HO/2rmVWPjlOkCbIZ88cz5IyafW9PYKCiY+rDj1yfNwMq9Tugtg086PBk6Dq3drJRLpHeZqfTZwKEIslz/3rijjfwW/XMPhv2sxvTtoXyNzkDwPM8VSYtZOlCfuHjm9f2BeZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ky7FGlQMwPzgEYpdmwHfv+gfsW6UicVzLedgyTDBo3s=; b=jl8znBeK3O0ijubMvOySX5wdJprxrrtJFG0z8W+At/rSQQBVbVy7dcaKHkkYe23pkz2QxvvVNHg/WwSq3gn2dUzs2KsVySpAJsIQ0wxH8ieNYTp/Wtg3ALw+gj+VVvHSKKzidOJCpXrRqpL4civMrgRT4a/tWNYP4JDDv9ws1Hdt35NtAU0e/FUBiT+XPxIe6Xy4T4XrCzTi09UzUYxzvMEFxqQ55fVOQNgePV+o+5ZAlQTMrwedeT0K8soXyepmtainPkxlm3P6akEfGlHJ7zaPsJdf+ZMDfibOZnKIiPfD1Axr2BopNX7JchXLRJCFvj+COBikRM9yjewPD6obhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ky7FGlQMwPzgEYpdmwHfv+gfsW6UicVzLedgyTDBo3s=; b=K5JsnnLBcpY06xpKKs/nw3XfClFI5qM1/XjOUszdWfdQRgTbDL1a4/GxdLDPVD5gL9grX7BCICWOY0s56V1hU6+Fhafk9l+b4BmS3xoipGgCKH/GYPFwcUtY0ervQQhuaT0wt4QKOnrXGb5PNdi/AAVRSiKTJGoH66ZKeKUkPQd4aaRrWQSNGD8Eoih1J+8+YdaDOW3nIOotfGRLKCp0hE8dNzvo90IjQ1qImRdk9Hc7lVGHz2ks49ZcQrPXMheJ+pyihB0SVSPBSe09yp/aN4NHMlH/oU7OiOapQhMnwhjX+ryDngT2Bm+cEfqsvZD9wL/h2986eD/Qio2xnVGCFg== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from SA3PR12MB598757.namprd12.prod.outlook.com (2603:10b6:806:52d::14) by PH8PR12MB6721.namprd12.prod.outlook.com (2603:10b6:510:1cc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.12; Tue, 1 Dec 2026 07:08:26 +0000 Received: from SA3PR12MB598757.namprd12.prod.outlook.com ([fe80::e206:100:5946:a777]) by SA3PR12MB598757.namprd12.prod.outlook.com ([fe80::e206:100:5946:a777%5]) with mapi id 15.21.0688.009; Tue, 1 Dec 2026 07:08:26 +0000 From: Alistair Popple Date: Tue, 01 Dec 2026 18:06:32 +1100 Subject: [PATCH RFC 16/16] drm/xe: Import DMA-bufs as a DMA address list Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261201-dmabuf_shared_buf_v1_xe_rc5-v1-16-b672717c7fc9@nvidia.com> References: <20261201-dmabuf_shared_buf_v1_xe_rc5-v1-0-b672717c7fc9@nvidia.com> In-Reply-To: <20261201-dmabuf_shared_buf_v1_xe_rc5-v1-0-b672717c7fc9@nvidia.com> To: Karol Wachowski , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Philipp Stanner , David Airlie , Simona Vetter , Rodrigo Vivi , Matthew Brost , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Jason Gunthorpe , Leon Romanovsky , Kees Cook , "Gustavo A. R. Silva" , Alex Williamson , Kevin Tian , "Joerg Roedel (AMD)" , Will Deacon , Robin Murphy Cc: dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, intel-xe@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, kvm@vger.kernel.org, iommu@lists.linux.dev, Alexey Kardashevskiy , Mina Almasry , Baolu Lu , chaitanyak@nvidia.com, Dongwon Kim , Felix Kuehling , jhubbard@nvidia.com, Karl Mehltretter , Vivek Kasireddy , Xu Yilun , zhipingz@meta.com, Alistair Popple X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796108809; l=11594; i=apopple@nvidia.com; s=20261105; h=from:subject:message-id; bh=yJWeCsXnhMKB2uvUXkWN1C7QgqTGG6nAMgjeDPfSrE4=; b=PFM6DEtzmECcIirX4z8wc9W2qBf2Y55ba5nhiReBPY/LF5mJP1balHnQ58yp4wKV7ydvBZJHh gg7hoLlY0LcC6s7ugPRdnV/3ZP9xcVV673p52SI28BZoNNdWKPUJ94f X-Developer-Key: i=apopple@nvidia.com; a=ed25519; pk=WdWPT9rAq3YNfXldbGv1NSGVLGxzQGFGJvRUiShhNqs= X-ClientProxiedBy: SY5P282CA0059.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:20a::19) To DS4PR12MB634945.namprd12.prod.outlook.com (2603:10b6:8:514::7) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA3PR12MB598757:EE_|PH8PR12MB6721:EE_ X-MS-Office365-Filtering-Correlation-Id: e8b4307b-2154-48d9-6bb7-08df4f79e4f2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016|23010399003|11063799006|261009223027099003|18002099003|22082099003|921020|10067099003|261028144727099003|56012099006|261026121527099003|261102130727099003|261026140227099003|261022075727099003|261021121427099003|261022105027099003|261102123227099003|261021123027099003; X-Microsoft-Antispam-Message-Info: LI/N7F9C5MzA5m5u1XpqJB8XPN2mEa+yHMHwXfG2dC0TMJMFLh+Xer43sQevvXpXgJw9M9K12p2qe38egl1kJh7n2XnmW02bN+CWgRaydENfo1OP+IIHzyxHMrCj/+FeKhOrLctjryr4XH25Fk0oJ0s3JVlIxPu25VBHKi0S8IprJQhSoKe7tixXTjVsw/tMXBw8IE0PVaLpj+JJPGIeukI6Lg+4cPiAAdTeQqYYwNToOsgpOOhQXKi/ulwXseCFic5D0UrhXDxUTYIS4UAnro/at7xTatIGygrHxtKegv6f+xO7/Z1I8Simcp69vqViDa1lLLCg7vbZlMCc4TP1SyJ2VXLjgFR+QilJLMURyhSm5GxZ2UF/9/BRJojlkMqq4ngbq/o/6lcfCU29MOFYwno0DQ3H8PZG3IEd+e037XTYjdrYxJHZCC4gjPIUhxzHh1/ckeEthbqX5X8Dh4FcBGF4q7DYKFmZaqdxFeYv+iDOJfdu1Itx0zOKREWIw1BoncaxQp6+dNUHIDEi3Ulf5DNqsMxjK1RJW980LuhnZgmjKsTpMdCbNJMSpkWJekDbB4qancAyfpP2jMY89QSX0V437+GTf4MSEnTBn4HXEB0YuC8W75y+E5HTgI/fj1slRTI/XTMwQABCBAniGPwLPARjX+WCcaqGnZg41Upcj5l47fJMwfBncb31qJvROPaGRjrc7C7IFfgUfwxzcex/LA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA3PR12MB598757.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(366016)(23010399003)(11063799006)(261009223027099003)(18002099003)(22082099003)(921020)(10067099003)(261028144727099003)(56012099006)(261026121527099003)(261102130727099003)(261026140227099003)(261022075727099003)(261021121427099003)(261022105027099003)(261102123227099003)(261021123027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?azlJTXgxZHNyekNiSklXS1lUOWZ5aHNsYTcyTGNka3BjL3R1SXV3SlRENHdR?= =?utf-8?B?WXU2T1I5T3R3cmRvc1NsRzlVL3NRUGtmUVQ4THdJTy80ZnYyT09SRmltR1Vr?= =?utf-8?B?NFJSSSs4Q015UVh4cTRUdXhqd0hJRzIrcDVFbjlnb3d3ZjVVZ1pFbnUxNUtG?= =?utf-8?B?Q2hiMnB4Y3EyTzhPaVIvNitRMkNDTUZaREVGdXlNWkNSVllIUnNzS2w0Y25h?= =?utf-8?B?RVBLUTVQcStYdDRQSnJnNGhEeE9pdUJTeFB3cmppYm1idUxLaDNkRzc0cGxS?= =?utf-8?B?WXNENC80Z1R5UWFOQ1A4ZXVrdzk4MDRoYjZBMVJnMjJ5Zit6YWphQWM4UmVE?= =?utf-8?B?dTVpTHVoRzhkTTVZWFJ2WUk0Q2x6MUw4RmlxTWlqZzNjcjlwaE9JUnY3WTln?= =?utf-8?B?cFJmUm9FbWY5dGc3bEVGVmFTbUVCZ3A5S0ZZL3JFbjJGdGJQLzZ6TG42MUY2?= =?utf-8?B?cEhhWk5IY3lKaFFwY2hEb3NVVHBtUWZmaTJMb3B0M1pkRUxLZjgvSHFDY3pq?= =?utf-8?B?dndjamFhQThwR09ZRVdEU2thMzVKV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-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e8b4307b-2154-48d9-6bb7-08df4f79e4f2 X-MS-Exchange-CrossTenant-AuthSource: DS4PR12MB634945.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 07:08:26.5064 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UsEqF/BEHNxKtPLgHHoEY0wN92SJwCR3JqpADNHSAzIvMO310CDKolOki721ijP6EcRF+d3FM7uki0u+UqknDg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6721 Xe maps an imported DMA-buf with dma_buf_map_sgt() and keeps the sg_table as the backing of the buffer object. However the only thing it ever reads from the table is the DMA address and length of each entry, which the resource cursor walks when the buffer is bound to a VM or mapped into the GGTT. Map the attachment with dma_buf_map_dma_list() instead, which returns just the DMA address ranges of the buffer. The list is kept in struct xe_bo for as long as the buffer is mapped. It takes over from the sg pointer in the TTM buffer object, which Xe no longer sets, as the record of whether the attachment is mapped. Add xe_res_first_bo_dma() to start a walk over either the list of an imported buffer or the sg_table of a buffer's own pages, and use it where an imported buffer can turn up: binding to a VM, mapping into the GGTT and xe_bo_addr(). The other users of xe_bo_sg() only ever see buffers which Xe allocated itself so they are left alone. This works with any exporter. The DMA-buf core copies the addresses out of the sg_table of an exporter which still maps one itself. Signed-off-by: Alistair Popple --- Note it wouldn't be too difficult to remove sg_table usage entirely and instead use a dma_shared_buf. However this change is meant as an example for how drivers could be switched to the new interface, so I haven't done that. --- drivers/gpu/drm/xe/xe_bo.c | 52 +++++++++++-------------- drivers/gpu/drm/xe/xe_bo_types.h | 6 +++ drivers/gpu/drm/xe/xe_ggtt.c | 2 +- drivers/gpu/drm/xe/xe_pt.c | 4 +- drivers/gpu/drm/xe/xe_res_cursor.h | 78 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 33 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index 14b71d951659..475df4f24966 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -856,37 +856,35 @@ static int xe_bo_move_dmabuf(struct ttm_buffer_object *ttm_bo, struct ttm_resource *new_res) { struct dma_buf_attachment *attach = ttm_bo->base.import_attach; - struct xe_ttm_tt *xe_tt = container_of(ttm_bo->ttm, struct xe_ttm_tt, - ttm); + struct xe_bo *bo = ttm_to_xe_bo(ttm_bo); struct xe_device *xe = ttm_to_xe_device(ttm_bo->bdev); bool device_unplugged = drm_dev_is_unplugged(&xe->drm); - struct sg_table *sg; + const struct dma_addr_list *list; xe_assert(xe, attach); xe_assert(xe, ttm_bo->ttm); if (device_unplugged && new_res->mem_type == XE_PL_SYSTEM && - ttm_bo->sg) { + bo->dma_list) { dma_resv_wait_timeout(ttm_bo->base.resv, DMA_RESV_USAGE_BOOKKEEP, false, MAX_SCHEDULE_TIMEOUT); - dma_buf_unmap_sgt(attach, ttm_bo->sg, DMA_BIDIRECTIONAL); - ttm_bo->sg = NULL; + dma_buf_unmap_dma_list(attach, bo->dma_list, DMA_BIDIRECTIONAL); + bo->dma_list = NULL; } if (new_res->mem_type == XE_PL_SYSTEM) goto out; - if (ttm_bo->sg) { - dma_buf_unmap_sgt(attach, ttm_bo->sg, DMA_BIDIRECTIONAL); - ttm_bo->sg = NULL; + if (bo->dma_list) { + dma_buf_unmap_dma_list(attach, bo->dma_list, DMA_BIDIRECTIONAL); + bo->dma_list = NULL; } - sg = dma_buf_map_sgt(attach, DMA_BIDIRECTIONAL); - if (IS_ERR(sg)) - return PTR_ERR(sg); + list = dma_buf_map_dma_list(attach, DMA_BIDIRECTIONAL); + if (IS_ERR(list)) + return PTR_ERR(list); - ttm_bo->sg = sg; - xe_tt->sg = sg; + bo->dma_list = list; out: ttm_bo_move_null(ttm_bo, new_res); @@ -1749,12 +1747,11 @@ int xe_bo_dma_unmap_pinned(struct xe_bo *bo) if (tt) { struct xe_ttm_tt *xe_tt = container_of(tt, typeof(*xe_tt), ttm); - if (ttm_bo->type == ttm_bo_type_sg && ttm_bo->sg) { - dma_buf_unmap_sgt(ttm_bo->base.import_attach, - ttm_bo->sg, - DMA_BIDIRECTIONAL); - ttm_bo->sg = NULL; - xe_tt->sg = NULL; + if (bo->dma_list) { + dma_buf_unmap_dma_list(ttm_bo->base.import_attach, + bo->dma_list, + DMA_BIDIRECTIONAL); + bo->dma_list = NULL; } else if (xe_tt->sg) { dma_unmap_sgtable(ttm_to_xe_device(ttm_bo->bdev)->drm.dev, xe_tt->sg, @@ -1863,14 +1860,10 @@ static void xe_ttm_bo_delete_mem_notify(struct ttm_buffer_object *ttm_bo) * Object is idle and about to be destroyed. Release the * dma-buf attachment. */ - if (ttm_bo->type == ttm_bo_type_sg && ttm_bo->sg) { - struct xe_ttm_tt *xe_tt = container_of(ttm_bo->ttm, - struct xe_ttm_tt, ttm); - - dma_buf_unmap_sgt(ttm_bo->base.import_attach, ttm_bo->sg, - DMA_BIDIRECTIONAL); - ttm_bo->sg = NULL; - xe_tt->sg = NULL; + if (bo->dma_list) { + dma_buf_unmap_dma_list(ttm_bo->base.import_attach, bo->dma_list, + DMA_BIDIRECTIONAL); + bo->dma_list = NULL; } } @@ -3453,8 +3446,7 @@ dma_addr_t __xe_bo_addr(struct xe_bo *bo, u64 offset, size_t page_size) if (!xe_bo_is_vram(bo) && !xe_bo_is_stolen(bo)) { xe_assert(xe, bo->ttm.ttm); - xe_res_first_sg(xe_bo_sg(bo), page << PAGE_SHIFT, - page_size, &cur); + xe_res_first_bo_dma(bo, page << PAGE_SHIFT, page_size, &cur); return xe_res_dma(&cur) + offset; } else { struct xe_res_cursor cur; diff --git a/drivers/gpu/drm/xe/xe_bo_types.h b/drivers/gpu/drm/xe/xe_bo_types.h index 8ec4a01a0092..dd00fae0610e 100644 --- a/drivers/gpu/drm/xe/xe_bo_types.h +++ b/drivers/gpu/drm/xe/xe_bo_types.h @@ -17,6 +17,7 @@ #include "xe_device_types.h" #include "xe_ggtt_types.h" +struct dma_addr_list; struct xe_device; struct xe_mem_pool_node; struct xe_vm; @@ -39,6 +40,11 @@ struct xe_bo { struct xe_bo *parent_obj; /** @dma_buf: Imported dma-buf ref to keep its resv alive. */ struct dma_buf *dma_buf; + /** + * @dma_list: DMA addresses of an imported dma-buf whilst it is mapped, + * NULL otherwise. Protected by the BO dma_resv. + */ + const struct dma_addr_list *dma_list; /** @flags: flags for this buffer object */ u32 flags; /** @vm: VM this BO is attached to, for extobj this will be NULL */ diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c index b7c55dc8a0bb..21ea116a5f1c 100644 --- a/drivers/gpu/drm/xe/xe_ggtt.c +++ b/drivers/gpu/drm/xe/xe_ggtt.c @@ -741,7 +741,7 @@ static void xe_ggtt_map_bo(struct xe_ggtt *ggtt, struct xe_ggtt_node *node, if (!xe_bo_is_vram(bo) && !xe_bo_is_stolen(bo)) { xe_assert(xe_bo_device(bo), bo->ttm.ttm); - for (xe_res_first_sg(xe_bo_sg(bo), 0, xe_bo_size(bo), &cur); + for (xe_res_first_bo_dma(bo, 0, xe_bo_size(bo), &cur); cur.remaining; xe_res_next(&cur, XE_PAGE_SIZE)) ggtt->pt_ops->ggtt_set_pte(ggtt, end - cur.remaining, pte | xe_res_dma(&cur)); diff --git a/drivers/gpu/drm/xe/xe_pt.c b/drivers/gpu/drm/xe/xe_pt.c index aeeac0f1ab83..b745de5210df 100644 --- a/drivers/gpu/drm/xe/xe_pt.c +++ b/drivers/gpu/drm/xe/xe_pt.c @@ -887,8 +887,8 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma, xe_res_first(bo->ttm.resource, 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); + xe_res_first_bo_dma(bo, xe_vma_bo_offset(vma), + xe_vma_size(vma), &curs); } else if (!range) { curs.size = xe_vma_size(vma); } diff --git a/drivers/gpu/drm/xe/xe_res_cursor.h b/drivers/gpu/drm/xe/xe_res_cursor.h index c3a037e5f34e..e6541b0c3eb0 100644 --- a/drivers/gpu/drm/xe/xe_res_cursor.h +++ b/drivers/gpu/drm/xe/xe_res_cursor.h @@ -24,6 +24,7 @@ #ifndef _XE_RES_CURSOR_H_ #define _XE_RES_CURSOR_H_ +#include #include #include @@ -57,6 +58,8 @@ struct xe_res_cursor { struct scatterlist *sgl; /** @dma_addr: Current element in a struct drm_pagemap_addr array */ const struct drm_pagemap_addr *dma_addr; + /** @dma_range: Current range of a struct dma_addr_list */ + const struct dma_addr_range *dma_range; /** @mm: Buddy allocator for VRAM cursor */ struct gpu_buddy *mm; /** @@ -93,6 +96,7 @@ static inline void xe_res_first(struct ttm_resource *res, { cur->sgl = NULL; cur->dma_addr = NULL; + cur->dma_range = NULL; if (!res) goto fallback; @@ -172,6 +176,21 @@ static inline void __xe_res_sg_next(struct xe_res_cursor *cur) cur->sgl = sgl; } +static inline void __xe_res_dma_list_next(struct xe_res_cursor *cur) +{ + const struct dma_addr_range *range = cur->dma_range; + u64 start = cur->start; + + while (start >= range->len) { + start -= range->len; + range++; + } + + cur->start = start; + cur->size = range->len - start; + cur->dma_range = range; +} + /** * __xe_res_dma_next() - Advance the cursor when end-of-segment is reached * @cur: The cursor @@ -222,11 +241,61 @@ static inline void xe_res_first_sg(const struct sg_table *sg, cur->remaining = size; cur->size = 0; cur->dma_addr = NULL; + cur->dma_range = NULL; cur->sgl = sg->sgl; cur->mem_type = XE_PL_TT; __xe_res_sg_next(cur); } +/** + * xe_res_first_dma_list - initialize a xe_res_cursor with a DMA address list + * + * @list: DMA address list of an imported dma-buf to walk + * @start: Start of the range + * @size: Size of the range + * @cur: cursor object to initialize + * + * Start walking over the range of allocations between @start and @size. + */ +static inline void xe_res_first_dma_list(const struct dma_addr_list *list, + u64 start, u64 size, + struct xe_res_cursor *cur) +{ + XE_WARN_ON(!list); + XE_WARN_ON(start + size > list->size); + cur->node = NULL; + cur->start = start; + cur->remaining = size; + cur->size = 0; + cur->dma_addr = NULL; + cur->sgl = NULL; + cur->dma_range = list->ranges; + cur->mem_type = XE_PL_TT; + __xe_res_dma_list_next(cur); +} + +/** + * xe_res_first_bo_dma - initialize a xe_res_cursor with the DMA addresses of + * a buffer object + * + * @bo: buffer object to walk, which must not be in VRAM or stolen memory + * @start: Start of the range + * @size: Size of the range + * @cur: cursor object to initialize + * + * Start walking over the range of allocations between @start and @size. The + * addresses are those of the exporter's DMA address list for an imported + * dma-buf and those of the buffer object's own pages otherwise. + */ +static inline void xe_res_first_bo_dma(struct xe_bo *bo, u64 start, u64 size, + struct xe_res_cursor *cur) +{ + if (bo->dma_list) + xe_res_first_dma_list(bo->dma_list, start, size, cur); + else + xe_res_first_sg(xe_bo_sg(bo), start, size, cur); +} + /** * xe_res_first_dma - initialize a xe_res_cursor with dma_addr array * @@ -255,6 +324,7 @@ static inline void xe_res_first_dma(const struct drm_pagemap_addr *dma_addr, cur->dma_addr = dma_addr; __xe_res_dma_next(cur); cur->sgl = NULL; + cur->dma_range = NULL; cur->mem_type = XE_PL_TT; } @@ -296,6 +366,12 @@ static inline void xe_res_next(struct xe_res_cursor *cur, u64 size) return; } + if (cur->dma_range) { + cur->start += size; + __xe_res_dma_list_next(cur); + return; + } + switch (cur->mem_type) { case XE_PL_STOLEN: /* Just advance within the contiguous region. */ @@ -339,6 +415,8 @@ static inline u64 xe_res_dma(const struct xe_res_cursor *cur) return cur->dma_start + cur->start; else if (cur->sgl) return sg_dma_address(cur->sgl) + cur->start; + else if (cur->dma_range) + return cur->dma_range->addr + cur->start; else return cur->start; } -- 2.54.0