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=pgMNYCU9Na2fZ/+cM+22IKt7/Tz0B64Odgh+Q2xWbkCRcnxGgArsfvqcn+s+eOeMk1Zx 2JHY9Xi8XzbOIloW0waGc8ljlHu5W7VQDNLCS3kX8Q/Ad05ANmkBtIoVFekqSTvEc/TfA g0ytjX2g+yjduzbOnkgLqDNNIs4eC3eiOSOJH76rUomTMdp1pfVWAAZePPw47ZEB7mOU4 ull3aGsx2ctyhPykDvZu8FyAkjBSRfCIPPbI9WDU2vuS53cGEuYwIUKoi0p/uDvgmlpAX qiDphKHJ9pD+vGzdEsSKpDAeLlzwRicnqJdT5hwe0BpJgsCpb91NpEe75YZYWtHJeAA== 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=dpJw01qFPpmImQXy1d5BTb9pf2gFSqKfWhq5SXztvU8=; b=CeKoOSW6F7mt6/ox/qEO+FobAzb52W6gvSo6VjEDFOCKH6EavRJy3zvoSN4lzKxA4DdB XeuWzstbwin9HR6wgUoiI3Ys+su+hVU9yYI/uJkTSayIlnHncMDr9WH2+90ybIqeMi53C l6jFMDwHTWOF4GRwO4mlPJ1qwTltY+dHxQ7kzf87m0OmwQ2A8Yzhn2S9K63Ir7l/ODvtl gDWBHBwrhDiu/e3WDE7+g3W2sQHRQf5HOZ9kcdN8sk73zIjN8vPn2jiXrlxc08s7G2+5k Jb09uDZi1u9f2FEnnjGug5Hfpi4kLi9wXr8Q19Soz1Sq45EMq11OHNlpz3LBaUjqFGg== 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=MKuKVGVC; 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 7BD3C60A6F63 for ; Thu, 3 Dec 2026 20:24:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7BD3C60A6F63 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=MKuKVGVC 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=dpJw01qFPpmImQXy1d5BTb9pf2gFSqKfWhq5SXztvU8=; b=MKuKVGVCypKGcgOLIDP1FspUTkiQ+Co258ZOD9tORL87JLhuZlaCzZIk nAfPI+rkkFj45SHTSkJjCJG8xC39OaH6PgBr/t4wPlD7+5yVm1VGiI4ZN ZlHOD5OLiSE79+SH+TUegaqZ7/oz0LXE5mYopENljrtPMay8kVDXXTs1e mcqfA38AOqWDRkF+4v+e+US6dHPDrQcQFftm6OVKhel/QSiCkwv3OLJAH jOkjtFerzb+gi3o4CaISr6mIxkc4ea5ndiismZ0RSAZ/1L4dzjz3UxsbA OQuPPxkKfS+khcYkCGD55m5I9Xzd75b4ryEC8voMG+AeY63HbJcrMqw4N A==; X-CSE-ConnectionGUID: 6YNtrCigSFi/q6VYatdCgA== X-CSE-MsgGUID: 0Mu/rKe7Re60xfMXByRr8g== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5351204" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5351204" 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: 21Xpbel2Sw2QPFvgXqFxXQ== X-CSE-MsgGUID: l450TbOhTHiuigS2Hd2FqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="15862515" 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 27/35] drm/xe: Lock the bo in xe_bo_dma_unmap_pinned() Date: Thu, 3 Dec 2026 12:23:44 -0800 Message-Id: <20261203202352.4153159-28-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_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 Reviewed-by: Matthew Auld --- 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 855c3e62763f..8549a3157716 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -2629,8 +2629,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); @@ -2645,6 +2652,7 @@ int xe_bo_dma_unmap_pinned(struct xe_bo *bo) &xe_tt->ttm); } } + xe_bo_unlock(bo); return 0; } -- 2.34.1