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 4/7] drm/xe/vm: Add madvise autoreset notifier worker
Date: Thu, 04 Jun 2026 10:14:55 +0000	[thread overview]
Message-ID: <20260604101456.0E5371F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260604095012.367231-5-arvind.yadav@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Returning false for non-blockable invalidations incorrectly prevents the OOM reaper from unmapping memory.
- [Medium] Redundant VMA splitting for partial overlaps when the VMA already has default attributes.
--

commit fe0b22bc527cb1c9caa55068f36be5982435fd31
Author: Arvind Yadav <arvind.yadav@intel.com>

drm/xe/vm: Add madvise autoreset notifier worker

This commit adds a worker to reset madvise-managed VMA attributes when
userspace unmaps CPU-only mirror ranges. It uses an MMU notifier callback
to record pending unmap events and widens the range if multiple unmaps
arrive before the worker runs. The worker then resets attributes for ranges
not covered by a CPU VMA.

> diff --git a/drivers/gpu/drm/xe/xe_vm_madvise.c b/drivers/gpu/drm/xe/xe_vm_madvise.c
> index c4fb290041956..c2abe712598a1 100644
> --- a/drivers/gpu/drm/xe/xe_vm_madvise.c
> +++ b/drivers/gpu/drm/xe/xe_vm_madvise.c
[ ... ]
> @@ -732,3 +738,501 @@ int xe_vm_madvise_ioctl(struct drm_device *dev, void *data, struct drm_file *fil
[ ... ]
> +static int xe_vm_madvise_process_unmap(struct xe_vm *vm, u64 start, u64 end)
> +{
[ ... ]
> +		has_default_attr = xe_vma_has_default_mem_attrs(vma);
> +		seg_start = max(addr, xe_vma_start(vma));
> +		seg_end = min(end, xe_vma_end(vma));
> +
> +		/* Merge adjacent default-attr VMAs when possible. */
> +		if (has_default_attr &&
> +		    xe_vma_start(vma) >= start &&
> +		    xe_vma_end(vma) <= end) {
> +			seg_start = xe_vma_start(vma);
> +			seg_end = xe_vma_end(vma);
> +			xe_vm_find_cpu_addr_mirror_vma_range(vm, &seg_start, &seg_end);
> +			if (xe_vma_start(vma) == seg_start && xe_vma_end(vma) == seg_end) {
> +				/* Nothing to merge. */
> +				addr = seg_end;
> +				continue;
> +			}
> +		} else if (xe_vma_start(vma) == seg_start && xe_vma_end(vma) == seg_end) {
> +			/* Exact VMA match, reset in place. */
> +			xe_vma_reset_to_default_attrs(vma);
> +			addr = seg_end;
> +			continue;
> +		}
> +
> +		err = xe_vm_alloc_cpu_addr_mirror_vma(vm, seg_start, seg_end - seg_start);

[Severity: Medium]
When a CPU hole partially overlaps a GPU VMA that already has default
attributes, will this fall through to xe_vm_alloc_cpu_addr_mirror_vma() and
cause redundant VMA splitting?

If the overlap is strictly partial, both the if and else if conditions above
fail. The fall-through maps the overlapping portion with default attributes,
forcing the GPUVM infrastructure to split the existing VMA. 

Since the existing VMA already possessed default attributes, this split
appears to be redundant and might needlessly fragment a single large VMA into
smaller identical pieces. Repeated partial unmaps from userspace could
artificially fragment the VMA tree and leak xe_vma objects.

[ ... ]
> +static bool xe_madvise_notifier_callback(struct mmu_interval_notifier *mni,
> +					 const struct mmu_notifier_range *range,
> +					 unsigned long cur_seq)
> +{
> +	struct xe_madvise_notifier *notifier =
> +		container_of(mni, struct xe_madvise_notifier, mmu_notifier);
> +	struct xe_vm *vm = notifier->vm;
> +	u64 adj_start, adj_end;
> +
> +	if (range->event != MMU_NOTIFY_UNMAP)
> +		return true;
> +
> +	if (!mmu_notifier_range_blockable(range))
> +		return false;

[Severity: High]
Does returning false for non-blockable invalidations incorrectly prevent the
OOM reaper from unmapping memory?

Because the callback implementation is entirely non-blocking (it relies on
down_read_trylock(), spin_lock(), and queue_work()), there seems to be no
technical limitation requiring it to block. 

Returning false from an MMU interval notifier's invalidate callback signals
that the invalidation could not be completed without blocking, causing
__mmu_notifier_invalidate_range_start() to return -EAGAIN. 

Since the OOM reaper operates in a non-blockable context, receiving -EAGAIN
means it cannot retry indefinitely and will skip the VMA, failing to reclaim
the memory and defeating the purpose of the OOM killer. Could this safely
process the event and unconditionally return true for unmap events instead?

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

  reply	other threads:[~2026-06-04 10:14 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 [this message]
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
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=20260604101456.0E5371F00893@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.