Re: [PATCH v4 2/7] mm/slab: Give bucket caches the alignment of the caches they mirror

From: Kees Cook

Date: Thu Sep 24 2026 - 21:00:55 EST


On Thu, Sep 24, 2026 at 07:22:58PM +0100, Harry Yoo wrote:
> On Mon, Sep 21, 2026 at 04:25:25PM -0700, Kees Cook wrote:
> > On Mon, Sep 21, 2026 at 02:17:21PM +0100, Harry Yoo wrote:
> > > On Mon, Sep 21, 2026 at 12:58:13AM -0700, Kees Cook wrote:
> > > > if (WARN_ON(!cache_name))
> > > > goto fail;
> > > > (*b)[aligned_idx] = kmem_cache_create_usercopy(cache_name, size,
> > > > - 0, flags, cache_useroffset,
> > > > + kmalloc_caches[KMALLOC_NORMAL][idx]->align,
> > > > + flags, cache_useroffset,
> > > > cache_usersize, ctor);
> > > > kfree(cache_name);
> > > > if (WARN_ON(!(*b)[aligned_idx]))
> >
> > It looks "obviously correct", but I probably failed to correctly
> > describe it. I'm happy to do whatever here.
>
> That is correct, but is there any reason why kmem_buckets users should
> not specify their own alignment requirement and inherit the alignment
> from kmalloc?
>
> For DMA yeah it might be confusing for every user to figure out that
> the alignment should be __kmalloc_minalign(), but otherwise there isn't
> really a good enough reason to inherit the alignment from kmalloc, no?

Oh, so you mean explicitly add an alignment arg to kmem_buckets_create()?
And perhaps if _that_ one is "0" we can fallback to whatever
kmalloc_caches uses?

--
Kees Cook