Message ID | 1369863613-14781-2-git-send-email-bsd@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
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 > -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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
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(-)