Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] slub: print just the function name in /sys/kernel/slab/*/ctor
@ 2026-07-25 13:28 Alexey Dobriyan
  2026-07-27  5:27 ` Harry Yoo
  2026-07-27 15:52 ` Christoph Lameter (Ampere)
  0 siblings, 2 replies; 9+ messages in thread
From: Alexey Dobriyan @ 2026-07-25 13:28 UTC (permalink / raw)
  To: Vlastimil Babka, Harry Yoo, Andrew Morton
  Cc: Hao Li, Christoph Lameter, David Rientjes, Roman Gushchin,
	linux-mm

Sysfs "ctor" file prints offset/length of the cache's ctor function

	$ sudo cat /sys/kernel/slab/bdev_cache/ctor
	init_once+0x0/0x10

This is not useful:

Offset will always be 0 because ctor is a function.

I'm not sure what ctor function size is doing here, it should be in
/proc/kallsyms

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 mm/slub.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/mm/slub.c
+++ b/mm/slub.c
@@ -9149,7 +9149,7 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
 {
 	if (!s->ctor)
 		return 0;
-	return sysfs_emit(buf, "%pS\n", s->ctor);
+	return sysfs_emit(buf, "%ps\n", s->ctor);
 }
 SLAB_ATTR_RO(ctor);
 


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

* Re: [PATCH] slub: print just the function name in /sys/kernel/slab/*/ctor
  2026-07-25 13:28 [PATCH] slub: print just the function name in /sys/kernel/slab/*/ctor Alexey Dobriyan
@ 2026-07-27  5:27 ` Harry Yoo
  2026-07-30 14:15   ` Vlastimil Babka (SUSE)
  2026-07-27 15:52 ` Christoph Lameter (Ampere)
  1 sibling, 1 reply; 9+ messages in thread
From: Harry Yoo @ 2026-07-27  5:27 UTC (permalink / raw)
  To: Alexey Dobriyan, Vlastimil Babka, Andrew Morton
  Cc: Hao Li, Christoph Lameter, David Rientjes, Roman Gushchin,
	linux-mm


[-- Attachment #1.1: Type: text/plain, Size: 984 bytes --]



On 7/25/26 10:28 PM, Alexey Dobriyan wrote:
> Sysfs "ctor" file prints offset/length of the cache's ctor function
> 
> 	$ sudo cat /sys/kernel/slab/bdev_cache/ctor
> 	init_once+0x0/0x10
> 
> This is not useful:
> 
> Offset will always be 0 because ctor is a function.
> 
> I'm not sure what ctor function size is doing here, it should be in
> /proc/kallsyms
> 
> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> ---

I'm not convinced that changing this (without strong justification)
after exposing it to sysfs for 10+ years is worth the trouble.

>  mm/slub.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -9149,7 +9149,7 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
>  {
>  	if (!s->ctor)
>  		return 0;
> -	return sysfs_emit(buf, "%pS\n", s->ctor);
> +	return sysfs_emit(buf, "%ps\n", s->ctor);
>  }
>  SLAB_ATTR_RO(ctor);
>  

-- 
Cheers,
Harry / Hyeonggon


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH] slub: print just the function name in /sys/kernel/slab/*/ctor
  2026-07-25 13:28 [PATCH] slub: print just the function name in /sys/kernel/slab/*/ctor Alexey Dobriyan
  2026-07-27  5:27 ` Harry Yoo
@ 2026-07-27 15:52 ` Christoph Lameter (Ampere)
  1 sibling, 0 replies; 9+ messages in thread
From: Christoph Lameter (Ampere) @ 2026-07-27 15:52 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: Vlastimil Babka, Harry Yoo, Andrew Morton, Hao Li, David Rientjes,
	Roman Gushchin, linux-mm


Reviewed-by: Christoph Lameter (Ampere) <cl@gentwo.org>



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

* Re: [PATCH] slub: print just the function name in /sys/kernel/slab/*/ctor
  2026-07-27  5:27 ` Harry Yoo
@ 2026-07-30 14:15   ` Vlastimil Babka (SUSE)
  2026-08-02  5:13     ` Harry Yoo
  2026-08-05  9:16     ` Alexey Dobriyan
  0 siblings, 2 replies; 9+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-07-30 14:15 UTC (permalink / raw)
  To: Harry Yoo, Alexey Dobriyan, Andrew Morton
  Cc: Hao Li, Christoph Lameter, David Rientjes, Roman Gushchin,
	linux-mm

