* [PATCH 0/2] kvm: x86: Emulate MSR_PLATFORM_INFO @ 2013-05-29 21:40 Bandan Das 2013-05-29 21:40 ` [PATCH 1/2] kvm: make vendor_intel a generic function Bandan Das 2013-05-29 21:40 ` [PATCH 2/2] kvm: x86: emulate MSR_PLATFORM_INFO Bandan Das 0 siblings, 2 replies; 7+ messages in thread From: Bandan Das @ 2013-05-29 21:40 UTC (permalink / raw) To: kvm; +Cc: Gleb Natapov, Paolo Bonzini, Marcelo Tosatti These patches add an emulated MSR_PLATFORM_INFO that kvm guests can read as described in section 14.3.2.4 of the Intel SDM. The relevant changes and details are in [2/2]; [1/2] makes vendor_intel generic. There are atleat two known applications that fail to run because of this MSR missing - Sandra and vTune. Bandan Das (2): kvm: make vendor_intel a generic function kvm: x86: emulate MSR_PLATFORM_INFO arch/x86/include/asm/kvm_emulate.h | 13 --------- arch/x86/include/asm/kvm_host.h | 28 +++++++++++++++++++ arch/x86/include/uapi/asm/msr-index.h | 2 ++ arch/x86/kvm/cpuid.c | 18 +++++++++++++ arch/x86/kvm/cpuid.h | 16 +++++++++++ arch/x86/kvm/emulate.c | 15 +++-------- arch/x86/kvm/x86.c | 51 ++++++++++++++++++++++++++++++++--- 7 files changed, 115 insertions(+), 28 deletions(-) -- 1.8.1.4 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] kvm: make vendor_intel a generic function 2013-05-29 21:40 [PATCH 0/2] kvm: x86: Emulate MSR_PLATFORM_INFO Bandan Das @ 2013-05-29 21:40 ` Bandan Das 2013-05-30 5:39 ` Paolo Bonzini 2013-05-29 21:40 ` [PATCH 2/2] kvm: x86: emulate MSR_PLATFORM_INFO Bandan Das 1 sibling, 1 reply; 7+ messages in thread From: Bandan Das @ 2013-05-29 21:40 UTC (permalink / raw) To: kvm; +Cc: Gleb Natapov, Paolo Bonzini, Marcelo Tosatti, Bandan Das Make vendor_intel generic so that functions in x86.c can use it. Signed-off-by: Bandan Das <bsd@redhat.com> --- arch/x86/include/asm/kvm_emulate.h | 13 ------------- arch/x86/include/asm/kvm_host.h | 28 ++++++++++++++++++++++++++++ arch/x86/kvm/emulate.c | 15 +++------------ arch/x86/kvm/x86.c | 3 --- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h index 15f960c..611a55f 100644 --- a/arch/x86/include/asm/kvm_emulate.h +++ b/arch/x86/include/asm/kvm_emulate.h @@ -319,19 +319,6 @@ struct x86_emulate_ctxt { #define REPE_PREFIX 0xf3 #define REPNE_PREFIX 0xf2 -/* CPUID vendors */ -#define X86EMUL_CPUID_VENDOR_AuthenticAMD_ebx 0x68747541 -#define X86EMUL_CPUID_VENDOR_AuthenticAMD_ecx 0x444d4163 -#define X86EMUL_CPUID_VENDOR_AuthenticAMD_edx 0x69746e65 - -#define X86EMUL_CPUID_VENDOR_AMDisbetterI_ebx 0x69444d41 -#define X86EMUL_CPUID_VENDOR_AMDisbetterI_ecx 0x21726574 -#define X86EMUL_CPUID_VENDOR_AMDisbetterI_edx 0x74656273 - -#define X86EMUL_CPUID_VENDOR_GenuineIntel_ebx 0x756e6547 -#define X86EMUL_CPUID_VENDOR_GenuineIntel_ecx 0x6c65746e -#define X86EMUL_CPUID_VENDOR_GenuineIntel_edx 0x49656e69 - enum x86_intercept_stage { X86_ICTP_NONE = 0, /* Allow zero-init to not match anything */ X86_ICPT_PRE_EXCEPT, diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 3741c65..d2ab1ff 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -144,6 +144,23 @@ enum { #include <asm/kvm_emulate.h> +/* CPUID vendors */ +#define X86EMUL_CPUID_VENDOR_AuthenticAMD_ebx 0x68747541 +#define X86EMUL_CPUID_VENDOR_AuthenticAMD_ecx 0x444d4163 +#define X86EMUL_CPUID_VENDOR_AuthenticAMD_edx 0x69746e65 + +#define X86EMUL_CPUID_VENDOR_AMDisbetterI_ebx 0x69444d41 +#define X86EMUL_CPUID_VENDOR_AMDisbetterI_ecx 0x21726574 +#define X86EMUL_CPUID_VENDOR_AMDisbetterI_edx 0x74656273 + +#define X86EMUL_CPUID_VENDOR_GenuineIntel_ebx 0x756e6547 +#define X86EMUL_CPUID_VENDOR_GenuineIntel_ecx 0x6c65746e +#define X86EMUL_CPUID_VENDOR_GenuineIntel_edx 0x49656e69 + +void kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx); +#define emul_to_vcpu(ctxt) \ + container_of(ctxt, struct kvm_vcpu, arch.emulate_ctxt) + #define KVM_NR_MEM_OBJS 40 #define KVM_NR_DB_REGS 4 @@ -942,6 +959,17 @@ static inline unsigned long read_msr(unsigned long msr) } #endif +static inline bool vendor_intel(struct kvm_vcpu *vcpu) +{ + u32 eax, ebx, ecx, edx; + + eax = ecx = 0; + kvm_cpuid(vcpu, &eax, &ebx, &ecx, &edx); + return ebx == X86EMUL_CPUID_VENDOR_GenuineIntel_ebx + && ecx == X86EMUL_CPUID_VENDOR_GenuineIntel_ecx + && edx == X86EMUL_CPUID_VENDOR_GenuineIntel_edx; +} + static inline u32 get_rdx_init_val(void) { return 0x600; /* P6 family */ diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 8db0010..dfa28a3 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -2280,17 +2280,6 @@ setup_syscalls_segments(struct x86_emulate_ctxt *ctxt, ss->avl = 0; } -static bool vendor_intel(struct x86_emulate_ctxt *ctxt) -{ - u32 eax, ebx, ecx, edx; - - eax = ecx = 0; - ctxt->ops->get_cpuid(ctxt, &eax, &ebx, &ecx, &edx); - return ebx == X86EMUL_CPUID_VENDOR_GenuineIntel_ebx - && ecx == X86EMUL_CPUID_VENDOR_GenuineIntel_ecx - && edx == X86EMUL_CPUID_VENDOR_GenuineIntel_edx; -} - static bool em_syscall_is_enabled(struct x86_emulate_ctxt *ctxt) { const struct x86_emulate_ops *ops = ctxt->ops; @@ -2396,6 +2385,8 @@ static int em_syscall(struct x86_emulate_ctxt *ctxt) static int em_sysenter(struct x86_emulate_ctxt *ctxt) { const struct x86_emulate_ops *ops = ctxt->ops; + struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); + struct desc_struct cs, ss; u64 msr_data; u16 cs_sel, ss_sel; @@ -2411,7 +2402,7 @@ static int em_sysenter(struct x86_emulate_ctxt *ctxt) * mode). */ if ((ctxt->mode == X86EMUL_MODE_PROT32) && (efer & EFER_LMA) - && !vendor_intel(ctxt)) + && !vendor_intel(vcpu)) return emulate_ud(ctxt); /* XXX sysenter/sysexit have not been tested in 64bit mode. diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 094b5d9..2fb4faf 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -68,9 +68,6 @@ #define KVM_MAX_MCE_BANKS 32 #define KVM_MCE_CAP_SUPPORTED (MCG_CTL_P | MCG_SER_P) -#define emul_to_vcpu(ctxt) \ - container_of(ctxt, struct kvm_vcpu, arch.emulate_ctxt) - /* EFER defaults: * - enable syscall per default because its emulated by KVM * - enable LME and LMA per default on 64 bit KVM -- 1.8.1.4 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] kvm: make vendor_intel a generic function 2013-05-29 21:40 ` [PATCH 1/2] kvm: make vendor_intel a generic function Bandan Das @ 2013-05-30 5:39 ` Paolo Bonzini 2013-05-30 6:07 ` Gleb Natapov 0 siblings, 1 reply; 7+ messages in thread From: Paolo Bonzini @ 2013-05-30 5:39 UTC (permalink / raw) To: Bandan Das; +Cc: kvm, Gleb Natapov, Marcelo Tosatti Il 29/05/2013 23:40, Bandan Das ha scritto: > Make vendor_intel generic so that functions in x86.c > can use it. > > Signed-off-by: Bandan Das <bsd@redhat.com> > --- > arch/x86/include/asm/kvm_emulate.h | 13 ------------- > arch/x86/include/asm/kvm_host.h | 28 ++++++++++++++++++++++++++++ > arch/x86/kvm/emulate.c | 15 +++------------ > arch/x86/kvm/x86.c | 3 --- > 4 files changed, 31 insertions(+), 28 deletions(-) > > diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h > index 15f960c..611a55f 100644 > --- a/arch/x86/include/asm/kvm_emulate.h > +++ b/arch/x86/include/asm/kvm_emulate.h > @@ -319,19 +319,6 @@ struct x86_emulate_ctxt { > #define REPE_PREFIX 0xf3 > #define REPNE_PREFIX 0xf2 > > -/* CPUID vendors */ > -#define X86EMUL_CPUID_VENDOR_AuthenticAMD_ebx 0x68747541 > -#define X86EMUL_CPUID_VENDOR_AuthenticAMD_ecx 0x444d4163 > -#define X86EMUL_CPUID_VENDOR_AuthenticAMD_edx 0x69746e65 > - > -#define X86EMUL_CPUID_VENDOR_AMDisbetterI_ebx 0x69444d41 > -#define X86EMUL_CPUID_VENDOR_AMDisbetterI_ecx 0x21726574 > -#define X86EMUL_CPUID_VENDOR_AMDisbetterI_edx 0x74656273 > - > -#define X86EMUL_CPUID_VENDOR_GenuineIntel_ebx 0x756e6547 > -#define X86EMUL_CPUID_VENDOR_GenuineIntel_ecx 0x6c65746e > -#define X86EMUL_CPUID_VENDOR_GenuineIntel_edx 0x49656e69 > - > enum x86_intercept_stage { > X86_ICTP_NONE = 0, /* Allow zero-init to not match anything */ > X86_ICPT_PRE_EXCEPT, > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index 3741c65..d2ab1ff 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -144,6 +144,23 @@ enum { > > #include <asm/kvm_emulate.h> > > +/* CPUID vendors */ > +#define X86EMUL_CPUID_VENDOR_AuthenticAMD_ebx 0x68747541 > +#define X86EMUL_CPUID_VENDOR_AuthenticAMD_ecx 0x444d4163 > +#define X86EMUL_CPUID_VENDOR_AuthenticAMD_edx 0x69746e65 > + > +#define X86EMUL_CPUID_VENDOR_AMDisbetterI_ebx 0x69444d41 > +#define X86EMUL_CPUID_VENDOR_AMDisbetterI_ecx 0x21726574 > +#define X86EMUL_CPUID_VENDOR_AMDisbetterI_edx 0x74656273 > + > +#define X86EMUL_CPUID_VENDOR_GenuineIntel_ebx 0x756e6547 > +#define X86EMUL_CPUID_VENDOR_GenuineIntel_ecx 0x6c65746e > +#define X86EMUL_CPUID_VENDOR_GenuineIntel_edx 0x49656e69 > + > +void kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx); > +#define emul_to_vcpu(ctxt) \ > + container_of(ctxt, struct kvm_vcpu, arch.emulate_ctxt) > + > #define KVM_NR_MEM_OBJS 40 > > #define KVM_NR_DB_REGS 4 > @@ -942,6 +959,17 @@ static inline unsigned long read_msr(unsigned long msr) > } > #endif > > +static inline bool vendor_intel(struct kvm_vcpu *vcpu) > +{ > + u32 eax, ebx, ecx, edx; > + > + eax = ecx = 0; > + kvm_cpuid(vcpu, &eax, &ebx, &ecx, &edx); > + return ebx == X86EMUL_CPUID_VENDOR_GenuineIntel_ebx > + && ecx == X86EMUL_CPUID_VENDOR_GenuineIntel_ecx > + && edx == X86EMUL_CPUID_VENDOR_GenuineIntel_edx; > +} > + > static inline u32 get_rdx_init_val(void) > { > return 0x600; /* P6 family */ > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > index 8db0010..dfa28a3 100644 > --- a/arch/x86/kvm/emulate.c > +++ b/arch/x86/kvm/emulate.c > @@ -2280,17 +2280,6 @@ setup_syscalls_segments(struct x86_emulate_ctxt *ctxt, > ss->avl = 0; > } > > -static bool vendor_intel(struct x86_emulate_ctxt *ctxt) > -{ > - u32 eax, ebx, ecx, edx; > - > - eax = ecx = 0; > - ctxt->ops->get_cpuid(ctxt, &eax, &ebx, &ecx, &edx); > - return ebx == X86EMUL_CPUID_VENDOR_GenuineIntel_ebx > - && ecx == X86EMUL_CPUID_VENDOR_GenuineIntel_ecx > - && edx == X86EMUL_CPUID_VENDOR_GenuineIntel_edx; > -} > - > static bool em_syscall_is_enabled(struct x86_emulate_ctxt *ctxt) > { > const struct x86_emulate_ops *ops = ctxt->ops; > @@ -2396,6 +2385,8 @@ static int em_syscall(struct x86_emulate_ctxt *ctxt) > static int em_sysenter(struct x86_emulate_ctxt *ctxt) > { > const struct x86_emulate_ops *ops = ctxt->ops; > + struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); Unfortunately, this is not acceptable. The emulator is not supposed to know about the vcpu. Everything has to go through the context; in principle, the emulator should be usable outside of KVM. I would just duplicate the code in kvm_guest_vcpu_model (perhaps you can rename it to kvm_cpuid_get_intel_model or something like that; having both "guest" and "vcpu" in the name is a pleonasm :)). Paolo > + > struct desc_struct cs, ss; > u64 msr_data; > u16 cs_sel, ss_sel; > @@ -2411,7 +2402,7 @@ static int em_sysenter(struct x86_emulate_ctxt *ctxt) > * mode). > */ > if ((ctxt->mode == X86EMUL_MODE_PROT32) && (efer & EFER_LMA) > - && !vendor_intel(ctxt)) > + && !vendor_intel(vcpu)) > return emulate_ud(ctxt); > > /* XXX sysenter/sysexit have not been tested in 64bit mode. > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 094b5d9..2fb4faf 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -68,9 +68,6 @@ > #define KVM_MAX_MCE_BANKS 32 > #define KVM_MCE_CAP_SUPPORTED (MCG_CTL_P | MCG_SER_P) > > -#define emul_to_vcpu(ctxt) \ > - container_of(ctxt, struct kvm_vcpu, arch.emulate_ctxt) > - > /* EFER defaults: > * - enable syscall per default because its emulated by KVM > * - enable LME and LMA per default on 64 bit KVM > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] kvm: make vendor_intel a generic function 2013-05-30 5:39 ` Paolo Bonzini @ 2013-05-30 6:07 ` Gleb Natapov 2013-05-30 6:32 ` Paolo Bonzini 0 siblings, 1 reply; 7+ messages in thread From: Gleb Natapov @ 2013-05-30 6:07 UTC (permalink / raw) To: Paolo Bonzini; +Cc: Bandan Das, kvm, Marcelo Tosatti On Thu, May 30, 2013 at 07:39:01AM +0200, Paolo Bonzini wrote: > Il 29/05/2013 23:40, Bandan Das ha scritto: > > Make vendor_intel generic so that functions in x86.c > > can use it. > > > > Signed-off-by: Bandan Das <bsd@redhat.com> > > --- > > arch/x86/include/asm/kvm_emulate.h | 13 ------------- > > arch/x86/include/asm/kvm_host.h | 28 ++++++++++++++++++++++++++++ > > arch/x86/kvm/emulate.c | 15 +++------------ > > arch/x86/kvm/x86.c | 3 --- > > 4 files changed, 31 insertions(+), 28 deletions(-) > > > > diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h > > index 15f960c..611a55f 100644 > > --- a/arch/x86/include/asm/kvm_emulate.h > > +++ b/arch/x86/include/asm/kvm_emulate.h > > @@ -319,19 +319,6 @@ struct x86_emulate_ctxt { > > #define REPE_PREFIX 0xf3 > > #define REPNE_PREFIX 0xf2 > > > > -/* CPUID vendors */ > > -#define X86EMUL_CPUID_VENDOR_AuthenticAMD_ebx 0x68747541 > > -#define X86EMUL_CPUID_VENDOR_AuthenticAMD_ecx 0x444d4163 > > -#define X86EMUL_CPUID_VENDOR_AuthenticAMD_edx 0x69746e65 > > - > > -#define X86EMUL_CPUID_VENDOR_AMDisbetterI_ebx 0x69444d41 > > -#define X86EMUL_CPUID_VENDOR_AMDisbetterI_ecx 0x21726574 > > -#define X86EMUL_CPUID_VENDOR_AMDisbetterI_edx 0x74656273 > > - > > -#define X86EMUL_CPUID_VENDOR_GenuineIntel_ebx 0x756e6547 > > -#define X86EMUL_CPUID_VENDOR_GenuineIntel_ecx 0x6c65746e > > -#define X86EMUL_CPUID_VENDOR_GenuineIntel_edx 0x49656e69 > > - > > enum x86_intercept_stage { > > X86_ICTP_NONE = 0, /* Allow zero-init to not match anything */ > > X86_ICPT_PRE_EXCEPT, > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > > index 3741c65..d2ab1ff 100644 > > --- a/arch/x86/include/asm/kvm_host.h > > +++ b/arch/x86/include/asm/kvm_host.h > > @@ -144,6 +144,23 @@ enum { > > > > #include <asm/kvm_emulate.h> > > > > +/* CPUID vendors */ > > +#define X86EMUL_CPUID_VENDOR_AuthenticAMD_ebx 0x68747541 > > +#define X86EMUL_CPUID_VENDOR_AuthenticAMD_ecx 0x444d4163 > > +#define X86EMUL_CPUID_VENDOR_AuthenticAMD_edx 0x69746e65 > > + > > +#define X86EMUL_CPUID_VENDOR_AMDisbetterI_ebx 0x69444d41 > > +#define X86EMUL_CPUID_VENDOR_AMDisbetterI_ecx 0x21726574 > > +#define X86EMUL_CPUID_VENDOR_AMDisbetterI_edx 0x74656273 > > + > > +#define X86EMUL_CPUID_VENDOR_GenuineIntel_ebx 0x756e6547 > > +#define X86EMUL_CPUID_VENDOR_GenuineIntel_ecx 0x6c65746e > > +#define X86EMUL_CPUID_VENDOR_GenuineIntel_edx 0x49656e69 > > + > > +void kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx); > > +#define emul_to_vcpu(ctxt) \ > > + container_of(ctxt, struct kvm_vcpu, arch.emulate_ctxt) > > + > > #define KVM_NR_MEM_OBJS 40 > > > > #define KVM_NR_DB_REGS 4 > > @@ -942,6 +959,17 @@ static inline unsigned long read_msr(unsigned long msr) > > } > > #endif > > > > +static inline bool vendor_intel(struct kvm_vcpu *vcpu) > > +{ > > + u32 eax, ebx, ecx, edx; > > + > > + eax = ecx = 0; > > + kvm_cpuid(vcpu, &eax, &ebx, &ecx, &edx); > > + return ebx == X86EMUL_CPUID_VENDOR_GenuineIntel_ebx > > + && ecx == X86EMUL_CPUID_VENDOR_GenuineIntel_ecx > > + && edx == X86EMUL_CPUID_VENDOR_GenuineIntel_edx; > > +} > > + > > static inline u32 get_rdx_init_val(void) > > { > > return 0x600; /* P6 family */ > > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > > index 8db0010..dfa28a3 100644 > > --- a/arch/x86/kvm/emulate.c > > +++ b/arch/x86/kvm/emulate.c > > @@ -2280,17 +2280,6 @@ setup_syscalls_segments(struct x86_emulate_ctxt *ctxt, > > ss->avl = 0; > > } > > > > -static bool vendor_intel(struct x86_emulate_ctxt *ctxt) > > -{ > > - u32 eax, ebx, ecx, edx; > > - > > - eax = ecx = 0; > > - ctxt->ops->get_cpuid(ctxt, &eax, &ebx, &ecx, &edx); > > - return ebx == X86EMUL_CPUID_VENDOR_GenuineIntel_ebx > > - && ecx == X86EMUL_CPUID_VENDOR_GenuineIntel_ecx > > - && edx == X86EMUL_CPUID_VENDOR_GenuineIntel_edx; > > -} > > - > > static bool em_syscall_is_enabled(struct x86_emulate_ctxt *ctxt) > > { > > const struct x86_emulate_ops *ops = ctxt->ops; > > @@ -2396,6 +2385,8 @@ static int em_syscall(struct x86_emulate_ctxt *ctxt) > > static int em_sysenter(struct x86_emulate_ctxt *ctxt) > > { > > const struct x86_emulate_ops *ops = ctxt->ops; > > + struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); > > Unfortunately, this is not acceptable. The emulator is not supposed to > know about the vcpu. Everything has to go through the context; in > principle, the emulator should be usable outside of KVM. > > I would just duplicate the code in kvm_guest_vcpu_model (perhaps you can > rename it to kvm_cpuid_get_intel_model or something like that; having > both "guest" and "vcpu" in the name is a pleonasm :)). > I thought having inline function that gets &eax, &ebx, &ecx, &edx as a parameter and returns a vendor. > Paolo > > > + > > struct desc_struct cs, ss; > > u64 msr_data; > > u16 cs_sel, ss_sel; > > @@ -2411,7 +2402,7 @@ static int em_sysenter(struct x86_emulate_ctxt *ctxt) > > * mode). > > */ > > if ((ctxt->mode == X86EMUL_MODE_PROT32) && (efer & EFER_LMA) > > - && !vendor_intel(ctxt)) > > + && !vendor_intel(vcpu)) > > return emulate_ud(ctxt); > > > > /* XXX sysenter/sysexit have not been tested in 64bit mode. > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > index 094b5d9..2fb4faf 100644 > > --- a/arch/x86/kvm/x86.c > > +++ b/arch/x86/kvm/x86.c > > @@ -68,9 +68,6 @@ > > #define KVM_MAX_MCE_BANKS 32 > > #define KVM_MCE_CAP_SUPPORTED (MCG_CTL_P | MCG_SER_P) > > > > -#define emul_to_vcpu(ctxt) \ > > - container_of(ctxt, struct kvm_vcpu, arch.emulate_ctxt) > > - > > /* EFER defaults: > > * - enable syscall per default because its emulated by KVM > > * - enable LME and LMA per default on 64 bit KVM > > > -- Gleb. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] kvm: make vendor_intel a generic function 2013-05-30 6:07 ` Gleb Natapov @ 2013-05-30 6:32 ` Paolo Bonzini 2013-06-04 16:10 ` Bandan Das 0 siblings, 1 reply; 7+ messages in thread From: Paolo Bonzini @ 2013-05-30 6:32 UTC (permalink / raw) To: Gleb Natapov, Bandan Das; +Cc: kvm, Marcelo Tosatti Il 30/05/2013 08:07, Gleb Natapov ha scritto: >> > Unfortunately, this is not acceptable. The emulator is not supposed to >> > know about the vcpu. Everything has to go through the context; in >> > principle, the emulator should be usable outside of KVM. >> > >> > I would just duplicate the code in kvm_guest_vcpu_model (perhaps you can >> > rename it to kvm_cpuid_get_intel_model or something like that; having >> > both "guest" and "vcpu" in the name is a pleonasm :)). > > I thought having inline function that gets &eax, &ebx, &ecx, &edx as a > parameter and returns a vendor. That could work too. Bandan, whatever looks nicer to you. :) Paolo ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] kvm: make vendor_intel a generic function 2013-05-30 6:32 ` Paolo Bonzini @ 2013-06-04 16:10 ` Bandan Das 0 siblings, 0 replies; 7+ messages in thread From: Bandan Das @ 2013-06-04 16:10 UTC (permalink / raw) To: Paolo Bonzini; +Cc: Gleb Natapov, kvm, Marcelo Tosatti Paolo Bonzini <pbonzini@redhat.com> writes: > Il 30/05/2013 08:07, Gleb Natapov ha scritto: >>> > Unfortunately, this is not acceptable. The emulator is not supposed to >>> > know about the vcpu. Everything has to go through the context; in >>> > principle, the emulator should be usable outside of KVM. >>> > >>> > I would just duplicate the code in kvm_guest_vcpu_model (perhaps you can >>> > rename it to kvm_cpuid_get_intel_model or something like that; having >>> > both "guest" and "vcpu" in the name is a pleonasm :)). >> >> I thought having inline function that gets &eax, &ebx, &ecx, &edx as a >> parameter and returns a vendor. > > That could work too. Bandan, whatever looks nicer to you. :) OK, I posted a v2. I changed vendor_intel() to just do the checking and the call to cpuid happens outside the function now through whatever method is appropriate. As a cleanup work, I think there should be a corresponding vendor_amd() too for the AMD related checks that happen in emulate.c. I will send a separate change for it. Bandan > Paolo ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] kvm: x86: emulate MSR_PLATFORM_INFO 2013-05-29 21:40 [PATCH 0/2] kvm: x86: Emulate MSR_PLATFORM_INFO Bandan Das 2013-05-29 21:40 ` [PATCH 1/2] kvm: make vendor_intel a generic function Bandan Das @ 2013-05-29 21:40 ` Bandan Das 1 sibling, 0 replies; 7+ messages in thread From: Bandan Das @ 2013-05-29 21:40 UTC (permalink / raw) To: kvm; +Cc: Gleb Natapov, Paolo Bonzini, Marcelo Tosatti, Bandan Das To emulate MSR_PLATFORM_INFO, we divide guest virtual_tsc_khz by the base clock - which is guest CPU model dependent. The relevant bits in this emulated MSR are : Max Non-Turbo Ratio (15:8) - virtual_tsc_khz/bclk Max Effi Ratio (47:40) - virtual_tsc_khz/bclk Prog Ratio Limit for Trubo (28) - 0 Prog TDC-TDP Limit for Turbo (29) - 0 Signed-off-by: Bandan Das <bsd@redhat.com> --- arch/x86/include/uapi/asm/msr-index.h | 2 ++ arch/x86/kvm/cpuid.c | 18 +++++++++++++ arch/x86/kvm/cpuid.h | 16 ++++++++++++ arch/x86/kvm/x86.c | 48 +++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+) diff --git a/arch/x86/include/uapi/asm/msr-index.h b/arch/x86/include/uapi/asm/msr-index.h index 2af848d..b0268d5 100644 --- a/arch/x86/include/uapi/asm/msr-index.h +++ b/arch/x86/include/uapi/asm/msr-index.h @@ -331,6 +331,8 @@ #define MSR_IA32_MISC_ENABLE 0x000001a0 +#define MSR_IA32_PLATFORM_INFO 0x000000ce + #define MSR_IA32_TEMPERATURE_TARGET 0x000001a2 #define MSR_IA32_ENERGY_PERF_BIAS 0x000001b0 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index a20ecb5..04cb30c 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -608,6 +608,24 @@ struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu, } EXPORT_SYMBOL_GPL(kvm_find_cpuid_entry); +u8 kvm_guest_vcpu_model(struct kvm_vcpu *vcpu) +{ + struct kvm_cpuid_entry2 *best; + u8 cpuid_model, cpuid_extmodel; + + if (!vendor_intel(vcpu)) + return CPUID_MODEL_UNKNOWN; + + best = kvm_find_cpuid_entry(vcpu, 1, 0); + + cpuid_model = (best->eax >> 4) & 0xf; + cpuid_extmodel = (best->eax >> 16) & 0xf; + + cpuid_model += (cpuid_extmodel << 4); + + return cpuid_model; +} + int cpuid_maxphyaddr(struct kvm_vcpu *vcpu) { struct kvm_cpuid_entry2 *best; diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h index b7fd079..4fad70d 100644 --- a/arch/x86/kvm/cpuid.h +++ b/arch/x86/kvm/cpuid.h @@ -3,6 +3,21 @@ #include "x86.h" +#define MODEL_NEHALEM_CLARKSFIELD 0x1e /* Core i7 and Ex BCLK: 133Mhz */ +#define MODEL_NEHALEM_BLOOMFIELD 0x1a /* Core i7 Xeon 3000 BCLK: 133 Mhz */ +#define MODEL_NEHALEM_EX 0x2e /* Core i7 and i5 Nehalem BCLK: 133 Mhz */ +#define MODEL_WESTMERE_ARRANDALE 0x25 /* Celeron/Pentium/Core i3/i5/i7 BCLK: 133 Mhz */ +#define MODEL_WESTMERE_EX 0x2f /* Xeon E7 BCLK: 133 Mhz */ +#define MODEL_WESTMERE_GULFTOWN 0x2c /* Core i7 Xeon 3000 BCLK: 133 Mhz */ +#define MODEL_SANDYBRIDGE_SANDY 0x2a /* Core/Celeron/Pentium/Xeon BCLK: 133 Mhz */ +#define MODEL_SANDYBRIDGE_E 0x2d /* Core i7 and Ex BCLK: 100 Mhz */ +#define MODEL_IVYBRIDGE_IVY 0x3a /* Core i3/i5/i7 (Ex) and Xeon E3 BCLK: 100 Mhz */ +#define MODEL_HASWELL_HASWELL 0x3c /* BCLK: 100 Mhz */ +#define CPUID_MODEL_UNKNOWN 0x0 /* Everything else */ + +#define BCLK_133_DEFAULT (133 * 1000) +#define BCLK_100_DEFAULT (100 * 1000) + void kvm_update_cpuid(struct kvm_vcpu *vcpu); struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu, u32 function, u32 index); @@ -18,6 +33,7 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid, struct kvm_cpuid_entry2 __user *entries); void kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx); +u8 kvm_guest_vcpu_model(struct kvm_vcpu *vcpu); static inline bool guest_cpuid_has_xsave(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 2fb4faf..7d06729 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -236,6 +236,49 @@ void kvm_set_shared_msr(unsigned slot, u64 value, u64 mask) } EXPORT_SYMBOL_GPL(kvm_set_shared_msr); +static u64 kvm_get_platform_info(struct kvm_vcpu *vcpu) +{ + u8 cpumodel; + u32 bclk; + + /* + * Programmable Ratio Limit for Turbo Mode (bit 28): 0 + * Programmable TDC-TDP Limit for Turbo Mode (bit 29): 0 + */ + u64 platform_info = 0, max_nonturbo_ratio = 0, max_effi_ratio = 0; + + cpumodel = kvm_guest_vcpu_model(vcpu); + + switch (cpumodel) { + case MODEL_NEHALEM_CLARKSFIELD: + case MODEL_NEHALEM_BLOOMFIELD: + case MODEL_NEHALEM_EX: + case MODEL_WESTMERE_ARRANDALE: + case MODEL_WESTMERE_GULFTOWN: + case MODEL_WESTMERE_EX: + bclk = BCLK_133_DEFAULT; + break; + case MODEL_SANDYBRIDGE_SANDYBRIDGE: + case MODEL_SANDYBRIDGE_E: + case MODEL_IVYBRIDGE_IVYBRIDGE: + case MODEL_HASWELL_HASWELL: + bclk = BCLK_100_DEFAULT; + break; + default: + bclk = 0; + break; + } + + if (bclk) { + max_nonturbo_ratio = max_effi_ratio + = (u8)(vcpu->arch.virtual_tsc_khz / bclk); + platform_info = (max_effi_ratio << 40) + | (max_nonturbo_ratio << 8); + } + + return platform_info; +} + static void drop_user_return_notifiers(void *ignore) { unsigned int cpu = smp_processor_id(); @@ -1971,6 +2014,8 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) case MSR_IA32_MISC_ENABLE: vcpu->arch.ia32_misc_enable_msr = data; break; + case MSR_IA32_PLATFORM_INFO: + return 1; case MSR_KVM_WALL_CLOCK_NEW: case MSR_KVM_WALL_CLOCK: vcpu->kvm->arch.wall_clock = data; @@ -2336,6 +2381,9 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) case MSR_IA32_MISC_ENABLE: data = vcpu->arch.ia32_misc_enable_msr; break; + case MSR_IA32_PLATFORM_INFO: + data = kvm_get_platform_info(vcpu); + break; case MSR_IA32_PERF_STATUS: /* TSC increment by tick */ data = 1000ULL; -- 1.8.1.4 ^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-06-04 16:10 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-05-29 21:40 [PATCH 0/2] kvm: x86: Emulate MSR_PLATFORM_INFO Bandan Das 2013-05-29 21:40 ` [PATCH 1/2] kvm: make vendor_intel a generic function Bandan Das 2013-05-30 5:39 ` Paolo Bonzini 2013-05-30 6:07 ` Gleb Natapov 2013-05-30 6:32 ` Paolo Bonzini 2013-06-04 16:10 ` Bandan Das 2013-05-29 21:40 ` [PATCH 2/2] kvm: x86: emulate MSR_PLATFORM_INFO Bandan Das
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.