* [PATCH] x86: correct remaining extended CPUID level checks
@ 2016-05-09 13:19 Jan Beulich
2016-05-09 13:25 ` Andrew Cooper
2016-05-09 13:34 ` Wei Liu
0 siblings, 2 replies; 3+ messages in thread
From: Jan Beulich @ 2016-05-09 13:19 UTC (permalink / raw)
To: xen-devel; +Cc: Andrew Cooper, Wei Liu
[-- Attachment #1: Type: text/plain, Size: 2938 bytes --]
We should consistently check the upper 16 bits to be equal 0x8000 and
only then the full value to be >= the desired level.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
As to inclusion in 4.7 - I think this would be desirable, but it's not
a must: I'm unaware of real world environments where
CPUID[0x80000000].EAX would yield a value not having the upper 16 bits
set to 0x8000.
--- a/xen/arch/x86/boot/head.S
+++ b/xen/arch/x86/boot/head.S
@@ -133,7 +133,10 @@ __start:
/* Interrogate CPU extended features via CPUID. */
mov $0x80000000,%eax
cpuid
+ shld $16,%eax,%ecx
xor %edx,%edx
+ cmp $0x8000,%cx # any function @ 0x8000xxxx?
+ jne 1f
cmp $0x80000000,%eax # any function > 0x80000000?
jbe 1f
mov $0x80000001,%eax
--- a/xen/arch/x86/cpu/common.c
+++ b/xen/arch/x86/cpu/common.c
@@ -297,9 +297,12 @@ static void generic_identify(struct cpui
/* AMD-defined flags: level 0x80000001 */
c->extended_cpuid_level = cpuid_eax(0x80000000);
- cpuid(0x80000001, &tmp, &tmp,
- &c->x86_capability[cpufeat_word(X86_FEATURE_LAHF_LM)],
- &c->x86_capability[cpufeat_word(X86_FEATURE_SYSCALL)]);
+ if ((c->extended_cpuid_level >> 16) != 0x8000)
+ c->extended_cpuid_level = 0;
+ if (c->extended_cpuid_level > 0x80000000)
+ cpuid(0x80000001, &tmp, &tmp,
+ &c->x86_capability[cpufeat_word(X86_FEATURE_LAHF_LM)],
+ &c->x86_capability[cpufeat_word(X86_FEATURE_SYSCALL)]);
if (c == &boot_cpu_data)
bootsym(cpuid_ext_features) =
c->x86_capability[cpufeat_word(X86_FEATURE_NX)];
--- a/xen/arch/x86/efi/efi-boot.h
+++ b/xen/arch/x86/efi/efi-boot.h
@@ -605,7 +605,9 @@ static void __init efi_arch_handle_modul
static void __init efi_arch_cpu(void)
{
- if ( cpuid_eax(0x80000000) > 0x80000000 )
+ uint32_t eax = cpuid_eax(0x80000000);
+
+ if ( (eax >> 16) == 0x8000 && eax > 0x80000000 )
{
cpuid_ext_features = cpuid_edx(0x80000001);
boot_cpu_data.x86_capability[cpufeat_word(X86_FEATURE_SYSCALL)]
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -884,7 +884,7 @@ const char *hvm_efer_valid(const struct
ASSERT(v->domain == current->domain);
hvm_cpuid(0x80000000, &level, NULL, NULL, NULL);
- if ( level >= 0x80000001 )
+ if ( (level >> 16) == 0x8000 && level > 0x80000000 )
{
unsigned int dummy;
--- a/xen/arch/x86/hvm/mtrr.c
+++ b/xen/arch/x86/hvm/mtrr.c
@@ -455,7 +455,7 @@ bool_t mtrr_var_range_msr_set(
{
phys_addr = 36;
hvm_cpuid(0x80000000, &eax, NULL, NULL, NULL);
- if ( eax >= 0x80000008 )
+ if ( (eax >> 16) == 0x8000 && eax >= 0x80000008 )
{
hvm_cpuid(0x80000008, &eax, NULL, NULL, NULL);
phys_addr = (uint8_t)eax;
[-- Attachment #2: x86-ext-CPUID-level-checks.patch --]
[-- Type: text/plain, Size: 2986 bytes --]
x86: correct remaining extended CPUID level checks
We should consistently check the upper 16 bits to be equal 0x8000 and
only then the full value to be >= the desired level.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
As to inclusion in 4.7 - I think this would be desirable, but it's not
a must: I'm unaware of real world environments where
CPUID[0x80000000].EAX would yield a value not having the upper 16 bits
set to 0x8000.
--- a/xen/arch/x86/boot/head.S
+++ b/xen/arch/x86/boot/head.S
@@ -133,7 +133,10 @@ __start:
/* Interrogate CPU extended features via CPUID. */
mov $0x80000000,%eax
cpuid
+ shld $16,%eax,%ecx
xor %edx,%edx
+ cmp $0x8000,%cx # any function @ 0x8000xxxx?
+ jne 1f
cmp $0x80000000,%eax # any function > 0x80000000?
jbe 1f
mov $0x80000001,%eax
--- a/xen/arch/x86/cpu/common.c
+++ b/xen/arch/x86/cpu/common.c
@@ -297,9 +297,12 @@ static void generic_identify(struct cpui
/* AMD-defined flags: level 0x80000001 */
c->extended_cpuid_level = cpuid_eax(0x80000000);
- cpuid(0x80000001, &tmp, &tmp,
- &c->x86_capability[cpufeat_word(X86_FEATURE_LAHF_LM)],
- &c->x86_capability[cpufeat_word(X86_FEATURE_SYSCALL)]);
+ if ((c->extended_cpuid_level >> 16) != 0x8000)
+ c->extended_cpuid_level = 0;
+ if (c->extended_cpuid_level > 0x80000000)
+ cpuid(0x80000001, &tmp, &tmp,
+ &c->x86_capability[cpufeat_word(X86_FEATURE_LAHF_LM)],
+ &c->x86_capability[cpufeat_word(X86_FEATURE_SYSCALL)]);
if (c == &boot_cpu_data)
bootsym(cpuid_ext_features) =
c->x86_capability[cpufeat_word(X86_FEATURE_NX)];
--- a/xen/arch/x86/efi/efi-boot.h
+++ b/xen/arch/x86/efi/efi-boot.h
@@ -605,7 +605,9 @@ static void __init efi_arch_handle_modul
static void __init efi_arch_cpu(void)
{
- if ( cpuid_eax(0x80000000) > 0x80000000 )
+ uint32_t eax = cpuid_eax(0x80000000);
+
+ if ( (eax >> 16) == 0x8000 && eax > 0x80000000 )
{
cpuid_ext_features = cpuid_edx(0x80000001);
boot_cpu_data.x86_capability[cpufeat_word(X86_FEATURE_SYSCALL)]
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -884,7 +884,7 @@ const char *hvm_efer_valid(const struct
ASSERT(v->domain == current->domain);
hvm_cpuid(0x80000000, &level, NULL, NULL, NULL);
- if ( level >= 0x80000001 )
+ if ( (level >> 16) == 0x8000 && level > 0x80000000 )
{
unsigned int dummy;
--- a/xen/arch/x86/hvm/mtrr.c
+++ b/xen/arch/x86/hvm/mtrr.c
@@ -455,7 +455,7 @@ bool_t mtrr_var_range_msr_set(
{
phys_addr = 36;
hvm_cpuid(0x80000000, &eax, NULL, NULL, NULL);
- if ( eax >= 0x80000008 )
+ if ( (eax >> 16) == 0x8000 && eax >= 0x80000008 )
{
hvm_cpuid(0x80000008, &eax, NULL, NULL, NULL);
phys_addr = (uint8_t)eax;
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] x86: correct remaining extended CPUID level checks
2016-05-09 13:19 [PATCH] x86: correct remaining extended CPUID level checks Jan Beulich
@ 2016-05-09 13:25 ` Andrew Cooper
2016-05-09 13:34 ` Wei Liu
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Cooper @ 2016-05-09 13:25 UTC (permalink / raw)
To: Jan Beulich, xen-devel; +Cc: Wei Liu
On 09/05/16 14:19, Jan Beulich wrote:
> We should consistently check the upper 16 bits to be equal 0x8000 and
> only then the full value to be >= the desired level.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> ---
> As to inclusion in 4.7 - I think this would be desirable, but it's not
> a must: I'm unaware of real world environments where
> CPUID[0x80000000].EAX would yield a value not having the upper 16 bits
> set to 0x8000.
Either way, Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86: correct remaining extended CPUID level checks
2016-05-09 13:19 [PATCH] x86: correct remaining extended CPUID level checks Jan Beulich
2016-05-09 13:25 ` Andrew Cooper
@ 2016-05-09 13:34 ` Wei Liu
1 sibling, 0 replies; 3+ messages in thread
From: Wei Liu @ 2016-05-09 13:34 UTC (permalink / raw)
To: Jan Beulich; +Cc: xen-devel, Wei Liu, Andrew Cooper
On Mon, May 09, 2016 at 07:19:56AM -0600, Jan Beulich wrote:
> We should consistently check the upper 16 bits to be equal 0x8000 and
> only then the full value to be >= the desired level.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> ---
> As to inclusion in 4.7 - I think this would be desirable, but it's not
> a must: I'm unaware of real world environments where
> CPUID[0x80000000].EAX would yield a value not having the upper 16 bits
> set to 0x8000.
>
We're early in our RC so:
Release-acked-by: Wei Liu <wei.liu2@citrix.com>
Wei.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-05-09 13:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-09 13:19 [PATCH] x86: correct remaining extended CPUID level checks Jan Beulich
2016-05-09 13:25 ` Andrew Cooper
2016-05-09 13:34 ` Wei Liu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.