thread/core siblings info for guests
Avi,
There are some OSes like windows server which impose licensing restriction on number of cpus. These licensing restrictions are based on number of packages/sockets. And look into the cupid data to decide which cpus are thread siblings, core siblings and packages siblings. With current KVM/Qemu implementation it is hiding all this cupid information from the guests. So guest sees each cpu as a single package. And the license restrictions inside the OS is limiting no of cpus the guest can run.
These cupid bits should be exposed to the guest so that the OS would see the thread or core sibling information correctly to utilize more cpus.
Is anybody is working on this?
Thanks & Regards,
Nitin
Linux Open Source Technology Center, Intel Corporation
----------------------------------------------------------------------------
The Mind is like a parachute; it works much better when it's open.
Quoted 6 lines · Nitin A
Avi,
There are some OSes like windows server which impose licensing restriction on number of cpus. These licensing restrictions are based on number of packages/sockets. And look into the cupid data to decide which cpus are thread siblings, core siblings and packages siblings. With current KVM/Qemu implementation it is hiding all this cupid information from the guests. So guest sees each cpu as a single package. And the license restrictions inside the OS is limiting no of cpus the guest can run.
These cupid bits should be exposed to the guest so that the OS would see the thread or core sibling information correctly to utilize more cpus.Is anybody is working on this?
Not that I know of. Indeed finer control over cpuid is needed. We need to support at least three modes:
- default: expose some machine that is likely to be widely supported
- host: expose as much of the host cpu as we can
- managed: management application controls everything
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 7 lines · Avi Kivity
Not that I know of. Indeed finer control over cpuid is needed. We need to support at least three modes:
- default: expose some machine that is likely to be widely supported
- host: expose as much of the host cpu as we can
- managed: management application controls everything
qemu has an array with predefined cpu types, selectable via -cpu <name>.
IMHO it would be a good idea to reuse that, especially with the
upstream merge in mind ...
cheers,
Gerd
Quoted 9 lines
From: Avi Kivity [mailto:[email protected]]
Indeed finer control over cpuid is needed. We need to support at least three modes:
- default: expose some machine that is likely to be widely supported
- host: expose as much of the host cpu as we can
- managed: management application controls everything
[Nitin>]
Avi,
Would you like to elaborate more on these three mode's usage scenario?
As I see, there are 2 things to look for while providing the cpuid to the guest.
1. Guest migration across different hosts. This limits exposed cpu features.
2. Utilizing host CPU features. This expands exposed cpu features.
Both these needs should be accommodated keeping the flexibility to override.
Thanks & Regards,
Nitin
Linux Open Source Technology Center, Intel Corporation
-----------------------------------------------------------------------------
The Mind is like a parachute; it works much better when it's open.
Quoted 4 lines · * Kamble, Nitin A ([email protected]) wrote:
Quoted 4 lines
From: Avi Kivity [mailto:[email protected]] Indeed finer control over cpuid is needed. We need to support at least three modes:
Quoted 8 lines
Quoted 3 lines
- default: expose some machine that is likely to be widely supported
- host: expose as much of the host cpu as we can
- managed: management application controls everythingAvi,
Would you like to elaborate more on these three mode's usage scenario?As I see, there are 2 things to look for while providing the cpuid to the guest.
1. Guest migration across different hosts. This limits exposed cpu features.
This falls under managed above, as it's smth the mgmt app knows (e.g. what's the least common denominator in your migration pool?).
Quoted 1 line
2. Utilizing host CPU features. This expands exposed cpu features.
This falls under host above.
And the default mode above is just about picking a sane default.
thanks,
-chris
Hi Avi,
Attached is a patch to handle the "host mode" as you mentioned earlier.
It works this way:
Qemu's -cpu option is extended to take a new paramenter: -cpu _host_.
With that parameter the cpuid bits are collected from the host cpu. And few bits of cleared to get it working with the kvm.
I tested the patch with Windows & Linux guests, and I see the host
topology is propagating into the guest. With that windows server is not imposing the incorrect licensing restriction to guest, as it was doing earlier. With the patch I could bring up the windows server guest with 16 cpus on kvm.
I also fixed implementation of indexed cpuid leaves (0x4 & 0xb) in
qemu. And also some code cleanup are there for consistent terminology to have more readable code,
Please check-in the patch in kvm-usermode.git tree. There are no
changes for the kernel side or kvm.git tree for this.
Next things:
* Default mode: I am not planning to do anything for this. I see the
current situation is good enough for the default mode.
* Managed mode: For this, I am thinking few things.
1. Either an option can be added to qemu to take (almost) all of it's cpuid bits from a file.
2. Or use command line options to modify particular bits of guest cpuid.
3. Or do the both.
What do you think about the managed mode implementation? you probably have better idea regarding how and what kind of tools will be managing it.
Signature · 5 lines
Thanks & Regards, Nitin Open Source Technology Center, Intel Corporation ----------------------------------------------------------------- The mind is like a parachute; it works much better when it's open
Quoted 11 lines · Avi Kivity
Not that I know of. Indeed finer control over cpuid is needed. We need to support at least three modes:
- default: expose some machine that is likely to be widely supported
- host: expose as much of the host cpu as we can
- managed: management application controls everything--
error compilingcommittee.c: too many arguments to function
libkvm/libkvm-x86.c +2 -2
@@ -458,7 +458,7 @@ __u64 kvm_get_cr8(kvm_context_t kvm, int vcpu) }int kvm_setup_cpuid (kvm_context_t kvm,int vcpu,int nent, -struct kvm_cpuid_entry *entries) +struct kvm_cpuid_entry2 *entries) {struct kvm_cpuid *cpuid;int r;
@@ -469,7 +469,7 @@ int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, cpuid->nent = nent;memcpy (cpuid->entries, entries, nent *sizeof (*entries)); - r =ioctl (kvm->vcpu_fd[vcpu],KVM_SET_CPUID , cpuid); + r =ioctl (kvm->vcpu_fd[vcpu],KVM_SET_CPUID2 , cpuid);free (cpuid);return r;
libkvm/libkvm.h +1 -1
@@ -374,7 +374,7 @@ int kvm_guest_debug(kvm_context_t, int vcpu, struct kvm_debug_guest *dbg);* \return 0 on success, or -errno on error */ int kvm_setup_cpuid (kvm_context_t kvm,int vcpu,int nent, -struct kvm_cpuid_entry *entries); +struct kvm_cpuid_entry2 *entries);/*! * \brief Setting the number of shadow pages to be allocated to the vm
qemu/qemu-kvm-x86.c +34 -17
116 lines not on this page · raw message
qemu/target-i386/cpu.h +13 -12
@@ -600,18 +600,19 @@ typedef struct CPUX86State {CPU_COMMON /* processor features (e.g. for CPUID insn) */ - uint32_t cpuid_level; -uint32_t cpuid_vendor1; -uint32_t cpuid_vendor2; -uint32_t cpuid_vendor3; -uint32_t cpuid_version; -uint32_t cpuid_features; -uint32_t cpuid_ext_features; -uint32_t cpuid_xlevel; -uint32_t cpuid_model[12 ]; -uint32_t cpuid_ext2_features; -uint32_t cpuid_ext3_features; -uint32_t cpuid_apic_id; + uint32_t cpuid_level; /* leaf 0x00000000:EAX */ +uint32_t cpuid_vendor1;/* leaf 0x00000000:EBX */ +uint32_t cpuid_vendor2;/* leaf 0x00000000:ECX */ +uint32_t cpuid_vendor3;/* leaf 0x00000000:EDX */ +uint32_t cpuid_version;/* leaf 0x00000001:EAX */ +uint32_t cpuid_features;/* leaf 0x00000001:EDX */ +uint32_t cpuid_ext_features;/* leaf 0x00000001:ECX */ +uint32_t cpuid_xlevel;/* leaf 0x00000001:EDX */ +uint32_t cpuid_model[12 ];/* leaves 0x80000002 - 0x80000004 */ +uint32_t cpuid_ext2_features;/* leaf 0x80000001:EDX */ +uint32_t cpuid_ext3_features;/* leaf 0x80000001:ECX */ +uint32_t cpuid_apic_id;/* leaf 0x00000001:EBX.bits 24-31 */ +uint32_t cpu_host_cpu;/* guest cpuid =:= host cpuid */ #ifdef USE_KQEMU int kqemu_enabled;
qemu/target-i386/helper.c +73 -15
112 lines not on this page · raw message
qemu/target-i386/op_helper.c +56 -13
146 lines not on this page · raw message
Hi Nitin,
first of all thanks for taking on that work - it's something that's direly necessary and I appreciate what you're doing.
Quoted 13 lines · Nitin A Kamble
Hi Avi,
Attached is a patch to handle the "host mode" as you mentioned earlier.It works this way:
Qemu's -cpu option is extended to take a new paramenter: -cpu
_host_.
With that parameter the cpuid bits are collected from the host cpu. And few bits of cleared to get it working with the kvm.
I tested the patch with Windows & Linux guests, and I see the host
topology is propagating into the guest. With that windows server is not imposing the incorrect licensing restriction to guest, as it was doing earlier. With the patch I could bring up the windows server guest with 16 cpus on kvm.
This sounds like qemu-only source to me. Getting the cpuid from the host is nothing that involves the KVM interface whatsoever - even though I have to admit that it's only useful when used with opcode passthrough to the CPU, but that could also happen with kqemu.
Quoted 3 lines
I also fixed implementation of indexed cpuid leaves (
0x4&0xb) in qemu. And also some code cleanup are there for consistent terminology to have more readable code,
Please - don't mix cleanup with functional changes. The patch becomes unreadable - and I don't see any problems with leave 4 (b is not implemented, right?) in qemu. The qemu<->kvm cpuid interface is broken, yes. But that's two completely separate problems: CPUID bits being wrong in qemu should go to the qemu mailinglist, while libkvm breakage should be handled on the kvm list IMHO.
Quoted 16 lines
Please check-in the patch in kvm-usermode.git tree. There are no
changes for the kernel side or kvm.git tree for this.Signed-off-by Nitin A Kamble <[email protected]>Next things:
* Default mode: I am not planning to do anything for this. I see the current situation is good enough for the default mode.* Managed mode: For this, I am thinking few things.
1. Either an option can be added to qemu to take (almost) all of it's cpuid bits from a file.
2. Or use command line options to modify particular bits of guest cpuid.
3. Or do the both.
Quoted 3 lines
What do you think about the managed mode implementation? you probably have better idea regarding how and what kind of tools will be managing it.
Well, the case where you really need CPUID feature hiding is when you have a datacenter with a lot of different hosts in it. Then the management software would need to have a way to tell qemu the least common set of bits available throughout the whole center. Sounds like we really need config files ;-).
Some more comments:
- top-posting is evil ;-)
- please inline patches - it's hard to comment on any code like that (at least with my mail client)
So thanks to the lack of inlining I'll try to explain some rough bits on what I grasped while looking through the qemu parts of the patch:
1. void helper_cpuid(void)
You put a call like
+ if (env->cpu_host_cpu) {
+ host_cpuid(function, ECX, &EAX, &EBX, &ECX, &EDX);
+ break;
+ }
in almost every CPUID leaf. I don't think that's the way to go - there's got to be some more generic way to do what you're trying to achieve. Maybe just replace the whole helper_cpuid function with something special for the host case?
2. index->function cleanup
Is there any way you rename the variable apart from personal taste? I don't really like changes like that - they just break other's patches and it's not that hard to understand what index means here.
3. Do not use tabs in qemu code
4. The identifier "_host_" is ... arguable. I don't have any strong opinion on what to choose here, but the underscores look strange.
5.
+void host_cpuid(uint32_t function, uint32_t index, uint32_t *eax, uint32_t *ebx,
+ uint32_t *ecx, uint32_t *edx);
+
Are you seriously defining a function stub in the middle of a c file?
--
Sorry if I'm too harsh - usually I'm nicer when reviewing patches
Alex
Hi Alex,
Thanks a lot for your detailed review. I think I can do some changes as per your lines, which will make it friendlier for the qemu tree merge. And Avi also has some comments, which may need change in userland code. So hold on and I will cut another patch soon.
Thanks & Regards,
Nitin
Linux Open Source Technology Center, Intel Corporation
---------------------------------------------------------------------------
The Mind is like a parachute; it works much better when it's open.
Quoted 122 lines
-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Friday, October 17, 2008 5:19 PM
To: Kamble, Nitin A
Cc: Avi Kivity; [email protected]; [email protected]; [email protected]
Subject: Re: thread/core siblings info for guestsHi Nitin,
first of all thanks for taking on that work - it's something that's direly necessary and I appreciate what you're doing.
Quoted 4 lines · Nitin A Kamble
Hi Avi,
Attached is a patch to handle the "host mode" as you mentioned earlier.Quoted 12 lines
It works this way:
Qemu's -cpu option is extended to take a new paramenter: -cpu
_host_.
With that parameter the cpuid bits are collected from the host cpu. And
few bits of cleared to get it working with the kvm.
I tested the patch with Windows & Linux guests, and I see the host
topology is propagating into the guest. With that windows server is not
imposing the incorrect licensing restriction to guest, as it was doing earlier. With the patch I could bring up the windows server guest with 16 cpus on kvm.This sounds like qemu-only source to me. Getting the cpuid from the host is nothing that involves the KVM interface whatsoever - even though I have to admit that it's only useful when used with opcode passthrough to the CPU, but that could also happen with kqemu.
Quoted 4 lines
I also fixed implementation of indexed cpuid leaves (
0x4&0xb) in qemu. And also some code cleanup are there for consistent terminology to
have more readable code,Please - don't mix cleanup with functional changes. The patch becomes unreadable - and I don't see any problems with leave 4 (b is not implemented, right?) in qemu. The qemu<->kvm cpuid interface is broken, yes. But that's two completely separate problems: CPUID bits being wrong in qemu should go to the qemu mailinglist, while libkvm breakage should be handled on the kvm list IMHO.
Quoted 16 lines
Please check-in the patch in kvm-usermode.git tree. There are no
changes for the kernel side or kvm.git tree for this.Signed-off-by Nitin A Kamble <[email protected]>Next things:
* Default mode: I am not planning to do anything for this. I see the current situation is good enough for the default mode.* Managed mode: For this, I am thinking few things.
1. Either an option can be added to qemu to take (almost) all of it's cpuid bits from a file.
2. Or use command line options to modify particular bits of guest cpuid.
3. Or do the both.Quoted 3 lines
What do you think about the managed mode implementation? you probably have better idea regarding how and what kind of tools will be managing it.
Well, the case where you really need CPUID feature hiding is when you have a datacenter with a lot of different hosts in it. Then the management software would need to have a way to tell qemu the least common set of bits available throughout the whole center. Sounds like we really need config files ;-).
Some more comments:
- top-posting is evil ;-)
- please inline patches - it's hard to comment on any code like that (at least with my mail client)So thanks to the lack of inlining I'll try to explain some rough bits on what I grasped while looking through the qemu parts of the patch:
1. void
helper_cpuid(void)You put a call like
qemu/target-i386/op_helper.c +4
-0+if (env->cpu_host_cpu) { +host_cpuid (function,ECX , &EAX , &EBX , &ECX , &EDX ); +break ; + }in almost every CPUID leaf. I don't think that's the way to go - there's got to be some more generic way to do what you're trying to achieve. Maybe just replace the whole
helper_cpuidfunction with something special for the host case?2.
index->functioncleanupIs there any way you rename the variable apart from personal taste? I don't really like changes like that - they just break other's patches and it's not that hard to understand what index means here.
3. Do not use tabs in qemu code
4. The identifier "_host_" is ... arguable. I don't have any strong opinion on what to choose here, but the underscores look strange.
5.
+void host_cpuid(uint32_t function,
uint32_tindex,uint32_t*eax,uint32_t*ebx,(quoted diff) +2
-0+ uint32_t *ecx, uint32_t *edx); +Are you seriously defining a function stub in the middle of a c file?
--
Sorry if I'm too harsh - usually I'm nicer when reviewing patches
Alex
Quoted 73 lines · Nitin A Kamble
Hi Avi,
Attached is a patch to handle the "host mode" as you mentioned earlier.It works this way:
Qemu's -cpu option is extended to take a new paramenter: -cpu _host_.
With that parameter the cpuid bits are collected from the host cpu. And few bits of cleared to get it working with the kvm.
I tested the patch with Windows & Linux guests, and I see the host
topology is propagating into the guest. With that windows server is not imposing the incorrect licensing restriction to guest, as it was doing earlier. With the patch I could bring up the windows server guest with 16 cpus on kvm.
I also fixed implementation of indexed cpuid leaves (0x4&0xb) in
qemu. And also some code cleanup are there for consistent terminology to have more readable code,Please check-in the patch in kvm-usermode.git tree. There are no
changes for the kernel side or kvm.git tree for this.Signed-off-by Nitin A Kamble <[email protected]>Next things:
* Default mode: I am not planning to do anything for this. I see the
current situation is good enough for the default mode.* Managed mode: For this, I am thinking few things.
1. Either an option can be added to qemu to take (almost) all of it's cpuid bits from a file.
2. Or use command line options to modify particular bits of guest cpuid.
3. Or do the both.What do you think about the managed mode implementation? you probably have better idea regarding how and what kind of tools will be managing it.
qemu/target-i386/helper.c +35
-0+static int fill_x86_defs_for_host (CPUX86State *env,x86_def_t * def) +{ +uint32 eax, ebx, ecx, edx; + + env->cpu_host_cpu =1 ; + +host_cpuid (0 ,0 , &eax, &ebx, &ecx, &edx); + env->cpuid_level = eax; + env->cpuid_vendor1 = ebx; + env->cpuid_vendor2 = ecx; + env->cpuid_vendor3 = edx; + +host_cpuid (1 ,0 , &eax, &ebx, &ecx, &edx); + env->cpuid_version = eax; + env->cpuid_features = edx &0xdfffffff ;/* disable Thermal Monitro */ + env->cpuid_ext_features = ecx; + +host_cpuid (0x80000000 ,0 , &eax, &ebx, &ecx, &edx); + env->cpuid_xlevel = eax; + +host_cpuid (0x80000001 ,0 , &eax, &ebx, &ecx, &edx); + env->cpuid_ext3_features = ecx; + env->cpuid_ext2_features = edx &0xf7ffffff ;/* disable rdtscp */ + +host_cpuid (0x80000002 ,0 , &eax, &ebx, &ecx, &edx); + env->cpuid_model[0 ] = eax; + env->cpuid_model[1 ] = ebx; + env->cpuid_model[2 ] = ecx; + env->cpuid_model[3 ] = edx; + +host_cpuid (0x80000003 ,0 , &eax, &ebx, &ecx, &edx); + env->cpuid_model[4 ] = eax; + env->cpuid_model[5 ] = ebx; + env->cpuid_model[6 ] = ecx; + env->cpuid_model[7 ] = edx;
qemu/target-i386/helper.c void x86_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...)) · line 440
Quoted 10 lines
qemu/target-i386/helper.c +10
-0+ +host_cpuid (0x80000004 ,0 , &eax, &ebx, &ecx, &edx); + env->cpuid_model[8 ] = eax; + env->cpuid_model[9 ] = ebx; + env->cpuid_model[10 ] = ecx; + env->cpuid_model[11 ] = edx; + +return 0 ; +} +
There is already a kernel function for this (KVM_GET_SUPPORTED_CPUID, IIRC) that does this. It has the advantage of knowing which bits the kernel supports, so there's no need to keep the kernel and userspace at the same version.
Signature · 1 line
error compiling committee.c: too many arguments to function
Hi Avi,
I do find that ioctl in the kvm kernel module code. and the qemu code
can do the ioctl to get the cpuinfo bits. But seems like nobody is using this ioctl yet. What was the purpose of this code?
Quoted 8 lines · Avi Kivity
There is already a kernel function for this (
KVM_GET_SUPPORTED_CPUID, IIRC) that does this. It has the advantage of knowing which bits the kernel supports, so there's no need to keep the kernel and userspace at the same version.--
error compilingcommittee.c: too many arguments to function
Signature · 5 lines
Thanks & Regards, Nitin Open Source Technology Center, Intel Corporation ----------------------------------------------------------------- The mind is like a parachute; it works much better when it's open
Quoted 6 lines · Nitin A Kamble
Hi Avi,
I do find that ioctl in the kvm kernel module code. and the qemu code
can do the ioctl to get the cpuinfo bits. But seems like nobody is using this ioctl yet. What was the purpose of this code?
It's for -cpu host and for implementing greatest common denominator type of calculations. Qemu doesn't use it yet.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Avi & Alex,
Thanks for your suggestions. Now I have 2 attached patches to export
the host cpuid data to guests.
It reuses the ioctl KVM_GET_SUPPORTED_CPUID as Avi pointed out. Also
as per Alex's suggestions the changes have been simplified for easier merge with the qemu tree.
the kvm_kernel_patch is for the kvm.git tree.
And the kvm_userspace_patch is for the kvm-userspace.git tree.
Signature · 5 lines
Thanks & Regards, Nitin Open Source Technology Center, Intel Corporation ----------------------------------------------------------------- The mind is like a parachute; it works much better when it's open
arch/x86/include/asm/kvm_host.h +1 -1
@@ -86,7 +86,7 @@#define KVM_NUM_MMU_PAGES (1 << KVM_MMU_HASH_SHIFT)#define KVM_MIN_FREE_MMU_PAGES 5#define KVM_REFILL_PAGES 25 -#define KVM_MAX_CPUID_ENTRIES 40 +#define KVM_MAX_CPUID_ENTRIES 100#define KVM_NR_FIXED_MTRR_REGION 88#define KVM_NR_VAR_MTRR 8
arch/x86/kvm/x86.c +30 -38
127 lines not on this page · raw message
libkvm/libkvm-x86.c +31 -3
@@ -379,6 +379,34 @@ int kvm_set_msrs(kvm_context_t kvm, int vcpu, struct kvm_msr_entry *msrs,return r; } +/* +* Returns available host cpuid entries. User must free. +*/ +struct kvm_cpuid2 *kvm_get_host_cpuid_entries (kvm_context_t kvm) +{ +struct kvm_cpuid2 sizer, *cpuids; +int r, e; + + sizer.nent =0 ; + r =ioctl (kvm->fd,KVM_GET_SUPPORTED_CPUID , &sizer); +if (r ==-1 && errno !=E2BIG ) +return NULL ; + cpuids =malloc (sizeof *cpuids + sizer.nent *sizeof *cpuids->entries); +if (!cpuids) { + errno =ENOMEM ; +return NULL ; + } + cpuids->nent = sizer.nent; + r =ioctl (kvm->fd,KVM_GET_SUPPORTED_CPUID , cpuids); +if (r ==-1 ) { + e = errno; +free (cpuids); + errno = e; +return NULL ; + } +return cpuids; +} +static void print_seg (FILE *file,const char *name,struct kvm_segment *seg) { fprintf(stderr,
@@ -458,9 +486,9 @@ __u64 kvm_get_cr8(kvm_context_t kvm, int vcpu) }int kvm_setup_cpuid (kvm_context_t kvm,int vcpu,int nent, -struct kvm_cpuid_entry *entries) +struct kvm_cpuid_entry2 *entries) { -struct kvm_cpuid *cpuid; +struct kvm_cpuid2 *cpuid;int r; cpuid =malloc (sizeof (*cpuid) + nent *sizeof (*entries));
@@ -469,7 +497,7 @@ int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, cpuid->nent = nent;memcpy (cpuid->entries, entries, nent *sizeof (*entries)); - r =ioctl (kvm->vcpu_fd[vcpu],KVM_SET_CPUID , cpuid); + r =ioctl (kvm->vcpu_fd[vcpu],KVM_SET_CPUID2 , cpuid);free (cpuid);return r;
libkvm/libkvm.h +4 -1
@@ -27,6 +27,9 @@ typedef struct kvm_context *kvm_context_t;struct kvm_msr_list *kvm_get_msr_list (kvm_context_t );int kvm_get_msrs (kvm_context_t ,int vcpu,struct kvm_msr_entry *msrs,int n);int kvm_set_msrs (kvm_context_t ,int vcpu,struct kvm_msr_entry *msrs,int n); +struct kvm_cpuid2 *kvm_get_host_cpuid_entries (kvm_context_t ); +void get_host_cpuid_entry (uint32_t function,uint32_t index, +struct kvm_cpuid_entry2 * e);#endif /*!
@@ -374,7 +377,7 @@ int kvm_guest_debug(kvm_context_t, int vcpu, struct kvm_debug_guest *dbg);* \return 0 on success, or -errno on error */ int kvm_setup_cpuid (kvm_context_t kvm,int vcpu,int nent, -struct kvm_cpuid_entry *entries); +struct kvm_cpuid_entry2 *entries);/*! * \brief Setting the number of shadow pages to be allocated to the vm
qemu/qemu-kvm-x86.c +121 -21
195 lines not on this page · raw message
qemu/target-i386/cpu.h +1 -0
@@ -612,6 +612,7 @@ typedef struct CPUX86State {uint32_t cpuid_ext2_features;uint32_t cpuid_ext3_features;uint32_t cpuid_apic_id; +uint32_t cpuid_host_cpu;#ifdef USE_KQEMU int kqemu_enabled;
qemu/target-i386/helper.c +52 -0
68 lines not on this page · raw message
Quoted 11 lines · Nitin A Kamble
Avi & Alex,
Thanks for your suggestions. Now I have 2 attached patches to export
the host cpuid data to guests.
It reuses the ioctlKVM_GET_SUPPORTED_CPUIDas Avi pointed out. Also
as per Alex's suggestions the changes have been simplified for easier merge with the qemu tree.the
kvm_kernel_patchis for the kvm.git tree.
And thekvm_userspace_patchis for the kvm-userspace.git tree.
You need changelog entries that describe the patches. Also, one patch per email.
Quoted 19 lines
@ -1194,36 +1194,14 @@ static void do_cpuid_1_ent(struct
kvm_cpuid_entry2*entry, u32 function,
static void do_cpuid_ent(structkvm_cpuid_entry2*entry, u32 function,arch/x86/kvm/x86.c +0
-14u32 index, int *nent, int maxnent) { - const u32 kvm_supported_word0_x86_features = bit(X86_FEATURE_FPU) | -bit (X86_FEATURE_VME ) |bit (X86_FEATURE_DE ) | -bit (X86_FEATURE_PSE ) |bit (X86_FEATURE_TSC ) | -bit (X86_FEATURE_MSR ) |bit (X86_FEATURE_PAE ) | -bit (X86_FEATURE_CX8 ) |bit (X86_FEATURE_APIC ) | -bit (X86_FEATURE_SEP ) |bit (X86_FEATURE_PGE ) | -bit (X86_FEATURE_CMOV ) |bit (X86_FEATURE_PSE36 ) | -bit (X86_FEATURE_CLFLSH ) |bit (X86_FEATURE_MMX ) | -bit (X86_FEATURE_FXSR ) |bit (X86_FEATURE_XMM ) | -bit (X86_FEATURE_XMM2 ) |bit (X86_FEATURE_SELFSNOOP ); -const u32 kvm_supported_word1_x86_features =bit (X86_FEATURE_FPU ) | -bit (X86_FEATURE_VME ) |bit (X86_FEATURE_DE ) | -bit (X86_FEATURE_PSE ) |bit (X86_FEATURE_TSC ) | - bit(X86_FEATURE_MSR) | bit(X86_FEATURE_PAE) |
arch/x86/kvm/x86.c static void do_cpuid_1_ent(struct kvm_cpuid_entry2 *entry, u32 function, · line 1199
Quoted 10 lines
arch/x86/kvm/x86.c +3
-7-bit (X86_FEATURE_CX8 ) |bit (X86_FEATURE_APIC ) | -bit (X86_FEATURE_PGE ) | -bit (X86_FEATURE_CMOV ) |bit (X86_FEATURE_PSE36 ) | -bit (X86_FEATURE_MMX ) |bit (X86_FEATURE_FXSR ) | -bit (X86_FEATURE_SYSCALL ) | - (bit (X86_FEATURE_NX ) &&is_efer_nx ()) | -#ifdef CONFIG_X86_64 +const u32 kvm_unsupported_word0_x86_features =bit (X86_FEATURE_ACC ); +const u32 kvm_unsupported_word1_x86_features =bit (X86_FEATURE_RDTSCP ) | +#ifndef CONFIG_X86_64
What's the motivation for this change?
A potential problem is that a newer cpu might define new bits, which we don't support, yet we report them as supported.
arch/x86/kvm/x86.c static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, · line 1230
Quoted 10 lines
get_cpu()beforearch/x86/kvm/x86.c +1
-0@@ -1246,6 +1224,7 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,int t, times = entry->eax &0xff ; entry->flags |=KVM_CPUID_FLAG_STATEFUL_FUNC ; + entry->flags |=KVM_CPUID_FLAG_STATE_READ_NEXT ;for (t =1 ; t < times && *nent < maxnent; ++t) {do_cpuid_1_ent (&entry[t], function,0 ); entry[t].flags |=KVM_CPUID_FLAG_STATEFUL_FUNC ;
Why?
arch/x86/kvm/x86.c static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, · line 1261
Quoted 10 lines
arch/x86/kvm/x86.c +1
-1@@ -1276,7 +1255,7 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, entry->flags |=KVM_CPUID_FLAG_SIGNIFCANT_INDEX ;/* read more entries until level_type is zero */ for (i =1 ; *nent < maxnent; ++i) { - level_type = entry[i -1 ].ecx &0xff ; + level_type = entry[i -1 ].ecx &0xff00 ;if (!level_type)break ;do_cpuid_1_ent (&entry[i], function, i);
Why?
Quoted 5 lines
arch/x86/kvm/x86.c +1
-0@@ -1302,10 +1281,14 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid, {struct kvm_cpuid_entry2 *cpuid_entries;int limit, nent =0 , r = -E2BIG ; +int sizer =0 ;
arch/x86/kvm/x86.c static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid, · line 1292
Quoted 10 lines
arch/x86/kvm/x86.c +5
-2u32 func; -if (cpuid->nent <1 ) - goto out; +if (cpuid->nent ==0 ) { + sizer =1 ; + cpuid->nent =KVM_MAX_CPUID_ENTRIES ; + } +
That's an ABI change. New userspace could call an older kernel with nent = 0, and get an unexpected response.
arch/x86/kvm/x86.c void kvm_emulate_cpuid(struct kvm_vcpu *vcpu) · line 2855
Quoted 12 lines
arch/x86/kvm/x86.c +7
-0@@ -2860,6 +2845,13 @@ void kvm_emulate_cpuid(struct kvm_vcpu *vcpu)kvm_register_write (vcpu,VCPU_REGS_RCX , best->ecx);kvm_register_write (vcpu,VCPU_REGS_RDX , best->edx); } +if (function ==0x1 ) {/* set the per-cpu apicid */ +u32 ebx =kvm_register_read (vcpu,VCPU_REGS_RBX ); + ebx &=0x00ffffff ; + ebx |= (vcpu->vcpu_id <<24 ); +kvm_register_write (vcpu,VCPU_REGS_RBX , ebx); + } +
ABI change again. This is userspace's job.
Signature · 1 line
error compiling committee.c: too many arguments to function
Hi Avi,
Thanks for the comments on the patches. please see bellow for my
response to your comments.
Thanks & Regards,
Nitin
Quoted 3 lines · Avi Kivity
You need changelog entries that describe the patches. Also, one patch per email.
sounds right. I will cut my patch into smaller patches and send them one by one.
Quoted 32 lines
Quoted 19 lines
@ -1194,36 +1194,14 @@ static void do_cpuid_1_ent(struct
kvm_cpuid_entry2*entry, u32 function,
static void do_cpuid_ent(structkvm_cpuid_entry2*entry, u32 function,
u32 index, int *nent, int maxnent)
{arch/x86/kvm/x86.c +0
-14-const u32 kvm_supported_word0_x86_features =bit (X86_FEATURE_FPU ) | -bit (X86_FEATURE_VME ) |bit (X86_FEATURE_DE ) | -bit (X86_FEATURE_PSE ) |bit (X86_FEATURE_TSC ) | -bit (X86_FEATURE_MSR ) |bit (X86_FEATURE_PAE ) | -bit (X86_FEATURE_CX8 ) |bit (X86_FEATURE_APIC ) | -bit (X86_FEATURE_SEP ) |bit (X86_FEATURE_PGE ) | -bit (X86_FEATURE_CMOV ) |bit (X86_FEATURE_PSE36 ) | -bit (X86_FEATURE_CLFLSH ) |bit (X86_FEATURE_MMX ) | -bit (X86_FEATURE_FXSR ) |bit (X86_FEATURE_XMM ) | -bit (X86_FEATURE_XMM2 ) |bit (X86_FEATURE_SELFSNOOP ); -const u32 kvm_supported_word1_x86_features =bit (X86_FEATURE_FPU ) | -bit (X86_FEATURE_VME ) |bit (X86_FEATURE_DE ) | -bit (X86_FEATURE_PSE ) |bit (X86_FEATURE_TSC ) | - bit(X86_FEATURE_MSR) | bit(X86_FEATURE_PAE) |arch/x86/kvm/x86.c static void do_cpuid_1_ent(struct kvm_cpuid_entry2 *entry, u32 function, · line 1199
Quoted 10 lines
arch/x86/kvm/x86.c +3
-7-bit (X86_FEATURE_CX8 ) |bit (X86_FEATURE_APIC ) | -bit (X86_FEATURE_PGE ) | -bit (X86_FEATURE_CMOV ) |bit (X86_FEATURE_PSE36 ) | -bit (X86_FEATURE_MMX ) |bit (X86_FEATURE_FXSR ) | -bit (X86_FEATURE_SYSCALL ) | - (bit (X86_FEATURE_NX ) &&is_efer_nx ()) | -#ifdef CONFIG_X86_64 +const u32 kvm_unsupported_word0_x86_features =bit (X86_FEATURE_ACC ); +const u32 kvm_unsupported_word1_x86_features =bit (X86_FEATURE_RDTSCP ) | +#ifndef CONFIG_X86_64What's the motivation for this change?
Quoted 2 lines
A potential problem is that a newer cpu might define new bits, which we don't support, yet we report them as supported.
The motivation is: IMO There would be very few features which KVM will not be able to support by default. Also lots of cpuid bits are being blocked unnecessarily by the current code.
If there is a new feature which would break KVM implementation then it
will easy to notice, and easy to block that bit in the KVM at that time. But if the new feature is not affecting KVM then it will not be noticed, and KVM will end up unsupporting that cpu feature.
Quoted 5 lines
Quoted 5 lines
get_cpu()beforearch/x86/kvm/x86.c +0
-0@@ -1246,6 +1224,7 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,int t, times = entry->eax &0xff ;
Quoted 8 lines
arch/x86/kvm/x86.c static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, · line 1230
Quoted 6 lines
arch/x86/kvm/x86.c +1
-0entry->flags |=KVM_CPUID_FLAG_STATEFUL_FUNC ; + entry->flags |=KVM_CPUID_FLAG_STATE_READ_NEXT ;for (t =1 ; t < times && *nent < maxnent; ++t) {do_cpuid_1_ent (&entry[t], function,0 ); entry[t].flags |=KVM_CPUID_FLAG_STATEFUL_FUNC ;Why?
This is a bug fix. Without this change the code does not find a leaf 2 entry in the list.
Quoted 13 lines
arch/x86/kvm/x86.c static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, · line 1261
Quoted 11 lines
arch/x86/kvm/x86.c +1
-1@@ -1276,7 +1255,7 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, entry->flags |=KVM_CPUID_FLAG_SIGNIFCANT_INDEX ;/* read more entries until level_type is zero */ for (i =1 ; *nent < maxnent; ++i) { - level_type = entry[i -1 ].ecx &0xff ; + level_type = entry[i -1 ].ecx &0xff00 ;if (!level_type)break ;do_cpuid_1_ent (&entry[i], function, i);Why?
This is also a bugfix. The type field is in bits 8-15. As per the code, the bits 0-7 would not define the end of counting. You can look at IA32 processor Software developer's manual for this.
Quoted 8 lines
Quoted 8 lines
arch/x86/kvm/x86.c +1
-0@@ -1302,10 +1281,14 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid, {struct kvm_cpuid_entry2 *cpuid_entries;int limit, nent =0 , r = -E2BIG ; +int sizer =0 ;u32 func;
Quoted 11 lines
arch/x86/kvm/x86.c static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
Quoted 8 lines
arch/x86/kvm/x86.c +5
-2-if (cpuid->nent <1 ) - goto out; +if (cpuid->nent ==0 ) { + sizer =1 ; + cpuid->nent =KVM_MAX_CPUID_ENTRIES ; + } +That's an ABI change. New userspace could call an older kernel with nent = 0, and get an unexpected response.
That is right. What do you suggest for solution? Currently this ABI is not utilized. Would adding another ioctl would work?
Quoted 6 lines
Quoted 6 lines
arch/x86/kvm/x86.c +2
-0@@ -2860,6 +2845,13 @@ void kvm_emulate_cpuid(struct kvm_vcpu *vcpu)kvm_register_write (vcpu,VCPU_REGS_RCX , best->ecx);kvm_register_write (vcpu,VCPU_REGS_RDX , best->edx); } +if (function ==0x1 ) {/* set the per-cpu apicid */ +u32 ebx =kvm_register_read (vcpu,VCPU_REGS_RBX );
Quoted 8 lines
arch/x86/kvm/x86.c void kvm_emulate_cpuid(struct kvm_vcpu *vcpu)
Quoted 6 lines
arch/x86/kvm/x86.c +5
-0+ ebx &=0x00ffffff ; + ebx |= (vcpu->vcpu_id <<24 ); +kvm_register_write (vcpu,VCPU_REGS_RBX , ebx); + } +ABI change again. This is userspace's job.
This does not look like an ABI change to me. I will look if vcpu_id is available in the userspace, if yes, then this code can be moved into userspace.
Quoted 4 lines
--
error compilingcommittee.c: too many arguments to function
Signature · 5 lines
Thanks & Regards, Nitin Open Source Technology Center, Intel Corporation ----------------------------------------------------------------- The mind is like a parachute; it works much better when it's open
Quoted 35 lines · Nitin A Kamble
Quoted 32 lines
Quoted 20 lines
@ -1194,36 +1194,14 @@ static void do_cpuid_1_ent(struct
kvm_cpuid_entry2*entry, u32 function,
static void do_cpuid_ent(structkvm_cpuid_entry2*entry, u32 function,
u32 index, int *nent, int maxnent)
{arch/x86/kvm/x86.c +0
-14-const u32 kvm_supported_word0_x86_features =bit (X86_FEATURE_FPU ) | -bit (X86_FEATURE_VME ) |bit (X86_FEATURE_DE ) | -bit (X86_FEATURE_PSE ) |bit (X86_FEATURE_TSC ) | -bit (X86_FEATURE_MSR ) |bit (X86_FEATURE_PAE ) | -bit (X86_FEATURE_CX8 ) |bit (X86_FEATURE_APIC ) | -bit (X86_FEATURE_SEP ) |bit (X86_FEATURE_PGE ) | -bit (X86_FEATURE_CMOV ) |bit (X86_FEATURE_PSE36 ) | -bit (X86_FEATURE_CLFLSH ) |bit (X86_FEATURE_MMX ) | -bit (X86_FEATURE_FXSR ) |bit (X86_FEATURE_XMM ) | -bit (X86_FEATURE_XMM2 ) |bit (X86_FEATURE_SELFSNOOP ); -const u32 kvm_supported_word1_x86_features =bit (X86_FEATURE_FPU ) | -bit (X86_FEATURE_VME ) |bit (X86_FEATURE_DE ) | -bit (X86_FEATURE_PSE ) |bit (X86_FEATURE_TSC ) | - bit(X86_FEATURE_MSR) | bit(X86_FEATURE_PAE) |arch/x86/kvm/x86.c static void do_cpuid_1_ent(struct kvm_cpuid_entry2 *entry, u32 function, · line 1199
Quoted 10 lines
arch/x86/kvm/x86.c +3
-7-bit (X86_FEATURE_CX8 ) |bit (X86_FEATURE_APIC ) | -bit (X86_FEATURE_PGE ) | -bit (X86_FEATURE_CMOV ) |bit (X86_FEATURE_PSE36 ) | -bit (X86_FEATURE_MMX ) |bit (X86_FEATURE_FXSR ) | -bit (X86_FEATURE_SYSCALL ) | - (bit (X86_FEATURE_NX ) &&is_efer_nx ()) | -#ifdef CONFIG_X86_64 +const u32 kvm_unsupported_word0_x86_features =bit (X86_FEATURE_ACC ); +const u32 kvm_unsupported_word1_x86_features =bit (X86_FEATURE_RDTSCP ) | +#ifndef CONFIG_X86_64What's the motivation for this change?
Quoted 3 lines
A potential problem is that a newer cpu might define new bits, which we don't support, yet we report them as supported.
Quoted 8 lines
The motivation is: IMO There would be very few features which KVM will not be able to support by default. Also lots of cpuid bits are being blocked unnecessarily by the current code.
If there is a new feature which would break KVM implementation then it
will easy to notice, and easy to block that bit in the KVM at that time. But if the new feature is not affecting KVM then it will not be noticed, and KVM will end up unsupporting that cpu feature.
Having an extra cpuid bit means that a guest will crash, while missing one slows it down a bit. We need to be conservative and not risk passing incorrect data.
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
get_cpu()beforearch/x86/kvm/x86.c +0
-0@@ -1246,6 +1224,7 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,int t, times = entry->eax &0xff ;Quoted 9 lines
arch/x86/kvm/x86.c static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, · line 1230
Quoted 7 lines
arch/x86/kvm/x86.c +1
-0entry->flags |=KVM_CPUID_FLAG_STATEFUL_FUNC ; + entry->flags |=KVM_CPUID_FLAG_STATE_READ_NEXT ;for (t =1 ; t < times && *nent < maxnent; ++t) {do_cpuid_1_ent (&entry[t], function,0 ); entry[t].flags |=KVM_CPUID_FLAG_STATEFUL_FUNC ;Why?
Quoted 4 lines
This is a bug fix. Without this change the code does not find a leaf 2 entry in the list.
Please send it as a separate patch, with a changelog entry describing why it is needed.
Quoted 14 lines
Quoted 14 lines
arch/x86/kvm/x86.c static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, · line 1261
Quoted 12 lines
arch/x86/kvm/x86.c +1
-1@@ -1276,7 +1255,7 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, entry->flags |=KVM_CPUID_FLAG_SIGNIFCANT_INDEX ;/* read more entries until level_type is zero */ for (i =1 ; *nent < maxnent; ++i) { - level_type = entry[i -1 ].ecx &0xff ; + level_type = entry[i -1 ].ecx &0xff00 ;if (!level_type)break ;do_cpuid_1_ent (&entry[i], function, i);Why?
Quoted 6 lines
This is also a bugfix. The type field is in bits 8-15. As per the code, the bits 0-7 would not define the end of counting. You can look at IA32 processor Software developer's manual for this.
Separate patch, please.
Quoted 19 lines
Quoted 7 lines
Quoted 7 lines
arch/x86/kvm/x86.c +1
-0@@ -1302,10 +1281,14 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid, {struct kvm_cpuid_entry2 *cpuid_entries;int limit, nent =0 , r = -E2BIG ; +int sizer =0 ;u32 func;Quoted 12 lines
arch/x86/kvm/x86.c static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
Quoted 9 lines
arch/x86/kvm/x86.c +5
-2-if (cpuid->nent <1 ) - goto out; +if (cpuid->nent ==0 ) { + sizer =1 ; + cpuid->nent =KVM_MAX_CPUID_ENTRIES ; + } +That's an ABI change. New userspace could call an older kernel with nent = 0, and get an unexpected response.
Quoted 4 lines
That is right. What do you suggest for solution? Currently this ABI is not utilized. Would adding another ioctl would work?
We could have the response to KVM_CHECK_EXTENSION(KVM_CAP_CPUID2 (or however it's called)) return the number of entries, and document that 1 means "unknown" (well, we could have done it with your proposal too).
Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
arch/x86/kvm/x86.c +0
-0@@ -2860,6 +2845,13 @@ void kvm_emulate_cpuid(struct kvm_vcpu *vcpu)kvm_register_write (vcpu,VCPU_REGS_RCX , best->ecx);kvm_register_write (vcpu,VCPU_REGS_RDX , best->edx);arch/x86/kvm/x86.c void kvm_emulate_cpuid(struct kvm_vcpu *vcpu) · line 2856
Quoted 10 lines
arch/x86/kvm/x86.c +7
-0} +if (function ==0x1 ) {/* set the per-cpu apicid */ +u32 ebx =kvm_register_read (vcpu,VCPU_REGS_RBX ); + ebx &=0x00ffffff ; + ebx |= (vcpu->vcpu_id <<24 ); +kvm_register_write (vcpu,VCPU_REGS_RBX , ebx); + } +ABI change again. This is userspace's job.
Quoted 1 line
This does not look like an ABI change to me.
Right, it isn't an ABI change. But we should avoid situations where the same call does different things in different kernel versions.
Quoted 5 lines
I will look if
vcpu_idis
available in the userspace, if yes, then this code can be moved into userspace.
Yes, it's available in userspace.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
PATCH 1/1 thread/core siblings info for guests
Hi Avi,
Attached is the patch for the bugfix1, as we discussed in the earlier
email.
For cpuid leaf 0xb the bits 8-15 in ECX register define the end of counting leaf.
The previous code was using bits 0-7 for this purpose, which is a bug.
Please Apply,
Thanks & Regards,
Nitin
commit 96ab287a9d90fc4c04438f6943b36049bbdfe854
Author: Nitin A Kamble <[email protected]> Date: Wed Nov 5 15:28:13 2008 -0800
For cpuid leaf 0xb the bits 8-15 in ECX register define the end of counting leaf. The previous code was using bits 0-7 for this purpose, which is a bug.
arch/x86/kvm/x86.c +1 -1
@@ -1276,7 +1276,7 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, entry->flags |=KVM_CPUID_FLAG_SIGNIFCANT_INDEX ;/* read more entries until level_type is zero */ for (i =1 ; *nent < maxnent; ++i) { - level_type = entry[i -1 ].ecx &0xff ; + level_type = entry[i -1 ].ecx &0xff00 ;if (!level_type)break ;do_cpuid_1_ent (&entry[i], function, i);
Avi Kivity
AppliedQuoted 10 lines · Nitin A Kamble
Hi Avi,
Attached is the patch for the bugfix1, as we discussed in the earlier
email.For cpuid leaf
0xbthe bits 8-15 in ECX register define the end of counting leaf.
The previous code was using bits 0-7 for this purpose, which is a bug.
Applied, thanks.
Signature · 1 line
error compiling committee.c: too many arguments to function
PATCH 1/1 thread/core siblings info for guests
In reply to Avi KivityHi Avi,
This patches the 2nd bug in the kernel code.
The code to traverse the cpuid data array list for counting type of leaves is currently broken.
This patches fixes the 2 things in it.
1. Set the 1st counting entry's flag KVM_CPUID_FLAG_STATE_READ_NEXT. Without it the code will never find a valid entry.
2. Also the stop condition in the for loop while looking for the next unflaged entry is broken. It needs to stop when it find one matching entry; and in the case of count of 1, it will be the same entry found in this iteration.
Please apply.
Thanks & Regards,
Nitin
commit 61fd85ec73d691d080a0adecab2f61840eef1a3e
Author: Nitin A Kamble <[email protected]> Date: Wed Nov 5 15:47:35 2008 -0800
The code to traverse the cpuid data array list for counting type of leaves is currently broken.
This patches fixes the 2 things in it.
1. Set the 1st counting entry's flag KVM_CPUID_FLAG_STATE_READ_NEXT. Without it the code will never find a valid entry.
2. Also the stop condition in the for loop while looking for the next unflaged entry is broken. It needs to stop when it find one matching entry; and in the case of count of 1, it will be the same entry found in this iteration.
arch/x86/kvm/x86.c +2 -1
@@ -1246,6 +1246,7 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,int t, times = entry->eax &0xff ; entry->flags |=KVM_CPUID_FLAG_STATEFUL_FUNC ; + entry->flags |=KVM_CPUID_FLAG_STATE_READ_NEXT ;for (t =1 ; t < times && *nent < maxnent; ++t) {do_cpuid_1_ent (&entry[t], function,0 ); entry[t].flags |=KVM_CPUID_FLAG_STATEFUL_FUNC ;
@@ -2801,7 +2802,7 @@ static int move_to_next_stateful_cpuid_entry(struct kvm_vcpu *vcpu, int i) e->flags &= ~KVM_CPUID_FLAG_STATE_READ_NEXT ;/* when no next entry is found, the current entry[i] is reselected */ -for (j = i +1 ; j == i; j = (j +1 ) % nent) { +for (j = i +1 ; ; j = (j +1 ) % nent) {struct kvm_cpuid_entry2 *ej = &vcpu->arch.cpuid_entries[j];if (ej->function == e->function) { ej->flags |=KVM_CPUID_FLAG_STATE_READ_NEXT ;
Avi Kivity
AppliedQuoted 14 lines · Nitin A Kamble
Hi Avi,
This patches the 2nd bug in the kernel code.The code to traverse the cpuid data array list for counting type of leaves is currently broken.
This patches fixes the 2 things in it.
1. Set the 1st counting entry's flagKVM_CPUID_FLAG_STATE_READ_NEXT. Without it the code will never find a valid entry.
2. Also the stop condition in the for loop while looking for the next unflaged entry is broken. It needs to stop when it find one matching entry; and in the case of count of 1, it will be the same entry found in this iteration.
Applied, thanks.
Signature · 1 line
error compiling committee.c: too many arguments to function
PATCH 1/1 thread/core siblings info for guests
In reply to Avi KivityHi Avi,
This patch cover's the kernel ABI change as we discussed in the
earlier email.
Patch Description:
Change the ioctl KVM_GET_SUPPORTED_CPUID, such that it will return the no of entries in the list when requested no of entries (nent) is 0.
Also add another KVM_CHECK_EXTENSION, KVM_CAP_CPUID_SIZER to determine if the running kernel supports the above changed ABI.
Please Apply.
Thanks & Regards,
Nitin
commit 70e4e65bc591eb9cf25c1cbc0d16b2cbdb089a6f
Author: Nitin A Kamble <[email protected]> Date: Wed Nov 5 16:17:46 2008 -0800
Change the ioctl KVM_GET_SUPPORTED_CPUID, such that it will return the no of entries in the list when request no of entries (nent) is 0.
Also add another KVM_CHECK_EXTENSION, KVM_CAP_CPUID_SIZER to determine if the running kernel supports the above changed ABI.
arch/x86/include/asm/kvm_host.h +1 -1
@@ -86,7 +86,7 @@#define KVM_NUM_MMU_PAGES (1 << KVM_MMU_HASH_SHIFT)#define KVM_MIN_FREE_MMU_PAGES 5#define KVM_REFILL_PAGES 25 -#define KVM_MAX_CPUID_ENTRIES 40 +#define KVM_MAX_CPUID_ENTRIES 100#define KVM_NR_FIXED_MTRR_REGION 88#define KVM_NR_VAR_MTRR 8
arch/x86/kvm/x86.c +11 -4
@@ -969,6 +969,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_NOP_IO_DELAY :case KVM_CAP_MP_STATE :case KVM_CAP_SYNC_MMU : +case KVM_CAP_CPUID_SIZER : r =1 ;break ;case KVM_CAP_COALESCED_MMIO :
@@ -1303,10 +1304,14 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid, {struct kvm_cpuid_entry2 *cpuid_entries;int limit, nent =0 , r = -E2BIG ; +int sizer =0 ;u32 func; -if (cpuid->nent <1 ) - goto out; +if (cpuid->nent ==0 ) { + sizer =1 ; + cpuid->nent =KVM_MAX_CPUID_ENTRIES ; + } + r = -ENOMEM ; cpuid_entries =vmalloc (sizeof (struct kvm_cpuid_entry2 ) * cpuid->nent);if (!cpuid_entries)
@@ -1327,9 +1332,11 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,do_cpuid_ent (&cpuid_entries[nent], func,0 , &nent, cpuid->nent); r = -EFAULT ; -if (copy_to_user (entries, cpuid_entries, +if (!sizer) { +if (copy_to_user (entries, cpuid_entries, nent *sizeof (struct kvm_cpuid_entry2 ))) - goto out_free; + goto out_free; + } cpuid->nent = nent; r =0 ;
include/linux/kvm.h +3 -0
@@ -392,6 +392,9 @@ struct kvm_trace_rec {#endif #define KVM_CAP_IOMMU 18#define KVM_CAP_NMI 19 +#define KVM_CAP_CPUID_SIZER 20/* return of 1 means the KVM_GET_SUPPORTED_CPUID */ +/* ioctl will return the size of list when input */ +/* list size (nent) is 0 */ /* * ioctls for VM fds
Quoted 4 lines · Nitin A Kamble
Hi Avi,
This patch cover's the kernel ABI change as we discussed in the
earlier email.
Quoted 8 lines
Patch Description:
Change the ioctl
KVM_GET_SUPPORTED_CPUID, such that it will return the no of entries in the list when requested no of entries (nent) is 0.Also add another
KVM_CHECK_EXTENSION,KVM_CAP_CPUID_SIZERto determine if the running kernel supports the above changed ABI.
The capability itself can return the count; for example
case KVM_CAP_NR_CPUID_LEAVES:
return KVM_MAX_CPUID_ENTRIES;
which is simpler to use and shorter.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 6 lines
The capability itself can return the count; for example
case
KVM_CAP_NR_CPUID_LEAVES:return KVM_MAX_CPUID_ENTRIES;which is simpler to use and shorter.
Avi,
Yes, it is simpler and shorter, but is returning a constant. It will be wasting space for the unused entries. Also it put's a restriction that the list count can not go more than that. The dynamic size finding, the patch I sent, is not complicated or long to be an issue. Would you like to give another consideration for the same patch (patch-3) I sent earlier?
Thanks & Regards,
Nitin
Quoted 5 lines · Nitin A
Quoted 5 lines
The capability itself can return the count; for example
case
KVM_CAP_NR_CPUID_LEAVES:return KVM_MAX_CPUID_ENTRIES;
Quoted 8 lines
Quoted 2 lines
which is simpler to use and shorter.
Avi,
Yes, it is simpler and shorter, but is returning a constant. It will be wasting space for the unused entries. Also it put's a restriction that the list count can not go more than that. The dynamic size finding, the patch I sent, is not complicated or long to be an issue. Would you like to give another consideration for the same patch (patch-3) I sent earlier?
Oh, I confused the sizing code with something else.
We can add this, but older kernels will still miss the code so we have to work around it. I guess userspace can start with a large number, and double it each time the ioctl fails.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 15 lines · Avi Kivity
Quoted 5 lines · Nitin A
Quoted 5 lines
The capability itself can return the count; for example
case
KVM_CAP_NR_CPUID_LEAVES:return KVM_MAX_CPUID_ENTRIES;Quoted 8 lines
Quoted 2 lines
which is simpler to use and shorter.
Avi,
Yes, it is simpler and shorter, but is returning a constant. It will be wasting space for the unused entries. Also it put's a restriction that the list count can not go more than that. The dynamic size finding, the patch I sent, is not complicated or long to be an issue. Would you like to give another consideration for the same patch (patch-3) I sent earlier?
Quoted 5 lines
Oh, I confused the sizing code with something else.
We can add this, but older kernels will still miss the code so we have to work around it. I guess userspace can start with a large number, and double it each time the ioctl fails.
Avi,
You mean older kernels which does not support the KVM_CAP_CPUID_SIZER
ioctl.
Two ways to handle it:
1. qemu giving error that "-cpu host" option is not supported on this kernel.
2. or as per your suggestion guess it in userland.
Either way it is code for kvm-userspace.git tree.
I am attaching the patch again. Please apply.
BTW I did not get your opinion for the patch for the kvm-userspace.git tree. Would you comment on it please?
Signature · 5 lines
Thanks & Regards, Nitin Open Source Technology Center, Intel Corporation ----------------------------------------------------------------- The mind is like a parachute; it works much better when it's open
commit 70e4e65bc591eb9cf25c1cbc0d16b2cbdb089a6f
Author: Nitin A Kamble <[email protected]> Date: Wed Nov 5 16:17:46 2008 -0800
Change the ioctl KVM_GET_SUPPORTED_CPUID, such that it will return the no of entries in the list when requested no of entries (nent) is 0.
Also add another KVM_CHECK_EXTENSION, KVM_CAP_CPUID_SIZER to determine if the running kernel supports the above changed ABI.
arch/x86/include/asm/kvm_host.h +1 -1
@@ -86,7 +86,7 @@#define KVM_NUM_MMU_PAGES (1 << KVM_MMU_HASH_SHIFT)#define KVM_MIN_FREE_MMU_PAGES 5#define KVM_REFILL_PAGES 25 -#define KVM_MAX_CPUID_ENTRIES 40 +#define KVM_MAX_CPUID_ENTRIES 100#define KVM_NR_FIXED_MTRR_REGION 88#define KVM_NR_VAR_MTRR 8
arch/x86/kvm/x86.c +11 -4
@@ -969,6 +969,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_NOP_IO_DELAY :case KVM_CAP_MP_STATE :case KVM_CAP_SYNC_MMU : +case KVM_CAP_CPUID_SIZER : r =1 ;break ;case KVM_CAP_COALESCED_MMIO :
@@ -1303,10 +1304,14 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid, {struct kvm_cpuid_entry2 *cpuid_entries;int limit, nent =0 , r = -E2BIG ; +int sizer =0 ;u32 func; -if (cpuid->nent <1 ) - goto out; +if (cpuid->nent ==0 ) { + sizer =1 ; + cpuid->nent =KVM_MAX_CPUID_ENTRIES ; + } + r = -ENOMEM ; cpuid_entries =vmalloc (sizeof (struct kvm_cpuid_entry2 ) * cpuid->nent);if (!cpuid_entries)
@@ -1327,9 +1332,11 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,do_cpuid_ent (&cpuid_entries[nent], func,0 , &nent, cpuid->nent); r = -EFAULT ; -if (copy_to_user (entries, cpuid_entries, +if (!sizer) { +if (copy_to_user (entries, cpuid_entries, nent *sizeof (struct kvm_cpuid_entry2 ))) - goto out_free; + goto out_free; + } cpuid->nent = nent; r =0 ;
include/linux/kvm.h +3 -0
@@ -392,6 +392,9 @@ struct kvm_trace_rec {#endif #define KVM_CAP_IOMMU 18#define KVM_CAP_NMI 19 +#define KVM_CAP_CPUID_SIZER 20/* return of 1 means the KVM_GET_SUPPORTED_CPUID */ +/* ioctl will return the size of list when input */ +/* list size (nent) is 0 */ /* * ioctls for VM fds