Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.20 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796329446; b=2fbiXgDL+Zkbwr94H5kpJFemJW8NcnETaayK1Kux5tkzxYVuo/fuHq7k1mfMscbmJ8EI KfvsqNTOrg9+GUAM50cW4NB6hUnlTThv2SbAPpRQWMpp+jHqCbwPhKBwF4BJ19sqwMLUZ 5y+NL0ppqz2zfVYBnC1NS+1OFC/FJvp+vLy9R5Ml7OWVIeoOQTf0NmzQOZFlU3Q1W5P5P u8O5FLlXyWuLiXIGiH0pJ5oAB/lVeQDWYYAjzXNG6SGo8dEgMe34oQdRLaRpQzsakj7h5 PMPiKDNN6Zp5VqDODzq1cBN2hA0aQOy/AzUUfIUiKBZTZKQUCebD4KzSwmrpEq0GnyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796329446; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=p1+W6+YLBiRv0Zj9i5r1qQEAo739JH/cV54Solw4l/o=; b=QSoWQBBjmP4Yih1aFn9GDaYEWnJ+HMCWgAm9ZLTm2ymNTYl6EWpVWCdjPUhJvydfZSNY uGjUSOQaw8oAzH3Y4GIzPkqCEtTU5lAz01pu23FP3bs//IFsoP+TraxmOJlVLKRu26vRh vhpCh4zL6OFWL7XmYngOw118CwfoEXjKGgp2A+/2TGBjl5033XmPvkOxMtb9jPKG3KLue xZ8nhCvMtTtGQCVWu0sne4eRZdRT8WUGnxSAZr6Qil4vQxbryIih7zhecH8sfE/2mApwT dm6IEHuCmftTXYeZLuV9WSD7DjnnZxMnnqgvDLZX+RGNJEXd304gHDfzoEHQPLwI+9Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=KYWB1F6W; arc=none smtp.remote-ip=198.175.65.20 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BC7E60A6F54 for ; Thu, 3 Dec 2026 20:24:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3BC7E60A6F54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com 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=KYWB1F6W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796329447; x=1827865447; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p1+W6+YLBiRv0Zj9i5r1qQEAo739JH/cV54Solw4l/o=; b=KYWB1F6WrrpHseR5Jr5xeOppJegV4aZp/YECo6ebAqAaBAEgrDm9t4po GHsD1pp3+GCK84/oDVZpJLrOjKTi7myaPG7iDnjr9UitLssf1DXzKoJbq 6ArfJgjHLiOW+ms2zGcJDhFzNasX6B9IX3Nx4jtOWEFbixweFxvYnJmFN sL9wSwholZJwy3Z0yis9TR+vtyv3Ehvb6cP3lpdU9bCiMIg/xU8reuYfH YIi57fdkuQ66wcCUpllCG10u+fBc5F77ujl/npbwoJNCS6rd0Cyy/0wOt bOYLKExgjQ98LvUeoZNHh95wy4MUjpOH70WeQElHLf9rB4rgtdRLOhZBL g==; X-CSE-ConnectionGUID: 9Qb7Y9z8Q3eLODOIddrIvw== X-CSE-MsgGUID: /SXizsNhTeyMLp6XkvcjvQ== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5351201" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5351201" 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-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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