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=1796208838; b=cDHfMjOd6Wgvkm/e8hqRss6PrzpbrrateLK4kgNjgwII+cSjClY0Y7PKhu+GHZJg38/T hxgeYeS52/WkPnXMSbN580gOBb8txAdcyIZ3S5BwoD5Ul0eFg4LcC7/eN+v8t95jMjf3c hZlUHqNkC05BTSiPdYd937t0x/TUItumYSsVltrAPwTtneWMJncv/C3xX3rYU8lme8fO3 CZrofw3MCzG7Mi9osXp1tfc3GPZRr1RlCND7rmel2WOAPPfl3tiLlWVP4eMKSiMKmXcaX cbNcwR+wTPuC78Qzk5YJDqfERWzQ5o3DqA49VQ50np8Y/W2UWnrBr3dM7XBUmLUgp0w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796208838; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=G2v09Gx0AXHBQb0QGnjxk8EADJSnOdNbrvNKsOyXfYQ=; b=f5DmC30Wyc6Vm4S5peixPwrfUkYr1nb2Jf8gKrQmwz+n+hHl7KO4Yrb9jpNP628hLGK2 Cf1yUcnpzqsCiltmrAtZDKI0VRTh2kRfPVAgeXvT53fElR8/uyLCZtf5lQPr7mOQZYgEE F+7rvIjvrSzYGUQBQHm1Cv+oQHw6sQ4pyWt56ReQo2HPuMYecSJZoCobVIV8X2PiXUU9o hxj7h8xfeqY/FFHRYcLJA3Z6BEDxY80LWfvWHVWlM0EX38O5PQp/ufzSNUoSSGFuvN79J FloKqffnPq4sTcvc/QOF1i/ZMmLFC/JrYqS6a1NV+nh0aRi/Q5ZrZezLuJPKnmq5fcw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=EsrhawPb; 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 D769D606A323 for ; Wed, 2 Dec 2026 10:53:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=EsrhawPb Received: by smtp.kernel.org (Postfix) with ESMTPSA id 318D11F00896; Wed, 2 Dec 2026 10:53:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796208838; bh=G2v09Gx0AXHBQb0QGnjxk8EADJSnOdNbrvNKsOyXfYQ=; h=Subject:To:Cc:From:Date; b=EsrhawPb+GCRQRJx4ZrvyoU6+Ky/qorulWyEERYbf1J+CvRWboCUlaGUmu3vF19cB JyToObPdl+PAs68Mk5G1QU/NQ1CI4nk538GXd4+CR64ZasuRqIwVI1HowNOtk56Uti xshc0w5e3pPatBWK9JGZko09XqilsFvMS3Md6ClE= Subject: FAILED: patch "[PATCH] drm/xe/dma-buf: Validate BOs on export to charge the exporter" failed to apply to 6.18-stable tree To: thomas.hellstrom@linux.intel.com,airlied@redhat.com,matthew.auld@intel.com,matthew.brost@intel.com,rodrigo.vivi@intel.com Cc: From: Date: Wed, 02 Dec 2026 11:53:56 +0100 Message-ID: <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 The patch below does not apply to the 6.18-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y git checkout FETCH_HEAD git cherry-pick -x 22e05ee854e1bdacebcfa36ecd3f33ec80cf897a # git commit -s git send-email --to '' --in-reply-to '2026120256-untainted-bankable-4a8f@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..' Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 22e05ee854e1bdacebcfa36ecd3f33ec80cf897a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= Date: Wed, 11 Nov 2026 11:09:29 +0100 Subject: [PATCH] drm/xe/dma-buf: Validate BOs on export to charge the exporter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_buf.c index 6a85b292dee7..97299ca8f831 100644 --- a/drivers/gpu/drm/xe/xe_dma_buf.c +++ b/drivers/gpu/drm/xe/xe_dma_buf.c @@ -242,60 +242,62 @@ 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); - /* - * Reject exporting purgeable BOs. DONTNEED BOs can be purged - * at any time, making the exported dma-buf unusable. Purged BOs - * have no backing store and are permanently invalid. - */ - ret = xe_bo_lock(bo, true); + 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; + + /* + * Reject exporting purgeable BOs. DONTNEED BOs can be purged + * at any time, making the exported dma-buf unusable. Purged BOs + * have no backing store and are permanently invalid. + */ + if (xe_bo_madv_is_dontneed(bo)) { + ret = -EBUSY; + break; + } + + if (xe_bo_is_purged(bo)) { + ret = -EINVAL; + 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; + + xe_bo_willneed_get_locked(bo); + } if (ret) return ERR_PTR(ret); - if (xe_bo_madv_is_dontneed(bo)) { - ret = -EBUSY; - goto out_unlock; - } - - if (xe_bo_is_purged(bo)) { - ret = -EINVAL; - goto out_unlock; - } - - xe_bo_willneed_get_locked(bo); - xe_bo_unlock(bo); - - ret = ttm_bo_setup_export(&bo->ttm, &ctx); - if (ret) - goto out_put; - buf = drm_gem_prime_export(obj, flags); if (IS_ERR(buf)) { - ret = PTR_ERR(buf); - goto out_put; + xe_bo_lock(bo, false); + xe_bo_willneed_put_locked(bo); + xe_bo_unlock(bo); + return buf; } buf->ops = &xe_dmabuf_ops; return buf; - -out_put: - xe_bo_lock(bo, false); - xe_bo_willneed_put_locked(bo); -out_unlock: - xe_bo_unlock(bo); - return ERR_PTR(ret); } static struct drm_gem_object *