x86: Fix bug about glibc.cpu.hwcaps.

Message ID 20230301032238.566874-1-caiyinyu@loongson.cn
State Committed
Commit 4c721f24fc190d1dc935eb0bab283de7cf13182e
Headers
Series x86: Fix bug about glibc.cpu.hwcaps. |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

caiyinyu March 1, 2023, 3:22 a.m. UTC
  1. export GLIBC_TUNABLES=glibc.cpu.hwcaps=-AVX512
2. Add  _dl_printf("p -- %s\n", p); just before switch(nl) in
   sysdeps/x86/cpu-tunables.c
3. compiled and run ./testrun.sh /usr/bin/ls
you will get:

p -- -AVX512
p -- LC_ADDRESS=en_US.UTF-8
p -- LC_NUMERIC=C
...

The function, TUNABLE_CALLBACK (set_hwcaps)
(tunable_val_t *valp), checks far more than it should and it
should stop at end of "-AVX512".
---
 sysdeps/x86/cpu-tunables.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Noah Goldstein March 1, 2023, 4:19 a.m. UTC | #1
On Tue, Feb 28, 2023 at 9:22 PM caiyinyu <caiyinyu@loongson.cn> wrote:
>
> 1. export GLIBC_TUNABLES=glibc.cpu.hwcaps=-AVX512
> 2. Add  _dl_printf("p -- %s\n", p); just before switch(nl) in
>    sysdeps/x86/cpu-tunables.c
> 3. compiled and run ./testrun.sh /usr/bin/ls
> you will get:
>
> p -- -AVX512
> p -- LC_ADDRESS=en_US.UTF-8
> p -- LC_NUMERIC=C
> ...
>
> The function, TUNABLE_CALLBACK (set_hwcaps)
> (tunable_val_t *valp), checks far more than it should and it
> should stop at end of "-AVX512".
> ---
>  sysdeps/x86/cpu-tunables.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/sysdeps/x86/cpu-tunables.c b/sysdeps/x86/cpu-tunables.c
> index d3e1367bda..772fb0c4c2 100644
> --- a/sysdeps/x86/cpu-tunables.c
> +++ b/sysdeps/x86/cpu-tunables.c
> @@ -107,13 +107,13 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
>       NOTE: the IFUNC selection may change over time.  Please check all
>       multiarch implementations when experimenting.  */
>
> -  const char *p = valp->strval;
> +  const char *p = valp->strval, *c;
>    struct cpu_features *cpu_features = &GLRO(dl_x86_cpu_features);
>    size_t len;
>
>    do
>      {
> -      const char *c, *n;
> +      const char *n;
>        bool disable;
>        size_t nl;
>
> @@ -283,7 +283,7 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
>         }
>        p += len + 1;
>      }
> -  while (*p != '\0');
> +  while (*c != '\0');
>  }
>
>  # if CET_ENABLED
> --
> 2.31.1
>

Can you make a bugzilla for this?
  
caiyinyu March 1, 2023, 9:10 a.m. UTC | #2
在 2023/3/1 下午12:19, Noah Goldstein 写道:
> On Tue, Feb 28, 2023 at 9:22 PM caiyinyu <caiyinyu@loongson.cn> wrote:
>> 1. export GLIBC_TUNABLES=glibc.cpu.hwcaps=-AVX512
>> 2. Add  _dl_printf("p -- %s\n", p); just before switch(nl) in
>>     sysdeps/x86/cpu-tunables.c
>> 3. compiled and run ./testrun.sh /usr/bin/ls
>> you will get:
>>
>> p -- -AVX512
>> p -- LC_ADDRESS=en_US.UTF-8
>> p -- LC_NUMERIC=C
>> ...
>>
>> The function, TUNABLE_CALLBACK (set_hwcaps)
>> (tunable_val_t *valp), checks far more than it should and it
>> should stop at end of "-AVX512".
>> ---
>>   sysdeps/x86/cpu-tunables.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/sysdeps/x86/cpu-tunables.c b/sysdeps/x86/cpu-tunables.c
>> index d3e1367bda..772fb0c4c2 100644
>> --- a/sysdeps/x86/cpu-tunables.c
>> +++ b/sysdeps/x86/cpu-tunables.c
>> @@ -107,13 +107,13 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
>>        NOTE: the IFUNC selection may change over time.  Please check all
>>        multiarch implementations when experimenting.  */
>>
>> -  const char *p = valp->strval;
>> +  const char *p = valp->strval, *c;
>>     struct cpu_features *cpu_features = &GLRO(dl_x86_cpu_features);
>>     size_t len;
>>
>>     do
>>       {
>> -      const char *c, *n;
>> +      const char *n;
>>         bool disable;
>>         size_t nl;
>>
>> @@ -283,7 +283,7 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
>>          }
>>         p += len + 1;
>>       }
>> -  while (*p != '\0');
>> +  while (*c != '\0');
>>   }
>>
>>   # if CET_ENABLED
>> --
>> 2.31.1
>>
> Can you make a bugzilla for this?
bugzilla:

