All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND PATCH] mm: slab: Do not create kmalloc caches smaller than arch_slab_minalign()
@ 2023-10-06 16:39 Catalin Marinas
  2023-10-09  8:22 ` Vlastimil Babka
  0 siblings, 1 reply; 4+ messages in thread
From: Catalin Marinas @ 2023-10-06 16:39 UTC (permalink / raw)
  To: linux-mm, Andrew Morton
  Cc: linux-kernel, Mark Rutland, Vlastimil Babka, Peter Collingbourne

Commit b035f5a6d852 ("mm: slab: reduce the kmalloc() minimum alignment
if DMA bouncing possible") allows architectures with non-coherent DMA to
define a small ARCH_KMALLOC_MINALIGN (e.g. sizeof(unsigned long long))
and this has been enabled on arm64. With KASAN_HW_TAGS enabled, however,
ARCH_SLAB_MINALIGN becomes 16 on arm64 (arch_slab_minalign() dynamically
selects it since commit d949a8155d13 ("mm: make minimum slab alignment a
runtime property")). This can lead to a situation where kmalloc-8 caches
are attempted to be created with a kmem_caches.size aligned to 16. When
the cache is mergeable, it can lead to kernel warnings like:

sysfs: cannot create duplicate filename '/kernel/slab/:d-0000016'
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.6.0-rc1-00001-gda98843cd306-dirty #5
Hardware name: QEMU QEMU Virtual Machine, BIOS 0.0.0 02/06/2015
Call trace:
 dump_backtrace+0x90/0xe8
 show_stack+0x18/0x24
 dump_stack_lvl+0x48/0x60
 dump_stack+0x18/0x24
 sysfs_warn_dup+0x64/0x80
 sysfs_create_dir_ns+0xe8/0x108
 kobject_add_internal+0x98/0x264
 kobject_init_and_add+0x8c/0xd8
 sysfs_slab_add+0x12c/0x248
 slab_sysfs_init+0x98/0x14c
 do_one_initcall+0x6c/0x1b0
 kernel_init_freeable+0x1c0/0x288
 kernel_init+0x24/0x1e0
 ret_from_fork+0x10/0x20
kobject: kobject_add_internal failed for :d-0000016 with -EEXIST, don't try to register things with the same name in the same directory.
SLUB: Unable to add boot slab dma-kmalloc-8 to sysfs

Limit the __kmalloc_minalign() return value (used to create the
kmalloc-* caches) to arch_slab_minalign() so that kmalloc-8 caches are
skipped when KASAN_HW_TAGS is enabled (both config and runtime).

Fixes: b035f5a6d852 ("mm: slab: reduce the kmalloc() minimum alignment if DMA bouncing possible")
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Reported-by: Mark Rutland <mark.rutland@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Peter Collingbourne <pcc@google.com>
Cc: <stable@vger.kernel.org> # 6.5.x
---

The previous post was messed up by my git send-email configuration, so
sending it again. Also cc'ing Vlastimil since he reviewed the previous
slab changes for ARCH_KMALLOC_MINALIGN. Thanks.

 mm/slab_common.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/mm/slab_common.c b/mm/slab_common.c
index cd71f9581e67..8b45922ed295 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -895,10 +895,13 @@ void __init setup_kmalloc_cache_index_table(void)
 
 static unsigned int __kmalloc_minalign(void)
 {
+	unsigned int minalign = dma_get_cache_alignment();
+
 	if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) &&
 	    is_swiotlb_allocated())
-		return ARCH_KMALLOC_MINALIGN;
-	return dma_get_cache_alignment();
+		minalign = ARCH_KMALLOC_MINALIGN;
+
+	return ALIGN(minalign, arch_slab_minalign());
 }
 
 void __init

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [RESEND PATCH] mm: slab: Do not create kmalloc caches smaller than arch_slab_minalign()
  2023-10-06 16:39 [RESEND PATCH] mm: slab: Do not create kmalloc caches smaller than arch_slab_minalign() Catalin Marinas
@ 2023-10-09  8:22 ` Vlastimil Babka
  2023-10-09 11:20   ` Catalin Marinas
  0 siblings, 1 reply; 4+ messages in thread
From: Vlastimil Babka @ 2023-10-09  8:22 UTC (permalink / raw)
  To: Catalin Marinas, linux-mm, Andrew Morton
  Cc: linux-kernel, Mark Rutland, Peter Collingbourne, Petr Tesarik

On 10/6/23 18:39, Catalin Marinas wrote:
> Commit b035f5a6d852 ("mm: slab: reduce the kmalloc() minimum alignment
> if DMA bouncing possible") allows architectures with non-coherent DMA to
> define a small ARCH_KMALLOC_MINALIGN (e.g. sizeof(unsigned long long))
> and this has been enabled on arm64. With KASAN_HW_TAGS enabled, however,
> ARCH_SLAB_MINALIGN becomes 16 on arm64 (arch_slab_minalign() dynamically
> selects it since commit d949a8155d13 ("mm: make minimum slab alignment a
> runtime property")). This can lead to a situation where kmalloc-8 caches
> are attempted to be created with a kmem_caches.size aligned to 16. When
> the cache is mergeable, it can lead to kernel warnings like:
> 
> sysfs: cannot create duplicate filename '/kernel/slab/:d-0000016'
> CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.6.0-rc1-00001-gda98843cd306-dirty #5
> Hardware name: QEMU QEMU Virtual Machine, BIOS 0.0.0 02/06/2015
> Call trace:
>  dump_backtrace+0x90/0xe8
>  show_stack+0x18/0x24
>  dump_stack_lvl+0x48/0x60
>  dump_stack+0x18/0x24
>  sysfs_warn_dup+0x64/0x80
>  sysfs_create_dir_ns+0xe8/0x108
>  kobject_add_internal+0x98/0x264
>  kobject_init_and_add+0x8c/0xd8
>  sysfs_slab_add+0x12c/0x248
>  slab_sysfs_init+0x98/0x14c
>  do_one_initcall+0x6c/0x1b0
>  kernel_init_freeable+0x1c0/0x288
>  kernel_init+0x24/0x1e0
>  ret_from_fork+0x10/0x20
> kobject: kobject_add_internal failed for :d-0000016 with -EEXIST, don't try to register things with the same name in the same directory.
> SLUB: Unable to add boot slab dma-kmalloc-8 to sysfs
> 
> Limit the __kmalloc_minalign() return value (used to create the
> kmalloc-* caches) to arch_slab_minalign() so that kmalloc-8 caches are
> skipped when KASAN_HW_TAGS is enabled (both config and runtime).
> 
> Fixes: b035f5a6d852 ("mm: slab: reduce the kmalloc() minimum alignment if DMA bouncing possible")
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> Reported-by: Mark Rutland <mark.rutland@arm.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Peter Collingbourne <pcc@google.com>
> Cc: <stable@vger.kernel.org> # 6.5.x
> ---
> 
> The previous post was messed up by my git send-email configuration, so
> sending it again. Also cc'ing Vlastimil since he reviewed the previous
> slab changes for ARCH_KMALLOC_MINALIGN. Thanks.

It also touches only slab files so I can take it via slab tree.

>  mm/slab_common.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/slab_common.c b/mm/slab_common.c
> index cd71f9581e67..8b45922ed295 100644
> --- a/mm/slab_common.c
> +++ b/mm/slab_common.c
> @@ -895,10 +895,13 @@ void __init setup_kmalloc_cache_index_table(void)
>  
>  static unsigned int __kmalloc_minalign(void)
>  {
> +	unsigned int minalign = dma_get_cache_alignment();
> +
>  	if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) &&
>  	    is_swiotlb_allocated())
> -		return ARCH_KMALLOC_MINALIGN;
> -	return dma_get_cache_alignment();
> +		minalign = ARCH_KMALLOC_MINALIGN;
> +
> +	return ALIGN(minalign, arch_slab_minalign());

Could it be max() instead of ALIGN()? It would be more obvious, at least to
me :)

>  }
>  
>  void __init


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RESEND PATCH] mm: slab: Do not create kmalloc caches smaller than arch_slab_minalign()
  2023-10-09  8:22 ` Vlastimil Babka
