Re: [PATCH 5/5] s390/hmcdrv: Replace page allocator calls with k[mz]alloc()
From: Heiko Carstens
Date: Wed Nov 18 2026 - 09:26:44 EST
On Tue, Nov 17, 2026 at 02:44:42PM +0200, Mike Rapoport wrote:
> > > int hmcdrv_cache_startup(size_t cachesize)
> > > {
> > > + if (cachesize > KMALLOC_MAX_SIZE)
> > > + return -ENOMEM;
> >
> > What is the reason for this check? I can see that this seems to be a
> > common pattern, however the buddy allocator would warn as well for
> > allocations larger than MAX_PAGE_ORDER if I'm not mistaken.
>
> Since cachesize is a module parameter there's a very corner case when it
> could have value within a page of ULONG_MAX. Then round_up() wraps to 0 and
> kmalloc(0) returns ZERO_SIZE_PTR rather than NULL and does not warn.
>
> The module would load with a bogus cache instead of failing as it does now.
>
> While it's really unlikely to happen in practice I'm sure Sashiko will be
> unhappy without this check :)
Ok, then let's keep that.
> > > + if (!ftp.len || ftp.len > KMALLOC_MAX_SIZE)
> > > + return -ENOMEM;
> >
> > Same here, and as far as I can tell the Sashiko finding seems to be
> > valid as well, even though it looks to me as if this worked only by
> > accident. Also, as far as I can see, the reported "delete" command is
> > currently not used at all from the only existing user space
> > application that I'm aware of. But let's not change this, please.
>
> Sashiko is wrong about get_order(0) returning 0, it actually returns 52, so
> __get_free_pages() returns NULL and we end up with -ENOMEM anyway :)
Yes, indeed.
> So it's either keep if (!ftp.len) and let it fail for "delete" like it does
> today or have
>
> size = round_up(ftp.len, PAGE_SIZE) ? : PAGE_SIZE;
>
> and allocate at least a page for ftp.len == 0.
>
> What's your preference?
Then let's keep the code as it is.
> The ftp.len > KMALLOC_MAX_SIZE check seems bogus indeed.
This can be removed when applying - no need to send a new version.
Reviewed-by: Heiko Carstens <hca@xxxxxxxxxxxxx>