https://sourceware.org/bugzilla/show_bug.cgi?id=30183
  
Noah Goldstein March 1, 2023, 4:42 p.m. UTC | #3
On Wed, Mar 1, 2023 at 3:11 AM caiyinyu <caiyinyu@loongson.cn> wrote:
>
>
> 在 2023/3/1 下午12:19, Noah Goldstein 写道:
> > On Tue, Feb 28, 2023 at 9:22 PM caiyinyu <caiyinyu@loongson.cn> wrote:
> >> 1. export GLIBC_TUNABLES=glibc.cpu.hwcaps=-AVX512
> >> 2. Add  _dl_printf("p -- %s\n", p); just before switch(nl) in
> >>     sysdeps/x86/cpu-tunables.c
> >> 3. compiled and run ./testrun.sh /usr/bin/ls
> >> you will get:
> >>
> >> p -- -AVX512
> >> p -- LC_ADDRESS=en_US.UTF-8
> >> p -- LC_NUMERIC=C
> >> ...
> >>
> >> The function, TUNABLE_CALLBACK (set_hwcaps)
> >> (tunable_val_t *valp), checks far more than it should and it
> >> should stop at end of "-AVX512".
> >> ---
> >>   sysdeps/x86/cpu-tunables.c | 6 +++---
> >>   1 file changed, 3 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/sysdeps/x86/cpu-tunables.c b/sysdeps/x86/cpu-tunables.c
> >> index d3e1367bda..772fb0c4c2 100644
> >> --- a/sysdeps/x86/cpu-tunables.c
> >> +++ b/sysdeps/x86/cpu-tunables.c
> >> @@ -107,13 +107,13 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
> >>        NOTE: the IFUNC selection may change over time.  Please check all
> >>        multiarch implementations when experimenting.  */
> >>
> >> -  const char *p = valp->strval;
> >> +  const char *p = valp->strval, *c;
> >>     struct cpu_features *cpu_features = &GLRO(dl_x86_cpu_features);
> >>     size_t len;
> >>
> >>     do
> >>       {
> >> -      const char *c, *n;
> >> +      const char *n;
> >>         bool disable;
> >>         size_t nl;
> >>
> >> @@ -283,7 +283,7 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
> >>          }
> >>         p += len + 1;
> >>       }
> >> -  while (*p != '\0');
> >> +  while (*c != '\0');
> >>   }
> >>
> >>   # if CET_ENABLED
> >> --
> >> 2.31.1
> >>
> > Can you make a bugzilla for this?
> bugzilla:
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=30183
>
>
Can you append '[BZ #30183]' to the commit message.
Otherwise looks good.
  
H.J. Lu March 1, 2023, 5:33 p.m. UTC | #4
On Wed, Mar 1, 2023 at 8:43 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> On Wed, Mar 1, 2023 at 3:11 AM caiyinyu <caiyinyu@loongson.cn> wrote:
> >
> >
> > 在 2023/3/1 下午12:19, Noah Goldstein 写道:
> > > On Tue, Feb 28, 2023 at 9:22 PM caiyinyu <caiyinyu@loongson.cn> wrote:
> > >> 1. export GLIBC_TUNABLES=glibc.cpu.hwcaps=-AVX512
> > >> 2. Add  _dl_printf("p -- %s\n", p); just before switch(nl) in
> > >>     sysdeps/x86/cpu-tunables.c
> > >> 3. compiled and run ./testrun.sh /usr/bin/ls
> > >> you will get:
> > >>
> > >> p -- -AVX512
> > >> p -- LC_ADDRESS=en_US.UTF-8
> > >> p -- LC_NUMERIC=C
> > >> ...
> > >>
> > >> The function, TUNABLE_CALLBACK (set_hwcaps)
> > >> (tunable_val_t *valp), checks far more than it should and it
> > >> should stop at end of "-AVX512".
> > >> ---
> > >>   sysdeps/x86/cpu-tunables.c | 6 +++---
> > >>   1 file changed, 3 insertions(+), 3 deletions(-)
> > >>
> > >> diff --git a/sysdeps/x86/cpu-tunables.c b/sysdeps/x86/cpu-tunables.c
> > >> index d3e1367bda..772fb0c4c2 100644
> > >> --- a/sysdeps/x86/cpu-tunables.c
> > >> +++ b/sysdeps/x86/cpu-tunables.c
> > >> @@ -107,13 +107,13 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
> > >>        NOTE: the IFUNC selection may change over time.  Please check all
> > >>        multiarch implementations when experimenting.  */
> > >>
> > >> -  const char *p = valp->strval;
> > >> +  const char *p = valp->strval, *c;
> > >>     struct cpu_features *cpu_features = &GLRO(dl_x86_cpu_features);
> > >>     size_t len;
> > >>
> > >>     do
> > >>       {
> > >> -      const char *c, *n;
> > >> +      const char *n;
> > >>         bool disable;
> > >>         size_t nl;
> > >>
> > >> @@ -283,7 +283,7 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
> > >>          }
> > >>         p += len + 1;
> > >>       }
> > >> -  while (*p != '\0');
> > >> +  while (*c != '\0');
> > >>   }
> > >>
> > >>   # if CET_ENABLED
> > >> --
> > >> 2.31.1
> > >>
> > > Can you make a bugzilla for this?
> > bugzilla:
> >
> > https://sourceware.org/bugzilla/show_bug.cgi?id=30183
> >
> >
> Can you append '[BZ #30183]' to the commit message.
> Otherwise looks good.

