[PATCH RESEND] bpf: fix order of args in call to bpf_map_kvcalloc

Mohammad Shehar Yaar Tausif posted 1 patch 1 year, 8 months ago
There is a newer version of this series
kernel/bpf/bpf_local_storage.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH RESEND] bpf: fix order of args in call to bpf_map_kvcalloc
Posted by Mohammad Shehar Yaar Tausif 1 year, 8 months ago
The original function call passed size of smap->bucket before the number of
buckets which raises the error 'calloc-transposed-args' on compilation.

Fixes: 62827d612ae5 ("bpf: Remove __bpf_local_storage_map_alloc")
Reviewed-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>
---
- already merged in linux-next
- [1] suggested sending as a fix for 6.10 cycle

[1] https://lore.kernel.org/all/363ad8d1-a2d2-4fca-b66a-3d838eb5def9@intel.com/
---
 kernel/bpf/bpf_local_storage.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
index 976cb258a0ed..c938dea5ddbf 100644
--- a/kernel/bpf/bpf_local_storage.c
+++ b/kernel/bpf/bpf_local_storage.c
@@ -782,8 +782,8 @@ bpf_local_storage_map_alloc(union bpf_attr *attr,
 	nbuckets = max_t(u32, 2, nbuckets);
 	smap->bucket_log = ilog2(nbuckets);
 
-	smap->buckets = bpf_map_kvcalloc(&smap->map, sizeof(*smap->buckets),
-					 nbuckets, GFP_USER | __GFP_NOWARN);
+	smap->buckets = bpf_map_kvcalloc(&smap->map, nbuckets,
+					 sizeof(*smap->buckets), GFP_USER | __GFP_NOWARN);
 	if (!smap->buckets) {
 		err = -ENOMEM;
 		goto free_smap;

---
base-commit: 2ef5971ff345d3c000873725db555085e0131961
change-id: 20240612-master-fe9e63ab5c95

Best regards,
-- 
Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>
Re: [PATCH RESEND] bpf: fix order of args in call to bpf_map_kvcalloc
Posted by Alexei Starovoitov 1 year, 8 months ago
On Wed, Jun 12, 2024 at 2:51 AM Mohammad Shehar Yaar Tausif
<sheharyaar48@gmail.com> wrote:
>
> The original function call passed size of smap->bucket before the number of
> buckets which raises the error 'calloc-transposed-args' on compilation.
>
> Fixes: 62827d612ae5 ("bpf: Remove __bpf_local_storage_map_alloc")
> Reviewed-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>
> ---
> - already merged in linux-next
> - [1] suggested sending as a fix for 6.10 cycle

No. It's not a fix.

pw-bot: cr

>
> [1] https://lore.kernel.org/all/363ad8d1-a2d2-4fca-b66a-3d838eb5def9@intel.com/
> ---
>  kernel/bpf/bpf_local_storage.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
> index 976cb258a0ed..c938dea5ddbf 100644
> --- a/kernel/bpf/bpf_local_storage.c
> +++ b/kernel/bpf/bpf_local_storage.c
> @@ -782,8 +782,8 @@ bpf_local_storage_map_alloc(union bpf_attr *attr,
>         nbuckets = max_t(u32, 2, nbuckets);
>         smap->bucket_log = ilog2(nbuckets);
>
> -       smap->buckets = bpf_map_kvcalloc(&smap->map, sizeof(*smap->buckets),
> -                                        nbuckets, GFP_USER | __GFP_NOWARN);
> +       smap->buckets = bpf_map_kvcalloc(&smap->map, nbuckets,
> +                                        sizeof(*smap->buckets), GFP_USER | __GFP_NOWARN);
>         if (!smap->buckets) {
>                 err = -ENOMEM;
>                 goto free_smap;
>
> ---
> base-commit: 2ef5971ff345d3c000873725db555085e0131961
> change-id: 20240612-master-fe9e63ab5c95
>
> Best regards,
> --
> Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>
>
Re: [PATCH RESEND] bpf: fix order of args in call to bpf_map_kvcalloc
Posted by Linux regression tracking (Thorsten Leemhuis) 1 year, 7 months ago
[CCing the regressions list and people mentioned below]

On 12.06.24 16:53, Alexei Starovoitov wrote:
> On Wed, Jun 12, 2024 at 2:51 AM Mohammad Shehar Yaar Tausif
> <sheharyaar48@gmail.com> wrote:
>>
>> The original function call passed size of smap->bucket before the number of
>> buckets which raises the error 'calloc-transposed-args' on compilation.
>>
>> Fixes: 62827d612ae5 ("bpf: Remove __bpf_local_storage_map_alloc")
>> Reviewed-by: Andrii Nakryiko <andrii@kernel.org>
>> Signed-off-by: Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>
>> ---
>> - already merged in linux-next
>> - [1] suggested sending as a fix for 6.10 cycle
> 
> No. It's not a fix.

If you have a minute, could you please explain why that is? From what I
can see a quite a few people run into build problems with 6.10-rc
recently that are fixed by the patch:

* Péter Ujfalusi
https://lore.kernel.org/bpf/363ad8d1-a2d2-4fca-b66a-3d838eb5def9@intel.com/

* Christian Kujau
https://lore.kernel.org/bpf/48360912-b239-51f2-8f25-07a46516dc76@nerdbynature.de/
https://lore.kernel.org/lkml/d0dd2457-ab58-1b08-caa4-93eaa2de221e@nerdbynature.de/

* Lorenzo Stoakes
https://fosstodon.org/@ljs@social.kernel.org/112734050799590482

At the same time I see that the culprit mentioned above is from 6.4-rc1,
so I guess it there must be some other reason why a few people seem to
tun into this now. Did some other change expose this problem? Or are
updated compilers causing this?

Ciao, Thorsten

>> [1] https://lore.kernel.org/all/363ad8d1-a2d2-4fca-b66a-3d838eb5def9@intel.com/
>> ---
>>  kernel/bpf/bpf_local_storage.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
>> index 976cb258a0ed..c938dea5ddbf 100644
>> --- a/kernel/bpf/bpf_local_storage.c
>> +++ b/kernel/bpf/bpf_local_storage.c
>> @@ -782,8 +782,8 @@ bpf_local_storage_map_alloc(union bpf_attr *attr,
>>         nbuckets = max_t(u32, 2, nbuckets);
>>         smap->bucket_log = ilog2(nbuckets);
>>
>> -       smap->buckets = bpf_map_kvcalloc(&smap->map, sizeof(*smap->buckets),
>> -                                        nbuckets, GFP_USER | __GFP_NOWARN);
>> +       smap->buckets = bpf_map_kvcalloc(&smap->map, nbuckets,
>> +                                        sizeof(*smap->buckets), GFP_USER | __GFP_NOWARN);
>>         if (!smap->buckets) {
>>                 err = -ENOMEM;
>>                 goto free_smap;
>>
>> ---
>> base-commit: 2ef5971ff345d3c000873725db555085e0131961
>> change-id: 20240612-master-fe9e63ab5c95
>>
>> Best regards,
>> --
>> Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>
>>
Re: [PATCH RESEND] bpf: fix order of args in call to bpf_map_kvcalloc
Posted by Vlastimil Babka 1 year, 7 months ago
On 7/8/24 10:20 AM, Linux regression tracking (Thorsten Leemhuis) wrote:
> [CCing the regressions list and people mentioned below]
> 
> On 12.06.24 16:53, Alexei Starovoitov wrote:
>> On Wed, Jun 12, 2024 at 2:51 AM Mohammad Shehar Yaar Tausif
>> <sheharyaar48@gmail.com> wrote:
>>>
>>> The original function call passed size of smap->bucket before the number of
>>> buckets which raises the error 'calloc-transposed-args' on compilation.
>>>
>>> Fixes: 62827d612ae5 ("bpf: Remove __bpf_local_storage_map_alloc")
>>> Reviewed-by: Andrii Nakryiko <andrii@kernel.org>
>>> Signed-off-by: Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>
>>> ---
>>> - already merged in linux-next
>>> - [1] suggested sending as a fix for 6.10 cycle
>> 
>> No. It's not a fix.
> 
> If you have a minute, could you please explain why that is? From what I
> can see a quite a few people run into build problems with 6.10-rc
> recently that are fixed by the patch:
> 
> * Péter Ujfalusi
> https://lore.kernel.org/bpf/363ad8d1-a2d2-4fca-b66a-3d838eb5def9@intel.com/
> 
> * Christian Kujau
> https://lore.kernel.org/bpf/48360912-b239-51f2-8f25-07a46516dc76@nerdbynature.de/
> https://lore.kernel.org/lkml/d0dd2457-ab58-1b08-caa4-93eaa2de221e@nerdbynature.de/
> 
> * Lorenzo Stoakes
> https://fosstodon.org/@ljs@social.kernel.org/112734050799590482
> 
> At the same time I see that the culprit mentioned above is from 6.4-rc1,

IIUC the order was wrong even before, but see below.

> so I guess it there must be some other reason why a few people seem to
> tun into this now. Did some other change expose this problem? Or are
> updated compilers causing this?

I think it's because of 2c321f3f70bc ("mm: change inlined allocation helpers
to account at the call site"), which was added in 6.10-rc1 and thus makes
this technically a 6.10 regression after all. So what triggers the bug is
AFAICS the following together:

- gcc-14 (didn't see it with gcc-13)
- commit 2c321f3f70bc that makes bpf_map_kvcalloc a macro that does
kvcalloc() directly instead of static inline function wrapping it for
!CONFIG_MEMCG
- CONFIG_MEMCG=n in .config

The fix is so trivial, it's better to include it in 6.10 even this late.

> Ciao, Thorsten
> 
>>> [1] https://lore.kernel.org/all/363ad8d1-a2d2-4fca-b66a-3d838eb5def9@intel.com/
>>> ---
>>>  kernel/bpf/bpf_local_storage.c | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
>>> index 976cb258a0ed..c938dea5ddbf 100644
>>> --- a/kernel/bpf/bpf_local_storage.c
>>> +++ b/kernel/bpf/bpf_local_storage.c
>>> @@ -782,8 +782,8 @@ bpf_local_storage_map_alloc(union bpf_attr *attr,
>>>         nbuckets = max_t(u32, 2, nbuckets);
>>>         smap->bucket_log = ilog2(nbuckets);
>>>
>>> -       smap->buckets = bpf_map_kvcalloc(&smap->map, sizeof(*smap->buckets),
>>> -                                        nbuckets, GFP_USER | __GFP_NOWARN);
>>> +       smap->buckets = bpf_map_kvcalloc(&smap->map, nbuckets,
>>> +                                        sizeof(*smap->buckets), GFP_USER | __GFP_NOWARN);
>>>         if (!smap->buckets) {
>>>                 err = -ENOMEM;
>>>                 goto free_smap;
>>>
>>> ---
>>> base-commit: 2ef5971ff345d3c000873725db555085e0131961
>>> change-id: 20240612-master-fe9e63ab5c95
>>>
>>> Best regards,
>>> --
>>> Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>
>>>

Re: [PATCH RESEND] bpf: fix order of args in call to bpf_map_kvcalloc
Posted by Suren Baghdasaryan 1 year, 7 months ago
On Tue, Jul 9, 2024 at 8:14 AM Vlastimil Babka <vbabka@suse.cz> wrote:
>
> On 7/8/24 10:20 AM, Linux regression tracking (Thorsten Leemhuis) wrote:
> > [CCing the regressions list and people mentioned below]
> >
> > On 12.06.24 16:53, Alexei Starovoitov wrote:
> >> On Wed, Jun 12, 2024 at 2:51 AM Mohammad Shehar Yaar Tausif
> >> <sheharyaar48@gmail.com> wrote:
> >>>
> >>> The original function call passed size of smap->bucket before the number of
> >>> buckets which raises the error 'calloc-transposed-args' on compilation.
> >>>
> >>> Fixes: 62827d612ae5 ("bpf: Remove __bpf_local_storage_map_alloc")
> >>> Reviewed-by: Andrii Nakryiko <andrii@kernel.org>
> >>> Signed-off-by: Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>
> >>> ---
> >>> - already merged in linux-next
> >>> - [1] suggested sending as a fix for 6.10 cycle
> >>
> >> No. It's not a fix.
> >
> > If you have a minute, could you please explain why that is? From what I
> > can see a quite a few people run into build problems with 6.10-rc
> > recently that are fixed by the patch:
> >
> > * Péter Ujfalusi
> > https://lore.kernel.org/bpf/363ad8d1-a2d2-4fca-b66a-3d838eb5def9@intel.com/
> >
> > * Christian Kujau
> > https://lore.kernel.org/bpf/48360912-b239-51f2-8f25-07a46516dc76@nerdbynature.de/
> > https://lore.kernel.org/lkml/d0dd2457-ab58-1b08-caa4-93eaa2de221e@nerdbynature.de/
> >
> > * Lorenzo Stoakes
> > https://fosstodon.org/@ljs@social.kernel.org/112734050799590482
> >
> > At the same time I see that the culprit mentioned above is from 6.4-rc1,
>
> IIUC the order was wrong even before, but see below.
>
> > so I guess it there must be some other reason why a few people seem to
> > tun into this now. Did some other change expose this problem? Or are
> > updated compilers causing this?
>
> I think it's because of 2c321f3f70bc ("mm: change inlined allocation helpers
> to account at the call site"), which was added in 6.10-rc1 and thus makes
> this technically a 6.10 regression after all.

IIUC the above mentioned change reveals a problem that was there
before the change. So, it's a build regression in 6.10 because the bug
got exposed but the bug was introduced much earlier. The fix should be
marked as:

Fixes: ddef81b5fd1d ("bpf: use bpf_map_kvcalloc in bpf_local_storage")

> So what triggers the bug is
> AFAICS the following together:
>
> - gcc-14 (didn't see it with gcc-13)
> - commit 2c321f3f70bc that makes bpf_map_kvcalloc a macro that does
> kvcalloc() directly instead of static inline function wrapping it for
> !CONFIG_MEMCG
> - CONFIG_MEMCG=n in .config
>
> The fix is so trivial, it's better to include it in 6.10 even this late.
>
> > Ciao, Thorsten
> >
> >>> [1] https://lore.kernel.org/all/363ad8d1-a2d2-4fca-b66a-3d838eb5def9@intel.com/
> >>> ---
> >>>  kernel/bpf/bpf_local_storage.c | 4 ++--
> >>>  1 file changed, 2 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
> >>> index 976cb258a0ed..c938dea5ddbf 100644
> >>> --- a/kernel/bpf/bpf_local_storage.c
> >>> +++ b/kernel/bpf/bpf_local_storage.c
> >>> @@ -782,8 +782,8 @@ bpf_local_storage_map_alloc(union bpf_attr *attr,
> >>>         nbuckets = max_t(u32, 2, nbuckets);
> >>>         smap->bucket_log = ilog2(nbuckets);
> >>>
> >>> -       smap->buckets = bpf_map_kvcalloc(&smap->map, sizeof(*smap->buckets),
> >>> -                                        nbuckets, GFP_USER | __GFP_NOWARN);
> >>> +       smap->buckets = bpf_map_kvcalloc(&smap->map, nbuckets,
> >>> +                                        sizeof(*smap->buckets), GFP_USER | __GFP_NOWARN);
> >>>         if (!smap->buckets) {
> >>>                 err = -ENOMEM;
> >>>                 goto free_smap;
> >>>
> >>> ---
> >>> base-commit: 2ef5971ff345d3c000873725db555085e0131961
> >>> change-id: 20240612-master-fe9e63ab5c95
> >>>
> >>> Best regards,
> >>> --
> >>> Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>
> >>>
>
Re: [PATCH RESEND] bpf: fix order of args in call to bpf_map_kvcalloc
Posted by Alexei Starovoitov 1 year, 7 months ago
On Tue, Jul 9, 2024 at 8:39 AM Suren Baghdasaryan <surenb@google.com> wrote:
>
> On Tue, Jul 9, 2024 at 8:14 AM Vlastimil Babka <vbabka@suse.cz> wrote:
> >
> > On 7/8/24 10:20 AM, Linux regression tracking (Thorsten Leemhuis) wrote:
> > > [CCing the regressions list and people mentioned below]
> > >
> > > On 12.06.24 16:53, Alexei Starovoitov wrote:
> > >> On Wed, Jun 12, 2024 at 2:51 AM Mohammad Shehar Yaar Tausif
> > >> <sheharyaar48@gmail.com> wrote:
> > >>>
> > >>> The original function call passed size of smap->bucket before the number of
> > >>> buckets which raises the error 'calloc-transposed-args' on compilation.
> > >>>
> > >>> Fixes: 62827d612ae5 ("bpf: Remove __bpf_local_storage_map_alloc")
> > >>> Reviewed-by: Andrii Nakryiko <andrii@kernel.org>
> > >>> Signed-off-by: Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>
> > >>> ---
> > >>> - already merged in linux-next
> > >>> - [1] suggested sending as a fix for 6.10 cycle
> > >>
> > >> No. It's not a fix.
> > >
> > > If you have a minute, could you please explain why that is? From what I
> > > can see a quite a few people run into build problems with 6.10-rc
> > > recently that are fixed by the patch:
> > >
> > > * Péter Ujfalusi
> > > https://lore.kernel.org/bpf/363ad8d1-a2d2-4fca-b66a-3d838eb5def9@intel.com/
> > >
> > > * Christian Kujau
> > > https://lore.kernel.org/bpf/48360912-b239-51f2-8f25-07a46516dc76@nerdbynature.de/
> > > https://lore.kernel.org/lkml/d0dd2457-ab58-1b08-caa4-93eaa2de221e@nerdbynature.de/
> > >
> > > * Lorenzo Stoakes
> > > https://fosstodon.org/@ljs@social.kernel.org/112734050799590482
> > >
> > > At the same time I see that the culprit mentioned above is from 6.4-rc1,
> >
> > IIUC the order was wrong even before, but see below.
> >
> > > so I guess it there must be some other reason why a few people seem to
> > > tun into this now. Did some other change expose this problem? Or are
> > > updated compilers causing this?
> >
> > I think it's because of 2c321f3f70bc ("mm: change inlined allocation helpers
> > to account at the call site"), which was added in 6.10-rc1 and thus makes
> > this technically a 6.10 regression after all.
>
> IIUC the above mentioned change reveals a problem that was there
> before the change. So, it's a build regression in 6.10 because the bug
> got exposed but the bug was introduced much earlier. The fix should be
> marked as:
>
> Fixes: ddef81b5fd1d ("bpf: use bpf_map_kvcalloc in bpf_local_storage")

Not really. The order was flipped before that patch.

> > So what triggers the bug is
> > AFAICS the following together:
> >
> > - gcc-14 (didn't see it with gcc-13)
> > - commit 2c321f3f70bc that makes bpf_map_kvcalloc a macro that does
> > kvcalloc() directly instead of static inline function wrapping it for
> > !CONFIG_MEMCG
> > - CONFIG_MEMCG=n in .config

Can somebody respin the patch with above details?

tbh I don't think it qualifies as a "bug".
Plenty of code places mix up size/n arguments to calloc.
Erroring the build in such cases is imo wrong.
Not sure what makes gcc-14 produce such warn/error.

But since the patch is trivial we can get that in quickly.
Pls respin with all details.
[PATCH for 6.10] bpf: fix order of args in call to bpf_map_kvcalloc
Posted by Vlastimil Babka 1 year, 7 months ago
From: Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>

The original function call passed size of smap->bucket before the number of
buckets which raises the error 'calloc-transposed-args' on compilation.

Vlastimil Babka added:

The order of parameters can be traced back all the way to 6ac99e8f23d4
("bpf: Introduce bpf sk local storage") accross several refactorings,
and that's why the commit is used as a Fixes: tag.

In v6.10-rc1, a different commit 2c321f3f70bc ("mm: change inlined
allocation helpers to account at the call site") however exposed the
order of args in a way that gcc-14 has enough visibility to start
warning about it, because (in !CONFIG_MEMCG case) bpf_map_kvcalloc is
then a macro alias for kvcalloc instead of a static inline wrapper.

To sum up the warning happens when the following conditions are all met:

- gcc-14 is used (didn't see it with gcc-13)
- commit 2c321f3f70bc is present
- CONFIG_MEMCG is not enabled in .config
- CONFIG_WERROR turns this from a compiler warning to error

Fixes: 6ac99e8f23d4 ("bpf: Introduce bpf sk local storage")
Reviewed-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
---
 kernel/bpf/bpf_local_storage.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
index 976cb258a0ed..c938dea5ddbf 100644
--- a/kernel/bpf/bpf_local_storage.c
+++ b/kernel/bpf/bpf_local_storage.c
@@ -782,8 +782,8 @@ bpf_local_storage_map_alloc(union bpf_attr *attr,
 	nbuckets = max_t(u32, 2, nbuckets);
 	smap->bucket_log = ilog2(nbuckets);
 
-	smap->buckets = bpf_map_kvcalloc(&smap->map, sizeof(*smap->buckets),
-					 nbuckets, GFP_USER | __GFP_NOWARN);
+	smap->buckets = bpf_map_kvcalloc(&smap->map, nbuckets,
+					 sizeof(*smap->buckets), GFP_USER | __GFP_NOWARN);
 	if (!smap->buckets) {
 		err = -ENOMEM;
 		goto free_smap;
-- 
2.45.2
Re: [PATCH for 6.10] bpf: fix order of args in call to bpf_map_kvcalloc
Posted by Christian Kujau 1 year, 7 months ago
On Wed, 10 Jul 2024, Vlastimil Babka wrote:
> Fixes: 6ac99e8f23d4 ("bpf: Introduce bpf sk local storage")

Thanks for not forgetting about this! If this matters, just tested this 
against today's mainline:

Tested-by: Christian Kujau <lists@nerdbynature.de>

C.
-- 
BOFH excuse #418:

Sysadmins busy fighting SPAM.
Re: [PATCH for 6.10] bpf: fix order of args in call to bpf_map_kvcalloc
Posted by Alexei Starovoitov 1 year, 7 months ago
On Wed, Jul 10, 2024 at 3:27 AM Christian Kujau <lists@nerdbynature.de> wrote:
>
> On Wed, 10 Jul 2024, Vlastimil Babka wrote:
> > Fixes: 6ac99e8f23d4 ("bpf: Introduce bpf sk local storage")
>
> Thanks for not forgetting about this! If this matters, just tested this
> against today's mainline:
>
> Tested-by: Christian Kujau <lists@nerdbynature.de>

Thanks everyone. Applied to bpf tree.
Re: [PATCH RESEND] bpf: fix order of args in call to bpf_map_kvcalloc
Posted by Lorenzo Stoakes 1 year, 7 months ago
On Mon, Jul 08, 2024 at 10:20:33AM GMT, Linux regression tracking (Thorsten Leemhuis) wrote:
> [CCing the regressions list and people mentioned below]
>
> On 12.06.24 16:53, Alexei Starovoitov wrote:
> > On Wed, Jun 12, 2024 at 2:51 AM Mohammad Shehar Yaar Tausif
> > <sheharyaar48@gmail.com> wrote:
> >>
> >> The original function call passed size of smap->bucket before the number of
> >> buckets which raises the error 'calloc-transposed-args' on compilation.
> >>
> >> Fixes: 62827d612ae5 ("bpf: Remove __bpf_local_storage_map_alloc")
> >> Reviewed-by: Andrii Nakryiko <andrii@kernel.org>
> >> Signed-off-by: Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>
> >> ---
> >> - already merged in linux-next
> >> - [1] suggested sending as a fix for 6.10 cycle
> >
> > No. It's not a fix.
>
> If you have a minute, could you please explain why that is? From what I
> can see a quite a few people run into build problems with 6.10-rc
> recently that are fixed by the patch:

This is explicitly breaking my build in Linus's kernel (and subsequently
mm-unstable where I hit it first).

I have gcc 14.1.1, and can easily repro this with a defconfig on x86-64 with:

 make mrproper && make defconfig && scripts/config --enable bpf_syscall && \
 make olddefconfig && make -j $(nproc)

kernel/bpf/bpf_local_storage.c:785:60: error: ‘kvmalloc_array_node_noprof’ sizes
specified with ‘sizeof’ in the earlier argument and not in the laterargument
[-Werror=calloc-transposed-args]
  785 |         smap->buckets = bpf_map_kvcalloc(&smap->map, sizeof(*smap->buckets),


It's kind of surprising no build bot caught this (maybe somebody needs to
look into that), but it's proactively causing problems right now, I have to
keep the kernel patched in order for it to build.

So a fix of some kind is needed, urgently.

>
> * Péter Ujfalusi
> https://lore.kernel.org/bpf/363ad8d1-a2d2-4fca-b66a-3d838eb5def9@intel.com/
>
> * Christian Kujau
> https://lore.kernel.org/bpf/48360912-b239-51f2-8f25-07a46516dc76@nerdbynature.de/
> https://lore.kernel.org/lkml/d0dd2457-ab58-1b08-caa4-93eaa2de221e@nerdbynature.de/
>
> * Lorenzo Stoakes
> https://fosstodon.org/@ljs@social.kernel.org/112734050799590482
>
> At the same time I see that the culprit mentioned above is from 6.4-rc1,
> so I guess it there must be some other reason why a few people seem to
> tun into this now. Did some other change expose this problem? Or are
> updated compilers causing this?

I suspect the latter. It seems x86-64 defconfig unables CONFIG_WERROR by default.

>
> Ciao, Thorsten
>
> >> [1] https://lore.kernel.org/all/363ad8d1-a2d2-4fca-b66a-3d838eb5def9@intel.com/
> >> ---
> >>  kernel/bpf/bpf_local_storage.c | 4 ++--
> >>  1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
> >> index 976cb258a0ed..c938dea5ddbf 100644
> >> --- a/kernel/bpf/bpf_local_storage.c
> >> +++ b/kernel/bpf/bpf_local_storage.c
> >> @@ -782,8 +782,8 @@ bpf_local_storage_map_alloc(union bpf_attr *attr,
> >>         nbuckets = max_t(u32, 2, nbuckets);
> >>         smap->bucket_log = ilog2(nbuckets);
> >>
> >> -       smap->buckets = bpf_map_kvcalloc(&smap->map, sizeof(*smap->buckets),
> >> -                                        nbuckets, GFP_USER | __GFP_NOWARN);
> >> +       smap->buckets = bpf_map_kvcalloc(&smap->map, nbuckets,
> >> +                                        sizeof(*smap->buckets), GFP_USER | __GFP_NOWARN);
> >>         if (!smap->buckets) {
> >>                 err = -ENOMEM;
> >>                 goto free_smap;
> >>
> >> ---
> >> base-commit: 2ef5971ff345d3c000873725db555085e0131961
> >> change-id: 20240612-master-fe9e63ab5c95
> >>
> >> Best regards,
> >> --
> >> Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>
> >>