* [PATCH] mm/slab: call __kmalloc_noprof() when size isn't builtin constant in kmalloc_array_noprof()
@ 2025-03-01 8:37 Ye Bin
2025-03-02 13:30 ` Harry Yoo
0 siblings, 1 reply; 4+ messages in thread
From: Ye Bin @ 2025-03-01 8:37 UTC (permalink / raw)
To: cl, penberg, rientjes, iamjoonsoo.kim, akpm, vbabka,
roman.gushchin, harry.yoo, linux-mm
Cc: yebin10
From: Ye Bin <yebin10@huawei.com>
If 'n' or 'size' isn't builtin constant just call __kmalloc_noprof()
in kmalloc_array_noprof().
Fixes: 7bd230a26648 ("mm/slab: enable slab allocation tagging for kmalloc and friends")
Signed-off-by: Ye Bin <yebin10@huawei.com>
---
include/linux/slab.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 3b03b31831a9..0edb8363fc4f 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -947,7 +947,7 @@ static inline __alloc_size(1, 2) void *kmalloc_array_noprof(size_t n, size_t siz
return NULL;
if (__builtin_constant_p(n) && __builtin_constant_p(size))
return kmalloc_noprof(bytes, flags);
- return kmalloc_noprof(bytes, flags);
+ return __kmalloc_noprof(bytes, flags);
}
#define kmalloc_array(...) alloc_hooks(kmalloc_array_noprof(__VA_ARGS__))
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/slab: call __kmalloc_noprof() when size isn't builtin constant in kmalloc_array_noprof()
2025-03-01 8:37 [PATCH] mm/slab: call __kmalloc_noprof() when size isn't builtin constant in kmalloc_array_noprof() Ye Bin
@ 2025-03-02 13:30 ` Harry Yoo
2025-03-04 10:03 ` Vlastimil Babka
0 siblings, 1 reply; 4+ messages in thread
From: Harry Yoo @ 2025-03-02 13:30 UTC (permalink / raw)
To: Ye Bin
Cc: cl, penberg, rientjes, iamjoonsoo.kim, akpm, vbabka,
roman.gushchin, linux-mm, yebin10
On Sat, Mar 01, 2025 at 04:37:20PM +0800, Ye Bin wrote:
> From: Ye Bin <yebin10@huawei.com>
>
> If 'n' or 'size' isn't builtin constant just call __kmalloc_noprof()
> in kmalloc_array_noprof().
>
> Fixes: 7bd230a26648 ("mm/slab: enable slab allocation tagging for kmalloc and friends")
> Signed-off-by: Ye Bin <yebin10@huawei.com>
> ---
> include/linux/slab.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/slab.h b/include/linux/slab.h
> index 3b03b31831a9..0edb8363fc4f 100644
> --- a/include/linux/slab.h
> +++ b/include/linux/slab.h
> @@ -947,7 +947,7 @@ static inline __alloc_size(1, 2) void *kmalloc_array_noprof(size_t n, size_t siz
> return NULL;
> if (__builtin_constant_p(n) && __builtin_constant_p(size))
> return kmalloc_noprof(bytes, flags);
> - return kmalloc_noprof(bytes, flags);
> + return __kmalloc_noprof(bytes, flags);
Can we simply call kmalloc_noprof(bytes, flags) once instead?
The compiler should know 'bytes' is a constant if both 'n' and 'size' are
constants.
> }
> #define kmalloc_array(...) alloc_hooks(kmalloc_array_noprof(__VA_ARGS__))
>
> --
> 2.34.1
--
Cheers,
Harry
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/slab: call __kmalloc_noprof() when size isn't builtin constant in kmalloc_array_noprof()
2025-03-02 13:30 ` Harry Yoo
@ 2025-03-04 10:03 ` Vlastimil Babka
2025-03-04 23:32 ` Harry Yoo
0 siblings, 1 reply; 4+ messages in thread
From: Vlastimil Babka @ 2025-03-04 10:03 UTC (permalink / raw)
To: Harry Yoo, Ye Bin
Cc: cl, penberg, rientjes, iamjoonsoo.kim, akpm, roman.gushchin,
linux-mm, yebin10
On 3/2/25 14:30, Harry Yoo wrote:
> On Sat, Mar 01, 2025 at 04:37:20PM +0800, Ye Bin wrote:
>> From: Ye Bin <yebin10@huawei.com>
>>
>> If 'n' or 'size' isn't builtin constant just call __kmalloc_noprof()
>> in kmalloc_array_noprof().
>>
>> Fixes: 7bd230a26648 ("mm/slab: enable slab allocation tagging for kmalloc and friends")
>> Signed-off-by: Ye Bin <yebin10@huawei.com>
>> ---
>> include/linux/slab.h | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/linux/slab.h b/include/linux/slab.h
>> index 3b03b31831a9..0edb8363fc4f 100644
>> --- a/include/linux/slab.h
>> +++ b/include/linux/slab.h
>> @@ -947,7 +947,7 @@ static inline __alloc_size(1, 2) void *kmalloc_array_noprof(size_t n, size_t siz
>> return NULL;
>> if (__builtin_constant_p(n) && __builtin_constant_p(size))
>> return kmalloc_noprof(bytes, flags);
>> - return kmalloc_noprof(bytes, flags);
>> + return __kmalloc_noprof(bytes, flags);
>
> Can we simply call kmalloc_noprof(bytes, flags) once instead?
>
> The compiler should know 'bytes' is a constant if both 'n' and 'size' are
> constants.
Right, applied like this, hope it's ok?
commit a6553ee4b00ba4b1466a81fb00fa4679b7ce5339 (HEAD -> slab/for-6.15/fixes-cleanups)
Author: Ye Bin <yebin10@huawei.com>
Date: Sat Mar 1 16:37:20 2025 +0800
mm/slab: call kmalloc_noprof() unconditionally in kmalloc_array_noprof()
If 'n' or 'size' isn't builtin constant, we used to call __kmalloc()
before commit 7bd230a26648 ("mm/slab: enable slab allocation tagging for
kmalloc and friends"), which inadvertedly changed both paths to
kmalloc_noprof().
As Harry Yoo points out we can just call kmalloc_noprof()
unconditionally. If the compiler knows n and size are constants it
doesn't guarantee that bytes will be also seen as constant, and that is
the important test in kmalloc_noprof() here, so we can just defer to it
always.
[ vbabka@suse.cz: change as Harry suggested and adjust commit log ]
Fixes: 7bd230a26648 ("mm/slab: enable slab allocation tagging for kmalloc and friends")
Signed-off-by: Ye Bin <yebin10@huawei.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 09eedaecf120..ab05a143d09a 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -941,8 +941,6 @@ static inline __alloc_size(1, 2) void *kmalloc_array_noprof(size_t n, size_t siz
if (unlikely(check_mul_overflow(n, size, &bytes)))
return NULL;
- if (__builtin_constant_p(n) && __builtin_constant_p(size))
- return kmalloc_noprof(bytes, flags);
return kmalloc_noprof(bytes, flags);
}
#define kmalloc_array(...) alloc_hooks(kmalloc_array_noprof(__VA_ARGS__))
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/slab: call __kmalloc_noprof() when size isn't builtin constant in kmalloc_array_noprof()
2025-03-04 10:03 ` Vlastimil Babka
@ 2025-03-04 23:32 ` Harry Yoo
0 siblings, 0 replies; 4+ messages in thread
From: Harry Yoo @ 2025-03-04 23:32 UTC (permalink / raw)
To: Vlastimil Babka
Cc: Ye Bin, cl, penberg, rientjes, iamjoonsoo.kim, akpm,
roman.gushchin, linux-mm, yebin10
On Tue, Mar 04, 2025 at 11:03:54AM +0100, Vlastimil Babka wrote:
> On 3/2/25 14:30, Harry Yoo wrote:
> > On Sat, Mar 01, 2025 at 04:37:20PM +0800, Ye Bin wrote:
> >> From: Ye Bin <yebin10@huawei.com>
> >>
> >> If 'n' or 'size' isn't builtin constant just call __kmalloc_noprof()
> >> in kmalloc_array_noprof().
> >>
> >> Fixes: 7bd230a26648 ("mm/slab: enable slab allocation tagging for kmalloc and friends")
> >> Signed-off-by: Ye Bin <yebin10@huawei.com>
> >> ---
> >> include/linux/slab.h | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/include/linux/slab.h b/include/linux/slab.h
> >> index 3b03b31831a9..0edb8363fc4f 100644
> >> --- a/include/linux/slab.h
> >> +++ b/include/linux/slab.h
> >> @@ -947,7 +947,7 @@ static inline __alloc_size(1, 2) void *kmalloc_array_noprof(size_t n, size_t siz
> >> return NULL;
> >> if (__builtin_constant_p(n) && __builtin_constant_p(size))
> >> return kmalloc_noprof(bytes, flags);
> >> - return kmalloc_noprof(bytes, flags);
> >> + return __kmalloc_noprof(bytes, flags);
> >
> > Can we simply call kmalloc_noprof(bytes, flags) once instead?
> >
> > The compiler should know 'bytes' is a constant if both 'n' and 'size' are
> > constants.
>
> Right, applied like this, hope it's ok?
>
>
> commit a6553ee4b00ba4b1466a81fb00fa4679b7ce5339 (HEAD -> slab/for-6.15/fixes-cleanups)
> Author: Ye Bin <yebin10@huawei.com>
> Date: Sat Mar 1 16:37:20 2025 +0800
>
> mm/slab: call kmalloc_noprof() unconditionally in kmalloc_array_noprof()
>
> If 'n' or 'size' isn't builtin constant, we used to call __kmalloc()
> before commit 7bd230a26648 ("mm/slab: enable slab allocation tagging for
> kmalloc and friends"), which inadvertedly changed both paths to
> kmalloc_noprof().
>
> As Harry Yoo points out we can just call kmalloc_noprof()
> unconditionally. If the compiler knows n and size are constants it
> doesn't guarantee that bytes will be also seen as constant, and that is
> the important test in kmalloc_noprof() here, so we can just defer to it
> always.
>
> [ vbabka@suse.cz: change as Harry suggested and adjust commit log ]
>
> Fixes: 7bd230a26648 ("mm/slab: enable slab allocation tagging for kmalloc and friends")
> Signed-off-by: Ye Bin <yebin10@huawei.com>
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Looks good to me, thanks!
FWIW,
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
--
Cheers,
Harry
> diff --git a/include/linux/slab.h b/include/linux/slab.h
> index 09eedaecf120..ab05a143d09a 100644
> --- a/include/linux/slab.h
> +++ b/include/linux/slab.h
> @@ -941,8 +941,6 @@ static inline __alloc_size(1, 2) void *kmalloc_array_noprof(size_t n, size_t siz
>
> if (unlikely(check_mul_overflow(n, size, &bytes)))
> return NULL;
> - if (__builtin_constant_p(n) && __builtin_constant_p(size))
> - return kmalloc_noprof(bytes, flags);
> return kmalloc_noprof(bytes, flags);
> }
> #define kmalloc_array(...) alloc_hooks(kmalloc_array_noprof(__VA_ARGS__))
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-04 23:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-01 8:37 [PATCH] mm/slab: call __kmalloc_noprof() when size isn't builtin constant in kmalloc_array_noprof() Ye Bin
2025-03-02 13:30 ` Harry Yoo
2025-03-04 10:03 ` Vlastimil Babka
2025-03-04 23:32 ` Harry Yoo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox