[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RESEND v1 3/7] x86: add intel proecessor trace support for cpuid
This patch add Intel processor trace support for cpuid handling. Signed-off-by: Luwei Kang <luwei.kang@xxxxxxxxx> --- tools/libxc/xc_cpuid_x86.c | 12 ++++++++++-- xen/arch/x86/cpuid.c | 22 ++++++++++++++++++++++ xen/arch/x86/domctl.c | 4 ++++ xen/include/asm-x86/cpufeature.h | 1 + xen/include/asm-x86/cpuid.h | 12 +++++++++++- xen/include/public/arch-x86/cpufeatureset.h | 1 + 6 files changed, 49 insertions(+), 3 deletions(-) diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c index 25b922e..c39a9cf 100644 --- a/tools/libxc/xc_cpuid_x86.c +++ b/tools/libxc/xc_cpuid_x86.c @@ -38,7 +38,7 @@ enum { #define clear_feature(idx, dst) ((dst) &= ~bitmaskof(idx)) #define set_feature(idx, dst) ((dst) |= bitmaskof(idx)) -#define DEF_MAX_BASE 0x0000000du +#define DEF_MAX_BASE 0x00000014u #define DEF_MAX_INTELEXT 0x80000008u #define DEF_MAX_AMDEXT 0x8000001cu @@ -471,6 +471,7 @@ static void xc_cpuid_hvm_policy(xc_interface *xch, case 0x00000002: /* Intel cache info (dumped by AMD policy) */ case 0x00000004: /* Intel cache info (dumped by AMD policy) */ case 0x0000000a: /* Architectural Performance Monitor Features */ + case 0x00000014: /* Intel Processor Trace Features */ case 0x80000002: /* Processor name string */ case 0x80000003: /* ... continued */ case 0x80000004: /* ... continued */ @@ -757,12 +758,19 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, continue; } + if ( input[0] == 0x14 ) + { + input[1]++; + if ( input[1] == 1 ) + continue; + } + input[0]++; if ( !(input[0] & 0x80000000u) && (input[0] > base_max ) ) input[0] = 0x80000000u; input[1] = XEN_CPUID_INPUT_UNUSED; - if ( (input[0] == 4) || (input[0] == 7) ) + if ( (input[0] == 4) || (input[0] == 7) || (input[0] == 0x14) ) input[1] = 0; else if ( input[0] == 0xd ) input[1] = 1; /* Xen automatically calculates almost everything. */ diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index 5ee82d3..c3d56fd 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -9,6 +9,7 @@ #include <asm/paging.h> #include <asm/processor.h> #include <asm/xstate.h> +#include <asm/intel_pt.h> const uint32_t known_features[] = INIT_KNOWN_FEATURES; const uint32_t special_features[] = INIT_SPECIAL_FEATURES; @@ -487,7 +488,19 @@ void recalculate_cpuid_policy(struct domain *d) __clear_bit(X86_FEATURE_VMX, max_fs); __clear_bit(X86_FEATURE_SVM, max_fs); } + + /* + * Hide Intel Processor trace feature when hardware not support + * PT-VMX or intel_pt option is disabled. + */ + if ( !opt_intel_pt ) + { + __clear_bit(X86_FEATURE_INTEL_PT, max_fs); + zero_leaves(p->intel_pt.raw, 0, ARRAY_SIZE(p->intel_pt.raw) - 1); + } } + else + zero_leaves(p->intel_pt.raw, 0, ARRAY_SIZE(p->intel_pt.raw) - 1); /* * Allow the toolstack to set HTT, X2APIC and CMP_LEGACY. These bits @@ -634,6 +647,15 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf, *res = p->feat.raw[subleaf]; break; + case 0x14: + ASSERT(p->intel_pt.max_subleaf < ARRAY_SIZE(p->intel_pt.raw)); + if ( subleaf > min_t(uint32_t, p->intel_pt.max_subleaf, + ARRAY_SIZE(p->intel_pt.raw) - 1) ) + return; + + *res = p->intel_pt.raw[subleaf]; + break; + case XSTATE_CPUID: if ( !p->basic.xsave || subleaf >= ARRAY_SIZE(p->xstate.raw) ) return; diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 5973d9f..493cca4 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -101,6 +101,10 @@ static int update_domain_cpuid_info(struct domain *d, p->feat.raw[ctl->input[1]] = leaf; break; + case 0x14: + p->intel_pt.raw[ctl->input[1]] = leaf; + break; + case XSTATE_CPUID: p->xstate.raw[ctl->input[1]] = leaf; break; diff --git a/xen/include/asm-x86/cpufeature.h b/xen/include/asm-x86/cpufeature.h index 84cc51d..8956667 100644 --- a/xen/include/asm-x86/cpufeature.h +++ b/xen/include/asm-x86/cpufeature.h @@ -95,6 +95,7 @@ #define cpu_has_mpx boot_cpu_has(X86_FEATURE_MPX) #define cpu_has_rdseed boot_cpu_has(X86_FEATURE_RDSEED) #define cpu_has_smap boot_cpu_has(X86_FEATURE_SMAP) +#define cpu_has_intel_pt boot_cpu_has(X86_FEATURE_INTEL_PT) #define cpu_has_sha boot_cpu_has(X86_FEATURE_SHA) /* CPUID level 0x80000007.edx */ diff --git a/xen/include/asm-x86/cpuid.h b/xen/include/asm-x86/cpuid.h index d2dd841..39f06aa 100644 --- a/xen/include/asm-x86/cpuid.h +++ b/xen/include/asm-x86/cpuid.h @@ -61,10 +61,11 @@ extern struct cpuidmasks cpuidmask_defaults; /* Whether or not cpuid faulting is available for the current domain. */ DECLARE_PER_CPU(bool, cpuid_faulting_enabled); -#define CPUID_GUEST_NR_BASIC (0xdu + 1) +#define CPUID_GUEST_NR_BASIC (0x14u + 1) #define CPUID_GUEST_NR_FEAT (0u + 1) #define CPUID_GUEST_NR_CACHE (5u + 1) #define CPUID_GUEST_NR_XSTATE (62u + 1) +#define CPUID_GUEST_NR_INTEL_PT (1u + 1) #define CPUID_GUEST_NR_EXTD_INTEL (0x8u + 1) #define CPUID_GUEST_NR_EXTD_AMD (0x1cu + 1) #define CPUID_GUEST_NR_EXTD MAX(CPUID_GUEST_NR_EXTD_INTEL, \ @@ -169,6 +170,15 @@ struct cpuid_policy } comp[CPUID_GUEST_NR_XSTATE]; } xstate; + /* Structured feature leaf: 0x00000014[xx] */ + union { + struct cpuid_leaf raw[CPUID_GUEST_NR_INTEL_PT]; + struct { + /* Subleaf 0. */ + uint32_t max_subleaf; + }; + } intel_pt; + /* Extended leaves: 0x800000xx */ union { struct cpuid_leaf raw[CPUID_GUEST_NR_EXTD]; diff --git a/xen/include/public/arch-x86/cpufeatureset.h b/xen/include/public/arch-x86/cpufeatureset.h index be6da8e..c35b061 100644 --- a/xen/include/public/arch-x86/cpufeatureset.h +++ b/xen/include/public/arch-x86/cpufeatureset.h @@ -215,6 +215,7 @@ XEN_CPUFEATURE(SMAP, 5*32+20) /*S Supervisor Mode Access Prevention */ XEN_CPUFEATURE(AVX512IFMA, 5*32+21) /*A AVX-512 Integer Fused Multiply Add */ XEN_CPUFEATURE(CLFLUSHOPT, 5*32+23) /*A CLFLUSHOPT instruction */ XEN_CPUFEATURE(CLWB, 5*32+24) /*A CLWB instruction */ +XEN_CPUFEATURE(INTEL_PT, 5*32+25) /*H Intel Processor Trace */ XEN_CPUFEATURE(AVX512PF, 5*32+26) /*A AVX-512 Prefetch Instructions */ XEN_CPUFEATURE(AVX512ER, 5*32+27) /*A AVX-512 Exponent & Reciprocal Instrs */ XEN_CPUFEATURE(AVX512CD, 5*32+28) /*A AVX-512 Conflict Detection Instrs */ -- 1.8.3.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |