From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796344949; b=qsgqoYZx54W9K22zgYCU7SKlVyaFsRJdQctKfEa3GRDDblFG+p4thaNXYofFEVv4TAi/ GlZSvxw0dCXKAsizvCfyt1bSyVmzFJm/6lpYGaf6dac9PmWVSuhFqSw6gB1n6K0CGtEkw kXILj7xrVBnLPceicMmsbwZAqY5f65Zh3ZpIgunwcl0/ubA1e4PS6gkwkZapAzdQbV6k1 c11wSUs5nCk/FqoaacaHComynwgf1UM23GQCDiEOtQio/tuS5Pa6JDtWECGsnDyQehfNy bFn9cjwxLiBk/jyjuKcp2z9Nij9fU80PXffhDUE5q/UuL9DLJVH/7UR0Mwe51YFHuzQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796344949; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=pWId6UwgTKWlBiZWTsRuKIogEn5njUmH28bpI6BRFjE=; b=f7ZRtR7K1rH0oMQb16ovrGQRrvPzOTp58HE8ndAU2h8MS69T0EbX8pLLBD0lsn089iXD 5/rYY4cM0Ae+6ynkqtgFkMEiEWGO6y8gb39O3M27v83SFTOGdWf/tU3siBNaLoEwDzKbH J1os9QK+R8G9d5v/aEFztza+Xp81YNXDBNuJPRbNNRltG6qq4UrVcQcnJB2cdCzKCuWAq 5FmTjvuQ8iMNc2A3rSjFMvAudTGt4gaU+plZPJuWDRxF0vyNpZ4TE6Z2ymNCzTBpQ3IMz t+kjjQqzkVWeK8A+oqZs1sUpHmEhMMM9GH2pCRkHm1MLajK4K6ExBdZASM9X9sdGB1g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bzBNq3Se; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24D01606A32D for ; Fri, 4 Dec 2026 00:42:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bzBNq3Se Received: by smtp.kernel.org (Postfix) with ESMTPSA id 040041F00897; Fri, 4 Dec 2026 00:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796344949; bh=pWId6UwgTKWlBiZWTsRuKIogEn5njUmH28bpI6BRFjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bzBNq3SeUS47zpRDmm2mnZi+d4pGLfkXavj4sekcTWPLkyQRUmRrzSkTOoOzGhGx3 vbTC7yYkKmPD7XzS1wa6onY9tNb5W3MKLd590nmWxGQsI5Pm4kcQtNw9m/131GXwxN w7Goimz/ln+EuOfNWmU9MR9ehUnQh3UlUWGzWSuA/eqNUDnuNnvjbV011rGAYzl77W vqRPLaEyEgNyuyOwxNPsIPoU+EiFuPe22LVDJEzF+5gZ0Y4szcSiOEFKaD9X2YJotO AHRxpUzTH5WQdQJtsyYFi2gQi6YLN3vsl5w8/ymS0RoAVFwFMkCgpMc6KhfpgcsHTv W8N+b4s3B8fCQ== From: Sasha Levin To: stable@vger.kernel.org Cc: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Matthew Brost , Matthew Auld , Dave Airlie , Rodrigo Vivi , intel-xe@lists.freedesktop.org, Sasha Levin Subject: [PATCH 6.18.y] drm/xe/dma-buf: Validate BOs on export to charge the exporter Date: Thu, 3 Dec 2026 19:42:26 -0500 Message-ID: <20261204004124.1501174-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120256-untainted-bankable-4a8f@gregkh> References: <2026120256-untainted-bankable-4a8f@gregkh> 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 From: Thomas Hellström [ Upstream commit 22e05ee854e1bdacebcfa36ecd3f33ec80cf897a ] xe_gem_prime_export() calls ttm_bo_setup_export() to make sure the exporter is charged for the memory backing an exported BO. However, that only populates a TTM_PL_SYSTEM tt. A BO that has been evicted, or that has deferred backing, will instead get its memory allocated when the importer maps it. For p2p imports this happens through xe_bo_validate() in xe_dma_buf_map(), so the importer, not the exporter, is charged for the allocation. Call xe_bo_validate() at export time instead, so that the BO is moved into its preferred placement and the exporter is charged. Do the purgeable checks and the validation in the same xe_validation_guard() transaction, to avoid locking the BO twice. The commit message and code was drafted using LLM. Link: https://patchwork.freedesktop.org/patch/747480/?series=172524&rev=1 Fixes: 91494dee1091 ("xe: populate buffers before exporting them.") Cc: Matthew Brost Cc: Matthew Auld Cc: Dave Airlie Cc: Rodrigo Vivi Cc: intel-xe@lists.freedesktop.org Cc: stable@vger.kernel.org # v6.18+ Reviewed-by: Matthew Auld Link: https://patch.msgid.link/20261111100929.2228-1-thomas.hellstrom@linux.intel.com Signed-off-by: Thomas Hellström (cherry picked from commit 451162b9f6570d19da1c5944aa0a0e3e8f17773d) Signed-off-by: Matthew Brost [ sashal: Replaced ttm_bo_setup_export() with an xe_bo_validate() call under xe_validation_guard, omitting the purgeable-BO checks and willneed get/put that this tree lacks. ] Signed-off-by: Sasha Levin --- drivers/gpu/drm/xe/xe_dma_buf.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_buf.c index 07010f097e584..dcaf3d0cce6b7 100644 --- a/drivers/gpu/drm/xe/xe_dma_buf.c +++ b/drivers/gpu/drm/xe/xe_dma_buf.c @@ -203,20 +203,32 @@ static const struct dma_buf_ops xe_dmabuf_ops = { struct dma_buf *xe_gem_prime_export(struct drm_gem_object *obj, int flags) { struct xe_bo *bo = gem_to_xe_bo(obj); + struct xe_validation_ctx ctx; + struct drm_exec exec; struct dma_buf *buf; - struct ttm_operation_ctx ctx = { - .interruptible = true, - .no_wait_gpu = true, - /* We opt to avoid OOM on system pages allocations */ - .gfp_retry_mayfail = true, - .allow_res_evict = false, - }; - int ret; + int ret = 0; if (bo->vm) return ERR_PTR(-EPERM); - ret = ttm_bo_setup_export(&bo->ttm, &ctx); + xe_validation_guard(&ctx, &xe_bo_device(bo)->val, &exec, + (struct xe_val_flags) {.interruptible = true}, ret) { + ret = drm_exec_lock_obj(&exec, &bo->ttm.base); + drm_exec_retry_on_contention(&exec); + if (ret) + break; + + /* + * Make sure the BO is backed in its preferred placement so that + * the exporter, rather than the importer, is charged for the + * memory allocation. + */ + ret = xe_bo_validate(bo, NULL, false, &exec); + drm_exec_retry_on_contention(&exec); + xe_validation_retry_on_oom(&ctx, &ret); + if (ret) + break; + } if (ret) return ERR_PTR(ret); -- 2.53.0