From: Jason Gunthorpe <jgg@ziepe.ca>
To: Douglas Gilbert <dgilbert@interlog.com>
Cc: linux-scsi@vger.kernel.org, martin.petersen@oracle.com,
jejb@linux.vnet.ibm.com, hare@suse.de, bvanassche@acm.org,
bostroesser@gmail.com
Subject: Re: [PATCH v2 1/5] sgl_alloc_order: remove 4 GiB limit
Date: Tue, 15 Nov 2022 20:39:05 -0400 [thread overview]
Message-ID: <Y3QxKaDxAANwQVQf@ziepe.ca> (raw)
In-Reply-To: <844d8e7e-614f-105b-3b33-e471a1bb24d1@interlog.com>
On Tue, Nov 15, 2022 at 07:20:13PM -0500, Douglas Gilbert wrote:
> On 2022-11-15 15:33, Jason Gunthorpe wrote:
> > On Sat, Nov 12, 2022 at 02:49:35PM -0500, Douglas Gilbert wrote:
> > > This patch fixes a check done by sgl_alloc_order() before it starts
> > > any allocations. The comment in the original said: "Check for integer
> > > overflow" but the right hand side of the expression in the condition
> > > is resolved as u32 so it can not exceed UINT32_MAX (4 GiB) which
> > > means 'length' can not exceed that value.
> > >
> > > This function may be used to replace vmalloc(unsigned long) for a
> > > large allocation (e.g. a ramdisk). vmalloc has no limit at 4 GiB so
> > > it seems unreasonable that sgl_alloc_order() whose length type is
> > > unsigned long long should be limited to 4 GB.
> > >
> > > Solutions to this issue were discussed by Jason Gunthorpe
> > > <jgg@ziepe.ca> and Bodo Stroesser <bostroesser@gmail.com>. This
> > > version is base on a linux-scsi post by Jason titled: "Re:
> > > [PATCH v7 1/4] sgl_alloc_order: remove 4 GiB limit" dated 20220201.
> > >
> > > An earlier patch fixed a memory leak in sg_alloc_order() due to the
> > > misuse of sgl_free(). Take the opportunity to put a one line comment
> > > above sgl_free()'s declaration warning that it is not suitable when
> > > order > 0 .
> > >
> > > Cc: Jason Gunthorpe <jgg@ziepe.ca>
> > > Cc: Bodo Stroesser <bostroesser@gmail.com>
> > > Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
> > > ---
> > > include/linux/scatterlist.h | 1 +
> > > lib/scatterlist.c | 23 ++++++++++++++---------
> > > 2 files changed, 15 insertions(+), 9 deletions(-)
> >
> > I still prefer the version I posted here:
> >
> > https://lore.kernel.org/linux-scsi/Y1aDQznakNaWD8kd@ziepe.ca/
>
> Three reasons that I don't:
> 1) making the first argument of type size_t may constrict the size
> that can be allocated on a 32 bit machine (faint recollection of
> extended/expanded memory on 8086). uint64_t would be better
> than unsigned long long but see point 3)
32 bit machines can't kmap more than size_t - so this is not
correct. We can't put sgl tables into highmem.
> 2) making the last (fifth) argument of type size_t is overkill on a
> 64 bit machine. IMO 32 bits is sufficient.
IIRC, I changed it to obviously avoid integer promotion/truncation
issues. It is better to handle those with correct typing than
introducing a bunch of frail checks. We don't need to worry about the
extra 32 bits in something like this.
> 3) it changes the signature of an existing exported kernel function
> requiring changes in several call sites.
So fix them. It is why we have one git tree. You'll get sympathy if it
is more than 5-10 :)
> type may require more than a one line change at the existing call
> sites. Due to the fact that this patch is removing an existing
> 4 GB limit, those call sites have zero need for this. If I was
> maintaining the driver containing those call sites, I would be
> a bit peeved.
Uh, if someone is "peeved" they are not understanding how kernel APIs
are expected to evolve, I think.
It should be two patches, one to correct the types in the function
signature, and another to resolve the 4G problem.
> [That said, maintaining out-of-tree patchsets, while
> trying to get them accepted in the mainline, is a considerable
> pain due to the constant changes in the block layer API.]
Which is consistent with how the community views in-kernel APIs.
Jason
next prev parent reply other threads:[~2022-11-16 0:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-12 19:49 [PATCH v2 0/5] scatterlist: add operations for scsi_debug Douglas Gilbert
2022-11-12 19:49 ` [PATCH v2 1/5] sgl_alloc_order: remove 4 GiB limit Douglas Gilbert
2022-11-15 20:33 ` Jason Gunthorpe
2022-11-16 0:20 ` Douglas Gilbert
2022-11-16 0:39 ` Jason Gunthorpe [this message]
2022-11-12 19:49 ` [PATCH v2 2/5] scatterlist: add sgl_copy_sgl() function Douglas Gilbert
2022-11-16 5:59 ` Christoph Hellwig
2022-11-12 19:49 ` [PATCH v2 3/5] scatterlist: add sgl_equal_sgl() function Douglas Gilbert
2022-11-12 19:49 ` [PATCH v2 4/5] scatterlist: add sgl_memset() Douglas Gilbert
2022-11-12 19:49 ` [PATCH v2 5/5] scsi_debug: change store from vmalloc to sgl Douglas Gilbert
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=Y3QxKaDxAANwQVQf@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=bostroesser@gmail.com \
--cc=bvanassche@acm.org \
--cc=dgilbert@interlog.com \
--cc=hare@suse.de \
--cc=jejb@linux.vnet.ibm.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox