[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v3 1/4] xen/libxc: Allow changes to hypervisor CPUID leaf from config file
Currently only "real" cpuid leaves can be overwritten by users via 'cpuid' option in the configuration file. This patch provides ability to do the same for hypervisor leaves (but for now only 0x40000000 is allowed). Signed-off-by: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx> --- tools/libxc/xc_cpuid_x86.c | 31 ++++++++++++++++++++++++++----- xen/arch/x86/domain.c | 19 ++++++++++++++++--- xen/arch/x86/traps.c | 3 +++ xen/include/asm-x86/domain.h | 7 +++++++ 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c index bbbf9b8..4920c7e 100644 --- a/tools/libxc/xc_cpuid_x86.c +++ b/tools/libxc/xc_cpuid_x86.c @@ -33,6 +33,8 @@ #define DEF_MAX_INTELEXT 0x80000008u #define DEF_MAX_AMDEXT 0x8000001cu +#define IS_HYPERVISOR_LEAF(idx) (((idx) & 0xffff0000) == 0x40000000) + static int hypervisor_is_64bit(xc_interface *xch) { xen_capabilities_info_t xen_caps = ""; @@ -43,22 +45,29 @@ static int hypervisor_is_64bit(xc_interface *xch) static void cpuid(const unsigned int *input, unsigned int *regs) { unsigned int count = (input[1] == XEN_CPUID_INPUT_UNUSED) ? 0 : input[1]; + uint8_t is_hyp = IS_HYPERVISOR_LEAF(input[0]); #ifdef __i386__ /* Use the stack to avoid reg constraint failures with some gcc flags */ asm ( "push %%ebx; push %%edx\n\t" - "cpuid\n\t" + "testb $0xff,%5\n\t" + "jz 1f\n\t" + XEN_EMULATE_PREFIX + "1: cpuid\n\t" "mov %%ebx,4(%4)\n\t" "mov %%edx,12(%4)\n\t" "pop %%edx; pop %%ebx\n\t" : "=a" (regs[0]), "=c" (regs[2]) - : "0" (input[0]), "1" (count), "S" (regs) + : "0" (input[0]), "1" (count), "S" (regs), "m" (is_hyp) : "memory" ); #else asm ( - "cpuid" + "testb $0xff,%6\n\t" + "jz 1f\n\t" + XEN_EMULATE_PREFIX + "1: cpuid" : "=a" (regs[0]), "=b" (regs[1]), "=c" (regs[2]), "=d" (regs[3]) - : "0" (input[0]), "2" (count) ); + : "0" (input[0]), "2" (count), "m" (is_hyp) ); #endif } @@ -555,6 +564,15 @@ static int xc_cpuid_policy( { xc_dominfo_t info; + if ( IS_HYPERVISOR_LEAF(input[0]) ) + { + /* Only leaf 1 can be modified */ + if ( input[0] == 0x40000000 ) + return 0; + else + return -EACCES; + } + if ( xc_domain_getinfo(xch, domid, 1, &info) == 0 ) return -EINVAL; @@ -757,7 +775,10 @@ int xc_cpuid_set( cpuid(input, regs); memcpy(polregs, regs, sizeof(regs)); - xc_cpuid_policy(xch, domid, input, polregs); + rc = xc_cpuid_policy(xch, domid, input, polregs); + if ( rc ) + return rc; + for ( i = 0; i < 4; i++ ) { diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index c42a079..98e2b5f 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1997,7 +1997,7 @@ void arch_dump_vcpu_info(struct vcpu *v) vpmu_dump(v); } -void domain_cpuid( +bool_t domain_cpuid_exists( struct domain *d, unsigned int input, unsigned int sub_input, @@ -2030,11 +2030,24 @@ void domain_cpuid( !d->disable_migrate && !d->arch.vtsc ) *edx &= ~(1u<<8); /* TSC Invariant */ - return; + return 1; } } - *eax = *ebx = *ecx = *edx = 0; + return 0; +} + +void domain_cpuid( + struct domain *d, + unsigned int input, + unsigned int sub_input, + unsigned int *eax, + unsigned int *ebx, + unsigned int *ecx, + unsigned int *edx) +{ + if ( !domain_cpuid_exists(d, input, sub_input, eax, ebx, ecx, edx) ) + *eax = *ebx = *ecx = *edx = 0; } void vcpu_kick(struct vcpu *v) diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index c462317..e1f39d9 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -690,6 +690,9 @@ int cpuid_hypervisor_leaves( uint32_t idx, uint32_t sub_idx, if ( idx > limit ) return 0; + if ( domain_cpuid_exists(d, base + idx, sub_idx, eax, ebx, ecx, edx) ) + return 1; + switch ( idx ) { case 0: diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h index 49f7c0c..5fd47de 100644 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -471,6 +471,13 @@ unsigned long pv_guest_cr4_fixup(const struct vcpu *, unsigned long guest_cr4); ((c) & ~(X86_CR4_PGE | X86_CR4_PSE | X86_CR4_TSD | \ X86_CR4_OSXSAVE | X86_CR4_SMEP | X86_CR4_FSGSBASE)) +bool_t domain_cpuid_exists(struct domain *d, + unsigned int input, + unsigned int sub_input, + unsigned int *eax, + unsigned int *ebx, + unsigned int *ecx, + unsigned int *edx); void domain_cpuid(struct domain *d, unsigned int input, unsigned int sub_input, -- 1.7.10.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |