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 52D93606A333 for ; Thu, 3 Dec 2026 20:24:57 +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=a7ZFB2rB Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CEA0B112BEE; Thu, 3 Dec 2026 20:24:51 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id C0419112BBE; Thu, 3 Dec 2026 20:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796329467; x=1827865467; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p1+W6+YLBiRv0Zj9i5r1qQEAo739JH/cV54Solw4l/o=; b=a7ZFB2rB8VtCAQYYlY+sMUZXZVYZJ9IaqAhE0pC8t00PZZ/5NfN64/yB K0iJY+i+MeKM2OtUBtHlQ3qBVh6+/Ufw13Ih+uWa05yKWRsz858hBEHvy vNNVd+5oqmgx0++ehs54s5egY8U76mJFE8g31AeH23EzldXNjml+trYZm 0TsxlTtaJrHiuyTPEXXcaynXlwE3SY9QIhaL1WfxJA8fbbPqOFoe2Yf2/ NPY91gArD6uN8q+yC5POGNGpbfxaEAB8u+FPG3kAQ2SMOZNbnXRt7/Cz1 rJgApXnFmC9rBS/kRTqxO04ex6ktEYkCYUozK4EDHSnwfZ1CBFd7dU467 w==; X-CSE-ConnectionGUID: NmSl2/QkQHiow6L6xNwCyg== X-CSE-MsgGUID: WZ6Z7BSYRDW5gvO4OQSqAw== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5351202" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5351202" Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 12:24:06 -0800 X-CSE-ConnectionGUID: fEagf87pQfaP/UxJhXz25g== X-CSE-MsgGUID: zNQSzItAT5OkTwzsfUUnWg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="15862510" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 12:24:06 -0800 From: Matthew Brost To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Matthew Auld , stable@vger.kernel.org Subject: [PATCH v6 26/35] drm/xe: Don't DMA map tt pages after device unplug Date: Thu, 3 Dec 2026 12:23:43 -0800 Message-Id: <20261203202352.4153159-27-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261203202352.4153159-1-matthew.brost@intel.com> References: <20261203202352.4153159-1-matthew.brost@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT 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 xe_bo_pci_dev_remove_all() drops all DMA mappings on device removal: non-exported bos are purged and exported dma-bufs are moved out to system. However, nothing prevents an exported dma-buf from being moved back to TT afterwards, e.g. via DMA_BUF_IOCTL_SYNC -> xe_dma_buf_begin_cpu_access() -> xe_bo_migrate(bo, XE_PL_TT), which re-establishes a DMA mapping for a device that is going away. Once the pci device has been removed from its IOMMU group, unmapping that tt on dma-buf release dereferences a NULL iommu group. Refuse non-eviction moves to TT once the device is unplugged. drm_dev_unplug() completes before xe_bo_pci_dev_remove_all() evicts bos under their dma-resv lock and the move runs under the same lock, so a mapping created before the unplug is evicted, and any later move to TT sees the unplugged device. Evictions stay allowed: xe_bo_pci_dev_remove_all() itself moves exported dma-bufs VRAM -> TT -> SYSTEM, where the copy out of VRAM needs the TT mapping and the final TT -> SYSTEM pass drops it. begin_cpu_access() already ignores migration failures, leaving CPU access in the system placement. v6: - Allow eviction moves to TT after unplug, xe_bo_pci_dev_remove_all() needs them to move exported dma-bufs out of VRAM (Sashiko) Fixes: 3cbb651117ff ("drm/xe/bo: Add a bo remove callback") Cc: Thomas Hellström Cc: Matthew Auld Cc: stable@vger.kernel.org # v6.16+ Signed-off-by: Matthew Brost --- drivers/gpu/drm/xe/xe_bo.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index 5d6b9a5cbdb2..855c3e62763f 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -1844,6 +1844,20 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict, return 0; } + /* + * 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. Evictions are + * exempt: xe_bo_pci_dev_remove_all() itself evicts exported dma-bufs + * VRAM -> TT -> SYSTEM, the copy out of VRAM needs the TT mapping and + * the final TT -> SYSTEM pass drops it again. + */ + if (ttm_bo->type != ttm_bo_type_sg && new_mem->mem_type == XE_PL_TT && + !evict && drm_dev_is_unplugged(&xe->drm)) + return -ENODEV; + /* Bo creation path, moving to system or TT. */ if ((!old_mem && ttm) && !handle_system_ccs) { if (new_mem->mem_type == XE_PL_TT) -- 2.34.1