x86/PMU: Xen PMU PV(H) support
v9 cover x86/PMU: Xen PMU PV(H) support
Here is the ninth version of PV(H) PMU patches.
Changes in v9:
* Restore VPMU context after context_saved() is called in context_switch(). This is needed because vpmu_load() may end up calling vmx_vmcs_try_enter()->vcpu_pause() and that needs is_running to be correctly set/cleared. (patch 18, dropped review acks)
* Added patch 2 to properly manage VPMU_CONTEXT_LOADED
* Addressed most of Jan's comments.
o Keep track of time in vpmu_force_context_switch() to properly break out of a loop when using hypercall continuations
o Fixed logic in calling vpmu_do_msr() in emulate_privileged_op()
o Cleaned up vpmu_interrupt() wrt vcpu variable names to (hopefully) make it more clear which vcpu we are using
o Cleaned up vpmu_do_wrmsr()
o Did *not* replace sizeof(uint64_t) with sizeof(variable) in amd_vpmu_initialise(): throughout the code registers are declared as uint64_t and if we are to add a new type (e.g. reg_t) this should be done in a separate patch, unrelated to this series.
o Various more minor cleanups and code style fixes
Changes in v8:
* Cleaned up a bit definitions of struct xenpf_symdata and xen_pmu_params
* Added compat checks for vpmu structures
* Converted vpmu flag manipulation macros to inline routines
* Reimplemented vpmu_unload_all() to avoid long loops
* Reworked PMU fault generation and handling (new patch #12)
* Added checks for domain->vcpu[] non-NULLness
* Added more comments, renamed some routines and macros, code style cleanup
Changes in v7:
* When reading hypervisor symbols make the caller pass buffer length (as opposed to having this length be part of the API). Make the hypervisor buffer static, make xensyms_read() return zero-length string on end-of-symbols. Make 'type' field of xenpf_symdata a char, drop compat_pf_symdata definition.
* Spread PVH support across patches as opposed to lumping it into a separate patch
* Rename vpmu_is_set_all() to vpmu_are_all_set()
* Split VPMU cleanup patch in two
* Use memmove when copying VMX guest and host MSRs
* Make padding of xen_arch_pmu's context union a constand that does not depend on arch context size.
* Set interface version to 0.1
* Check pointer validity in pvpmu_init/destroy()
* Fixed crash in core2_vpmu_dump()
* Fixed crash in vmx_add_msr()
* Break handling of Intel and AMD MSRs in traps.c into separate cases
* Pass full CS selector to guests
* Add lock in pvpmu init code to prevent potential race
Changes in v6:
* Two new patches:
o Merge VMX MSR add/remove routines in vmcs.c (patch 5)
o Merge VPMU read/write MSR routines in vpmu.c (patch 14)
* Check for pending NMI softirq after saving VPMU context to prevent a newly-scheduled guest from overwriting sampled_vcpu written by de-scheduled VPCU.
* Keep track of enabled counters on Intel. This was removed in earlier patches and was a mistake. As result of this change struct vpmu will have a pointer to private context data (i.e. data that is not exposed to a PV(H) guest). Use this private pointer on SVM as well for storing MSR bitmap status (it was unnecessarily exposed to PV guests earlier).
Dropped Reviewed-by: and Tested-by: tags from patch 4 since it needs to be reviewed agan (core2_vpmu_do_wrmsr() routine, mostly)
* Replaced references to dom0 with hardware_domain (and is_control_domain with is_hardware_domain for consistency)
* Prevent non-privileged domains from reading PMU MSRs in VPMU_PRIV_MODE
* Reverted unnecessary changes in vpmu_initialise()'s switch statement
* Fixed comment in vpmu_do_interrupt
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 (20):
common/symbols: Export hypervisor symbols to privileged guest x86/VPMU: Manage VPMU_CONTEXT_SAVE flag in vpmu_save_force() x86/VPMU: Set MSR bitmaps only for HVM/PVH guests x86/VPMU: Make vpmu macros a bit more efficient intel/VPMU: Clean up Intel VPMU code
vmx: Merge MSR management routines
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(H) guests
x86/VPMU: When handling MSR accesses, leave fault injection to callers x86/VPMU: Add support for PMU register handling on PV guests x86/VPMU: Handle PMU interrupts for PV guests
x86/VPMU: Merge vpmu_rdmsr and vpmu_wrmsr
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: Move VPMU files up from hvm/ directory
xen/arch/x86/Makefile | 1 + xen/arch/x86/domain.c | 21 +- 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 | 14 +- xen/arch/x86/hvm/svm/vpmu.c | 496 ---------------- xen/arch/x86/hvm/vlapic.c | 5 +- xen/arch/x86/hvm/vmx/Makefile | 1 - xen/arch/x86/hvm/vmx/vmcs.c | 114 ++-- xen/arch/x86/hvm/vmx/vmx.c | 41 +- xen/arch/x86/hvm/vmx/vpmu_core2.c | 937 ------------------------------- xen/arch/x86/hvm/vpmu.c | 265 --------- xen/arch/x86/oprofile/op_model_ppro.c | 8 +- xen/arch/x86/platform_hypercall.c | 33 ++ xen/arch/x86/traps.c | 60 +- xen/arch/x86/vpmu.c | 828 +++++++++++++++++++++++++++ xen/arch/x86/vpmu_amd.c | 517 +++++++++++++++++ xen/arch/x86/vpmu_intel.c | 934 ++++++++++++++++++++++++++++++ xen/arch/x86/x86_64/compat/entry.S | 4 + xen/arch/x86/x86_64/entry.S | 4 + xen/common/event_channel.c | 1 + xen/common/symbols.c | 54 ++ xen/include/Makefile | 1 + xen/include/asm-x86/domain.h | 2 + xen/include/asm-x86/hvm/vcpu.h | 3 - xen/include/asm-x86/hvm/vmx/vmcs.h | 10 +- xen/include/asm-x86/hvm/vmx/vpmu_core2.h | 51 -- xen/include/asm-x86/hvm/vpmu.h | 104 ---- xen/include/asm-x86/vpmu.h | 118 ++++ xen/include/public/arch-arm.h | 3 + xen/include/public/arch-x86/pmu.h | 75 +++ xen/include/public/platform.h | 19 + xen/include/public/pmu.h | 93 +++ xen/include/public/xen.h | 2 + xen/include/xen/hypercall.h | 4 + xen/include/xen/softirq.h | 1 + xen/include/xen/symbols.h | 3 + xen/include/xlat.lst | 5 + 39 files changed, 2906 insertions(+), 1931 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.1.4
PATCH v9 1/20 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 | 33 ++++++++++++++++++++++++ xen/common/symbols.c | 54 +++++++++++++++++++++++++++++++++++++++ xen/include/public/platform.h | 19 ++++++++++++++ xen/include/xen/symbols.h | 3 +++ xen/include/xlat.lst | 1 + 5 files changed, 110 insertions(+)
xen/arch/x86/platform_hypercall.c +33 -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,38 @@ ret_t do_platform_op(XEN_GUEST_HANDLE_PARAM(xen_platform_op_t) u_xenpf_op) }break ; +case XENPF_get_symbol: + { +static char name[KSYM_NAME_LEN +1 ];/* protected by xenpf_lock */ +XEN_GUEST_HANDLE (char ) nameh; +uint32_t namelen, copylen; + +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); + + namelen =strlen (name) +1 ; + +if ( namelen > op->u.symdata.namelen ) + { +/* Caller's buffer is too small for the whole string */ +if ( op->u.symdata.namelen ) + name[op->u.symdata.namelen] ='\0' ; + copylen = op->u.symdata.namelen; + } +else + copylen = namelen; + + op->u.symdata.namelen = namelen; + +if ( !ret &©_to_guest (nameh, name, copylen) ) + ret = -EFAULT ; +if ( !ret &&__copy_field_to_guest (u_xenpf_op, op, u.symdata) ) + ret = -EFAULT ; + } +break ; +default : ret = -ENOSYS ;break ;
xen/common/symbols.c +54 -0
63 lines not on this page · raw message
xen/include/public/platform.h +19 -0
@@ -527,6 +527,24 @@ 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 +struct xenpf_symdata { +/* IN/OUT variables */ +uint32_t namelen;/* IN: size of name buffer */ +/* OUT: strlen(name) of hypervisor symbol (may be */ +/* larger than what's been copied to guest) */ +uint32_t symnum;/* IN: Symbol to read */ +/* OUT: Next available symbol. If same as IN then */ +/* we reached the end */ + +/* OUT variables */ +char 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 +571,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 +3 -0
@@ -11,4 +11,7 @@ const char *symbols_lookup(unsigned long addr,unsigned long *offset, char *namebuf); +int xensyms_read (uint32_t *symnum,char *type, +uint64_t *address,char *name); +#endif /*_XEN_SYMBOLS_H*/
xen/include/xlat.lst +1 -0
@@ -86,6 +86,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.1.4
PATCH v9 2/20 x86/VPMU: Manage VPMU_CONTEXT_SAVE flag in vpmu_save_force()
In reply to Boris Ostrovskyvpmu_load() may leave VPMU_CONTEXT_SAVE set after calling vpmu_save_force() if the context is not loaded.
--- xen/arch/x86/hvm/vpmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/vpmu.c +2 -2
@@ -130,6 +130,8 @@ static void vpmu_save_force(void *arg)if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) )return ; +vpmu_set (vpmu,VPMU_CONTEXT_SAVE ); +if ( vpmu->arch_vpmu_ops ) (void )vpmu->arch_vpmu_ops->arch_vpmu_save (v);
@@ -178,7 +180,6 @@ void vpmu_load(struct vcpu *v)*/ if (vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) ) { -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 );
@@ -195,7 +196,6 @@ void vpmu_load(struct vcpu *v) vpmu =vcpu_vpmu (prev);/* Someone ran here before us */ -vpmu_set (vpmu,VPMU_CONTEXT_SAVE );vpmu_save_force (prev);vpmu_reset (vpmu,VPMU_CONTEXT_LOADED );
Signature · 1 line
1.8.1.4
Re: [PATCH v9 02/20] x86/VPMU: Manage VPMU_CONTEXT_SAVE flag in vpmu_save_force()
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
vpmu_load()may leaveVPMU_CONTEXT_SAVEset after callingvpmu_save_force()if the context is not loaded.
To me this is ambiguous (and looking at the patch I can't really resolve it): Do you mean to say this can validly happen, or that it could have happened in error prior to the patch? In any event please alter the description to either clearly state what the wrong old behavior was, or what the correct new behavior is to be.
Jan
Quoted 36 lines
Signed-off-by Boris Ostrovsky <[email protected]>--- xen/arch/x86/hvm/vpmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/arch/x86/hvm/vpmu.c +2
-2@@ -130,6 +130,8 @@ static void vpmu_save_force(void *arg)if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) )return ; +vpmu_set (vpmu,VPMU_CONTEXT_SAVE ); +if ( vpmu->arch_vpmu_ops ) (void )vpmu->arch_vpmu_ops->arch_vpmu_save (v);@@ -178,7 +180,6 @@ void vpmu_load(struct vcpu *v)*/ if (vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) ) { -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 );@@ -195,7 +196,6 @@ void vpmu_load(struct vcpu *v) vpmu =vcpu_vpmu (prev);/* Someone ran here before us */ -vpmu_set (vpmu,VPMU_CONTEXT_SAVE );vpmu_save_force (prev);vpmu_reset (vpmu,VPMU_CONTEXT_LOADED );Signature · 1 line
1.8.1.4
Re: [PATCH v9 02/20] x86/VPMU: Manage VPMU_CONTEXT_SAVE flag in vpmu_save_force()
Quoted 8 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
vpmu_load()may leaveVPMU_CONTEXT_SAVEset after callingvpmu_save_force()if the context is not loaded.To me this is ambiguous (and looking at the patch I can't really resolve it): Do you mean to say this can validly happen, or that it could have happened in error prior to the patch? In any event please alter the description to either clearly state what the wrong old behavior was, or what the correct new behavior is to be.
What I was trying to say (not particularly successfully, apparently) is that currently (i.e. prior to the patch) we may end up not clearing VPMU_CONTEXT_SAVE flag after calling vpmu_save_forced(). And that would be a bug, which this patch is fixing.
(It doesn't help that the diff doesn't show that the flag is cleared right after ->arch_vpmu_save() below)
-boris
Quoted 41 lines
Jan
Quoted 36 lines
Signed-off-by Boris Ostrovsky <[email protected]>--- xen/arch/x86/hvm/vpmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/arch/x86/hvm/vpmu.c +2
-2@@ -130,6 +130,8 @@ static void vpmu_save_force(void *arg)if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) )return ; +vpmu_set (vpmu,VPMU_CONTEXT_SAVE ); +if ( vpmu->arch_vpmu_ops ) (void )vpmu->arch_vpmu_ops->arch_vpmu_save (v);@@ -178,7 +180,6 @@ void vpmu_load(struct vcpu *v)*/ if (vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) ) { -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 );@@ -195,7 +196,6 @@ void vpmu_load(struct vcpu *v) vpmu =vcpu_vpmu (prev);/* Someone ran here before us */ -vpmu_set (vpmu,VPMU_CONTEXT_SAVE );vpmu_save_force (prev);vpmu_reset (vpmu,VPMU_CONTEXT_LOADED );Signature · 1 line
1.8.1.4
PATCH v9 3/20 x86/VPMU: Set MSR bitmaps only for HVM/PVH guests
In reply to Boris OstrovskyIn preparation for making VPMU code shared with PV make sure that we we update MSR bitmaps only for HVM/PVH guests
--- xen/arch/x86/hvm/svm/vpmu.c | 21 +++++++++++++-------- xen/arch/x86/hvm/vmx/vpmu_core2.c | 8 +++++--- 2 files changed, 18 insertions(+), 11 deletions(-)
xen/arch/x86/hvm/svm/vpmu.c +13 -8
@@ -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 ( !vpmu_is_set (vpmu,VPMU_RUNNING ) && +has_hvm_container_domain (v->domain) && ctx->msr_bitmap_set )amd_vpmu_unset_msr_bitmap (v);return 1 ;
@@ -284,8 +285,9 @@ 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 ) && - !(is_guest_mode (msr_content)) ) +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,8 +302,9 @@ 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 ) -amd_vpmu_set_msr_bitmap (v); +if (has_hvm_container_domain (v->domain) && + !((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set ) +amd_vpmu_set_msr_bitmap (v); }/* stop saving & restore if guest stops first counter */
@@ -311,8 +314,9 @@ 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 ) -amd_vpmu_unset_msr_bitmap (v); +if (has_hvm_container_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 +407,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 (has_hvm_container_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 +5 -3
@@ -335,7 +335,8 @@ static int core2_vpmu_save(struct vcpu *v)__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 ) && +has_hvm_container_domain (v->domain) && cpu_has_vmx_msr_bitmap )core2_vpmu_unset_msr_bitmap (v->arch.hvm_vmx.msr_bitmap);return 1 ;
@@ -448,7 +449,8 @@ 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 (has_hvm_container_domain (current->domain) && + cpu_has_vmx_msr_bitmap )core2_vpmu_set_msr_bitmap (current->arch.hvm_vmx.msr_bitmap); }return 1 ;
@@ -815,7 +817,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 (has_hvm_container_domain (v->domain) && 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 );
Signature · 1 line
1.8.1.4
PATCH v9 4/20 x86/VPMU: Make vpmu macros a bit more efficient
In reply to Boris OstrovskyIntroduce vpmu_are_all_set that allows testing multiple bits at once. Convert macros into inlines for better compiler checking.
--- xen/arch/x86/hvm/vmx/vpmu_core2.c | 5 +---- xen/arch/x86/hvm/vpmu.c | 3 +-- xen/include/asm-x86/hvm/vpmu.h | 25 +++++++++++++++++++++---- 3 files changed, 23 insertions(+), 10 deletions(-)
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_are_all_set (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ) )return 0 ;__core2_vpmu_save (v);
xen/arch/x86/hvm/vpmu.c +1 -2
@@ -145,8 +145,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_are_all_set (vpmu,VPMU_CONTEXT_ALLOCATED |VPMU_CONTEXT_LOADED ) )return ; vpmu->last_pcpu = pcpu;
xen/include/asm-x86/hvm/vpmu.h +21 -4
@@ -81,10 +81,27 @@ 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) +static inline void vpmu_set (struct vpmu_struct *vpmu,const u32 mask) +{ + vpmu->flags |= mask; +} +static inline void vpmu_reset (struct vpmu_struct *vpmu,const u32 mask) +{ + vpmu->flags &= ~mask; +} +static inline void vpmu_clear (struct vpmu_struct *vpmu) +{ + vpmu->flags =0 ; +} +static inline bool_t vpmu_is_set (const struct vpmu_struct *vpmu,const u32 mask) +{ +return !!(vpmu->flags & mask); +} +static inline bool_t vpmu_are_all_set (const struct vpmu_struct *vpmu, +const u32 mask) +{ +return !!((vpmu->flags & mask) == mask); +}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.1.4
PATCH v9 5/20 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 | 51 ++++ xen/arch/x86/hvm/vmx/vpmu_core2.c | 385 ++++++++++++++----------------- xen/include/asm-x86/hvm/vmx/vmcs.h | 2 + xen/include/asm-x86/hvm/vmx/vpmu_core2.h | 19 -- 4 files changed, 228 insertions(+), 229 deletions(-)
xen/arch/x86/hvm/vmx/vmcs.c +51 -0
@@ -1208,6 +1208,32 @@ 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 ; + + --msr_count; +memmove (&msr_area[idx], &msr_area[idx +1 ], +sizeof (struct vmx_msr_entry ) * (msr_count - idx)); + msr_area[msr_count].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;
@@ -1238,6 +1264,31 @@ 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 ; + + --msr_count; +memmove (&msr_area[idx], &msr_area[idx +1 ], +sizeof (struct vmx_msr_entry ) * (msr_count - idx)); + msr_area[msr_count].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 +175 -210
623 lines not on this page · raw message
xen/include/asm-x86/hvm/vmx/vmcs.h +2 -0
@@ -480,7 +480,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.1.4
Re: [PATCH v9 05/20] intel/VPMU: Clean up Intel VPMU code
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmcs.c +5
-0@@ -1208,6 +1208,32 @@ 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;
xen/arch/x86/hvm/vmx/vmcs.c int vmx_add_guest_msr(u32 msr) · line 1225
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmcs.c +10
-0+ +if ( msr_area ==NULL ) +return ; + +for ( idx =0 ; idx < msr_count; idx++ ) +if ( msr_area[idx].index == msr ) +break ; + +if ( idx == msr_count ) +return ;
This absence check (producing success) together with the presence check in the corresponding "add" function (also producing success) is certainly bogus without reference counting: Two independent callers of "add" would each validly assume they ought to call "rm" when done with their job, taking away the control over the MSR from the other. Yet if you don't think of independent callers, these presence/absence checks don't make sense at all.
Jan
Re: [PATCH v9 05/20] intel/VPMU: Clean up Intel VPMU code
Quoted 21 lines · Jan Beulich
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmcs.c +14
-0@@ -1208,6 +1208,32 @@ 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 )
Quoted 8 lines
xen/arch/x86/hvm/vmx/vmcs.c int vmx_add_guest_msr(u32 msr) · line 1225
Quoted 1 line
xen/arch/x86/hvm/vmx/vmcs.c +1
-0+return ;This absence check (producing success) together with the presence check in the corresponding "add" function (also producing success) is certainly bogus without reference counting: Two independent callers of "add" would each validly assume they ought to call "rm" when done with their job, taking away the control over the MSR from the other. Yet if you don't think of independent callers, these presence/absence checks don't make sense at all.
Hmm, yes, that's a problem. Refcounting would require separate data structures which would need to be dynamically grown (we don't know how many MSR we will be tracking and most often the number is very small).
So I wonder whether I should drop support for remove altogether since this is only used in error path and I am not sure whether adding more complexity is worth it.
-boris
Re: [PATCH v9 05/20] intel/VPMU: Clean up Intel VPMU code
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 11.08.14 at 18:01, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmcs.c +14
-0@@ -1208,6 +1208,32 @@ 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 )Quoted 8 lines
xen/arch/x86/hvm/vmx/vmcs.c int vmx_add_guest_msr(u32 msr) · line 1225
Quoted 1 line
xen/arch/x86/hvm/vmx/vmcs.c +1
-0+return ;This absence check (producing success) together with the presence check in the corresponding "add" function (also producing success) is certainly bogus without reference counting: Two independent callers of "add" would each validly assume they ought to call "rm" when done with their job, taking away the control over the MSR from the other. Yet if you don't think of independent callers, these presence/absence checks don't make sense at all.
Quoted 7 lines
Hmm, yes, that's a problem. Refcounting would require separate data structures which would need to be dynamically grown (we don't know how many MSR we will be tracking and most often the number is very small).
So I wonder whether I should drop support for remove altogether since this is only used in error path and I am not sure whether adding more complexity is worth it.
Probably not - see e.g. the debugctl and lbr handling, which also only ever adds MSRs to that list. That's not optimal, but sufficient for now - if we ever learn this presents a (performance) problem, we could then start thinking about adding remove support.
Jan
PATCH v9 6/20 vmx: Merge MSR management routines
In reply to Boris Ostrovskyvmx_add_host_load_msr()/vmx_rm_guest_msr() and vmx_add_guest_msr()/vmx_rm_guest_msr() share fair amount of code. Merge them to simplify code maintenance.
--- xen/arch/x86/hvm/vmx/vmcs.c | 155 +++++++++++++++++-------------------- xen/arch/x86/hvm/vmx/vmx.c | 4 +- xen/arch/x86/hvm/vmx/vpmu_core2.c | 8 +- xen/include/asm-x86/hvm/vmx/vmcs.h | 10 ++- 4 files changed, 85 insertions(+), 92 deletions(-)
xen/arch/x86/hvm/vmx/vmcs.c +73 -82
@@ -1176,117 +1176,108 @@ int vmx_write_guest_msr(u32 msr, u64 val)return -ESRCH ; } -int vmx_add_guest_msr (u32 msr) +int vmx_add_msr (u32 msr,u8 type) {struct vcpu *curr = current; -unsigned int i, msr_count = curr->arch.hvm_vmx.msr_count; -struct vmx_msr_entry *msr_area = curr->arch.hvm_vmx.msr_area; +unsigned int idx, *msr_count; +struct vmx_msr_entry **msr_area, *msr_area_elem; + +if ( type ==VMX_GUEST_MSR ) + { + msr_count = &curr->arch.hvm_vmx.msr_count; + msr_area = &curr->arch.hvm_vmx.msr_area; + } +else + { +ASSERT (type ==VMX_HOST_MSR ); + msr_count = &curr->arch.hvm_vmx.host_msr_count; + msr_area = &curr->arch.hvm_vmx.host_msr_area; + } -if ( msr_area ==NULL ) +if ( *msr_area ==NULL ) { -if ( (msr_area =alloc_xenheap_page ()) ==NULL ) +if ( (*msr_area =alloc_xenheap_page ()) ==NULL )return -ENOMEM ; - curr->arch.hvm_vmx.msr_area = msr_area; -__vmwrite (VM_EXIT_MSR_STORE_ADDR ,virt_to_maddr (msr_area)); -__vmwrite (VM_ENTRY_MSR_LOAD_ADDR ,virt_to_maddr (msr_area)); + +if ( type ==VMX_GUEST_MSR ) + { +__vmwrite (VM_EXIT_MSR_STORE_ADDR ,virt_to_maddr (*msr_area)); +__vmwrite (VM_ENTRY_MSR_LOAD_ADDR ,virt_to_maddr (*msr_area)); + } +else +__vmwrite (VM_EXIT_MSR_LOAD_ADDR ,virt_to_maddr (*msr_area)); } -for ( i =0 ; i < msr_count; i++ ) -if ( msr_area[i].index == msr ) +for ( idx =0 ; idx < *msr_count; idx++ ) +if ( (*msr_area)[idx].index == msr )return 0 ; -if ( msr_count == (PAGE_SIZE /sizeof (struct vmx_msr_entry )) ) +if ( *msr_count == (PAGE_SIZE /sizeof (struct vmx_msr_entry )) )return -ENOSPC ; - msr_area[msr_count].index = msr; - msr_area[msr_count].mbz =0 ; - msr_area[msr_count].data =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); + msr_area_elem = *msr_area + *msr_count; + msr_area_elem->index = msr; + msr_area_elem->mbz =0 ; -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 ; + ++*msr_count; -for ( idx =0 ; idx < msr_count; idx++ ) -if ( msr_area[idx].index == msr ) -break ; - -if ( idx == msr_count ) -return ; - - --msr_count; -memmove (&msr_area[idx], &msr_area[idx +1 ], -sizeof (struct vmx_msr_entry ) * (msr_count - idx)); - msr_area[msr_count].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; -unsigned int i, 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 ) +if ( type ==VMX_GUEST_MSR ) { -if ( (msr_area =alloc_xenheap_page ()) ==NULL ) -return -ENOMEM ; - curr->arch.hvm_vmx.host_msr_area = msr_area; -__vmwrite (VM_EXIT_MSR_LOAD_ADDR ,virt_to_maddr (msr_area)); + msr_area_elem->data =0 ; +__vmwrite (VM_EXIT_MSR_STORE_COUNT , *msr_count); +__vmwrite (VM_ENTRY_MSR_LOAD_COUNT , *msr_count); + } +else + { +rdmsrl (msr, msr_area_elem->data); +__vmwrite (VM_EXIT_MSR_LOAD_COUNT , *msr_count); } - -for ( i =0 ; i < msr_count; i++ ) -if ( msr_area[i].index == msr ) -return 0 ; - -if ( msr_count == (PAGE_SIZE /sizeof (struct vmx_msr_entry )) ) -return -ENOSPC ; - - msr_area[msr_count].index = msr; - msr_area[msr_count].mbz =0 ; -rdmsrl (msr, msr_area[msr_count].data); - curr->arch.hvm_vmx.host_msr_count = ++msr_count; -__vmwrite (VM_EXIT_MSR_LOAD_COUNT , msr_count);return 0 ; } -void vmx_rm_host_load_msr (u32 msr) +void vmx_rm_msr (u32 msr,u8 type) {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; +unsigned int idx, *msr_count; +struct vmx_msr_entry **msr_area; -if ( msr_area ==NULL ) +if ( type ==VMX_GUEST_MSR ) + { + msr_count = &curr->arch.hvm_vmx.msr_count; + msr_area = &curr->arch.hvm_vmx.msr_area; + } +else + { +ASSERT (type ==VMX_HOST_MSR ); + msr_count = &curr->arch.hvm_vmx.host_msr_count; + 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 ) +for ( idx =0 ; idx < *msr_count; idx++ ) +if ( (*msr_area)[idx].index == msr )break ; -if ( idx == msr_count ) +if ( idx == *msr_count )return ; - --msr_count; -memmove (&msr_area[idx], &msr_area[idx +1 ], -sizeof (struct vmx_msr_entry ) * (msr_count - idx)); - msr_area[msr_count].index =0 ; + --*msr_count; +memmove (&(*msr_area)[idx], &(*msr_area)[idx +1 ], +sizeof (struct vmx_msr_entry ) * (*msr_count - idx)); + msr_area[*msr_count]->index =0 ; - curr->arch.hvm_vmx.host_msr_count = msr_count; -__vmwrite (VM_EXIT_MSR_LOAD_COUNT , msr_count); +if ( type ==VMX_GUEST_MSR ) + { +__vmwrite (VM_EXIT_MSR_STORE_COUNT , *msr_count); +__vmwrite (VM_ENTRY_MSR_LOAD_COUNT , *msr_count); + } +else + { +__vmwrite (VM_EXIT_MSR_LOAD_COUNT , *msr_count); + } }void vmx_set_eoi_exit_bitmap (struct vcpu *v,u8 vector)
xen/arch/x86/hvm/vmx/vmx.c +2 -2
@@ -2262,12 +2262,12 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)for ( ; (rc ==0 ) && lbr->count; lbr++ )for ( i =0 ; (rc ==0 ) && (i < lbr->count); i++ ) -if ( (rc =vmx_add_guest_msr (lbr->base + i)) ==0 ) +if ( (rc =vmx_add_msr (lbr->base + i,VMX_GUEST_MSR )) ==0 )vmx_disable_intercept_for_msr (v, lbr->base + i,MSR_TYPE_R |MSR_TYPE_W ); }if ( (rc <0 ) || - (vmx_add_host_load_msr (msr) <0 ) ) + (vmx_add_msr (msr,VMX_HOST_MSR ) <0 ) )hvm_inject_hw_exception (TRAP_machine_check,0 );else {
xen/arch/x86/hvm/vmx/vpmu_core2.c +4 -4
@@ -368,10 +368,10 @@ static int core2_vpmu_alloc_resource(struct vcpu *v)return 0 ;wrmsrl (MSR_CORE_PERF_GLOBAL_CTRL ,0 ); -if (vmx_add_host_load_msr (MSR_CORE_PERF_GLOBAL_CTRL ) ) +if (vmx_add_msr (MSR_CORE_PERF_GLOBAL_CTRL ,VMX_HOST_MSR ) ) goto out_err; -if (vmx_add_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL ) ) +if (vmx_add_msr (MSR_CORE_PERF_GLOBAL_CTRL ,VMX_GUEST_MSR ) ) goto out_err;vmx_write_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL ,core2_calc_intial_glb_ctrl_msr ());
@@ -388,8 +388,8 @@ static int core2_vpmu_alloc_resource(struct vcpu *v)return 1 ; out_err: -vmx_rm_host_load_msr (MSR_CORE_PERF_GLOBAL_CTRL ); -vmx_rm_guest_msr (MSR_CORE_PERF_GLOBAL_CTRL ); +vmx_rm_msr (MSR_CORE_PERF_GLOBAL_CTRL ,VMX_HOST_MSR ); +vmx_rm_msr (MSR_CORE_PERF_GLOBAL_CTRL ,VMX_GUEST_MSR );release_pmu_ownship (PMU_OWNER_HVM ); printk("Failed to allocate VPMU resources for domain %u vcpu %u\n",
xen/include/asm-x86/hvm/vmx/vmcs.h +6 -4
@@ -475,14 +475,16 @@ enum vmcs_field {#define MSR_TYPE_R 1#define MSR_TYPE_W 2 + +#define VMX_GUEST_MSR 0 +#define VMX_HOST_MSR 1 +void vmx_disable_intercept_for_msr (struct vcpu *v,u32 msr,int type);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); +int vmx_add_msr (u32 msr,u8 type); +void vmx_rm_msr (u32 msr,u8 type);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);
Signature · 1 line
1.8.1.4
PATCH v9 7/20 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 | 8 ++++++++ xen/include/asm-x86/hvm/vpmu.h | 1 + 5 files changed, 13 insertions(+), 22 deletions(-)
xen/arch/x86/hvm/svm/vpmu.c +0 -4
@@ -299,8 +299,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 (has_hvm_container_domain (v->domain) && !((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set )
@@ -311,8 +309,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 (has_hvm_container_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>
@@ -734,8 +735,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
@@ -527,19 +527,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;
@@ -705,10 +692,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 +8 -0
@@ -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);
xen/include/asm-x86/hvm/vpmu.h +1 -0
@@ -103,6 +103,7 @@ static inline bool_t vpmu_are_all_set(const struct vpmu_struct *vpmu,return !!((vpmu->flags & mask) == mask); } +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.1.4
Re: [PATCH v9 07/20] x86/VPMU: Handle APIC_LVTPC accesses
xen/arch/x86/hvm/vlapic.c static int vlapic_reg_write(struct vcpu *v, · line 741
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/hvm/vlapic.c +3
-1@@ -734,8 +735,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);
Each time I review a version of this series I find myself verifying that the introduction of the "else" that wasn't previously there is benign. It is, yes, but the patch also doesn't win anything from that change. Hence please either drop _both_ "else"-s, or convert the whole construct to a small switch().
Jan
PATCH v9 8/20 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 | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
xen/arch/x86/hvm/vmx/vpmu_core2.c +1 -10
@@ -165,14 +165,6 @@ static int core2_get_fixed_pmc_count(void)return MASK_EXTR (eax,PMU_FIXED_NR_MASK ); } -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 +365,7 @@ static int core2_vpmu_alloc_resource(struct vcpu *v)if (vmx_add_msr (MSR_CORE_PERF_GLOBAL_CTRL ,VMX_GUEST_MSR ) ) 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.1.4
PATCH v9 9/20 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 | 84 ++++++++++++---------- xen/arch/x86/hvm/vmx/vpmu_core2.c | 117 +++++++++++++++++-------------- xen/arch/x86/hvm/vpmu.c | 4 ++ 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 | 16 ++--- xen/include/public/arch-arm.h | 3 + xen/include/public/arch-x86/pmu.h | 68 ++++++++++++++++++ xen/include/public/pmu.h | 38 ++++++++++ 9 files changed, 236 insertions(+), 132 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 +47 -37
@@ -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,12 +84,14 @@ 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; -}; +/* Use private context as a flag for MSR bitmap */ +#define msr_bitmap_on (vpmu) do { \ + (vpmu)->priv_context = (void *)-1L; \ + } while (0) +#define msr_bitmap_off (vpmu) do { \ + (vpmu)->priv_context = NULL; \ + } while (0) +#define is_msr_bitmap_on (vpmu) ((vpmu)->priv_context != NULL)static inline int get_pmu_reg_type (u32 addr) {
@@ -142,7 +145,6 @@ 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;for ( i =0 ; i < num_counters; i++ ) {
@@ -150,14 +152,13 @@ static void amd_vpmu_set_msr_bitmap(struct vcpu *v)svm_intercept_msr (v, ctrls[i],MSR_INTERCEPT_WRITE ); } - ctxt->msr_bitmap_set =1 ; +msr_bitmap_on (vpmu); }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;for ( i =0 ; i < num_counters; i++ ) {
@@ -165,7 +166,7 @@ static void amd_vpmu_unset_msr_bitmap(struct vcpu *v)svm_intercept_msr (v, ctrls[i],MSR_INTERCEPT_RW ); } - ctxt->msr_bitmap_set =0 ; +msr_bitmap_off (vpmu); }static int amd_vpmu_do_interrupt (struct cpu_user_regs *regs)
@@ -177,19 +178,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 +202,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 +216,17 @@ 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;unsigned int i;/*
@@ -245,7 +249,7 @@ static int amd_vpmu_save(struct vcpu *v)context_save (v);if ( !vpmu_is_set (vpmu,VPMU_RUNNING ) && -has_hvm_container_domain (v->domain) && ctx->msr_bitmap_set ) +has_hvm_container_domain (v->domain) &&is_msr_bitmap_on (vpmu) )amd_vpmu_unset_msr_bitmap (v);return 1 ;
@@ -256,7 +260,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 +274,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,8 +306,7 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)return 1 ;vpmu_set (vpmu,VPMU_RUNNING ); -if (has_hvm_container_domain (v->domain) && - !((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set ) +if (has_hvm_container_domain (v->domain) &&is_msr_bitmap_on (vpmu) )amd_vpmu_set_msr_bitmap (v); }
@@ -310,8 +315,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 (has_hvm_container_domain (v->domain) && - ((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set ) +if (has_hvm_container_domain (v->domain) &&is_msr_bitmap_on (vpmu) )amd_vpmu_unset_msr_bitmap (v);release_pmu_ownship (PMU_OWNER_HVM ); }
@@ -352,7 +356,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;
@@ -382,7 +386,8 @@ static int amd_vpmu_initialise(struct vcpu *v) } } - ctxt = xzalloc(struct amd_vpmu_context); + ctxt =xzalloc_bytes (sizeof (struct xen_pmu_amd_ctxt ) + +2 *sizeof (uint64_t ) *AMD_MAX_COUNTERS );if ( !ctxt ) { gdprintk(XENLOG_WARNING, "Insufficient memory for PMU, "
@@ -391,7 +396,11 @@ 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->priv_context =NULL ;vpmu_set (vpmu,VPMU_CONTEXT_ALLOCATED );return 0 ; }
@@ -403,8 +412,7 @@ static void amd_vpmu_destroy(struct vcpu *v)if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )return ; -if (has_hvm_container_domain (v->domain) && - ((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set ) +if (has_hvm_container_domain (v->domain) &&is_msr_bitmap_on (vpmu) )amd_vpmu_unset_msr_bitmap (v);xfree (vpmu->context);
@@ -421,7 +429,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; +const uint64_t *counter_regs =vpmu_reg_pointer (ctxt, counters); +const uint64_t *ctrl_regs =vpmu_reg_pointer (ctxt, ctrls);unsigned int i;printk (" VPMU state: 0x%x " , vpmu->flags);
@@ -451,8 +461,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 +64 -53
286 lines not on this page · raw message
xen/arch/x86/hvm/vpmu.c +4 -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
@@ -228,6 +229,9 @@ void vpmu_initialise(struct vcpu *v)struct vpmu_struct *vpmu =vcpu_vpmu (v);uint8_t vendor = current_cpu_data.x86_vendor; +BUILD_BUG_ON (sizeof (struct xen_pmu_intel_ctxt ) >XENPMU_CTXT_PAD_SZ ); +BUILD_BUG_ON (sizeof (struct xen_pmu_amd_ctxt ) >XENPMU_CTXT_PAD_SZ ); +if (vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )vpmu_destroy (v);vpmu_clear (vpmu);
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 +7 -9
@@ -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 {
@@ -64,7 +66,8 @@ struct vpmu_struct {u32 flags;u32 last_pcpu;u32 hw_lapic_lvtpc; -void *context; +void *context;/* May be shared with PV guest */ +void *priv_context;/* hypervisor-only */ struct arch_vpmu_ops *arch_vpmu_ops; };
@@ -76,11 +79,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 */ - -static inline void vpmu_set (struct vpmu_struct *vpmu,const u32 mask) { vpmu->flags |= mask;
xen/include/public/arch-arm.h +3 -0
@@ -407,6 +407,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 +68 -0
68 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 1 + + +/* 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.1.4
Re: [PATCH v9 09/20] x86/VPMU: Add public xenpmu.h
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
static int
amd_vpmu_initialise(struct vcpu *v)
{xen/arch/x86/hvm/svm/vpmu.c +1
-1-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;
xen/arch/x86/hvm/svm/vpmu.c static int amd_vpmu_initialise(struct vcpu *v) · line 390
Quoted 6 lines
xen/arch/x86/hvm/svm/vpmu.c +2
-1@@ -382,7 +386,8 @@ static int amd_vpmu_initialise(struct vcpu *v) } } - ctxt = xzalloc(struct amd_vpmu_context); + ctxt =xzalloc_bytes (sizeof (struct xen_pmu_amd_ctxt ) + +2 *sizeof (uint64_t ) *AMD_MAX_COUNTERS );
So I guess this is one of said sizeof()-s, and I continue to think this would benefit from using a proper field. It is my understanding that the real (non-C89 compliant) declaration of struct xen_pmu_amd_ctxt would be
struct xen_pmu_amd_ctxt {
/* Offsets to counter and control MSRs (relative to xen_arch_pmu.c.amd) */
uint32_t counters;
uint32_t ctrls;
uint64_t values[];
};Just like already done elsewhere you _can_ add variable-sized arrays to the public interface as long as you guard them suitably. And then your statement would become
ctxt = xzalloc_bytes(sizeof(*ctxt) +
2 * sizeof(*ctxt->values) * AMD_MAX_COUNTERS);
making clear what the allocation is doing.
xen/arch/x86/hvm/svm/vpmu.c static int amd_vpmu_initialise(struct vcpu *v) · line 400
Quoted 6 lines
xen/arch/x86/hvm/svm/vpmu.c +2
-0@@ -391,7 +396,11 @@ 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 ;
ctxt->counters = sizeof(*ctxt);
ctxt->ctrls = ctxt->counters + sizeof(*ctxt->values) * AMD_MAX_COUNTERS;or
ctxt->counters = offsetof(typeof(ctxt), values[0]);
ctxt->ctrls = offsetof(typeof(ctxt), values[AMD_MAX_COUNTERS]);xen/arch/x86/hvm/vpmu.c void vpmu_initialise(struct vcpu *v) · line 233
Quoted 6 lines
xen/arch/x86/hvm/vpmu.c +2
-0@@ -228,6 +229,9 @@ void vpmu_initialise(struct vcpu *v)struct vpmu_struct *vpmu =vcpu_vpmu (v);uint8_t vendor = current_cpu_data.x86_vendor; +BUILD_BUG_ON (sizeof (struct xen_pmu_intel_ctxt ) >XENPMU_CTXT_PAD_SZ ); +BUILD_BUG_ON (sizeof (struct xen_pmu_amd_ctxt ) >XENPMU_CTXT_PAD_SZ );
Don't these need to include the variable size array portions too?
Jan
Re: [PATCH v9 09/20] x86/VPMU: Add public xenpmu.h
Quoted 20 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
static int
amd_vpmu_initialise(struct vcpu *v)
{xen/arch/x86/hvm/svm/vpmu.c +1
-1-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;xen/arch/x86/hvm/svm/vpmu.c static int amd_vpmu_initialise(struct vcpu *v) · line 390
Quoted 6 lines
xen/arch/x86/hvm/svm/vpmu.c +2
-1@@ -382,7 +386,8 @@ static int amd_vpmu_initialise(struct vcpu *v) } } - ctxt = xzalloc(struct amd_vpmu_context); + ctxt =xzalloc_bytes (sizeof (struct xen_pmu_amd_ctxt ) + +2 *sizeof (uint64_t ) *AMD_MAX_COUNTERS );So I guess this is one of said sizeof()-s, and I continue to think this would benefit from using a proper field. It is my understanding that the real (non-C89 compliant) declaration of struct
xen_pmu_amd_ctxtwould be
Quoted 6 lines
struct xen_pmu_amd_ctxt {
/* Offsets to counter and control MSRs (relative to xen_arch_pmu.c.amd) */
uint32_t counters;
uint32_t ctrls;
uint64_t values[];
};OK, this should work.
Quoted 24 lines
Just like already done elsewhere you _can_ add variable-sized arrays to the public interface as long as you guard them suitably. And then your statement would become
ctxt = xzalloc_bytes(sizeof(*ctxt) +
2 *sizeof(*ctxt->values)*AMD_MAX_COUNTERS);making clear what the allocation is doing.
xen/arch/x86/hvm/svm/vpmu.c static int amd_vpmu_initialise(struct vcpu *v) · line 400
Quoted 6 lines
xen/arch/x86/hvm/svm/vpmu.c +2
-0@@ -391,7 +396,11 @@ 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 ;ctxt->counters = sizeof(*ctxt); ctxt->ctrls = ctxt->counters + sizeof(*ctxt->values) * AMD_MAX_COUNTERS;or
ctxt->counters = offsetof(typeof(ctxt), values[0]); ctxt->ctrls = offsetof(typeof(ctxt), values[AMD_MAX_COUNTERS]);
Quoted 7 lines
xen/arch/x86/hvm/vpmu.c void vpmu_initialise(struct vcpu *v) · line 233
Quoted 6 lines
xen/arch/x86/hvm/vpmu.c +2
-0@@ -228,6 +229,9 @@ void vpmu_initialise(struct vcpu *v)struct vpmu_struct *vpmu =vcpu_vpmu (v);uint8_t vendor = current_cpu_data.x86_vendor; +BUILD_BUG_ON (sizeof (struct xen_pmu_intel_ctxt ) >XENPMU_CTXT_PAD_SZ ); +BUILD_BUG_ON (sizeof (struct xen_pmu_amd_ctxt ) >XENPMU_CTXT_PAD_SZ );Don't these need to include the variable size array portions too?
Not in BUILD_BUG_ON but I should check whether I have enough space when computing ctxt->{ctrls | counters}.
-boris
Re: [PATCH v9 09/20] x86/VPMU: Add public xenpmu.h
Quoted 27 lines · Boris Ostrovsky
Quoted 18 lines · Jan Beulich
Review
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
static int
amd_vpmu_initialise(struct vcpu *v)
{(quoted diff) +3
-1- 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; @@ -382,7 +386,8 @@ static int amd_vpmu_initialise(struct vcpu *v) } } - ctxt = xzalloc(struct amd_vpmu_context); + ctxt = xzalloc_bytes(sizeof(struct xen_pmu_amd_ctxt) + + 2 * sizeof(uint64_t) * AMD_MAX_COUNTERS);So I guess this is one of said sizeof()-s, and I continue to think this would benefit from using a proper field. It is my understanding that the real (non-C89 compliant) declaration of struct
xen_pmu_amd_ctxtwould beQuoted 7 lines
struct xen_pmu_amd_ctxt { /* Offsets to counter and control MSRs (relative to xen_arch_pmu.c.amd) */ uint32_t counters; uint32_t ctrls; uint64_t values[]; };
Quoted 1 line
OK, this should work.
Actually, no, it won't: we decided early on that register banks should be outside the fixed portion of the structure. Keeping values[] inside xen_pmu_amd_ctxt doesn't necessarily preclude this *if* it is never referred to by code and is only used for determining the type. But that would be an unreasonable requirement IMO.
I understand the dislike to sizeof(uint64_t). OTOH, your original concern was that we may forget to update size calculation if value changes type sometime later. But the type cannot be anything but uint64_t since it is used in rd/wrmsr().
I also considered introducing pmu_reg_t (typedef'd to uint64_t) but we'd be back again to rd/wrmsr() -- even though compiler may not flag it this still would be rather unnatural.
-boris
Quoted 39 lines
Quoted 26 lines
Just like already done elsewhere you _can_ add variable-sized arrays to the public interface as long as you guard them suitably. And then your statement would become
ctxt = xzalloc_bytes(sizeof(*ctxt) +
2 *sizeof(*ctxt->values)*AMD_MAX_COUNTERS);making clear what the allocation is doing.
Review static int amd_vpmu_initialise(struct vcpu *v) · line 400
Quoted 6 lines
(quoted diff) +1
-0@@ -391,7 +396,11 @@ 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;ctxt->counters = sizeof(*ctxt); ctxt->ctrls = ctxt->counters + sizeof(*ctxt->values) *
AMD_MAX_COUNTERS;or
ctxt->counters = offsetof(typeof(ctxt), values[0]); ctxt->ctrls = offsetof(typeof(ctxt), values[AMD_MAX_COUNTERS]);Quoted 8 lines
Review void vpmu_initialise(struct vcpu *v) · line 234
Quoted 7 lines
(quoted diff) +1
-0@@ -228,6 +229,9 @@ void vpmu_initialise(struct vcpu *v) struct vpmu_struct *vpmu = vcpu_vpmu(v); uint8_t vendor = current_cpu_data.x86_vendor; + BUILD_BUG_ON(sizeof(struct xen_pmu_intel_ctxt) > XENPMU_CTXT_PAD_SZ); + BUILD_BUG_ON(sizeof(struct xen_pmu_amd_ctxt) > XENPMU_CTXT_PAD_SZ);Don't these need to include the variable size array portions too?
Not in
BUILD_BUG_ONbut I should check whether I have enough space when computing ctxt->{ctrls | counters}.-boris
Re: [PATCH v9 09/20] x86/VPMU: Add public xenpmu.h
Quoted 26 lines
Quoted 1 line
Quoted 1 line
Boris Ostrovsky <[email protected]> 08/18/14 6:02 PM >>>
Quoted 16 lines · Boris Ostrovsky
Quoted 7 lines · Jan Beulich
xen/arch/x86/hvm/svm/vpmu.c static int amd_vpmu_initialise(struct vcpu *v) · line 390
Quoted 2 lines
xen/arch/x86/hvm/svm/vpmu.c +2
-0+ ctxt =xzalloc_bytes (sizeof (struct xen_pmu_amd_ctxt ) + +2 *sizeof (uint64_t ) *AMD_MAX_COUNTERS );So I guess this is one of said sizeof()-s, and I continue to think this would benefit from using a proper field. It is my understanding that the real (non-C89 compliant) declaration of struct
xen_pmu_amd_ctxtwould beQuoted 7 lines
struct xen_pmu_amd_ctxt { /* Offsets to counter and control MSRs (relative to xen_arch_pmu.c.amd) */ uint32_t counters; uint32_t ctrls; uint64_t values[]; };Quoted 1 line
OK, this should work.
Actually, no, it won't: we decided early on that register banks should be outside the fixed portion of the structure. Keeping values[] inside
xen_pmu_amd_ctxtdoesn't necessarily preclude this *if* it is never referred to by code and is only used for determining the type. But that would be an unreasonable requirement IMO.
Quoted 4 lines
I understand the dislike to
sizeof(uint64_t). OTOH, your original concern was that we may forget to update size calculation if value changes type sometime later. But the type cannot be anything butuint64_tsince it is used in rd/wrmsr().
I see; stay with the explicit sizeof(uint64_t) here then, but please try to use sizeof(variable-or-field) elsewhere when possible.
Jan
PATCH v9 10/20 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
@@ -403,6 +403,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
@@ -150,9 +150,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.1.4
PATCH v9 11/20 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 | 188 +++++++++++++++++++++++++++++++++++-- xen/arch/x86/x86_64/compat/entry.S | 4 + xen/arch/x86/x86_64/entry.S | 4 + xen/include/Makefile | 1 + xen/include/asm-x86/hvm/vpmu.h | 14 +-- xen/include/public/arch-x86/pmu.h | 11 ++- xen/include/public/pmu.h | 44 ++++++++- xen/include/public/xen.h | 1 + xen/include/xen/hypercall.h | 4 + xen/include/xlat.lst | 4 + 13 files changed, 264 insertions(+), 29 deletions(-)
xen/arch/x86/domain.c +2 -2
@@ -1482,7 +1482,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_SELF ) )vpmu_save (prev);if ( !list_empty (&prev->arch.hvm_vcpu.tm_list) )
@@ -1526,7 +1526,7 @@ void context_switch(struct vcpu *prev, struct vcpu *next) !is_hardware_domain(next->domain)); } -if (is_hvm_vcpu (next) && (prev != next) ) +if (is_hvm_vcpu (next) && (prev != next) && (vpmu_mode &XENPMU_MODE_SELF ) )/* Must be done with interrupts enabled */ vpmu_load (next);
xen/arch/x86/hvm/svm/vpmu.c +2 -2
@@ -476,14 +476,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
@@ -702,13 +702,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 )
@@ -871,7 +871,7 @@ int vmx_vpmu_initialise(struct vcpu *v, unsigned int vpmu_flags)/* future: */ case 0x3d :case 0x4e : - 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 +180 -8
247 lines not on this page · raw message
xen/arch/x86/x86_64/compat/entry.S +4 -0
@@ -417,6 +417,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
@@ -465,6 +467,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
@@ -762,6 +762,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
@@ -810,6 +812,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/Makefile +1 -0
@@ -26,6 +26,7 @@ headers-y := \ headers-$(CONFIG_X86) += compat/arch-x86/xen-mca.h headers-$(CONFIG_X86) += compat/arch-x86/xen.h headers-$(CONFIG_X86) += compat/arch-x86/xen-$(compat-arch-y).h +headers-$(CONFIG_X86) += compat/pmu.h compat/arch-x86/pmu.h headers-y += compat/arch-$(compat-arch-y).h compat/xlat.h headers-$(FLASK_ENABLE) += compat/xsm/flask_op.h
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;
@@ -115,5 +108,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/arch-x86/pmu.h +9 -2
@@ -9,12 +9,16 @@ struct xen_pmu_amd_ctxt {uint32_t counters;uint32_t ctrls; }; +typedef struct xen_pmu_amd_ctxt xen_pmu_amd_ctxt_t ; +DEFINE_XEN_GUEST_HANDLE (xen_pmu_amd_ctxt_t);/* Intel PMU registers and structures */ struct xen_pmu_cntr_pair {uint64_t counter;uint64_t control; }; +typedef struct xen_pmu_cntr_pair xen_pmu_cntr_pair_t ; +DEFINE_XEN_GUEST_HANDLE (xen_pmu_cntr_pair_t);struct xen_pmu_intel_ctxt {uint64_t global_ctrl;
@@ -31,8 +35,10 @@ struct xen_pmu_intel_ctxt {uint32_t fixed_counters;uint32_t arch_counters; }; +typedef struct xen_pmu_intel_ctxt xen_pmu_intel_ctxt_t ; +DEFINE_XEN_GUEST_HANDLE (xen_pmu_intel_ctxt_t); -struct xen_arch_pmu { +struct xen_pmu_arch {union {struct cpu_user_regs regs;uint8_t pad[256 ];
@@ -53,7 +59,8 @@ struct xen_arch_pmu { uint8_t pad[XENPMU_CTXT_PAD_SZ]; } c; }; -typedef struct xen_arch_pmu xen_arch_pmu_t ; +typedef struct xen_pmu_arch xen_pmu_arch_t ; +DEFINE_XEN_GUEST_HANDLE (xen_pmu_arch_t);#endif /* __XEN_PUBLIC_ARCH_X86_PMU_H__ */ /*
xen/include/public/pmu.h +43 -1
56 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
xen/include/xlat.lst +4 -0
@@ -101,6 +101,10 @@ ! vcpu_set_singleshot_timer vcpu.h ? xenoprof_init xenoprof.h ? xenoprof_passive xenoprof.h +? pmu_params pmu.h +? pmu_intel_ctxt arch-x86/pmu.h +? pmu_amd_ctxt arch-x86/pmu.h +? pmu_cntr_pair arch-x86/pmu.h ? flask_access xsm/flask_op.h ! flask_boolean xsm/flask_op.h ? flask_cache_stats xsm/flask_op.h
Signature · 1 line
1.8.1.4
Re: [PATCH v9 11/20] x86/VPMU: Interface for setting PMU mode and flags
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/domain.c +1
-1@@ -1482,7 +1482,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_SELF ) )vpmu_save (prev);if ( !list_empty (&prev->arch.hvm_vcpu.tm_list) )
xen/arch/x86/domain.c void context_switch(struct vcpu *prev, struct vcpu *next) · line 1531
Quoted 7 lines
xen/arch/x86/domain.c +1
-1@@ -1526,7 +1526,7 @@ void context_switch(struct vcpu *prev, struct vcpu *next) !is_hardware_domain(next->domain)); } -if (is_hvm_vcpu (next) && (prev != next) ) +if (is_hvm_vcpu (next) && (prev != next) && (vpmu_mode &XENPMU_MODE_SELF ) )/* Must be done with interrupts enabled */ vpmu_load (next);
Wouldn't such vPMU internals be better hidden in the functions themselves? I realize you can save the calls this way, but if the condition changes again later, we'll again have to adjust this core function rather than just the vPMU code. It's bad enough that the vpmu_mode variable is visible to non-vPMU code.
Quoted 12 lines
xen/arch/x86/hvm/vpmu.c +2
-0@@ -21,6 +21,8 @@#include <xen/config.h> #include <xen/sched.h> #include <xen/xenoprof.h> +#include <xen/event.h> +#include <xen/guest_access.h> #include <asm/regs.h> #include <asm/types.h> #include <asm/msr.h>
xen/arch/x86/hvm/vpmu.c line 43
Quoted 10 lines
xen/arch/x86/hvm/vpmu.c +7
-0@@ -32,13 +34,21 @@#include <asm/hvm/svm/vmcb.h> #include <asm/apic.h> #include <public/pmu.h> +#include <xen/tasklet.h> + +#include <compat/pmu.h> +CHECK_pmu_params; +CHECK_pmu_intel_ctxt; +CHECK_pmu_amd_ctxt; +CHECK_pmu_cntr_pair;
Such being placed in a HVM-specific file suggests that the series is badly
ordered: Anything relevant to PV should normally only be added here _after_ the file got moved out of the hvm/ subtree. Yet since I realize this would be a major re-work, I think you can leave this as is unless you expect potentially just part of the series to go in, with the splitting point being (immediately or later) after this patch (from my looking at it I would suppose that patches 3 and 4 could go in right away - they don't appear to depend on patches 1 and 2 - and patch 1 probably could go in too, but it doesn't make much sense to have it in without the rest of the series).
Quoted 13 lines
xen/arch/x86/hvm/vpmu.c +9
-0@@ -274,3 +290,159 @@ void vpmu_dump(struct vcpu *v) vpmu->arch_vpmu_ops->arch_vpmu_dump (v); } +static atomic_t vpmu_sched_counter; + +static void vpmu_sched_checkin (unsigned long unused) +{ +atomic_inc (&vpmu_sched_counter); +} + +static int +vpmu_force_context_switch (XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg)
xen/arch/x86/hvm/vpmu.c void vpmu_dump(struct vcpu *v) · line 311
Quoted 10 lines
xen/arch/x86/hvm/vpmu.c +10
-0+{ +unsigned i, j, allbutself_num; +cpumask_t allbutself; +static s_time_t start; +static struct tasklet *sync_task; +int ret =0 ; + + allbutself_num =num_online_cpus () -1 ; + +if ( sync_task )/* if true, we are in hypercall continuation */
"true"? This is not a boolean, so perhaps "set" would be the better term?
Quoted 9 lines
xen/arch/x86/hvm/vpmu.c +9
-0+ goto cont_wait; + +cpumask_andnot (&allbutself, &cpu_online_map, +cpumask_of (smp_processor_id ())); + + sync_task = xmalloc_array(struct tasklet, allbutself_num); +if ( !sync_task ) + { +printk ("vpmu_force_context_switch: out of memory\n" );
xen/arch/x86/hvm/vpmu.c void vpmu_dump(struct vcpu *v) · line 330
Quoted 10 lines
xen/arch/x86/hvm/vpmu.c +10
-0+return -ENOMEM ; + } + +for ( i =0 ; i < allbutself_num; i++ ) +tasklet_init (&sync_task[i], vpmu_sched_checkin,0 ); + +atomic_set (&vpmu_sched_counter,0 ); + + j =0 ; +for_each_cpu ( i, &allbutself )
This looks to be the only use for the (on stack) allbutself variable, but you could easily avoid this by using for_each_online_cpu() and skipping the local one. I'd also recommend that you count allbutself_num here rather than up front, since that will much more obviously prove that you wait for exactly as many CPUs as you scheduled. The array allocation above is bogus anyway, as on a huge system this can easily be more than a page in size.
Quoted 72 lines
xen/arch/x86/hvm/vpmu.c +72
-0+tasklet_schedule_on_cpu (&sync_task[j++], i); + +vpmu_save (current); + + start =NOW (); + + cont_wait: +/* +* Note that we may fail here if a CPU is hot-unplugged while we are +* waiting. We will then time out. +*/ +while (atomic_read (&vpmu_sched_counter) != allbutself_num ) + { +/* Give up after 5 seconds */ +if (NOW () > start +SECONDS (5 ) ) + { +printk ("vpmu_force_context_switch: failed to sync\n" ); + ret = -EBUSY ; +break ; + } +cpu_relax (); +if (hypercall_preempt_check () ) +return hypercall_create_continuation ( + __HYPERVISOR_xenpmu_op,"ih" , XENPMU_mode_set, arg); + } + +for ( i =0 ; i < allbutself_num; i++ ) +tasklet_kill (&sync_task[i]); +xfree (sync_task); + sync_task =NULL ; + +return ret; +} + +long do_xenpmu_op (int op,XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg) +{ +int ret = -EINVAL ; +xen_pmu_params_t pmu_params; + +switch ( op ) + { +case XENPMU_mode_set: + { +static DEFINE_SPINLOCK (xenpmu_mode_lock); +uint32_t current_mode; + +if ( !is_control_domain (current->domain) ) +return -EPERM ; + +if (copy_from_guest (&pmu_params, arg,1 ) ) +return -EFAULT ; + +if ( pmu_params.val & ~XENPMU_MODE_SELF ) +return -EINVAL ; + +/* +* Return error is someone else is in the middle of changing mode --- +* this is most likely indication of two system administrators +* working against each other +*/ +if ( !spin_trylock (&xenpmu_mode_lock) ) +return -EAGAIN ; + + current_mode = vpmu_mode; + vpmu_mode = pmu_params.val; + +if ( vpmu_mode ==XENPMU_MODE_OFF ) + { +/* +* Make sure all (non-dom0) VCPUs have unloaded their VPMUs. This +* can be achieved by having all physical processors go through +* context_switch().
xen/arch/x86/hvm/vpmu.c void vpmu_dump(struct vcpu *v) · line 412
Quoted 10 lines
xen/arch/x86/hvm/vpmu.c +10
-0+*/ + ret =vpmu_force_context_switch (arg); +if ( ret ) + vpmu_mode = current_mode; + } +else + ret =0 ; + +spin_unlock (&xenpmu_mode_lock); +break ;
This still isn't safe: There's nothing preventing another vCPU to issue another XENPMU_mode_set operation while the one turning the vPMU off is still in the process of waiting, but having exited the lock protected region in order to allow other processing to occur. I think you simply need another mode "being-turned-off" during which only mode changes to XENPMU_MODE_OFF, and only by the originally requesting vCPU, are permitted (or else your "if true, we are in hypercall continuation" comment above wouldn't always be true either, as that second vCPU might also issue a second turn-off request).
xen/arch/x86/hvm/vpmu.c void vpmu_dump(struct vcpu *v) · line 419
Quoted 5 lines
xen/arch/x86/hvm/vpmu.c +5
-0+case XENPMU_mode_get: + pmu_params.val = vpmu_mode; + pmu_params.version.maj =XENPMU_VER_MAJ ; + pmu_params.version.min =XENPMU_VER_MIN ; +if (copy_to_guest (arg, &pmu_params,1 ) )
You're leaking hypervisor stack contents here ...
xen/arch/x86/hvm/vpmu.c void vpmu_dump(struct vcpu *v) · line 441
Quoted 3 lines
xen/arch/x86/hvm/vpmu.c +3
-0+case XENPMU_feature_get: + pmu_params.val = vpmu_mode; +if (copy_to_guest (arg, &pmu_params,1 ) )
... and here.
xen/include/Makefile headers-y := \ · line 29
Quoted 7 lines
xen/include/Makefile +1
-0@@ -26,6 +26,7 @@ headers-y := \ headers-$(CONFIG_X86) += compat/arch-x86/xen-mca.h headers-$(CONFIG_X86) += compat/arch-x86/xen.h headers-$(CONFIG_X86) += compat/arch-x86/xen-$(compat-arch-y).h +headers-$(CONFIG_X86) += compat/pmu.h compat/arch-x86/pmu.h
The first one isn't x86-specific, so doesn't belong here.
Quoted 20 lines
xen/include/public/arch-x86/pmu.h +4
-0@@ -9,12 +9,16 @@ struct xen_pmu_amd_ctxt {uint32_t counters;uint32_t ctrls; }; +typedef struct xen_pmu_amd_ctxt xen_pmu_amd_ctxt_t ; +DEFINE_XEN_GUEST_HANDLE (xen_pmu_amd_ctxt_t);/* Intel PMU registers and structures */ struct xen_pmu_cntr_pair {uint64_t counter;uint64_t control; }; +typedef struct xen_pmu_cntr_pair xen_pmu_cntr_pair_t ; +DEFINE_XEN_GUEST_HANDLE (xen_pmu_cntr_pair_t);struct xen_pmu_intel_ctxt {uint64_t global_ctrl;
xen/include/public/arch-x86/pmu.h struct xen_pmu_intel_ctxt { · line 39
Quoted 5 lines
xen/include/public/arch-x86/pmu.h +2
-0@@ -31,8 +35,10 @@ struct xen_pmu_intel_ctxt {uint32_t fixed_counters;uint32_t arch_counters; }; +typedef struct xen_pmu_intel_ctxt xen_pmu_intel_ctxt_t ; +DEFINE_XEN_GUEST_HANDLE (xen_pmu_intel_ctxt_t);
If you really need these typedefs and handles, why don't you add them right away when introducing this header?
xen/include/public/arch-x86/pmu.h struct xen_pmu_intel_ctxt { · line 41
Quoted 2 lines
xen/include/public/arch-x86/pmu.h +1
-1-struct xen_arch_pmu { +struct xen_pmu_arch {
And why can't this be named the final way from the beginning?
Jan
Re: [PATCH v9 11/20] x86/VPMU: Interface for setting PMU mode and flags
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/domain.c +1
-1@@ -1482,7 +1482,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_SELF ) )vpmu_save (prev);if ( !list_empty (&prev->arch.hvm_vcpu.tm_list) )@@ -1526,7 +1526,7 @@ void context_switch(struct vcpu *prev, struct vcpu *next) !is_hardware_domain(next->domain)); }
Quoted 9 lines
xen/arch/x86/domain.c void context_switch(struct vcpu *prev, struct vcpu *next) · line 1531
Quoted 4 lines
xen/arch/x86/domain.c +1
-1-if (is_hvm_vcpu (next) && (prev != next) ) +if (is_hvm_vcpu (next) && (prev != next) && (vpmu_mode &XENPMU_MODE_SELF ) )/* Must be done with interrupts enabled */ vpmu_load (next);Wouldn't such vPMU internals be better hidden in the functions themselves? I realize you can save the calls this way, but if the condition changes again later, we'll again have to adjust this core function rather than just the vPMU code. It's bad enough that the
vpmu_modevariable is visible to non-vPMU code.
How about an inline function?
Quoted 25 lines
Quoted 13 lines
xen/arch/x86/hvm/vpmu.c +2
-0@@ -21,6 +21,8 @@#include <xen/config.h> #include <xen/sched.h> #include <xen/xenoprof.h> +#include <xen/event.h> +#include <xen/guest_access.h> #include <asm/regs.h> #include <asm/types.h> #include <asm/msr.h> xen/arch/x86/hvm/vpmu.c line 43
Quoted 10 lines
xen/arch/x86/hvm/vpmu.c +7
-0@@ -32,13 +34,21 @@#include <asm/hvm/svm/vmcb.h> #include <asm/apic.h> #include <public/pmu.h> +#include <xen/tasklet.h> + +#include <compat/pmu.h> +CHECK_pmu_params; +CHECK_pmu_intel_ctxt; +CHECK_pmu_amd_ctxt; +CHECK_pmu_cntr_pair;Such being placed in a HVM-specific file suggests that the series is badly
ordered: Anything relevant to PV should normally only be added here
Quoted 8 lines
_after_ the file got moved out of the hvm/ subtree. Yet since I realize this would be a major re-work, I think you can leave this as is unless you expect potentially just part of the series to go in, with the splitting point being (immediately or later) after this patch (from my looking at it I would suppose that patches 3 and 4 could go in right away - they don't appear to depend on patches 1 and 2 - and patch 1 probably could go in too, but it doesn't make much sense to have it in without the rest of the series).
I would prefer the whole series to get in in one go (with patch 2 possibly being the only exception). All other patches (including patch 1) are not particularly useful on their own.
Quoted 18 lines
Quoted 18 lines
xen/arch/x86/hvm/vpmu.c +18
-0+ goto cont_wait; + +cpumask_andnot (&allbutself, &cpu_online_map, +cpumask_of (smp_processor_id ())); + + sync_task = xmalloc_array(struct tasklet, allbutself_num); +if ( !sync_task ) + { +printk ("vpmu_force_context_switch: out of memory\n" ); +return -ENOMEM ; + } + +for ( i =0 ; i < allbutself_num; i++ ) +tasklet_init (&sync_task[i], vpmu_sched_checkin,0 ); + +atomic_set (&vpmu_sched_counter,0 ); + + j =0 ;
Quoted 8 lines
Quoted 1 line
+
for_each_cpu( i, &allbutself )This looks to be the only use for the (on stack) allbutself variable, but you could easily avoid this by using
for_each_online_cpu()and skipping the local one. I'd also recommend that you countallbutself_numhere rather than up front, since that will much more obviously prove that you wait for exactly as many CPUs as you scheduled. The array allocation above is bogus anyway, as on a huge system this can easily be more than a page in size.
I don't understand the last sentence. What does page-sized allocation have to do with this?
Quoted 79 lines
Quoted 79 lines
xen/arch/x86/hvm/vpmu.c +78
-0+tasklet_schedule_on_cpu (&sync_task[j++], i); + +vpmu_save (current); + + start =NOW (); + + cont_wait: +/* +* Note that we may fail here if a CPU is hot-unplugged while we are +* waiting. We will then time out. +*/ +while (atomic_read (&vpmu_sched_counter) != allbutself_num ) + { +/* Give up after 5 seconds */ +if (NOW () > start +SECONDS (5 ) ) + { +printk ("vpmu_force_context_switch: failed to sync\n" ); + ret = -EBUSY ; +break ; + } +cpu_relax (); +if (hypercall_preempt_check () ) +return hypercall_create_continuation ( + __HYPERVISOR_xenpmu_op,"ih" , XENPMU_mode_set, arg); + } + +for ( i =0 ; i < allbutself_num; i++ ) +tasklet_kill (&sync_task[i]); +xfree (sync_task); + sync_task =NULL ; + +return ret; +} + +long do_xenpmu_op (int op,XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg) +{ +int ret = -EINVAL ; +xen_pmu_params_t pmu_params; + +switch ( op ) + { +case XENPMU_mode_set: + { +static DEFINE_SPINLOCK (xenpmu_mode_lock); +uint32_t current_mode; + +if ( !is_control_domain (current->domain) ) +return -EPERM ; + +if (copy_from_guest (&pmu_params, arg,1 ) ) +return -EFAULT ; + +if ( pmu_params.val & ~XENPMU_MODE_SELF ) +return -EINVAL ; + +/* +* Return error is someone else is in the middle of changing mode --- +* this is most likely indication of two system administrators +* working against each other +*/ +if ( !spin_trylock (&xenpmu_mode_lock) ) +return -EAGAIN ; + + current_mode = vpmu_mode; + vpmu_mode = pmu_params.val; + +if ( vpmu_mode ==XENPMU_MODE_OFF ) + { +/* +* Make sure all (non-dom0) VCPUs have unloaded their VPMUs. This +* can be achieved by having all physical processors go through +* context_switch(). +*/ + ret =vpmu_force_context_switch (arg); +if ( ret ) + vpmu_mode = current_mode; + } +else
Quoted 8 lines
xen/arch/x86/hvm/vpmu.c void vpmu_dump(struct vcpu *v) · line 412
Quoted 4 lines
xen/arch/x86/hvm/vpmu.c +4
-0+ ret =0 ; + +spin_unlock (&xenpmu_mode_lock); +break ;This still isn't safe: There's nothing preventing another vCPU to issue another
XENPMU_mode_setoperation while the one turning the vPMU off is still in the process of waiting, but having exited the lock protected region in order to allow other processing to occur.
I think that's OK: one of these two competing requests will timeout in the while loop of vpmu_force_context_switch(). It will, in fact, likely be the first caller because the second one will get right into the while loop, without setting up the waiting data. This is a little counter-intuitive but trying to set mode simultaneously from two different places is asking for trouble anyway.
Quoted 6 lines
I think you simply
need another mode "being-turned-off" during which only mode changes toXENPMU_MODE_OFF, and only by the originally requesting vCPU, are permitted (or else your "if true, we are in hypercall continuation" comment above wouldn't always be true either, as that second vCPU might also issue a second turn-off request).
-boris
Re: [PATCH v9 11/20] x86/VPMU: Interface for setting PMU mode and flags
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 12.08.14 at 17:12, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/domain.c +1
-1@@ -1482,7 +1482,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_SELF ) )vpmu_save (prev);if ( !list_empty (&prev->arch.hvm_vcpu.tm_list) )@@ -1526,7 +1526,7 @@ void context_switch(struct vcpu *prev, struct vcpu *next) !is_hardware_domain(next->domain)); }Quoted 9 lines
xen/arch/x86/domain.c void context_switch(struct vcpu *prev, struct vcpu *next) · line 1531
Quoted 4 lines
xen/arch/x86/domain.c +1
-1-if (is_hvm_vcpu (next) && (prev != next) ) +if (is_hvm_vcpu (next) && (prev != next) && (vpmu_mode &XENPMU_MODE_SELF ) )/* Must be done with interrupts enabled */ vpmu_load (next);Wouldn't such vPMU internals be better hidden in the functions themselves? I realize you can save the calls this way, but if the condition changes again later, we'll again have to adjust this core function rather than just the vPMU code. It's bad enough that the
vpmu_modevariable is visible to non-vPMU code.
Quoted 1 line
How about an inline function?
Yeah, that would perhaps do too. Albeit I'd still prefer all vPMU logic to be handle in the called vPMU functions.
Quoted 3 lines
I would prefer the whole series to get in in one go (with patch 2 possibly being the only exception). All other patches (including patch
1) are not particularly useful on their own.
Okay. In that case in patch 1, please consider swapping struct xenpf_symdata's address and name fields (I had put a respective note on the patch for when committing it), shrinking the structure for compat mode guests.
Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
xen/arch/x86/domain.c +18
-0+ goto cont_wait; + +cpumask_andnot (&allbutself, &cpu_online_map, +cpumask_of (smp_processor_id ())); + + sync_task = xmalloc_array(struct tasklet, allbutself_num); +if ( !sync_task ) + { +printk ("vpmu_force_context_switch: out of memory\n" ); +return -ENOMEM ; + } + +for ( i =0 ; i < allbutself_num; i++ ) +tasklet_init (&sync_task[i], vpmu_sched_checkin,0 ); + +atomic_set (&vpmu_sched_counter,0 ); + + j =0 ;Quoted 8 lines
Quoted 1 line
+
for_each_cpu( i, &allbutself )This looks to be the only use for the (on stack) allbutself variable, but you could easily avoid this by using
for_each_online_cpu()and skipping the local one. I'd also recommend that you countallbutself_numhere rather than up front, since that will much more obviously prove that you wait for exactly as many CPUs as you scheduled. The array allocation above is bogus anyway, as on a huge system this can easily be more than a page in size.
Quoted 2 lines
I don't understand the last sentence. What does page-sized allocation have to do with this?
We dislike greater than page size allocations at runtime.
Quoted 53 lines
Quoted 44 lines
Quoted 44 lines
xen/arch/x86/domain.c +44
-0+long do_xenpmu_op (int op,XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg) +{ +int ret = -EINVAL ; +xen_pmu_params_t pmu_params; + +switch ( op ) + { +case XENPMU_mode_set: + { +static DEFINE_SPINLOCK (xenpmu_mode_lock); +uint32_t current_mode; + +if ( !is_control_domain (current->domain) ) +return -EPERM ; + +if (copy_from_guest (&pmu_params, arg,1 ) ) +return -EFAULT ; + +if ( pmu_params.val & ~XENPMU_MODE_SELF ) +return -EINVAL ; + +/* +* Return error is someone else is in the middle of changing mode --- +* this is most likely indication of two system administrators +* working against each other +*/ +if ( !spin_trylock (&xenpmu_mode_lock) ) +return -EAGAIN ; + + current_mode = vpmu_mode; + vpmu_mode = pmu_params.val; + +if ( vpmu_mode ==XENPMU_MODE_OFF ) + { +/* +* Make sure all (non-dom0) VCPUs have unloaded their VPMUs. This +* can be achieved by having all physical processors go through +* context_switch(). +*/ + ret =vpmu_force_context_switch (arg); +if ( ret ) + vpmu_mode = current_mode; + } +else Quoted 8 lines
xen/arch/x86/domain.c
Quoted 4 lines
xen/arch/x86/domain.c +4
-0+ ret =0 ; + +spin_unlock (&xenpmu_mode_lock); +break ;This still isn't safe: There's nothing preventing another vCPU to issue another
XENPMU_mode_setoperation while the one turning the vPMU off is still in the process of waiting, but having exited the lock protected region in order to allow other processing to occur.
Quoted 6 lines
I think that's OK: one of these two competing requests will timeout in the while loop of
vpmu_force_context_switch(). It will, in fact, likely be the first caller because the second one will get right into the while loop, without setting up the waiting data. This is a little counter-intuitive but trying to set mode simultaneously from two different places is asking for trouble anyway.
Sure it is, but we nevertheless want the hypervisor to be safe. So I consider what you currently have acceptable only if you can prove that nothing bad can happen no matter in what order multiple requests get issued - from looking over your code I wasn't able to convince myself of this.
Jan
Re: [PATCH v9 11/20] x86/VPMU: Interface for setting PMU mode and flags
Quoted 27 lines · Jan Beulich
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 12.08.14 at 17:12, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/domain.c +1
-1@@ -1482,7 +1482,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_SELF ) )vpmu_save (prev);if ( !list_empty (&prev->arch.hvm_vcpu.tm_list) )xen/arch/x86/domain.c void context_switch(struct vcpu *prev, struct vcpu *next) · line 1531
Quoted 7 lines
xen/arch/x86/domain.c +1
-1@@ -1526,7 +1526,7 @@ void context_switch(struct vcpu *prev, struct vcpu *next) !is_hardware_domain(next->domain)); } -if (is_hvm_vcpu (next) && (prev != next) ) +if (is_hvm_vcpu (next) && (prev != next) && (vpmu_mode &XENPMU_MODE_SELF ) )/* Must be done with interrupts enabled */ vpmu_load (next);Wouldn't such vPMU internals be better hidden in the functions themselves? I realize you can save the calls this way, but if the condition changes again later, we'll again have to adjust this core function rather than just the vPMU code. It's bad enough that the
vpmu_modevariable is visible to non-vPMU code.
Quoted 3 lines
Quoted 1 line
How about an inline function?
Yeah, that would perhaps do too. Albeit I'd still prefer all vPMU logic to be handle in the called vPMU functions.
I was thinking about an inline in vpmu.h. Something like
inline void vpmu_next(struct vcpu *prev, struct vcpu *next)
{
if ( is_hvm_vcpu(next) && (prev != next) && (vpmu_mode &
XENPMU_MODE_SELF) )
/* Must be done with interrupts enabled */
vpmu_load(next);
}(and similar for vpmu_save())
Quoted 34 lines
Quoted 3 lines
I would prefer the whole series to get in in one go (with patch 2 possibly being the only exception). All other patches (including patch
1) are not particularly useful on their own.Okay. In that case in patch 1, please consider swapping struct xenpf_symdata's address and name fields (I had put a respective note on the patch for when committing it), shrinking the structure for compat mode guests.
Quoted 26 lines
Quoted 26 lines
Quoted 9 lines
xen/arch/x86/domain.c +9
-0+ goto cont_wait; + +cpumask_andnot (&allbutself, &cpu_online_map, +cpumask_of (smp_processor_id ())); + + sync_task = xmalloc_array(struct tasklet, allbutself_num); +if ( !sync_task ) + { +printk ("vpmu_force_context_switch: out of memory\n" );xen/arch/x86/domain.c void context_switch(struct vcpu *prev, struct vcpu *next)
Quoted 10 lines
xen/arch/x86/domain.c +10
-0+return -ENOMEM ; + } + +for ( i =0 ; i < allbutself_num; i++ ) +tasklet_init (&sync_task[i], vpmu_sched_checkin,0 ); + +atomic_set (&vpmu_sched_counter,0 ); + + j =0 ; +for_each_cpu ( i, &allbutself )This looks to be the only use for the (on stack) allbutself variable, but you could easily avoid this by using
for_each_online_cpu()and skipping the local one. I'd also recommend that you countallbutself_numhere rather than up front, since that will much more obviously prove that you wait for exactly as many CPUs as you scheduled. The array allocation above is bogus anyway, as on a huge system this can easily be more than a page in size.
Quoted 3 lines
Quoted 2 lines
I don't understand the last sentence. What does page-sized allocation have to do with this?
We dislike greater than page size allocations at runtime.
I can allocate array of pointers and then allocate tasklets in the for(i) loop above if that makes it more palatable but I still need allbutself_num value earlier than what you suggested.
Quoted 59 lines
Quoted 53 lines
Quoted 45 lines
Quoted 45 lines
xen/arch/x86/domain.c +44
-0+long do_xenpmu_op (int op,XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg) +{ +int ret = -EINVAL ; +xen_pmu_params_t pmu_params; + +switch ( op ) + { +case XENPMU_mode_set: + { +static DEFINE_SPINLOCK (xenpmu_mode_lock); +uint32_t current_mode; + +if ( !is_control_domain (current->domain) ) +return -EPERM ; + +if (copy_from_guest (&pmu_params, arg,1 ) ) +return -EFAULT ; + +if ( pmu_params.val & ~XENPMU_MODE_SELF ) +return -EINVAL ; + +/* +* Return error is someone else is in the middle of changing mode --- +* this is most likely indication of two system administrators +* working against each other +*/ +if ( !spin_trylock (&xenpmu_mode_lock) ) +return -EAGAIN ; + + current_mode = vpmu_mode; + vpmu_mode = pmu_params.val; + +if ( vpmu_mode ==XENPMU_MODE_OFF ) + { +/* +* Make sure all (non-dom0) VCPUs have unloaded their VPMUs. This +* can be achieved by having all physical processors go through +* context_switch(). +*/ + ret =vpmu_force_context_switch (arg); +if ( ret ) + vpmu_mode = current_mode; + } +else Quoted 8 lines
xen/arch/x86/domain.c
Quoted 4 lines
xen/arch/x86/domain.c +4
-0+ ret =0 ; + +spin_unlock (&xenpmu_mode_lock); +break ;This still isn't safe: There's nothing preventing another vCPU to issue another
XENPMU_mode_setoperation while the one turning the vPMU off is still in the process of waiting, but having exited the lock protected region in order to allow other processing to occur.Quoted 6 lines
I think that's OK: one of these two competing requests will timeout in the while loop of
vpmu_force_context_switch(). It will, in fact, likely be the first caller because the second one will get right into the while loop, without setting up the waiting data. This is a little counter-intuitive but trying to set mode simultaneously from two different places is asking for trouble anyway.
Quoted 5 lines
Sure it is, but we nevertheless want the hypervisor to be safe. So I consider what you currently have acceptable only if you can prove that nothing bad can happen no matter in what order multiple requests get issued - from looking over your code I wasn't able to convince myself of this.
Would a comment with what I said above (possibly a bit massaged) be sufficient?
-boris
Re: [PATCH v9 11/20] x86/VPMU: Interface for setting PMU mode and flags
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 12.08.14 at 18:25, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 12.08.14 at 17:12, <[email protected]> wrote:
How about an inline function?
Yeah, that would perhaps do too. Albeit I'd still prefer all vPMU logic to be handle in the called vPMU functions.
I was thinking about an inline in
vpmu.h. Something likeinline void
vpmu_next(struct vcpu *prev, struct vcpu *next)
Quoted 8 lines
{ if ( is_hvm_vcpu(next) && (prev != next) && (vpmu_mode & XENPMU_MODE_SELF) ) /* Must be done with interrupts enabled */ vpmu_load(next); }(and similar for
vpmu_save())
That doesn't change my opinion: Perhaps acceptable, but doing isolation in the Linux like way rather than true separation.
Quoted 13 lines
Quoted 11 lines
Quoted 6 lines
I think that's OK: one of these two competing requests will timeout in the while loop of
vpmu_force_context_switch(). It will, in fact, likely be the first caller because the second one will get right into the while loop, without setting up the waiting data. This is a little counter-intuitive but trying to set mode simultaneously from two different places is asking for trouble anyway.Sure it is, but we nevertheless want the hypervisor to be safe. So I consider what you currently have acceptable only if you can prove that nothing bad can happen no matter in what order multiple requests get issued - from looking over your code I wasn't able to convince myself of this.
Quoted 2 lines
Would a comment with what I said above (possibly a bit massaged) be sufficient?
Perhaps, as long as that comment supplies the requested proof.
Jan
PATCH v9 12/20 x86/VPMU: Initialize PMU for PV(H) guests
In reply to Boris OstrovskyCode for initializing/tearing down PMU for PV guests
--- xen/arch/x86/hvm/hvm.c | 3 +- xen/arch/x86/hvm/svm/svm.c | 8 +++- xen/arch/x86/hvm/svm/vpmu.c | 37 ++++++++++------- xen/arch/x86/hvm/vmx/vmx.c | 9 ++++- xen/arch/x86/hvm/vmx/vpmu_core2.c | 69 +++++++++++++++++++++---------- 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 + 10 files changed, 174 insertions(+), 42 deletions(-)
xen/arch/x86/hvm/hvm.c +2 -1
@@ -4768,7 +4768,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/svm.c +6 -2
@@ -1158,7 +1158,9 @@ static int svm_vcpu_initialise(struct vcpu *v)return rc; } -vpmu_initialise (v); +/* PVH's VPMU is initialized via hypercall */ +if (is_hvm_domain (v->domain) ) +vpmu_initialise (v);svm_guest_osvw_init (v);
@@ -1167,7 +1169,9 @@ static int svm_vcpu_initialise(struct vcpu *v)static void svm_vcpu_destroy (struct vcpu *v) { -vpmu_destroy (v); +/* PVH's VPMU destroyed via hypercall */ +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 -14
@@ -386,14 +386,21 @@ static int amd_vpmu_initialise(struct vcpu *v) } } - ctxt =xzalloc_bytes (sizeof (struct xen_pmu_amd_ctxt ) + -2 *sizeof (uint64_t ) *AMD_MAX_COUNTERS ); -if ( !ctxt ) +if (is_hvm_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 ) + +2 *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 );
@@ -412,17 +419,19 @@ static void amd_vpmu_destroy(struct vcpu *v)if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_ALLOCATED ) )return ; -if (has_hvm_container_domain (v->domain) &&is_msr_bitmap_on (vpmu) ) -amd_vpmu_unset_msr_bitmap (v); +if (has_hvm_container_domain (v->domain) ) + { +if (is_msr_bitmap_on (vpmu) ) +amd_vpmu_unset_msr_bitmap (v); -xfree (vpmu->context); -vpmu_reset (vpmu,VPMU_CONTEXT_ALLOCATED ); +if (is_hvm_domain (v->domain) ) +xfree (vpmu->context); -if (vpmu_is_set (vpmu,VPMU_RUNNING ) ) - { -vpmu_reset (vpmu,VPMU_RUNNING );release_pmu_ownship (PMU_OWNER_HVM ); } + + vpmu->context =NULL ; +vpmu_clear (vpmu); }/* VPMU part of the 'q' keyhandler */
xen/arch/x86/hvm/vmx/vmx.c +7 -2
@@ -116,7 +116,9 @@ static int vmx_vcpu_initialise(struct vcpu *v)return rc; } -vpmu_initialise (v); +/* PVH's VPMU is initialized via hypercall */ +if (is_hvm_domain (v->domain) ) +vpmu_initialise (v);vmx_install_vlapic_mapping (v);
@@ -130,7 +132,10 @@ static int vmx_vcpu_initialise(struct vcpu *v)static void vmx_vcpu_destroy (struct vcpu *v) {vmx_destroy_vmcs (v); -vpmu_destroy (v); + +/* PVH's VPMU is destroyed via hypercall */ +if (is_hvm_domain (v->domain) ) +vpmu_destroy (v);passive_domain_destroy (v); }
xen/arch/x86/hvm/vmx/vpmu_core2.c +47 -22
102 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
@@ -61,6 +61,7 @@ struct vpmu_struct {void *context;/* May be shared with PV guest */ void *priv_context;/* hypervisor-only */ 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
Signature · 1 line
1.8.1.4
Re: [PATCH v9 12/20] x86/VPMU: Initialize PMU for PV(H) guests
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/hvm/svm/svm.c +3
-1@@ -1158,7 +1158,9 @@ static int svm_vcpu_initialise(struct vcpu *v)return rc; } -vpmu_initialise (v); +/* PVH's VPMU is initialized via hypercall */ +if (is_hvm_domain (v->domain) ) +vpmu_initialise (v);svm_guest_osvw_init (v);
xen/arch/x86/hvm/svm/svm.c static int svm_vcpu_initialise(struct vcpu *v) · line 1174
Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c +3
-1@@ -1167,7 +1169,9 @@ static int svm_vcpu_initialise(struct vcpu *v)static void svm_vcpu_destroy (struct vcpu *v) { -vpmu_destroy (v); +/* PVH's VPMU destroyed via hypercall */ +if (is_hvm_domain (v->domain) ) +vpmu_destroy (v);
While I can see that being the case for init, is this really correct for destroy even for a misbehaving guest?
Quoted 12 lines
xen/arch/x86/hvm/svm/vpmu.c +1
-4@@ -386,14 +386,21 @@ static int amd_vpmu_initialise(struct vcpu *v) } } - ctxt =xzalloc_bytes (sizeof (struct xen_pmu_amd_ctxt ) + -2 *sizeof (uint64_t ) *AMD_MAX_COUNTERS ); -if ( !ctxt ) +if (is_hvm_domain (v->domain) ) { - gdprintk(XENLOG_WARNING, "Insufficient memory for PMU, "
xen/arch/x86/hvm/svm/vpmu.c static int amd_vpmu_initialise(struct vcpu *v) · line 397
Quoted 10 lines
xen/arch/x86/hvm/svm/vpmu.c +7
-3-" 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 ) + +2 *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);
If you already have to touch this, please make it sane: gdprintk() already prints a (domain,vcpu) pair, and two of them are unlikely to be useful here. Also this should make use of %pv.
xen/arch/x86/hvm/svm/vpmu.c static int amd_vpmu_initialise(struct vcpu *v) · line 404
Quoted 7 lines
xen/arch/x86/hvm/svm/vpmu.c +6
-0+return -ENOMEM ; + } + } +else + { + ctxt = &v->arch.vpmu.xenpmu_data->pmu.c.amd; }
Pointless braces.
Quoted 10 lines
xen/arch/x86/hvm/svm/vpmu.c +1
-1@@ -387,7 +399,7 @@ static int core2_vpmu_alloc_resource(struct vcpu *v)return 1 ; -out_err: +out_err_hvm:vmx_rm_msr (MSR_CORE_PERF_GLOBAL_CTRL ,VMX_HOST_MSR );vmx_rm_msr (MSR_CORE_PERF_GLOBAL_CTRL ,VMX_GUEST_MSR );release_pmu_ownship (PMU_OWNER_HVM );
xen/arch/x86/hvm/svm/vpmu.c out_err: · line 410
Quoted 4 lines
xen/arch/x86/hvm/svm/vpmu.c +1
-0@@ -395,6 +407,7 @@ out_err:xfree (core2_vpmu_cxt);xfree (p); +out_err:
I think I said this before: Please indent labels by at least one space.
xen/arch/x86/hvm/vpmu.c line 26
Quoted 8 lines
xen/arch/x86/hvm/vpmu.c +2
-0@@ -22,10 +22,13 @@#include <xen/sched.h> #include <xen/xenoprof.h> #include <xen/event.h> +#include <xen/softirq.h> +#include <xen/hypercall.h>
Leftover additions from an earlier version?
Jan
PATCH v9 13/20 x86/VPMU: When handling MSR accesses, leave fault injection to callers
In reply to Boris OstrovskyThis is done in preparation to subsequent PV patches.
--- xen/arch/x86/hvm/svm/svm.c | 6 ++-- xen/arch/x86/hvm/svm/vpmu.c | 6 ++-- xen/arch/x86/hvm/vmx/vmx.c | 26 +++++++++++----- xen/arch/x86/hvm/vmx/vpmu_core2.c | 65 +++++++++++++++++---------------------- 4 files changed, 54 insertions(+), 49 deletions(-)
xen/arch/x86/hvm/svm/svm.c +4 -2
@@ -1642,7 +1642,8 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)case MSR_AMD_FAM15H_EVNTSEL3 :case MSR_AMD_FAM15H_EVNTSEL4 :case MSR_AMD_FAM15H_EVNTSEL5 : -vpmu_do_rdmsr (msr, msr_content); +if (vpmu_do_rdmsr (msr, msr_content) ) + goto gpf;break ;case MSR_AMD64_DR0_ADDRESS_MASK :
@@ -1793,7 +1794,8 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)case MSR_AMD_FAM15H_EVNTSEL3 :case MSR_AMD_FAM15H_EVNTSEL4 :case MSR_AMD_FAM15H_EVNTSEL5 : -vpmu_do_wrmsr (msr, msr_content); +if (vpmu_do_wrmsr (msr, msr_content) ) + goto gpf;break ;case MSR_IA32_MCx_MISC (4 ):/* Threshold register */
xen/arch/x86/hvm/svm/vpmu.c +3 -3
@@ -303,7 +303,7 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) is_pmu_enabled(msr_content) && !vpmu_is_set(vpmu, VPMU_RUNNING) ) {if ( !acquire_pmu_ownership (PMU_OWNER_HVM ) ) -return 1 ; +return 0 ;vpmu_set (vpmu,VPMU_RUNNING );if (has_hvm_container_domain (v->domain) &&is_msr_bitmap_on (vpmu) )
@@ -333,7 +333,7 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)/* Write to hw counters */ wrmsrl (msr, msr_content); -return 1 ; +return 0 ; }static int amd_vpmu_do_rdmsr (unsigned int msr,uint64_t *msr_content)
@@ -351,7 +351,7 @@ static int amd_vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content)rdmsrl (msr, *msr_content); -return 1 ; +return 0 ; }static int amd_vpmu_initialise (struct vcpu *v)
xen/arch/x86/hvm/vmx/vmx.c +19 -7
@@ -2078,12 +2078,17 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content) *msr_content |=MSR_IA32_MISC_ENABLE_BTS_UNAVAIL |MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL ;/* Perhaps vpmu will change some bits. */ +/* FALLTHROUGH */ + 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_IA32_PEBS_ENABLE : +case MSR_IA32_DS_AREA :if (vpmu_do_rdmsr (msr, msr_content) ) - goto done; + goto gp_fault;break ;default : -if (vpmu_do_rdmsr (msr, msr_content) ) -break ;if (passive_domain_do_rdmsr (msr, msr_content) ) goto done; switch ( long_mode_do_msr_read(msr, msr_content) )
@@ -2256,8 +2261,8 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)if ( msr_content & ~supported ) {/* Perhaps some other bits are supported in vpmu. */ -if ( !vpmu_do_wrmsr (msr, msr_content) ) -break ; +if (vpmu_do_wrmsr (msr, msr_content) ) + goto gp_fault; }if ( msr_content &IA32_DEBUGCTLMSR_LBR ) {
@@ -2286,9 +2291,16 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)if ( !nvmx_msr_write_intercept (msr, msr_content) ) goto gp_fault;break ; -default : + 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_IA32_PEBS_ENABLE : +case MSR_IA32_DS_AREA :if (vpmu_do_wrmsr (msr, msr_content) ) -return X86EMUL_OKAY ; + goto gp_fault; +break ; +default :if (passive_domain_do_wrmsr (msr, msr_content) )return X86EMUL_OKAY ;
xen/arch/x86/hvm/vmx/vpmu_core2.c +28 -37
137 lines not on this page · raw message
Signature · 1 line
1.8.1.4
Re: [PATCH v9 13/20] x86/VPMU: When handling MSR accesses, leave fault injection to callers
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vpmu_core2.c +2
-1@@ -458,13 +458,13 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)if (cpu_has (¤t_cpu_data,X86_FEATURE_DSCPL ) ) supported |=IA32_DEBUGCTLMSR_BTS_OFF_OS |IA32_DEBUGCTLMSR_BTS_OFF_USR ; -if ( msr_content & supported ) + + if ( !(msr_content & supported ) ||
xen/arch/x86/hvm/vmx/vpmu_core2.c static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) · line 467
Quoted 10 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +4
-5+ !vpmu_is_set(vpmu, VPMU_CPU_HAS_BTS) ) { -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 ); -return 0 ; +gdprintk (XENLOG_WARNING , +"Debug Store is not supported on this cpu\n" ); +return 1 ;
The code here (and in particular the #GP injection) was wrong anyway; see the small series I sent earlier today. Please base your on top of that.
xen/arch/x86/hvm/vmx/vpmu_core2.c static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) · line 483
Quoted 11 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-2@@ -476,18 +476,17 @@ 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; -return 1 ; +return 0 ;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 );return 1 ;
Suspicious: Most return values get flipped, but this one (and at least one more below) doesn't. Any such inconsistencies that are being corrected (assuming this is intentional) as you go should be spelled out in the description. And then the question of course is whether it's really necessary to flip the meaning of this and some similar SVM function's return values anyway.
xen/arch/x86/hvm/vmx/vpmu_core2.c static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) · line 547
Quoted 8 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +0
-4@@ -541,45 +539,43 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) } } -if ( (global_ctrl & *enabled_cntrs) || (core2_vpmu_cxt->ds_area !=0 ) ) -vpmu_set (vpmu,VPMU_RUNNING ); -else -vpmu_reset (vpmu,VPMU_RUNNING );
The moving off this code is - again without at least a brief comment - also not obviously correct; at least to me it looks like this slightly alters behavior (perhaps towards the better, but anyway).
Quoted 5 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +0
-1@@ -607,19 +603,14 @@ static int core2_vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content)rdmsrl (msr, *msr_content); } } -else
xen/arch/x86/hvm/vmx/vpmu_core2.c static int core2_vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) · line 619
Quoted 10 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-7+else if ( msr ==MSR_IA32_MISC_ENABLE ) {/* Extension for BTS */ -if ( msr ==MSR_IA32_MISC_ENABLE ) - { -if (vpmu_is_set (vpmu,VPMU_CPU_HAS_BTS ) ) - *msr_content &= ~MSR_IA32_MISC_ENABLE_BTS_UNAVAIL ; - } -else -return 0 ;
Again a case where the return value stays the same even if in general it appears to get flipped in this function.
xen/arch/x86/hvm/vmx/vpmu_core2.c static int core2_vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) · line 614
Quoted 7 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +3
-1+if (vpmu_is_set (vpmu,VPMU_CPU_HAS_BTS ) ) + *msr_content &= ~MSR_IA32_MISC_ENABLE_BTS_UNAVAIL ; } -return 1 ; +return 0 ; }
Jan
Re: [PATCH v9 13/20] x86/VPMU: When handling MSR accesses, leave fault injection to callers
Quoted 32 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vpmu_core2.c +2
-1@@ -458,13 +458,13 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content)if (cpu_has (¤t_cpu_data,X86_FEATURE_DSCPL ) ) supported |=IA32_DEBUGCTLMSR_BTS_OFF_OS |IA32_DEBUGCTLMSR_BTS_OFF_USR ; -if ( msr_content & supported ) + + if ( !(msr_content & supported ) ||xen/arch/x86/hvm/vmx/vpmu_core2.c static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) · line 467
Quoted 10 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +4
-5+ !vpmu_is_set(vpmu, VPMU_CPU_HAS_BTS) ) { -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 ); -return 0 ; +gdprintk (XENLOG_WARNING , +"Debug Store is not supported on this cpu\n" ); +return 1 ;The code here (and in particular the #GP injection) was wrong anyway; see the small series I sent earlier today. Please base your on top of that.
Quoted 9 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-1@@ -476,18 +476,17 @@ 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; -return 1 ; +return 0 ;case MSR_CORE_PERF_GLOBAL_STATUS :gdprintk (XENLOG_INFO ,"Can not write readonly MSR: " "MSR_PERF_GLOBAL_STATUS(0x38E)!\n" );
Quoted 8 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) · line 483
Quoted 2 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +0
-1-hvm_inject_hw_exception (TRAP_gp_fault,0 );return 1 ;Suspicious: Most return values get flipped, but this one (and at least one more below) doesn't. Any such inconsistencies that are being corrected (assuming this is intentional) as you go should be spelled out in the description. And then the question of course is whether it's really necessary to flip the meaning of this and some similar SVM function's return values anyway.
The return value of 1 of vpmu_do_msr() will now indicate that the routine encountered a fault as opposed to indicating whether the MSR access was to a VPMU register.
I will make a comment to that effect.
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +0
-0@@ -541,45 +539,43 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) } }
Quoted 7 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) · line 547
Quoted 4 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +0
-4-if ( (global_ctrl & *enabled_cntrs) || (core2_vpmu_cxt->ds_area !=0 ) ) -vpmu_set (vpmu,VPMU_RUNNING ); -else -vpmu_reset (vpmu,VPMU_RUNNING );The moving off this code is - again without at least a brief comment - also not obviously correct; at least to me it looks like this slightly alters behavior (perhaps towards the better, but anyway).
Right. Because we don't want to change VPMU state if a fault is encountered (which is possible with current code).
Come think of it, this is still not enough --- we may leave registers updated when fault happens. I should fix that too.
-boris
Quoted 28 lines
Quoted 6 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +0
-1@@ -607,19 +603,14 @@ static int core2_vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content)rdmsrl (msr, *msr_content); } } -else xen/arch/x86/hvm/vmx/vpmu_core2.c static int core2_vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) · line 619
Quoted 10 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-7+else if ( msr ==MSR_IA32_MISC_ENABLE ) {/* Extension for BTS */ -if ( msr ==MSR_IA32_MISC_ENABLE ) - { -if (vpmu_is_set (vpmu,VPMU_CPU_HAS_BTS ) ) - *msr_content &= ~MSR_IA32_MISC_ENABLE_BTS_UNAVAIL ; - } -else -return 0 ;Again a case where the return value stays the same even if in general it appears to get flipped in this function.
xen/arch/x86/hvm/vmx/vpmu_core2.c static int core2_vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) · line 614
Quoted 7 lines
xen/arch/x86/hvm/vmx/vpmu_core2.c +3
-1+if (vpmu_is_set (vpmu,VPMU_CPU_HAS_BTS ) ) + *msr_content &= ~MSR_IA32_MISC_ENABLE_BTS_UNAVAIL ; } -return 1 ; +return 0 ; }Jan
Re: [PATCH v9 13/20] x86/VPMU: When handling MSR accesses, leave fault injection to callers
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 12.08.14 at 17:47, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-1@@ -476,18 +476,17 @@ 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; -return 1 ; +return 0 ;case MSR_CORE_PERF_GLOBAL_STATUS :gdprintk (XENLOG_INFO ,"Can not write readonly MSR: " "MSR_PERF_GLOBAL_STATUS(0x38E)!\n" );Quoted 8 lines
Review static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) · line 483
Quoted 2 lines
(quoted diff) +0
-1- hvm_inject_hw_exception(TRAP_gp_fault, 0); return 1;Suspicious: Most return values get flipped, but this one (and at least one more below) doesn't. Any such inconsistencies that are being corrected (assuming this is intentional) as you go should be spelled out in the description. And then the question of course is whether it's really necessary to flip the meaning of this and some similar SVM function's return values anyway.
Quoted 3 lines
The return value of 1 of
vpmu_do_msr()will now indicate that the routine encountered a fault as opposed to indicating whether the MSR access was to a VPMU register.
And how would it now indicate that latter fact?
Jan
Re: [PATCH v9 13/20] x86/VPMU: When handling MSR accesses, leave fault injection to callers
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 12.08.14 at 17:47, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
xen/arch/x86/hvm/vmx/vpmu_core2.c static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) · line 483
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vpmu_core2.c +1
-2@@ -476,18 +476,17 @@ 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; -return 1 ; +return 0 ;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 );return 1 ;Suspicious: Most return values get flipped, but this one (and at least one more below) doesn't. Any such inconsistencies that are being corrected (assuming this is intentional) as you go should be spelled out in the description. And then the question of course is whether it's really necessary to flip the meaning of this and some similar SVM function's return values anyway.
Quoted 4 lines
Quoted 3 lines
The return value of 1 of
vpmu_do_msr()will now indicate that the routine encountered a fault as opposed to indicating whether the MSR access was to a VPMU register.And how would it now indicate that latter fact?
It won't. Which is why I made changes to vmx_msr_read/write_intercept() to only call this routine when we know that a VPMU register is possibly accessed.
I thought about tri-stating vpmu_do_msr() returns (-1 for faults, 0 for no registers have been accessed, 1 for successful accesses) but decided against it.
-boris
PATCH v9 14/20 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 | 45 ++++++++++++++++++++++++++++------ xen/arch/x86/hvm/vpmu.c | 7 ++++++ xen/arch/x86/traps.c | 51 +++++++++++++++++++++++++++++++++++++-- xen/include/public/pmu.h | 1 + 5 files changed, 96 insertions(+), 11 deletions(-)
xen/arch/x86/domain.c +1 -2
@@ -2012,8 +2012,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 +38 -7
108 lines not on this page · raw message
xen/arch/x86/hvm/vpmu.c +7 -0
@@ -525,6 +525,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 +49 -2
101 lines not on this page · raw message
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.1.4
Re: [PATCH v9 14/20] x86/VPMU: Add support for PMU register handling on PV guests
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/traps.c +0
-1@@ -2556,7 +2564,22 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)if ( v->arch.debugreg[7 ] &DR7_ACTIVE_MASK )wrmsrl (regs->_ecx, msr_content);break ; -
xen/arch/x86/traps.c static int emulate_privileged_op(struct cpu_user_regs *regs) · line 2576
Quoted 10 lines
xen/arch/x86/traps.c +10
-0+ 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: +if ( boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) + vpmu_msr =1 ; +/* FALLTHROUGH */ + case MSR_AMD_FAM15H_EVNTSEL0...MSR_AMD_FAM15H_PERFCTR5: +if ( vpmu_msr || + ((boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) && !vpmu_msr) )
Pointlessly complicated right side of the ||: (a || (b && !a)) is the same as (a || b). Meaning this _still_ doesn't achieve what you appear to want, i.e. the set of Intel MSRs continues to also get handled on AMD CPUs.
Jan
PATCH v9 15/20 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 | 158 +++++++++++++++++++++++++++++++++++++++++++---- xen/include/public/pmu.h | 7 +++ 2 files changed, 153 insertions(+), 12 deletions(-)
xen/arch/x86/hvm/vpmu.c +146 -12
@@ -80,44 +80,167 @@ static void __init parse_vpmu_param(char *s)void vpmu_lvtpc_update (uint32_t val) { -struct vpmu_struct *vpmu =vcpu_vpmu (current); +struct vcpu *curr = current; +struct vpmu_struct *vpmu =vcpu_vpmu (curr); vpmu->hw_lapic_lvtpc =PMU_APIC_VECTOR | (val &APIC_LVT_MASKED ); -apic_write (APIC_LVTPC , vpmu->hw_lapic_lvtpc); + +/* Postpone APIC updates for PV(H) guests if PMU interrupt is pending */ +if (is_hvm_domain (curr->domain) || + !(vpmu->xenpmu_data && (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) { -struct vpmu_struct *vpmu =vcpu_vpmu (current); +struct vcpu *curr = current; +struct vpmu_struct *vpmu =vcpu_vpmu (curr);if ( !(vpmu_mode &XENPMU_MODE_SELF ) )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 (curr->domain) && + vpmu->xenpmu_data && (vpmu->xenpmu_data->pmu_flags &PMU_CACHED ) ) + { +vpmu_set (vpmu,VPMU_CONTEXT_SAVE ); + vpmu->arch_vpmu_ops->arch_vpmu_save (curr); +vpmu_reset (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ); + } +return ret; + }return 0 ; }int vpmu_do_rdmsr (unsigned int msr,uint64_t *msr_content) { -struct vpmu_struct *vpmu =vcpu_vpmu (current); +struct vcpu *curr = current; +struct vpmu_struct *vpmu =vcpu_vpmu (curr);if ( !(vpmu_mode &XENPMU_MODE_SELF ) )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 (curr->domain) && + vpmu->xenpmu_data && (vpmu->xenpmu_data->pmu_flags &PMU_CACHED ) ) + { +vpmu_set (vpmu,VPMU_CONTEXT_SAVE ); + vpmu->arch_vpmu_ops->arch_vpmu_save (curr); +vpmu_reset (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ); + } +return ret; + }return 0 ; } +static struct vcpu *choose_hwdom_vcpu (void ) +{ +struct vcpu *v; +unsigned idx =smp_processor_id () % hardware_domain->max_vcpus; + +if ( hardware_domain->vcpu ==NULL ) +return NULL ; + + v = hardware_domain->vcpu[idx]; + +/* +* If index is not populated search downwards the vcpu array until +* a valid vcpu can be found +*/ +while ( !v && idx-- ) + v = hardware_domain->vcpu[idx]; + +return v; +} +int vpmu_do_interrupt (struct cpu_user_regs *regs) { -struct vcpu *v = current; -struct vpmu_struct *vpmu =vcpu_vpmu (v); +struct vcpu *sampled = current, *sampling; +struct vpmu_struct *vpmu; + +/* dom0 will handle interrupt for special domains (e.g. idle domain) */ +if ( sampled->domain->domain_id >=DOMID_FIRST_RESERVED ) + { + sampling =choose_hwdom_vcpu (); +if ( !sampling ) +return 0 ; + } +else + sampling = sampled; + + vpmu =vcpu_vpmu (sampling); +if ( !is_hvm_domain (sampling->domain) ) + { +/* PV(H) guest or dom0 is doing system profiling */ +const struct cpu_user_regs *gregs; + +if ( !vpmu->xenpmu_data ) +return 0 ; + +if ( vpmu->xenpmu_data->pmu_flags &PMU_CACHED ) +return 1 ; + +if (is_pvh_domain (sampled->domain) && + !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 ); + vpmu->arch_vpmu_ops->arch_vpmu_save (sampling); +vpmu_reset (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ); + +/* Store appropriate registers in xenpmu_data */ +if (is_pv_32bit_domain (sampled->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 *)&vpmu->xenpmu_data->pmu.r.regs; +XLAT_cpu_user_regs (cmp, gregs); + } +else if ( !is_hardware_domain (sampled->domain) && + !is_idle_vcpu (sampled) ) + { +/* PV(H) guest */ + gregs =guest_cpu_user_regs (); + vpmu->xenpmu_data->pmu.r.regs = *gregs; + } +else + vpmu->xenpmu_data->pmu.r.regs = *regs; + + vpmu->xenpmu_data->domain_id = sampled->domain->domain_id; + vpmu->xenpmu_data->vcpu_id = sampled->vcpu_id; + vpmu->xenpmu_data->pcpu_id =smp_processor_id (); + + 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 (sampling,VIRQ_XENPMU ); + +return 1 ; + }if ( vpmu->arch_vpmu_ops ) { -struct vlapic *vlapic =vcpu_vlapic (v); +struct vlapic *vlapic =vcpu_vlapic (sampling);u32 vlapic_lvtpc;unsigned char int_vec;
@@ -131,9 +254,9 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs) 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 ); +vlapic_set_irq (vcpu_vlapic (sampling), int_vec,0 );else - v->nmi_pending =1 ; + sampling->nmi_pending =1 ;return 1 ; }
@@ -232,7 +355,9 @@ 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_hvm_domain (v->domain) && + vpmu->xenpmu_data->pmu_flags &PMU_CACHED ) )return ;if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_load )
@@ -436,6 +561,7 @@ vpmu_force_context_switch(XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg)long do_xenpmu_op (int op,XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg) {int ret = -EINVAL ; +struct vcpu *curr;xen_pmu_params_t pmu_params; switch ( op )
@@ -532,6 +658,14 @@ 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: + curr = current; + curr->arch.vpmu.xenpmu_data->pmu_flags &= ~PMU_CACHED ; +vpmu_lvtpc_update (curr->arch.vpmu.xenpmu_data->pmu.l.lapic_lvtpc); +vpmu_load (curr); + 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 */
@@ -59,6 +60,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.1.4
Re: [PATCH v9 15/20] x86/VPMU: Handle PMU interrupts for PV guests
xen/arch/x86/hvm/vpmu.c long do_xenpmu_op(int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg) · line 658
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/hvm/vpmu.c +1
-0@@ -436,6 +561,7 @@ vpmu_force_context_switch(XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg)long do_xenpmu_op (int op,XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg) {int ret = -EINVAL ; +struct vcpu *curr;xen_pmu_params_t pmu_params; switch ( op )@@ -532,6 +658,14 @@ 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);
So why does this not get switched to use "curr" at once?
Jan
PATCH v9 16/20 x86/VPMU: Merge vpmu_rdmsr and vpmu_wrmsr
In reply to Boris OstrovskyThe two routines share most of their logic.
--- xen/arch/x86/hvm/svm/svm.c | 4 +-- xen/arch/x86/hvm/vmx/vmx.c | 6 ++-- xen/arch/x86/hvm/vpmu.c | 66 +++++++++++++++++++----------------------- xen/arch/x86/traps.c | 4 +-- xen/include/asm-x86/hvm/vpmu.h | 6 ++-- 5 files changed, 40 insertions(+), 46 deletions(-)
xen/arch/x86/hvm/svm/svm.c +2 -2
@@ -1642,7 +1642,7 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)case MSR_AMD_FAM15H_EVNTSEL3 :case MSR_AMD_FAM15H_EVNTSEL4 :case MSR_AMD_FAM15H_EVNTSEL5 : -if (vpmu_do_rdmsr (msr, msr_content) ) +if (vpmu_do_msr (msr, msr_content,VPMU_MSR_READ ) ) goto gpf;break ;
@@ -1794,7 +1794,7 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)case MSR_AMD_FAM15H_EVNTSEL3 :case MSR_AMD_FAM15H_EVNTSEL4 :case MSR_AMD_FAM15H_EVNTSEL5 : -if (vpmu_do_wrmsr (msr, msr_content) ) +if (vpmu_do_msr (msr, &msr_content,VPMU_MSR_WRITE ) ) goto gpf;break ;
xen/arch/x86/hvm/vmx/vmx.c +3 -3
@@ -2085,7 +2085,7 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content) case MSR_CORE_PERF_FIXED_CTR_CTRL...MSR_CORE_PERF_GLOBAL_OVF_CTRL:case MSR_IA32_PEBS_ENABLE :case MSR_IA32_DS_AREA : -if (vpmu_do_rdmsr (msr, msr_content) ) +if (vpmu_do_msr (msr, msr_content,VPMU_MSR_READ ) ) goto gp_fault;break ;default :
@@ -2261,7 +2261,7 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)if ( msr_content & ~supported ) {/* Perhaps some other bits are supported in vpmu. */ -if (vpmu_do_wrmsr (msr, msr_content) ) +if (vpmu_do_msr (msr, &msr_content,VPMU_MSR_WRITE ) ) goto gp_fault; }if ( msr_content &IA32_DEBUGCTLMSR_LBR )
@@ -2297,7 +2297,7 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) case MSR_CORE_PERF_FIXED_CTR_CTRL...MSR_CORE_PERF_GLOBAL_OVF_CTRL:case MSR_IA32_PEBS_ENABLE :case MSR_IA32_DS_AREA : -if (vpmu_do_wrmsr (msr, msr_content) ) +if (vpmu_do_msr (msr, &msr_content,VPMU_MSR_WRITE ) ) goto gp_fault;break ;default :
xen/arch/x86/hvm/vpmu.c +29 -37
86 lines not on this page · raw message
xen/arch/x86/traps.c +2 -2
@@ -2575,7 +2575,7 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)if ( vpmu_msr || ((boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) && !vpmu_msr) ) { -if (vpmu_do_wrmsr (regs->ecx, msr_content) ) +if (vpmu_do_msr (regs->ecx, &msr_content,VPMU_MSR_WRITE ) ) goto fail;break ; }
@@ -2698,7 +2698,7 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)if ( vpmu_msr || ((boot_cpu_data.x86_vendor !=X86_VENDOR_AMD ) && !vpmu_msr) ) { -if (vpmu_do_rdmsr (regs->ecx, &msr_content) ) +if (vpmu_do_msr (regs->ecx, &msr_content,VPMU_MSR_READ ) ) goto fail; regs->eax = (uint32_t )msr_content;
xen/include/asm-x86/hvm/vpmu.h +4 -2
@@ -94,9 +94,11 @@ static inline bool_t vpmu_are_all_set(const struct vpmu_struct *vpmu,return !!((vpmu->flags & mask) == mask); } +#define VPMU_MSR_READ 0 +#define VPMU_MSR_WRITE 1 +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_msr (unsigned int msr,uint64_t *msr_content,int rw);int vpmu_do_interrupt (struct cpu_user_regs *regs);void vpmu_do_cpuid (unsigned int input,unsigned int *eax,unsigned int *ebx,unsigned int *ecx,unsigned int *edx);
Signature · 1 line
1.8.1.4
PATCH v9 17/20 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 | 92 +++++++++++++++++++++++++++++++++++------------- xen/arch/x86/traps.c | 11 ++++++ xen/include/public/pmu.h | 3 ++ 3 files changed, 81 insertions(+), 25 deletions(-)
xen/arch/x86/hvm/vpmu.c +67 -25
@@ -98,7 +98,9 @@ int vpmu_do_msr(unsigned int msr, uint64_t *msr_content, int rw)struct arch_vpmu_ops *ops = vpmu->arch_vpmu_ops;int ret =0 ; -if ( !(vpmu_mode &XENPMU_MODE_SELF ) ) +if ( (vpmu_mode ==XENPMU_MODE_OFF ) || + ((vpmu_mode &XENPMU_MODE_ALL ) && + !is_hardware_domain (current->domain)) )return 0 ; switch ( rw )
@@ -161,8 +163,12 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs)struct vcpu *sampled = current, *sampling;struct vpmu_struct *vpmu; -/* dom0 will handle interrupt for special domains (e.g. idle domain) */ -if ( sampled->domain->domain_id >=DOMID_FIRST_RESERVED ) +/* +* dom0 will handle interrupt for special domains (e.g. idle domain) or, +* in XENPMU_MODE_ALL, for everyone. +*/ +if ( (vpmu_mode &XENPMU_MODE_ALL ) || + (sampled->domain->domain_id >=DOMID_FIRST_RESERVED ) ) { sampling =choose_hwdom_vcpu ();if ( !sampling )
@@ -172,7 +178,7 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs) sampling = sampled; vpmu =vcpu_vpmu (sampling); -if ( !is_hvm_domain (sampling->domain) ) +if ( !is_hvm_domain (sampling->domain) || (vpmu_mode &XENPMU_MODE_ALL ) ) {/* PV(H) guest or dom0 is doing system profiling */ const struct cpu_user_regs *gregs;
@@ -184,6 +190,7 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs)return 1 ;if (is_pvh_domain (sampled->domain) && + !(vpmu_mode &XENPMU_MODE_ALL ) && !vpmu->arch_vpmu_ops->do_interrupt (regs) )return 0 ;
@@ -192,32 +199,65 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs) vpmu->arch_vpmu_ops->arch_vpmu_save (sampling);vpmu_reset (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ); -/* Store appropriate registers in xenpmu_data */ -if (is_pv_32bit_domain (sampled->domain) ) +if ( !is_hvm_domain (sampled->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 *)&vpmu->xenpmu_data->pmu.r.regs; -XLAT_cpu_user_regs (cmp, gregs); +/* Store appropriate registers in xenpmu_data */ +if (is_pv_32bit_domain (sampled->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 *)&vpmu->xenpmu_data->pmu.r.regs; +XLAT_cpu_user_regs (cmp, gregs); + +/* Adjust RPL for kernel mode */ +if ((cmp->cs &3 ) ==1 ) + cmp->cs &= ~3 ; + } +else if ( !is_hardware_domain (sampled->domain) && + !is_idle_vcpu (sampled) ) + { +/* 64-bit PV(H) unprivileged guest */ + gregs =guest_cpu_user_regs (); + vpmu->xenpmu_data->pmu.r.regs = *gregs; + } +else + vpmu->xenpmu_data->pmu.r.regs = *regs; + +if ( !is_pvh_domain (sampled->domain) ) + { +if ( sampled->arch.flags & TF_kernel_mode ) + sampling->arch.vpmu.xenpmu_data->pmu.r.regs.cs &= ~3 ; + } +else + { +struct segment_register seg_cs; + +hvm_get_segment_register (sampled, x86_seg_cs, &seg_cs); + sampling->arch.vpmu.xenpmu_data->pmu.r.regs.cs = seg_cs.sel; + } } -else if ( !is_hardware_domain (sampled->domain) && - !is_idle_vcpu (sampled) ) +else { -/* PV(H) guest */ +/* HVM guest */ +struct segment_register seg_cs; + gregs =guest_cpu_user_regs (); vpmu->xenpmu_data->pmu.r.regs = *gregs; + +hvm_get_segment_register (sampled, x86_seg_cs, &seg_cs); + sampling->arch.vpmu.xenpmu_data->pmu.r.regs.cs = seg_cs.sel; } -else - vpmu->xenpmu_data->pmu.r.regs = *regs; - vpmu->xenpmu_data->domain_id = sampled->domain->domain_id; + vpmu->xenpmu_data->domain_id = (sampled == sampling) ? +DOMID_SELF : + sampled->domain->domain_id; vpmu->xenpmu_data->vcpu_id = sampled->vcpu_id; vpmu->xenpmu_data->pcpu_id =smp_processor_id ();
@@ -569,7 +609,9 @@ 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.val & ~XENPMU_MODE_SELF ) +if ( (pmu_params.val & ~(XENPMU_MODE_SELF |XENPMU_MODE_ALL )) || + ((pmu_params.val &XENPMU_MODE_SELF ) && + (pmu_params.val &XENPMU_MODE_ALL )) )return -EINVAL ;/*
@@ -583,7 +625,7 @@ long do_xenpmu_op(int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg) current_mode = vpmu_mode; vpmu_mode = pmu_params.val; -if ( vpmu_mode ==XENPMU_MODE_OFF ) +if ( (vpmu_mode ==XENPMU_MODE_OFF ) || (vpmu_mode ==XENPMU_MODE_ALL ) ) {/* * Make sure all (non-dom0) VCPUs have unloaded their VPMUs. This
xen/arch/x86/traps.c +11 -0
@@ -2575,6 +2575,10 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)if ( vpmu_msr || ((boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) && !vpmu_msr) ) { +if ( (vpmu_mode &XENPMU_MODE_ALL ) && + !is_hardware_domain (v->domain) ) +break ; +if (vpmu_do_msr (regs->ecx, &msr_content,VPMU_MSR_WRITE ) ) goto fail;break ;
@@ -2698,6 +2702,13 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)if ( vpmu_msr || ((boot_cpu_data.x86_vendor !=X86_VENDOR_AMD ) && !vpmu_msr) ) { +if ( (vpmu_mode &XENPMU_MODE_ALL ) && + !is_hardware_domain (v->domain) ) + { +/* Don't leak PMU MSRs to unprivileged domains */ + regs->eax = regs->edx =0 ; +break ; + }if (vpmu_do_msr (regs->ecx, &msr_content,VPMU_MSR_READ ) ) goto fail;
xen/include/public/pmu.h +3 -0
@@ -50,9 +50,12 @@ DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t);* - XENPMU_MODE_OFF: No PMU virtualization * - XENPMU_MODE_SELF: Guests can profile themselves, dom0 profiles * itself and Xen +* - XENPMU_MODE_ALL: Only dom0 has access to VPMU and it profiles +* everyone: itself, the hypervisor and the guests. */ #define XENPMU_MODE_OFF 0#define XENPMU_MODE_SELF (1<<0) +#define XENPMU_MODE_ALL (1<<1)/* * PMU features:
Signature · 1 line
1.8.1.4
Re: [PATCH v9 17/20] x86/VPMU: Add privileged PMU mode
xen/arch/x86/hvm/vpmu.c int vpmu_do_interrupt(struct cpu_user_regs *regs) · line 202
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/hvm/vpmu.c +1
-2@@ -192,32 +199,65 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs) vpmu->arch_vpmu_ops->arch_vpmu_save (sampling);vpmu_reset (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ); -/* Store appropriate registers in xenpmu_data */ -if (is_pv_32bit_domain (sampled->domain) ) +if ( !is_hvm_domain (sampled->domain) )
I agree with using "sampled" here.
Quoted 4 lines
xen/arch/x86/hvm/vpmu.c +0
-3{ -/* -* 32-bit dom0 cannot process Xen's addresses (which are 64 bit) -* and therefore we treat it the same way as a non-priviledged
xen/arch/x86/hvm/vpmu.c int vpmu_do_interrupt(struct cpu_user_regs *regs) · line 205
Quoted 10 lines
xen/arch/x86/hvm/vpmu.c +2
-8-* PV 32-bit domain. -*/ -struct compat_cpu_user_regs *cmp; - - gregs =guest_cpu_user_regs (); - - cmp = (void *)&vpmu->xenpmu_data->pmu.r.regs; -XLAT_cpu_user_regs (cmp, gregs); +/* Store appropriate registers in xenpmu_data */ +if (is_pv_32bit_domain (sampled->domain) )
But why is this not "sampling"? The layout of the data you present should depend on the consumer of the data
xen/arch/x86/hvm/vpmu.c int vpmu_do_interrupt(struct cpu_user_regs *regs) · line 209
Quoted 4 lines
xen/arch/x86/hvm/vpmu.c +4
-0+ { +/* +* 32-bit dom0 cannot process Xen's addresses (which are 64 bit) +* and therefore we treat it the same way as a non-priviledged
non-privileged
xen/arch/x86/hvm/vpmu.c int vpmu_do_interrupt(struct cpu_user_regs *regs) · line 222
Quoted 13 lines
xen/arch/x86/hvm/vpmu.c +13
-0+* PV 32-bit domain. +*/ +struct compat_cpu_user_regs *cmp; + + gregs =guest_cpu_user_regs (); + + cmp = (void *)&vpmu->xenpmu_data->pmu.r.regs; +XLAT_cpu_user_regs (cmp, gregs); + +/* Adjust RPL for kernel mode */ +if ((cmp->cs &3 ) ==1 ) + cmp->cs &= ~3 ; + }
Jan
Re: [PATCH v9 17/20] x86/VPMU: Add privileged PMU mode
Quoted 10 lines · Jan Beulich
xen/arch/x86/hvm/vpmu.c int vpmu_do_interrupt(struct cpu_user_regs *regs) · line 202
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/hvm/vpmu.c +1
-2@@ -192,32 +199,65 @@ int vpmu_do_interrupt(struct cpu_user_regs *regs) vpmu->arch_vpmu_ops->arch_vpmu_save (sampling);vpmu_reset (vpmu,VPMU_CONTEXT_SAVE |VPMU_CONTEXT_LOADED ); -/* Store appropriate registers in xenpmu_data */ -if (is_pv_32bit_domain (sampled->domain) ) +if ( !is_hvm_domain (sampled->domain) )I agree with using "sampled" here.
Quoted 16 lines
Quoted 4 lines
xen/arch/x86/hvm/vpmu.c +0
-3{ -/* -* 32-bit dom0 cannot process Xen's addresses (which are 64 bit) -* and therefore we treat it the same way as a non-priviledged xen/arch/x86/hvm/vpmu.c int vpmu_do_interrupt(struct cpu_user_regs *regs) · line 205
Quoted 10 lines
xen/arch/x86/hvm/vpmu.c +2
-8-* PV 32-bit domain. -*/ -struct compat_cpu_user_regs *cmp; - - gregs =guest_cpu_user_regs (); - - cmp = (void *)&vpmu->xenpmu_data->pmu.r.regs; -XLAT_cpu_user_regs (cmp, gregs); +/* Store appropriate registers in xenpmu_data */ +if (is_pv_32bit_domain (sampled->domain) )But why is this not "sampling"? The layout of the data you present should depend on the consumer of the data
Right.
-boris
PATCH v9 18/20 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 | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
xen/arch/x86/domain.c +8 -10
@@ -1478,17 +1478,15 @@ 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_SELF ) ) +_update_runstate_area (prev); +if ( vpmu_mode &XENPMU_MODE_SELF )vpmu_save (prev); - -if ( !list_empty (&prev->arch.hvm_vcpu.tm_list) ) -pt_save_timer (prev); } +if (is_hvm_vcpu (prev) && !list_empty (&prev->arch.hvm_vcpu.tm_list) ) +pt_save_timer (prev); +local_irq_disable ();set_current (next);
@@ -1526,12 +1524,12 @@ void context_switch(struct vcpu *prev, struct vcpu *next) !is_hardware_domain(next->domain)); } -if (is_hvm_vcpu (next) && (prev != next) && (vpmu_mode &XENPMU_MODE_SELF ) ) +context_saved (prev); + +if ( (prev != next) && (vpmu_mode &XENPMU_MODE_SELF ) )/* Must be done with interrupts enabled */ vpmu_load (next); -context_saved (prev); -if ( prev != next )_update_runstate_area (next);
Signature · 1 line
1.8.1.4
Re: [PATCH v9 18/20] x86/VPMU: Save VPMU state for PV guests during context switch
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/domain.c +1
-1@@ -1526,12 +1524,12 @@ void context_switch(struct vcpu *prev, struct vcpu *next) !is_hardware_domain(next->domain)); } -if (is_hvm_vcpu (next) && (prev != next) && (vpmu_mode &XENPMU_MODE_SELF ) ) +context_saved (prev);
xen/arch/x86/domain.c void context_switch(struct vcpu *prev, struct vcpu *next) · line 1535
Quoted 10 lines
xen/arch/x86/domain.c +2
-2+ +if ( (prev != next) && (vpmu_mode &XENPMU_MODE_SELF ) )/* Must be done with interrupts enabled */ vpmu_load (next); -context_saved (prev); -if ( prev != next )_update_runstate_area (next);
While fine afaict, this re-ordering needs an explanation in the commit message (and not just in the overview mail).
Jan
PATCH v9 19/20 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 | 3 +- xen/arch/x86/hvm/vmx/vpmu_core2.c | 3 +- xen/arch/x86/hvm/vpmu.c | 192 +++++++++++++++++++++++++++++++------- xen/include/asm-x86/hvm/vpmu.h | 4 +- xen/include/xen/softirq.h | 1 + 5 files changed, 164 insertions(+), 39 deletions(-)
xen/arch/x86/hvm/svm/vpmu.c +2 -1
@@ -169,7 +169,7 @@ static void amd_vpmu_unset_msr_bitmap(struct vcpu *v)msr_bitmap_off (vpmu); } -static int amd_vpmu_do_interrupt (struct cpu_user_regs *regs) +static int amd_vpmu_do_interrupt (const struct cpu_user_regs *regs) {return 1 ; }
@@ -224,6 +224,7 @@ static inline void context_save(struct vcpu *v)rdmsrl (counters[i], counter_regs[i]); } +/* Must be NMI-safe */ static int amd_vpmu_save (struct vcpu *v) {struct vpmu_struct *vpmu =vcpu_vpmu (v);
xen/arch/x86/hvm/vmx/vpmu_core2.c +2 -1
@@ -300,6 +300,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);
@@ -710,7 +711,7 @@ static void core2_vpmu_dump(const struct vcpu *v) } } -static int core2_vpmu_do_interrupt (struct cpu_user_regs *regs) +static int core2_vpmu_do_interrupt (const struct cpu_user_regs *regs) {struct vcpu *v = current;u64 msr_content;
xen/arch/x86/hvm/vpmu.c +157 -35
299 lines not on this page · raw message
xen/include/asm-x86/hvm/vpmu.h +2 -2
@@ -41,7 +41,7 @@struct arch_vpmu_ops {int (*do_wrmsr)(unsigned int msr,uint64_t msr_content);int (*do_rdmsr)(unsigned int msr,uint64_t *msr_content); -int (*do_interrupt)(struct cpu_user_regs *regs); +int (*do_interrupt)(const struct cpu_user_regs *regs);void (*do_cpuid)(unsigned int input,unsigned int *eax,unsigned int *ebx,unsigned int *ecx,unsigned int *edx);
@@ -99,7 +99,7 @@ static inline bool_t vpmu_are_all_set(const struct vpmu_struct *vpmu,void vpmu_lvtpc_update (uint32_t val);int vpmu_do_msr (unsigned int msr,uint64_t *msr_content,int rw); -int vpmu_do_interrupt (struct cpu_user_regs *regs); +int vpmu_do_interrupt (const struct cpu_user_regs *regs);void vpmu_do_cpuid (unsigned int input,unsigned int *eax,unsigned int *ebx,unsigned int *ecx,unsigned int *edx);void vpmu_initialise (struct vcpu *v);
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.1.4
Re: [PATCH v9 19/20] x86/VPMU: NMI-based VPMU support
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
static void
__initparse_vpmu_param(char *s)
{xen/arch/x86/hvm/vpmu.c +8
-8-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_SELF ; +if (*s =='\0' ) +return ; + + do { + ss = strchr(s, ',');
xen/arch/x86/hvm/vpmu.c uint64_t __read_mostly vpmu_features = 0; · line 84
Quoted 10 lines
xen/arch/x86/hvm/vpmu.c +8
-1+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 :
This should be "default".
Quoted 6 lines
xen/arch/x86/hvm/vpmu.c +6
-0+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,"all" ) ) + {
xen/arch/x86/hvm/vpmu.c uint64_t __read_mostly vpmu_features = 0; · line 100
Quoted 10 lines
xen/arch/x86/hvm/vpmu.c +10
-0+ vpmu_mode &= ~XENPMU_MODE_SELF ; + vpmu_mode |=XENPMU_MODE_ALL ; + } +else + { +printk ("VPMU: unknown flag: %s - vpmu disabled!\n" , s); + vpmu_mode =XENPMU_MODE_OFF ; +return ; + } +default :
And this should be "case 1" and preceded by a fall-through comment.
xen/arch/x86/hvm/vpmu.c int vpmu_do_interrupt(struct cpu_user_regs *regs) · line 321
Quoted 8 lines
xen/arch/x86/hvm/vpmu.c +3
-1@@ -265,30 +316,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 (sampling,VIRQ_XENPMU ); +if ( vpmu_interrupt_type &APIC_DM_NMI ) + { +per_cpu (sampled_vcpu,smp_processor_id ()) = sampled;
Please use this_cpu() instead of kind of open-coding it (also again below, and who knows where else).
xen/arch/x86/hvm/vpmu.c void vpmu_destroy(struct vcpu *v) · line 556
Quoted 6 lines
xen/arch/x86/hvm/vpmu.c +1
-0static int pvpmu_init (struct domain *d,xen_pmu_params_t *params) {struct vcpu *v;struct page_info *page;uint64_t gfn = params->val; +static bool_t __read_mostly pvpmu_initted =0 ;
Pointless initializer. Also I think pvpmu_init_done would be a better name.
Quoted 10 lines
xen/arch/x86/hvm/vpmu.c +6
-0@@ -476,6 +578,26 @@ static int pvpmu_init(struct domain *d, xen_pmu_params_t *params)return -EINVAL ; } +spin_lock (&init_lock); + +if ( !pvpmu_initted ) + { +if (reserve_lapic_nmi () ==0 ) +set_nmi_callback (pmu_nmi_interrupt);
xen/arch/x86/hvm/vpmu.c static int pvpmu_init(struct domain *d, xen_pmu_params_t *params) · line 596
Quoted 10 lines
xen/arch/x86/hvm/vpmu.c +10
-0+else + { +spin_unlock (&init_lock); +printk (XENLOG_G_ERR "Failed to reserve PMU NMI\n" ); +put_page (page); +return -EBUSY ; + } +open_softirq (PMU_SOFTIRQ , pmu_softnmi); + + pvpmu_initted =1 ;
Consistency please: Either you have an if and an else branch, and each does all that is needed, or you have just an if branch ending in "return" and the else branch is implicit.
Jan
PATCH v9 20/20 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/vlapic.c | 2 +-
xen/arch/x86/hvm/vmx/Makefile | 1 -
xen/arch/x86/oprofile/op_model_ppro.c | 2 +-
xen/arch/x86/traps.c | 2 +-
xen/arch/x86/{hvm => }/vpmu.c | 4 ++--
xen/arch/x86/{hvm/svm/vpmu.c => vpmu_amd.c} | 2 +-
xen/arch/x86/{hvm/vmx/vpmu_core2.c => vpmu_intel.c} | 2 +-
xen/include/asm-x86/hvm/vmx/vmcs.h | 2 +-
xen/include/asm-x86/{hvm => }/vpmu.h | 0
12 files changed, 9 insertions(+), 11 deletions(-)
rename xen/arch/x86/{hvm => }/vpmu.c (99%)
rename xen/arch/x86/{hvm/svm/vpmu.c => vpmu_amd.c} (99%)
rename xen/arch/x86/{hvm/vmx/vpmu_core2.c => vpmu_intel.c} (99%)
rename xen/include/asm-x86/{hvm => }/vpmu.h (100%)xen/arch/x86/Makefile +1 -0
@@ -59,6 +59,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/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/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 renamed from xen/arch/x86/hvm/vpmu.c +2 -2
@@ -32,7 +32,7 @@#include <asm/hvm/support.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/vmx/vmcs.h> -#include <asm/hvm/vpmu.h> +#include <asm/vpmu.h> #include <asm/hvm/svm/svm.h> #include <asm/hvm/svm/vmcb.h> #include <asm/apic.h>
@@ -587,7 +587,7 @@ static int pvpmu_init(struct domain *d, xen_pmu_params_t *params)else {spin_unlock (&init_lock); -printk (XENLOG_G_ERR "Failed to reserve PMU NMI\n" ); +printk ("XENLOG_G_ERR Failed to reserve PMU NMI\n" );put_page (page);return -EBUSY ; }
xen/arch/x86/vpmu_amd.c renamed from xen/arch/x86/hvm/svm/vpmu.c +1 -1
@@ -29,7 +29,7 @@#include <xen/irq.h> #include <asm/apic.h> #include <asm/hvm/vlapic.h> -#include <asm/hvm/vpmu.h> +#include <asm/vpmu.h> #include <public/pmu.h> #define MSR_F10H_EVNTSEL_GO_SHIFT 40
xen/arch/x86/vpmu_intel.c renamed from xen/arch/x86/hvm/vmx/vpmu_core2.c +1 -1
@@ -37,7 +37,7 @@#include <public/sched.h> #include <public/hvm/save.h> #include <public/pmu.h> -#include <asm/hvm/vpmu.h> +#include <asm/vpmu.h> /* * See Intel SDM Vol 2a Instruction Set Reference chapter 3 for CPUID
xen/include/asm-x86/hvm/vmx/vmcs.h +1 -1
@@ -20,7 +20,7 @@#define __ASM_X86_HVM_VMX_VMCS_H__#include <asm/hvm/io.h> -#include <asm/hvm/vpmu.h> +#include <asm/vpmu.h> #include <irq_vectors.h> extern void vmcs_dump_vcpu (struct vcpu *v);
xen/include/asm-x86/vpmu.h renamed from xen/include/asm-x86/hvm/vpmu.h +0 -0
Signature · 1 line
1.8.1.4
Re: [PATCH v9 20/20] x86/VPMU: Move VPMU files up from hvm/ directory
xen/arch/x86/vpmu.c static int pvpmu_init(struct domain *d, xen_pmu_params_t *params) · line 590
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
xen/arch/x86/vpmu.c renamed from xen/arch/x86/hvm/vpmu.c +1
-1@@ -587,7 +587,7 @@ static int pvpmu_init(struct domain *d, xen_pmu_params_t *params)else {spin_unlock (&init_lock); -printk (XENLOG_G_ERR "Failed to reserve PMU NMI\n" ); +printk ("XENLOG_G_ERR Failed to reserve PMU NMI\n" );
Certainly not.
Jan
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 08.08.14 at 18:55, <[email protected]> wrote:
Here is the ninth version of PV(H) PMU patches.
Changes in v9:
Quoted 16 lines
* Restore VPMU context after
context_saved()is called incontext_switch(). This is needed becausevpmu_load()may end up calling vmx_vmcs_try_enter()->vcpu_pause() and that needsis_runningto be correctly set/cleared. (patch 18, dropped review acks)
* Added patch 2 to properly manageVPMU_CONTEXT_LOADED
* Addressed most of Jan's comments.
o Keep track of time invpmu_force_context_switch()to properly break out of a loop when using hypercall continuations
o Fixed logic in callingvpmu_do_msr()inemulate_privileged_op()
o Cleaned upvpmu_interrupt()wrt vcpu variable names to (hopefully) make it more clear which vcpu we are using
o Cleaned upvpmu_do_wrmsr()
o Did *not* replacesizeof(uint64_t)with sizeof(variable) inamd_vpmu_initialise(): throughout the code registers are declared asuint64_tand if we are to add a new type (e.g.reg_t) this should be done in a separate patch, unrelated to this series.
Suspicious, but I hopefully won't forget to comment on this when reaching the actual patch.
In any event, I think you continue to send this series to an incomplete list of people (possibly because you didn't update it after the initial version): Both SVM and VMX have one more maintainer than you Cc (Aravind and Eddie respectively; oddly enough you send the patch directly to two of the others).
Jan