Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jan Maslak" <jan.maslak@intel.com>, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v5 1/4] drm/xe/xe_migrate: Fix page tracking in access_memory
Date: Wed, 14 Oct 2026 14:47:08 +0000	[thread overview]
Message-ID: <sashiko-outbox-171444@kernel.org> (raw)
In-Reply-To: <20261014142706.598490-2-jan.maslak@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/xe: DMA mapping leak due to unsafe 0 address check
--

commit fb4208eca07c762dce441a27786ec36c6738057d
Author: Christoph Manszewski <c.manszewski@gmail.com>

drm/xe/xe_migrate: Fix page tracking in access_memory

xe_migrate_access_memory() advances the pagemap cursor based on the current
page in the CPU buffer. Include the initial page offset when recalculating
current_page so subsequent iterations continue to index the mapped pages
correctly.

> diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
> index fffb3eb6c76eb..3711d4542ad3d 100644
> --- a/drivers/gpu/drm/xe/xe_migrate.c
> +++ b/drivers/gpu/drm/xe/xe_migrate.c
> @@ -2563,7 +2563,7 @@ int xe_migrate_access_memory(struct xe_migrate *m, struct xe_bo *bo,
>  
>  		buf += current_bytes;
>  		offset += current_bytes;
> -		current_page = (int)(buf - orig_buf) / PAGE_SIZE;
> +		current_page = (int)(buf - orig_buf + page_offset) / PAGE_SIZE;

[Severity: High]
Does this code leak DMA mappings when the DMA subsystem returns 0 as a valid
DMA address?

In the out_err block of xe_migrate_access_memory() in
drivers/gpu/drm/xe/xe_migrate.c, we unconditionally call
xe_migrate_dma_unmap():

out_err:
	xe_migrate_dma_unmap(xe, pagemap_addr, len + page_offset, write);

However, if xe_migrate_dma_unmap() encounters an IOVA of 0, it stops unmapping
early:

	if (!pagemap_addr[i].addr)
		break;

Since 0 is explicitly allowed as a valid DMA address by the DMA API (errors
are handled via dma_mapping_error()), this early break can cause the unmap
loop to terminate incorrectly. This would permanently leak the mapping for 0
and all subsequent valid mapped pages in the array. Can this eventually
exhaust IOMMU or DMA space?

>  		bytes_left -= current_bytes;
>  		if (bytes_left)
>  			xe_res_next(&cursor, current_bytes);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261014142706.598490-1-jan.maslak@intel.com?part=1

  reply	other threads:[~2026-10-14 14:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 14:27 [PATCH v5 0/4] drm/xe/xe_migrate: Fix memory corruption with unaligned dst in MEM_COPY Jan Maslak
2026-10-14 14:27 ` [PATCH v5 1/4] drm/xe/xe_migrate: Fix page tracking in access_memory Jan Maslak
2026-10-14 14:47   ` sashiko-bot [this message]
2026-10-14 14:27 ` [PATCH v5 2/4] drm/xe/xe_migrate: Align MEM_COPY pitch with destination address Jan Maslak
2026-10-14 14:41   ` sashiko-bot
2026-10-14 14:27 ` [PATCH v5 3/4] drm/xe/xe_migrate: Optimize unaligned access_memory copies Jan Maslak
2026-10-14 14:36   ` sashiko-bot
2026-10-14 14:27 ` [PATCH v5 4/4] drm/xe/tests: Add xe_migrate_access_memory subtest Jan Maslak
2026-10-14 14:45   ` sashiko-bot
2026-10-14 16:11 ` ✗ CI.checkpatch: warning for drm/xe/xe_migrate: Fix memory corruption with unaligned dst in MEM_COPY (rev5) Patchwork
2026-10-14 16:13 ` ✓ CI.KUnit: success " Patchwork
2026-10-14 23:56 ` ✗ Xe.CI.BAT: 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=sashiko-outbox-171444@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jan.maslak@intel.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox