All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arvind Yadav" <arvind.yadav@intel.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [RFC v3 7/7] drm/xe/svm: Correct memory attribute reset for partial unmap
Date: Thu, 04 Jun 2026 10:12:17 +0000	[thread overview]
Message-ID: <20260604101217.6A9021F00898@smtp.kernel.org> (raw)
In-Reply-To: <20260604095012.367231-8-arvind.yadav@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Concurrent MMU notifiers fail to queue partial unmap range updates due to list poisoning, causing unmapped regions to retain stale attributes.
- [High] Disjoint partial unmaps are silently ignored during coalescing, preventing their VMA memory attributes from being reset.
--

commit 63782c32791ae66c7e1c022f8db4a4b168c0d897
Author: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>

drm/xe/svm: Correct memory attribute reset for partial unmap

When performing a partial unmap of an SVM range, the memory attributes
were being reset for the entire range instead of just the portion
being unmapped. This could lead to unintended side effects and behaviour.

> diff --git a/drivers/gpu/drm/xe/xe_svm.c b/drivers/gpu/drm/xe/xe_svm.c
> --- a/drivers/gpu/drm/xe/xe_svm.c
> +++ b/drivers/gpu/drm/xe/xe_svm.c
> @@ -127,6 +129,34 @@ static void xe_svm_range_free(struct drm_gpusvm_range *range)
[ ... ]
> +static void xe_svm_range_set_unmapped(struct xe_svm_range *range,
> +				      const struct mmu_notifier_range *mmu_range)
> +{
> +	u64 new_start = max_t(u64, xe_svm_range_start(range), mmu_range->start);
> +	u64 new_end = min_t(u64, xe_svm_range_end(range), mmu_range->end);
> +
> +	drm_gpusvm_range_set_unmapped(&range->base, mmu_range);
> +	if (range->base.pages.flags.partial_unmap) {
> +		if (range->partial_unmap.start || range->partial_unmap.end) {
> +			/*
> +			 * Coalesce overlapping or adjacent intervals.
> +			 * Disjoint ranges cannot be tracked in one interval
> +			 * without covering still-mapped memory.
> +			 */
> +			if (new_start <= range->partial_unmap.end &&
> +			    new_end >= range->partial_unmap.start) {
> +				range->partial_unmap.start =
> +					min(range->partial_unmap.start, new_start);
> +				range->partial_unmap.end =
> +					max(range->partial_unmap.end, new_end);
> +			}

[Severity: High]
If the new partial unmap is disjoint from the tracked interval, the overlap
condition evaluates to false. Because there is no else block here, does
this mean the disjoint interval is silently discarded?

If so, the garbage collector might only reset the VMA attributes for the
initial subrange, leaving the disjoint unmapped region with stale memory
attributes.

> +		} else {
> +			range->partial_unmap.start = new_start;
> +			range->partial_unmap.end = new_end;
> +		}
> +	}
> +}
[ ... ]
> @@ -135,12 +165,14 @@ xe_svm_garbage_collector_add_range(struct xe_vm *vm, struct xe_svm_range *range,
>  
>  	range_debug(range, "GARBAGE COLLECTOR ADD");
>  
> -	drm_gpusvm_range_set_unmapped(&range->base, mmu_range);
> -
>  	spin_lock(&vm->svm.garbage_collector.lock);
> +
> +	xe_svm_range_set_unmapped(range, mmu_range);
> +
>  	if (list_empty(&range->garbage_collector_link))
>  		list_add_tail(&range->garbage_collector_link,
>  			      &vm->svm.garbage_collector.range_list);
> +
>  	spin_unlock(&vm->svm.garbage_collector.lock);

[Severity: High]
Is it possible to lose concurrent MMU notifier updates here due to list
poisoning?

In xe_svm_garbage_collector(), the worker thread removes the item using
list_del(), which poisons the list node pointers, and then the lock is
dropped:

xe_svm_garbage_collector() {
    ...
    list_del(&range->garbage_collector_link);
    spin_unlock(&vm->svm.garbage_collector.lock);
    ...
}

If a concurrent MMU notifier fires for the same range during this unlocked
window, xe_svm_garbage_collector_add_range() acquires the lock, updates the
partial unmap bounds, and evaluates the list_empty() condition above.

Because the pointers are poisoned, list_empty() evaluates to false, and the
range is not re-queued. Would this cause the VMA attributes for this
concurrent unmap to never be reset? 

Note that switching to list_del_init() would allow it to be re-queued, but
could that introduce a use-after-free since the worker then destroys the
range?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260604095012.367231-1-arvind.yadav@intel.com?part=7

  reply	other threads:[~2026-06-04 10:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-04  9:50 [RFC v3 0/7] drm/xe/svm: Add MMU notifier-based madvise autoreset on munmap Arvind Yadav
2026-06-04  9:50 ` [RFC v3 1/7] drm/xe/vm: Track CPU_AUTORESET state in xe_vma Arvind Yadav
2026-06-04  9:50 ` [RFC v3 2/7] drm/xe/vm: Preserve cpu_autoreset_active across GPUVA operations Arvind Yadav
2026-06-04 10:07   ` sashiko-bot
2026-06-04  9:50 ` [RFC v3 3/7] drm/xe/svm: Clear CPU_AUTORESET_ACTIVE on first GPU fault Arvind Yadav
2026-06-04  9:50 ` [RFC v3 4/7] drm/xe/vm: Add madvise autoreset notifier worker Arvind Yadav
2026-06-04 10:14   ` sashiko-bot
2026-06-04  9:50 ` [RFC v3 5/7] drm/xe/vm: Disable madvise notifier on GPU touch Arvind Yadav
2026-06-04 10:03   ` sashiko-bot
2026-06-04  9:50 ` [RFC v3 6/7] drm/xe/vm: Wire MADVISE_AUTORESET notifiers into VM lifecycle Arvind Yadav
2026-06-04 10:05   ` sashiko-bot
2026-06-04  9:50 ` [RFC v3 7/7] drm/xe/svm: Correct memory attribute reset for partial unmap Arvind Yadav
2026-06-04 10:12   ` sashiko-bot [this message]
2026-06-04 10:32 ` ✗ CI.checkpatch: warning for drm/xe/svm: Add MMU notifier-based madvise autoreset on munmap (rev3) Patchwork
2026-06-04 10:34 ` ✓ CI.KUnit: success " Patchwork
2026-06-04 11:35 ` ✓ Xe.CI.BAT: " Patchwork
2026-06-05  0:02 ` ✗ Xe.CI.FULL: failure " Patchwork

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=20260604101217.6A9021F00898@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=arvind.yadav@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.