x86/PMU: Xen PMU PV(H) support
v5 cover x86/PMU: Xen PMU PV(H) support
(Resending v5 per Kevin's request)
Here is the fifth version of PV(H) PMU patches.
Changes in v5:
* Dropped patch number 2 ("Stop AMD counters when called from vpmu_save_force()") as no longer needed
* Added patch number 2 that marks context as loaded before PMU registers are loaded. This prevents situation where a PMU interrupt may occur while context is still viewed as not loaded. (This is really a bug fix for exsiting VPMU code)
* Renamed xenpmu.h files to pmu.h
* More careful use of is_pv_domain(), is_hvm_domain(, is_pvh_domain and has_hvm_container_domain(). Also explicitly disabled support for PVH until patch 16 to make distinction between usage of the above macros more clear.
* Added support for disabling VPMU support during runtime.
* Disable VPMUs for non-privileged domains when switching to privileged profiling mode
* Added ARM stub for xen_arch_pmu_t
* Separated vpmu_mode from vpmu_features
* Moved CS register query to make sure we use appropriate query mechanism for various guest types.
* LVTPC is now set from value in shared area, not copied from dom0
* Various code and comments cleanup as suggested by Jan.
Changes in v4:
* Added support for PVH guests:
o changes in pvpmu_init() to accommodate both PV and PVH guests, still in patch 10
o more careful use of is_hvm_domain
o Additional patch (16)
* Moved HVM interrupt handling out of vpmu_do_interrupt() for NMI-safe handling
* Fixed dom0's VCPU selection in privileged mode
* Added a cast in register copy for 32-bit PV guests cpu_user_regs_t in vpmu_do_interrupt. (don't want to expose compat_cpu_user_regs in a public header)
* Renamed public structures by prefixing them with "xen_"
* Added an entry for xenpf_symdata in xlat.lst
* Fixed pv_cpuid check for vpmu-specific cpuid adjustments
* Varios code style fixes
* Eliminated anonymous unions
* Added more verbiage to NMI patch description
Changes in v3:
* Moved PMU MSR banks out from architectural context data structures to allow for future expansion without protocol changes
* PMU interrupts can be either NMIs or regular vector interrupts (the latter is the default)
* Context is now marked as PMU_CACHED by the hypervisor code to avoid certain race conditions with the guest
* Fixed races with PV guest in MSR access handlers
* More Intel VPMU cleanup
* Moved NMI-unsafe code from NMI handler
* Dropped changes to vcpu->is_running
* Added LVTPC apic handling (cached for PV guests)
* Separated privileged profiling mode into a standalone patch
* Separated NMI handling into a standalone patch
Changes in v2:
* Xen symbols are exported as data structure (as opoosed to a set of formatted strings in v1). Even though one symbol per hypercall is returned performance appears to be acceptable: reading whole file from dom0 userland takes on average about twice as long as reading /proc/kallsyms
* More cleanup of Intel VPMU code to simplify publicly exported structures
* There is an architecture-independent and x86-specific public include files (ARM has a stub)
* General cleanup of public include files to make them more presentable (and to make auto doc generation better)
* Setting of vcpu->is_running is now done on ARM in schedule_tail as well (making changes to common/schedule.c architecture-independent). Note that this is not tested since I don't have access to ARM hardware.
* PCPU ID of interrupted processor is now passed to PV guest
The following patch series adds PMU support in Xen for PV(H) guests. There is a companion patchset for Linux kernel. In addition, another set of changes will be provided (later) for userland perf code.
This version has following limitations:
* For accurate profiling of dom0/Xen dom0 VCPUs should be pinned.
* Hypervisor code is only profiled on processors that have running dom0 VCPUs on them.
* No backtrace support.
* Will fail to load under XSM: we ran out of bits in permissions vector and this needs to be fixed separately
A few notes that may help reviewing:
* A shared data structure (xenpmu_data_t) between each PV VPCU and hypervisor CPU is used for passing registers' values as well as PMU state at the time of PMU interrupt.
* PMU interrupts are taken by hypervisor either as NMIs or regular vector interrupts for both HVM and PV(H). The interrupts are sent as NMIs to HVM guests and as virtual interrupts to PV(H) guests
* PV guest's interrupt handler does not read/write PMU MSRs directly. Instead, it accesses xenpmu_data_t and flushes it to HW it before returning.
* PMU mode is controlled at runtime via /sys/hypervisor/pmu/pmu/{pmu_mode,pmu_flags} in addition to 'vpmu' boot option (which is preserved for back compatibility). The following modes are provided:
* disable: VPMU is off
* enable: VPMU is on. Guests can profile themselves, dom0 profiles itself and Xen
* priv_enable: dom0 only profiling. dom0 collects samples for everyone. Sampling in guests is suspended.
* /proc/xen/xensyms file exports hypervisor's symbols to dom0 (similar to /proc/kallsyms)
* VPMU infrastructure is now used for HVM, PV and PVH and therefore has been moved up from hvm subtree
Boris Ostrovsky (17):
common/symbols: Export hypervisor symbols to privileged guest
VPMU: Mark context LOADED before registers are loaded x86/VPMU: Minor VPMU cleanup
intel/VPMU: Clean up Intel VPMU code
x86/VPMU: Handle APIC_LVTPC accesses
intel/VPMU: MSR_CORE_PERF_GLOBAL_CTRL should be initialized to zero x86/VPMU: Add public xenpmu.h
x86/VPMU: Make vpmu not HVM-specific
x86/VPMU: Interface for setting PMU mode and flags x86/VPMU: Initialize PMU for PV guests
x86/VPMU: Add support for PMU register handling on PV guests x86/VPMU: Handle PMU interrupts for PV guests
x86/VPMU: Add privileged PMU mode
x86/VPMU: Save VPMU state for PV guests during context switch x86/VPMU: NMI-based VPMU support
x86/VPMU: Suport for PVH guests
x86/VPMU: Move VPMU files up from hvm/ directory
xen/arch/x86/Makefile | 1 + xen/arch/x86/domain.c | 15 +- xen/arch/x86/hvm/Makefile | 1 - xen/arch/x86/hvm/hvm.c | 3 +- xen/arch/x86/hvm/svm/Makefile | 1 - xen/arch/x86/hvm/svm/svm.c | 6 +- xen/arch/x86/hvm/svm/vpmu.c | 494 ---------------- xen/arch/x86/hvm/vlapic.c | 5 +- xen/arch/x86/hvm/vmx/Makefile | 1 - xen/arch/x86/hvm/vmx/vmcs.c | 55 ++ xen/arch/x86/hvm/vmx/vmx.c | 6 +- xen/arch/x86/hvm/vmx/vpmu_core2.c | 931 ------------------------------ xen/arch/x86/hvm/vpmu.c | 266 --------- xen/arch/x86/oprofile/op_model_ppro.c | 8 +- xen/arch/x86/platform_hypercall.c | 18 + xen/arch/x86/traps.c | 35 +- xen/arch/x86/vpmu.c | 720 +++++++++++++++++++++++ xen/arch/x86/vpmu_amd.c | 509 +++++++++++++++++ xen/arch/x86/vpmu_intel.c | 940 +++++++++++++++++++++++++++++++ xen/arch/x86/x86_64/compat/entry.S | 4 + xen/arch/x86/x86_64/entry.S | 4 + xen/arch/x86/x86_64/platform_hypercall.c | 2 + xen/common/event_channel.c | 1 + xen/common/symbols.c | 50 +- xen/common/vsprintf.c | 2 +- xen/include/asm-x86/domain.h | 2 + xen/include/asm-x86/hvm/vcpu.h | 3 - xen/include/asm-x86/hvm/vmx/vmcs.h | 4 +- xen/include/asm-x86/hvm/vmx/vpmu_core2.h | 51 -- xen/include/asm-x86/hvm/vpmu.h | 104 ---- xen/include/asm-x86/vpmu.h | 99 ++++ xen/include/public/arch-arm.h | 3 + xen/include/public/arch-x86/pmu.h | 63 +++ xen/include/public/platform.h | 16 + xen/include/public/pmu.h | 99 ++++ xen/include/public/xen.h | 2 + xen/include/xen/hypercall.h | 4 + xen/include/xen/softirq.h | 1 + xen/include/xen/symbols.h | 6 +- xen/include/xlat.lst | 1 + 40 files changed, 2661 insertions(+), 1875 deletions(-) delete mode 100644 xen/arch/x86/hvm/svm/vpmu.c delete mode 100644 xen/arch/x86/hvm/vmx/vpmu_core2.c delete mode 100644 xen/arch/x86/hvm/vpmu.c create mode 100644 xen/arch/x86/vpmu.c create mode 100644 xen/arch/x86/vpmu_amd.c create mode 100644 xen/arch/x86/vpmu_intel.c delete mode 100644 xen/include/asm-x86/hvm/vmx/vpmu_core2.h delete mode 100644 xen/include/asm-x86/hvm/vpmu.h create mode 100644 xen/include/asm-x86/vpmu.h create mode 100644 xen/include/public/arch-x86/pmu.h create mode 100644 xen/include/public/pmu.h
Signature · 1 line
1.8.3.1
PATCH RESEND v5 1/17 common/symbols: Export hypervisor symbols to privileged guest
Export Xen's symbols as {<address><type><name>} triplet via new XENPF_get_symbol hypercall
--- xen/arch/x86/platform_hypercall.c | 18 ++++++++++++ xen/arch/x86/x86_64/platform_hypercall.c | 2 ++ xen/common/symbols.c | 50 +++++++++++++++++++++++++++++++- xen/common/vsprintf.c | 2 +- xen/include/public/platform.h | 16 ++++++++++ xen/include/xen/symbols.h | 6 ++-- xen/include/xlat.lst | 1 + 7 files changed, 91 insertions(+), 4 deletions(-)
xen/arch/x86/platform_hypercall.c +18 -0
@@ -23,6 +23,7 @@#include <xen/cpu.h> #include <xen/pmstat.h> #include <xen/irq.h> +#include <xen/symbols.h> #include <asm/current.h> #include <public/platform.h> #include <acpi/cpufreq/processor_perf.h>
@@ -601,6 +602,23 @@ ret_t do_platform_op(XEN_GUEST_HANDLE_PARAM(xen_platform_op_t) u_xenpf_op) }break ; +case XENPF_get_symbol: + { +char name[XEN_KSYM_NAME_LEN +1 ]; +XEN_GUEST_HANDLE (char ) nameh; + +guest_from_compat_handle (nameh, op->u.symdata.name); + + ret =xensyms_read (&op->u.symdata.symnum, &op->u.symdata.type, + &op->u.symdata.address, name); + +if ( !ret &©_to_guest (nameh, name,strlen (name)) ) + ret = -EFAULT ; +if ( !ret &&__copy_field_to_guest (u_xenpf_op, op, u.symdata) ) + ret = -EFAULT ; + } +break ; +default : ret = -ENOSYS ;break ;
xen/arch/x86/x86_64/platform_hypercall.c +2 -0
@@ -32,6 +32,8 @@ CHECK_pf_pcpu_version; CHECK_pf_enter_acpi_sleep;#undef xen_pf_enter_acpi_sleep +#define xenpf_symdata compat_pf_symdata +#define COMPAT #define _XEN_GUEST_HANDLE (t) XEN_GUEST_HANDLE(t)#define _XEN_GUEST_HANDLE_PARAM (t) XEN_GUEST_HANDLE_PARAM(t)
xen/common/symbols.c +49 -1
65 lines not on this page · raw message
xen/common/vsprintf.c +1 -1
@@ -275,7 +275,7 @@ static char *pointer(char *str, char *end, const char **fmt_ptr,case 'S' :/* Symbol name unconditionally with offset and size */ {unsigned long sym_size, sym_offset; -char namebuf[KSYM_NAME_LEN +1 ]; +char namebuf[XEN_KSYM_NAME_LEN +1 ];/* Advance parents fmt string, as we have consumed 's' or 'S' */ ++*fmt_ptr;
xen/include/public/platform.h +16 -0
@@ -527,6 +527,21 @@ struct xenpf_core_parking {typedef struct xenpf_core_parking xenpf_core_parking_t ;DEFINE_XEN_GUEST_HANDLE (xenpf_core_parking_t); +#define XENPF_get_symbol 61 +#define XEN_KSYM_NAME_LEN 127 +struct xenpf_symdata { +/* IN variables */ +uint32_t symnum; + +/* OUT variables */ +uint32_t type; +uint64_t address; + +XEN_GUEST_HANDLE (char ) name; +}; +typedef struct xenpf_symdata xenpf_symdata_t ; +DEFINE_XEN_GUEST_HANDLE (xenpf_symdata_t); +/* * ` enum neg_errnoval * ` HYPERVISOR_platform_op(const struct xen_platform_op*);
@@ -553,6 +568,7 @@ struct xen_platform_op {struct xenpf_cpu_hotadd cpu_add;struct xenpf_mem_hotadd mem_add;struct xenpf_core_parking core_parking; +struct xenpf_symdata symdata;uint8_t pad[128 ]; } u; };
xen/include/xen/symbols.h +4 -2
@@ -2,8 +2,7 @@#define _XEN_SYMBOLS_H#include <xen/types.h> - -#define KSYM_NAME_LEN 127 +#include <public/platform.h> /* Lookup an address. */ const char *symbols_lookup(unsigned long addr,
@@ -11,4 +10,7 @@ const char *symbols_lookup(unsigned long addr,unsigned long *offset, char *namebuf); +int xensyms_read (uint32_t *symnum,uint32_t *type, +uint64_t *address,char *name); +#endif /*_XEN_SYMBOLS_H*/
xen/include/xlat.lst +1 -0
@@ -85,6 +85,7 @@ ? processor_px platform.h ! psd_package platform.h ? xenpf_enter_acpi_sleep platform.h +! xenpf_symdata platform.h ? xenpf_pcpuinfo platform.h ? xenpf_pcpu_version platform.h ! sched_poll sched.h
Signature · 1 line
1.8.3.1
PATCH RESEND v5 2/17 VPMU: Mark context LOADED before registers are loaded
In reply to Boris OstrovskyBecause a PMU interrupt may be generated as soon as PMU registers are loaded (or, more precisely, as soon as HW PMU is "armed") we don't want to delay marking context as LOADED until after registers are loaded. Otherwise during interrupt handling VPMU_CONTEXT_LOADED may not be set and this could be confusing.
(Technically, only SVM needs this change right now since VMX will "arm" PMU later, during VMRUN when global control register is loaded from VMCS. However, both AMD and Intel code will require this patch when we introduce PV VPMU).
--- xen/arch/x86/hvm/svm/vpmu.c | 2 ++ xen/arch/x86/hvm/vmx/vpmu_core2.c | 2 ++ xen/arch/x86/hvm/vpmu.c | 3 +-- 3 files changed, 5 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/svm/vpmu.c +2 -0
@@ -203,6 +203,8 @@ static void amd_vpmu_load(struct vcpu *v)return ; } +vpmu_set (vpmu,VPMU_CONTEXT_LOADED ); +context_load (v); }
xen/arch/x86/hvm/vmx/vpmu_core2.c +2 -0
@@ -369,6 +369,8 @@ static void core2_vpmu_load(struct vcpu *v)if (vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) )return ; +vpmu_set (vpmu,VPMU_CONTEXT_LOADED ); +__core2_vpmu_load (v); }
xen/arch/x86/hvm/vpmu.c +1 -2
@@ -211,10 +211,9 @@ void vpmu_load(struct vcpu *v)if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_load ) {apic_write_around (APIC_LVTPC , vpmu->hw_lapic_lvtpc); +/* Arch code needs to set VPMU_CONTEXT_LOADED */ vpmu->arch_vpmu_ops->arch_vpmu_load (v); } - -vpmu_set (vpmu,VPMU_CONTEXT_LOADED ); }void vpmu_initialise (struct vcpu *v)
Signature · 1 line
1.8.3.1
Re: [PATCH v5 RESEND 02/17] VPMU: Mark context LOADED before registers are loaded
Quoted 11 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:50 PMBecause a PMU interrupt may be generated as soon as PMU registers are loaded (or,
more precisely, as soon as HW PMU is "armed") we don't want to delay marking
context as LOADED until after registers are loaded. Otherwise during interrupt handlingVPMU_CONTEXT_LOADEDmay not be set and this could be confusing.
Quoted 7 lines
(Technically, only SVM needs this change right now since VMX will "arm" PMU later,
during VMRUN when global control register is loaded from VMCS. However, both
AMD and Intel code will require this patch when we introduce PV VPMU).Signed-off-by Boris Ostrovsky <[email protected]>
Quoted 52 lines
--- xen/arch/x86/hvm/svm/vpmu.c | 2 ++ xen/arch/x86/hvm/vmx/vpmu_core2.c | 2 ++ xen/arch/x86/hvm/vpmu.c | 3 +-- 3 files changed, 5 insertions(+), 2 deletions(-)xen/arch/x86/hvm/svm/vpmu.c +2
-0@@ -203,6 +203,8 @@ static void amd_vpmu_load(struct vcpu *v)return ; } +vpmu_set (vpmu,VPMU_CONTEXT_LOADED ); +context_load (v); }xen/arch/x86/hvm/vmx/vpmu_core2.c +2
-0@@ -369,6 +369,8 @@ static void core2_vpmu_load(struct vcpu *v)if (vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) )return ; +vpmu_set (vpmu,VPMU_CONTEXT_LOADED ); +__core2_vpmu_load (v); }xen/arch/x86/hvm/vpmu.c +1
-2@@ -211,10 +211,9 @@ void vpmu_load(struct vcpu *v)if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_load ) {apic_write_around (APIC_LVTPC , vpmu->hw_lapic_lvtpc); +/* Arch code needs to set VPMU_CONTEXT_LOADED */ vpmu->arch_vpmu_ops->arch_vpmu_load (v); } - -vpmu_set (vpmu,VPMU_CONTEXT_LOADED ); }void
vpmu_initialise(struct vcpu *v)
--
1.8.3.1
PATCH RESEND v5 3/17 x86/VPMU: Minor VPMU cleanup
In reply to Boris OstrovskyUpdate macros that modify VPMU flags to allow changing multiple bits at once.
Make sure that we only touch MSR bitmap on HVM guests (both VMX and SVM). This is needed by subsequent PMU patches.
--- xen/arch/x86/hvm/svm/vpmu.c | 14 +++++++++----- xen/arch/x86/hvm/vmx/vpmu_core2.c | 9 +++------ xen/arch/x86/hvm/vpmu.c | 3 +-- xen/include/asm-x86/hvm/vpmu.h | 9 +++++---- 4 files changed, 18 insertions(+), 17 deletions(-)
xen/arch/x86/hvm/svm/vpmu.c +9 -5
@@ -244,7 +244,8 @@ static int amd_vpmu_save(struct vcpu *v)context_save (v); -if ( !vpmu_is_set (vpmu,VPMU_RUNNING ) && ctx->msr_bitmap_set ) +if (is_hvm_domain (v->domain) && + !vpmu_is_set (vpmu,VPMU_RUNNING ) && ctx->msr_bitmap_set )amd_vpmu_unset_msr_bitmap (v);return 1 ;
@@ -284,7 +285,7 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)struct vpmu_struct *vpmu =vcpu_vpmu (v);/* For all counters, enable guest only mode for HVM guest */ -if ( (get_pmu_reg_type (msr) ==MSR_TYPE_CTRL ) && +if (is_hvm_domain (v->domain) && (get_pmu_reg_type (msr) ==MSR_TYPE_CTRL ) && !(is_guest_mode (msr_content)) ) {set_guest_mode (msr_content);
@@ -300,7 +301,8 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)apic_write (APIC_LVTPC ,PMU_APIC_VECTOR ); vpmu->hw_lapic_lvtpc =PMU_APIC_VECTOR ; -if ( !((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set ) +if (is_hvm_domain (v->domain) && + !((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set )amd_vpmu_set_msr_bitmap (v); }
@@ -311,7 +313,8 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)apic_write (APIC_LVTPC ,PMU_APIC_VECTOR |APIC_LVT_MASKED ); vpmu->hw_lapic_lvtpc =PMU_APIC_VECTOR |APIC_LVT_MASKED ;vpmu_reset (vpmu,VPMU_RUNNING ); -if ( ((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set ) +if (is_hvm_domain (v->domain) && + ((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set )amd_vpmu_unset_msr_bitmap (v);release_pmu_ownship (PMU_OWNER_HVM ); }
@@ -403,7 +406,8 @@ static void amd_vpmu_destroy(struct vcpu *v)if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )return ; -if ( ((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set ) +if (is_hvm_domain (v->domain) && + ((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set )amd_vpmu_unset_msr_bitmap (v);xfree (vpmu->context);
xen/arch/x86/hvm/vmx/vpmu_core2.c +3 -6
@@ -326,10 +326,7 @@ static int core2_vpmu_save(struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v); -if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_SAVE ) ) -return 0 ; - -if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) ) +if ( !vpmu_is_set_all (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ) )return 0 ;__core2_vpmu_save (v);
@@ -448,7 +445,7 @@ static int core2_vpmu_msr_common_check(u32 msr_index, int *type, int *index) {__core2_vpmu_load (current);vpmu_set (vpmu,VPMU_CONTEXT_LOADED ); -if ( cpu_has_vmx_msr_bitmap ) +if ( cpu_has_vmx_msr_bitmap &&is_hvm_domain (current->domain) )core2_vpmu_set_msr_bitmap (current->arch.hvm_vmx.msr_bitmap); }return 1 ;
@@ -815,7 +812,7 @@ static void core2_vpmu_destroy(struct vcpu *v)return ;xfree (core2_vpmu_cxt->pmu_enable);xfree (vpmu->context); -if ( cpu_has_vmx_msr_bitmap ) +if ( cpu_has_vmx_msr_bitmap &&is_hvm_domain (v->domain) )core2_vpmu_unset_msr_bitmap (v->arch.hvm_vmx.msr_bitmap);release_pmu_ownship (PMU_OWNER_HVM );vpmu_reset (vpmu,VPMU_CONTEXT_ALLOCATED );
xen/arch/x86/hvm/vpmu.c +1 -2
@@ -143,8 +143,7 @@ void vpmu_save(struct vcpu *v)struct vpmu_struct *vpmu =vcpu_vpmu (v);int pcpu =smp_processor_id (); -if ( !(vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) && -vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED )) ) +if ( !vpmu_is_set_all (vpmu,VPMU_CONTEXT_ALLOCATED |VPMU_CONTEXT_LOADED ) )return ; vpmu->last_pcpu = pcpu;
xen/include/asm-x86/hvm/vpmu.h +5 -4
@@ -81,10 +81,11 @@ struct vpmu_struct {#define VPMU_CPU_HAS_BTS 0x200/* Has Branch Trace Store */ -#define vpmu_set (_vpmu, _x) ((_vpmu)->flags |= (_x)) -#define vpmu_reset (_vpmu, _x) ((_vpmu)->flags &= ~(_x)) -#define vpmu_is_set (_vpmu, _x) ((_vpmu)->flags & (_x)) -#define vpmu_clear (_vpmu) ((_vpmu)->flags = 0) +#define vpmu_set (_vpmu, _x) ((_vpmu)->flags |= (_x)) +#define vpmu_reset (_vpmu, _x) ((_vpmu)->flags &= ~(_x)) +#define vpmu_is_set (_vpmu, _x) ((_vpmu)->flags & (_x)) +#define vpmu_is_set_all (_vpmu, _x) (((_vpmu)->flags & (_x)) == (_x)) +#define vpmu_clear (_vpmu) ((_vpmu)->flags = 0)int vpmu_do_wrmsr (unsigned int msr,uint64_t msr_content);int vpmu_do_rdmsr (unsigned int msr,uint64_t *msr_content);
Signature · 1 line
1.8.3.1
Re: [PATCH v5 RESEND 03/17] x86/VPMU: Minor VPMU cleanup
Quoted 97 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:50 PMUpdate macros that modify VPMU flags to allow changing multiple bits at once.
Make sure that we only touch MSR bitmap on HVM guests (both VMX and SVM). This
is needed by subsequent PMU patches.Signed-off-by Boris Ostrovsky <[email protected]>Reviewed-by Konrad Rzeszutek Wilk <[email protected]>--- xen/arch/x86/hvm/svm/vpmu.c | 14 +++++++++----- xen/arch/x86/hvm/vmx/vpmu_core2.c | 9 +++------ xen/arch/x86/hvm/vpmu.c | 3 +-- xen/include/asm-x86/hvm/vpmu.h | 9 +++++---- 4 files changed, 18 insertions(+), 17 deletions(-)xen/arch/x86/hvm/svm/vpmu.c +3
-2@@ -244,7 +244,8 @@ static int amd_vpmu_save(struct vcpu *v)context_save (v); -if ( !vpmu_is_set (vpmu,VPMU_RUNNING ) && ctx->msr_bitmap_set ) +if (is_hvm_domain (v->domain) && + !vpmu_is_set (vpmu,VPMU_RUNNING ) && ctx->msr_bitmap_set )amd_vpmu_unset_msr_bitmap (v);return 1 ;@@ -284,7 +285,7 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)struct vpmu_struct *vpmu =vcpu_vpmu (v);/* For all counters, enable guest only mode for HVM guest */ - if ( (get_pmu_reg_type(msr) == MSR_TYPE_CTRL) && + if ( is_hvm_domain(v->domain) && (get_pmu_reg_type(msr) ==
MSR_TYPE_CTRL) &&!(is_guest_mode(msr_content)) ) { set_guest_mode(msr_content);xen/arch/x86/hvm/svm/vpmu.c +2
-1@@ -300,7 +301,8 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)apic_write (APIC_LVTPC ,PMU_APIC_VECTOR ); vpmu->hw_lapic_lvtpc =PMU_APIC_VECTOR ; -if ( !((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set ) +if (is_hvm_domain (v->domain) && + !((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set )amd_vpmu_set_msr_bitmap(v); }xen/arch/x86/hvm/svm/vpmu.c +2
-1@@ -311,7 +313,8 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) apic_write(APIC_LVTPC, PMU_APIC_VECTOR | APIC_LVT_MASKED); vpmu->hw_lapic_lvtpc =PMU_APIC_VECTOR |APIC_LVT_MASKED ;vpmu_reset (vpmu,VPMU_RUNNING ); -if ( ((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set ) +if (is_hvm_domain (v->domain) && + ((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set )amd_vpmu_unset_msr_bitmap(v); release_pmu_ownship(PMU_OWNER_HVM); }xen/arch/x86/hvm/svm/vpmu.c +2
-1@@ -403,7 +406,8 @@ static void amd_vpmu_destroy(struct vcpu *v)if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )return ; -if ( ((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set ) +if (is_hvm_domain (v->domain) && + ((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set )amd_vpmu_unset_msr_bitmap (v);xfree (vpmu->context);xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-4@@ -326,10 +326,7 @@ static int core2_vpmu_save(struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v); -if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_SAVE ) ) -return 0 ; - -if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) ) +if ( !vpmu_is_set_all (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ) )return 0 ;
Quoted 1 line
__core2_vpmu_save(v);
right below you miss a bitmap check:
/* Unset PMU MSR bitmap to trap lazy load. */
if ( !vpmu_is_set(vpmu, VPMU_RUNNING) && cpu_has_vmx_msr_bitmap )
core2_vpmu_unset_msr_bitmap(v->arch.hvm_vmx.msr_bitmap);Quoted 60 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-1@@ -448,7 +445,7 @@ static int core2_vpmu_msr_common_check(u32 msr_index, int *type, int *index) {__core2_vpmu_load (current);vpmu_set (vpmu,VPMU_CONTEXT_LOADED ); -if ( cpu_has_vmx_msr_bitmap ) +if ( cpu_has_vmx_msr_bitmap &&is_hvm_domain (current->domain) )core2_vpmu_set_msr_bitmap(current->arch.hvm_vmx.msr_bitmap); } return 1;xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-1@@ -815,7 +812,7 @@ static void core2_vpmu_destroy(struct vcpu *v)return ;xfree (core2_vpmu_cxt->pmu_enable);xfree (vpmu->context); -if ( cpu_has_vmx_msr_bitmap ) +if ( cpu_has_vmx_msr_bitmap &&is_hvm_domain (v->domain) )core2_vpmu_unset_msr_bitmap (v->arch.hvm_vmx.msr_bitmap);release_pmu_ownship (PMU_OWNER_HVM );vpmu_reset (vpmu,VPMU_CONTEXT_ALLOCATED );xen/arch/x86/hvm/vpmu.c +1
-2@@ -143,8 +143,7 @@ void vpmu_save(struct vcpu *v)struct vpmu_struct *vpmu =vcpu_vpmu (v);int pcpu =smp_processor_id (); -if ( !(vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) && -vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED )) ) +if ( !vpmu_is_set_all (vpmu,VPMU_CONTEXT_ALLOCATED |VPMU_CONTEXT_LOADED ) )return ;vpmu->last_pcpu = pcpu;xen/include/asm-x86/hvm/vpmu.h +0
-0@@ -81,10 +81,11 @@ struct vpmu_struct {#define VPMU_CPU_HAS_BTS 0x200/* Has Branch Trace Store */
xen/include/asm-x86/hvm/vpmu.h +5
-5-#define vpmu_set (_vpmu, _x) ((_vpmu)->flags |= (_x)) -#define vpmu_reset (_vpmu, _x) ((_vpmu)->flags &= ~(_x)) -#define vpmu_is_set (_vpmu, _x) ((_vpmu)->flags & (_x)) -#define vpmu_clear (_vpmu) ((_vpmu)->flags = 0) +#define vpmu_set (_vpmu, _x) ((_vpmu)->flags |= (_x)) +#define vpmu_reset (_vpmu, _x) ((_vpmu)->flags &= ~(_x)) +#define vpmu_is_set (_vpmu, _x) ((_vpmu)->flags & (_x)) +#define vpmu_is_set_all (_vpmu, _x) (((_vpmu)->flags & (_x)) == (_x)) +#define vpmu_clear (_vpmu) ((_vpmu)->flags = 0)int vpmu_do_wrmsr (unsigned int msr,uint64_t msr_content);int vpmu_do_rdmsr (unsigned int msr,uint64_t *msr_content); --1.8.3.1
Re: [PATCH v5 RESEND 03/17] x86/VPMU: Minor VPMU cleanup
Quoted 17 lines · Kevin
Quoted 17 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-4@@ -326,10 +326,7 @@ static int core2_vpmu_save(struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v); -if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_SAVE ) ) -return 0 ; - -if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) ) +if ( !vpmu_is_set_all (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ) )return 0 ;
Quoted 6 lines
Quoted 1 line
__core2_vpmu_save(v);right below you miss a bitmap check:
/* Unset PMU MSR bitmap to trap lazy load. */ if ( !vpmu_is_set(vpmu, VPMU_RUNNING) && cpu_has_vmx_msr_bitmap ) core2_vpmu_unset_msr_bitmap(v->arch.hvm_vmx.msr_bitmap);
You mean is_hvm_domain()? Yes, (although this check does appears in a later patch). I'll move it here.
-boris
PATCH RESEND v5 4/17 intel/VPMU: Clean up Intel VPMU code
In reply to Boris OstrovskyRemove struct pmumsr and core2_pmu_enable. Replace static MSR structures with fields in core2_vpmu_context.
Call core2_get_pmc_count() once, during initialization.
Properly clean up when core2_vpmu_alloc_resource() fails and add routines to remove MSRs from VMCS.
--- xen/arch/x86/hvm/vmx/vmcs.c | 55 ++++++ xen/arch/x86/hvm/vmx/vpmu_core2.c | 310 ++++++++++++++----------------- xen/include/asm-x86/hvm/vmx/vmcs.h | 2 + xen/include/asm-x86/hvm/vmx/vpmu_core2.h | 19 -- 4 files changed, 199 insertions(+), 187 deletions(-)
xen/arch/x86/hvm/vmx/vmcs.c +55 -0
@@ -1205,6 +1205,34 @@ int vmx_add_guest_msr(u32 msr)return 0 ; } +void vmx_rm_guest_msr (u32 msr) +{ +struct vcpu *curr = current; +unsigned int idx, msr_count = curr->arch.hvm_vmx.msr_count; +struct vmx_msr_entry *msr_area = curr->arch.hvm_vmx.msr_area; + +if ( msr_area ==NULL ) +return ; + +for ( idx =0 ; idx < msr_count; idx++ ) +if ( msr_area[idx].index == msr ) +break ; + +if ( idx == msr_count ) +return ; + +for ( ; idx < msr_count -1 ; idx++ ) + { + msr_area[idx].index = msr_area[idx +1 ].index; + msr_area[idx].data = msr_area[idx +1 ].data; + } + msr_area[msr_count -1 ].index =0 ; + + curr->arch.hvm_vmx.msr_count = --msr_count; +__vmwrite (VM_EXIT_MSR_STORE_COUNT , msr_count); +__vmwrite (VM_ENTRY_MSR_LOAD_COUNT , msr_count); +} +int vmx_add_host_load_msr (u32 msr) {struct vcpu *curr = current;
@@ -1235,6 +1263,33 @@ int vmx_add_host_load_msr(u32 msr)return 0 ; } +void vmx_rm_host_load_msr (u32 msr) +{ +struct vcpu *curr = current; +unsigned int idx, msr_count = curr->arch.hvm_vmx.host_msr_count; +struct vmx_msr_entry *msr_area = curr->arch.hvm_vmx.host_msr_area; + +if ( msr_area ==NULL ) +return ; + +for ( idx =0 ; idx < msr_count; idx++ ) +if ( msr_area[idx].index == msr ) +break ; + +if ( idx == msr_count ) +return ; + +for ( ; idx < msr_count -1 ; idx++ ) + { + msr_area[idx].index = msr_area[idx +1 ].index; + msr_area[idx].data = msr_area[idx +1 ].data; + } + msr_area[msr_count -1 ].index =0 ; + + curr->arch.hvm_vmx.host_msr_count = --msr_count; +__vmwrite (VM_EXIT_MSR_LOAD_COUNT , msr_count); +} +void vmx_set_eoi_exit_bitmap (struct vcpu *v,u8 vector) {if ( !test_and_set_bit (vector, v->arch.hvm_vmx.eoi_exit_bitmap) )
xen/arch/x86/hvm/vmx/vpmu_core2.c +142 -168
570 lines not on this page · raw message
xen/include/asm-x86/hvm/vmx/vmcs.h +2 -0
@@ -473,7 +473,9 @@ void vmx_enable_intercept_for_msr(struct vcpu *v, u32 msr, int type);int vmx_read_guest_msr (u32 msr,u64 *val);int vmx_write_guest_msr (u32 msr,u64 val);int vmx_add_guest_msr (u32 msr); +void vmx_rm_guest_msr (u32 msr);int vmx_add_host_load_msr (u32 msr); +void vmx_rm_host_load_msr (u32 msr);void vmx_vmcs_switch (struct vmcs_struct *from,struct vmcs_struct *to);void vmx_set_eoi_exit_bitmap (struct vcpu *v,u8 vector);void vmx_clear_eoi_exit_bitmap (struct vcpu *v,u8 vector);
xen/include/asm-x86/hvm/vmx/vpmu_core2.h +0 -19
@@ -23,29 +23,10 @@#ifndef __ASM_X86_HVM_VPMU_CORE_H_#define __ASM_X86_HVM_VPMU_CORE_H_ -/* Currently only 3 fixed counters are supported. */ -#define VPMU_CORE2_NUM_FIXED 3 -/* Currently only 3 Non-architectual Performance Control MSRs */ -#define VPMU_CORE2_NUM_CTRLS 3 -struct arch_msr_pair {u64 counter;u64 control; }; -struct core2_pmu_enable { -char ds_area_enable; -char fixed_ctr_enable[VPMU_CORE2_NUM_FIXED ]; -char arch_pmc_enable[1 ]; -}; - -struct core2_vpmu_context { -struct core2_pmu_enable *pmu_enable; -u64 fix_counters[VPMU_CORE2_NUM_FIXED ]; -u64 ctrls[VPMU_CORE2_NUM_CTRLS ]; -u64 global_ovf_status; -struct arch_msr_pair arch_msr_pair[1 ]; -}; -#endif /* __ASM_X86_HVM_VPMU_CORE_H_ */
Signature · 1 line
1.8.3.1
Re: [PATCH v5 RESEND 04/17] intel/VPMU: Clean up Intel VPMU code
Quoted 7 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:50 PMRemove struct pmumsr and
core2_pmu_enable. Replace static MSR structures with
fields incore2_vpmu_context.
Quoted 7 lines
Call
core2_get_pmc_count()once, during initialization.Properly clean up when
core2_vpmu_alloc_resource()fails and add routines to remove MSRs from VMCS.Signed-off-by Boris Ostrovsky <[email protected]>
it's a good cleanup in general. ack with two small comments later.
Quoted 69 lines
--- xen/arch/x86/hvm/vmx/vmcs.c | 55 ++++++ xen/arch/x86/hvm/vmx/vpmu_core2.c | 310 ++++++++++++++----------------- xen/include/asm-x86/hvm/vmx/vmcs.h | 2 + xen/include/asm-x86/hvm/vmx/vpmu_core2.h | 19 -- 4 files changed, 199 insertions(+), 187 deletions(-)xen/arch/x86/hvm/vmx/vmcs.c +45
-0@@ -1205,6 +1205,34 @@ int vmx_add_guest_msr(u32 msr)return 0 ; } +void vmx_rm_guest_msr (u32 msr) +{ +struct vcpu *curr = current; +unsigned int idx, msr_count = curr->arch.hvm_vmx.msr_count; +struct vmx_msr_entry *msr_area = curr->arch.hvm_vmx.msr_area; + +if ( msr_area ==NULL ) +return ; + +for ( idx =0 ; idx < msr_count; idx++ ) +if ( msr_area[idx].index == msr ) +break ; + +if ( idx == msr_count ) +return ; + +for ( ; idx < msr_count -1 ; idx++ ) + { + msr_area[idx].index = msr_area[idx +1 ].index; + msr_area[idx].data = msr_area[idx +1 ].data; + } + msr_area[msr_count -1 ].index =0 ; + + curr->arch.hvm_vmx.msr_count = --msr_count; +__vmwrite (VM_EXIT_MSR_STORE_COUNT , msr_count); +__vmwrite (VM_ENTRY_MSR_LOAD_COUNT , msr_count); +} +int vmx_add_host_load_msr (u32 msr) {struct vcpu *curr = current;@@ -1235,6 +1263,33 @@ int vmx_add_host_load_msr(u32 msr)return 0 ; } +void vmx_rm_host_load_msr (u32 msr) +{ +struct vcpu *curr = current; +unsigned int idx, msr_count = curr->arch.hvm_vmx.host_msr_count; +struct vmx_msr_entry *msr_area = curr->arch.hvm_vmx.host_msr_area; + +if ( msr_area ==NULL ) +return ; + +for ( idx =0 ; idx < msr_count; idx++ ) +if ( msr_area[idx].index == msr ) +break ; + +if ( idx == msr_count ) +return ; + +for ( ; idx < msr_count -1 ; idx++ )
xen/arch/x86/hvm/vmx/vmcs.c int vmx_add_host_load_msr(u32 msr) · line 1293
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmcs.c +10
-0+ { + msr_area[idx].index = msr_area[idx +1 ].index; + msr_area[idx].data = msr_area[idx +1 ].data; + } + msr_area[msr_count -1 ].index =0 ; + + curr->arch.hvm_vmx.host_msr_count = --msr_count; +__vmwrite (VM_EXIT_MSR_LOAD_COUNT , msr_count); +} +
suggest to combine common code in above two 'rm' functions. You can pass in a msr_area pointer/count , and only last several lines actually differ.
Quoted 13 lines
xen/arch/x86/hvm/vmx/vmcs.c +0
-0void vmx_set_eoi_exit_bitmap (struct vcpu *v,u8 vector) {if ( !test_and_set_bit(vector, v->arch.hvm_vmx.eoi_exit_bitmap) )xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-0@@ -69,6 +69,26 @@static bool_t __read_mostly full_width_write;/* +* MSR_CORE_PERF_FIXED_CTR_CTRL contains the configuration of all fixed
xen/arch/x86/hvm/vmx/vpmu_core2.c line 82
Quoted 10 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +10
-0+* counters. 4 bits for every counter. +*/ +#define FIXED_CTR_CTRL_BITS 4 +#define FIXED_CTR_CTRL_MASK ((1 << FIXED_CTR_CTRL_BITS) - 1) + +#define VPMU_CORE2_MAX_FIXED_PMCS 4 +struct core2_vpmu_context { +u64 fixed_ctrl; +u64 ds_area; +u64 pebs_enable;
just stay 'pebs' to be consistent.
Quoted 5 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +5
-0+u64 global_ovf_status; +u64 fix_counters[VPMU_CORE2_MAX_FIXED_PMCS ]; +struct arch_msr_pair arch_msr_pair[1 ]; +}; +
Re: [PATCH v5 RESEND 04/17] intel/VPMU: Clean up Intel VPMU code
Quoted 92 lines · Kevin
Quoted 7 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:50 PMRemove struct pmumsr and
core2_pmu_enable. Replace static MSR structures with
fields incore2_vpmu_context.Quoted 7 lines
Call
core2_get_pmc_count()once, during initialization.Properly clean up when
core2_vpmu_alloc_resource()fails and add routines to remove MSRs from VMCS.Signed-off-by Boris Ostrovsky <[email protected]>it's a good cleanup in general. ack with two small comments later.
Acked-by Kevin Tian <[email protected]>Quoted 73 lines
--- xen/arch/x86/hvm/vmx/vmcs.c | 55 ++++++ xen/arch/x86/hvm/vmx/vpmu_core2.c | 310 ++++++++++++++----------------- xen/include/asm-x86/hvm/vmx/vmcs.h | 2 + xen/include/asm-x86/hvm/vmx/vpmu_core2.h | 19 -- 4 files changed, 199 insertions(+), 187 deletions(-)xen/arch/x86/hvm/vmx/vmcs.c +49
-0@@ -1205,6 +1205,34 @@ int vmx_add_guest_msr(u32 msr)return 0 ; } +void vmx_rm_guest_msr (u32 msr) +{ +struct vcpu *curr = current; +unsigned int idx, msr_count = curr->arch.hvm_vmx.msr_count; +struct vmx_msr_entry *msr_area = curr->arch.hvm_vmx.msr_area; + +if ( msr_area ==NULL ) +return ; + +for ( idx =0 ; idx < msr_count; idx++ ) +if ( msr_area[idx].index == msr ) +break ; + +if ( idx == msr_count ) +return ; + +for ( ; idx < msr_count -1 ; idx++ ) + { + msr_area[idx].index = msr_area[idx +1 ].index; + msr_area[idx].data = msr_area[idx +1 ].data; + } + msr_area[msr_count -1 ].index =0 ; + + curr->arch.hvm_vmx.msr_count = --msr_count; +__vmwrite (VM_EXIT_MSR_STORE_COUNT , msr_count); +__vmwrite (VM_ENTRY_MSR_LOAD_COUNT , msr_count); +} +int vmx_add_host_load_msr (u32 msr) {struct vcpu *curr = current;@@ -1235,6 +1263,33 @@ int vmx_add_host_load_msr(u32 msr)return 0 ; } +void vmx_rm_host_load_msr (u32 msr) +{ +struct vcpu *curr = current; +unsigned int idx, msr_count = curr->arch.hvm_vmx.host_msr_count; +struct vmx_msr_entry *msr_area = curr->arch.hvm_vmx.host_msr_area; + +if ( msr_area ==NULL ) +return ; + +for ( idx =0 ; idx < msr_count; idx++ ) +if ( msr_area[idx].index == msr ) +break ; + +if ( idx == msr_count ) +return ; + +for ( ; idx < msr_count -1 ; idx++ ) + { + msr_area[idx].index = msr_area[idx +1 ].index; + msr_area[idx].data = msr_area[idx +1 ].data; + }
Quoted 8 lines
xen/arch/x86/hvm/vmx/vmcs.c int vmx_add_host_load_msr(u32 msr) · line 1292
Quoted 6 lines
xen/arch/x86/hvm/vmx/vmcs.c +6
-0+ msr_area[msr_count -1 ].index =0 ; + + curr->arch.hvm_vmx.host_msr_count = --msr_count; +__vmwrite (VM_EXIT_MSR_LOAD_COUNT , msr_count); +} +suggest to combine common code in above two 'rm' functions. You can pass in a
msr_areapointer/count , and only last several lines actually differ.
I then should see if I can merge vmx_add_guest_msr/vmx_add_host_load_msr as well since they have similarities too.
Quoted 12 lines
Quoted 12 lines
xen/arch/x86/hvm/vmx/vmcs.c +0
-0void vmx_set_eoi_exit_bitmap (struct vcpu *v,u8 vector) {if ( !test_and_set_bit(vector, v->arch.hvm_vmx.eoi_exit_bitmap) )xen/arch/x86/hvm/vmx/vpmu_core2.c +0
-0@@ -69,6 +69,26 @@static bool_t __read_mostly full_width_write;
Quoted 13 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c line 82
Quoted 12 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +11
-0/* +* MSR_CORE_PERF_FIXED_CTR_CTRL contains the configuration of all fixed +* counters. 4 bits for every counter. +*/ +#define FIXED_CTR_CTRL_BITS 4 +#define FIXED_CTR_CTRL_MASK ((1 << FIXED_CTR_CTRL_BITS) - 1) + +#define VPMU_CORE2_MAX_FIXED_PMCS 4 +struct core2_vpmu_context { +u64 fixed_ctrl; +u64 ds_area; +u64 pebs_enable;just stay 'pebs' to be consistent.
The name is was chosen to reflect the MSR name (MSR_IA32_PEBS_ENABLE).
-boris
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +5
-0+u64 global_ovf_status; +u64 fix_counters[VPMU_CORE2_MAX_FIXED_PMCS ]; +struct arch_msr_pair arch_msr_pair[1 ]; +}; +
PATCH RESEND v5 5/17 x86/VPMU: Handle APIC_LVTPC accesses
In reply to Boris OstrovskyUpdate APIC_LVTPC vector when HVM guest writes to it.
--- xen/arch/x86/hvm/svm/vpmu.c | 4 ---- xen/arch/x86/hvm/vlapic.c | 5 ++++- xen/arch/x86/hvm/vmx/vpmu_core2.c | 17 ----------------- xen/arch/x86/hvm/vpmu.c | 14 +++++++++++--- xen/include/asm-x86/hvm/vpmu.h | 1 + 5 files changed, 16 insertions(+), 25 deletions(-)
xen/arch/x86/hvm/svm/vpmu.c +0 -4
@@ -298,8 +298,6 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)if ( !acquire_pmu_ownership (PMU_OWNER_HVM ) )return 1 ;vpmu_set (vpmu,VPMU_RUNNING ); -apic_write (APIC_LVTPC ,PMU_APIC_VECTOR ); - vpmu->hw_lapic_lvtpc =PMU_APIC_VECTOR ;if (is_hvm_domain (v->domain) && !((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set )
@@ -310,8 +308,6 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)if ( (get_pmu_reg_type (msr) ==MSR_TYPE_CTRL ) && (is_pmu_enabled (msr_content) ==0 ) &&vpmu_is_set (vpmu,VPMU_RUNNING ) ) { -apic_write (APIC_LVTPC ,PMU_APIC_VECTOR |APIC_LVT_MASKED ); - vpmu->hw_lapic_lvtpc =PMU_APIC_VECTOR |APIC_LVT_MASKED ;vpmu_reset (vpmu,VPMU_RUNNING );if (is_hvm_domain (v->domain) && ((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set )
xen/arch/x86/hvm/vlapic.c +4 -1
@@ -38,6 +38,7 @@#include <asm/hvm/support.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/nestedhvm.h> +#include <asm/hvm/vpmu.h> #include <public/hvm/ioreq.h> #include <public/hvm/params.h>
@@ -732,8 +733,10 @@ static int vlapic_reg_write(struct vcpu *v,vlapic_adjust_i8259_target (v->domain);pt_may_unmask_irq (v->domain,NULL ); } -if ( (offset ==APIC_LVTT ) && !(val &APIC_LVT_MASKED ) ) +else if ( (offset ==APIC_LVTT ) && !(val &APIC_LVT_MASKED ) )pt_may_unmask_irq (NULL , &vlapic->pt); +else if ( offset ==APIC_LVTPC ) +vpmu_lvtpc_update (val);break ;case APIC_TMICT :
xen/arch/x86/hvm/vmx/vpmu_core2.c +0 -17
@@ -534,19 +534,6 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)else vpmu_reset (vpmu,VPMU_RUNNING ); -/* Setup LVTPC in local apic */ -if (vpmu_is_set (vpmu,VPMU_RUNNING ) && -is_vlapic_lvtpc_enabled (vcpu_vlapic (v)) ) - { -apic_write_around (APIC_LVTPC ,PMU_APIC_VECTOR ); - vpmu->hw_lapic_lvtpc =PMU_APIC_VECTOR ; - } -else - { -apic_write_around (APIC_LVTPC ,PMU_APIC_VECTOR |APIC_LVT_MASKED ); - vpmu->hw_lapic_lvtpc =PMU_APIC_VECTOR |APIC_LVT_MASKED ; - } -if ( type !=MSR_TYPE_GLOBAL ) {u64 mask;
@@ -712,10 +699,6 @@ static int core2_vpmu_do_interrupt(struct cpu_user_regs *regs)return 0 ; } -/* HW sets the MASK bit when performance counter interrupt occurs*/ - vpmu->hw_lapic_lvtpc =apic_read (APIC_LVTPC ) & ~APIC_LVT_MASKED ; -apic_write_around (APIC_LVTPC , vpmu->hw_lapic_lvtpc); -return 1 ; }
xen/arch/x86/hvm/vpmu.c +11 -3
@@ -64,6 +64,14 @@ static void __init parse_vpmu_param(char *s) } } +void vpmu_lvtpc_update (uint32_t val) +{ +struct vpmu_struct *vpmu =vcpu_vpmu (current); + + vpmu->hw_lapic_lvtpc =PMU_APIC_VECTOR | (val &APIC_LVT_MASKED ); +apic_write (APIC_LVTPC , vpmu->hw_lapic_lvtpc); +} +int vpmu_do_wrmsr (unsigned int msr,uint64_t msr_content) {struct vpmu_struct *vpmu =vcpu_vpmu (current);
@@ -230,18 +238,18 @@ void vpmu_initialise(struct vcpu *v)case X86_VENDOR_AMD :if (svm_vpmu_initialise (v, opt_vpmu_enabled) !=0 ) opt_vpmu_enabled =0 ; -break ; +return ;case X86_VENDOR_INTEL :if (vmx_vpmu_initialise (v, opt_vpmu_enabled) !=0 ) opt_vpmu_enabled =0 ; -break ; +return ;default :printk ("VPMU: Initialization failed. " "Unknown CPU vendor %d\n" , vendor); opt_vpmu_enabled =0 ; -break ; +return ; } }
xen/include/asm-x86/hvm/vpmu.h +1 -0
@@ -87,6 +87,7 @@ struct vpmu_struct {#define vpmu_is_set_all (_vpmu, _x) (((_vpmu)->flags & (_x)) == (_x))#define vpmu_clear (_vpmu) ((_vpmu)->flags = 0) +void vpmu_lvtpc_update (uint32_t val);int vpmu_do_wrmsr (unsigned int msr,uint64_t msr_content);int vpmu_do_rdmsr (unsigned int msr,uint64_t *msr_content);int vpmu_do_interrupt (struct cpu_user_regs *regs);
Signature · 1 line
1.8.3.1
Re: [PATCH v5 RESEND 05/17] x86/VPMU: Handle APIC_LVTPC accesses
Quoted 6 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:50 PMUpdate
APIC_LVTPCvector when HVM guest writes to it.Signed-off-by Boris Ostrovsky <[email protected]>
Quoted 12 lines
xen/arch/x86/hvm/vpmu.c +2
-2@@ -230,18 +238,18 @@ void vpmu_initialise(struct vcpu *v)case X86_VENDOR_AMD :if (svm_vpmu_initialise (v, opt_vpmu_enabled) !=0 ) opt_vpmu_enabled =0 ; -break ; +return ;case X86_VENDOR_INTEL :if (vmx_vpmu_initialise (v, opt_vpmu_enabled) !=0 ) opt_vpmu_enabled =0 ; -break ; +return ;
xen/arch/x86/hvm/vpmu.c void vpmu_initialise(struct vcpu *v) · line 255
Quoted 10 lines
xen/arch/x86/hvm/vpmu.c +1
-1default :printk ("VPMU: Initialization failed. " "Unknown CPU vendor %d\n" , vendor); opt_vpmu_enabled =0 ; -break ; +return ; } }
not understand break->return change here
Re: [PATCH v5 RESEND 05/17] x86/VPMU: Handle APIC_LVTPC accesses
Quoted 21 lines · Kevin
Quoted 6 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:50 PMUpdate
APIC_LVTPCvector when HVM guest writes to it.Signed-off-by Boris Ostrovsky <[email protected]>Quoted 13 lines
xen/arch/x86/hvm/vpmu.c +2
-2@@ -230,18 +238,18 @@ void vpmu_initialise(struct vcpu *v)case X86_VENDOR_AMD :if (svm_vpmu_initialise (v, opt_vpmu_enabled) !=0 ) opt_vpmu_enabled =0 ; -break ; +return ;case X86_VENDOR_INTEL :if (vmx_vpmu_initialise (v, opt_vpmu_enabled) !=0 ) opt_vpmu_enabled =0 ; -break ; +return ;
Quoted 10 lines
xen/arch/x86/hvm/vpmu.c void vpmu_initialise(struct vcpu *v) · line 255
Quoted 9 lines
xen/arch/x86/hvm/vpmu.c +1
-1default :printk ("VPMU: Initialization failed. " "Unknown CPU vendor %d\n" , vendor); opt_vpmu_enabled =0 ; -break ; +return ; } }not understand
break->returnchange here
Hmm... I am sure there was a perfectly good reason why I did this ;-).
Perhaps at some point I had something at the end of the routine that I wasn't supposed to be executed if initialization failed. But it's not there now so I'll revert these changes (unless I find why I did this).
-boris
PATCH RESEND v5 6/17 intel/VPMU: MSR_CORE_PERF_GLOBAL_CTRL should be initialized to zero
In reply to Boris OstrovskyMSR_CORE_PERF_GLOBAL_CTRL register should be set zero initially. It is up to the guest to set it so that counters are enabled.
--- xen/arch/x86/hvm/vmx/vpmu_core2.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
xen/arch/x86/hvm/vmx/vpmu_core2.c +1 -9
@@ -164,13 +164,6 @@ static int core2_get_fixed_pmc_count(void)return ( (eax &PMU_FIXED_NR_MASK ) >>PMU_FIXED_NR_SHIFT ); } -static u64 core2_calc_intial_glb_ctrl_msr (void ) -{ -int arch_pmc_bits = (1 << arch_pmc_cnt) -1 ; -u64 fix_pmc_bits = (1 << fixed_pmc_cnt) -1 ; -return ( (fix_pmc_bits <<32 ) | arch_pmc_bits ); -} -/* edx bits 5-12: Bit width of fixed-function performance counters */ static int core2_get_bitwidth_fix_count (void ) {
@@ -373,8 +366,7 @@ static int core2_vpmu_alloc_resource(struct vcpu *v)if (vmx_add_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL ) ) goto out_err; -vmx_write_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , -core2_calc_intial_glb_ctrl_msr ()); +vmx_write_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL ,0 ); core2_vpmu_cxt =xzalloc_bytes (sizeof (struct core2_vpmu_context ) + (arch_pmc_cnt-1 )*sizeof (struct arch_msr_pair ));
Signature · 1 line
1.8.3.1
Re: [PATCH v5 RESEND 06/17] intel/VPMU: MSR_CORE_PERF_GLOBAL_CTRL should be initialized to zero
Quoted 7 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:50 PM
MSR_CORE_PERF_GLOBAL_CTRLregister should be set zero initially. It is up to the guest to set it so that counters are enabled.Signed-off-by Boris Ostrovsky <[email protected]>
Quoted 35 lines
--- xen/arch/x86/hvm/vmx/vpmu_core2.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-10@@ -164,13 +164,6 @@ static int core2_get_fixed_pmc_count(void)return ( (eax &PMU_FIXED_NR_MASK ) >>PMU_FIXED_NR_SHIFT ); } -static u64 core2_calc_intial_glb_ctrl_msr (void ) -{ -int arch_pmc_bits = (1 << arch_pmc_cnt) -1 ; -u64 fix_pmc_bits = (1 << fixed_pmc_cnt) -1 ; -return ( (fix_pmc_bits <<32 ) | arch_pmc_bits ); -} -/* edx bits 5-12: Bit width of fixed-function performance counters */ static int core2_get_bitwidth_fix_count (void ) {@@ -373,8 +366,7 @@ static int core2_vpmu_alloc_resource(struct vcpu *v)if (vmx_add_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL ) ) goto out_err; -vmx_write_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , -core2_calc_intial_glb_ctrl_msr ()); +vmx_write_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL ,0 ); core2_vpmu_cxt =xzalloc_bytes (sizeof (struct core2_vpmu_context ) + (arch_pmc_cnt-1 )*sizeof (struct arch_msr_pair )); --1.8.3.1
PATCH RESEND v5 7/17 x86/VPMU: Add public xenpmu.h
In reply to Boris OstrovskyAdd pmu.h header files, move various macros and structures that will be shared between hypervisor and PV guests to it.
Move MSR banks out of architectural PMU structures to allow for larger sizes in the future. The banks are allocated immediately after the context and PMU structures store offsets to them.
--- xen/arch/x86/hvm/svm/vpmu.c | 71 ++++++++++++++------------ xen/arch/x86/hvm/vmx/vpmu_core2.c | 87 +++++++++++++++++--------------- xen/arch/x86/hvm/vpmu.c | 1 + xen/arch/x86/oprofile/op_model_ppro.c | 6 ++- xen/include/asm-x86/hvm/vmx/vpmu_core2.h | 32 ------------ xen/include/asm-x86/hvm/vpmu.h | 13 ++--- xen/include/public/arch-arm.h | 3 ++ xen/include/public/arch-x86/pmu.h | 63 +++++++++++++++++++++++ xen/include/public/pmu.h | 38 ++++++++++++++ 9 files changed, 199 insertions(+), 115 deletions(-) delete mode 100644 xen/include/asm-x86/hvm/vmx/vpmu_core2.h create mode 100644 xen/include/public/arch-x86/pmu.h create mode 100644 xen/include/public/pmu.h
xen/arch/x86/hvm/svm/vpmu.c +39 -32
@@ -30,10 +30,7 @@#include <asm/apic.h> #include <asm/hvm/vlapic.h> #include <asm/hvm/vpmu.h> - -#define F10H_NUM_COUNTERS 4 -#define F15H_NUM_COUNTERS 6 -#define MAX_NUM_COUNTERS F15H_NUM_COUNTERS +#include <public/pmu.h> #define MSR_F10H_EVNTSEL_GO_SHIFT 40#define MSR_F10H_EVNTSEL_EN_SHIFT 22
@@ -49,6 +46,10 @@ static const u32 __read_mostly *counters;static const u32 __read_mostly *ctrls;static bool_t __read_mostly k7_counters_mirrored; +#define F10H_NUM_COUNTERS 4 +#define F15H_NUM_COUNTERS 6 +#define AMD_MAX_COUNTERS 6 +/* PMU Counter MSRs. */ static const u32 AMD_F10H_COUNTERS [] = {MSR_K7_PERFCTR0 ,
@@ -83,13 +84,6 @@ static const u32 AMD_F15H_CTRLS[] = { MSR_AMD_FAM15H_EVNTSEL5 }; -/* storage for context switching */ -struct amd_vpmu_context { -u64 counters[MAX_NUM_COUNTERS ]; -u64 ctrls[MAX_NUM_COUNTERS ]; -bool_t msr_bitmap_set; -}; -static inline int get_pmu_reg_type (u32 addr) {if ( (addr >=MSR_K7_EVNTSEL0 ) && (addr <=MSR_K7_EVNTSEL3 ) )
@@ -142,7 +136,7 @@ static void amd_vpmu_set_msr_bitmap(struct vcpu *v) {unsigned int i;struct vpmu_struct *vpmu =vcpu_vpmu (v); -struct amd_vpmu_context *ctxt = vpmu->context; +struct xen_pmu_amd_ctxt *ctxt = vpmu->context;for ( i =0 ; i < num_counters; i++ ) {
@@ -157,7 +151,7 @@ static void amd_vpmu_unset_msr_bitmap(struct vcpu *v) {unsigned int i;struct vpmu_struct *vpmu =vcpu_vpmu (v); -struct amd_vpmu_context *ctxt = vpmu->context; +struct xen_pmu_amd_ctxt *ctxt = vpmu->context;for ( i =0 ; i < num_counters; i++ ) {
@@ -177,19 +171,22 @@ static inline void context_load(struct vcpu *v) {unsigned int i;struct vpmu_struct *vpmu =vcpu_vpmu (v); -struct amd_vpmu_context *ctxt = vpmu->context; +struct xen_pmu_amd_ctxt *ctxt = vpmu->context; +uint64_t *counter_regs =vpmu_reg_pointer (ctxt, counters); +uint64_t *ctrl_regs =vpmu_reg_pointer (ctxt, ctrls);for ( i =0 ; i < num_counters; i++ ) { -wrmsrl (counters[i], ctxt->counters[i]); -wrmsrl (ctrls[i], ctxt->ctrls[i]); +wrmsrl (counters[i], counter_regs[i]); +wrmsrl (ctrls[i], ctrl_regs[i]); } }static void amd_vpmu_load (struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v); -struct amd_vpmu_context *ctxt = vpmu->context; +struct xen_pmu_amd_ctxt *ctxt = vpmu->context; +uint64_t *ctrl_regs =vpmu_reg_pointer (ctxt, ctrls);vpmu_reset (vpmu,VPMU_FROZEN );
@@ -198,7 +195,7 @@ static void amd_vpmu_load(struct vcpu *v)unsigned int i;for ( i =0 ; i < num_counters; i++ ) -wrmsrl (ctrls[i], ctxt->ctrls[i]); +wrmsrl (ctrls[i], ctrl_regs[i]);return ; }
@@ -212,17 +209,18 @@ static inline void context_save(struct vcpu *v) {unsigned int i;struct vpmu_struct *vpmu =vcpu_vpmu (v); -struct amd_vpmu_context *ctxt = vpmu->context; +struct xen_pmu_amd_ctxt *ctxt = vpmu->context; +uint64_t *counter_regs =vpmu_reg_pointer (ctxt, counters);/* No need to save controls -- they are saved in amd_vpmu_do_wrmsr */ for ( i =0 ; i < num_counters; i++ ) -rdmsrl (counters[i], ctxt->counters[i]); +rdmsrl (counters[i], counter_regs[i]); }static int amd_vpmu_save (struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v); -struct amd_vpmu_context *ctx = vpmu->context; +struct xen_pmu_amd_ctxt *ctx = vpmu->context;unsigned int i;/*
@@ -256,7 +254,9 @@ static void context_update(unsigned int msr, u64 msr_content)unsigned int i;struct vcpu *v = current;struct vpmu_struct *vpmu =vcpu_vpmu (v); -struct amd_vpmu_context *ctxt = vpmu->context; +struct xen_pmu_amd_ctxt *ctxt = vpmu->context; +uint64_t *counter_regs =vpmu_reg_pointer (ctxt, counters); +uint64_t *ctrl_regs =vpmu_reg_pointer (ctxt, ctrls);if ( k7_counters_mirrored && ((msr >=MSR_K7_EVNTSEL0 ) && (msr <=MSR_K7_PERFCTR3 )) )
@@ -268,12 +268,12 @@ static void context_update(unsigned int msr, u64 msr_content) {if ( msr == ctrls[i] ) { - ctxt->ctrls[i] = msr_content; + ctrl_regs[i] = msr_content;return ; }else if (msr == counters[i] ) { - ctxt->counters[i] = msr_content; + counter_regs[i] = msr_content;return ; } }
@@ -300,7 +300,7 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)vpmu_set (vpmu,VPMU_RUNNING );if (is_hvm_domain (v->domain) && - !((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set ) + !((struct xen_pmu_amd_ctxt *)vpmu->context)->msr_bitmap_set )amd_vpmu_set_msr_bitmap (v); }
@@ -310,7 +310,7 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) {vpmu_reset (vpmu,VPMU_RUNNING );if (is_hvm_domain (v->domain) && - ((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set ) + ((struct xen_pmu_amd_ctxt *)vpmu->context)->msr_bitmap_set )amd_vpmu_unset_msr_bitmap (v);release_pmu_ownship (PMU_OWNER_HVM ); }
@@ -351,7 +351,7 @@ static int amd_vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content)static int amd_vpmu_initialise (struct vcpu *v) { -struct amd_vpmu_context *ctxt; +struct xen_pmu_amd_ctxt *ctxt;struct vpmu_struct *vpmu =vcpu_vpmu (v);uint8_t family = current_cpu_data.x86;
@@ -381,7 +381,9 @@ static int amd_vpmu_initialise(struct vcpu *v) } } - ctxt = xzalloc(struct amd_vpmu_context); + ctxt =xzalloc_bytes (sizeof (struct xen_pmu_amd_ctxt ) + +sizeof (uint64_t ) *AMD_MAX_COUNTERS + +sizeof (uint64_t ) *AMD_MAX_COUNTERS );if ( !ctxt ) { gdprintk(XENLOG_WARNING, "Insufficient memory for PMU, "
@@ -390,6 +392,9 @@ static int amd_vpmu_initialise(struct vcpu *v)return -ENOMEM ; } + ctxt->counters =sizeof (struct xen_pmu_amd_ctxt ); + ctxt->ctrls = ctxt->counters +sizeof (uint64_t ) *AMD_MAX_COUNTERS ; + vpmu->context = ctxt;vpmu_set (vpmu,VPMU_CONTEXT_ALLOCATED );return 0 ;
@@ -403,7 +408,7 @@ static void amd_vpmu_destroy(struct vcpu *v)return ;if (is_hvm_domain (v->domain) && - ((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set ) + ((struct xen_pmu_amd_ctxt *)vpmu->context)->msr_bitmap_set )amd_vpmu_unset_msr_bitmap (v);xfree (vpmu->context);
@@ -420,7 +425,9 @@ static void amd_vpmu_destroy(struct vcpu *v)static void amd_vpmu_dump (const struct vcpu *v) {const struct vpmu_struct *vpmu =vcpu_vpmu (v); -const struct amd_vpmu_context *ctxt = vpmu->context; +const struct xen_pmu_amd_ctxt *ctxt = vpmu->context; +uint64_t *counter_regs =vpmu_reg_pointer (ctxt, counters); +uint64_t *ctrl_regs =vpmu_reg_pointer (ctxt, ctrls);unsigned int i;printk (" VPMU state: 0x%x " , vpmu->flags);
@@ -450,8 +457,8 @@ static void amd_vpmu_dump(const struct vcpu *v)rdmsrl (ctrls[i], ctrl);rdmsrl (counters[i], cntr);printk (" %#x: %#lx (%#lx in HW) %#x: %#lx (%#lx in HW)\n" , - ctrls[i], ctxt->ctrls[i], ctrl, - counters[i], ctxt->counters[i], cntr); + ctrls[i], ctrl_regs[i], ctrl, + counters[i], counter_regs[i], cntr); } }
xen/arch/x86/hvm/vmx/vpmu_core2.c +45 -42
221 lines not on this page · raw message
xen/arch/x86/hvm/vpmu.c +1 -0
@@ -31,6 +31,7 @@#include <asm/hvm/svm/svm.h> #include <asm/hvm/svm/vmcb.h> #include <asm/apic.h> +#include <public/pmu.h> /* * "vpmu" : vpmu generally enabled
xen/arch/x86/oprofile/op_model_ppro.c +5 -1
@@ -20,11 +20,15 @@#include <asm/regs.h> #include <asm/current.h> #include <asm/hvm/vpmu.h> -#include <asm/hvm/vmx/vpmu_core2.h> #include "op_x86_model.h" #include "op_counter.h" +struct arch_msr_pair { +u64 counter; +u64 control; +}; +/* * Intel "Architectural Performance Monitoring" CPUID * detection/enumeration details:
xen/include/asm-x86/hvm/vmx/vpmu_core2.h deleted +0 -32
@@ -1,32 +0,0 @@ - -/* -* vpmu_core2.h: CORE 2 specific PMU virtualization for HVM domain. -* -* Copyright (c) 2007, Intel Corporation. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms and conditions of the GNU General Public License, -* version 2, as published by the Free Software Foundation. -* -* This program is distributed in the hope it will be useful, but WITHOUT -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -* more details. -* -* You should have received a copy of the GNU General Public License along with -* this program; if not, write to the Free Software Foundation, Inc., 59 Temple -* Place - Suite 330, Boston, MA 02111-1307 USA. -* -* Author: Haitao Shan <[email protected]> -*/ - -#ifndef __ASM_X86_HVM_VPMU_CORE_H_ -#define __ASM_X86_HVM_VPMU_CORE_H_ - -struct arch_msr_pair { -u64 counter; -u64 control; -}; - -#endif /* __ASM_X86_HVM_VPMU_CORE_H_ */ -
xen/include/asm-x86/hvm/vpmu.h +5 -8
@@ -22,6 +22,8 @@#ifndef __ASM_X86_HVM_VPMU_H_#define __ASM_X86_HVM_VPMU_H_ +#include <public/pmu.h> +/* * Flag bits given as a string on the hypervisor boot parameter 'vpmu'. * See arch/x86/hvm/vpmu.c.
@@ -29,12 +31,9 @@#define VPMU_BOOT_ENABLED 0x1/* vpmu generally enabled. */ #define VPMU_BOOT_BTS 0x2/* Intel BTS feature wanted. */ - -#define msraddr_to_bitpos (x) (((x)&0xffff) + ((x)>>31)*0x2000)#define vcpu_vpmu (vcpu) (&((vcpu)->arch.hvm_vcpu.vpmu))#define vpmu_vcpu (vpmu) (container_of((vpmu), struct vcpu, \ arch.hvm_vcpu.vpmu)) -#define vpmu_domain (vpmu) (vpmu_vcpu(vpmu)->domain)#define MSR_TYPE_COUNTER 0#define MSR_TYPE_CTRL 1
@@ -42,6 +41,9 @@#define MSR_TYPE_ARCH_COUNTER 3#define MSR_TYPE_ARCH_CTRL 4 +/* Start of PMU register bank */ +#define vpmu_reg_pointer (ctxt, offset) ((void *)((uintptr_t)ctxt + \ + (uintptr_t)ctxt->offset))/* Arch specific operations shared by all vpmus */ struct arch_vpmu_ops {
@@ -76,11 +78,6 @@ struct vpmu_struct {#define VPMU_FROZEN 0x10/* Stop counters while VCPU is not running */ #define VPMU_PASSIVE_DOMAIN_ALLOCATED 0x20 -/* VPMU features */ -#define VPMU_CPU_HAS_DS 0x100/* Has Debug Store */ -#define VPMU_CPU_HAS_BTS 0x200/* Has Branch Trace Store */ - -#define vpmu_set (_vpmu, _x) ((_vpmu)->flags |= (_x))#define vpmu_reset (_vpmu, _x) ((_vpmu)->flags &= ~(_x))#define vpmu_is_set (_vpmu, _x) ((_vpmu)->flags & (_x))
xen/include/public/arch-arm.h +3 -0
@@ -388,6 +388,9 @@ typedef uint64_t xen_callback_t;#endif +/* Stub definition of PMU structure */ +typedef struct xen_arch_pmu {}xen_arch_pmu_t ; +#endif /* __XEN_PUBLIC_ARCH_ARM_H__ */ /*
xen/include/public/arch-x86/pmu.h new file +63 -0
63 lines not on this page · raw message
xen/include/public/pmu.h new file +38 -0
@@ -0,0 +1,38 @@ +#ifndef __XEN_PUBLIC_PMU_H__ +#define __XEN_PUBLIC_PMU_H__ + +#include "xen.h" +#if defined(__i386__) || defined(__x86_64__) +#include "arch-x86/pmu.h" +#elif defined (__arm__) || defined (__aarch64__) +#include "arch-arm.h" +#else +#error "Unsupported architecture" +#endif + +#define XENPMU_VER_MAJ 0 +#define XENPMU_VER_MIN 0 + + +/* Shared between hypervisor and PV domain */ +struct xen_pmu_data { +uint32_t domain_id; +uint32_t vcpu_id; +uint32_t pcpu_id; +uint32_t pmu_flags; + +xen_arch_pmu_t pmu; +}; +typedef struct xen_pmu_data xen_pmu_data_t ; + +#endif /* __XEN_PUBLIC_PMU_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
1.8.3.1
Re: [PATCH v5 RESEND 07/17] x86/VPMU: Add public xenpmu.h
Quoted 81 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:50 PMAdd
pmu.hheader files, move various macros and structures that will be shared between hypervisor and PV guests to it.Move MSR banks out of architectural PMU structures to allow for larger sizes in the future. The banks are allocated immediately after the context and PMU structures store offsets to them.
Signed-off-by Boris Ostrovsky <[email protected]>--- xen/arch/x86/hvm/svm/vpmu.c | 71 ++++++++++++++------------ xen/arch/x86/hvm/vmx/vpmu_core2.c | 87 +++++++++++++++++--------------- xen/arch/x86/hvm/vpmu.c | 1 + xen/arch/x86/oprofile/op_model_ppro.c | 6 ++- xen/include/asm-x86/hvm/vmx/vpmu_core2.h | 32 ------------ xen/include/asm-x86/hvm/vpmu.h | 13 ++--- xen/include/public/arch-arm.h | 3 ++ xen/include/public/arch-x86/pmu.h | 63 +++++++++++++++++++++++ xen/include/public/pmu.h | 38 ++++++++++++++ 9 files changed, 199 insertions(+), 115 deletions(-) delete mode 100644 xen/include/asm-x86/hvm/vmx/vpmu_core2.h create mode 100644 xen/include/public/arch-x86/pmu.h create mode 100644 xen/include/public/pmu.hxen/include/public/arch-x86/pmu.h new file +31
-0@@ -0,0 +1,63 @@ +#ifndef __XEN_PUBLIC_ARCH_X86_PMU_H__ +#define __XEN_PUBLIC_ARCH_X86_PMU_H__ + +/* x86-specific PMU definitions */ + +/* AMD PMU registers and structures */ +struct xen_pmu_amd_ctxt { +uint32_t counters;/* Offset to counter MSRs */ +uint32_t ctrls;/* Offset to control MSRs */ +uint32_t msr_bitmap_set;/* Used by HVM only */ +}; + +/* Intel PMU registers and structures */ +struct xen_pmu_cntr_pair { +uint64_t counter; +uint64_t control; +}; + +struct xen_pmu_intel_ctxt { +uint64_t global_ctrl; +uint64_t global_ovf_ctrl; +uint64_t global_status; +uint64_t fixed_ctrl; +uint64_t ds_area; +uint64_t pebs_enable; +uint64_t debugctl; +uint32_t fixed_counters;/* Offset to fixed counter MSRs */ +uint32_t arch_counters;/* Offset to architectural counter MSRs */ +}; + +#define XENPMU_MAX_CTXT_SZ (sizeof(struct xen_pmu_amd_ctxt) >\
+ sizeof(structxen_pmu_intel_ctxt) ? \
+ sizeof(structxen_pmu_amd_ctxt) : \
+ sizeof(structxen_pmu_intel_ctxt))
+#defineXENPMU_CTXT_PAD_SZ(((XENPMU_MAX_CTXT_SZ+ 64) &
~63) + 128)xen/include/public/arch-x86/pmu.h new file +5
-0+struct xen_arch_pmu { +union { +struct cpu_user_regs regs; +uint8_t pad1[256 ]; + } r;
xen/include/public/arch-x86/pmu.h line 50
Quoted 10 lines
xen/include/public/arch-x86/pmu.h new file +10
-0+union { +uint32_t lapic_lvtpc; +uint64_t pad2; + } l; +union { +struct xen_pmu_amd_ctxt amd; +struct xen_pmu_intel_ctxt intel; +uint8_t pad3[XENPMU_CTXT_PAD_SZ ]; + } c; +};
'xen_' prefix is meaningless here, and suppose to sustain vpmu in the names.
Re: [PATCH v5 RESEND 07/17] x86/VPMU: Add public xenpmu.h
Quoted 11 lines
Quoted 11 lines
Quoted 1 line · On 26.04.14 at 10:21, <[email protected]> wrote:
From: Boris Ostrovsky [mailto:[email protected]]
xen/include/public/arch-x86/pmu.h new file +9
-0+struct xen_arch_pmu { +union { +struct cpu_user_regs regs; +uint8_t pad1[256 ]; + } r; +union { +uint32_t lapic_lvtpc; +uint64_t pad2; + } l;
Quoted 8 lines
xen/include/public/arch-x86/pmu.h line 50
Quoted 6 lines
xen/include/public/arch-x86/pmu.h new file +6
-0+union { +struct xen_pmu_amd_ctxt amd; +struct xen_pmu_intel_ctxt intel; +uint8_t pad3[XENPMU_CTXT_PAD_SZ ]; + } c; +};'
xen_' prefix is meaningless here, and suppose to sustain vpmu in the names.
If these were field names, I'd agree. But I specifically asked for xen_ prefixes on anything going at some kind of global scope (i.e. structure name tags here).
Jan
Re: [PATCH v5 RESEND 07/17] x86/VPMU: Add public xenpmu.h
Quoted 23 lines
From: Jan Beulich [mailto:[email protected]]
Sent: Monday, April 28, 2014 5:03 PMQuoted 11 lines
Quoted 11 lines
Quoted 1 line · On 26.04.14 at 10:21, <[email protected]> wrote:
From: Boris Ostrovsky [mailto:[email protected]]
xen/include/public/arch-x86/pmu.h new file +9
-0+struct xen_arch_pmu { +union { +struct cpu_user_regs regs; +uint8_t pad1[256 ]; + } r; +union { +uint32_t lapic_lvtpc; +uint64_t pad2; + } l;Quoted 8 lines
xen/include/public/arch-x86/pmu.h line 50
Quoted 6 lines
xen/include/public/arch-x86/pmu.h new file +6
-0+union { +struct xen_pmu_amd_ctxt amd; +struct xen_pmu_intel_ctxt intel; +uint8_t pad3[XENPMU_CTXT_PAD_SZ ]; + } c; +};'
xen_' prefix is meaningless here, and suppose to sustain vpmu in the names.
Quoted 4 lines
If these were field names, I'd agree. But I specifically asked for
xen_prefixes on anything going at some kind of global scope (i.e. structure name tags here).
Then it's fine to me as long as it's the common practice.
Thanks
Kevin
PATCH RESEND v5 8/17 x86/VPMU: Make vpmu not HVM-specific
In reply to Boris Ostrovskyvpmu structure will be used for both HVM and PV guests. Move it from hvm_vcpu to arch_vcpu.
--- xen/include/asm-x86/domain.h | 2 ++ xen/include/asm-x86/hvm/vcpu.h | 3 --- xen/include/asm-x86/hvm/vpmu.h | 5 ++--- 3 files changed, 4 insertions(+), 6 deletions(-)
xen/include/asm-x86/domain.h +2 -0
@@ -400,6 +400,8 @@ struct arch_vcpuvoid (*ctxt_switch_from) (struct vcpu *);void (*ctxt_switch_to) (struct vcpu *); +struct vpmu_struct vpmu; +/* Virtual Machine Extensions */ union {struct pv_vcpu pv_vcpu;
xen/include/asm-x86/hvm/vcpu.h +0 -3
@@ -152,9 +152,6 @@ struct hvm_vcpu {u32 msr_tsc_aux;u64 msr_tsc_adjust; -/* VPMU */ -struct vpmu_struct vpmu; -union {struct arch_vmx_struct vmx;struct arch_svm_struct svm;
xen/include/asm-x86/hvm/vpmu.h +2 -3
@@ -31,9 +31,8 @@#define VPMU_BOOT_ENABLED 0x1/* vpmu generally enabled. */ #define VPMU_BOOT_BTS 0x2/* Intel BTS feature wanted. */ -#define vcpu_vpmu (vcpu) (&((vcpu)->arch.hvm_vcpu.vpmu)) -#define vpmu_vcpu (vpmu) (container_of((vpmu), struct vcpu, \ - arch.hvm_vcpu.vpmu)) +#define vcpu_vpmu (vcpu) (&(vcpu)->arch.vpmu) +#define vpmu_vcpu (vpmu) container_of(vpmu, struct vcpu, arch.vpmu)#define MSR_TYPE_COUNTER 0#define MSR_TYPE_CTRL 1
Signature · 1 line
1.8.3.1
Re: [PATCH v5 RESEND 08/17] x86/VPMU: Make vpmu not HVM-specific
Quoted 6 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:50 PMvpmu structure will be used for both HVM and PV guests. Move it from
hvm_vcputoarch_vcpu.
Quoted 6 lines
Signed-off-by Boris Ostrovsky <[email protected]>--- xen/include/asm-x86/domain.h | 2 ++ xen/include/asm-x86/hvm/vcpu.h | 3 --- xen/include/asm-x86/hvm/vpmu.h | 5 ++--- 3 files changed, 4 insertions(+), 6 deletions(-)
Quoted 48 lines
xen/include/asm-x86/domain.h +2
-0@@ -400,6 +400,8 @@ struct arch_vcpuvoid (*ctxt_switch_from) (struct vcpu *);void (*ctxt_switch_to) (struct vcpu *); +struct vpmu_struct vpmu; +/* Virtual Machine Extensions */ union {struct pv_vcpu pv_vcpu;xen/include/asm-x86/hvm/vcpu.h +0
-3@@ -152,9 +152,6 @@ struct hvm_vcpu {u32 msr_tsc_aux;u64 msr_tsc_adjust; -/* VPMU */ -struct vpmu_struct vpmu; -union {struct arch_vmx_struct vmx;struct arch_svm_struct svm;xen/include/asm-x86/hvm/vpmu.h +2
-4@@ -31,9 +31,8 @@#define VPMU_BOOT_ENABLED 0x1/* vpmu generally enabled. */ #define VPMU_BOOT_BTS 0x2/* Intel BTS feature wanted. */ -#define vcpu_vpmu (vcpu) (&((vcpu)->arch.hvm_vcpu.vpmu)) -#define vpmu_vcpu (vpmu) (container_of((vpmu), struct vcpu, \ - arch.hvm_vcpu.vpmu)) +#define vcpu_vpmu (vcpu) (&(vcpu)->arch.vpmu) +#define vpmu_vcpu (vpmu) container_of(vpmu, struct vcpu, arch.vpmu)#define MSR_TYPE_COUNTER 0#define MSR_TYPE_CTRL 1 --1.8.3.1
PATCH RESEND v5 9/17 x86/VPMU: Interface for setting PMU mode and flags
In reply to Boris OstrovskyAdd runtime interface for setting PMU mode and flags. Three main modes are provided:
* PMU off
* PMU on: Guests can access PMU MSRs and receive PMU interrupts. dom0 profiles itself and the hypervisor.
* dom0-only PMU: dom0 collects samples for both itself and guests.
For feature flags only Intel's BTS is currently supported.
Mode and flags are set via HYPERVISOR_xenpmu_op hypercall.
--- xen/arch/x86/domain.c | 4 +- xen/arch/x86/hvm/svm/vpmu.c | 4 +- xen/arch/x86/hvm/vmx/vpmu_core2.c | 10 +-- xen/arch/x86/hvm/vpmu.c | 121 ++++++++++++++++++++++++++++++++++--- xen/arch/x86/x86_64/compat/entry.S | 4 ++ xen/arch/x86/x86_64/entry.S | 4 ++ xen/include/asm-x86/hvm/vpmu.h | 14 ++--- xen/include/public/pmu.h | 48 +++++++++++++++ xen/include/public/xen.h | 1 + xen/include/xen/hypercall.h | 4 ++ 10 files changed, 188 insertions(+), 26 deletions(-)
xen/arch/x86/domain.c +2 -2
@@ -1465,7 +1465,7 @@ void context_switch(struct vcpu *prev, struct vcpu *next)if (is_hvm_vcpu (prev) ) { -if (prev != next) +if ( (prev != next) && (vpmu_mode &XENPMU_MODE_ON ) )vpmu_save (prev);if ( !list_empty (&prev->arch.hvm_vcpu.tm_list) )
@@ -1508,7 +1508,7 @@ void context_switch(struct vcpu *prev, struct vcpu *next) (next->domain->domain_id != 0)); } -if (is_hvm_vcpu (next) && (prev != next) ) +if (is_hvm_vcpu (next) && (prev != next) && (vpmu_mode &XENPMU_MODE_ON ) )/* Must be done with interrupts enabled */ vpmu_load (next);
xen/arch/x86/hvm/svm/vpmu.c +2 -2
@@ -472,14 +472,14 @@ struct arch_vpmu_ops amd_vpmu_ops = { .arch_vpmu_dump = amd_vpmu_dump }; -int svm_vpmu_initialise (struct vcpu *v,unsigned int vpmu_flags) +int svm_vpmu_initialise (struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v);uint8_t family = current_cpu_data.x86;int ret =0 ;/* vpmu enabled? */ -if ( !vpmu_flags ) +if ( vpmu_mode ==XENPMU_MODE_OFF )return 0 ; switch ( family )
xen/arch/x86/hvm/vmx/vpmu_core2.c +5 -5
@@ -703,13 +703,13 @@ static int core2_vpmu_do_interrupt(struct cpu_user_regs *regs)return 1 ; } -static int core2_vpmu_initialise (struct vcpu *v,unsigned int vpmu_flags) +static int core2_vpmu_initialise (struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v);u64 msr_content;struct cpuinfo_x86 *c = ¤t_cpu_data; -if ( !(vpmu_flags &VPMU_BOOT_BTS ) ) +if ( !(vpmu_features &XENPMU_FEATURE_INTEL_BTS ) ) goto func_out;/* Check the 'Debug Store' feature in the CPUID.EAX[1]:EDX[21] */ if (cpu_has (c,X86_FEATURE_DS ) )
@@ -820,7 +820,7 @@ struct arch_vpmu_ops core2_no_vpmu_ops = { .do_cpuid = core2_no_vpmu_do_cpuid, }; -int vmx_vpmu_initialise (struct vcpu *v,unsigned int vpmu_flags) +int vmx_vpmu_initialise (struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v);uint8_t family = current_cpu_data.x86;
@@ -828,7 +828,7 @@ int vmx_vpmu_initialise(struct vcpu *v, unsigned int vpmu_flags)int ret =0 ; vpmu->arch_vpmu_ops = &core2_no_vpmu_ops; -if ( !vpmu_flags ) +if ( vpmu_mode ==XENPMU_MODE_OFF )return 0 ;if ( family ==6 )
@@ -867,7 +867,7 @@ int vmx_vpmu_initialise(struct vcpu *v, unsigned int vpmu_flags)case 0x3f :case 0x45 :case 0x46 : - ret =core2_vpmu_initialise (v, vpmu_flags); + ret =core2_vpmu_initialise (v);if ( !ret ) vpmu->arch_vpmu_ops = &core2_vpmu_ops;return ret;
xen/arch/x86/hvm/vpmu.c +113 -8
174 lines not on this page · raw message
xen/arch/x86/x86_64/compat/entry.S +4 -0
@@ -416,6 +416,8 @@ ENTRY(compat_hypercall_table) .quad do_domctl .quad compat_kexec_op .quad do_tmem_op + .quad do_ni_hypercall /* reserved for XenClient */ + .quad do_xenpmu_op /* 40 */ .rept __HYPERVISOR_arch_0-((.-compat_hypercall_table)/8) .quad compat_ni_hypercall .endr
@@ -464,6 +466,8 @@ ENTRY(compat_hypercall_args_table) .byte 1 /* do_domctl */ .byte 2 /* compat_kexec_op */ .byte 1 /* do_tmem_op */ + .byte 0 /* reserved for XenClient */ + .byte 2 /* do_xenpmu_op */ /* 40 */ .rept __HYPERVISOR_arch_0-(.-compat_hypercall_args_table) .byte 0 /* compat_ni_hypercall */ .endr
xen/arch/x86/x86_64/entry.S +4 -0
@@ -757,6 +757,8 @@ ENTRY(hypercall_table) .quad do_domctl .quad do_kexec_op .quad do_tmem_op + .quad do_ni_hypercall /* reserved for XenClient */ + .quad do_xenpmu_op /* 40 */ .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8) .quad do_ni_hypercall .endr
@@ -805,6 +807,8 @@ ENTRY(hypercall_args_table) .byte 1 /* do_domctl */ .byte 2 /* do_kexec */ .byte 1 /* do_tmem_op */ + .byte 0 /* reserved for XenClient */ + .byte 2 /* do_xenpmu_op */ /* 40 */ .rept __HYPERVISOR_arch_0-(.-hypercall_args_table) .byte 0 /* do_ni_hypercall */ .endr
xen/include/asm-x86/hvm/vpmu.h +5 -9
@@ -24,13 +24,6 @@#include <public/pmu.h> -/* -* Flag bits given as a string on the hypervisor boot parameter 'vpmu'. -* See arch/x86/hvm/vpmu.c. -*/ -#define VPMU_BOOT_ENABLED 0x1/* vpmu generally enabled. */ -#define VPMU_BOOT_BTS 0x2/* Intel BTS feature wanted. */ -#define vcpu_vpmu (vcpu) (&(vcpu)->arch.vpmu)#define vpmu_vcpu (vpmu) container_of(vpmu, struct vcpu, arch.vpmu)
@@ -58,8 +51,8 @@ struct arch_vpmu_ops {void (*arch_vpmu_dump)(const struct vcpu *); }; -int vmx_vpmu_initialise (struct vcpu *,unsigned int flags); -int svm_vpmu_initialise (struct vcpu *,unsigned int flags); +int vmx_vpmu_initialise (struct vcpu *); +int svm_vpmu_initialise (struct vcpu *);struct vpmu_struct {u32 flags;
@@ -98,5 +91,8 @@ void vpmu_dump(struct vcpu *v);extern int acquire_pmu_ownership (int pmu_ownership);extern void release_pmu_ownership (int pmu_ownership); +extern uint64_t vpmu_mode; +extern uint64_t vpmu_features; +#endif /* __ASM_X86_HVM_VPMU_H_*/
xen/include/public/pmu.h +48 -0
54 lines not on this page · raw message
xen/include/public/xen.h +1 -0
@@ -101,6 +101,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);#define __HYPERVISOR_kexec_op 37#define __HYPERVISOR_tmem_op 38#define __HYPERVISOR_xc_reserved_op 39/* reserved for XenClient */ +#define __HYPERVISOR_xenpmu_op 40/* Architecture-specific hypercall definitions. */ #define __HYPERVISOR_arch_0 48
xen/include/xen/hypercall.h +4 -0
@@ -14,6 +14,7 @@#include <public/event_channel.h> #include <public/tmem.h> #include <public/version.h> +#include <public/pmu.h> #include <asm/hypercall.h> #include <xsm/xsm.h>
@@ -139,6 +140,9 @@ do_tmem_op(extern long do_xenoprof_op (int op,XEN_GUEST_HANDLE_PARAM (void ) arg); +extern long +do_xenpmu_op (int op,XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg); +#ifdef CONFIG_COMPAT extern int
Signature · 1 line
1.8.3.1
Re: [PATCH v5 RESEND 09/17] x86/VPMU: Interface for setting PMU mode and flags
Quoted 10 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:51 PMAdd runtime interface for setting PMU mode and flags. Three main modes are provided:
* PMU off
* PMU on: Guests can access PMU MSRs and receive PMU interrupts. dom0 profiles itself and the hypervisor.
* dom0-only PMU: dom0 collects samples for both itself and guests.
Quoted 5 lines
For feature flags only Intel's BTS is currently supported.
Mode and flags are set via
HYPERVISOR_xenpmu_ophypercall.Signed-off-by Boris Ostrovsky <[email protected]>
Similarly, why do you want so many "XEN" and "xen_" prefixes? :-)
Quoted 485 lines
--- xen/arch/x86/domain.c | 4 +- xen/arch/x86/hvm/svm/vpmu.c | 4 +- xen/arch/x86/hvm/vmx/vpmu_core2.c | 10 +-- xen/arch/x86/hvm/vpmu.c | 121 ++++++++++++++++++++++++++++++++++--- xen/arch/x86/x86_64/compat/entry.S | 4 ++ xen/arch/x86/x86_64/entry.S | 4 ++ xen/include/asm-x86/hvm/vpmu.h | 14 ++--- xen/include/public/pmu.h | 48 +++++++++++++++ xen/include/public/xen.h | 1 + xen/include/xen/hypercall.h | 4 ++ 10 files changed, 188 insertions(+), 26 deletions(-)xen/arch/x86/domain.c +1
-1@@ -1465,7 +1465,7 @@ void context_switch(struct vcpu *prev, struct vcpu *next)if (is_hvm_vcpu (prev) ) { -if (prev != next) +if ( (prev != next) && (vpmu_mode &XENPMU_MODE_ON ) )vpmu_save (prev);if ( !list_empty(&prev->arch.hvm_vcpu.tm_list) )xen/arch/x86/domain.c +1
-1@@ -1508,7 +1508,7 @@ void context_switch(struct vcpu *prev, struct vcpu *next) (next->domain->domain_id != 0)); } -if (is_hvm_vcpu (next) && (prev != next) ) +if (is_hvm_vcpu (next) && (prev != next) && (vpmu_mode &XENPMU_MODE_ON ) )/* Must be done with interrupts enabled */ vpmu_load(next);xen/arch/x86/hvm/svm/vpmu.c +2
-2@@ -472,14 +472,14 @@ struct arch_vpmu_ops amd_vpmu_ops = { .arch_vpmu_dump = amd_vpmu_dump }; -int svm_vpmu_initialise (struct vcpu *v,unsigned int vpmu_flags) +int svm_vpmu_initialise (struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v);uint8_t family = current_cpu_data.x86;int ret =0 ;/* vpmu enabled? */ -if ( !vpmu_flags ) +if ( vpmu_mode ==XENPMU_MODE_OFF )return 0 ; switch ( family )xen/arch/x86/hvm/vmx/vpmu_core2.c +2
-2@@ -703,13 +703,13 @@ static int core2_vpmu_do_interrupt(struct cpu_user_regs *regs)return 1 ; } -static int core2_vpmu_initialise (struct vcpu *v,unsigned int vpmu_flags) +static int core2_vpmu_initialise (struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v);u64 msr_content;struct cpuinfo_x86 *c = ¤t_cpu_data; -if ( !(vpmu_flags &VPMU_BOOT_BTS ) ) +if ( !(vpmu_features &XENPMU_FEATURE_INTEL_BTS ) ) goto func_out;/* Check the 'Debug Store' feature in the CPUID.EAX[1]:EDX[21] */ if ( cpu_has(c, X86_FEATURE_DS) )xen/arch/x86/hvm/vmx/vpmu_core2.c +2
-2@@ -820,7 +820,7 @@ struct arch_vpmu_ops core2_no_vpmu_ops = { .do_cpuid = core2_no_vpmu_do_cpuid, }; -int vmx_vpmu_initialise (struct vcpu *v,unsigned int vpmu_flags) +int vmx_vpmu_initialise (struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v);uint8_t family = current_cpu_data.x86;@@ -828,7 +828,7 @@ int vmx_vpmu_initialise(struct vcpu *v, unsigned int vpmu_flags)int ret =0 ; vpmu->arch_vpmu_ops = &core2_no_vpmu_ops; -if ( !vpmu_flags ) +if ( vpmu_mode ==XENPMU_MODE_OFF )return 0 ;if ( family == 6 )xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-1@@ -867,7 +867,7 @@ int vmx_vpmu_initialise(struct vcpu *v, unsigned int vpmu_flags)case 0x3f :case 0x45 :case 0x46 : - ret =core2_vpmu_initialise (v, vpmu_flags); + ret =core2_vpmu_initialise (v);if ( !ret ) vpmu->arch_vpmu_ops = &core2_vpmu_ops;return ret;xen/arch/x86/hvm/vpmu.c +8
-3@@ -21,6 +21,7 @@#include <xen/config.h> #include <xen/sched.h> #include <xen/xenoprof.h> +#include <xen/guest_access.h> #include <asm/regs.h> #include <asm/types.h> #include <asm/msr.h> @@ -38,7 +39,8 @@* "vpmu=off" : vpmu generally disabled * "vpmu=bts" : vpmu enabled and Intel BTS feature switched on. */ -static unsigned int __read_mostly opt_vpmu_enabled; +uint64_t __read_mostly vpmu_mode =XENPMU_MODE_OFF ; +uint64_t __read_mostly vpmu_features =0 ;static void parse_vpmu_param (char *s);custom_param ("vpmu" , parse_vpmu_param);@@ -52,7 +54,7 @@ static void __init parse_vpmu_param(char *s)break ;default :if ( !strcmp (s,"bts" ) ) - opt_vpmu_enabled |=VPMU_BOOT_BTS ; + vpmu_features |=XENPMU_FEATURE_INTEL_BTS ;else if ( *s ) {printk ("VPMU: unknown flag: %s - vpmu disabled!\n" , s);@@ -60,7 +62,7 @@ static void __init parse_vpmu_param(char *s) }/* fall through */ case 1 : - opt_vpmu_enabled |=VPMU_BOOT_ENABLED ; + vpmu_mode =XENPMU_MODE_ON ;break ; } }@@ -77,6 +79,9 @@ int vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) {struct vpmu_struct *vpmu =vcpu_vpmu (current); +if ( !(vpmu_mode &XENPMU_MODE_ON ) ) +return 0 ; +if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_wrmsr )return vpmu->arch_vpmu_ops->do_wrmsr (msr, msr_content);return 0;xen/arch/x86/hvm/vpmu.c +3
-0@@ -86,6 +91,9 @@ int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) {struct vpmu_struct *vpmu =vcpu_vpmu (current); +if ( !(vpmu_mode &XENPMU_MODE_ON ) ) +return 0 ; +if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_rdmsr )return vpmu->arch_vpmu_ops->do_rdmsr (msr, msr_content);return 0;xen/arch/x86/hvm/vpmu.c +40
-5@@ -237,19 +245,19 @@ void vpmu_initialise(struct vcpu *v)switch ( vendor ) {case X86_VENDOR_AMD : -if (svm_vpmu_initialise (v, opt_vpmu_enabled) !=0 ) - opt_vpmu_enabled =0 ; +if (svm_vpmu_initialise (v) !=0 ) + vpmu_mode =XENPMU_MODE_OFF ;return ;case X86_VENDOR_INTEL : -if (vmx_vpmu_initialise (v, opt_vpmu_enabled) !=0 ) - opt_vpmu_enabled =0 ; +if (vmx_vpmu_initialise (v) !=0 ) + vpmu_mode =XENPMU_MODE_OFF ;return ;default :printk ("VPMU: Initialization failed. " "Unknown CPU vendor %d\n" , vendor); - opt_vpmu_enabled =0 ; + vpmu_mode =XENPMU_MODE_OFF ;return ; } }@@ -271,3 +279,100 @@ void vpmu_dump(struct vcpu *v) vpmu->arch_vpmu_ops->arch_vpmu_dump (v); } +/* Unload VPMU contexts */ +static void vpmu_unload_all (void ) +{ +struct domain *d; +struct vcpu *v; +struct vpmu_struct *vpmu; + +for_each_domain (d) + { + for_each_vcpu ( d, v ) + { +if ( v != current ) +vcpu_pause (v); + vpmu =vcpu_vpmu (v); + +if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) ) + { +if ( v != current ) +vcpu_unpause (v); +continue ; + } + +vpmu_set (vpmu,VPMU_CONTEXT_SAVE ); +on_selected_cpus (cpumask_of (vpmu->last_pcpu), + vpmu_save_force, (void *)v,1 ); +vpmu_reset (vpmu,VPMU_CONTEXT_LOADED ); + +if ( v != current ) +vcpu_unpause (v); + } + } +} + + +long do_xenpmu_op(int op,
XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t)arg)xen/arch/x86/hvm/vpmu.c +20
-0+{ +int ret = -EINVAL ; +xen_pmu_params_t pmu_params; + +switch ( op ) + { +case XENPMU_mode_set: +if ( !is_control_domain (current->domain) ) +return -EPERM ; + +if (copy_from_guest (&pmu_params, arg,1 ) ) +return -EFAULT ; + +if ( pmu_params.d.val & ~XENPMU_MODE_ON ) +return -EINVAL ; + + vpmu_mode = pmu_params.d.val; +if ( vpmu_mode ==XENPMU_MODE_OFF ) +/* +* After this VPMU context will never be loaded during context
+ * switch. We also prevent PMU MSR accesses (which can
loadxen/arch/x86/hvm/vpmu.c +41
-0+* context) when VPMU is disabled. +*/ +vpmu_unload_all (); + + ret =0 ; +break ; + +case XENPMU_mode_get: + pmu_params.d.val = vpmu_mode; + pmu_params.v.version.maj =XENPMU_VER_MAJ ; + pmu_params.v.version.min =XENPMU_VER_MIN ; +if (copy_to_guest (arg, &pmu_params,1 ) ) +return -EFAULT ; + ret =0 ; +break ; + +case XENPMU_feature_set: +if ( !is_control_domain (current->domain) ) +return -EPERM ; + +if (copy_from_guest (&pmu_params, arg,1 ) ) +return -EFAULT ; + +if ( pmu_params.d.val & ~XENPMU_FEATURE_INTEL_BTS ) +return -EINVAL ; + + vpmu_features = pmu_params.d.val; + + ret =0 ; +break ; + +case XENPMU_feature_get: + pmu_params.d.val = vpmu_mode; +if (copy_to_guest (arg, &pmu_params,1 ) ) +return -EFAULT ; + ret =0 ; +break ; + } + +return ret; +}xen/arch/x86/x86_64/compat/entry.S +4
-0@@ -416,6 +416,8 @@ ENTRY(compat_hypercall_table) .quad do_domctl .quad compat_kexec_op .quad do_tmem_op + .quad do_ni_hypercall /* reserved for XenClient */ + .quad do_xenpmu_op /* 40 */ .rept __HYPERVISOR_arch_0-((.-compat_hypercall_table)/8) .quad compat_ni_hypercall .endr@@ -464,6 +466,8 @@ ENTRY(compat_hypercall_args_table) .byte 1 /* do_domctl */ .byte 2 /* compat_kexec_op */ .byte 1 /* do_tmem_op */ + .byte 0 /* reserved for XenClient */ + .byte 2 /* do_xenpmu_op */ /* 40 */ .rept __HYPERVISOR_arch_0-(.-compat_hypercall_args_table) .byte 0 /* compat_ni_hypercall */ .endrxen/arch/x86/x86_64/entry.S +4
-0@@ -757,6 +757,8 @@ ENTRY(hypercall_table) .quad do_domctl .quad do_kexec_op .quad do_tmem_op + .quad do_ni_hypercall /* reserved for XenClient */ + .quad do_xenpmu_op /* 40 */ .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8) .quad do_ni_hypercall .endr@@ -805,6 +807,8 @@ ENTRY(hypercall_args_table) .byte 1 /* do_domctl */ .byte 2 /* do_kexec */ .byte 1 /* do_tmem_op */ + .byte 0 /* reserved for XenClient */ + .byte 2 /* do_xenpmu_op */ /* 40 */ .rept __HYPERVISOR_arch_0-(.-hypercall_args_table) .byte 0 /* do_ni_hypercall */ .endrxen/include/asm-x86/hvm/vpmu.h +5
-9@@ -24,13 +24,6 @@#include <public/pmu.h> -/* -* Flag bits given as a string on the hypervisor boot parameter 'vpmu'. -* See arch/x86/hvm/vpmu.c. -*/ -#define VPMU_BOOT_ENABLED 0x1/* vpmu generally enabled. */ -#define VPMU_BOOT_BTS 0x2/* Intel BTS feature wanted. */ -#define vcpu_vpmu (vcpu) (&(vcpu)->arch.vpmu)#define vpmu_vcpu (vpmu) container_of(vpmu, struct vcpu, arch.vpmu)@@ -58,8 +51,8 @@ struct arch_vpmu_ops {void (*arch_vpmu_dump)(const struct vcpu *); }; -int vmx_vpmu_initialise (struct vcpu *,unsigned int flags); -int svm_vpmu_initialise (struct vcpu *,unsigned int flags); +int vmx_vpmu_initialise (struct vcpu *); +int svm_vpmu_initialise (struct vcpu *);struct vpmu_struct {u32 flags;@@ -98,5 +91,8 @@ void vpmu_dump(struct vcpu *v);extern int acquire_pmu_ownership (int pmu_ownership);extern void release_pmu_ownership (int pmu_ownership); +extern uint64_t vpmu_mode; +extern uint64_t vpmu_features; +#endif /* __ASM_X86_HVM_VPMU_H_*/ xen/include/public/pmu.h +48
-0@@ -13,6 +13,54 @@#define XENPMU_VER_MAJ 0#define XENPMU_VER_MIN 0 +/* +* ` enum neg_errnoval +* ` HYPERVISOR_xenpmu_op(enum xenpmu_op cmd, struct xenpmu_params *args); +* +* @cmd == XENPMU_* (PMU operation) +* @args == struct xenpmu_params +*/ +/* ` enum xenpmu_op { */ +#define XENPMU_mode_get 0/* Also used for getting PMU version */ +#define XENPMU_mode_set 1 +#define XENPMU_feature_get 2 +#define XENPMU_feature_set 3 +/* ` } */ + +/* Parameters structure for HYPERVISOR_xenpmu_op call */ +struct xen_pmu_params { +/* IN/OUT parameters */ +union { +struct version { +uint8_t maj; +uint8_t min; + } version; +uint64_t pad; + } v; +union { +uint64_t val; +XEN_GUEST_HANDLE (void ) valp; + } d; + +/* IN parameters */ +uint64_t vcpu; +}; +typedef struct xen_pmu_params xen_pmu_params_t ; +DEFINE_XEN_GUEST_HANDLE (xen_pmu_params_t); + +/* PMU modes: +* - XENPMU_MODE_OFF: No PMU virtualization +* - XENPMU_MODE_ON: Guests can profile themselves, dom0 profiles +* itself and Xen +*/ +#define XENPMU_MODE_OFF 0 +#define XENPMU_MODE_ON (1<<0) + +/* +* PMU features: +* - XENPMU_FEATURE_INTEL_BTS: Intel BTS support (ignored on AMD) +*/ +#define XENPMU_FEATURE_INTEL_BTS 1/* Shared between hypervisor and PV domain */
structxen_pmu_data{xen/include/public/xen.h +1
-0@@ -101,6 +101,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);#define __HYPERVISOR_kexec_op 37#define __HYPERVISOR_tmem_op 38#define __HYPERVISOR_xc_reserved_op 39/* reserved for XenClient */ +#define __HYPERVISOR_xenpmu_op 40/* Architecture-specific hypercall definitions. */ #define
__HYPERVISOR_arch_048xen/include/xen/hypercall.h +4
-0@@ -14,6 +14,7 @@#include <public/event_channel.h> #include <public/tmem.h> #include <public/version.h> +#include <public/pmu.h> #include <asm/hypercall.h> #include <xsm/xsm.h> @@ -139,6 +140,9 @@ do_tmem_op(extern long do_xenoprof_op (int op,XEN_GUEST_HANDLE_PARAM (void ) arg); +extern long +do_xenpmu_op (int op,XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg); +#ifdef CONFIG_COMPAT extern int
--
1.8.3.1
PATCH RESEND v5 10/17 x86/VPMU: Initialize PMU for PV guests
In reply to Boris OstrovskyCode for initializing/tearing down PMU for PV guests
--- xen/arch/x86/hvm/svm/svm.c | 6 ++- xen/arch/x86/hvm/svm/vpmu.c | 40 +++++++++--------- xen/arch/x86/hvm/vmx/vmx.c | 6 ++- xen/arch/x86/hvm/vmx/vpmu_core2.c | 51 +++++++++++++++-------- xen/arch/x86/hvm/vpmu.c | 85 ++++++++++++++++++++++++++++++++++++++- xen/common/event_channel.c | 1 + xen/include/asm-x86/hvm/vpmu.h | 1 + xen/include/public/pmu.h | 2 + xen/include/public/xen.h | 1 + xen/include/xen/softirq.h | 1 + 10 files changed, 154 insertions(+), 40 deletions(-)
xen/arch/x86/hvm/svm/svm.c +4 -2
@@ -1045,7 +1045,8 @@ static int svm_vcpu_initialise(struct vcpu *v)return rc; } -vpmu_initialise (v); +if (is_hvm_domain (v->domain) ) +vpmu_initialise (v);svm_guest_osvw_init (v);
@@ -1054,7 +1055,8 @@ static int svm_vcpu_initialise(struct vcpu *v)static void svm_vcpu_destroy (struct vcpu *v) { -vpmu_destroy (v); +if (is_hvm_domain (v->domain) ) +vpmu_destroy (v);svm_destroy_vmcb (v);passive_domain_destroy (v); }
xen/arch/x86/hvm/svm/vpmu.c +22 -18
@@ -381,16 +381,21 @@ static int amd_vpmu_initialise(struct vcpu *v) } } - ctxt =xzalloc_bytes (sizeof (struct xen_pmu_amd_ctxt ) + -sizeof (uint64_t ) *AMD_MAX_COUNTERS + -sizeof (uint64_t ) *AMD_MAX_COUNTERS ); -if ( !ctxt ) +if ( !is_pv_domain (v->domain) ) { -gdprintk (XENLOG_WARNING ,"Insufficient memory for PMU, " -" PMU feature is unavailable on domain %d vcpu %d.\n" , - v->vcpu_id, v->domain->domain_id); -return -ENOMEM ; + ctxt =xzalloc_bytes (sizeof (struct xen_pmu_amd_ctxt ) + +sizeof (uint64_t ) *AMD_MAX_COUNTERS + +sizeof (uint64_t ) *AMD_MAX_COUNTERS ); +if ( !ctxt ) + { +gdprintk (XENLOG_WARNING ,"Insufficient memory for PMU, " +" PMU feature is unavailable on domain %d vcpu %d.\n" , + v->vcpu_id, v->domain->domain_id); +return -ENOMEM ; + } } +else + ctxt = &v->arch.vpmu.xenpmu_data->pmu.c.amd; ctxt->counters =sizeof (struct xen_pmu_amd_ctxt ); ctxt->ctrls = ctxt->counters +sizeof (uint64_t ) *AMD_MAX_COUNTERS ;
@@ -407,18 +412,17 @@ static void amd_vpmu_destroy(struct vcpu *v)if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )return ; -if (is_hvm_domain (v->domain) && - ((struct xen_pmu_amd_ctxt *)vpmu->context)->msr_bitmap_set ) -amd_vpmu_unset_msr_bitmap (v); - -xfree (vpmu->context); -vpmu_reset (vpmu,VPMU_CONTEXT_ALLOCATED ); - -if (vpmu_is_set (vpmu,VPMU_RUNNING ) ) +if (is_hvm_domain (v->domain) ) { -vpmu_reset (vpmu,VPMU_RUNNING ); -release_pmu_ownship (PMU_OWNER_HVM ); +if ( ((struct xen_pmu_amd_ctxt *)vpmu->context)->msr_bitmap_set ) +amd_vpmu_unset_msr_bitmap (v); + +xfree (vpmu->context); } + + vpmu->context =NULL ; +vpmu_clear (vpmu); +release_pmu_ownship (PMU_OWNER_HVM ); }/* VPMU part of the 'q' keyhandler */
xen/arch/x86/hvm/vmx/vmx.c +4 -2
@@ -112,7 +112,8 @@ static int vmx_vcpu_initialise(struct vcpu *v)return rc; } -vpmu_initialise (v); +if (is_hvm_domain (v->domain) ) +vpmu_initialise (v);vmx_install_vlapic_mapping (v);
@@ -126,7 +127,8 @@ static int vmx_vcpu_initialise(struct vcpu *v)static void vmx_vcpu_destroy (struct vcpu *v) {vmx_destroy_vmcs (v); -vpmu_destroy (v); +if (is_hvm_domain (v->domain) ) +vpmu_destroy (v);passive_domain_destroy (v); }
xen/arch/x86/hvm/vmx/vpmu_core2.c +34 -17
73 lines not on this page · raw message
xen/arch/x86/hvm/vpmu.c +84 -1
114 lines not on this page · raw message
xen/common/event_channel.c +1 -0
@@ -108,6 +108,7 @@ static int virq_is_global(uint32_t virq)case VIRQ_TIMER :case VIRQ_DEBUG :case VIRQ_XENOPROF : +case VIRQ_XENPMU : rc =0 ;break ; case VIRQ_ARCH_0 ... VIRQ_ARCH_7:
xen/include/asm-x86/hvm/vpmu.h +1 -0
@@ -60,6 +60,7 @@ struct vpmu_struct {u32 hw_lapic_lvtpc;void *context;struct arch_vpmu_ops *arch_vpmu_ops; +xen_pmu_data_t *xenpmu_data; };/* VPMU states */
xen/include/public/pmu.h +2 -0
@@ -25,6 +25,8 @@#define XENPMU_mode_set 1#define XENPMU_feature_get 2#define XENPMU_feature_set 3 +#define XENPMU_init 4 +#define XENPMU_finish 5/* ` } */ /* Parameters structure for HYPERVISOR_xenpmu_op call */
xen/include/public/xen.h +1 -0
@@ -161,6 +161,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);#define VIRQ_MEM_EVENT 10/* G. (DOM0) A memory event has occured */ #define VIRQ_XC_RESERVED 11/* G. Reserved for XenClient */ #define VIRQ_ENOMEM 12/* G. (DOM0) Low on heap memory */ +#define VIRQ_XENPMU 13/* V. PMC interrupt */ /* Architecture-specific VIRQ definitions. */ #define VIRQ_ARCH_0 16
xen/include/xen/softirq.h +1 -0
@@ -8,6 +8,7 @@ enum {NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ ,RCU_SOFTIRQ ,TASKLET_SOFTIRQ , +PMU_SOFTIRQ , NR_COMMON_SOFTIRQS };
Signature · 1 line
1.8.3.1
Re: [PATCH v5 RESEND 10/17] x86/VPMU: Initialize PMU for PV guests
Quoted 6 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:51 PMCode for initializing/tearing down PMU for PV guests
Signed-off-by Boris Ostrovsky <[email protected]>
Quoted 408 lines
--- xen/arch/x86/hvm/svm/svm.c | 6 ++- xen/arch/x86/hvm/svm/vpmu.c | 40 +++++++++--------- xen/arch/x86/hvm/vmx/vmx.c | 6 ++- xen/arch/x86/hvm/vmx/vpmu_core2.c | 51 +++++++++++++++-------- xen/arch/x86/hvm/vpmu.c | 85 ++++++++++++++++++++++++++++++++++++++- xen/common/event_channel.c | 1 + xen/include/asm-x86/hvm/vpmu.h | 1 + xen/include/public/pmu.h | 2 + xen/include/public/xen.h | 1 + xen/include/xen/softirq.h | 1 + 10 files changed, 154 insertions(+), 40 deletions(-)xen/arch/x86/hvm/svm/svm.c +4
-2@@ -1045,7 +1045,8 @@ static int svm_vcpu_initialise(struct vcpu *v)return rc; } -vpmu_initialise (v); +if (is_hvm_domain (v->domain) ) +vpmu_initialise (v);svm_guest_osvw_init (v);@@ -1054,7 +1055,8 @@ static int svm_vcpu_initialise(struct vcpu *v)static void svm_vcpu_destroy (struct vcpu *v) { -vpmu_destroy (v); +if (is_hvm_domain (v->domain) ) +vpmu_destroy (v);svm_destroy_vmcb (v);passive_domain_destroy (v); }xen/arch/x86/hvm/svm/vpmu.c +23
-18@@ -381,16 +381,21 @@ static int amd_vpmu_initialise(struct vcpu *v) } } - ctxt =xzalloc_bytes (sizeof (struct xen_pmu_amd_ctxt ) + -sizeof (uint64_t ) *AMD_MAX_COUNTERS + -sizeof (uint64_t ) *AMD_MAX_COUNTERS ); -if ( !ctxt ) +if ( !is_pv_domain (v->domain) ) { -gdprintk (XENLOG_WARNING ,"Insufficient memory for PMU, " -" PMU feature is unavailable on domain %d vcpu %d.\n" , - v->vcpu_id, v->domain->domain_id); -return -ENOMEM ; + ctxt =xzalloc_bytes (sizeof (struct xen_pmu_amd_ctxt ) + + sizeof(uint64_t) * AMD_MAX_COUNTERS + +sizeof (uint64_t ) *AMD_MAX_COUNTERS ); +if ( !ctxt ) + { +gdprintk (XENLOG_WARNING ,"Insufficient memory for PMU, " + " PMU feature is unavailable on domain %d vcpu %d.\n", + v->vcpu_id, v->domain->domain_id); +return -ENOMEM ; + } } +else + ctxt = &v->arch.vpmu.xenpmu_data->pmu.c.amd; ctxt->counters =sizeof (struct xen_pmu_amd_ctxt ); ctxt->ctrls = ctxt->counters +sizeof (uint64_t ) *AMD_MAX_COUNTERS ;@@ -407,18 +412,17 @@ static void amd_vpmu_destroy(struct vcpu *v)if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )return ; -if (is_hvm_domain (v->domain) && - ((struct xen_pmu_amd_ctxt *)vpmu->context)->msr_bitmap_set ) -amd_vpmu_unset_msr_bitmap (v); - -xfree (vpmu->context); -vpmu_reset (vpmu,VPMU_CONTEXT_ALLOCATED ); - -if (vpmu_is_set (vpmu,VPMU_RUNNING ) ) +if (is_hvm_domain (v->domain) ) { -vpmu_reset (vpmu,VPMU_RUNNING ); -release_pmu_ownship (PMU_OWNER_HVM ); +if ( ((struct xen_pmu_amd_ctxt *)vpmu->context)->msr_bitmap_set ) +amd_vpmu_unset_msr_bitmap (v); + +xfree (vpmu->context); } + + vpmu->context =NULL ; +vpmu_clear (vpmu); +release_pmu_ownship (PMU_OWNER_HVM ); }/* VPMU part of the 'q' keyhandler */
xen/arch/x86/hvm/vmx/vmx.c +4
-2@@ -112,7 +112,8 @@ static int vmx_vcpu_initialise(struct vcpu *v)return rc; } -vpmu_initialise (v); +if (is_hvm_domain (v->domain) ) +vpmu_initialise (v);vmx_install_vlapic_mapping (v);@@ -126,7 +127,8 @@ static int vmx_vcpu_initialise(struct vcpu *v)static void vmx_vcpu_destroy (struct vcpu *v) {vmx_destroy_vmcs (v); -vpmu_destroy (v); +if (is_hvm_domain (v->domain) ) +vpmu_destroy (v);passive_domain_destroy (v); }xen/arch/x86/hvm/vmx/vpmu_core2.c +13
-13@@ -358,22 +358,30 @@ static int core2_vpmu_alloc_resource(struct vcpu *v)struct vpmu_struct *vpmu =vcpu_vpmu (v);struct xen_pmu_intel_ctxt *core2_vpmu_cxt; -if ( !acquire_pmu_ownership (PMU_OWNER_HVM ) ) -return 0 ; +if ( !is_pv_domain (v->domain) ) + { +if ( !acquire_pmu_ownership (PMU_OWNER_HVM ) ) +return 0 ; -wrmsrl (MSR_CORE_PERF_GLOBAL_CTRL ,0 ); -if (vmx_add_host_load_msr (MSR_CORE_PERF_GLOBAL_CTRL ) ) - goto out_err; +wrmsrl (MSR_CORE_PERF_GLOBAL_CTRL ,0 ); +if (vmx_add_host_load_msr (MSR_CORE_PERF_GLOBAL_CTRL ) ) + goto out_err; -if (vmx_add_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL ) ) - goto out_err; -vmx_write_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL ,0 ); +if (vmx_add_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL ) ) + goto out_err; +vmx_write_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL ,0 ); - core2_vpmu_cxt =xzalloc_bytes (sizeof (struct xen_pmu_intel_ctxt ) + -sizeof (uint64_t ) * fixed_pmc_cnt + -sizeof (struct xen_pmu_cntr_pair ) * arch_pmc_cnt); -if ( !core2_vpmu_cxt ) - goto out_err; + core2_vpmu_cxt = xzalloc_bytes(sizeof(struct xen_pmu_intel_ctxt) + + sizeof(uint64_t) *
fixed_pmc_cnt+
+ sizeof(structxen_pmu_cntr_pair) *arch_pmc_cnt);xen/arch/x86/hvm/vmx/vpmu_core2.c +21
-4+if ( !core2_vpmu_cxt ) + goto out_err; + } +else + { + core2_vpmu_cxt = &v->arch.vpmu.xenpmu_data->pmu.c.intel; +vpmu_set (vpmu,VPMU_CONTEXT_ALLOCATED ); + } core2_vpmu_cxt->fixed_counters =sizeof (struct xen_pmu_intel_ctxt ); core2_vpmu_cxt->arch_counters = core2_vpmu_cxt->fixed_counters +@@ -753,6 +761,10 @@ func_out: fixed_pmc_cnt =core2_get_fixed_pmc_count ();check_pmc_quirk (); +/* PV domains can allocate resources immediately */ +if (is_pv_domain (v->domain) && !core2_vpmu_alloc_resource (v) ) +return 1 ; +return 0 ; }@@ -763,11 +775,16 @@ static void core2_vpmu_destroy(struct vcpu *v)if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )return ; -xfree (vpmu->context); -if ( cpu_has_vmx_msr_bitmap &&is_hvm_domain (v->domain) ) -core2_vpmu_unset_msr_bitmap (v->arch.hvm_vmx.msr_bitmap); +if (is_hvm_domain (v->domain) ) + { +xfree (vpmu->context); +if ( cpu_has_vmx_msr_bitmap ) +core2_vpmu_unset_msr_bitmap (v->arch.hvm_vmx.msr_bitmap); + } +release_pmu_ownship (PMU_OWNER_HVM ); -vpmu_reset (vpmu,VPMU_CONTEXT_ALLOCATED ); + vpmu->context =NULL ; +vpmu_clear (vpmu); }struct
arch_vpmu_opscore2_vpmu_ops= {xen/arch/x86/hvm/vpmu.c +10
-0@@ -21,10 +21,14 @@#include <xen/config.h> #include <xen/sched.h> #include <xen/xenoprof.h> +#include <xen/event.h> +#include <xen/softirq.h> +#include <xen/hypercall.h> #include <xen/guest_access.h> #include <asm/regs.h> #include <asm/types.h> #include <asm/msr.h> +#include <asm/p2m.h> #include <asm/hvm/support.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/vmx/vmcs.h> @@ -267,7 +271,13 @@ void vpmu_destroy(struct vcpu *v)struct vpmu_struct *vpmu =vcpu_vpmu (v);if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_destroy ) + { +/* Unload VPMU first. This will stop counters */ +on_selected_cpus (cpumask_of (vcpu_vpmu (v)->last_pcpu), + vpmu_save_force, (void *)v,1 ); + vpmu->arch_vpmu_ops->arch_vpmu_destroy (v); + } }/* Dump some vpmu informations on console. Used in keyhandler
dump_domains(). */xen/arch/x86/hvm/vpmu.c +61
-0@@ -312,6 +322,67 @@ static void vpmu_unload_all(void) } } +static int pvpmu_init (struct domain *d,xen_pmu_params_t *params) +{ +struct vcpu *v; +struct page_info *page; +uint64_t gfn = params->d.val; + +if ( !is_pv_domain (d) ) +return -EINVAL ; + +if ( params->vcpu <0 || params->vcpu >= d->max_vcpus ) +return -EINVAL ; + + page =get_page_from_gfn (d, gfn,NULL ,P2M_ALLOC ); +if ( !page ) +return -EINVAL ; + +if ( !get_page_type (page, PGT_writable_page) ) + { +put_page (page); +return -EINVAL ; + } + + v = d->vcpu[params->vcpu]; + v->arch.vpmu.xenpmu_data =__map_domain_page_global (page); +if ( !v->arch.vpmu.xenpmu_data ) + { +put_page_and_type (page); +return -EINVAL ; + } + +vpmu_initialise (v); + +return 0 ; +} + +static void pvpmu_finish (struct domain *d,xen_pmu_params_t *params) +{ +struct vcpu *v; +uint64_t mfn; + +if ( params->vcpu <0 || params->vcpu >= d->max_vcpus ) +return ; + + v = d->vcpu[params->vcpu]; +if (v != current) +vcpu_pause (v); + +if ( v->arch.vpmu.xenpmu_data ) + { + mfn =domain_page_map_to_mfn (v->arch.vpmu.xenpmu_data); +if (mfn_valid (mfn) ) + { +unmap_domain_page_global (v->arch.vpmu.xenpmu_data); +put_page_and_type (mfn_to_page (mfn)); + } + } +vpmu_destroy (v); + +if (v != current) +vcpu_unpause (v); +}long do_xenpmu_op (int op,XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg){
xen/arch/x86/hvm/vpmu.c +13
-1@@ -372,7 +443,19 @@ long do_xenpmu_op(int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg)return -EFAULT ; ret =0 ;break ; - } + +case XENPMU_init: +if (copy_from_guest (&pmu_params, arg,1 ) ) +return -EFAULT ; + ret =pvpmu_init (current->domain, &pmu_params); +break ; + +case XENPMU_finish: +if (copy_from_guest (&pmu_params, arg,1 ) ) +return -EFAULT ; +pvpmu_finish (current->domain, &pmu_params); +break ; + }return ret;}
xen/common/event_channel.c +1
-0@@ -108,6 +108,7 @@ static int virq_is_global(uint32_t virq)case VIRQ_TIMER :case VIRQ_DEBUG :case VIRQ_XENOPROF : +case VIRQ_XENPMU : rc =0 ;break ; case VIRQ_ARCH_0 ... VIRQ_ARCH_7:xen/include/asm-x86/hvm/vpmu.h +1
-0@@ -60,6 +60,7 @@ struct vpmu_struct {u32 hw_lapic_lvtpc;void *context;struct arch_vpmu_ops *arch_vpmu_ops; +xen_pmu_data_t *xenpmu_data; };/* VPMU states */ xen/include/public/pmu.h +2
-0@@ -25,6 +25,8 @@#define XENPMU_mode_set 1#define XENPMU_feature_get 2#define XENPMU_feature_set 3 +#define XENPMU_init 4 +#define XENPMU_finish 5/* ` } */ /* Parameters structure for HYPERVISOR_xenpmu_op call */ xen/include/public/xen.h +1
-0@@ -161,6 +161,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);#define VIRQ_MEM_EVENT 10/* G. (DOM0) A memory event has occured */ #define VIRQ_XC_RESERVED 11/* G. Reserved for XenClient */ #define VIRQ_ENOMEM 12/* G. (DOM0) Low on heap memory */ +#define VIRQ_XENPMU 13/* V. PMC interrupt */
/* Architecture-specific VIRQ definitions. */
#defineVIRQ_ARCH_016xen/include/xen/softirq.h +1
-1@@ -8,6 +8,7 @@ enum {NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ ,RCU_SOFTIRQ ,TASKLET_SOFTIRQ , +PMU_SOFTIRQ , NR_COMMON_SOFTIRQS }; --1.8.3.1
PATCH RESEND v5 11/17 x86/VPMU: Add support for PMU register handling on PV guests
In reply to Boris OstrovskyIntercept accesses to PMU MSRs and process them in VPMU module.
Dump VPMU state for all domains (HVM and PV) when requested.
--- xen/arch/x86/domain.c | 3 +- xen/arch/x86/hvm/vmx/vpmu_core2.c | 60 ++++++++++++++++++++++++++++++++------- xen/arch/x86/hvm/vpmu.c | 7 +++++ xen/arch/x86/traps.c | 31 +++++++++++++++++++- xen/include/public/pmu.h | 1 + 5 files changed, 89 insertions(+), 13 deletions(-)
xen/arch/x86/domain.c +1 -2
@@ -1995,8 +1995,7 @@ void arch_dump_vcpu_info(struct vcpu *v) {paging_dump_vcpu_info (v); -if (is_hvm_vcpu (v) ) -vpmu_dump (v); +vpmu_dump (v); } void domain_cpuid(
xen/arch/x86/hvm/vmx/vpmu_core2.c +50 -10
149 lines not on this page · raw message
xen/arch/x86/hvm/vpmu.c +7 -0
@@ -455,6 +455,13 @@ long do_xenpmu_op(int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg)return -EFAULT ;pvpmu_finish (current->domain, &pmu_params);break ; + +case XENPMU_lvtpc_set: +if ( current->arch.vpmu.xenpmu_data ==NULL ) +return -EINVAL ; +vpmu_lvtpc_update (current->arch.vpmu.xenpmu_data->pmu.l.lapic_lvtpc); + ret =0 ; +break ; }return ret;
xen/arch/x86/traps.c +30 -1
@@ -72,6 +72,7 @@#include <asm/apic.h> #include <asm/mc146818rtc.h> #include <asm/hpet.h> +#include <asm/hvm/vpmu.h> #include <public/arch-x86/cpuid.h> #include <xsm/xsm.h>
@@ -865,8 +866,10 @@ void pv_cpuid(struct cpu_user_regs *regs)__clear_bit (X86_FEATURE_TOPOEXT %32 , &c);break ; +case 0x0000000a :/* Architectural Performance Monitor Features (Intel) */ +break ; +case 0x00000005 :/* MONITOR/MWAIT */ -case 0x0000000a :/* Architectural Performance Monitor Features */ case 0x0000000b :/* Extended Topology Enumeration */ case 0x8000000a :/* SVM revision and features */ case 0x8000001b :/* Instruction Based Sampling */
@@ -882,6 +885,8 @@ void pv_cpuid(struct cpu_user_regs *regs) } out: +vpmu_do_cpuid (regs->eax, &a, &b, &c, &d); + regs->eax = a; regs->ebx = b; regs->ecx = c;
@@ -2497,6 +2502,14 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)if (wrmsr_safe (regs->ecx, msr_content) !=0 ) goto fail;break ; + case MSR_P6_PERFCTR0...MSR_P6_PERFCTR1: + case MSR_P6_EVNTSEL0...MSR_P6_EVNTSEL1: + case MSR_CORE_PERF_FIXED_CTR0...MSR_CORE_PERF_FIXED_CTR2: + case MSR_CORE_PERF_FIXED_CTR_CTRL...MSR_CORE_PERF_GLOBAL_OVF_CTRL: + case MSR_AMD_FAM15H_EVNTSEL0...MSR_AMD_FAM15H_PERFCTR5: +if ( !vpmu_do_wrmsr (regs->ecx, msr_content) ) + goto invalid; +break ;default :if (wrmsr_hypervisor_regs (regs->ecx, msr_content) ==1 )break ;
@@ -2584,6 +2597,22 @@ static int emulate_privileged_op(struct cpu_user_regs *regs) regs->eax = (uint32_t )msr_content; regs->edx = (uint32_t )(msr_content >>32 );break ; +case MSR_IA32_PERF_CAPABILITIES : +/* No extra capabilities are supported */ + regs->eax = regs->edx =0 ; +break ; + case MSR_P6_PERFCTR0...MSR_P6_PERFCTR1: + case MSR_P6_EVNTSEL0...MSR_P6_EVNTSEL1: + case MSR_CORE_PERF_FIXED_CTR0...MSR_CORE_PERF_FIXED_CTR2: + case MSR_CORE_PERF_FIXED_CTR_CTRL...MSR_CORE_PERF_GLOBAL_OVF_CTRL: + case MSR_AMD_FAM15H_EVNTSEL0...MSR_AMD_FAM15H_PERFCTR5: +if (vpmu_do_rdmsr (regs->ecx, &msr_content) ) + { + regs->eax = (uint32_t )msr_content; + regs->edx = (uint32_t )(msr_content >>32 ); +break ; + } + goto rdmsr_normal;default :if (rdmsr_hypervisor_regs (regs->ecx, &val) ) {
xen/include/public/pmu.h +1 -0
@@ -27,6 +27,7 @@#define XENPMU_feature_set 3#define XENPMU_init 4#define XENPMU_finish 5 +#define XENPMU_lvtpc_set 6/* ` } */ /* Parameters structure for HYPERVISOR_xenpmu_op call */
Signature · 1 line
1.8.3.1
Re: [PATCH v5 RESEND 11/17] x86/VPMU: Add support for PMU register handling on PV guests
Quoted 7 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:51 PMIntercept accesses to PMU MSRs and process them in VPMU module.
Dump VPMU state for all domains (HVM and PV) when requested.
Quoted 329 lines
Signed-off-by Boris Ostrovsky <[email protected]>--- xen/arch/x86/domain.c | 3 +- xen/arch/x86/hvm/vmx/vpmu_core2.c | 60 ++++++++++++++++++++++++++++++++------- xen/arch/x86/hvm/vpmu.c | 7 +++++ xen/arch/x86/traps.c | 31 +++++++++++++++++++- xen/include/public/pmu.h | 1 + 5 files changed, 89 insertions(+), 13 deletions(-)xen/arch/x86/domain.c +1
-2@@ -1995,8 +1995,7 @@ void arch_dump_vcpu_info(struct vcpu *v) {paging_dump_vcpu_info (v); -if (is_hvm_vcpu (v) ) -vpmu_dump (v); +vpmu_dump (v); } void domain_cpuid(xen/arch/x86/hvm/vmx/vpmu_core2.c +7
-1@@ -27,6 +27,7 @@#include <asm/regs.h> #include <asm/types.h> #include <asm/apic.h> +#include <asm/traps.h> #include <asm/msr.h> #include <asm/msr-index.h> #include <asm/hvm/support.h> @@ -297,19 +298,26 @@ static inline void __core2_vpmu_save(struct vcpu *v)rdmsrl (MSR_CORE_PERF_FIXED_CTR0 + i, fixed_counters[i]);for ( i =0 ; i < arch_pmc_cnt; i++ )rdmsrl (MSR_IA32_PERFCTR0 + i, xen_pmu_cntr_pair[i].counter); + +if (is_pv_domain (v->domain) ) +rdmsrl (MSR_CORE_PERF_GLOBAL_STATUS , core2_vpmu_cxt->global_status); }static int core2_vpmu_save (struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v); +if (is_pv_domain (v->domain) ) +wrmsrl (MSR_CORE_PERF_GLOBAL_CTRL ,0 ); +if ( !vpmu_is_set_all (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ) )return 0 ;__core2_vpmu_save (v);/* Unset PMU MSR bitmap to trap lazy load. */ - if ( !vpmu_is_set(vpmu, VPMU_RUNNING) &&
cpu_has_vmx_msr_bitmap)
+ if ( !vpmu_is_set(vpmu,VPMU_RUNNING) &&cpu_has_vmx_msr_bitmapxen/arch/x86/hvm/vmx/vpmu_core2.c +8
-0+ && !is_pv_domain(v->domain) )core2_vpmu_unset_msr_bitmap (v->arch.hvm_vmx.msr_bitmap);return 1 ;@@ -339,6 +347,13 @@ static inline void __core2_vpmu_load(struct vcpu *v)wrmsrl (MSR_CORE_PERF_FIXED_CTR_CTRL , core2_vpmu_cxt->fixed_ctrl);wrmsrl (MSR_IA32_DS_AREA , core2_vpmu_cxt->ds_area);wrmsrl (MSR_IA32_PEBS_ENABLE , core2_vpmu_cxt->pebs_enable); + +if (is_pv_domain (v->domain) ) + { +wrmsrl (MSR_CORE_PERF_GLOBAL_OVF_CTRL , core2_vpmu_cxt->global_ovf_ctrl); + core2_vpmu_cxt->global_ovf_ctrl =0 ; +wrmsrl (MSR_CORE_PERF_GLOBAL_CTRL , core2_vpmu_cxt->global_ctrl); + }}
static void
core2_vpmu_load(struct vcpu *v)xen/arch/x86/hvm/vmx/vpmu_core2.c +8
-0@@ -426,6 +441,14 @@ static int core2_vpmu_msr_common_check(u32 msr_index, int *type, int *index)return 1 ; } +static void inject_trap (struct vcpu *v,unsigned int trapno) +{ +if ( !is_pv_domain (v->domain) ) +hvm_inject_hw_exception (trapno,0 ); +else +send_guest_trap (v->domain, v->vcpu_id, trapno); +} +static int core2_vpmu_do_wrmsr (unsigned int msr,uint64_t msr_content) {u64 global_ctrl, non_global_ctrl;xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-1@@ -452,7 +475,7 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)if (vpmu_is_set (vpmu,VPMU_CPU_HAS_BTS ) )return 1 ; gdprintk(XENLOG_WARNING, "Debug Store is not supported on this cpu\n"); - hvm_inject_hw_exception(TRAP_gp_fault, 0); + inject_trap(v, TRAP_gp_fault);return 0 ;} }xen/arch/x86/hvm/vmx/vpmu_core2.c +2
-1@@ -464,11 +487,12 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) {case MSR_CORE_PERF_GLOBAL_OVF_CTRL : core2_vpmu_cxt->global_status &= ~msr_content; +wrmsrl (MSR_CORE_PERF_GLOBAL_OVF_CTRL , msr_content);return 1 ;case MSR_CORE_PERF_GLOBAL_STATUS :gdprintk (XENLOG_INFO ,"Can not write readonly MSR: " "MSR_PERF_GLOBAL_STATUS(0x38E)!\n" ); -hvm_inject_hw_exception (TRAP_gp_fault,0 ); +inject_trap (v, TRAP_gp_fault);return 1 ;case MSR_IA32_PEBS_ENABLE :if (
msr_content& 1 )xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-1@@ -484,7 +508,7 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) gdprintk(XENLOG_WARNING,"Illegal address for IA32_DS_AREA: %#" PRIx64"x\n" , msr_content); -hvm_inject_hw_exception (TRAP_gp_fault,0 ); +inject_trap (v, TRAP_gp_fault);return 1 ;} core2_vpmu_cxt->ds_area = msr_content;xen/arch/x86/hvm/vmx/vpmu_core2.c +5
-1@@ -509,10 +533,14 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) non_global_ctrl >>= FIXED_CTR_CTRL_BITS; global_ctrl >>=1 ; } + core2_vpmu_cxt->global_ctrl = msr_content;break ;case MSR_CORE_PERF_FIXED_CTR_CTRL : non_global_ctrl = msr_content; -vmx_read_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , &global_ctrl); +if ( !is_pv_domain (v->domain) ) +vmx_read_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , &global_ctrl); +else +rdmsrl (MSR_CORE_PERF_GLOBAL_CTRL , global_ctrl);global_ctrl >>= 32; for ( i = 0; i < fixed_pmc_cnt; i++ ) {xen/arch/x86/hvm/vmx/vpmu_core2.c +4
-1@@ -529,7 +557,10 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)struct xen_pmu_cntr_pair *xen_pmu_cntr_pair =vpmu_reg_pointer (core2_vpmu_cxt, arch_counters); -vmx_read_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , &global_ctrl); +if ( !is_pv_domain (v->domain) ) +vmx_read_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , &global_ctrl); +else +rdmsrl (MSR_CORE_PERF_GLOBAL_CTRL , global_ctrl);xen_pmu_cntr_pair[tmp].control = msr_content; for ( i = 0; i < arch_pmc_cnt && !pmu_enable; i++ ) pmu_enable += (global_ctrl >> i) &xen/arch/x86/hvm/vmx/vpmu_core2.c +9
-3@@ -568,13 +599,19 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) inject_gp =1 ;break ; } -if (inject_gp) -hvm_inject_hw_exception (TRAP_gp_fault,0 ); + +if (inject_gp) +inject_trap (v, TRAP_gp_fault);else wrmsrl (msr, msr_content); }else -vmx_write_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , msr_content); + { +if ( !is_pv_domain (v->domain) ) +vmx_write_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , msr_content); +else +wrmsrl (MSR_CORE_PERF_GLOBAL_CTRL , msr_content); + }return 1;}
xen/arch/x86/hvm/vmx/vpmu_core2.c +4
-1@@ -598,7 +635,10 @@ static int core2_vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) *msr_content = core2_vpmu_cxt->global_status;break ;case MSR_CORE_PERF_GLOBAL_CTRL : -vmx_read_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , msr_content); +if ( !is_pv_domain (v->domain) ) +vmx_read_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , msr_content); +else +rdmsrl (MSR_CORE_PERF_GLOBAL_CTRL , *msr_content);break; default: rdmsrl(msr, *msr_content);xen/arch/x86/hvm/vpmu.c +7
-0@@ -455,6 +455,13 @@ long do_xenpmu_op(int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg)return -EFAULT ;pvpmu_finish (current->domain, &pmu_params);break ; + +case XENPMU_lvtpc_set: +if ( current->arch.vpmu.xenpmu_data ==NULL ) +return -EINVAL ; +vpmu_lvtpc_update (current->arch.vpmu.xenpmu_data->pmu.l.lapic_lvtpc); + ret =0 ; +break ; }return ret;xen/arch/x86/traps.c +4
-1@@ -72,6 +72,7 @@#include <asm/apic.h> #include <asm/mc146818rtc.h> #include <asm/hpet.h> +#include <asm/hvm/vpmu.h> #include <public/arch-x86/cpuid.h> #include <xsm/xsm.h> @@ -865,8 +866,10 @@ void pv_cpuid(struct cpu_user_regs *regs)__clear_bit (X86_FEATURE_TOPOEXT %32 , &c);break ; +case 0x0000000a :/* Architectural Performance Monitor Features (Intel) */ +break ; +case 0x00000005 :/* MONITOR/MWAIT */ -case 0x0000000a :/* Architectural Performance Monitor Features */ case 0x0000000b :/* Extended Topology Enumeration */ case 0x8000000a :/* SVM revision and features */ case 0x8000001b: /* Instruction Based Sampling */xen/arch/x86/traps.c +5
-0@@ -882,6 +885,8 @@ void pv_cpuid(struct cpu_user_regs *regs) } out: +vpmu_do_cpuid (regs->eax, &a, &b, &c, &d); + regs->eax = a; regs->ebx = b; regs->ecx = c;@@ -2497,6 +2502,14 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)if (wrmsr_safe (regs->ecx, msr_content) !=0 ) goto fail;break ; + case MSR_P6_PERFCTR0...MSR_P6_PERFCTR1: + case MSR_P6_EVNTSEL0...MSR_P6_EVNTSEL1: + caseMSR_CORE_PERF_FIXED_CTR0...MSR_CORE_PERF_FIXED_CTR2:
+ case
MSR_CORE_PERF_FIXED_CTR_CTRL...MSR_CORE_PERF_GLOBAL_OVF_CTRL:
+ case
MSR_AMD_FAM15H_EVNTSEL0...MSR_AMD_FAM15H_PERFCTR5:xen/arch/x86/traps.c +10
-0+if ( !vpmu_do_wrmsr (regs->ecx, msr_content) ) + goto invalid; +break ;default :if (wrmsr_hypervisor_regs (regs->ecx, msr_content) ==1 )break ;@@ -2584,6 +2597,22 @@ static int emulate_privileged_op(struct cpu_user_regs *regs) regs->eax = (uint32_t)msr_content; regs->edx = (uint32_t )(msr_content >>32 );break ; +case MSR_IA32_PERF_CAPABILITIES : +/* No extra capabilities are supported */ + regs->eax = regs->edx =0 ; +break ; + case MSR_P6_PERFCTR0...MSR_P6_PERFCTR1: + case MSR_P6_EVNTSEL0...MSR_P6_EVNTSEL1: + caseMSR_CORE_PERF_FIXED_CTR0...MSR_CORE_PERF_FIXED_CTR2:
+ case
MSR_CORE_PERF_FIXED_CTR_CTRL...MSR_CORE_PERF_GLOBAL_OVF_CTRL:
+ case
MSR_AMD_FAM15H_EVNTSEL0...MSR_AMD_FAM15H_PERFCTR5:xen/arch/x86/traps.c +7
-0+if (vpmu_do_rdmsr (regs->ecx, &msr_content) ) + { + regs->eax = (uint32_t )msr_content; + regs->edx = (uint32_t )(msr_content >>32 ); +break ; + } + goto rdmsr_normal;default :if (rdmsr_hypervisor_regs (regs->ecx, &val) ) {xen/include/public/pmu.h +1
-1@@ -27,6 +27,7 @@#define XENPMU_feature_set 3#define XENPMU_init 4#define XENPMU_finish 5 +#define XENPMU_lvtpc_set 6/* ` } */ /* Parameters structure for HYPERVISOR_xenpmu_op call */ --1.8.3.1
PATCH RESEND v5 12/17 x86/VPMU: Handle PMU interrupts for PV guests
In reply to Boris OstrovskyAdd support for handling PMU interrupts for PV guests.
VPMU for the interrupted VCPU is unloaded until the guest issues XENPMU_flush hypercall. This allows the guest to access PMU MSR values that are stored in VPMU context which is shared between hypervisor and domain, thus avoiding traps to hypervisor.
--- xen/arch/x86/hvm/vpmu.c | 110 ++++++++++++++++++++++++++++++++++++++++++++--- xen/include/public/pmu.h | 7 +++ 2 files changed, 112 insertions(+), 5 deletions(-)
xen/arch/x86/hvm/vpmu.c +105 -5
@@ -76,7 +76,12 @@ void vpmu_lvtpc_update(uint32_t val)struct vpmu_struct *vpmu =vcpu_vpmu (current); vpmu->hw_lapic_lvtpc =PMU_APIC_VECTOR | (val &APIC_LVT_MASKED ); -apic_write (APIC_LVTPC , vpmu->hw_lapic_lvtpc); + +/* Postpone APIC updates for PV guests if PMU interrupt is pending */ +if ( !is_pv_domain (current->domain) || + !(current->arch.vpmu.xenpmu_data && + current->arch.vpmu.xenpmu_data->pmu_flags &PMU_CACHED ) ) +apic_write (APIC_LVTPC , vpmu->hw_lapic_lvtpc); }int vpmu_do_wrmsr (unsigned int msr,uint64_t msr_content)
@@ -87,7 +92,23 @@ int vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)return 0 ;if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_wrmsr ) -return vpmu->arch_vpmu_ops->do_wrmsr (msr, msr_content); + { +int ret = vpmu->arch_vpmu_ops->do_wrmsr (msr, msr_content); + +/* +* We may have received a PMU interrupt during WRMSR handling +* and since do_wrmsr may load VPMU context we should save +* (and unload) it again. +*/ +if ( !is_hvm_domain (current->domain) && + (current->arch.vpmu.xenpmu_data->pmu_flags &PMU_CACHED ) ) + { +vpmu_set (vpmu,VPMU_CONTEXT_SAVE ); + vpmu->arch_vpmu_ops->arch_vpmu_save (current); +vpmu_reset (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ); + } +return ret; + }return 0 ; }
@@ -99,14 +120,86 @@ int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content)return 0 ;if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_rdmsr ) -return vpmu->arch_vpmu_ops->do_rdmsr (msr, msr_content); + { +int ret = vpmu->arch_vpmu_ops->do_rdmsr (msr, msr_content); + +if ( !is_hvm_domain (current->domain) && + (current->arch.vpmu.xenpmu_data->pmu_flags &PMU_CACHED ) ) + { +vpmu_set (vpmu,VPMU_CONTEXT_SAVE ); + vpmu->arch_vpmu_ops->arch_vpmu_save (current); +vpmu_reset (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ); + } +return ret; + }return 0 ; }int vpmu_do_interrupt (struct cpu_user_regs *regs) {struct vcpu *v = current; -struct vpmu_struct *vpmu =vcpu_vpmu (v); +struct vpmu_struct *vpmu; + +/* dom0 will handle this interrupt */ +if ( v->domain->domain_id >=DOMID_FIRST_RESERVED ) + v = dom0->vcpu[smp_processor_id () % dom0->max_vcpus]; + + vpmu =vcpu_vpmu (v); +if ( !is_hvm_domain (v->domain) ) + { +/* PV guest or dom0 is doing system profiling */ +const struct cpu_user_regs *gregs; +int err; + +if ( v->arch.vpmu.xenpmu_data->pmu_flags &PMU_CACHED ) +return 1 ; + +/* PV guest will be reading PMU MSRs from xenpmu_data */ +vpmu_set (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ); + err = vpmu->arch_vpmu_ops->arch_vpmu_save (v); +vpmu_reset (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ); + +/* Store appropriate registers in xenpmu_data */ +if (is_pv_32bit_domain (current->domain) ) + { +/* +* 32-bit dom0 cannot process Xen's addresses (which are 64 bit) +* and therefore we treat it the same way as a non-priviledged +* PV 32-bit domain. +*/ +struct compat_cpu_user_regs *cmp; + + gregs =guest_cpu_user_regs (); + + cmp = (void *)&v->arch.vpmu.xenpmu_data->pmu.r.regs; +XLAT_cpu_user_regs (cmp, gregs); +memcpy (&v->arch.vpmu.xenpmu_data->pmu.r.regs, + &cmp,sizeof (struct compat_cpu_user_regs )); + } +else if ( !is_control_domain (current->domain) && + !is_idle_vcpu (current) ) + { +/* PV guest */ + gregs =guest_cpu_user_regs (); +memcpy (&v->arch.vpmu.xenpmu_data->pmu.r.regs, + gregs,sizeof (struct cpu_user_regs )); + } +else +memcpy (&v->arch.vpmu.xenpmu_data->pmu.r.regs, + regs,sizeof (struct cpu_user_regs )); + + v->arch.vpmu.xenpmu_data->domain_id = current->domain->domain_id; + v->arch.vpmu.xenpmu_data->vcpu_id = current->vcpu_id; + v->arch.vpmu.xenpmu_data->pcpu_id =smp_processor_id (); + + v->arch.vpmu.xenpmu_data->pmu_flags |=PMU_CACHED ; +apic_write (APIC_LVTPC , vpmu->hw_lapic_lvtpc |APIC_LVT_MASKED ); + vpmu->hw_lapic_lvtpc |=APIC_LVT_MASKED ; + +send_guest_vcpu_virq (v,VIRQ_XENPMU ); + +return 1 ; + }if ( vpmu->arch_vpmu_ops ) {
@@ -225,7 +318,8 @@ void vpmu_load(struct vcpu *v)local_irq_enable ();/* Only when PMU is counting, we load PMU context immediately. */ -if ( !vpmu_is_set (vpmu,VPMU_RUNNING ) ) +if ( !vpmu_is_set (vpmu,VPMU_RUNNING ) || + (is_pv_domain (v->domain) && vpmu->xenpmu_data->pmu_flags &PMU_CACHED ) )return ;if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_load )
@@ -462,6 +556,12 @@ long do_xenpmu_op(int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg)vpmu_lvtpc_update (current->arch.vpmu.xenpmu_data->pmu.l.lapic_lvtpc); ret =0 ;break ; +case XENPMU_flush: + current->arch.vpmu.xenpmu_data->pmu_flags &= ~PMU_CACHED ; +vpmu_lvtpc_update (current->arch.vpmu.xenpmu_data->pmu.l.lapic_lvtpc); +vpmu_load (current); + ret =0 ; +break ; }return ret;
xen/include/public/pmu.h +7 -0
@@ -28,6 +28,7 @@#define XENPMU_init 4#define XENPMU_finish 5#define XENPMU_lvtpc_set 6 +#define XENPMU_flush 7/* Write cached MSR values to HW */ /* ` } */ /* Parameters structure for HYPERVISOR_xenpmu_op call */
@@ -65,6 +66,12 @@ DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t);*/ #define XENPMU_FEATURE_INTEL_BTS 1 +/* +* PMU MSRs are cached in the context so the PV guest doesn't need to trap to +* the hypervisor +*/ +#define PMU_CACHED 1 +/* Shared between hypervisor and PV domain */ struct xen_pmu_data {uint32_t domain_id;
Signature · 1 line
1.8.3.1
Re: [PATCH v5 RESEND 12/17] x86/VPMU: Handle PMU interrupts for PV guests
Quoted 28 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:51 PMAdd support for handling PMU interrupts for PV guests.
VPMU for the interrupted VCPU is unloaded until the guest issues
XENPMU_flush
hypercall. This allows the guest to access PMU MSR values that are stored in VPMU context which is shared between hypervisor and domain, thus avoiding traps to hypervisor.Signed-off-by Boris Ostrovsky <[email protected]>--- xen/arch/x86/hvm/vpmu.c | 110 ++++++++++++++++++++++++++++++++++++++++++++--- xen/include/public/pmu.h | 7 +++ 2 files changed, 112 insertions(+), 5 deletions(-)xen/arch/x86/hvm/vpmu.c +2
-1int vpmu_do_interrupt (struct cpu_user_regs *regs) {struct vcpu *v = current; -struct vpmu_struct *vpmu =vcpu_vpmu (v); +struct vpmu_struct *vpmu; +
xen/arch/x86/hvm/vpmu.c int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) · line 152
Quoted 10 lines
xen/arch/x86/hvm/vpmu.c +10
-0+/* dom0 will handle this interrupt */ +if ( v->domain->domain_id >=DOMID_FIRST_RESERVED ) + v = dom0->vcpu[smp_processor_id () % dom0->max_vcpus]; + + vpmu =vcpu_vpmu (v); +if ( !is_hvm_domain (v->domain) ) + { +/* PV guest or dom0 is doing system profiling */ +const struct cpu_user_regs *gregs; +int err;
a bit misleading. if non-dom0, it should be guest profiling only, right?
Re: [PATCH v5 RESEND 12/17] x86/VPMU: Handle PMU interrupts for PV guests
Quoted 31 lines · Kevin
Quoted 31 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:51 PMAdd support for handling PMU interrupts for PV guests.
VPMU for the interrupted VCPU is unloaded until the guest issues
XENPMU_flush
hypercall. This allows the guest to access PMU MSR values that are stored in VPMU context which is shared between hypervisor and domain, thus avoiding traps to hypervisor.Signed-off-by Boris Ostrovsky <[email protected]>--- xen/arch/x86/hvm/vpmu.c | 110 ++++++++++++++++++++++++++++++++++++++++++++--- xen/include/public/pmu.h | 7 +++ 2 files changed, 112 insertions(+), 5 deletions(-)xen/arch/x86/hvm/vpmu.c +5
-1int vpmu_do_interrupt (struct cpu_user_regs *regs) {struct vcpu *v = current; -struct vpmu_struct *vpmu =vcpu_vpmu (v); +struct vpmu_struct *vpmu; + +/* dom0 will handle this interrupt */ +if ( v->domain->domain_id >=DOMID_FIRST_RESERVED ) + v = dom0->vcpu[smp_processor_id () % dom0->max_vcpus];
Quoted 8 lines
xen/arch/x86/hvm/vpmu.c int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) · line 152
Quoted 7 lines
xen/arch/x86/hvm/vpmu.c +7
-0+ + vpmu =vcpu_vpmu (v); +if ( !is_hvm_domain (v->domain) ) + { +/* PV guest or dom0 is doing system profiling */ +const struct cpu_user_regs *gregs; +int err;a bit misleading. if non-dom0, it should be guest profiling only, right?
Right. I meant that either a regular PV guest profiling itself or dom0 profiling itself and the hypervisor. I possibly also meant here XENPMU_MODE_PRIV mode (where dom0 profiles everyone --- itself, hypervisor and all guests) but that it introduced in a later patch and shouldn't be here yet)
I'll re-phrase it.
-boris
Quoted 2 lines
Acked-by Kevin Tian <[email protected]>
PATCH RESEND v5 13/17 x86/VPMU: Add privileged PMU mode
In reply to Boris OstrovskyAdd support for privileged PMU mode which allows privileged domain (dom0) profile both itself (and the hypervisor) and the guests. While this mode is on profiling in guests is disabled.
--- xen/arch/x86/hvm/vpmu.c | 97 +++++++++++++++++++++++++++++++++--------------- xen/arch/x86/traps.c | 6 ++- xen/include/public/pmu.h | 3 ++ 3 files changed, 76 insertions(+), 30 deletions(-)
xen/arch/x86/hvm/vpmu.c +68 -29
@@ -88,7 +88,8 @@ int vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) {struct vpmu_struct *vpmu =vcpu_vpmu (current); -if ( !(vpmu_mode &XENPMU_MODE_ON ) ) +if ( (vpmu_mode ==XENPMU_MODE_OFF ) || + ((vpmu_mode &XENPMU_MODE_PRIV ) && !is_control_domain (current->domain)) )return 0 ;if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_wrmsr )
@@ -116,7 +117,8 @@ int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) {struct vpmu_struct *vpmu =vcpu_vpmu (current); -if ( !(vpmu_mode &XENPMU_MODE_ON ) ) +if ( (vpmu_mode ==XENPMU_MODE_OFF ) || + ((vpmu_mode &XENPMU_MODE_PRIV ) && !is_control_domain (current->domain)) )return 0 ;if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_rdmsr )
@@ -141,14 +143,18 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs)struct vpmu_struct *vpmu;/* dom0 will handle this interrupt */ -if ( v->domain->domain_id >=DOMID_FIRST_RESERVED ) +if ( (vpmu_mode &XENPMU_MODE_PRIV ) || + (v->domain->domain_id >=DOMID_FIRST_RESERVED ) ) v = dom0->vcpu[smp_processor_id () % dom0->max_vcpus]; vpmu =vcpu_vpmu (v); -if ( !is_hvm_domain (v->domain) ) +if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) ) +return 0 ; + +if ( !is_hvm_domain (v->domain) || (vpmu_mode &XENPMU_MODE_PRIV ) ) {/* PV guest or dom0 is doing system profiling */ -const struct cpu_user_regs *gregs; +struct cpu_user_regs *gregs;int err;if ( v->arch.vpmu.xenpmu_data->pmu_flags &PMU_CACHED )
@@ -159,34 +165,62 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs) err = vpmu->arch_vpmu_ops->arch_vpmu_save (v);vpmu_reset (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ); -/* Store appropriate registers in xenpmu_data */ -if (is_pv_32bit_domain (current->domain) ) +if ( !is_hvm_domain (current->domain) ) { -/* -* 32-bit dom0 cannot process Xen's addresses (which are 64 bit) -* and therefore we treat it the same way as a non-priviledged -* PV 32-bit domain. -*/ -struct compat_cpu_user_regs *cmp; - - gregs =guest_cpu_user_regs (); +/* Store appropriate registers in xenpmu_data */ +if (is_pv_32bit_domain (current->domain) ) + { + gregs =guest_cpu_user_regs (); + +if ( (vpmu_mode &XENPMU_MODE_PRIV ) && + !is_pv_32bit_domain (v->domain) ) +memcpy (&v->arch.vpmu.xenpmu_data->pmu.r.regs, + gregs,sizeof (struct cpu_user_regs )); +else + { +/* +* 32-bit dom0 cannot process Xen's addresses (which are +* 64 bit) and therefore we treat it the same way as a +* non-priviledged PV 32-bit domain. +*/ + +struct compat_cpu_user_regs *cmp; + + cmp = (struct compat_cpu_user_regs *) + &v->arch.vpmu.xenpmu_data->pmu.r.regs; +XLAT_cpu_user_regs (cmp, gregs); +memcpy (&v->arch.vpmu.xenpmu_data->pmu.r.regs, + &cmp,sizeof (struct compat_cpu_user_regs )); + } + } +else if ( !is_control_domain (current->domain) && + !is_idle_vcpu (current) ) + { +/* PV guest */ + gregs =guest_cpu_user_regs (); +memcpy (&v->arch.vpmu.xenpmu_data->pmu.r.regs, + gregs,sizeof (struct cpu_user_regs )); + } +else +memcpy (&v->arch.vpmu.xenpmu_data->pmu.r.regs, + regs,sizeof (struct cpu_user_regs )); - cmp = (void *)&v->arch.vpmu.xenpmu_data->pmu.r.regs; -XLAT_cpu_user_regs (cmp, gregs); -memcpy (&v->arch.vpmu.xenpmu_data->pmu.r.regs, - &cmp,sizeof (struct compat_cpu_user_regs )); + gregs = &v->arch.vpmu.xenpmu_data->pmu.r.regs; + gregs->cs = (current->arch.flags & TF_kernel_mode) ?0 :0x3 ; } -else if ( !is_control_domain (current->domain) && - !is_idle_vcpu (current) ) +else { -/* PV guest */ +/* HVM guest */ +struct segment_register cs; + gregs =guest_cpu_user_regs ();memcpy (&v->arch.vpmu.xenpmu_data->pmu.r.regs, gregs,sizeof (struct cpu_user_regs )); + +hvm_get_segment_register (current, x86_seg_cs, &cs); + gregs = &v->arch.vpmu.xenpmu_data->pmu.r.regs; + gregs->cs = cs.attr.fields.dpl; } -else -memcpy (&v->arch.vpmu.xenpmu_data->pmu.r.regs, - regs,sizeof (struct cpu_user_regs )); v->arch.vpmu.xenpmu_data->domain_id = current->domain->domain_id; v->arch.vpmu.xenpmu_data->vcpu_id = current->vcpu_id;
@@ -492,15 +526,20 @@ long do_xenpmu_op(int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg)if (copy_from_guest (&pmu_params, arg,1 ) )return -EFAULT ; -if ( pmu_params.d.val & ~XENPMU_MODE_ON ) +if ( (pmu_params.d.val & ~(XENPMU_MODE_ON |XENPMU_MODE_PRIV )) || + ((pmu_params.d.val &XENPMU_MODE_ON ) && + (pmu_params.d.val &XENPMU_MODE_PRIV )) )return -EINVAL ; vpmu_mode = pmu_params.d.val; -if ( vpmu_mode ==XENPMU_MODE_OFF ) + +if ( (vpmu_mode ==XENPMU_MODE_OFF ) || (vpmu_mode &XENPMU_MODE_PRIV ) )/* * After this VPMU context will never be loaded during context -* switch. We also prevent PMU MSR accesses (which can load -* context) when VPMU is disabled. +* switch. Because PMU MSR accesses load VPMU context we don't +* allow them when VPMU is off and, for non-provileged domains, +* when we are in privileged mode. (We do want these accesses to +* load VPMU context for control domain in this mode) */ vpmu_unload_all ();
xen/arch/x86/traps.c +5 -1
@@ -2508,7 +2508,11 @@ static int emulate_privileged_op(struct cpu_user_regs *regs) case MSR_CORE_PERF_FIXED_CTR_CTRL...MSR_CORE_PERF_GLOBAL_OVF_CTRL: case MSR_AMD_FAM15H_EVNTSEL0...MSR_AMD_FAM15H_PERFCTR5:if ( !vpmu_do_wrmsr (regs->ecx, msr_content) ) - goto invalid; + { +if ( (vpmu_mode &XENPMU_MODE_PRIV ) && +is_control_domain (v->domain) ) + goto invalid; + }break ;default :if (wrmsr_hypervisor_regs (regs->ecx, msr_content) ==1 )
xen/include/public/pmu.h +3 -0
@@ -56,9 +56,12 @@ DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t);* - XENPMU_MODE_OFF: No PMU virtualization * - XENPMU_MODE_ON: Guests can profile themselves, dom0 profiles * itself and Xen +* - XENPMU_MODE_PRIV: Only dom0 has access to VPMU and it profiles +* everyone: itself, the hypervisor and the guests. */ #define XENPMU_MODE_OFF 0#define XENPMU_MODE_ON (1<<0) +#define XENPMU_MODE_PRIV (1<<1)/* * PMU features:
Signature · 1 line
1.8.3.1
Re: [PATCH v5 RESEND 13/17] x86/VPMU: Add privileged PMU mode
Quoted 21 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:51 PMAdd support for privileged PMU mode which allows privileged domain (dom0) profile both itself (and the hypervisor) and the guests. While this mode is on profiling in guests is disabled.
Signed-off-by Boris Ostrovsky <[email protected]>--- xen/arch/x86/hvm/vpmu.c | 97 +++++++++++++++++++++++++++++++++--------------- xen/arch/x86/traps.c | 6 ++- xen/include/public/pmu.h | 3 ++ 3 files changed, 76 insertions(+), 30 deletions(-)xen/arch/x86/hvm/vpmu.c +0
-0
xen/arch/x86/hvm/vpmu.c int vpmu_do_wrmsr(unsigned int msr, uint64_t · line 95
Quoted 9 lines
xen/arch/x86/hvm/vpmu.c +2
-1@@ -88,7 +88,8 @@ int vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) {struct vpmu_struct *vpmu =vcpu_vpmu (current); -if ( !(vpmu_mode &XENPMU_MODE_ON ) ) +if ( (vpmu_mode ==XENPMU_MODE_OFF ) || + ((vpmu_mode &XENPMU_MODE_PRIV ) && !is_control_domain (current->domain)) )return 0 ;
how about combining above checks into a macro, e.g.
#define vpmu_is_on(mode, vcpu) \ ((mode == XENPMU_MODE_ON) || \ ((mode & XENPMU_MODE_PRIV) && is_control_domain(vcpu->domain)))
Re: [PATCH v5 RESEND 13/17] x86/VPMU: Add privileged PMU mode
Quoted 32 lines · Kevin
Quoted 21 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:51 PMAdd support for privileged PMU mode which allows privileged domain (dom0) profile both itself (and the hypervisor) and the guests. While this mode is on profiling in guests is disabled.
Signed-off-by Boris Ostrovsky <[email protected]>--- xen/arch/x86/hvm/vpmu.c | 97 +++++++++++++++++++++++++++++++++--------------- xen/arch/x86/traps.c | 6 ++- xen/include/public/pmu.h | 3 ++ 3 files changed, 76 insertions(+), 30 deletions(-)xen/arch/x86/hvm/vpmu.c +0
-0xen/arch/x86/hvm/vpmu.c int vpmu_do_wrmsr(unsigned int msr, uint64_t · line 95
Quoted 9 lines
xen/arch/x86/hvm/vpmu.c +2
-1@@ -88,7 +88,8 @@ int vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) {struct vpmu_struct *vpmu =vcpu_vpmu (current); -if ( !(vpmu_mode &XENPMU_MODE_ON ) ) +if ( (vpmu_mode ==XENPMU_MODE_OFF ) || + ((vpmu_mode &XENPMU_MODE_PRIV ) && !is_control_domain (current->domain)) )return 0 ;how about combining above checks into a macro, e.g.
Quoted 3 lines
#define vpmu_is_on(mode, vcpu) \ ((mode == XENPMU_MODE_ON) || \ ((mode & XENPMU_MODE_PRIV) && is_control_domain(vcpu->domain)))
I am not sure it's worth it for just two appearances of this code fragment. I'll see if this is more common though.
-boris
Quoted 2 lines
Acked-by Kevin Tian <[email protected]>
PATCH RESEND v5 14/17 x86/VPMU: Save VPMU state for PV guests during context switch
In reply to Boris OstrovskySave VPMU state during context switch for both HVM and PV guests unless we are in PMU privileged mode (i.e. dom0 is doing all profiling).
--- xen/arch/x86/domain.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
xen/arch/x86/domain.c +5 -7
@@ -1461,16 +1461,14 @@ void context_switch(struct vcpu *prev, struct vcpu *next) }if ( prev != next ) -_update_runstate_area (prev); - -if (is_hvm_vcpu (prev) ) { -if ( (prev != next) && (vpmu_mode &XENPMU_MODE_ON ) ) +_update_runstate_area (prev); +if ( vpmu_mode &XENPMU_MODE_ON )vpmu_save (prev); + } -if ( !list_empty (&prev->arch.hvm_vcpu.tm_list) ) +if (is_hvm_vcpu (prev) && !list_empty (&prev->arch.hvm_vcpu.tm_list) )pt_save_timer (prev); - }local_irq_disable ();
@@ -1508,7 +1506,7 @@ void context_switch(struct vcpu *prev, struct vcpu *next) (next->domain->domain_id != 0)); } -if (is_hvm_vcpu (next) && (prev != next) && (vpmu_mode &XENPMU_MODE_ON ) ) +if ( (prev != next) && (vpmu_mode &XENPMU_MODE_ON ) )/* Must be done with interrupts enabled */ vpmu_load (next);
Signature · 1 line
1.8.3.1
Re: [PATCH v5 RESEND 14/17] x86/VPMU: Save VPMU state for PV guests during context switch
Quoted 7 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:51 PMSave VPMU state during context switch for both HVM and PV guests unless we are in PMU privileged mode (i.e. dom0 is doing all profiling).
Signed-off-by Boris Ostrovsky <[email protected]>
Quoted 44 lines
--- xen/arch/x86/domain.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)xen/arch/x86/domain.c +4
-6@@ -1461,16 +1461,14 @@ void context_switch(struct vcpu *prev, struct vcpu *next) }if ( prev != next ) -_update_runstate_area (prev); - -if (is_hvm_vcpu (prev) ) { -if ( (prev != next) && (vpmu_mode &XENPMU_MODE_ON ) ) +_update_runstate_area (prev); +if ( vpmu_mode &XENPMU_MODE_ON )vpmu_save (prev); + } -if ( !list_empty (&prev->arch.hvm_vcpu.tm_list) ) +if (is_hvm_vcpu (prev) && !list_empty (&prev->arch.hvm_vcpu.tm_list) )pt_save_timer (prev); - }local_irq_disable();xen/arch/x86/domain.c +1
-1@@ -1508,7 +1506,7 @@ void context_switch(struct vcpu *prev, struct vcpu *next) (next->domain->domain_id != 0)); } -if (is_hvm_vcpu (next) && (prev != next) && (vpmu_mode & XENPMU_MODE_ON) ) +if ( (prev != next) && (vpmu_mode &XENPMU_MODE_ON ) )/* Must be done with interrupts enabled */ vpmu_load(next);--
1.8.3.1
PATCH RESEND v5 15/17 x86/VPMU: NMI-based VPMU support
In reply to Boris OstrovskyAdd support for using NMIs as PMU interrupts.
Most of processing is still performed by vpmu_do_interrupt(). However, since certain operations are not NMI-safe we defer them to a softint that vpmu_do_interrupt() will schedule:
* For PV guests that would be send_guest_vcpu_virq()
* For HVM guests it's VLAPIC accesses and hvm_get_segment_register() (the later can be called in privileged profiling mode when the interrupted guest is an HVM one).
With send_guest_vcpu_virq() and hvm_get_segment_register() for PV(H) and vlapic accesses for HVM moved to sofint, the only routines/macros that vpmu_do_interrupt() calls in NMI mode are:
* memcpy()
* querying domain type (is_XX_domain())
* guest_cpu_user_regs()
* XLAT_cpu_user_regs()
* raise_softirq()
* vcpu_vpmu()
* vpmu_ops->arch_vpmu_save()
* vpmu_ops->do_interrupt() (in the future for PVH support)
The latter two only access PMU MSRs with {rd,wr}msrl() (not the _safe versions which would not be NMI-safe).
--- xen/arch/x86/hvm/svm/vpmu.c | 1 + xen/arch/x86/hvm/vmx/vpmu_core2.c | 1 + xen/arch/x86/hvm/vpmu.c | 169 ++++++++++++++++++++++++++++++-------- 3 files changed, 138 insertions(+), 33 deletions(-)
xen/arch/x86/hvm/svm/vpmu.c +1 -0
@@ -182,6 +182,7 @@ static inline void context_load(struct vcpu *v) } } +/* Must be NMI-safe */ static void amd_vpmu_load (struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v);
xen/arch/x86/hvm/vmx/vpmu_core2.c +1 -0
@@ -303,6 +303,7 @@ static inline void __core2_vpmu_save(struct vcpu *v)rdmsrl (MSR_CORE_PERF_GLOBAL_STATUS , core2_vpmu_cxt->global_status); } +/* Must be NMI-safe */ static int core2_vpmu_save (struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v);
xen/arch/x86/hvm/vpmu.c +136 -33
250 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [PATCH v5 RESEND 15/17] x86/VPMU: NMI-based VPMU support
Quoted 29 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:51 PMAdd support for using NMIs as PMU interrupts.
Most of processing is still performed by
vpmu_do_interrupt(). However, since certain operations are not NMI-safe we defer them to a softint thatvpmu_do_interrupt()
will schedule:
* For PV guests that would besend_guest_vcpu_virq()
* For HVM guests it's VLAPIC accesses andhvm_get_segment_register()(the later
can be called in privileged profiling mode when the interrupted guest is an HVM one).With
send_guest_vcpu_virq()andhvm_get_segment_register()for PV(H) and vlapic
accesses for HVM moved to sofint, the only routines/macros thatvpmu_do_interrupt()
calls in NMI mode are:
*memcpy()
* querying domain type (is_XX_domain())
*guest_cpu_user_regs()
*XLAT_cpu_user_regs()
*raise_softirq()
*vcpu_vpmu()
*vpmu_ops->arch_vpmu_save()
*vpmu_ops->do_interrupt()(in the future for PVH support)
Quoted 5 lines
The latter two only access PMU MSRs with {rd,wr}msrl() (not the
_safeversions
which would not be NMI-safe).Signed-off-by Boris Ostrovsky <[email protected]>
if a SCHEDULE_SOFTIRQ happens before NMI_SOFTIRQ, will it cause any race condition when accessing previous recorded content in nmi softirq handler?
Thanks
Kevin
Quoted 306 lines
--- xen/arch/x86/hvm/svm/vpmu.c | 1 + xen/arch/x86/hvm/vmx/vpmu_core2.c | 1 + xen/arch/x86/hvm/vpmu.c | 169 ++++++++++++++++++++++++++++++-------- 3 files changed, 138 insertions(+), 33 deletions(-)xen/arch/x86/hvm/svm/vpmu.c +1
-0@@ -182,6 +182,7 @@ static inline void context_load(struct vcpu *v) } } +/* Must be NMI-safe */ static void amd_vpmu_load (struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v);xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-0@@ -303,6 +303,7 @@ static inline void __core2_vpmu_save(struct vcpu *v)rdmsrl (MSR_CORE_PERF_GLOBAL_STATUS , core2_vpmu_cxt->global_status); } +/* Must be NMI-safe */ static int core2_vpmu_save (struct vcpu *v) {struct vpmu_struct *vpmu = vcpu_vpmu(v);xen/arch/x86/hvm/vpmu.c +40
-15@@ -36,6 +36,7 @@#include <asm/hvm/svm/svm.h> #include <asm/hvm/svm/vmcb.h> #include <asm/apic.h> +#include <asm/nmi.h> #include <public/pmu.h> /* @@ -49,33 +50,57 @@ static void parse_vpmu_param(char *s);custom_param ("vpmu" , parse_vpmu_param); static DEFINE_PER_CPU(struct vcpu *, last_vcpu); +static DEFINE_PER_CPU(struct vcpu *, sampled_vcpu); + +static uint32_t __read_mostly vpmu_interrupt_type =PMU_APIC_VECTOR ;static void __init parse_vpmu_param (char *s) { -switch (parse_bool (s) ) - { -case 0 : -break ; -default : -if ( !strcmp (s,"bts" ) ) - vpmu_features |=XENPMU_FEATURE_INTEL_BTS ; -else if ( *s ) +char *ss; + + vpmu_mode =XENPMU_MODE_ON ; +if (*s =='\0' ) +return ; + +do { + ss =strchr (s,',' ); +if ( ss ) + *ss ='\0' ; + +switch (parse_bool (s) ) { -printk ("VPMU: unknown flag: %s - vpmu disabled!\n" , s); +case 0 : + vpmu_mode =XENPMU_MODE_OFF ; +return ; +case -1 : +if ( !strcmp (s,"nmi" ) ) + vpmu_interrupt_type =APIC_DM_NMI ; +else if ( !strcmp (s,"bts" ) ) + vpmu_features |=XENPMU_FEATURE_INTEL_BTS ; +else if ( !strcmp (s,"priv" ) ) + { + vpmu_mode &= ~XENPMU_MODE_ON ; + vpmu_mode |=XENPMU_MODE_PRIV ; + } +else + { +printk ("VPMU: unknown flag: %s - vpmu disabled!\n" , s); + vpmu_mode =XENPMU_MODE_OFF ; +return ; + } +default :break ; } -/* fall through */ -case 1 : - vpmu_mode =XENPMU_MODE_ON ; -break ; - } + + s = ss +1 ; + }while ( ss ); }void vpmu_lvtpc_update (uint32_t val) {struct vpmu_struct *vpmu =vcpu_vpmu (current); - vpmu->hw_lapic_lvtpc =PMU_APIC_VECTOR | (val & APIC_LVT_MASKED); + vpmu->hw_lapic_lvtpc = vpmu_interrupt_type | (val &APIC_LVT_MASKED );/* Postpone APIC updates for PV guests if PMU interrupt is pending */ if ( !is_pv_domain(current->domain) ||xen/arch/x86/hvm/vpmu.c +22
-0@@ -84,6 +109,27 @@ void vpmu_lvtpc_update(uint32_t val)apic_write (APIC_LVTPC , vpmu->hw_lapic_lvtpc); } +static void vpmu_send_nmi (struct vcpu *v) +{ +struct vlapic *vlapic; +u32 vlapic_lvtpc; +unsigned char int_vec; + +ASSERT (is_hvm_vcpu (v) ); + + vlapic =vcpu_vlapic (v); +if ( !is_vlapic_lvtpc_enabled (vlapic) ) +return ; + + vlapic_lvtpc =vlapic_get_reg (vlapic,APIC_LVTPC ); + int_vec = vlapic_lvtpc &APIC_VECTOR_MASK ; + +if (GET_APIC_DELIVERY_MODE (vlapic_lvtpc) ==APIC_MODE_FIXED ) +vlapic_set_irq (vcpu_vlapic (v), int_vec,0 ); +else + v->nmi_pending =1 ; +} +int vpmu_do_wrmsr (unsigned int msr,uint64_t msr_content) {struct vpmu_struct *vpmu =vcpu_vpmu (current);@@ -137,6 +183,7 @@ int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content)return 0 ; } +/* This routine may be called in NMI context */ int vpmu_do_interrupt (struct cpu_user_regs *regs) {struct vcpu *v = current;xen/arch/x86/hvm/vpmu.c +7
-3@@ -217,9 +264,13 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs)memcpy (&v->arch.vpmu.xenpmu_data->pmu.r.regs, gregs,sizeof (struct cpu_user_regs )); -hvm_get_segment_register(current, x86_seg_cs, &cs); -gregs = &v->arch.vpmu.xenpmu_data->pmu.r.regs; -gregs->cs = cs.attr.fields.dpl; +/* This is unsafe in NMI context, we'll do it in softint handler */ +if ( !(vpmu_interrupt_type &APIC_DM_NMI ) ) + { +hvm_get_segment_register (current, x86_seg_cs, &cs); + gregs = &v->arch.vpmu.xenpmu_data->pmu.r.regs; + gregs->cs = cs.attr.fields.dpl; + } }v->arch.vpmu.xenpmu_data->domain_id =
current->domain->domain_id;xen/arch/x86/hvm/vpmu.c +14
-14@@ -230,30 +281,30 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs)apic_write (APIC_LVTPC , vpmu->hw_lapic_lvtpc |APIC_LVT_MASKED ); vpmu->hw_lapic_lvtpc |=APIC_LVT_MASKED ; -send_guest_vcpu_virq (v,VIRQ_XENPMU ); +if ( vpmu_interrupt_type &APIC_DM_NMI ) + { +per_cpu (sampled_vcpu,smp_processor_id ()) = current; +raise_softirq (PMU_SOFTIRQ ); + } +else +send_guest_vcpu_virq (v,VIRQ_XENPMU );return 1 ; }if ( vpmu->arch_vpmu_ops ) { -struct vlapic *vlapic =vcpu_vlapic (v); -u32 vlapic_lvtpc; -unsigned char int_vec; -if ( !vpmu->arch_vpmu_ops->do_interrupt (regs) )return 0 ; -if ( !is_vlapic_lvtpc_enabled (vlapic) ) -return 1 ; - - vlapic_lvtpc =vlapic_get_reg (vlapic,APIC_LVTPC ); - int_vec = vlapic_lvtpc &APIC_VECTOR_MASK ; - -if (GET_APIC_DELIVERY_MODE (vlapic_lvtpc) == APIC_MODE_FIXED ) -vlapic_set_irq (vcpu_vlapic (v), int_vec,0 ); +if ( vpmu_interrupt_type &APIC_DM_NMI ) + { +per_cpu (sampled_vcpu,smp_processor_id ()) = current; +raise_softirq (PMU_SOFTIRQ ); + }else - v->nmi_pending =1 ; +vpmu_send_nmi (v); +return 1 ;}xen/arch/x86/hvm/vpmu.c +53
-1@@ -301,7 +352,7 @@ void vpmu_save(struct vcpu *v)if ( vpmu->arch_vpmu_ops->arch_vpmu_save (v) )vpmu_reset (vpmu,VPMU_CONTEXT_LOADED ); -apic_write (APIC_LVTPC ,PMU_APIC_VECTOR |APIC_LVT_MASKED ); +apic_write (APIC_LVTPC , vpmu_interrupt_type |APIC_LVT_MASKED ); }void vpmu_load (struct vcpu *v)@@ -450,11 +501,48 @@ static void vpmu_unload_all(void) } } +/* Process the softirq set by PMU NMI handler */ +static void pmu_softnmi (void ) +{ +struct cpu_user_regs *regs; +struct vcpu *v, *sampled =per_cpu (sampled_vcpu,smp_processor_id ()); + +if ( (vpmu_mode &XENPMU_MODE_PRIV ) || + (sampled->domain->domain_id >=DOMID_FIRST_RESERVED ) ) + v = dom0->vcpu[smp_processor_id () % dom0->max_vcpus]; +else + { +if (is_hvm_domain (sampled->domain) ) + { +vpmu_send_nmi (sampled); +return ; + } + v = sampled; + } + + regs = &v->arch.vpmu.xenpmu_data->pmu.r.regs; +if ( !is_pv_domain (sampled->domain) ) + { +struct segment_register cs; + +hvm_get_segment_register (sampled, x86_seg_cs, &cs); + regs->cs = cs.attr.fields.dpl; + } + +send_guest_vcpu_virq (v,VIRQ_XENPMU ); +} + +int pmu_nmi_interrupt (struct cpu_user_regs *regs,int cpu) +{ +return vpmu_do_interrupt (regs); +} +static int pvpmu_init (struct domain *d,xen_pmu_params_t *params) {struct vcpu *v;struct page_info *page;uint64_t gfn = params->d.val; +static bool_t __read_mostly pvpmu_initted =0 ;if ( !is_pv_domain (d) )return -EINVAL ;@@ -480,6 +568,21 @@ static int pvpmu_init(struct domain *d, xen_pmu_params_t *params)return -EINVAL ; } +if ( !pvpmu_initted ) + { +if (reserve_lapic_nmi () ==0 ) +set_nmi_callback (pmu_nmi_interrupt); +else + { +printk ("Failed to reserve PMU NMI\n" ); +put_page (page); +return -EBUSY ; + } +open_softirq (PMU_SOFTIRQ , pmu_softnmi); + + pvpmu_initted =1 ; + } +vpmu_initialise (v);return 0;--
1.8.3.1
Re: [PATCH v5 RESEND 15/17] x86/VPMU: NMI-based VPMU support
Quoted 29 lines · Kevin
Quoted 29 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:51 PMAdd support for using NMIs as PMU interrupts.
Most of processing is still performed by
vpmu_do_interrupt(). However, since certain operations are not NMI-safe we defer them to a softint thatvpmu_do_interrupt()
will schedule:
* For PV guests that would besend_guest_vcpu_virq()
* For HVM guests it's VLAPIC accesses andhvm_get_segment_register()(the later
can be called in privileged profiling mode when the interrupted guest is an HVM one).With
send_guest_vcpu_virq()andhvm_get_segment_register()for PV(H) and vlapic
accesses for HVM moved to sofint, the only routines/macros thatvpmu_do_interrupt()
calls in NMI mode are:
*memcpy()
* querying domain type (is_XX_domain())
*guest_cpu_user_regs()
*XLAT_cpu_user_regs()
*raise_softirq()
*vcpu_vpmu()
*vpmu_ops->arch_vpmu_save()
*vpmu_ops->do_interrupt()(in the future for PVH support)
Quoted 7 lines
Quoted 5 lines
The latter two only access PMU MSRs with {rd,wr}msrl() (not the
_safeversions
which would not be NMI-safe).Signed-off-by Boris Ostrovsky <[email protected]>if a
SCHEDULE_SOFTIRQhappens beforeNMI_SOFTIRQ, will it cause any race condition when accessing previous recorded content in nmi softirq handler?
I think you are right.
I in fact had an earlier version where I'd put the record into a linked list but when I later looked at that code again I took it out because I thought it was unnecessary. But now that you mentioned it I may need to resurrect that code. Let me think about this again.
-boris
PATCH RESEND v5 16/17 x86/VPMU: Suport for PVH guests
In reply to Boris OstrovskyAdd support for PVH guests. Most of operations are performed as in an HVM guest. However, interrupt management is done in PV-like manner.
--- xen/arch/x86/hvm/hvm.c | 3 ++- xen/arch/x86/hvm/svm/vpmu.c | 13 +++++++------ xen/arch/x86/hvm/vmx/vpmu_core2.c | 24 ++++++++++++------------ xen/arch/x86/hvm/vpmu.c | 34 ++++++++++++++++++++++------------ 4 files changed, 43 insertions(+), 31 deletions(-)
xen/arch/x86/hvm/hvm.c +2 -1
@@ -3451,7 +3451,8 @@ static hvm_hypercall_t *const pvh_hypercall64_table[NR_hypercalls] = { [ __HYPERVISOR_physdev_op ] = (hvm_hypercall_t *)hvm_physdev_op,HYPERCALL (hvm_op),HYPERCALL (sysctl), - HYPERCALL(domctl) +HYPERCALL (domctl), + HYPERCALL(xenpmu_op) };int hvm_do_hypercall (struct cpu_user_regs *regs)
xen/arch/x86/hvm/svm/vpmu.c +7 -6
@@ -162,6 +162,7 @@ static void amd_vpmu_unset_msr_bitmap(struct vcpu *v) ctxt->msr_bitmap_set =0 ; } +/* Must be NMI-safe */ static int amd_vpmu_do_interrupt (struct cpu_user_regs *regs) {return 1 ;
@@ -243,7 +244,7 @@ static int amd_vpmu_save(struct vcpu *v)context_save (v); -if (is_hvm_domain (v->domain) && +if (has_hvm_container_domain (v->domain) && !vpmu_is_set (vpmu,VPMU_RUNNING ) && ctx->msr_bitmap_set )amd_vpmu_unset_msr_bitmap (v);
@@ -286,7 +287,7 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)struct vpmu_struct *vpmu =vcpu_vpmu (v);/* For all counters, enable guest only mode for HVM guest */ -if (is_hvm_domain (v->domain) && (get_pmu_reg_type (msr) ==MSR_TYPE_CTRL ) && +if (has_hvm_container_domain (v->domain) && (get_pmu_reg_type (msr) ==MSR_TYPE_CTRL ) && !(is_guest_mode (msr_content)) ) {set_guest_mode (msr_content);
@@ -300,7 +301,7 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)return 1 ;vpmu_set (vpmu,VPMU_RUNNING ); -if (is_hvm_domain (v->domain) && +if (has_hvm_container_domain (v->domain) && !((struct xen_pmu_amd_ctxt *)vpmu->context)->msr_bitmap_set )amd_vpmu_set_msr_bitmap (v); }
@@ -310,7 +311,7 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) (is_pmu_enabled(msr_content) == 0) && vpmu_is_set(vpmu, VPMU_RUNNING) ) {vpmu_reset (vpmu,VPMU_RUNNING ); -if (is_hvm_domain (v->domain) && +if (has_hvm_container_domain (v->domain) && ((struct xen_pmu_amd_ctxt *)vpmu->context)->msr_bitmap_set )amd_vpmu_unset_msr_bitmap (v);release_pmu_ownship (PMU_OWNER_HVM );
@@ -382,7 +383,7 @@ static int amd_vpmu_initialise(struct vcpu *v) } } -if ( !is_pv_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) ) { ctxt = xzalloc_bytes(sizeof(struct xen_pmu_amd_ctxt) + sizeof(uint64_t) * AMD_MAX_COUNTERS +
@@ -413,7 +414,7 @@ static void amd_vpmu_destroy(struct vcpu *v)if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )return ; -if (is_hvm_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) ) {if ( ((struct xen_pmu_amd_ctxt *)vpmu->context)->msr_bitmap_set )amd_vpmu_unset_msr_bitmap (v);
xen/arch/x86/hvm/vmx/vpmu_core2.c +12 -12
@@ -299,7 +299,7 @@ static inline void __core2_vpmu_save(struct vcpu *v)for ( i =0 ; i < arch_pmc_cnt; i++ )rdmsrl (MSR_IA32_PERFCTR0 + i, xen_pmu_cntr_pair[i].counter); -if (is_pv_domain (v->domain) ) +if ( !has_hvm_container_domain (v->domain) )rdmsrl (MSR_CORE_PERF_GLOBAL_STATUS , core2_vpmu_cxt->global_status); }
@@ -308,7 +308,7 @@ static int core2_vpmu_save(struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v); -if (is_pv_domain (v->domain) ) +if ( !has_hvm_container_domain (v->domain) )wrmsrl (MSR_CORE_PERF_GLOBAL_CTRL ,0 );if ( !vpmu_is_set_all (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ) )
@@ -318,7 +318,7 @@ static int core2_vpmu_save(struct vcpu *v)/* Unset PMU MSR bitmap to trap lazy load. */ if ( !vpmu_is_set (vpmu,VPMU_RUNNING ) && cpu_has_vmx_msr_bitmap - && !is_pv_domain (v->domain) ) + &&has_hvm_container_domain (v->domain) )core2_vpmu_unset_msr_bitmap (v->arch.hvm_vmx.msr_bitmap);return 1 ;
@@ -349,7 +349,7 @@ static inline void __core2_vpmu_load(struct vcpu *v)wrmsrl (MSR_IA32_DS_AREA , core2_vpmu_cxt->ds_area);wrmsrl (MSR_IA32_PEBS_ENABLE , core2_vpmu_cxt->pebs_enable); -if (is_pv_domain (v->domain) ) +if ( !has_hvm_container_domain (v->domain) ) {wrmsrl (MSR_CORE_PERF_GLOBAL_OVF_CTRL , core2_vpmu_cxt->global_ovf_ctrl); core2_vpmu_cxt->global_ovf_ctrl =0 ;
@@ -436,7 +436,7 @@ static int core2_vpmu_msr_common_check(u32 msr_index, int *type, int *index) {__core2_vpmu_load (current);vpmu_set (vpmu,VPMU_CONTEXT_LOADED ); -if ( cpu_has_vmx_msr_bitmap &&is_hvm_domain (current->domain) ) +if ( cpu_has_vmx_msr_bitmap &&has_hvm_container_domain (current->domain) )core2_vpmu_set_msr_bitmap (current->arch.hvm_vmx.msr_bitmap); }return 1 ;
@@ -444,7 +444,7 @@ static int core2_vpmu_msr_common_check(u32 msr_index, int *type, int *index)static void inject_trap (struct vcpu *v,unsigned int trapno) { -if ( !is_pv_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) )hvm_inject_hw_exception (trapno,0 );else send_guest_trap (v->domain, v->vcpu_id, trapno);
@@ -538,7 +538,7 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)break ;case MSR_CORE_PERF_FIXED_CTR_CTRL : non_global_ctrl = msr_content; -if ( !is_pv_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) )vmx_read_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , &global_ctrl);else rdmsrl (MSR_CORE_PERF_GLOBAL_CTRL , global_ctrl);
@@ -558,7 +558,7 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)struct xen_pmu_cntr_pair *xen_pmu_cntr_pair =vpmu_reg_pointer (core2_vpmu_cxt, arch_counters); -if ( !is_pv_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) )vmx_read_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , &global_ctrl);else rdmsrl (MSR_CORE_PERF_GLOBAL_CTRL , global_ctrl);
@@ -608,7 +608,7 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) }else { -if ( !is_pv_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) )vmx_write_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , msr_content);else wrmsrl (MSR_CORE_PERF_GLOBAL_CTRL , msr_content);
@@ -636,7 +636,7 @@ static int core2_vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) *msr_content = core2_vpmu_cxt->global_status;break ;case MSR_CORE_PERF_GLOBAL_CTRL : -if ( !is_pv_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) )vmx_read_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , msr_content);else rdmsrl (MSR_CORE_PERF_GLOBAL_CTRL , *msr_content);
@@ -803,7 +803,7 @@ func_out:check_pmc_quirk ();/* PV domains can allocate resources immediately */ -if (is_pv_domain (v->domain) && !core2_vpmu_alloc_resource (v) ) +if ( !has_hvm_container_domain (v->domain) && !core2_vpmu_alloc_resource (v) )return 1 ;return 0 ;
@@ -816,7 +816,7 @@ static void core2_vpmu_destroy(struct vcpu *v)if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )return ; -if (is_hvm_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) ) {xfree (vpmu->context);if ( cpu_has_vmx_msr_bitmap )
xen/arch/x86/hvm/vpmu.c +22 -12
@@ -103,7 +103,7 @@ void vpmu_lvtpc_update(uint32_t val) vpmu->hw_lapic_lvtpc = vpmu_interrupt_type | (val &APIC_LVT_MASKED );/* Postpone APIC updates for PV guests if PMU interrupt is pending */ -if ( !is_pv_domain (current->domain) || +if ( !has_hvm_container_domain (current->domain) || !(current->arch.vpmu.xenpmu_data && current->arch.vpmu.xenpmu_data->pmu_flags &PMU_CACHED ) )apic_write (APIC_LVTPC , vpmu->hw_lapic_lvtpc);
@@ -147,7 +147,7 @@ int vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)* and since do_wrmsr may load VPMU context we should save * (and unload) it again. */ -if ( !is_hvm_domain (current->domain) && +if ( !has_hvm_container_domain (current->domain) && (current->arch.vpmu.xenpmu_data->pmu_flags &PMU_CACHED ) ) {vpmu_set (vpmu,VPMU_CONTEXT_SAVE );
@@ -171,7 +171,7 @@ int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) {int ret = vpmu->arch_vpmu_ops->do_rdmsr (msr, msr_content); -if ( !is_hvm_domain (current->domain) && +if ( !has_hvm_container_domain (current->domain) && (current->arch.vpmu.xenpmu_data->pmu_flags &PMU_CACHED ) ) {vpmu_set (vpmu,VPMU_CONTEXT_SAVE );
@@ -200,13 +200,17 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs)if ( !is_hvm_domain (v->domain) || (vpmu_mode &XENPMU_MODE_PRIV ) ) { -/* PV guest or dom0 is doing system profiling */ +/* PV(H) guest or dom0 is doing system profiling */ struct cpu_user_regs *gregs;int err;if ( v->arch.vpmu.xenpmu_data->pmu_flags &PMU_CACHED )return 1 ; +if (is_pvh_domain (current->domain) && !(vpmu_mode &XENPMU_MODE_PRIV ) && + !vpmu->arch_vpmu_ops->do_interrupt (regs) ) +return 0 ; +/* PV guest will be reading PMU MSRs from xenpmu_data */ vpmu_set (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ); err = vpmu->arch_vpmu_ops->arch_vpmu_save (v);
@@ -243,7 +247,7 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs)else if ( !is_control_domain (current->domain) && !is_idle_vcpu (current) ) { -/* PV guest */ +/* PV(H) guest */ gregs =guest_cpu_user_regs ();memcpy (&v->arch.vpmu.xenpmu_data->pmu.r.regs, gregs,sizeof (struct cpu_user_regs ));
@@ -253,7 +257,15 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs) regs, sizeof(struct cpu_user_regs)); gregs = &v->arch.vpmu.xenpmu_data->pmu.r.regs; - gregs->cs = (current->arch.flags & TF_kernel_mode) ?0 :0x3 ; +if ( !is_pvh_domain (current->domain) ) + gregs->cs = (current->arch.flags & TF_kernel_mode) ?0 :0x3 ; +else if ( !(vpmu_interrupt_type &APIC_DM_NMI ) ) + { +struct segment_register seg_cs; + +hvm_get_segment_register (current, x86_seg_cs, &seg_cs); + gregs->cs = seg_cs.attr.fields.dpl; + } }else {
@@ -277,7 +289,8 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs) v->arch.vpmu.xenpmu_data->vcpu_id = current->vcpu_id; v->arch.vpmu.xenpmu_data->pcpu_id =smp_processor_id (); - v->arch.vpmu.xenpmu_data->pmu_flags |=PMU_CACHED ; +if ( !is_pvh_domain (current->domain) || (vpmu_mode &XENPMU_MODE_PRIV ) ) + v->arch.vpmu.xenpmu_data->pmu_flags |=PMU_CACHED ;apic_write (APIC_LVTPC , vpmu->hw_lapic_lvtpc |APIC_LVT_MASKED ); vpmu->hw_lapic_lvtpc |=APIC_LVT_MASKED ;
@@ -404,7 +417,7 @@ void vpmu_load(struct vcpu *v)/* Only when PMU is counting, we load PMU context immediately. */ if ( !vpmu_is_set (vpmu,VPMU_RUNNING ) || - (is_pv_domain (v->domain) && vpmu->xenpmu_data->pmu_flags &PMU_CACHED ) ) + (!has_hvm_container_domain (v->domain) && vpmu->xenpmu_data->pmu_flags &PMU_CACHED ) )return ;if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_load )
@@ -521,7 +534,7 @@ static void pmu_softnmi(void) } regs = &v->arch.vpmu.xenpmu_data->pmu.r.regs; -if ( !is_pv_domain (sampled->domain) ) +if (has_hvm_container_domain (sampled->domain) ) {struct segment_register cs;
@@ -544,9 +557,6 @@ static int pvpmu_init(struct domain *d, xen_pmu_params_t *params)uint64_t gfn = params->d.val;static bool_t __read_mostly pvpmu_initted =0 ; -if ( !is_pv_domain (d) ) -return -EINVAL ; -if ( params->vcpu <0 || params->vcpu >= d->max_vcpus )return -EINVAL ;
Signature · 1 line
1.8.3.1
Re: [PATCH v5 RESEND 16/17] x86/VPMU: Suport for PVH guests
Quoted 8 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:51 PMAdd support for PVH guests. Most of operations are performed as in an HVM guest.
However, interrupt management is done in PV-like manner.Signed-off-by Boris Ostrovsky <[email protected]>
If others are OK with the various ***_domain checks, I'm OK with it.
Quoted 365 lines
--- xen/arch/x86/hvm/hvm.c | 3 ++- xen/arch/x86/hvm/svm/vpmu.c | 13 +++++++------ xen/arch/x86/hvm/vmx/vpmu_core2.c | 24 ++++++++++++------------ xen/arch/x86/hvm/vpmu.c | 34 ++++++++++++++++++++++------------ 4 files changed, 43 insertions(+), 31 deletions(-)xen/arch/x86/hvm/hvm.c +2
-1@@ -3451,7 +3451,8 @@ static hvm_hypercall_t *const pvh_hypercall64_table[NR_hypercalls] = { [ __HYPERVISOR_physdev_op ] = (hvm_hypercall_t *)hvm_physdev_op,HYPERCALL (hvm_op),HYPERCALL (sysctl), -HYPERCALL (domctl) +HYPERCALL (domctl), +HYPERCALL (xenpmu_op) };int
hvm_do_hypercall(struct cpu_user_regs *regs)xen/arch/x86/hvm/svm/vpmu.c +1
-0@@ -162,6 +162,7 @@ static void amd_vpmu_unset_msr_bitmap(struct vcpu *v) ctxt->msr_bitmap_set =0 ; } +/* Must be NMI-safe */ static int amd_vpmu_do_interrupt (struct cpu_user_regs *regs) {return 1;xen/arch/x86/hvm/svm/vpmu.c +1
-2@@ -243,7 +244,7 @@ static int amd_vpmu_save(struct vcpu *v)context_save (v); -if (is_hvm_domain (v->domain) && +if (has_hvm_container_domain (v->domain) && !vpmu_is_set (vpmu,VPMU_RUNNING ) && ctx->msr_bitmap_set )amd_vpmu_unset_msr_bitmap (v);@@ -286,7 +287,7 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)struct vpmu_struct *vpmu =vcpu_vpmu (v);/* For all counters, enable guest only mode for HVM guest */ - if ( is_hvm_domain(v->domain) && (get_pmu_reg_type(msr) ==
MSR_TYPE_CTRL) &&
+ if (has_hvm_container_domain(v->domain)&&
(get_pmu_reg_type(msr)==MSR_TYPE_CTRL) &&!(is_guest_mode(msr_content)) ) { set_guest_mode(msr_content);xen/arch/x86/hvm/svm/vpmu.c +1
-1@@ -300,7 +301,7 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)return 1 ;vpmu_set (vpmu,VPMU_RUNNING ); -if (is_hvm_domain (v->domain) && +if (has_hvm_container_domain (v->domain) && !((struct xen_pmu_amd_ctxt *)vpmu->context)->msr_bitmap_set )amd_vpmu_set_msr_bitmap(v); }xen/arch/x86/hvm/svm/vpmu.c +1
-1@@ -310,7 +311,7 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) (is_pmu_enabled(msr_content) == 0) && vpmu_is_set(vpmu, VPMU_RUNNING) ) {vpmu_reset (vpmu,VPMU_RUNNING ); - if ( is_hvm_domain(v->domain) && + if ( has_hvm_container_domain(v->domain) && ((struct xen_pmu_amd_ctxt*)vpmu->context)->msr_bitmap_set )
amd_vpmu_unset_msr_bitmap(v); release_pmu_ownship(PMU_OWNER_HVM);xen/arch/x86/hvm/svm/vpmu.c +3
-2@@ -382,7 +383,7 @@ static int amd_vpmu_initialise(struct vcpu *v) } } -if ( !is_pv_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) ) { ctxt =xzalloc_bytes (sizeof (struct xen_pmu_amd_ctxt ) + sizeof(uint64_t) * AMD_MAX_COUNTERS +@@ -413,7 +414,7 @@ static void amd_vpmu_destroy(struct vcpu *v)if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )return ; -if (is_hvm_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) ) {if ( ((struct xen_pmu_amd_ctxt *)vpmu->context)->msr_bitmap_set )amd_vpmu_unset_msr_bitmap(v);xen/arch/x86/hvm/vmx/vpmu_core2.c +2
-2@@ -299,7 +299,7 @@ static inline void __core2_vpmu_save(struct vcpu *v)for ( i =0 ; i < arch_pmc_cnt; i++ )rdmsrl (MSR_IA32_PERFCTR0 + i, xen_pmu_cntr_pair[i].counter); -if (is_pv_domain (v->domain) ) +if ( !has_hvm_container_domain (v->domain) )rdmsrl (MSR_CORE_PERF_GLOBAL_STATUS , core2_vpmu_cxt->global_status); }@@ -308,7 +308,7 @@ static int core2_vpmu_save(struct vcpu *v) { struct vpmu_struct *vpmu = vcpu_vpmu(v); - if ( is_pv_domain(v->domain) ) + if ( !has_hvm_container_domain(v->domain) ) wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0); if ( !vpmu_is_set_all(vpmu, VPMU_CONTEXT_SAVE |
VPMU_CONTEXT_LOADED) )xen/arch/x86/hvm/vmx/vpmu_core2.c +0
-0@@ -318,7 +318,7 @@ static int core2_vpmu_save(struct vcpu *v)/* Unset PMU MSR bitmap to trap lazy load. */ if ( !vpmu_is_set(vpmu, VPMU_RUNNING) &&
cpu_has_vmx_msr_bitmapxen/arch/x86/hvm/vmx/vpmu_core2.c +2
-2- && !is_pv_domain(v->domain) ) + && has_hvm_container_domain(v->domain) )core2_vpmu_unset_msr_bitmap (v->arch.hvm_vmx.msr_bitmap);return 1 ;@@ -349,7 +349,7 @@ static inline void __core2_vpmu_load(struct vcpu *v)wrmsrl (MSR_IA32_DS_AREA , core2_vpmu_cxt->ds_area);wrmsrl (MSR_IA32_PEBS_ENABLE , core2_vpmu_cxt->pebs_enable); -if (is_pv_domain (v->domain) ) +if ( !has_hvm_container_domain (v->domain) ) {wrmsrl (MSR_CORE_PERF_GLOBAL_OVF_CTRL , core2_vpmu_cxt->global_ovf_ctrl);core2_vpmu_cxt->global_ovf_ctrl = 0;xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-1@@ -436,7 +436,7 @@ static int core2_vpmu_msr_common_check(u32 msr_index, int *type, int *index) {__core2_vpmu_load (current);vpmu_set (vpmu,VPMU_CONTEXT_LOADED ); -if ( cpu_has_vmx_msr_bitmap && is_hvm_domain(current->domain) ) +if ( cpu_has_vmx_msr_bitmap &&has_hvm_container_domain (current->domain) )core2_vpmu_set_msr_bitmap(current->arch.hvm_vmx.msr_bitmap); } return 1;xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-1@@ -444,7 +444,7 @@ static int core2_vpmu_msr_common_check(u32 msr_index, int *type, int *index)static void inject_trap (struct vcpu *v,unsigned int trapno) { -if ( !is_pv_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) )hvm_inject_hw_exception (trapno,0 );else send_guest_trap(v->domain, v->vcpu_id, trapno);xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-1@@ -538,7 +538,7 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) break;case MSR_CORE_PERF_FIXED_CTR_CTRL : non_global_ctrl = msr_content; -if ( !is_pv_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) )vmx_read_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , &global_ctrl);else rdmsrl(MSR_CORE_PERF_GLOBAL_CTRL, global_ctrl);xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-1@@ -558,7 +558,7 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)struct xen_pmu_cntr_pair *xen_pmu_cntr_pair =vpmu_reg_pointer (core2_vpmu_cxt, arch_counters); -if ( !is_pv_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) )vmx_read_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , &global_ctrl);else rdmsrl(MSR_CORE_PERF_GLOBAL_CTRL, global_ctrl);xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-1@@ -608,7 +608,7 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) }else { -if ( !is_pv_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) )vmx_write_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , msr_content);else wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, msr_content);xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-1@@ -636,7 +636,7 @@ static int core2_vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) *msr_content = core2_vpmu_cxt->global_status;break ;case MSR_CORE_PERF_GLOBAL_CTRL : -if ( !is_pv_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) )vmx_read_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL , msr_content);else rdmsrl(MSR_CORE_PERF_GLOBAL_CTRL, *msr_content);xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-1@@ -803,7 +803,7 @@ func_out:check_pmc_quirk ();/* PV domains can allocate resources immediately */ -if (is_pv_domain (v->domain) && !core2_vpmu_alloc_resource (v) ) +if ( !has_hvm_container_domain (v->domain) && !core2_vpmu_alloc_resource (v) )return 1 ;return 0;xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-1@@ -816,7 +816,7 @@ static void core2_vpmu_destroy(struct vcpu *v)if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )return ; -if (is_hvm_domain (v->domain) ) +if (has_hvm_container_domain (v->domain) ) {xfree (vpmu->context);if ( cpu_has_vmx_msr_bitmap )xen/arch/x86/hvm/vpmu.c +1
-1@@ -103,7 +103,7 @@ void vpmu_lvtpc_update(uint32_t val) vpmu->hw_lapic_lvtpc = vpmu_interrupt_type | (val &APIC_LVT_MASKED );/* Postpone APIC updates for PV guests if PMU interrupt is pending */ - if ( !is_pv_domain(current->domain) || + if ( !has_hvm_container_domain(current->domain) || !(current->arch.vpmu.xenpmu_data && current->arch.vpmu.xenpmu_data->pmu_flags &
PMU_CACHED) )apic_write(APIC_LVTPC, vpmu->hw_lapic_lvtpc);xen/arch/x86/hvm/vpmu.c +1
-1@@ -147,7 +147,7 @@ int vpmu_do_wrmsr(unsigned int msr, uint64_tmsr_content) * and since do_wrmsr may load VPMU context we should save * (and unload) it again. */ -if ( !is_hvm_domain (current->domain) && +if ( !has_hvm_container_domain (current->domain) && (current->arch.vpmu.xenpmu_data->pmu_flags &PMU_CACHED ) ){ vpmu_set(vpmu, VPMU_CONTEXT_SAVE);xen/arch/x86/hvm/vpmu.c +1
-1@@ -171,7 +171,7 @@ int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) {int ret = vpmu->arch_vpmu_ops->do_rdmsr (msr, msr_content); -if ( !is_hvm_domain (current->domain) && +if ( !has_hvm_container_domain (current->domain) && (current->arch.vpmu.xenpmu_data->pmu_flags &PMU_CACHED ) ){ vpmu_set(vpmu, VPMU_CONTEXT_SAVE);xen/arch/x86/hvm/vpmu.c +2
-1@@ -200,13 +200,17 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs)if ( !is_hvm_domain (v->domain) || (vpmu_mode &XENPMU_MODE_PRIV ) ) { -/* PV guest or dom0 is doing system profiling */ +/* PV(H) guest or dom0 is doing system profiling */ struct cpu_user_regs *gregs;int err;if ( v->arch.vpmu.xenpmu_data->pmu_flags &PMU_CACHED )return 1 ; + if ( is_pvh_domain(current->domain) && !(vpmu_mode &
XENPMU_MODE_PRIV) &&xen/arch/x86/hvm/vpmu.c +3
-0+ !vpmu->arch_vpmu_ops->do_interrupt(regs) ) +return 0 ; +/* PV guest will be reading PMU MSRs from xenpmu_data */ vpmu_set(vpmu, VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED); err = vpmu->arch_vpmu_ops->arch_vpmu_save(v);xen/arch/x86/hvm/vpmu.c +10
-2@@ -243,7 +247,7 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs)else if ( !is_control_domain (current->domain) && !is_idle_vcpu (current) ) { -/* PV guest */ +/* PV(H) guest */ gregs =guest_cpu_user_regs ();memcpy (&v->arch.vpmu.xenpmu_data->pmu.r.regs, gregs,sizeof (struct cpu_user_regs ));@@ -253,7 +257,15 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs) regs, sizeof(struct cpu_user_regs)); gregs = &v->arch.vpmu.xenpmu_data->pmu.r.regs; - gregs->cs = (current->arch.flags & TF_kernel_mode) ?0 :0x3 ; +if ( !is_pvh_domain (current->domain) ) + gregs->cs = (current->arch.flags & TF_kernel_mode) ?0 :0x3 ; +else if ( !(vpmu_interrupt_type &APIC_DM_NMI ) ) + { +struct segment_register seg_cs; + +hvm_get_segment_register (current, x86_seg_cs, &seg_cs); + gregs->cs = seg_cs.attr.fields.dpl; + } }else {xen/arch/x86/hvm/vpmu.c +2
-1@@ -277,7 +289,8 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs) v->arch.vpmu.xenpmu_data->vcpu_id = current->vcpu_id; v->arch.vpmu.xenpmu_data->pcpu_id =smp_processor_id (); - v->arch.vpmu.xenpmu_data->pmu_flags |=PMU_CACHED ; +if ( !is_pvh_domain (current->domain) || (vpmu_mode &XENPMU_MODE_PRIV ) ) + v->arch.vpmu.xenpmu_data->pmu_flags |=PMU_CACHED ;apic_write (APIC_LVTPC , vpmu->hw_lapic_lvtpc |APIC_LVT_MASKED );vpmu->hw_lapic_lvtpc |= APIC_LVT_MASKED;xen/arch/x86/hvm/vpmu.c +1
-1@@ -404,7 +417,7 @@ void vpmu_load(struct vcpu *v)/* Only when PMU is counting, we load PMU context immediately. */ if ( !vpmu_is_set (vpmu,VPMU_RUNNING ) || - (is_pv_domain (v->domain) && vpmu->xenpmu_data->pmu_flags & PMU_CACHED) ) + (!has_hvm_container_domain(v->domain) && vpmu->xenpmu_data->pmu_flags & PMU_CACHED) )return ;if ( vpmu->arch_vpmu_ops &&
vpmu->arch_vpmu_ops->arch_vpmu_load)xen/arch/x86/hvm/vpmu.c +1
-5@@ -521,7 +534,7 @@ static void pmu_softnmi(void) } regs = &v->arch.vpmu.xenpmu_data->pmu.r.regs; -if ( !is_pv_domain (sampled->domain) ) +if (has_hvm_container_domain (sampled->domain) ) {struct segment_register cs;@@ -544,9 +557,6 @@ static int pvpmu_init(struct domain *d, xen_pmu_params_t *params)uint64_t gfn = params->d.val;static bool_t __read_mostly pvpmu_initted =0 ; -if ( !is_pv_domain (d) ) -return -EINVAL ; -if ( params->vcpu <0 || params->vcpu >= d->max_vcpus )return -EINVAL ; --1.8.3.1
PATCH RESEND v5 17/17 x86/VPMU: Move VPMU files up from hvm/ directory
In reply to Boris OstrovskySince PMU is now not HVM specific we can move VPMU-related files up from arch/x86/hvm/ directory.
Specifically:
arch/x86/hvm/vpmu.c -> arch/x86/vpmu.c
arch/x86/hvm/svm/vpmu.c -> arch/x86/vpmu_amd.c
arch/x86/hvm/vmx/vpmu_core2.c -> arch/x86/vpmu_intel.c
include/asm-x86/hvm/vpmu.h -> include/asm-x86/vpmu.h--- xen/arch/x86/Makefile | 1 + xen/arch/x86/hvm/Makefile | 1 - xen/arch/x86/hvm/svm/Makefile | 1 - xen/arch/x86/hvm/svm/vpmu.c | 509 ------------------ xen/arch/x86/hvm/vlapic.c | 2 +- xen/arch/x86/hvm/vmx/Makefile | 1 - xen/arch/x86/hvm/vmx/vpmu_core2.c | 940 ---------------------------------- xen/arch/x86/hvm/vpmu.c | 720 -------------------------- xen/arch/x86/oprofile/op_model_ppro.c | 2 +- xen/arch/x86/traps.c | 2 +- xen/arch/x86/vpmu.c | 720 ++++++++++++++++++++++++++ xen/arch/x86/vpmu_amd.c | 509 ++++++++++++++++++ xen/arch/x86/vpmu_intel.c | 940 ++++++++++++++++++++++++++++++++++ xen/include/asm-x86/hvm/vmx/vmcs.h | 2 +- xen/include/asm-x86/hvm/vpmu.h | 99 ---- xen/include/asm-x86/vpmu.h | 99 ++++ 16 files changed, 2273 insertions(+), 2275 deletions(-) delete mode 100644 xen/arch/x86/hvm/svm/vpmu.c delete mode 100644 xen/arch/x86/hvm/vmx/vpmu_core2.c delete mode 100644 xen/arch/x86/hvm/vpmu.c create mode 100644 xen/arch/x86/vpmu.c create mode 100644 xen/arch/x86/vpmu_amd.c create mode 100644 xen/arch/x86/vpmu_intel.c delete mode 100644 xen/include/asm-x86/hvm/vpmu.h create mode 100644 xen/include/asm-x86/vpmu.h
xen/arch/x86/Makefile +1 -0
@@ -58,6 +58,7 @@ obj-y += crash.o obj-y += tboot.o obj-y += hpet.o obj-y += xstate.o +obj-y += vpmu.o vpmu_amd.o vpmu_intel.o obj-$(crash_debug) += gdbstub.o
xen/arch/x86/hvm/Makefile +0 -1
@@ -22,4 +22,3 @@ obj-y += vlapic.o obj-y += vmsi.o obj-y += vpic.o obj-y += vpt.o -obj-y += vpmu.o
xen/arch/x86/hvm/svm/Makefile +0 -1
@@ -6,4 +6,3 @@ obj-y += nestedsvm.o obj-y += svm.o obj-y += svmdebug.o obj-y += vmcb.o -obj-y += vpmu.o
xen/arch/x86/hvm/svm/vpmu.c deleted +0 -509
509 lines not on this page · raw message
xen/arch/x86/hvm/vlapic.c +1 -1
@@ -38,7 +38,7 @@#include <asm/hvm/support.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/nestedhvm.h> -#include <asm/hvm/vpmu.h> +#include <asm/vpmu.h> #include <public/hvm/ioreq.h> #include <public/hvm/params.h>
xen/arch/x86/hvm/vmx/Makefile +0 -1
@@ -3,5 +3,4 @@ obj-y += intr.o obj-y += realmode.o obj-y += vmcs.o obj-y += vmx.o -obj-y += vpmu_core2.o obj-y += vvmx.o
xen/arch/x86/hvm/vmx/vpmu_core2.c deleted +0 -940
940 lines not on this page · raw message
xen/arch/x86/hvm/vpmu.c deleted +0 -720
720 lines not on this page · raw message
xen/arch/x86/oprofile/op_model_ppro.c +1 -1
@@ -19,7 +19,7 @@#include <asm/processor.h> #include <asm/regs.h> #include <asm/current.h> -#include <asm/hvm/vpmu.h> +#include <asm/vpmu.h> #include "op_x86_model.h" #include "op_counter.h"
xen/arch/x86/traps.c +1 -1
@@ -72,7 +72,7 @@#include <asm/apic.h> #include <asm/mc146818rtc.h> #include <asm/hpet.h> -#include <asm/hvm/vpmu.h> +#include <asm/vpmu.h> #include <public/arch-x86/cpuid.h> #include <xsm/xsm.h>
xen/arch/x86/vpmu.c new file +720 -0
720 lines not on this page · raw message
xen/arch/x86/vpmu_amd.c new file +509 -0
66 lines not on this page · raw message
xen/arch/x86/vpmu_intel.c new file +940 -0
940 lines not on this page · raw message
xen/include/asm-x86/hvm/vpmu.h deleted +0 -99
99 lines not on this page · raw message
xen/include/asm-x86/vpmu.h new file +99 -0
99 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.3.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH v5 RESEND 17/17] x86/VPMU: Move VPMU files up from hvm/ directory
Quoted 6 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:51 PMSince PMU is now not HVM specific we can move VPMU-related files up from
arch/x86/hvm/directory.
Quoted 7 lines
Specifically:
arch/x86/hvm/vpmu.c -> arch/x86/vpmu.c arch/x86/hvm/svm/vpmu.c -> arch/x86/vpmu_amd.c arch/x86/hvm/vmx/vpmu_core2.c -> arch/x86/vpmu_intel.c include/asm-x86/hvm/vpmu.h -> include/asm-x86/vpmu.hSigned-off-by Boris Ostrovsky <[email protected]>
Quoted 29 lines
--- xen/arch/x86/Makefile | 1 + xen/arch/x86/hvm/Makefile | 1 - xen/arch/x86/hvm/svm/Makefile | 1 - xen/arch/x86/hvm/svm/vpmu.c | 509 ------------------ xen/arch/x86/hvm/vlapic.c | 2 +- xen/arch/x86/hvm/vmx/Makefile | 1 - xen/arch/x86/hvm/vmx/vpmu_core2.c | 940 ---------------------------------- xen/arch/x86/hvm/vpmu.c | 720 -------------------------- xen/arch/x86/oprofile/op_model_ppro.c | 2 +- xen/arch/x86/traps.c | 2 +- xen/arch/x86/vpmu.c | 720 ++++++++++++++++++++++++++ xen/arch/x86/vpmu_amd.c | 509 ++++++++++++++++++ xen/arch/x86/vpmu_intel.c | 940 ++++++++++++++++++++++++++++++++++ xen/include/asm-x86/hvm/vmx/vmcs.h | 2 +- xen/include/asm-x86/hvm/vpmu.h | 99 ---- xen/include/asm-x86/vpmu.h | 99 ++++ 16 files changed, 2273 insertions(+), 2275 deletions(-) delete mode 100644 xen/arch/x86/hvm/svm/vpmu.c delete mode 100644 xen/arch/x86/hvm/vmx/vpmu_core2.c delete mode 100644 xen/arch/x86/hvm/vpmu.c create mode 100644 xen/arch/x86/vpmu.c create mode 100644 xen/arch/x86/vpmu_amd.c create mode 100644 xen/arch/x86/vpmu_intel.c delete mode 100644 xen/include/asm-x86/hvm/vpmu.h create mode 100644 xen/include/asm-x86/vpmu.h
Quoted 4 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:50 PM(Resending v5 per Kevin's request)
Hi, Boris, thanks for resending. will spend some time to review and get back my comments soon.
Thanks
Kevin
Quoted 214 lines
Here is the fifth version of PV(H) PMU patches.
Changes in v5:
* Dropped patch number 2 ("Stop AMD counters when called from
vpmu_save_force()")
as no longer needed
* Added patch number 2 that marks context as loaded before PMU registers are
loaded. This prevents situation where a PMU interrupt may occur while
context
is still viewed as not loaded. (This is really a bug fix for exsiting VPMU code)
* Renamedxenpmu.hfiles topmu.h
* More careful use ofis_pv_domain(), is_hvm_domain(,is_pvh_domainandhas_hvm_container_domain(). Also explicitly disabled support for PVH until patch 16 to make distinction between usage of the above macros more
clear.
* Added support for disabling VPMU support during runtime.
* Disable VPMUs for non-privileged domains when switching to privileged profiling mode
* Added ARM stub forxen_arch_pmu_t
* Separatedvpmu_modefromvpmu_features
* Moved CS register query to make sure we use appropriate query mechanism for
various guest types.
* LVTPC is now set from value in shared area, not copied from dom0
* Various code and comments cleanup as suggested by Jan.Changes in v4:
* Added support for PVH guests:
o changes inpvpmu_init()to accommodate both PV and PVH guests, still in
patch 10
o more careful use ofis_hvm_domain
o Additional patch (16)
* Moved HVM interrupt handling out ofvpmu_do_interrupt()for NMI-safe handling
* Fixed dom0's VCPU selection in privileged mode
* Added a cast in register copy for 32-bit PV guestscpu_user_regs_tinvpmu_do_interrupt.
(don't want to exposecompat_cpu_user_regsin a public header)
* Renamed public structures by prefixing them with "xen_"
* Added an entry forxenpf_symdatain xlat.lst
* Fixedpv_cpuidcheck for vpmu-specific cpuid adjustments
* Varios code style fixes
* Eliminated anonymous unions
* Added more verbiage to NMI patch descriptionChanges in v3:
* Moved PMU MSR banks out from architectural context data structures to allow
for future expansion without protocol changes
* PMU interrupts can be either NMIs or regular vector interrupts (the latter is the default)
* Context is now marked asPMU_CACHEDby the hypervisor code to avoid certain
race conditions with the guest
* Fixed races with PV guest in MSR access handlers
* More Intel VPMU cleanup
* Moved NMI-unsafe code from NMI handler
* Dropped changes tovcpu->is_running
* Added LVTPC apic handling (cached for PV guests)
* Separated privileged profiling mode into a standalone patch
* Separated NMI handling into a standalone patchChanges in v2:
* Xen symbols are exported as data structure (as opoosed to a set of formatted
strings in v1). Even though one symbol per hypercall is returned performance appears to be acceptable: reading whole file from dom0 userland takes on average
about twice as long as reading/proc/kallsyms
* More cleanup of Intel VPMU code to simplify publicly exported structures
* There is an architecture-independent and x86-specific public include files (ARM
has a stub)
* General cleanup of public include files to make them more presentable (and to make auto doc generation better)
* Setting ofvcpu->is_runningis now done on ARM inschedule_tailas well (making
changes tocommon/schedule.carchitecture-independent). Note that this is not
tested since I don't have access to ARM hardware.
* PCPU ID of interrupted processor is now passed to PV guestThe following patch series adds PMU support in Xen for PV(H) guests. There is a companion patchset for Linux kernel. In addition, another set of changes will be provided (later) for userland perf code.
This version has following limitations:
* For accurate profiling of dom0/Xen dom0 VCPUs should be pinned.
* Hypervisor code is only profiled on processors that have running dom0 VCPUs
on them.
* No backtrace support.
* Will fail to load under XSM: we ran out of bits in permissions vector and this needs to be fixed separatelyA few notes that may help reviewing:
* A shared data structure (
xenpmu_data_t) between each PV VPCU and hypervisor
CPU is used for passing registers' values as well as PMU state at the time of PMU interrupt.
* PMU interrupts are taken by hypervisor either as NMIs or regular vector interrupts for both HVM and PV(H). The interrupts are sent as NMIs to HVM guests
and as virtual interrupts to PV(H) guests
* PV guest's interrupt handler does not read/write PMU MSRs directly. Instead, it
accessesxenpmu_data_tand flushes it to HW it before returning.
* PMU mode is controlled at runtime via/sys/hypervisor/pmu/pmu/{pmu_mode,pmu_flags}
in addition to 'vpmu' boot option (which is preserved for back compatibility). The following modes are provided:
* disable: VPMU is off
* enable: VPMU is on. Guests can profile themselves, dom0 profiles itself
and Xen
*priv_enable: dom0 only profiling. dom0 collects samples for everyone.
Sampling
in guests is suspended.
*/proc/xen/xensymsfile exports hypervisor's symbols to dom0 (similar to/proc/kallsyms)
* VPMU infrastructure is now used for HVM, PV and PVH and therefore has been moved
up from hvm subtreeBoris Ostrovsky (17):
common/symbols: Export hypervisor symbols to privileged guest
VPMU: Mark context LOADED before registers are loaded x86/VPMU: Minor VPMU cleanup
intel/VPMU: Clean up Intel VPMU code
x86/VPMU: HandleAPIC_LVTPCaccesses
intel/VPMU:MSR_CORE_PERF_GLOBAL_CTRLshould be initialized to zero x86/VPMU: Add publicxenpmu.h
x86/VPMU: Make vpmu not HVM-specific
x86/VPMU: Interface for setting PMU mode and flags x86/VPMU: Initialize PMU for PV guests
x86/VPMU: Add support for PMU register handling on PV guests x86/VPMU: Handle PMU interrupts for PV guests
x86/VPMU: Add privileged PMU mode
x86/VPMU: Save VPMU state for PV guests during context switch x86/VPMU: NMI-based VPMU support
x86/VPMU: Suport for PVH guests
x86/VPMU: Move VPMU files up from hvm/ directoryxen/arch/x86/Makefile | 1 + xen/arch/x86/domain.c | 15 +- xen/arch/x86/hvm/Makefile | 1 - xen/arch/x86/hvm/hvm.c | 3 +- xen/arch/x86/hvm/svm/Makefile | 1 - xen/arch/x86/hvm/svm/svm.c | 6 +- xen/arch/x86/hvm/svm/vpmu.c | 494 ---------------- xen/arch/x86/hvm/vlapic.c | 5 +- xen/arch/x86/hvm/vmx/Makefile | 1 - xen/arch/x86/hvm/vmx/vmcs.c | 55 ++ xen/arch/x86/hvm/vmx/vmx.c | 6 +- xen/arch/x86/hvm/vmx/vpmu_core2.c | 931 ------------------------------ xen/arch/x86/hvm/vpmu.c | 266 --------- xen/arch/x86/oprofile/op_model_ppro.c | 8 +- xen/arch/x86/platform_hypercall.c | 18 + xen/arch/x86/traps.c | 35 +- xen/arch/x86/vpmu.c | 720 +++++++++++++++++++++++ xen/arch/x86/vpmu_amd.c | 509 +++++++++++++++++ xen/arch/x86/vpmu_intel.c | 940 +++++++++++++++++++++++++++++++ xen/arch/x86/x86_64/compat/entry.S | 4 + xen/arch/x86/x86_64/entry.S | 4 + xen/arch/x86/x86_64/platform_hypercall.c | 2 + xen/common/event_channel.c | 1 + xen/common/symbols.c | 50 +- xen/common/vsprintf.c | 2 +- xen/include/asm-x86/domain.h | 2 + xen/include/asm-x86/hvm/vcpu.h | 3 - xen/include/asm-x86/hvm/vmx/vmcs.h | 4 +- xen/include/asm-x86/hvm/vmx/vpmu_core2.h | 51 -- xen/include/asm-x86/hvm/vpmu.h | 104 ---- xen/include/asm-x86/vpmu.h | 99 ++++ xen/include/public/arch-arm.h | 3 + xen/include/public/arch-x86/pmu.h | 63 +++ xen/include/public/platform.h | 16 + xen/include/public/pmu.h | 99 ++++ xen/include/public/xen.h | 2 + xen/include/xen/hypercall.h | 4 + xen/include/xen/softirq.h | 1 + xen/include/xen/symbols.h | 6 +- xen/include/xlat.lst | 1 + 40 files changed, 2661 insertions(+), 1875 deletions(-) delete mode 100644 xen/arch/x86/hvm/svm/vpmu.c delete mode 100644 xen/arch/x86/hvm/vmx/vpmu_core2.c delete mode 100644 xen/arch/x86/hvm/vpmu.c create mode 100644 xen/arch/x86/vpmu.c create mode 100644 xen/arch/x86/vpmu_amd.c create mode 100644 xen/arch/x86/vpmu_intel.c delete mode 100644 xen/include/asm-x86/hvm/vmx/vpmu_core2.h delete mode 100644 xen/include/asm-x86/hvm/vpmu.h create mode 100644 xen/include/asm-x86/vpmu.h create mode 100644 xen/include/public/arch-x86/pmu.h create mode 100644 xen/include/public/pmu.h--
1.8.3.1
Quoted 4 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 8:50 PM(Resending v5 per Kevin's request)
Hi, Boris, I've acked most intel related patches, with some comments replied individually.
Thanks
Kevin
Quoted 214 lines
Here is the fifth version of PV(H) PMU patches.
Changes in v5:
* Dropped patch number 2 ("Stop AMD counters when called from
vpmu_save_force()")
as no longer needed
* Added patch number 2 that marks context as loaded before PMU registers are
loaded. This prevents situation where a PMU interrupt may occur while
context
is still viewed as not loaded. (This is really a bug fix for exsiting VPMU code)
* Renamedxenpmu.hfiles topmu.h
* More careful use ofis_pv_domain(), is_hvm_domain(,is_pvh_domainandhas_hvm_container_domain(). Also explicitly disabled support for PVH until patch 16 to make distinction between usage of the above macros more
clear.
* Added support for disabling VPMU support during runtime.
* Disable VPMUs for non-privileged domains when switching to privileged profiling mode
* Added ARM stub forxen_arch_pmu_t
* Separatedvpmu_modefromvpmu_features
* Moved CS register query to make sure we use appropriate query mechanism for
various guest types.
* LVTPC is now set from value in shared area, not copied from dom0
* Various code and comments cleanup as suggested by Jan.Changes in v4:
* Added support for PVH guests:
o changes inpvpmu_init()to accommodate both PV and PVH guests, still in
patch 10
o more careful use ofis_hvm_domain
o Additional patch (16)
* Moved HVM interrupt handling out ofvpmu_do_interrupt()for NMI-safe handling
* Fixed dom0's VCPU selection in privileged mode
* Added a cast in register copy for 32-bit PV guestscpu_user_regs_tinvpmu_do_interrupt.
(don't want to exposecompat_cpu_user_regsin a public header)
* Renamed public structures by prefixing them with "xen_"
* Added an entry forxenpf_symdatain xlat.lst
* Fixedpv_cpuidcheck for vpmu-specific cpuid adjustments
* Varios code style fixes
* Eliminated anonymous unions
* Added more verbiage to NMI patch descriptionChanges in v3:
* Moved PMU MSR banks out from architectural context data structures to allow
for future expansion without protocol changes
* PMU interrupts can be either NMIs or regular vector interrupts (the latter is the default)
* Context is now marked asPMU_CACHEDby the hypervisor code to avoid certain
race conditions with the guest
* Fixed races with PV guest in MSR access handlers
* More Intel VPMU cleanup
* Moved NMI-unsafe code from NMI handler
* Dropped changes tovcpu->is_running
* Added LVTPC apic handling (cached for PV guests)
* Separated privileged profiling mode into a standalone patch
* Separated NMI handling into a standalone patchChanges in v2:
* Xen symbols are exported as data structure (as opoosed to a set of formatted
strings in v1). Even though one symbol per hypercall is returned performance appears to be acceptable: reading whole file from dom0 userland takes on average
about twice as long as reading/proc/kallsyms
* More cleanup of Intel VPMU code to simplify publicly exported structures
* There is an architecture-independent and x86-specific public include files (ARM
has a stub)
* General cleanup of public include files to make them more presentable (and to make auto doc generation better)
* Setting ofvcpu->is_runningis now done on ARM inschedule_tailas well (making
changes tocommon/schedule.carchitecture-independent). Note that this is not
tested since I don't have access to ARM hardware.
* PCPU ID of interrupted processor is now passed to PV guestThe following patch series adds PMU support in Xen for PV(H) guests. There is a companion patchset for Linux kernel. In addition, another set of changes will be provided (later) for userland perf code.
This version has following limitations:
* For accurate profiling of dom0/Xen dom0 VCPUs should be pinned.
* Hypervisor code is only profiled on processors that have running dom0 VCPUs
on them.
* No backtrace support.
* Will fail to load under XSM: we ran out of bits in permissions vector and this needs to be fixed separatelyA few notes that may help reviewing:
* A shared data structure (
xenpmu_data_t) between each PV VPCU and hypervisor
CPU is used for passing registers' values as well as PMU state at the time of PMU interrupt.
* PMU interrupts are taken by hypervisor either as NMIs or regular vector interrupts for both HVM and PV(H). The interrupts are sent as NMIs to HVM guests
and as virtual interrupts to PV(H) guests
* PV guest's interrupt handler does not read/write PMU MSRs directly. Instead, it
accessesxenpmu_data_tand flushes it to HW it before returning.
* PMU mode is controlled at runtime via/sys/hypervisor/pmu/pmu/{pmu_mode,pmu_flags}
in addition to 'vpmu' boot option (which is preserved for back compatibility). The following modes are provided:
* disable: VPMU is off
* enable: VPMU is on. Guests can profile themselves, dom0 profiles itself
and Xen
*priv_enable: dom0 only profiling. dom0 collects samples for everyone.
Sampling
in guests is suspended.
*/proc/xen/xensymsfile exports hypervisor's symbols to dom0 (similar to/proc/kallsyms)
* VPMU infrastructure is now used for HVM, PV and PVH and therefore has been moved
up from hvm subtreeBoris Ostrovsky (17):
common/symbols: Export hypervisor symbols to privileged guest
VPMU: Mark context LOADED before registers are loaded x86/VPMU: Minor VPMU cleanup
intel/VPMU: Clean up Intel VPMU code
x86/VPMU: HandleAPIC_LVTPCaccesses
intel/VPMU:MSR_CORE_PERF_GLOBAL_CTRLshould be initialized to zero x86/VPMU: Add publicxenpmu.h
x86/VPMU: Make vpmu not HVM-specific
x86/VPMU: Interface for setting PMU mode and flags x86/VPMU: Initialize PMU for PV guests
x86/VPMU: Add support for PMU register handling on PV guests x86/VPMU: Handle PMU interrupts for PV guests
x86/VPMU: Add privileged PMU mode
x86/VPMU: Save VPMU state for PV guests during context switch x86/VPMU: NMI-based VPMU support
x86/VPMU: Suport for PVH guests
x86/VPMU: Move VPMU files up from hvm/ directoryxen/arch/x86/Makefile | 1 + xen/arch/x86/domain.c | 15 +- xen/arch/x86/hvm/Makefile | 1 - xen/arch/x86/hvm/hvm.c | 3 +- xen/arch/x86/hvm/svm/Makefile | 1 - xen/arch/x86/hvm/svm/svm.c | 6 +- xen/arch/x86/hvm/svm/vpmu.c | 494 ---------------- xen/arch/x86/hvm/vlapic.c | 5 +- xen/arch/x86/hvm/vmx/Makefile | 1 - xen/arch/x86/hvm/vmx/vmcs.c | 55 ++ xen/arch/x86/hvm/vmx/vmx.c | 6 +- xen/arch/x86/hvm/vmx/vpmu_core2.c | 931 ------------------------------ xen/arch/x86/hvm/vpmu.c | 266 --------- xen/arch/x86/oprofile/op_model_ppro.c | 8 +- xen/arch/x86/platform_hypercall.c | 18 + xen/arch/x86/traps.c | 35 +- xen/arch/x86/vpmu.c | 720 +++++++++++++++++++++++ xen/arch/x86/vpmu_amd.c | 509 +++++++++++++++++ xen/arch/x86/vpmu_intel.c | 940 +++++++++++++++++++++++++++++++ xen/arch/x86/x86_64/compat/entry.S | 4 + xen/arch/x86/x86_64/entry.S | 4 + xen/arch/x86/x86_64/platform_hypercall.c | 2 + xen/common/event_channel.c | 1 + xen/common/symbols.c | 50 +- xen/common/vsprintf.c | 2 +- xen/include/asm-x86/domain.h | 2 + xen/include/asm-x86/hvm/vcpu.h | 3 - xen/include/asm-x86/hvm/vmx/vmcs.h | 4 +- xen/include/asm-x86/hvm/vmx/vpmu_core2.h | 51 -- xen/include/asm-x86/hvm/vpmu.h | 104 ---- xen/include/asm-x86/vpmu.h | 99 ++++ xen/include/public/arch-arm.h | 3 + xen/include/public/arch-x86/pmu.h | 63 +++ xen/include/public/platform.h | 16 + xen/include/public/pmu.h | 99 ++++ xen/include/public/xen.h | 2 + xen/include/xen/hypercall.h | 4 + xen/include/xen/softirq.h | 1 + xen/include/xen/symbols.h | 6 +- xen/include/xlat.lst | 1 + 40 files changed, 2661 insertions(+), 1875 deletions(-) delete mode 100644 xen/arch/x86/hvm/svm/vpmu.c delete mode 100644 xen/arch/x86/hvm/vmx/vpmu_core2.c delete mode 100644 xen/arch/x86/hvm/vpmu.c create mode 100644 xen/arch/x86/vpmu.c create mode 100644 xen/arch/x86/vpmu_amd.c create mode 100644 xen/arch/x86/vpmu_intel.c delete mode 100644 xen/include/asm-x86/hvm/vmx/vpmu_core2.h delete mode 100644 xen/include/asm-x86/hvm/vpmu.h create mode 100644 xen/include/asm-x86/vpmu.h create mode 100644 xen/include/public/arch-x86/pmu.h create mode 100644 xen/include/public/pmu.h--
1.8.3.1