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=1796254420; b=xgMcY7Zd5o7V5CqFvQdygDxS7JO2iQWrDoiYAo7FM/P8aqIborhecxQ0N+m6DMpAbqiP CkBuKZoIb9cCETKn2bAOEa0FSIdnNcRIWukHZ6JSaEu9hNX4pWmRF+WoN1uROcydex+Io VGq9C5hErPgn6c8V9jXQZJ1WZMRe3gwoNHLcAx1XfMBI8P9/Iv3NjWq9gESAV7nvqSaWu DBYZgrI8oU2ATwDONBCeD7XeBuJHxWpnDE10JuV1vNaTKtnj1PdcVP3vJHGO9egkDudYU Hs9CMiO9qgzgoUXvLuO8MxA1eGk9wusMix6B6DLmzY+jOztr2omeSc7MMTKP68sxvkQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796254420; 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=QwLdL2Wdf8jJzUoxJ9gJDOVajAqJm7hb4QaLQOWynNE=; b=XOiDo9rI5GmxYv7ZAd09IJRD1gvqX4/L9CuP/2Vg8b7yjEYLkXe0dwKcKkzb3i4ApqUH AORo377R2um/jmsW5PumByL0GknQP0VENA3Vu9zH5qBiFLORrc6wKZeIkgxh6GMqxCKT0 R12AEqcQOkFvsWBv1FY4G2h4RFP3LIx7HRd8rehE/hG4R0tu+rFmLVFkwOJEZodGIhJIl JhdgiaT1pJF7Mohmry9D2yh0TwLgXJ1au1XjDl0aPrftU6zQw89iEnYX32cNh7zrISLEP kKpyhkWDRSY9gn2+mPSuIoCFkSvCT3eHx2mtJSdhgbFR4HYsBED5o/vxFx5TGw6tZFQ== 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=nlHh4NFM; 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 E5CE060A6F7F for ; Wed, 2 Dec 2026 23:33:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E5CE060A6F7F 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=nlHh4NFM 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=QwLdL2Wdf8jJzUoxJ9gJDOVajAqJm7hb4QaLQOWynNE=; b=nlHh4NFMDZUXhCgsfejAWm/UohiVVbUVmlsKs7vfPoyQHgsQjvgHXRe4 ozHLtKBSvyyywji1FxXNkK2cLyWzU1JZca42hF9wLzI+4HimltUlyQ7U5 0O6xGQTHREN0jI6WdoJf5JeXVeyAJFeUx0UaJF624vRRs5i3/JWpbp7NW bDKgePswkf8cFLuBfQxv/sVrz2FjIb0HqcI58lSX9NmdIJwJR4tiVZpHy 8GRgihHo+PcPn8GX4ZAUo3hQFX0sJ2UaABTu4UhdTmOlvFmGHDVtMzDlH Pe0KpkzN+r8hlrf3CtyC4KpKFme5nQRBJT3GiwPB6j7IFUhR6h/63sH7+ A==; X-CSE-ConnectionGUID: RjYaiHxxSDCgbzeAgLwgCg== X-CSE-MsgGUID: MazCuoO3SB6mgwfzfFGEMw== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5203287" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5203287" 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: 3fcvpIyqQJq2KdfyT3x5OQ== X-CSE-MsgGUID: vtGCZfAAQvqNgjx8hV3/uA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="13484105" 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 28/36] drm/xe: Lock the bo in xe_bo_dma_unmap_pinned() Date: Wed, 2 Dec 2026 15:33:15 -0800 Message-Id: <20261202233323.3743190-29-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_apply_to_pinned() drops xe->pinned.lock before invoking the callback with only a bo reference held. Unlike the other pinned callbacks, xe_bo_dma_unmap_pinned() does not take the bo's dma-resv lock, so on device removal it can race with an importer unpinning an exported bo (xe_bo_unpin_external()) followed by an eviction that unmaps the same tt, resulting in a double DMA unmap and sg table free. The imported-bo branch also calls dma_buf_unmap_sgt(), which asserts that the dma-resv lock is held. Take the bo lock around the unmap. 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, 9 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index 8ff92b2c9176..878a1b0e7dac 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -2585,8 +2585,15 @@ int xe_bo_restore_pinned(struct xe_bo *bo) int xe_bo_dma_unmap_pinned(struct xe_bo *bo) { struct ttm_buffer_object *ttm_bo = &bo->ttm; - struct ttm_tt *tt = ttm_bo->ttm; + struct ttm_tt *tt; + /* + * The caller only holds a reference: without the lock, a concurrent + * unpin followed by eviction or destruction may unmap, or free, the + * same tt. + */ + xe_bo_lock(bo, false); + tt = ttm_bo->ttm; if (tt) { struct xe_ttm_tt *xe_tt = container_of(tt, typeof(*xe_tt), ttm); @@ -2601,6 +2608,7 @@ int xe_bo_dma_unmap_pinned(struct xe_bo *bo) &xe_tt->ttm); } } + xe_bo_unlock(bo); return 0; } -- 2.34.1