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 80D8B606A322 for ; Thu, 3 Dec 2026 00:07:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=l7VSAdJx Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 464AF1126B2; Thu, 3 Dec 2026 00:07:04 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 204C11126AE; Thu, 3 Dec 2026 00:06:58 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 9A39B61EC8; Thu, 3 Dec 2026 00:06:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 367511F00899; Thu, 3 Dec 2026 00:06:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796256417; bh=VLy6Qycd1DopwsGCN1XHwr1xFjZJy4ZooAPpjKw81dc=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=l7VSAdJx8xc3nWYTyPHwbobhtxFV69ZbijU7ScBdOWQfak/uXc0JZGw0YbhXCAHYO oSi/YYYTQPtet/VGQ3it89RxRFRyGpKEbEKnF7oVqzZUcGE12bFJ5CXgCvkM9TKHRw 7AuVE9HvXDrJ/VWvz5XGmbPaqu32GQOB+/SQS0zpEdeY9AtPlZ9bNHxyVB7CU4UZJj v33zwml25374/lFbZoR7vbbNahvINoPVp4zqQ96xMs6C+Iqv3KaFOwQULKfeJ0ohD/ NDmFkGOyjreKoEPZpAub2Yz1EPnRPJGT6oe7aXlt7SAaZgemR4AS1ZVUJ6IMRNX5xw r3lPn1ISFgewQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 29/36] drm/xe: Use IOVA-based DMA mapping for eligible tt BOs To: "Matthew Brost" , intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org In-Reply-To: <20261202233323.3743190-30-matthew.brost@intel.com> References: <20261202233323.3743190-1-matthew.brost@intel.com> <20261202233323.3743190-30-matthew.brost@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 00:06:56 +0000 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: , Reply-To: sashiko-reviews@lists.linux.dev 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=ham 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 X-Archived-By: Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] drm/xe: xe_tt_map() returns -ENODEV during unplug VRAM eviction - [High] drm/xe: IOVA mapping can escape xe_bo_pci_dev_remove_all() on unplug -- commit a2fdff5ea39545a2086c69c17159fb3fb9d84d16 Author: Matthew Brost drm/xe: Use IOVA-based DMA mapping for eligible tt BOs This commit adds support for DMA-mapping eligible ttm_tt objects with the IOVA-based DMA API as a contiguous alternative to scatter-gather lists, and switches TT resource cursor users to xe_res_first_tt(). > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c > index 878a1b0e7dac3..e2a725c790d8b 100644 > --- a/drivers/gpu/drm/xe/xe_bo.c > +++ b/drivers/gpu/drm/xe/xe_bo.c [ ... ] > @@ -543,28 +616,207 @@ static void xe_tt_unmap_sg(struct xe_device *xe, s= truct ttm_tt *tt) [ ... ] > +/* > + * xe_tt_map - DMA map a tt, using IOVA when available and sg otherwise. > + */ > +static int xe_tt_map(struct xe_device *xe, struct ttm_tt *tt) > +{ > + struct xe_ttm_tt *xe_tt =3D container_of(tt, struct xe_ttm_tt, ttm); > + > + /* > + * Once the device is unplugged, xe_bo_pci_dev_remove_all() has dropped > + * (or is about to drop, under each bo's lock) all DMA mappings. Don't > + * create new ones, e.g. when an exported dma-buf moved out to system > + * is migrated back to TT by begin_cpu_access(): such a mapping would > + * outlive the device's IOMMU group and crash on unmap. > + */ > + if (drm_dev_is_unplugged(&xe->drm)) > + return -ENODEV; [Severity: High] Does rejecting xe_tt_map() when drm_dev_is_unplugged() is true break VRAM eviction of exported dma-buf BOs during device removal? In xe_device_remove(), drm_dev_unplug() runs before xe_bo_pci_dev_remove_all(). When xe_bo_pci_dev_remove_all() evicts an exported dma-buf BO (tbo->base.dma_buf !=3D NULL) from VRAM, xe_evict_flags= () skips purge_placement and routes the BO to XE_PL_TT so its contents can be copied to system memory. That hop calls xe_bo_move() -> xe_tt_map(), which now fails with -ENODEV, aborting ttm_resource_manager_evict_all(), triggering drm_WARN_ON() in xe_bo_pci_dev_remove_all(), and leaving the BO and any remaining BOs on that VRAM manager's LRU unevicted. [ ... ] > @@ -2603,6 +2892,8 @@ int xe_bo_dma_unmap_pinned(struct xe_bo *bo) > DMA_BIDIRECTIONAL); > ttm_bo->sg =3D NULL; > xe_tt->sg =3D 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 an IOVA-mapped user BO in XE_PL_TT escape xe_bo_pci_dev_remove_all() if it is unpinned concurrently with device removal? An exported user BO created without a VM has neither XE_BO_FLAG_GGTT nor XE_BO_FLAG_PINNED, so xe_tt->iova_eligible is true. If a dma-buf importer pins and later unpins that BO while xe_bo_pci_dev_remove_all() is running: CPU0 CPU1 xe_bo_pci_dev_remove_all() ttm_resource_manager_evict_all(TT) (skips pinned BO on unevictable) xe_dma_buf_unpin() xe_bo_unpin_external() xe_bo_account_unpin() list_del_init(&bo->pinned_link) ttm_bo_unpin() (moves BO back to TT LRU) xe_bo_pci_dev_remove_pinned() (misses BO, no longer on pinned.late.external) The same miss happens without a race if the user BO was already pinned for display scanout via __xe_pin_fb_vma() before xe_dma_buf_pin() -> xe_bo_pin_external() ran, because first_pin is false and bo->pinned_link is never added to xe->pinned.late.external. In either case, xe_tt->use_iova survives PCI device removal, and when the BO is later destroyed after the device's IOMMU domain has been torn down, xe_ttm_tt_unpopulate() -> xe_tt_unmap_iova() -> dma_iova_destroy() hits a NULL pointer dereference (and trips the xe_assert() in xe_ttm_tt_destroy()). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202233323.3743= 190-1-matthew.brost@intel.com?part=3D29