On 7/27/26 07:27, Harry Yoo wrote:
> 
> 
> On 7/25/26 10:28 PM, Alexey Dobriyan wrote:
>> Sysfs "ctor" file prints offset/length of the cache's ctor function
>> 
>> 	$ sudo cat /sys/kernel/slab/bdev_cache/ctor
>> 	init_once+0x0/0x10
>> 
>> This is not useful:
>> 
>> Offset will always be 0 because ctor is a function.
>> 
>> I'm not sure what ctor function size is doing here, it should be in
>> /proc/kallsyms
>> 
>> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
>> ---
> 
> I'm not convinced that changing this (without strong justification)
> after exposing it to sysfs for 10+ years is worth the trouble.

Agreed. It's a pity this was exported in the first place. I can't see a
benefit for anyone knowing what the function is called. Should have been at
most a flag whether there's ctor or not.
But possibly a justification is not to leak the function size, which might
be theoretically (although unlikely) a hint to some attack.
Well at least if somebody complains about getting broken, it's trivial to
revert and we can hear about their usecase.
In-tree tools (slabinfo etc) were checked to work properly?

>>  mm/slub.c |    2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> --- a/mm/slub.c
>> +++ b/mm/slub.c
>> @@ -9149,7 +9149,7 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
>>  {
>>  	if (!s->ctor)
>>  		return 0;
>> -	return sysfs_emit(buf, "%pS\n", s->ctor);
>> +	return sysfs_emit(buf, "%ps\n", s->ctor);
>>  }
>>  SLAB_ATTR_RO(ctor);
>>  
> 



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

* Re: [PATCH] slub: print just the function name in /sys/kernel/slab/*/ctor
  2026-07-30 14:15   ` Vlastimil Babka (SUSE)
@ 2026-08-02  5:13     ` Harry Yoo
  2026-08-04 17:25       ` Vlastimil Babka (SUSE)
  2026-08-05  9:16     ` Alexey Dobriyan
  1 sibling, 1 reply; 9+ messages in thread
From: Harry Yoo @ 2026-08-02  5:13 UTC (permalink / raw)
  To: Vlastimil Babka (SUSE)
  Cc: Alexey Dobriyan, Andrew Morton, Hao Li, Christoph Lameter,
	David Rientjes, Roman Gushchin, linux-mm

On Thu, Jul 30, 2026 at 04:15:26PM +0200, Vlastimil Babka (SUSE) wrote:
> On 7/27/26 07:27, Harry Yoo wrote:
> > 
> > 
> > On 7/25/26 10:28 PM, Alexey Dobriyan wrote:
> >> Sysfs "ctor" file prints offset/length of the cache's ctor function
> >> 
> >> 	$ sudo cat /sys/kernel/slab/bdev_cache/ctor
> >> 	init_once+0x0/0x10
> >> 
> >> This is not useful:
> >> 
> >> Offset will always be 0 because ctor is a function.
> >> 
> >> I'm not sure what ctor function size is doing here, it should be in
> >> /proc/kallsyms
> >> 
> >> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> >> ---
> > 
> > I'm not convinced that changing this (without strong justification)
> > after exposing it to sysfs for 10+ years is worth the trouble.
> 
> Agreed. It's a pity this was exported in the first place. I can't see a
> benefit for anyone knowing what the function is called. Should have been at
> most a flag whether there's ctor or not.

Agreed.

> But possibly a justification is not to leak the function size, which might
> be theoretically (although unlikely) a hint to some attack.

...but you need to be the owner (root) to read this :P 

> Well at least if somebody complains about getting broken, it's trivial to
> revert and we can hear about their usecase.

If we were to experiment with this, we'll change it to print a flag
rather than the ctor's name, right?

> In-tree tools (slabinfo etc) were checked to work properly?

Looks like it doesn't read ctor at all.

Commit a87615b8f9e2 ("SLUB: slabinfo upgrade") added -o/--ops option
that should "Display of ctor / dtor etc.", but it reads "ops" attribute
that has never existed? Bit puzzled.

> >>  mm/slub.c |    2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >> 
> >> --- a/mm/slub.c
> >> +++ b/mm/slub.c
> >> @@ -9149,7 +9149,7 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
> >>  {
> >>  	if (!s->ctor)
> >>  		return 0;
> >> -	return sysfs_emit(buf, "%pS\n", s->ctor);
> >> +	return sysfs_emit(buf, "%ps\n", s->ctor);
> >>  }
> >>  SLAB_ATTR_RO(ctor);

-- 
Cheers,
Harry / Hyeonggon


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

* Re: [PATCH] slub: print just the function name in /sys/kernel/slab/*/ctor
  2026-08-02  5:13     ` Harry Yoo
@ 2026-08-04 17:25       ` Vlastimil Babka (SUSE)
  2026-08-05  9:22         ` Alexey Dobriyan
  0 siblings, 1 reply; 9+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-08-04 17:25 UTC (permalink / raw)
  To: Harry Yoo
  Cc: Alexey Dobriyan, Andrew Morton, Hao Li, Christoph Lameter,
	David Rientjes, Roman Gushchin, linux-mm

On 8/2/26 07:13, Harry Yoo wrote:
> On Thu, Jul 30, 2026 at 04:15:26PM +0200, Vlastimil Babka (SUSE) wrote:
>> On 7/27/26 07:27, Harry Yoo wrote:
>> > 
>> > 
>> > On 7/25/26 10:28 PM, Alexey Dobriyan wrote:
>> >> Sysfs "ctor" file prints offset/length of the cache's ctor function
>> >> 
>> >> 	$ sudo cat /sys/kernel/slab/bdev_cache/ctor
>> >> 	init_once+0x0/0x10
>> >> 
>> >> This is not useful:
>> >> 
>> >> Offset will always be 0 because ctor is a function.
>> >> 
>> >> I'm not sure what ctor function size is doing here, it should be in
>> >> /proc/kallsyms
>> >> 
>> >> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
>> >> ---
>> > 
>> > I'm not convinced that changing this (without strong justification)
>> > after exposing it to sysfs for 10+ years is worth the trouble.
>> 
>> Agreed. It's a pity this was exported in the first place. I can't see a
>> benefit for anyone knowing what the function is called. Should have been at
>> most a flag whether there's ctor or not.
> 
> Agreed.
> 
>> But possibly a justification is not to leak the function size, which might
>> be theoretically (although unlikely) a hint to some attack.
> 
> ...but you need to be the owner (root) to read this :P 
> 
>> Well at least if somebody complains about getting broken, it's trivial to
>> revert and we can hear about their usecase.
> 
> If we were to experiment with this, we'll change it to print a flag
> rather than the ctor's name, right?

Yep, let's try that. Alexey?

>> In-tree tools (slabinfo etc) were checked to work properly?
> 
> Looks like it doesn't read ctor at all.
> 
> Commit a87615b8f9e2 ("SLUB: slabinfo upgrade") added -o/--ops option
> that should "Display of ctor / dtor etc.", but it reads "ops" attribute
> that has never existed? Bit puzzled.

Might have been stale code from some previous revisions that included dtor.

>> >>  mm/slub.c |    2 +-
>> >>  1 file changed, 1 insertion(+), 1 deletion(-)
>> >> 
>> >> --- a/mm/slub.c
>> >> +++ b/mm/slub.c
>> >> @@ -9149,7 +9149,7 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
>> >>  {
>> >>  	if (!s->ctor)
>> >>  		return 0;
>> >> -	return sysfs_emit(buf, "%pS\n", s->ctor);
>> >> +	return sysfs_emit(buf, "%ps\n", s->ctor);
>> >>  }
>> >>  SLAB_ATTR_RO(ctor);
> 



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

* Re: [PATCH] slub: print just the function name in /sys/kernel/slab/*/ctor
  2026-07-30 14:15   ` Vlastimil Babka (SUSE)
  2026-08-02  5:13     ` Harry Yoo
@ 2026-08-05  9:16     ` Alexey Dobriyan
  1 sibling, 0 replies; 9+ messages in thread
From: Alexey Dobriyan @ 2026-08-05  9:16 UTC (permalink / raw)
  To: Vlastimil Babka (SUSE)
  Cc: Harry Yoo, Andrew Morton, Hao Li, Christoph Lameter,
	David Rientjes, Roman Gushchin, linux-mm