@ 2023-10-09 11:20   ` Catalin Marinas
  2023-10-11 13:31     ` Vlastimil Babka
  0 siblings, 1 reply; 4+ messages in thread
From: Catalin Marinas @ 2023-10-09 11:20 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: linux-mm, Andrew Morton, linux-kernel, Mark Rutland,
	Peter Collingbourne, Petr Tesarik

On Mon, Oct 09, 2023 at 10:22:52AM +0200, Vlastimil Babka wrote:
> On 10/6/23 18:39, Catalin Marinas wrote:
> > Commit b035f5a6d852 ("mm: slab: reduce the kmalloc() minimum alignment
> > if DMA bouncing possible") allows architectures with non-coherent DMA to
> > define a small ARCH_KMALLOC_MINALIGN (e.g. sizeof(unsigned long long))
> > and this has been enabled on arm64. With KASAN_HW_TAGS enabled, however,
> > ARCH_SLAB_MINALIGN becomes 16 on arm64 (arch_slab_minalign() dynamically
> > selects it since commit d949a8155d13 ("mm: make minimum slab alignment a
> > runtime property")). This can lead to a situation where kmalloc-8 caches
> > are attempted to be created with a kmem_caches.size aligned to 16. When
> > the cache is mergeable, it can lead to kernel warnings like:
> > 
> > sysfs: cannot create duplicate filename '/kernel/slab/:d-0000016'
> > CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.6.0-rc1-00001-gda98843cd306-dirty #5
> > Hardware name: QEMU QEMU Virtual Machine, BIOS 0.0.0 02/06/2015
> > Call trace:
> >  dump_backtrace+0x90/0xe8
> >  show_stack+0x18/0x24
> >  dump_stack_lvl+0x48/0x60
> >  dump_stack+0x18/0x24
> >  sysfs_warn_dup+0x64/0x80
> >  sysfs_create_dir_ns+0xe8/0x108
> >  kobject_add_internal+0x98/0x264
> >  kobject_init_and_add+0x8c/0xd8
> >  sysfs_slab_add+0x12c/0x248
> >  slab_sysfs_init+0x98/0x14c
> >  do_one_initcall+0x6c/0x1b0
> >  kernel_init_freeable+0x1c0/0x288
> >  kernel_init+0x24/0x1e0
> >  ret_from_fork+0x10/0x20
> > kobject: kobject_add_internal failed for :d-0000016 with -EEXIST, don't try to register things with the same name in the same directory.
> > SLUB: Unable to add boot slab dma-kmalloc-8 to sysfs
> > 
> > Limit the __kmalloc_minalign() return value (used to create the
> > kmalloc-* caches) to arch_slab_minalign() so that kmalloc-8 caches are
> > skipped when KASAN_HW_TAGS is enabled (both config and runtime).
> > 
> > Fixes: b035f5a6d852 ("mm: slab: reduce the kmalloc() minimum alignment if DMA bouncing possible")
> > Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> > Reported-by: Mark Rutland <mark.rutland@arm.com>
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > Cc: Vlastimil Babka <vbabka@suse.cz>
> > Cc: Peter Collingbourne <pcc@google.com>
> > Cc: <stable@vger.kernel.org> # 6.5.x
> > ---
> > 
> > The previous post was messed up by my git send-email configuration, so
> > sending it again. Also cc'ing Vlastimil since he reviewed the previous
> > slab changes for ARCH_KMALLOC_MINALIGN. Thanks.
> 
> It also touches only slab files so I can take it via slab tree.

Thanks.

> >  mm/slab_common.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/mm/slab_common.c b/mm/slab_common.c
> > index cd71f9581e67..8b45922ed295 100644
> > --- a/mm/slab_common.c
> > +++ b/mm/slab_common.c
> > @@ -895,10 +895,13 @@ void __init setup_kmalloc_cache_index_table(void)
> >  
> >  static unsigned int __kmalloc_minalign(void)
> >  {
> > +	unsigned int minalign = dma_get_cache_alignment();
> > +
> >  	if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) &&
> >  	    is_swiotlb_allocated())
> > -		return ARCH_KMALLOC_MINALIGN;
> > -	return dma_get_cache_alignment();
> > +		minalign = ARCH_KMALLOC_MINALIGN;
> > +
> > +	return ALIGN(minalign, arch_slab_minalign());
> 
> Could it be max() instead of ALIGN()? It would be more obvious, at least to
> me :)

Yeah, max() would do since they are all a power of two. Do you want me
to repost?

-- 
Catalin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RESEND PATCH] mm: slab: Do not create kmalloc caches smaller than arch_slab_minalign()
  2023-10-09 11:20   ` Catalin Marinas
@ 2023-10-11 13:31     ` Vlastimil Babka
  0 siblings, 0 replies; 4+ messages in thread
From: Vlastimil Babka @ 2023-10-11 13:31 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: linux-mm, Andrew Morton, linux-kernel, Mark Rutland,
	Peter Collingbourne, Petr Tesarik

On 10/9/23 13:20, Catalin Marinas wrote:
>> >  mm/slab_common.c | 7 +++++--
>> >  1 file changed, 5 insertions(+), 2 deletions(-)
>> > 
>> > diff --git a/mm/slab_common.c b/mm/slab_common.c
>> > index cd71f9581e67..8b45922ed295 100644
>> > --- a/mm/slab_common.c
>> > +++ b/mm/slab_common.c
>> > @@ -895,10 +895,13 @@ void __init setup_kmalloc_cache_index_table(void)
>> >  
>> >  static unsigned int __kmalloc_minalign(void)
>> >  {
>> > +	unsigned int minalign = dma_get_cache_alignment();
>> > +
>> >  	if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) &&
>> >  	    is_swiotlb_allocated())
>> > -		return ARCH_KMALLOC_MINALIGN;
>> > -	return dma_get_cache_alignment();
>> > +		minalign = ARCH_KMALLOC_MINALIGN;
>> > +
>> > +	return ALIGN(minalign, arch_slab_minalign());
>> 
>> Could it be max() instead of ALIGN()? It would be more obvious, at least to
>> me :)
> 
> Yeah, max() would do since they are all a power of two. Do you want me
> to repost?

No need, picked up and changed locally. Thanks!



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-11 13:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-06 16:39 [RESEND PATCH] mm: slab: Do not create kmalloc caches smaller than arch_slab_minalign() Catalin Marinas
2023-10-09  8:22 ` Vlastimil Babka
2023-10-09 11:20   ` Catalin Marinas
2023-10-11 13:31     ` Vlastimil Babka

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.