x86info: dump kvm cpuid's
Subsystems (2)
Michael S. Tsirkin
maintainerPATCH v2 1/1 x86info: dump kvm cpuid's
The following makes 'x86info -r' dump hypervisor leaf cpu ids (for kvm this is signature+features) when running in a vm.
On the guest we see the signature and the features:
eax in: 0x40000000, eax = 00000000 ebx = 4b4d564b ecx = 564b4d56 edx = 0000004d eax in: 0x40000001, eax = 0100007b ebx = 00000000 ecx = 00000000 edx = 00000000
Hypervisor flag is checked to avoid output changes when not running on a VM.
Changes from v1:
Make work on non KVM hypervisors (only KVM was tested). Avi Kivity said kvm will in the future report max HV leaf in eax. For now it reports eax = 0 so add a work around for that.
---
identify.c +16 -3
@@ -9,8 +9,8 @@void get_cpu_info_basics (struct cpudata *cpu) { -unsigned int maxi, maxei, vendor, address_bits; -unsigned int eax; +unsigned int maxi, maxei, maxhv, vendor, address_bits; +unsigned int eax, ebx, ecx;cpuid (cpu->number,0 , &maxi, &vendor,NULL ,NULL ); maxi &=0xffff ;/* The high-order word is non-zero on some Cyrix CPUs */
@@ -19,7 +19,7 @@ void get_cpu_info_basics(struct cpudata *cpu)return ;/* Everything that supports cpuid supports these. */ -cpuid (cpu->number,1 , &eax,NULL ,NULL ,NULL ); +cpuid (cpu->number,1 , &eax, &ebx, &ecx,NULL ); cpu->stepping = eax &0xf ; cpu->model = (eax >>4 ) &0xf ; cpu->family = (eax >>8 ) &0xf ;
@@ -29,6 +29,19 @@ void get_cpu_info_basics(struct cpudata *cpu)cpuid (cpu->number,0xC0000000 , &maxei,NULL ,NULL ,NULL ); cpu->maxei2 = maxei; +if (ecx &0x80000000 ) { +cpuid (cpu->number,0x40000000 , &maxhv,NULL ,NULL ,NULL ); +/* +* KVM up to linux 3.4 reports 0 as the max hypervisor leaf, +* where it really means 0x40000001. +* Most (all?) hypervisors have at least one CPUID besides +* the vendor ID so assume that. +*/ + cpu->maxhv = maxhv ? maxhv :0x40000001 ; + }else { +/* Suppress hypervisor cpuid unless running on a hypervisor */ + cpu->maxhv =0 ; + }cpuid (cpu->number,0x80000008 ,&address_bits,NULL ,NULL ,NULL ); cpu->phyaddr_bits = address_bits &0xFF ;
x86info.c +4 -0
@@ -44,6 +44,10 @@ static void display_detailed_info(struct cpudata *cpu)if (cpu->maxei2 >=0xC0000000 )dump_raw_cpuid (cpu->number,0xC0000000 , cpu->maxei2); + +if (cpu->maxhv >=0x40000000 ) +dump_raw_cpuid (cpu->number,0x40000000 , cpu->maxhv); + }if (show_cacheinfo) {
x86info.h +1 -1
@@ -84,7 +84,7 @@ struct cpudata {unsigned int cachesize_trace;unsigned int phyaddr_bits;unsigned int viraddr_bits; -unsigned int cpuid_level, maxei, maxei2; +unsigned int cpuid_level, maxei, maxei2, maxhv;char name[CPU_NAME_LEN ];enum connector connector;unsigned int flags_ecx;
Quoted 12 lines · Michael S. Tsirkin
The following makes 'x86info -r' dump hypervisor leaf cpu ids (for kvm this is signature+features) when running in a vm.
On the guest we see the signature and the features:
eax in:0x40000000, eax = 00000000 ebx =4b4d564becx =564b4d56edx =0000004deax in:0x40000001, eax =0100007bebx = 00000000 ecx = 00000000 edx = 00000000Hypervisor flag is checked to avoid output changes when not running on a VM.
Signed-off-by Michael S. Tsirkin <[email protected]>
Looks good to me.
Quoted 72 lines
Changes from v1:
Make work on non KVM hypervisors (only KVM was tested). Avi Kivity said kvm will in the future report max HV leaf in eax. For now it reports eax = 0 so add a work around for that.---
identify.c +16
-3@@ -9,8 +9,8 @@void get_cpu_info_basics (struct cpudata *cpu) { -unsigned int maxi, maxei, vendor, address_bits; -unsigned int eax; +unsigned int maxi, maxei, maxhv, vendor, address_bits; +unsigned int eax, ebx, ecx;cpuid (cpu->number,0 , &maxi, &vendor,NULL ,NULL ); maxi &=0xffff ;/* The high-order word is non-zero on some Cyrix CPUs */ @@ -19,7 +19,7 @@ void get_cpu_info_basics(struct cpudata *cpu)return ;/* Everything that supports cpuid supports these. */ -cpuid (cpu->number,1 , &eax,NULL ,NULL ,NULL ); +cpuid (cpu->number,1 , &eax, &ebx, &ecx,NULL ); cpu->stepping = eax &0xf ; cpu->model = (eax >>4 ) &0xf ; cpu->family = (eax >>8 ) &0xf ;@@ -29,6 +29,19 @@ void get_cpu_info_basics(struct cpudata *cpu)cpuid (cpu->number,0xC0000000 , &maxei,NULL ,NULL ,NULL ); cpu->maxei2 = maxei; +if (ecx &0x80000000 ) { +cpuid (cpu->number,0x40000000 , &maxhv,NULL ,NULL ,NULL ); +/* +* KVM up to linux 3.4 reports 0 as the max hypervisor leaf, +* where it really means 0x40000001. +* Most (all?) hypervisors have at least one CPUID besides +* the vendor ID so assume that. +*/ + cpu->maxhv = maxhv ? maxhv :0x40000001 ; + }else { +/* Suppress hypervisor cpuid unless running on a hypervisor */ + cpu->maxhv =0 ; + }cpuid (cpu->number,0x80000008 ,&address_bits,NULL ,NULL ,NULL ); cpu->phyaddr_bits = address_bits &0xFF ;x86info.c +4
-0@@ -44,6 +44,10 @@ static void display_detailed_info(struct cpudata *cpu)if (cpu->maxei2 >=0xC0000000 )dump_raw_cpuid (cpu->number,0xC0000000 , cpu->maxei2); + +if (cpu->maxhv >=0x40000000 ) +dump_raw_cpuid (cpu->number,0x40000000 , cpu->maxhv); + }if (show_cacheinfo) {x86info.h +0
-0
x86info.h struct cpudata { · line 90
Quoted 8 lines
x86info.h +1
-1@@ -84,7 +84,7 @@ struct cpudata {unsigned int cachesize_trace;unsigned int phyaddr_bits;unsigned int viraddr_bits; -unsigned int cpuid_level, maxei, maxei2; +unsigned int cpuid_level, maxei, maxei2, maxhv;char name[CPU_NAME_LEN ];enum connector connector;unsigned int flags_ecx;
--
Gleb.
Quoted 36 lines · Michael S. Tsirkin
The following makes 'x86info -r' dump hypervisor leaf cpu ids (for kvm this is signature+features) when running in a vm.
On the guest we see the signature and the features:
eax in:0x40000000, eax = 00000000 ebx =4b4d564becx =564b4d56edx =0000004deax in:0x40000001, eax =0100007bebx = 00000000 ecx = 00000000 edx = 00000000Hypervisor flag is checked to avoid output changes when not running on a VM.
Signed-off-by Michael S. Tsirkin <[email protected]>Changes from v1:
Make work on non KVM hypervisors (only KVM was tested). Avi Kivity said kvm will in the future report max HV leaf in eax. For now it reports eax = 0 so add a work around for that.---
identify.c +2
-2@@ -9,8 +9,8 @@void get_cpu_info_basics (struct cpudata *cpu) { -unsigned int maxi, maxei, vendor, address_bits; -unsigned int eax; +unsigned int maxi, maxei, maxhv, vendor, address_bits; +unsigned int eax, ebx, ecx;cpuid (cpu->number,0 , &maxi, &vendor,NULL ,NULL ); maxi &=0xffff ;/* The high-order word is non-zero on some Cyrix CPUs */
identify.c void get_cpu_info_basics(struct cpudata *cpu) · line 22
Quoted 5 lines
identify.c +1
-1@@ -19,7 +19,7 @@ void get_cpu_info_basics(struct cpudata *cpu)return ;/* Everything that supports cpuid supports these. */ -cpuid (cpu->number,1 , &eax,NULL ,NULL ,NULL ); +cpuid (cpu->number,1 , &eax, &ebx, &ecx,NULL );
You probably want to check ebx, ecx, edx for the signatures of the hypervisor's you are willing to support and which you know do something sane with eax? Also it would be something worth reporting in its own right?
BTW, according to arch/x86/include/asm/kvm_para.h unsurprisingly KVM has a signature too 'KVMKVMKVM'.
identify.c void get_cpu_info_basics(struct cpudata *cpu) · line 36
Quoted 12 lines
identify.c +5
-0cpu->stepping = eax &0xf ; cpu->model = (eax >>4 ) &0xf ; cpu->family = (eax >>8 ) &0xf ;@@ -29,6 +29,19 @@ void get_cpu_info_basics(struct cpudata *cpu)cpuid (cpu->number,0xC0000000 , &maxei,NULL ,NULL ,NULL ); cpu->maxei2 = maxei; +if (ecx &0x80000000 ) { +cpuid (cpu->number,0x40000000 , &maxhv,NULL ,NULL ,NULL ); +/* +* KVM up to linux 3.4 reports 0 as the max hypervisor leaf, +* where it really means 0x40000001.
This is something where I definitely think you want to check the signature first.
Ian.
Quoted 44 lines
identify.c +8
-0+* Most (all?) hypervisors have at least one CPUID besides +* the vendor ID so assume that. +*/ + cpu->maxhv = maxhv ? maxhv :0x40000001 ; + }else { +/* Suppress hypervisor cpuid unless running on a hypervisor */ + cpu->maxhv =0 ; + }cpuid (cpu->number,0x80000008 ,&address_bits,NULL ,NULL ,NULL ); cpu->phyaddr_bits = address_bits &0xFF ;x86info.c +4
-0@@ -44,6 +44,10 @@ static void display_detailed_info(struct cpudata *cpu)if (cpu->maxei2 >=0xC0000000 )dump_raw_cpuid (cpu->number,0xC0000000 , cpu->maxei2); + +if (cpu->maxhv >=0x40000000 ) +dump_raw_cpuid (cpu->number,0x40000000 , cpu->maxhv); + }if (show_cacheinfo) {x86info.h +1
-1@@ -84,7 +84,7 @@ struct cpudata {unsigned int cachesize_trace;unsigned int phyaddr_bits;unsigned int viraddr_bits; -unsigned int cpuid_level, maxei, maxei2; +unsigned int cpuid_level, maxei, maxei2, maxhv;char name[CPU_NAME_LEN ];enum connector connector;unsigned int flags_ecx;_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Signature · 3 lines
Ian Campbell Your own qualities will help prevent your advancement in the world.
Michael S. Tsirkin
maintainerQuoted 39 lines · Ian Campbell
Quoted 38 lines · Michael S. Tsirkin
The following makes 'x86info -r' dump hypervisor leaf cpu ids (for kvm this is signature+features) when running in a vm.
On the guest we see the signature and the features:
eax in:0x40000000, eax = 00000000 ebx =4b4d564becx =564b4d56edx =0000004deax in:0x40000001, eax =0100007bebx = 00000000 ecx = 00000000 edx = 00000000Hypervisor flag is checked to avoid output changes when not running on a VM.
Signed-off-by Michael S. Tsirkin <[email protected]>Changes from v1:
Make work on non KVM hypervisors (only KVM was tested). Avi Kivity said kvm will in the future report max HV leaf in eax. For now it reports eax = 0 so add a work around for that.---
identify.c +2
-2@@ -9,8 +9,8 @@void get_cpu_info_basics (struct cpudata *cpu) { -unsigned int maxi, maxei, vendor, address_bits; -unsigned int eax; +unsigned int maxi, maxei, maxhv, vendor, address_bits; +unsigned int eax, ebx, ecx;cpuid (cpu->number,0 , &maxi, &vendor,NULL ,NULL ); maxi &=0xffff ;/* The high-order word is non-zero on some Cyrix CPUs */ @@ -19,7 +19,7 @@ void get_cpu_info_basics(struct cpudata *cpu)return ;
Quoted 7 lines
identify.c void get_cpu_info_basics(struct cpudata *cpu) · line 22
Quoted 3 lines
identify.c +1
-1/* Everything that supports cpuid supports these. */ -cpuid (cpu->number,1 , &eax,NULL ,NULL ,NULL ); +cpuid (cpu->number,1 , &eax, &ebx, &ecx,NULL );You probably want to check ebx, ecx, edx for the signatures of the hypervisor's you are willing to support and which you know do something sane with eax?
Everyone puts the max leaf in eax - this is what hardware CPUs do. So I think we can just interpret eax as such. If someone wants to put broken info in cpuid, send a patch to blacklist it.
Quoted 22 lines
Also it would be something worth reporting in its own right?
BTW, according to
arch/x86/include/asm/kvm_para.hunsurprisingly KVM has a signature too 'KVMKVMKVM'.identify.c void get_cpu_info_basics(struct cpudata *cpu) · line 36
Quoted 12 lines
identify.c +5
-0cpu->stepping = eax &0xf ; cpu->model = (eax >>4 ) &0xf ; cpu->family = (eax >>8 ) &0xf ;@@ -29,6 +29,19 @@ void get_cpu_info_basics(struct cpudata *cpu)cpuid (cpu->number,0xC0000000 , &maxei,NULL ,NULL ,NULL ); cpu->maxei2 = maxei; +if (ecx &0x80000000 ) { +cpuid (cpu->number,0x40000000 , &maxhv,NULL ,NULL ,NULL ); +/* +* KVM up to linux 3.4 reports 0 as the max hypervisor leaf, +* where it really means 0x40000001. This is something where I definitely think you want to check the signature first.
Quoted 1 line
Ian.
kvm lets users change the signature.
But worst case we print one useless line. Better than not printing something potentially useful.
Signature · 1 line
MST
Quoted 39 lines · Ian Campbell
Quoted 38 lines · Michael S. Tsirkin
The following makes 'x86info -r' dump hypervisor leaf cpu ids (for kvm this is signature+features) when running in a vm.
On the guest we see the signature and the features:
eax in:0x40000000, eax = 00000000 ebx =4b4d564becx =564b4d56edx =0000004deax in:0x40000001, eax =0100007bebx = 00000000 ecx = 00000000 edx = 00000000Hypervisor flag is checked to avoid output changes when not running on a VM.
Signed-off-by Michael S. Tsirkin <[email protected]>Changes from v1:
Make work on non KVM hypervisors (only KVM was tested). Avi Kivity said kvm will in the future report max HV leaf in eax. For now it reports eax = 0 so add a work around for that.---
identify.c +2
-2@@ -9,8 +9,8 @@void get_cpu_info_basics (struct cpudata *cpu) { -unsigned int maxi, maxei, vendor, address_bits; -unsigned int eax; +unsigned int maxi, maxei, maxhv, vendor, address_bits; +unsigned int eax, ebx, ecx;cpuid (cpu->number,0 , &maxi, &vendor,NULL ,NULL ); maxi &=0xffff ;/* The high-order word is non-zero on some Cyrix CPUs */ @@ -19,7 +19,7 @@ void get_cpu_info_basics(struct cpudata *cpu)return ;
Quoted 9 lines
identify.c void get_cpu_info_basics(struct cpudata *cpu) · line 22
Quoted 3 lines
identify.c +1
-1/* Everything that supports cpuid supports these. */ -cpuid (cpu->number,1 , &eax,NULL ,NULL ,NULL ); +cpuid (cpu->number,1 , &eax, &ebx, &ecx,NULL );You probably want to check ebx, ecx, edx for the signatures of the hypervisor's you are willing to support and which you know do something sane with eax? Also it would be something worth reporting in its own right?
Yes, but this is for -r option which only dumps raw cpuid info. Decoding hypervisor specific info is useful thing, but should not be pre-request for that patch.
Quoted 8 lines
BTW, according to
arch/x86/include/asm/kvm_para.hunsurprisingly KVM has a signature too 'KVMKVMKVM'.Quoted 5 lines
identify.c +0
-0cpu->stepping = eax &0xf ; cpu->model = (eax >>4 ) &0xf ; cpu->family = (eax >>8 ) &0xf ;@@ -29,6 +29,19 @@ void get_cpu_info_basics(struct cpudata *cpu)
Quoted 10 lines
identify.c void get_cpu_info_basics(struct cpudata *cpu) · line 36
Quoted 7 lines
identify.c +5
-0cpuid (cpu->number,0xC0000000 , &maxei,NULL ,NULL ,NULL ); cpu->maxei2 = maxei; +if (ecx &0x80000000 ) { +cpuid (cpu->number,0x40000000 , &maxhv,NULL ,NULL ,NULL ); +/* +* KVM up to linux 3.4 reports 0 as the max hypervisor leaf, +* where it really means 0x40000001. This is something where I definitely think you want to check the signature first.
In theory yes, but in practice what will this break?
Quoted 39 lines
Ian.
Quoted 36 lines
identify.c +8
-0+* Most (all?) hypervisors have at least one CPUID besides +* the vendor ID so assume that. +*/ + cpu->maxhv = maxhv ? maxhv :0x40000001 ; + }else { +/* Suppress hypervisor cpuid unless running on a hypervisor */ + cpu->maxhv =0 ; + }cpuid (cpu->number,0x80000008 ,&address_bits,NULL ,NULL ,NULL ); cpu->phyaddr_bits = address_bits &0xFF ;x86info.c +4
-0@@ -44,6 +44,10 @@ static void display_detailed_info(struct cpudata *cpu)if (cpu->maxei2 >=0xC0000000 )dump_raw_cpuid (cpu->number,0xC0000000 , cpu->maxei2); + +if (cpu->maxhv >=0x40000000 ) +dump_raw_cpuid (cpu->number,0x40000000 , cpu->maxhv); + }if (show_cacheinfo) {x86info.h +1
-1@@ -84,7 +84,7 @@ struct cpudata {unsigned int cachesize_trace;unsigned int phyaddr_bits;unsigned int viraddr_bits; -unsigned int cpuid_level, maxei, maxei2; +unsigned int cpuid_level, maxei, maxei2, maxhv;
Quoted 18 lines
Quoted 8 lines
x86info.h +0
-0char name[CPU_NAME_LEN ];enum connector connector;unsigned int flags_ecx;_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualizationSignature · 8 lines
Ian Campbell Your own qualities will help prevent your advancement in the world. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Gleb.
Quoted 18 lines · Gleb Natapov
Quoted 8 lines
BTW, according to
arch/x86/include/asm/kvm_para.hunsurprisingly KVM has a signature too 'KVMKVMKVM'.Quoted 5 lines
identify.c +0
-0cpu->stepping = eax &0xf ; cpu->model = (eax >>4 ) &0xf ; cpu->family = (eax >>8 ) &0xf ;@@ -29,6 +29,19 @@ void get_cpu_info_basics(struct cpudata *cpu)Quoted 10 lines
identify.c void get_cpu_info_basics(struct cpudata *cpu) · line 36
Quoted 7 lines
identify.c +5
-0cpuid (cpu->number,0xC0000000 , &maxei,NULL ,NULL ,NULL ); cpu->maxei2 = maxei; +if (ecx &0x80000000 ) { +cpuid (cpu->number,0x40000000 , &maxhv,NULL ,NULL ,NULL ); +/* +* KVM up to linux 3.4 reports 0 as the max hypervisor leaf, +* where it really means 0x40000001. This is something where I definitely think you want to check the signature first.
Quoted 1 line
In theory yes, but in practice what will this break?
I've got no idea -- but what's the harm in checking?
Ian.
Signature · 6 lines
Ian Campbell Current Noise: Hypocrisy - Roswell 47 Angels we have heard on High Tell us to go out and Buy. -- Tom Lehrer
Michael S. Tsirkin
maintainerQuoted 19 lines · Ian Campbell
Quoted 18 lines · Gleb Natapov
Quoted 18 lines
BTW, according to
arch/x86/include/asm/kvm_para.hunsurprisingly KVM has a signature too 'KVMKVMKVM'.identify.c void get_cpu_info_basics(struct cpudata *cpu) · line 36
Quoted 12 lines
identify.c +5
-0cpu->stepping = eax &0xf ; cpu->model = (eax >>4 ) &0xf ; cpu->family = (eax >>8 ) &0xf ;@@ -29,6 +29,19 @@ void get_cpu_info_basics(struct cpudata *cpu)cpuid (cpu->number,0xC0000000 , &maxei,NULL ,NULL ,NULL ); cpu->maxei2 = maxei; +if (ecx &0x80000000 ) { +cpuid (cpu->number,0x40000000 , &maxhv,NULL ,NULL ,NULL ); +/* +* KVM up to linux 3.4 reports 0 as the max hypervisor leaf, +* where it really means 0x40000001. This is something where I definitely think you want to check the signature first.
Quoted 5 lines
Quoted 1 line
In theory yes, but in practice what will this break?
I've got no idea -- but what's the harm in checking?
Ian.
Users can set kvm signature to anything, if they do debugging will be a bit harder for them.
Quoted 7 lines
Signature · 6 lines
Ian Campbell Current Noise: Hypocrisy - Roswell 47 Angels we have heard on High Tell us to go out and Buy. -- Tom Lehrer
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Ian Campbell
Quoted 18 lines · Gleb Natapov
Quoted 18 lines
BTW, according to
arch/x86/include/asm/kvm_para.hunsurprisingly KVM has a signature too 'KVMKVMKVM'.identify.c void get_cpu_info_basics(struct cpudata *cpu) · line 36
Quoted 12 lines
identify.c +5
-0cpu->stepping = eax &0xf ; cpu->model = (eax >>4 ) &0xf ; cpu->family = (eax >>8 ) &0xf ;@@ -29,6 +29,19 @@ void get_cpu_info_basics(struct cpudata *cpu)cpuid (cpu->number,0xC0000000 , &maxei,NULL ,NULL ,NULL ); cpu->maxei2 = maxei; +if (ecx &0x80000000 ) { +cpuid (cpu->number,0x40000000 , &maxhv,NULL ,NULL ,NULL ); +/* +* KVM up to linux 3.4 reports 0 as the max hypervisor leaf, +* where it really means 0x40000001. This is something where I definitely think you want to check the signature first.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
In theory yes, but in practice what will this break?
I've got no idea -- but what's the harm in checking?
Ian.
Users can set kvm signature to anything, if they do debugging will be a bit harder for them.
Ah, right, someone already mentioned that and I forgot, sorry.
And, just to complete my train of thought, cpuid just returns reserved values for requests for non-existent leaves (rather than #GP for example) so it's safe enough even if you do end up trying to read an eax=0x40000001 when it doesn't exist.
Seems fine to me then.
Ian.
Signature · 6 lines
Ian Campbell Current Noise: Hypocrisy - Buried He's like a function -- he returns a value, in the form of his opinion. It's up to you to cast it into a void or not. -- Phil Lapsley
Quoted 18 lines · Gleb Natapov
Quoted 8 lines
BTW, according to
arch/x86/include/asm/kvm_para.hunsurprisingly KVM has a signature too 'KVMKVMKVM'.Quoted 5 lines
identify.c +0
-0cpu->stepping = eax &0xf ; cpu->model = (eax >>4 ) &0xf ; cpu->family = (eax >>8 ) &0xf ;@@ -29,6 +29,19 @@ void get_cpu_info_basics(struct cpudata *cpu)Quoted 10 lines
identify.c void get_cpu_info_basics(struct cpudata *cpu) · line 36
Quoted 7 lines
identify.c +5
-0cpuid (cpu->number,0xC0000000 , &maxei,NULL ,NULL ,NULL ); cpu->maxei2 = maxei; +if (ecx &0x80000000 ) { +cpuid (cpu->number,0x40000000 , &maxhv,NULL ,NULL ,NULL ); +/* +* KVM up to linux 3.4 reports 0 as the max hypervisor leaf, +* where it really means 0x40000001. This is something where I definitely think you want to check the signature first.
Quoted 1 line
In theory yes, but in practice what will this break?
I've got no idea -- but what's the harm in checking?
Ian.
Signature · 6 lines
Ian Campbell Current Noise: Hypocrisy - Roswell 47 Angels we have heard on High Tell us to go out and Buy. -- Tom Lehrer
Quoted 36 lines · Michael S. Tsirkin
The following makes 'x86info -r' dump hypervisor leaf cpu ids (for kvm this is signature+features) when running in a vm.
On the guest we see the signature and the features:
eax in:0x40000000, eax = 00000000 ebx =4b4d564becx =564b4d56edx =0000004deax in:0x40000001, eax =0100007bebx = 00000000 ecx = 00000000 edx = 00000000Hypervisor flag is checked to avoid output changes when not running on a VM.
Signed-off-by Michael S. Tsirkin <[email protected]>Changes from v1:
Make work on non KVM hypervisors (only KVM was tested). Avi Kivity said kvm will in the future report max HV leaf in eax. For now it reports eax = 0 so add a work around for that.---
identify.c +2
-2@@ -9,8 +9,8 @@void get_cpu_info_basics (struct cpudata *cpu) { -unsigned int maxi, maxei, vendor, address_bits; -unsigned int eax; +unsigned int maxi, maxei, maxhv, vendor, address_bits; +unsigned int eax, ebx, ecx;cpuid (cpu->number,0 , &maxi, &vendor,NULL ,NULL ); maxi &=0xffff ;/* The high-order word is non-zero on some Cyrix CPUs */
identify.c void get_cpu_info_basics(struct cpudata *cpu) · line 22
Quoted 5 lines
identify.c +1
-1@@ -19,7 +19,7 @@ void get_cpu_info_basics(struct cpudata *cpu)return ;/* Everything that supports cpuid supports these. */ -cpuid (cpu->number,1 , &eax,NULL ,NULL ,NULL ); +cpuid (cpu->number,1 , &eax, &ebx, &ecx,NULL );
You probably want to check ebx, ecx, edx for the signatures of the hypervisor's you are willing to support and which you know do something sane with eax? Also it would be something worth reporting in its own right?
BTW, according to arch/x86/include/asm/kvm_para.h unsurprisingly KVM has a signature too 'KVMKVMKVM'.
identify.c void get_cpu_info_basics(struct cpudata *cpu) · line 36
Quoted 12 lines
identify.c +5
-0cpu->stepping = eax &0xf ; cpu->model = (eax >>4 ) &0xf ; cpu->family = (eax >>8 ) &0xf ;@@ -29,6 +29,19 @@ void get_cpu_info_basics(struct cpudata *cpu)cpuid (cpu->number,0xC0000000 , &maxei,NULL ,NULL ,NULL ); cpu->maxei2 = maxei; +if (ecx &0x80000000 ) { +cpuid (cpu->number,0x40000000 , &maxhv,NULL ,NULL ,NULL ); +/* +* KVM up to linux 3.4 reports 0 as the max hypervisor leaf, +* where it really means 0x40000001.
This is something where I definitely think you want to check the signature first.
Ian.
Quoted 44 lines
identify.c +8
-0+* Most (all?) hypervisors have at least one CPUID besides +* the vendor ID so assume that. +*/ + cpu->maxhv = maxhv ? maxhv :0x40000001 ; + }else { +/* Suppress hypervisor cpuid unless running on a hypervisor */ + cpu->maxhv =0 ; + }cpuid (cpu->number,0x80000008 ,&address_bits,NULL ,NULL ,NULL ); cpu->phyaddr_bits = address_bits &0xFF ;x86info.c +4
-0@@ -44,6 +44,10 @@ static void display_detailed_info(struct cpudata *cpu)if (cpu->maxei2 >=0xC0000000 )dump_raw_cpuid (cpu->number,0xC0000000 , cpu->maxei2); + +if (cpu->maxhv >=0x40000000 ) +dump_raw_cpuid (cpu->number,0x40000000 , cpu->maxhv); + }if (show_cacheinfo) {x86info.h +1
-1@@ -84,7 +84,7 @@ struct cpudata {unsigned int cachesize_trace;unsigned int phyaddr_bits;unsigned int viraddr_bits; -unsigned int cpuid_level, maxei, maxei2; +unsigned int cpuid_level, maxei, maxei2, maxhv;char name[CPU_NAME_LEN ];enum connector connector;unsigned int flags_ecx;_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Signature · 3 lines
Ian Campbell Your own qualities will help prevent your advancement in the world.
Michael S. Tsirkin
maintainerQuoted 10 lines · Michael S. Tsirkin
The following makes 'x86info -r' dump hypervisor leaf cpu ids (for kvm this is signature+features) when running in a vm.
On the guest we see the signature and the features:
eax in:0x40000000, eax = 00000000 ebx =4b4d564becx =564b4d56edx =0000004deax in:0x40000001, eax =0100007bebx = 00000000 ecx = 00000000 edx = 00000000Hypervisor flag is checked to avoid output changes when not running on a VM.
Quoted 7 lines
Signed-off-by Michael S. Tsirkin <[email protected]>Changes from v1:
Make work on non KVM hypervisors (only KVM was tested). Avi Kivity said kvm will in the future report max HV leaf in eax. For now it reports eax = 0 so add a work around for that.
Ping.
Davej, any comments?
Would be nice to have this in.
Quoted 74 lines
---
identify.c +16
-3@@ -9,8 +9,8 @@void get_cpu_info_basics (struct cpudata *cpu) { -unsigned int maxi, maxei, vendor, address_bits; -unsigned int eax; +unsigned int maxi, maxei, maxhv, vendor, address_bits; +unsigned int eax, ebx, ecx;cpuid (cpu->number,0 , &maxi, &vendor,NULL ,NULL ); maxi &=0xffff ;/* The high-order word is non-zero on some Cyrix CPUs */ @@ -19,7 +19,7 @@ void get_cpu_info_basics(struct cpudata *cpu)return ;/* Everything that supports cpuid supports these. */ -cpuid (cpu->number,1 , &eax,NULL ,NULL ,NULL ); +cpuid (cpu->number,1 , &eax, &ebx, &ecx,NULL ); cpu->stepping = eax &0xf ; cpu->model = (eax >>4 ) &0xf ; cpu->family = (eax >>8 ) &0xf ;@@ -29,6 +29,19 @@ void get_cpu_info_basics(struct cpudata *cpu)cpuid (cpu->number,0xC0000000 , &maxei,NULL ,NULL ,NULL ); cpu->maxei2 = maxei; +if (ecx &0x80000000 ) { +cpuid (cpu->number,0x40000000 , &maxhv,NULL ,NULL ,NULL ); +/* +* KVM up to linux 3.4 reports 0 as the max hypervisor leaf, +* where it really means 0x40000001. +* Most (all?) hypervisors have at least one CPUID besides +* the vendor ID so assume that. +*/ + cpu->maxhv = maxhv ? maxhv :0x40000001 ; + }else { +/* Suppress hypervisor cpuid unless running on a hypervisor */ + cpu->maxhv =0 ; + }cpuid (cpu->number,0x80000008 ,&address_bits,NULL ,NULL ,NULL ); cpu->phyaddr_bits = address_bits &0xFF ;x86info.c +4
-0@@ -44,6 +44,10 @@ static void display_detailed_info(struct cpudata *cpu)if (cpu->maxei2 >=0xC0000000 )dump_raw_cpuid (cpu->number,0xC0000000 , cpu->maxei2); + +if (cpu->maxhv >=0x40000000 ) +dump_raw_cpuid (cpu->number,0x40000000 , cpu->maxhv); + }if (show_cacheinfo) {x86info.h +1
-1@@ -84,7 +84,7 @@ struct cpudata {unsigned int cachesize_trace;unsigned int phyaddr_bits;unsigned int viraddr_bits; -unsigned int cpuid_level, maxei, maxei2; +unsigned int cpuid_level, maxei, maxei2, maxhv;char name[CPU_NAME_LEN ];enum connector connector;unsigned int flags_ecx;
Michael S. Tsirkin
maintainerQuoted 19 lines · Michael S. Tsirkin
Quoted 10 lines · Michael S. Tsirkin
The following makes 'x86info -r' dump hypervisor leaf cpu ids (for kvm this is signature+features) when running in a vm.
On the guest we see the signature and the features:
eax in:0x40000000, eax = 00000000 ebx =4b4d564becx =564b4d56edx =0000004deax in:0x40000001, eax =0100007bebx = 00000000 ecx = 00000000 edx = 00000000Hypervisor flag is checked to avoid output changes when not running on a VM.
Quoted 7 lines
Signed-off-by Michael S. Tsirkin <[email protected]>Changes from v1:
Make work on non KVM hypervisors (only KVM was tested). Avi Kivity said kvm will in the future report max HV leaf in eax. For now it reports eax = 0 so add a work around for that.
Quoted 3 lines
Ping.
Davej, any comments?
Would be nice to have this in.
Is this the right address?
Davej do you maintain x86info?
Thanks,
MST
Quoted 75 lines
Quoted 75 lines
---
identify.c +16
-3@@ -9,8 +9,8 @@void get_cpu_info_basics (struct cpudata *cpu) { -unsigned int maxi, maxei, vendor, address_bits; -unsigned int eax; +unsigned int maxi, maxei, maxhv, vendor, address_bits; +unsigned int eax, ebx, ecx;cpuid (cpu->number,0 , &maxi, &vendor,NULL ,NULL ); maxi &=0xffff ;/* The high-order word is non-zero on some Cyrix CPUs */ @@ -19,7 +19,7 @@ void get_cpu_info_basics(struct cpudata *cpu)return ;/* Everything that supports cpuid supports these. */ -cpuid (cpu->number,1 , &eax,NULL ,NULL ,NULL ); +cpuid (cpu->number,1 , &eax, &ebx, &ecx,NULL ); cpu->stepping = eax &0xf ; cpu->model = (eax >>4 ) &0xf ; cpu->family = (eax >>8 ) &0xf ;@@ -29,6 +29,19 @@ void get_cpu_info_basics(struct cpudata *cpu)cpuid (cpu->number,0xC0000000 , &maxei,NULL ,NULL ,NULL ); cpu->maxei2 = maxei; +if (ecx &0x80000000 ) { +cpuid (cpu->number,0x40000000 , &maxhv,NULL ,NULL ,NULL ); +/* +* KVM up to linux 3.4 reports 0 as the max hypervisor leaf, +* where it really means 0x40000001. +* Most (all?) hypervisors have at least one CPUID besides +* the vendor ID so assume that. +*/ + cpu->maxhv = maxhv ? maxhv :0x40000001 ; + }else { +/* Suppress hypervisor cpuid unless running on a hypervisor */ + cpu->maxhv =0 ; + }cpuid (cpu->number,0x80000008 ,&address_bits,NULL ,NULL ,NULL ); cpu->phyaddr_bits = address_bits &0xFF ;x86info.c +4
-0@@ -44,6 +44,10 @@ static void display_detailed_info(struct cpudata *cpu)if (cpu->maxei2 >=0xC0000000 )dump_raw_cpuid (cpu->number,0xC0000000 , cpu->maxei2); + +if (cpu->maxhv >=0x40000000 ) +dump_raw_cpuid (cpu->number,0x40000000 , cpu->maxhv); + }if (show_cacheinfo) {x86info.h +1
-1@@ -84,7 +84,7 @@ struct cpudata {unsigned int cachesize_trace;unsigned int phyaddr_bits;unsigned int viraddr_bits; -unsigned int cpuid_level, maxei, maxei2; +unsigned int cpuid_level, maxei, maxei2, maxhv;char name[CPU_NAME_LEN ];enum connector connector;unsigned int flags_ecx;
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Michael S. Tsirkin
Quoted 17 lines · Michael S. Tsirkin
The following makes 'x86info -r' dump hypervisor leaf cpu ids (for kvm this is signature+features) when running in a vm.
On the guest we see the signature and the features:
eax in:0x40000000, eax = 00000000 ebx =4b4d564becx =564b4d56edx =0000004deax in:0x40000001, eax =0100007bebx = 00000000 ecx = 00000000 edx = 00000000Hypervisor flag is checked to avoid output changes when not running on a VM.
Signed-off-by Michael S. Tsirkin <[email protected]>Changes from v1:
Make work on non KVM hypervisors (only KVM was tested). Avi Kivity said kvm will in the future report max HV leaf in eax. For now it reports eax = 0 so add a work around for that.
Quoted 8 lines
Quoted 3 lines
Ping.
Davej, any comments?
Would be nice to have this in.Is this the right address?
Davej do you maintain x86info?
Thanks,
MST
It's effectively abandonware at this point, largely due to my own lack of time. hwloc and similar tools seem to have taken it's place. If anyone is interested in taking over x86info, I'm happy to hand over the reins to someone capable.
Dave
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Michael S. Tsirkin
Quoted 17 lines · Michael S. Tsirkin
The following makes 'x86info -r' dump hypervisor leaf cpu ids (for kvm this is signature+features) when running in a vm.
On the guest we see the signature and the features:
eax in:0x40000000, eax = 00000000 ebx =4b4d564becx =564b4d56edx =0000004deax in:0x40000001, eax =0100007bebx = 00000000 ecx = 00000000 edx = 00000000Hypervisor flag is checked to avoid output changes when not running on a VM.
Signed-off-by Michael S. Tsirkin <[email protected]>Changes from v1:
Make work on non KVM hypervisors (only KVM was tested). Avi Kivity said kvm will in the future report max HV leaf in eax. For now it reports eax = 0 so add a work around for that.
Quoted 8 lines
Quoted 3 lines
Ping.
Davej, any comments?
Would be nice to have this in.Is this the right address?
Davej do you maintain x86info?
Thanks,
MST
It's effectively abandonware at this point, largely due to my own lack of time. hwloc and similar tools seem to have taken it's place. If anyone is interested in taking over x86info, I'm happy to hand over the reins to someone capable.
Dave