mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: aquiles <achillezongo07@gmail.com>
To: matthew.brost@intel.com, thomas.hellstrom@linux.intel.com,
	rodrigo.vivi@intel.com
Cc: airlied@gmail.com, simona@ffwll.ch,
	intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, aquiles <achillezongo07@gmail.com>
Subject: [PATCH v2 2/2] drm/xe: skip resv fence wait in xe_svm_invalidate if no ranges are bound
Date: Fri, 26 Jun 2026 11:58:08 +0000	[thread overview]
Message-ID: <20260626115808.2072258-1-achillezongo07@gmail.com> (raw)

xe_svm_invalidate() waited on the VM's reservation object fences before
processing MMU notifier events, even when no range in the affected
address region had active GPU bindings (tile_present == 0).

Add a pre-scan over the affected ranges and skip dma_resv_wait_timeout()
when no range needs invalidation and all BOOKKEEP fences are already
signaled. The fence check is necessary because tile_present is cleared
when an unbind is submitted, not when the GPU job completes — skipping
the wait without it risks unmapping DMA while an unbind is still in flight.

Signed-off-by: aquiles <achillezongo07@gmail.com>
---
 drivers/gpu/drm/xe/xe_svm.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_svm.c b/drivers/gpu/drm/xe/xe_svm.c
index e1651e70c..447c5c965 100644
--- a/drivers/gpu/drm/xe/xe_svm.c
+++ b/drivers/gpu/drm/xe/xe_svm.c
@@ -233,6 +233,7 @@ static void xe_svm_invalidate(struct drm_gpusvm *gpusvm,
 	ktime_t start = xe_gt_stats_ktime_get();
 	u64 adj_start = mmu_range->start, adj_end = mmu_range->end;
 	u8 tile_mask = 0, id;
+	bool needs_inval = false;
 	long err;
 
 	xe_svm_assert_in_notifier(vm);
@@ -258,11 +259,22 @@ static void xe_svm_invalidate(struct drm_gpusvm *gpusvm,
 	if (xe_vm_is_closed(vm))
 		goto range_notifier_event_end;
 
-	/*
-	 * XXX: Less than ideal to always wait on VM's resv slots if an
-	 * invalidation is not required. Could walk range list twice to figure
-	 * out if an invalidations is need, but also not ideal.
-	 */
+	/* Pre-scan: skip fence wait if no range has active GPU bindings. */
+
+	r = first;
+	drm_gpusvm_for_each_range(r, notifier, adj_start, adj_end) {
+		struct xe_svm_range *range = to_xe_range(r);
+
+		if (!range->base.pages.flags.unmapped && range->tile_present) {
+			needs_inval = true;
+			break;
+		}
+
+	}
+	if (!needs_inval &&
+	    dma_resv_test_signaled(xe_vm_resv(vm), DMA_RESV_USAGE_BOOKKEEP))
+		goto range_notifier_event_end;
+
 	err = dma_resv_wait_timeout(xe_vm_resv(vm),
 				    DMA_RESV_USAGE_BOOKKEEP,
 				    false, MAX_SCHEDULE_TIMEOUT);
-- 
2.54.0


                 reply	other threads:[~2026-06-26 11:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260626115808.2072258-1-achillezongo07@gmail.com \
    --to=achillezongo07@gmail.com \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.brost@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=simona@ffwll.ch \
    --cc=thomas.hellstrom@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®