All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Krzysztof Karas" <krzysztof.karas@intel.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 4/5] drm/i915/gem: Read and shrink memory in a separate function
Date: Thu, 23 Jul 2026 11:26:07 +0000	[thread overview]
Message-ID: <20260723112608.42E4B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260723102542.3245495-5-krzysztof.karas@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Memory leak on error path in `shmem_sg_alloc_table` when failing to allocate after populating exactly one scatterlist entry.
--

--- Patch [4]: [PATCH v4 4/5] drm/i915/gem: Read and shrink memory in a separate function ---
commit 5dd680cf1299c10f0034b5b2b67f54aa39eb638d
Author: Krzysztof Karas <krzysztof.karas@intel.com>

drm/i915/gem: Read and shrink memory in a separate function

This commit extracts the page reading and memory shrinking logic from
shmem_sg_alloc_table() into a new helper function shmem_shrink_get_folio().
It also removes a loop, noting that multiple shrink calls do not provide
additional benefits.

> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> index f35b7efa1fc23..ac8022997553b 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c

[ ... ]

> @@ -119,57 +169,16 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st,
>  	for (i = 0; i < page_count; i++) {
>  		unsigned long folio_page_index = 0;
>  		unsigned long nr_pages;
> -		const unsigned int shrink[] = {
> -			I915_SHRINK_BOUND | I915_SHRINK_UNBOUND,
> -			0,
> -		}, *s = shrink;
>  		gfp_t gfp = noreclaim;
>  
>  		/* Grab the next folio if we exhausted the current one. */
>  		if (!i || i > folio_end) {
> -			do {

[ ... ]

> +			folio = shmem_shrink_get_folio(mapping, i, gfp,
> +						       page_count, i915);
> +			if (IS_ERR(folio)) {
> +				ret = PTR_ERR(folio);
> +				goto err_sg;
> +			}

[Severity: High]
This is a pre-existing issue, but does this error path leak memory if the
allocation fails after exactly one scatterlist entry is populated?

Looking at the error handling for shmem_sg_alloc_table in
drivers/gpu/drm/i915/gem/i915_gem_shmem.c:

err_sg:
	sg_mark_end(sg);
	if (sg != st->sgl) {
		shmem_sg_free_table(st, mapping, false, false);
	} else {
		mapping_clear_unevictable(mapping);
		sg_free_table(st);
	}

If a folio is successfully allocated and added to the first scatterlist
entry, but the loop fails on a subsequent iteration before sg is advanced
with sg_next(), sg will still equal st->sgl.

When we jump to err_sg under this condition, the code skips calling
shmem_sg_free_table and only frees the scatterlist structure via
sg_free_table. Could this bypass the reference count decrements for the
folios already added to the first scatterlist entry, causing a permanent
leak during memory exhaustion?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260723102542.3245495-1-krzysztof.karas@intel.com?part=4

  reply	other threads:[~2026-07-23 11:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23 10:25 [PATCH v4 0/5] drivers: Improve memory management for large object allocations when i915/shmem is used with iommu Krzysztof Karas
2026-07-23 10:25 ` [PATCH v4 1/5] drm/i915/gem: Count mapped pages in a folio Krzysztof Karas
2026-07-23 10:51   ` sashiko-bot
2026-07-23 10:25 ` [PATCH v4 2/5] iommu/dma: Catch scatterlist length overflows Krzysztof Karas
2026-07-23 11:01   ` sashiko-bot
2026-07-23 10:25 ` [PATCH v4 3/5] drm/i915/gem: Pull out size validation into a separate function Krzysztof Karas
2026-07-23 11:14   ` sashiko-bot
2026-07-23 10:25 ` [PATCH v4 4/5] drm/i915/gem: Read and shrink memory in " Krzysztof Karas
2026-07-23 11:26   ` sashiko-bot [this message]
2026-07-23 10:25 ` [PATCH v4 5/5] drm/i915/gem: Remove iterator and use while loop Krzysztof Karas
2026-07-23 11:39   ` sashiko-bot
2026-07-23 11:39 ` ✓ i915.CI.BAT: success for drivers: Improve memory management for large object allocations when i915/shmem is used with iommu 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=20260723112608.42E4B1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=krzysztof.karas@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 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.