From: sashiko-bot@kernel.org
To: "Alice Ryhl" <aliceryhl@google.com>
Cc: dri-devel@lists.freedesktop.org, ojeda@kernel.org, gary@garyguo.net
Subject: Re: [PATCH 3/4] drm/tyr: vm: expand sub-block unmaps to 2MB boundaries on remap
Date: Tue, 17 Nov 2026 20:02:54 +0000 [thread overview]
Message-ID: <sashiko-outbox-219548@kernel.org> (raw)
In-Reply-To: <20261117-tyr-remap-2mb-v1-3-2a8efd4c8180@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/tyr: page table desync and GpuVa leak on pt_map() error
in sm_step_remap()
--
commit 890e6d1a0c182be186e5d6f90855d935bae30eda
Author: Sami Tolvanen <samitolvanen@google.com>
drm/tyr: vm: expand sub-block unmaps to 2MB boundaries on remap
This commit expands sub-block unmaps in sm_step_remap() to 2MB boundaries when
the surviving fragments are physically contiguous and remaps the surviving
head and tail fragments as 4KB pages.
> diff --git a/drivers/gpu/drm/tyr/vm.rs b/drivers/gpu/drm/tyr/vm.rs
> index 1dd11b2b12532..bcc864b174284 100644
> --- a/drivers/gpu/drm/tyr/vm.rs
> +++ b/drivers/gpu/drm/tyr/vm.rs
[ ... ]
> @@ -749,10 +780,50 @@ fn sm_step_remap<'op>(
> op.va_to_unmap().addr() + op.va_to_unmap().length()
> };
>
> - let unmap_length = unmap_end - unmap_start;
> + // The surviving fragments inherit the protection of the mapping being
> + // split.
> + let prot = op.va_to_unmap().data_ref().prot;
> +
> + let block = Alignment::SZ_2M;
> + let aligned_start = unmap_start.align_down(block);
> + let aligned_end = unmap_end.align_up(block).ok_or(EINVAL)?;
> +
> + // An end may only be expanded if the fragment the expansion sweeps and
> + // rebuilds is fully mapped and physically contiguous, because the
> + // rebuild maps it linearly from a single recovered address. A genuine
> + // 2MB block is always contiguous, so this never misses one and the
> + // partial-block unmap can never reach arm-lpae. A fragmented region is
> + // never expanded, so its sub-range unmap stays correct.
> + let head_paddr = match op.prev() {
> + Some(prev) if aligned_start < unmap_start && prev.addr() <= aligned_start => {
> + contiguous_phys(context.pt, aligned_start..unmap_start)
> + }
> + _ => None,
> + };
> + let tail_paddr = match op.next() {
> + Some(next) if aligned_end > unmap_end && next.addr() + next.length() >= aligned_end => {
> + contiguous_phys(context.pt, unmap_end..aligned_end)
> + }
> + _ => None,
> + };
> +
> + let region_start = if head_paddr.is_some() {
> + aligned_start
> + } else {
> + unmap_start
> + };
> + let region_end = if tail_paddr.is_some() {
> + aligned_end
> + } else {
> + unmap_end
> + };
> +
> + let prev_va = context.preallocated_gpuva()?;
> + let next_va = context.preallocated_gpuva()?;
>
> - if unmap_length > 0 {
> - let region = unmap_start..(unmap_start + unmap_length);
> + if region_end > region_start {
> + let region = region_start..region_end;
> + context.extend_lock(region.clone())?;
> pt_unmap(context.dev, context.pt, region.clone()).inspect_err(|e| {
> dev_err!(
> context.dev,
> @@ -764,14 +835,29 @@ fn sm_step_remap<'op>(
> })?;
> }
>
> - let prev_va = context.preallocated_gpuva()?;
> - let next_va = context.preallocated_gpuva()?;
> + if let Some(head_paddr) = head_paddr {
> + pt_map(
> + context.dev,
> + context.pt,
> + aligned_start,
> + head_paddr,
> + unmap_start - aligned_start,
> + prot,
> + )?;
> + }
> + if let Some(tail_paddr) = tail_paddr {
> + pt_map(
> + context.dev,
> + context.pt,
> + unmap_end,
> + tail_paddr,
> + aligned_end - unmap_end,
> + prot,
> + )?;
> + }
>
> - let (op_remapped, remap_ret) = op.remap(
> - [prev_va, next_va],
> - pin_init::init_zeroed(),
> - pin_init::init_zeroed(),
> - );
> + let (op_remapped, remap_ret) =
> + op.remap([prev_va, next_va], GpuVaData { prot }, GpuVaData { prot });
[Severity: Medium]
Can a pt_map() failure here leave context.pt out of sync with GpuVm and leak
the GpuVa?
pt_unmap() has already torn down the expanded 2MB range in context.pt before
pt_map() allocates L3 page tables for the surviving 4KB fragments. If either
pt_map() fails with ENOMEM, sm_step_remap() returns without restoring the
unmapped range in context.pt or updating the GpuVm tree via op.remap().
When Vm::kill() or Vm::unmap_range() later calls sm_step_unmap() on the
unsplit GpuVa, pt_unmap() hits the already-unmapped PTEs, triggers a WARN_ON
in __arm_lpae_unmap(), and returns Err(EINVAL) before op.remove() can unlink
and free the GpuVa and its GEM BO references.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-tyr-remap-2mb-v1-0-2a8efd4c8180@google.com?part=3
next prev parent reply other threads:[~2026-11-17 20:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 19:32 [PATCH 0/4] drm/tyr: fix partial 2MB block unmaps on GPUVM remap Alice Ryhl
2026-11-17 19:32 ` [PATCH 1/4] rust: drm/gpuvm: add GpuVa::data_ref accessor Alice Ryhl
2026-11-17 19:40 ` Danilo Krummrich
2026-11-17 19:32 ` [PATCH 2/4] rust: iommu: pgtable: add iova_to_phys Alice Ryhl
2026-11-17 19:32 ` [PATCH 3/4] drm/tyr: vm: expand sub-block unmaps to 2MB boundaries on remap Alice Ryhl
2026-11-17 20:02 ` sashiko-bot [this message]
2026-11-17 19:32 ` [PATCH 4/4] drm/tyr: vm: check the remaining length in pt_unmap() Alice Ryhl
2026-11-18 3:40 ` [PATCH 0/4] drm/tyr: fix partial 2MB block unmaps on GPUVM remap Deborah Brouwer
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=sashiko-outbox-219548@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=aliceryhl@google.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=ojeda@kernel.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.