From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30182606A322 for ; Wed, 2 Dec 2026 22:25:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=HVL6SCq5 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DB4C510E4F2; Wed, 2 Dec 2026 22:25:37 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 753D110E4F2; Wed, 2 Dec 2026 22:25:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796250333; x=1827786333; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=tTDVBPu0HUFI7Ltcm4KutkrfUhpT2eJivV1KIjVSea0=; b=HVL6SCq5My8AAyqkEXgXRy/XHoNuk73Jk/8QttVifY1tgNHcKxvsZ3kg Yz647mDHxStCn9fCdL0MUTptFvDYKOo+FIzu3UK9Yp8dCcbXzpUCph5g9 DkIEV7Gz2NGLiBiT+FSAfRVU5KYiBuoxEn8IWVL9C0/SMHw5g59nmJqqm /YjRuXzkUu/cfzIwc3hQLHkQUvCF+Bn3+pKyPO1IFT9oYOJxuPD3WWkfC M1fUlVuNdoGdmxLbzDkpVlrWFNhwdPgzbEOTa1P5NQsTtOZBC/fgR0TYB NK5MMov61LNQKGdO0K43U7Oax3Hr30cpa1UHDCJZgxoGPvpLs2JKyrpgU A==; X-CSE-ConnectionGUID: NCkrChUVQ82dXZrnI/Htdw== X-CSE-MsgGUID: 2WN2l6ewTxGo1NPT6/Z12w== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5236020" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5236020" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 14:25:32 -0800 X-CSE-ConnectionGUID: S3xZ4ZQwTsiOLS9p/anokw== X-CSE-MsgGUID: 975vzCcqR3GT/OMgebRW9A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="14160861" Received: from orsmsx902.amr.corp.intel.com ([10.22.229.24]) by fmviesa001.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 14:25:32 -0800 Received: from ORSMSX903.amr.corp.intel.com (10.22.229.25) by ORSMSX902.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 14:25:31 -0800 Received: from ORSEDG901.ED.cps.intel.com (10.7.248.11) by ORSMSX903.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57 via Frontend Transport; Wed, 2 Dec 2026 14:25:31 -0800 Received: from SA9PR02CU001.outbound.protection.outlook.com (40.93.196.43) by edgegateway.intel.com (134.134.137.111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 14:25:30 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bNqoaTSRT2bejJv+vBRztA1P1muIA0dsVR/VHk6YVbagcYI+9zZICi5bVwOp5qfHQbed0xcqdZBC0umwBosB2mXP3LbOXE4T1aLI6Vb2HE9tFW6ASs4i1uLxpFlWxlEOCC0HYbWnzeNLaP4ucv/2jcMjR30Dpll1WAcFF9TS4BvkMCpSwuRE1wsVUMWtHNzx1YyMTFmpcuAzxQf1XxXVVduXTtr6RPR5zaigrSNJ1GOU890jBAZF+2wLOQdHRwuoEQQNg9qsQ0ndWwZ6Jg/lLAy5BMa0gJ4DBZyzad1UEAdjsoW56wjvNCud1B85Dbvz4PoPDHCd3+T4Ud5J98+lBA== 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=V49s5nYdoABDA98yoSfB0fWM6WauAPNVmf5+DeiCMLU=; b=QWk6jWGkZfWwOe1xrqQPlCadtGsYGT9nCYUKrXYRezrw+VZ/W+Fo0VdXYgJ68KzctEWLpRz29SfugoZ/cdqQ+07cWNOPNi0VysBLx9iV8ud3M5phW8xq8zZKTgrQaPziHQzpy3isZZH2xdoHnPMvV02F6e7hNObBJVl3RXILz7RrurzKuNOYHzgml4HC2m2o/UEFikDsvYu6fRUzNelWCL5emqPqDzt45+fBE8h//7BcQ4FwzWmuxKMBsd68RQFTG2X9VlSLkznSpLFQ5yt/EgmV/aZpNGf74hdY7tML1o3kTUI5Vn1VSK3zn9t4VMI0DX2MU89hDnonqBT6zQ+pdA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from CO1PR11MB4787.namprd11.prod.outlook.com (2603:10b6:303:95::23) by SJ2PR11MB7473.namprd11.prod.outlook.com (2603:10b6:a03:4d2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.11; Wed, 2 Dec 2026 22:25:21 +0000 Received: from CO1PR11MB4787.namprd11.prod.outlook.com ([fe80::e7eb:a872:53d1:21fd]) by CO1PR11MB4787.namprd11.prod.outlook.com ([fe80::e7eb:a872:53d1:21fd%4]) with mapi id 15.21.0688.009; Wed, 2 Dec 2026 22:25:21 +0000 Date: Wed, 2 Dec 2026 14:25:19 -0800 From: Matthew Brost To: CC: , Subject: Re: [PATCH v4 26/33] drm/xe: Use IOVA-based DMA mapping for eligible tt BOs Message-ID: References: <20261201234915.3305331-1-matthew.brost@intel.com> <20261201234915.3305331-27-matthew.brost@intel.com> Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-ClientProxiedBy: MW4PR04CA0042.namprd04.prod.outlook.com (2603:10b6:303:6a::17) To CO1PR11MB4787.namprd11.prod.outlook.com (2603:10b6:303:95::23) X-Archived-By: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR11MB4787:EE_|SJ2PR11MB7473:EE_ X-MS-Office365-Filtering-Correlation-Id: 5bd2019e-2df2-46cd-e0df-08df50c32717 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|23010399003|366016|1800799024|376014|18002099003|22082099003|261102130727099003|10067099003|56012099006|261022105027099003|261026140227099003|261026121527099003|261022113327099003|261022075727099003|261021121427099003|261102123227099003|261028144727099003|261009223027099003|4143699003|11063799006|6133799003; X-Microsoft-Antispam-Message-Info: 97pylCeKFZCM94IoTofDtyMQfkKYnn7b5H67IPgWEqHXCx/ahEjUW5PUEIQ+L5Olmdo+SBjWLmo+bnsNm+cE/aF4fXXBq7mY3C2rF0F5s0GOW36Y6xsFNW1Uz2sd001AfDZKG/rUp6ENXIZs+vKoIZwyl1UceWMIyLNAcK7t4YI5zNl+13gGM5oKvpEZXPozy61yG6Uji9xwVh1Y2hrZW8+kbp2wAMJw52nPDnfcY0aK/ZnywsgYPCbN2NwCqRfVegFiFpObIghtlKt1zG/4ltjQFQQgisxFFZx2jcFDlvNWaNhnQWZfQkI8HeI4eusBT1cr0YddVx9Jwli0s2uUDS6HmU/oiMZ5mJ3TEB4lISA2pCBeKE1WO0nVUyKO1YyeGh1PMrMO86XAa7rihe7Qc+2sRHa9/t9U3AIM+toNLIIeKn7VqZXPUvR6KLXSuI9RqTq5D8g3R1Z1LJ0Fzp6Xwp4/8K7D0mLR/6yxW5JJ7v/MtdKJ3GkoM9UyZTeJAylH65FMy51nBEnFqwVUgp6Tmcrz1E27TYMvYrL7vWgEfUss1FbyGeJPORhiylITfpPcVq2AvkUOycHFOyARIXUc9IZuMSxl3TsUMvMJBfTLcRw= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO1PR11MB4787.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(18002099003)(22082099003)(261102130727099003)(10067099003)(56012099006)(261022105027099003)(261026140227099003)(261026121527099003)(261022113327099003)(261022075727099003)(261021121427099003)(261102123227099003)(261028144727099003)(261009223027099003)(4143699003)(11063799006)(6133799003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?C800MBbE/c8HhsGDV73ljheWtfMatIjXethYABqIxFt6JmGtd+NsycVgyV?= =?iso-8859-1?Q?1a5prOa8+hnuVQbVasUrXNn2u+Gq6WVhgqYeAhs48O4uWxlZ0UFb1ITxf5?= =?iso-8859-1?Q?v3otAOimS0CYei2FdhZ7u/kK0C7nUzuW3s0LZ0IB1qgBVcYmYWqawCNYNr?= =?iso-8859-1?Q?ss3V8WBYQiDGCFn6FQjE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g85NqFpBc2ttg5/3kpqD/6bYnS6zZN9UZVRUDoA2YCWyIBkEKaZC+/lAJu8gkaX/kvJ26Q52sAQ2g6Q/vEyk5AKU3W+s5V8bl0/LuCBTIjabLATD8rVZed73mYuu6uFG9znCh4r8h1pDEjKGDi2qb75utPCPe7WYFuye0TaI3JWEPRllZ9E/hftwdYzrnx4U0PnDO34rs7QQxg37kB85ag== X-MS-Exchange-CrossTenant-Network-Message-Id: 5bd2019e-2df2-46cd-e0df-08df50c32717 X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4787.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 22:25:21.5820 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lCT5qgmAx4IvsnwAt9rzwrMBMNtuYeed+mfbzYW2RacGLPluwrTspsbI5gC97NXGg83xtAP2vzQ3/eGC0gr5UQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR11MB7473 X-OriginatorOrg: intel.com X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Wed, Dec 02, 2026 at 01:03:36AM +0000, sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 4 potential > issues to consider: > - [High] drm/xe: missing unplug check in xe_tt_iova_reserve() strands > IOVA mappings > - [High] drm/xe: unlocked xe_tt_unmap_iova() call in > xe_bo_dma_unmap_pinned() > - [High] drm/xe: NULL iommu_group deref on unplug for scanout BOs using > IOVA mapping > - [Low] drm/xe: stale IOVA lifecycle and GGTT sg description in commit > message Aside from commit message, one these valid but not specific to the IOVA changes rather existing hotplug issues with dma-mappings. My plan 3 standlone fixes in the next rev prior to this patch. Also ofc I'll fix the commit message. Matt > -- > > commit 15b77bea89609de9937bc608810c99df9047f5f4 > Author: Matthew Brost > > drm/xe: Use IOVA-based DMA mapping for eligible tt BOs > > This commit adds support for mapping eligible ttm_tt pages into a single > contiguous IOVA range using the IOVA-based DMA API instead of a > scatter-gather list. > > > Whether the IOVA API can be used depends on the IOMMU mode, so the > > decision is made once per tt at xe_ttm_tt_create() time and recorded in > > struct xe_ttm_tt::use_iova. To keep the scope limited, only device BOs > > that are not GGTT-mapped are eligible: dma-buf imports manage their own > > mapping and GGTT bindings are programmed directly from the sg list. > > dma_iova_try_alloc() may still fail, in which case the tt transparently > > falls back to the sg list, which remains the default. > > > > The IOVA reservation is allocated at tt creation and freed at tt > > destroy. xe_tt_map_iova() links the tt pages (coalescing physically > > contiguous runs) and syncs the IOTLB; xe_tt_unmap_iova() unlinks them > > but keeps the reservation so the tt can be remapped without > > re-allocating IOVA space. xe_tt_map()/xe_tt_unmap() dispatch between the > > IOVA and sg backends, and xe_bo_dma_unmap_pinned() learns about the IOVA > > case. > > [Severity: Low] > Does the commit message still describe the pre-v4 IOVA reservation > lifecycle? > > In the v4 code, eligibility is recorded in xe_ttm_tt::iova_eligible (and > excludes XE_BO_FLAG_PINNED), xe_tt_iova_reserve() allocates the > reservation at map time and sets use_iova, and xe_tt_unmap_iova() frees > both the mapping and the reservation. Also, both here and in the > xe_ttm_tt_create() comment, it says GGTT bindings are programmed directly > from the sg list, whereas this patch converts xe_ggtt_map_bo() to use > xe_res_first_tt(). > > > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c > > index a3f5d204cd9de..f1cacef7064d2 100644 > > --- a/drivers/gpu/drm/xe/xe_bo.c > > +++ b/drivers/gpu/drm/xe/xe_bo.c > > [ ... ] > > > @@ -533,28 +616,197 @@ static void xe_tt_unmap_sg(struct xe_device *xe, struct ttm_tt *tt) > > } > > } > > > > -struct sg_table *xe_bo_sg(struct xe_bo *bo) > > +/* > > + * xe_tt_iova_reserve - Reserve the IOVA range backing a tt's DMA mapping. > > + * > > + * The reservation is taken when the tt is DMA mapped rather than when it is > > + * created, so that it is always released by xe_tt_unmap_iova() while the > > + * device's IOMMU domain is still alive. A tt whose reservation outlived > > + * pci device removal would hit a NULL iommu group in dma_iova_free(). > > + * > > + * Return: true if @xe_tt holds a reservation on return, false if the caller > > + * should fall back to the scatter-gather path. > > + */ > > +static bool xe_tt_iova_reserve(struct xe_device *xe, struct ttm_tt *tt) > > { > > - struct ttm_tt *tt = bo->ttm.ttm; > > struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm); > > > > - return xe_tt->sg; > > + if (xe_tt->use_iova) > > + return true; > > + > > + if (!xe_tt->iova_eligible) > > + return false; > > + > > + if (!dma_iova_try_alloc(xe->drm.dev, &xe_tt->iova, 0, > > + (size_t)tt->num_pages << PAGE_SHIFT)) > > + return false; > > + > > + xe_tt->use_iova = true; > > + return true; > > +} > > [Severity: High] > Can xe_tt_iova_reserve() take a new IOVA reservation after > xe_bo_pci_dev_remove_all() has already run, stranding the mapping until > after the PCI device is detached from its IOMMU group? > > During xe_device_remove(), drm_dev_unplug() runs followed by > xe_bo_pci_dev_remove_all(). For exported dma-buf BOs, xe_evict_flags() > moves them to XE_PL_SYSTEM rather than purging them, which unmaps their > initial IOVA reservation while keeping ttm_bo->ttm alive with > iova_eligible set: > > drivers/gpu/drm/xe/xe_bo.c:xe_evict_flags() { > ... > if (device_unplugged && !tbo->base.dma_buf) { > *placement = purge_placement; > return; > } > ... > } > > After xe_bo_pci_dev_remove_all() returns, dev->iommu_group remains valid > until PCI bus removal completes (or indefinitely after a sysfs driver > unbind). If an importer or userspace triggers DMA_BUF_IOCTL_SYNC > (xe_dma_buf_begin_cpu_access() -> xe_bo_migrate(bo, XE_PL_TT, ...)), > neither xe_dma_buf_begin_cpu_access() nor xe_tt_iova_reserve() checks > drm_dev_is_unplugged(). Moving from XE_PL_SYSTEM to XE_PL_TT performs a > CPU-only null move that calls xe_tt_map() -> xe_tt_iova_reserve(), > allocating a fresh IOVA reservation after xe_bo_pci_dev_remove_all() has > finished. > > Once PCI removal sets dev->iommu_group to NULL, closing the dma-buf calls > xe_ttm_tt_unpopulate() -> xe_tt_unmap_iova() -> dma_iova_destroy(), which > unconditionally dereferences iommu_get_dma_domain(dev) and causes a NULL > pointer dereference. > > [ ... ] > > > @@ -764,6 +1016,30 @@ static struct ttm_tt *xe_ttm_tt_create(struct ttm_buffer_object *ttm_bo, > > } > > } > > > > + /* > > + * Eligible BOs are DMA mapped using the IOVA-based DMA API, which > > + * yields a single contiguous IOVA range instead of a scatter-gather > > + * list. Only evictable device BOs that are not GGTT-mapped qualify: > > + * dma-buf imports manage their own mapping and GGTT bindings are > > + * programmed directly from the sg list. > > + * > > + * Pinned BOs are excluded because they are invisible to the eviction > > + * done by xe_bo_pci_dev_remove_all(): a BO pinned in XE_PL_TT (e.g. a > > + * page table on integrated) keeps its mapping until the BO is > > + * destroyed, which may happen long after the pci device was removed > > + * (an open drm file outliving a hot-unplug). Releasing IOVA state at > > + * that point would dereference a NULL iommu group. > > + * > > + * The IOVA range itself is reserved when the tt is DMA mapped and > > + * released when it is unmapped, so it never outlives the device; > > + * dma_iova_try_alloc() may still fail there, in which case we > > + * transparently fall back to the sg list. > > + */ > > + xe_tt->iova_eligible = ttm_bo->type != ttm_bo_type_sg && > > + !(bo->flags & (XE_BO_FLAG_GGTT | XE_BO_FLAG_GGTT_ALL | > > + XE_BO_FLAG_PINNED)) && > > + use_dma_iommu(xe->drm.dev); > > + > > return tt; > > } > > [Severity: High] > Can a user scanout BO on an integrated GPU bypass > xe_bo_pci_dev_remove_all() with an active IOVA reservation and cause a > NULL pointer dereference in dma_iova_destroy() after hot-unplug? > > User scanout BOs created via xe_gem_create_ioctl() or xe_bo_dumb_create() > do not have XE_BO_FLAG_GGTT, XE_BO_FLAG_GGTT_ALL or XE_BO_FLAG_PINNED at > creation time, so iova_eligible is true and they are mapped in XE_PL_TT > with use_iova set. When pinned to a display plane, __xe_pin_fb_vma() > calls xe_bo_pin_account() -> ttm_bo_pin(), which moves the BO to > xe->ttm.unevictable without adding it to xe->pinned.late.external. > > During xe_device_remove(), xe_display_unregister() calls > drm_atomic_helper_shutdown(), which queues plane unpinning > (intel_atomic_cleanup_work -> __xe_unpin_fb_vma()) asynchronously on > display->wq.cleanup. Because display->wq.cleanup is not flushed until > the devm callback xe_display_fini() -> intel_display_driver_remove() runs > after xe_device_remove(), xe_bo_pci_dev_remove_all() can run while the > scanout BO is still pinned on xe->ttm.unevictable (skipped by > ttm_resource_manager_evict_all()) and absent from > xe->pinned.late.external (skipped by xe_bo_pci_dev_remove_pinned()). > > When cleanup_work later unpins the BO and userspace closes the DRM fd > after PCI removal has cleared dev->iommu_group, xe_ttm_tt_unpopulate() -> > xe_tt_unmap_iova() -> dma_iova_destroy() dereferences a NULL > dev->iommu_group. > > [ ... ] > > > @@ -2524,6 +2813,8 @@ int xe_bo_dma_unmap_pinned(struct xe_bo *bo) > > DMA_BIDIRECTIONAL); > > ttm_bo->sg = NULL; > > xe_tt->sg = NULL; > > + } else if (xe_tt->use_iova) { > > + xe_tt_unmap_iova(ttm_to_xe_device(ttm_bo->bdev), tt); > > } else if (xe_tt->sg) { > > xe_tt_unmap_sg(ttm_to_xe_device(ttm_bo->bdev), > > &xe_tt->ttm); > > [Severity: High] > Can calling xe_tt_unmap_iova() here without holding the BO reservation > lock race with a concurrent unpin and eviction or destruction of an > exported dma-buf BO? > > Exported user BOs pinned via xe_dma_buf_pin() -> xe_bo_pin_external() are > iova_eligible and sit on xe->pinned.late.external. > xe_bo_apply_to_pinned() drops xe->pinned.lock before invoking > xe_bo_dma_unmap_pinned(bo) with only a GEM reference held, and unlike the > other xe_pinned_fn callbacks in xe_bo.c, xe_bo_dma_unmap_pinned() does > not call xe_bo_lock(bo): > > CPU0 CPU1 > xe_bo_pci_dev_remove_pinned() > xe_bo_apply_to_pinned() > spin_unlock(&xe->pinned.lock) > xe_bo_dma_unmap_pinned(bo) > dma_buf_unpin() > xe_bo_unpin_external(bo) > ... > xe_ttm_tt_unpopulate() > xe_tt_unmap_iova() > xe_tt_unmap_iova() > dma_iova_destroy(...) dma_iova_destroy(...) > ... > kfree(tt) <-- use-after-free > > Because xe_tt_unmap_iova() clears iova_linked and use_iova only after > dma_iova_destroy() and xe_tt_unaccount_iova(), concurrent execution can > call dma_iova_destroy() twice on the same IOVA state, underflow > xe->mem.dma_mapped_pages[], or access tt after it is freed. > > -- > Sashiko AI review · https://sashiko.dev/#/patchset/20261201234915.3305331-1-matthew.brost@intel.com?part=26