From: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
To: Andi Shyti <andi.shyti@kernel.org>
Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
Jani Nikula <jani.nikula@linux.intel.com>,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>,
Tvrtko Ursulin <tursulin@ursulin.net>,
Andi Shyti <andi.shyti@linux.intel.com>,
Andrew Morton <akpm@linux-foundation.org>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
Krzysztof Karas <krzysztof.karas@intel.com>,
Sebastian Brzezinka <sebastian.brzezinka@intel.com>,
Krzysztof Niemiec <krzysztof.niemiec@intel.com>
Subject: Re: [PATCH] drm/i915: Fix potential overflow of shmem scatterlist length
Date: Wed, 25 Feb 2026 16:11:31 +0100 [thread overview]
Message-ID: <5887622.44csPzL39Z@jkrzyszt-mobl2.ger.corp.intel.com> (raw)
In-Reply-To: <aZ7h4pJlB70wf7In@zenone.zhora.eu>
Hi Andi,
Thanks for review.
On Wednesday, 25 February 2026 15:41:13 CET Andi Shyti wrote:
> Hi Janusz,
>
> ...
>
> > @@ -153,8 +153,12 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st,
> > }
> > } while (1);
> >
>
> Perhaps we could add here:
>
> max_pages = max_segment >> PAGE_SHIFT;
> /* Just to be paranoic, but not necessary */
> if (!max_pages)
GEM_BUG_ON(!max_pages), I would rather say. The max_segment comes from
drivers/gpu/drm/i915/i915_scatterlist.h:i915_sg_segment_size(struct device *dev),
let's assume that can't be that much broken.
> max_pages = 1;
>
>
> > - nr_pages = min_t(unsigned long,
> > - folio_nr_pages(folio), page_count - i);
> > + nr_pages = min_array(((unsigned long[]) {
> > + folio_nr_pages(folio),
> > + page_count - i,
> > + max_segment / PAGE_SIZE,
>
> max_segment >> PAGE_SHIFT ?
Yeah, shift seems more optimal than division here, however, I've just followed
the patter used a few lines below. where we can see a multiplication, not a
right shift, and since PAGE_SIZE is a constant, I hope the compiler will
optimize that.
>
> For clarity this can be written as
>
> nr_pages = min_t(unsigned long,
> folio_nr_pages(folio), page_count - i);
> nr_pages = min_t(unsigned long, nr_pages, max_pages);
Do you think the min_array() is less clear? Let's see what others say.
>
> But these are nitpicks, it's then up to you to choose the style.
>
> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Thank you,
Janusz
>
> Thanks,
> Andi
>
> > + }), 3);
> > +
>
next prev parent reply other threads:[~2026-02-25 15:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-24 9:49 [PATCH] drm/i915: Fix potential overflow of shmem scatterlist length Janusz Krzysztofik
2026-02-25 14:41 ` Andi Shyti
2026-02-25 15:11 ` Janusz Krzysztofik [this message]
2026-02-25 15:38 ` Andi Shyti
2026-02-25 17:29 ` Janusz Krzysztofik
2026-02-26 12:23 ` Andi Shyti
2026-02-26 13:02 ` Sebastian Brzezinka
2026-02-27 5:21 ` Claude review: " Claude Code Review Bot
2026-02-27 5:21 ` Claude Code Review Bot
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=5887622.44csPzL39Z@jkrzyszt-mobl2.ger.corp.intel.com \
--to=janusz.krzysztofik@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=andi.shyti@kernel.org \
--cc=andi.shyti@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=krzysztof.karas@intel.com \
--cc=krzysztof.niemiec@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=sebastian.brzezinka@intel.com \
--cc=tursulin@ursulin.net \
--cc=willy@infradead.org \
/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