From: Andi Shyti <andi.shyti@kernel.org>
To: Krzysztof Karas <krzysztof.karas@intel.com>
Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
iommu@lists.linux.dev, "Andi Shyti" <andi.shyti@linux.intel.com>,
"Robin Murphy" <robin.murphy@arm.com>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"Michał Grzelak" <michal.grzelak@intel.com>,
"Janusz Krzysztofik" <janusz.krzysztofik@linux.intel.com>,
"Sebastian Brzezinka" <sebastian.brzezinka@intel.com>,
"Krzysztof Niemiec" <krzysztof.niemiec@intel.com>
Subject: Re: [PATCH v5 1/6] drm/i915/gem: Count mapped pages in a folio
Date: Wed, 19 Aug 2026 13:56:13 +0200 [thread overview]
Message-ID: <aoWMcLMNCl0cjcLx@zenone.zhora.eu> (raw)
In-Reply-To: <20260817095648.2438192-2-krzysztof.karas@intel.com>
Hi Krzysztof,
your patch looks good, but it needs to be polished a bit.
...
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> index 06543ae60706..f338dc39fad1 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> @@ -68,10 +68,13 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st,
> unsigned int max_segment)
> {
> unsigned int page_count; /* restricted by sg_alloc_table */
> - unsigned long i;
> + unsigned long next_pfn = 0; /* suppress gcc warning */
> + unsigned long folio_start = 0;
> + unsigned long folio_end = 0;
Can these go inside the for loop? Keep variables in the innermost
section needed.
Besides
> + struct folio *folio = NULL;
> struct scatterlist *sg;
> - unsigned long next_pfn = 0; /* suppress gcc warning */
> gfp_t noreclaim;
> + unsigned long i;
Please, don't reorder variables in this patch, it's out of the
scope.
> int ret;
>
> if (overflows_type(size / PAGE_SIZE, page_count))
> @@ -85,6 +88,9 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st,
> if (size > resource_size(&mr->region))
> return -ENOMEM;
>
> + if (max_segment < PAGE_SIZE)
> + return -EINVAL;
> +
the max_segment validation is out of the scope.
> if (sg_alloc_table(st, page_count, GFP_KERNEL | __GFP_NOWARN))
> return -ENOMEM;
>
> @@ -101,7 +107,7 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st,
> sg = st->sgl;
> st->nents = 0;
> for (i = 0; i < page_count; i++) {
> - struct folio *folio;
Why are you moving this out of the for loop?
> + unsigned long folio_page_index = 0;
This initialization is not necessary.
> unsigned long nr_pages;
> const unsigned int shrink[] = {
> I915_SHRINK_BOUND | I915_SHRINK_UNBOUND,
...
> + }
> + } while (1);
> +
> + folio_start = folio_pgoff(folio);
> + folio_end = folio_start + folio_nr_pages(folio) - 1;
> + }
> +
> + folio_page_index = i - folio_start;
> + if (WARN_ON_ONCE(folio_page_index >= folio_nr_pages(folio))) {
> + ret = -EINVAL;
> + folio_put(folio);
I think shmem_sg_free_table() drops the folio reference already,
right?
> + goto err_sg;
> + }
Is this WARN_ON_ONCE() check really necessary?
>
> nr_pages = min_array(((unsigned long[]) {
> - folio_nr_pages(folio),
> + folio_nr_pages(folio) - folio_page_index,
> page_count - i,
> max_segment / PAGE_SIZE,
> }), 3);
...
> @@ -186,6 +216,7 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st,
> i915_sg_trim(st);
>
> return 0;
> +
Drop this change
What I want from this patch is a minimal change, without any
churn not belonging to the sole scope of the patch.
Thanks, Krzysztof,
Andi
> err_sg:
> sg_mark_end(sg);
> if (sg != st->sgl) {
> --
> 2.34.1
>
next prev parent reply other threads:[~2026-08-19 11:56 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 9:56 [PATCH v5 0/6] drivers: Improve memory management for large object allocations when i915/shmem is used with iommu Krzysztof Karas
2026-08-17 9:56 ` [PATCH v5 1/6] drm/i915/gem: Count mapped pages in a folio Krzysztof Karas
2026-08-19 11:56 ` Andi Shyti [this message]
2026-08-31 10:10 ` Krzysztof Karas
2026-08-19 11:56 ` Janusz Krzysztofik
2026-08-31 10:58 ` Krzysztof Karas
2026-08-17 9:56 ` [PATCH 2/6] drm/i915/gem: Free sg table on failure to acquire second folio Krzysztof Karas
2026-08-17 9:56 ` [PATCH v5 3/6] iommu/dma: Catch scatterlist length overflows Krzysztof Karas
2026-08-17 10:11 ` sashiko-bot
2026-09-01 11:58 ` Krzysztof Karas
2026-08-18 12:10 ` Robin Murphy
2026-08-17 9:56 ` [PATCH v5 4/6] drm/i915/gem: Pull out size validation into a separate function Krzysztof Karas
2026-08-17 9:56 ` [PATCH v5 5/6] drm/i915/gem: Read and shrink memory in " Krzysztof Karas
2026-08-17 9:56 ` [PATCH v5 6/6] drm/i915/gem: Remove iterator and use while loop Krzysztof Karas
2026-08-17 15:01 ` ✓ i915.CI.BAT: success for drivers: Improve memory management for large object allocations when i915/shmem is used with iommu Patchwork
2026-08-18 3:30 ` ✓ i915.CI.Full: " 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=aoWMcLMNCl0cjcLx@zenone.zhora.eu \
--to=andi.shyti@kernel.org \
--cc=andi.shyti@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=iommu@lists.linux.dev \
--cc=janusz.krzysztofik@linux.intel.com \
--cc=jgg@ziepe.ca \
--cc=krzysztof.karas@intel.com \
--cc=krzysztof.niemiec@intel.com \
--cc=michal.grzelak@intel.com \
--cc=robin.murphy@arm.com \
--cc=sebastian.brzezinka@intel.com \
/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.