Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796254419; b=E1J7OL9ijo0pUfCAwXTgfOQfqFkM32WZkq6ANRgv6BNZm9a5EFXqmP2A/bcnA6Q5Qerv awcGiP3eI/yaoVxIMvX9vGiDMBoy11P5TnOVuginkd99OzsSqPs7ISn2CsRCwyno8G0Th I3l7D9R7vLKb2yOJNGWuEDQJyrG6G44H/gw1748lLLIwtxmt3AvMvPNd9mdiyWpLz94UZ 9jyrgVPKXS0dRupioVO2JusVep5zLD4ofShdDIw1BG4PoL+d+BNRKu89amYjcTIINZJ7E KxUFKsPaPbzqom737zA2cVsaTF3klnlth10CumWwyUtH6MVanafmo4l7hO6zRNJdSkg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796254419; 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=mpQCWB9dsJFJOU0cit9ym3pvfZ0+du+xBBbaYBHJs4M=; b=pWJeqlwM4p6ThHM6cBwMbBhRf+6DbwLDodhGQYC+oB8/um2x+4qW7FkJF51yQLXLRPED 60qPUw8zhV6LaeK/svrCszfh+9wbTwTMQpQfMGnx/eVe5SGL14S/27T8mZYGE/FprywOO qXLgErSd/lIyFDcNCRJ3JmmZcMBpswklqPSvGvkW66cQynpVwUEQitM1Da26GqW/e69ym QOGyL70gBhHFotNDyFW1Q2RFiZJBbOHzB78zVB05htQ7D5qzPN+gciGOdguSLuPhO8hXG itsH4u0o0Ettdy8q0yiRpPWzd8ceKX4dMNdZKqOVQ88PrJuG1IFVNwX+cbibh0NJOwg== 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=I92Gjg0M; arc=none smtp.remote-ip=192.198.163.17 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 48E3E606A69D for ; Wed, 2 Dec 2026 23:33:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 48E3E606A69D 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=I92Gjg0M DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796254420; x=1827790420; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mpQCWB9dsJFJOU0cit9ym3pvfZ0+du+xBBbaYBHJs4M=; b=I92Gjg0MMjwM1yQXSLuAkdhapf0/1BR+4fj+D4F5osY5ny6MxY1G4MiC Os5JLp09HCTgsUtF74M4mf6YMJzw/v0ZStdi8CY0PH++vzNU4wWR7vrIx toPj0QTponJpeJdB4/1MOgW8yMXR1Q+r9GpMuR1dsbK8vhTke5akN5Lv9 G4nljbN4Iv9Efi9DW7MhT5wuR9AXxkuyqATWx6Dn0JF5VM//aKX9jiyU7 FqAncDgtgsTT3VKplAsLeHlyc5kI9Y2OWqxZAgWmSvKmJ9xH2c+BCjXlA jL9UfSWIIFQRPnJLpY6ycLh6tr3tZxFdUtMxaqhqWSX/iwFlT2CuDgubp A==; X-CSE-ConnectionGUID: 0XDAvT3aQ2eT/vwIGATE/g== X-CSE-MsgGUID: cj6TKHwoQbuE+AaOIjmPmw== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5203278" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5203278" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 15:33:31 -0800 X-CSE-ConnectionGUID: kk0zI2JIRb2St2mGzoXQCg== X-CSE-MsgGUID: ARpXLjmbRZeRldj0R0zhqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="13484099" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 15:33:30 -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 v5 26/36] drm/xe: Don't DMA map tt pages after device unplug Date: Wed, 2 Dec 2026 15:33:13 -0800 Message-Id: <20261202233323.3743190-27-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261202233323.3743190-1-matthew.brost@intel.com> References: <20261202233323.3743190-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 to DMA map tt pages 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 map runs under the same lock, so a mapping created before the unplug is evicted, and any later map attempt sees the unplugged device. begin_cpu_access() already ignores migration failures, leaving CPU access in the system placement. 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 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index 41092e2810b4..8ff92b2c9176 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -499,6 +499,16 @@ static int xe_tt_map_sg(struct xe_device *xe, struct ttm_tt *tt) if (xe_tt->sg) 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. + */ + if (drm_dev_is_unplugged(&xe->drm)) + return -ENODEV; + ret = sg_alloc_table_from_pages_segment(&xe_tt->sgt, tt->pages, num_pages, 0, (u64)num_pages << PAGE_SHIFT, -- 2.34.1