On Thu, Jul 30, 2026 at 04:15:26PM +0200, Vlastimil Babka (SUSE) wrote:
> On 7/27/26 07:27, Harry Yoo wrote:
> > 
> > 
> > On 7/25/26 10:28 PM, Alexey Dobriyan wrote:
> >> Sysfs "ctor" file prints offset/length of the cache's ctor function
> >> 
> >> 	$ sudo cat /sys/kernel/slab/bdev_cache/ctor
> >> 	init_once+0x0/0x10
> >> 
> >> This is not useful:
> >> 
> >> Offset will always be 0 because ctor is a function.
> >> 
> >> I'm not sure what ctor function size is doing here, it should be in
> >> /proc/kallsyms
> >> 
> >> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> >> ---
> > 
> > I'm not convinced that changing this (without strong justification)
> > after exposing it to sysfs for 10+ years is worth the trouble.
> 
> Agreed. It's a pity this was exported in the first place. I can't see a
> benefit for anyone knowing what the function is called. Should have been at
> most a flag whether there's ctor or not.
> But possibly a justification is not to leak the function size, which might
> be theoretically (although unlikely) a hint to some attack.

Leaking size is a problem for custom kernels but not a problem
for distro kernels. Original format can be put under CAP_SYS_ADMIN.

> Well at least if somebody complains about getting broken, it's trivial to
> revert and we can hear about their usecase.
> In-tree tools (slabinfo etc) were checked to work properly?

I tried to google and grep my local git collection and found nothing.

> >> -	return sysfs_emit(buf, "%pS\n", s->ctor);
> >> +	return sysfs_emit(buf, "%ps\n", s->ctor);


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

* Re: [PATCH] slub: print just the function name in /sys/kernel/slab/*/ctor
  2026-08-04 17:25       ` Vlastimil Babka (SUSE)
@ 2026-08-05  9:22         ` Alexey Dobriyan
  2026-08-06  6:10           ` Harry Yoo
  0 siblings, 1 reply; 9+ messages in thread
From: Alexey Dobriyan @ 2026-08-05  9:22 UTC (permalink / raw)
  To: Vlastimil Babka (SUSE)
  Cc: Harry Yoo, Andrew Morton, Hao Li, Christoph Lameter,
	David Rientjes, Roman Gushchin, linux-mm

On Tue, Aug 04, 2026 at 07:25:15PM +0200, Vlastimil Babka (SUSE) wrote:
> On 8/2/26 07:13, Harry Yoo wrote:
> > On Thu, Jul 30, 2026 at 04:15:26PM +0200, Vlastimil Babka (SUSE) wrote:
> >> On 7/27/26 07:27, Harry Yoo wrote:
> >> > 
> >> > 
> >> > On 7/25/26 10:28 PM, Alexey Dobriyan wrote:
> >> >> Sysfs "ctor" file prints offset/length of the cache's ctor function
> >> >> 
> >> >> 	$ sudo cat /sys/kernel/slab/bdev_cache/ctor
> >> >> 	init_once+0x0/0x10
> >> >> 
> >> >> This is not useful:
> >> >> 
> >> >> Offset will always be 0 because ctor is a function.
> >> >> 
> >> >> I'm not sure what ctor function size is doing here, it should be in
> >> >> /proc/kallsyms
> >> >> 
> >> >> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> >> >> ---
> >> > 
> >> > I'm not convinced that changing this (without strong justification)
> >> > after exposing it to sysfs for 10+ years is worth the trouble.
> >> 
> >> Agreed. It's a pity this was exported in the first place. I can't see a
> >> benefit for anyone knowing what the function is called. Should have been at
> >> most a flag whether there's ctor or not.
> > 
> > Agreed.
> > 
> >> But possibly a justification is not to leak the function size, which might
> >> be theoretically (although unlikely) a hint to some attack.
> > 
> > ...but you need to be the owner (root) to read this :P 
> > 
> >> Well at least if somebody complains about getting broken, it's trivial to
> >> revert and we can hear about their usecase.
> > 
> > If we were to experiment with this, we'll change it to print a flag
> > rather than the ctor's name, right?
> 
> Yep, let's try that. Alexey?

I don't mind ctor name, it is internal implementation detail,
but offset/size are kind of useless.

My order of preferences is
1) delete +0x0/... part altogeter,
2) when someone complains, restore it as "+0x0/0x4" which is a minimum
   function size across all archs (or some other fixed fake size).

> 
> >> In-tree tools (slabinfo etc) were checked to work properly?
> > 
> > Looks like it doesn't read ctor at all.
> > 
> > Commit a87615b8f9e2 ("SLUB: slabinfo upgrade") added -o/--ops option
> > that should "Display of ctor / dtor etc.", but it reads "ops" attribute
> > that has never existed? Bit puzzled.
> 
> Might have been stale code from some previous revisions that included dtor.
> 
> >> >>  mm/slub.c |    2 +-
> >> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >> >> 
> >> >> --- a/mm/slub.c
> >> >> +++ b/mm/slub.c
> >> >> @@ -9149,7 +9149,7 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
> >> >>  {
> >> >>  	if (!s->ctor)
> >> >>  		return 0;
> >> >> -	return sysfs_emit(buf, "%pS\n", s->ctor);
> >> >> +	return sysfs_emit(buf, "%ps\n", s->ctor);
> >> >>  }
> >> >>  SLAB_ATTR_RO(ctor);


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

* Re: [PATCH] slub: print just the function name in /sys/kernel/slab/*/ctor
  2026-08-05  9:22         ` Alexey Dobriyan
@ 2026-08-06  6:10           ` Harry Yoo
  0 siblings, 0 replies; 9+ messages in thread
