diff mbox series

[ovs-dev] cpu: Fix cpuid check for some AMD processors.

Message ID 20230607082440.2847980-1-david.marchand@redhat.com
State Accepted
Commit 474a179aff6c4199d8007910e3f79f000af9d659
Headers show
Series [ovs-dev] cpu: Fix cpuid check for some AMD processors. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

David Marchand June 7, 2023, 8:24 a.m. UTC
Some venerable AMD processors do not support querying extended features
(EAX=7) with cpuid.
In this case, it is not a programmatic error and the runtime check should
simply return the isa is unsupported.

Reported-by: Davide Repetto <red@idp.it>
Reported-at: https://bugzilla.redhat.com/show_bug.cgi?id=2211747
Fixes: b366fa2f4947 ("dpif-netdev: Call cpuid for x86 isa availability.")
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/cpu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Ilya Maximets June 7, 2023, 10 p.m. UTC | #1
On 6/7/23 10:24, David Marchand wrote:
> Some venerable AMD processors do not support querying extended features
> (EAX=7) with cpuid.
> In this case, it is not a programmatic error and the runtime check should
> simply return the isa is unsupported.
> 
> Reported-by: Davide Repetto <red@idp.it>
> Reported-at: https://bugzilla.redhat.com/show_bug.cgi?id=2211747
> Fixes: b366fa2f4947 ("dpif-netdev: Call cpuid for x86 isa availability.")
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>  lib/cpu.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/cpu.c b/lib/cpu.c
> index 0292f715ec..fbbea40053 100644
> --- a/lib/cpu.c
> +++ b/lib/cpu.c
> @@ -37,7 +37,9 @@ static bool x86_has_isa(uint32_t leaf, enum x86_reg reg, uint32_t bit)
>  {
>      uint32_t regs[4];
>  
> -    ovs_assert(__get_cpuid_max(leaf & X86_LEAF_MASK, NULL) >= leaf);
> +    if (__get_cpuid_max(leaf & X86_LEAF_MASK, NULL) < leaf) {
> +        return false;
> +    }
>  
>      __cpuid_count(leaf, 0, regs[EAX], regs[EBX], regs[ECX], regs[EDX]);
>      return (regs[reg] & ((uint32_t) 1 << bit)) != 0;

Thanks!  Applied and backported down to 2.17.

Best regards, Ilya Maximets.
Davide Repetto June 8, 2023, 2:39 p.m. UTC | #2
Thank you all for your work! It's appreciated.

Il giorno gio, 08/06/2023 alle 00.00 +0200, Ilya Maximets ha scritto:
> On 6/7/23 10:24, David Marchand wrote:
> > Some venerable AMD processors do not support querying extended features
> > (EAX=7) with cpuid.
> > In this case, it is not a programmatic error and the runtime check should
> > simply return the isa is unsupported.
> > 
> > Reported-by: Davide Repetto <red@idp.it>
> > Reported-at: https://bugzilla.redhat.com/show_bug.cgi?id=2211747
> > Fixes: b366fa2f4947 ("dpif-netdev: Call cpuid for x86 isa availability.")
> > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > ---
> >  lib/cpu.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/lib/cpu.c b/lib/cpu.c
> > index 0292f715ec..fbbea40053 100644
> > --- a/lib/cpu.c
> > +++ b/lib/cpu.c
> > @@ -37,7 +37,9 @@ static bool x86_has_isa(uint32_t leaf, enum x86_reg reg, uint32_t bit)
> >  {
> >      uint32_t regs[4];
> >  
> > -    ovs_assert(__get_cpuid_max(leaf & X86_LEAF_MASK, NULL) >= leaf);
> > +    if (__get_cpuid_max(leaf & X86_LEAF_MASK, NULL) < leaf) {
> > +        return false;
> > +    }
> >  
> >      __cpuid_count(leaf, 0, regs[EAX], regs[EBX], regs[ECX], regs[EDX]);
> >      return (regs[reg] & ((uint32_t) 1 << bit)) != 0;
> 
> Thanks!  Applied and backported down to 2.17.
> 
> Best regards, Ilya Maximets.
diff mbox series

Patch

diff --git a/lib/cpu.c b/lib/cpu.c
index 0292f715ec..fbbea40053 100644
--- a/lib/cpu.c
+++ b/lib/cpu.c
@@ -37,7 +37,9 @@  static bool x86_has_isa(uint32_t leaf, enum x86_reg reg, uint32_t bit)
 {
     uint32_t regs[4];
 
-    ovs_assert(__get_cpuid_max(leaf & X86_LEAF_MASK, NULL) >= leaf);
+    if (__get_cpuid_max(leaf & X86_LEAF_MASK, NULL) < leaf) {
+        return false;
+    }
 
     __cpuid_count(leaf, 0, regs[EAX], regs[EBX], regs[ECX], regs[EDX]);
     return (regs[reg] & ((uint32_t) 1 << bit)) != 0;