Is it possible to add a testcase?
  
caiyinyu March 2, 2023, 2:37 a.m. UTC | #5
在 2023/3/2 上午12:42, Noah Goldstein 写道:
> On Wed, Mar 1, 2023 at 3:11 AM caiyinyu <caiyinyu@loongson.cn> wrote:
>>
>> 在 2023/3/1 下午12:19, Noah Goldstein 写道:
>>> On Tue, Feb 28, 2023 at 9:22 PM caiyinyu <caiyinyu@loongson.cn> wrote:
>>>> 1. export GLIBC_TUNABLES=glibc.cpu.hwcaps=-AVX512
>>>> 2. Add  _dl_printf("p -- %s\n", p); just before switch(nl) in
>>>>      sysdeps/x86/cpu-tunables.c
>>>> 3. compiled and run ./testrun.sh /usr/bin/ls
>>>> you will get:
>>>>
>>>> p -- -AVX512
>>>> p -- LC_ADDRESS=en_US.UTF-8
>>>> p -- LC_NUMERIC=C
>>>> ...
>>>>
>>>> The function, TUNABLE_CALLBACK (set_hwcaps)
>>>> (tunable_val_t *valp), checks far more than it should and it
>>>> should stop at end of "-AVX512".
>>>> ---
>>>>    sysdeps/x86/cpu-tunables.c | 6 +++---
>>>>    1 file changed, 3 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/sysdeps/x86/cpu-tunables.c b/sysdeps/x86/cpu-tunables.c
>>>> index d3e1367bda..772fb0c4c2 100644
>>>> --- a/sysdeps/x86/cpu-tunables.c
>>>> +++ b/sysdeps/x86/cpu-tunables.c
>>>> @@ -107,13 +107,13 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
>>>>         NOTE: the IFUNC selection may change over time.  Please check all
>>>>         multiarch implementations when experimenting.  */
>>>>
>>>> -  const char *p = valp->strval;
>>>> +  const char *p = valp->strval, *c;
>>>>      struct cpu_features *cpu_features = &GLRO(dl_x86_cpu_features);
>>>>      size_t len;
>>>>
>>>>      do
>>>>        {
>>>> -      const char *c, *n;
>>>> +      const char *n;
>>>>          bool disable;
>>>>          size_t nl;
>>>>
>>>> @@ -283,7 +283,7 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
>>>>           }
>>>>          p += len + 1;
>>>>        }
>>>> -  while (*p != '\0');
>>>> +  while (*c != '\0');
>>>>    }
>>>>
>>>>    # if CET_ENABLED
>>>> --
>>>> 2.31.1
>>>>
>>> Can you make a bugzilla for this?
>> bugzilla:
>>
>> https://sourceware.org/bugzilla/show_bug.cgi?id=30183
>>
>>
> Can you append '[BZ #30183]' to the commit message.
> Otherwise looks good.


OK.

https://sourceware.org/pipermail/libc-alpha/2023-March/145996.html
  

Patch

diff --git a/sysdeps/x86/cpu-tunables.c b/sysdeps/x86/cpu-tunables.c
index d3e1367bda..772fb0c4c2 100644
--- a/sysdeps/x86/cpu-tunables.c
+++ b/sysdeps/x86/cpu-tunables.c
@@ -107,13 +107,13 @@  TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
      NOTE: the IFUNC selection may change over time.  Please check all
      multiarch implementations when experimenting.  */
 
-  const char *p = valp->strval;
+  const char *p = valp->strval, *c;
   struct cpu_features *cpu_features = &GLRO(dl_x86_cpu_features);
   size_t len;
 
   do
     {
-      const char *c, *n;
+      const char *n;
       bool disable;
       size_t nl;
 
@@ -283,7 +283,7 @@  TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
 	}
       p += len + 1;
     }
-  while (*p != '\0');
+  while (*c != '\0');
 }
 
 # if CET_ENABLED