From: Harry Yoo @ 2026-08-06  6:10 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: Vlastimil Babka (SUSE), Andrew Morton, Hao Li, Christoph Lameter,
	David Rientjes, Roman Gushchin, linux-mm

On Wed, Aug 05, 2026 at 12:22:42PM +0300, Alexey Dobriyan wrote:
> On Tue, Aug 04, 2026 at 07:25:15PM +0200, Vlastimil Babka (SUSE) wrote:
> > On 8/2/26 07:13, Harry Yoo wrote:
> > > On Thu, Jul 30, 2026 at 04:15:26PM +0200, Vlastimil Babka (SUSE) wrote:
> > >> On 7/27/26 07:27, Harry Yoo wrote:
> > >> > 
> > >> > 
> > >> > On 7/25/26 10:28 PM, Alexey Dobriyan wrote:
> > >> >> Sysfs "ctor" file prints offset/length of the cache's ctor function
> > >> >> 
> > >> >> 	$ sudo cat /sys/kernel/slab/bdev_cache/ctor
> > >> >> 	init_once+0x0/0x10
> > >> >> 
> > >> >> This is not useful:
> > >> >> 
> > >> >> Offset will always be 0 because ctor is a function.
> > >> >> 
> > >> >> I'm not sure what ctor function size is doing here, it should be in
> > >> >> /proc/kallsyms
> > >> >> 
> > >> >> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> > >> >> ---
> > >> > 
> > >> > I'm not convinced that changing this (without strong justification)
> > >> > after exposing it to sysfs for 10+ years is worth the trouble.
> > >> 
> > >> Agreed. It's a pity this was exported in the first place. I can't see a
> > >> benefit for anyone knowing what the function is called. Should have been at
> > >> most a flag whether there's ctor or not.
> > > 
> > > Agreed.
> > > 
> > >> But possibly a justification is not to leak the function size, which might
> > >> be theoretically (although unlikely) a hint to some attack.
> > > 
> > > ...but you need to be the owner (root) to read this :P 
> > > 
> > >> Well at least if somebody complains about getting broken, it's trivial to
> > >> revert and we can hear about their usecase.
> > > 
> > > If we were to experiment with this, we'll change it to print a flag
> > > rather than the ctor's name, right?
> > 
> > Yep, let's try that. Alexey?
> 
> I don't mind ctor name, it is internal implementation detail,
> but offset/size are kind of useless.

I thought Vlastimil meant ctor name is also useless and suggested
it making it a flag (0/1) to represent whether the cache has a ctor or
not.

Or do you think there's a scenario where ctor name is useful to know? 

-- 
Cheers,
Harry / Hyeonggon


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

end of thread, other threads:[~2026-08-06  6:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-25 13:28 [PATCH] slub: print just the function name in /sys/kernel/slab/*/ctor Alexey Dobriyan
2026-07-27  5:27 ` Harry Yoo
2026-07-30 14:15   ` Vlastimil Babka (SUSE)
2026-08-02  5:13     ` Harry Yoo
2026-08-04 17:25       ` Vlastimil Babka (SUSE)
2026-08-05  9:22         ` Alexey Dobriyan
2026-08-06  6:10           ` Harry Yoo
2026-08-05  9:16     ` Alexey Dobriyan
2026-07-27 15:52 ` Christoph Lameter (Ampere)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox