A few VPMU/watchdog-related patches
v3 cover A few VPMU/watchdog-related patches
Changes in v3:
* Moved opt_watchdog check into initcall
Changes in v2:
* Added NMI cleanup patch
* Disaple VPMU in vpmu_initialise() instead of doing it in options parsing routines
* Update documentation by mentioning that VPMU doesn't work with watchdog
* Drop some sign-off area tags
The first patch is a light cleanup of nmi_watchdog usage.
The second patch is to disable VPMU when watchdog is on since both are using APIC_LVTPC register and VPMU, when running, will overwrite watchdog's settings.
The last patch is update to the earlier (reverted) commit 8097616. We prevent guests's updates to APIC_LVTPC when VPMU is disabled. Without this a guest may redirect a watchdog interrupt to VPMU which will not be able to handle it.
Boris Ostrovsky (3):
x86/nmi: Cleanup usage of nmi_watchdog
x86/VPMU: Disable VPMU when NMI watchdog is on
x86/VPMU: Handle APIC_LVTPC accesses
docs/misc/xen-command-line.markdown | 2 ++ xen/arch/x86/hvm/svm/vpmu.c | 4 ---- xen/arch/x86/hvm/vlapic.c | 3 +++ xen/arch/x86/hvm/vmx/vpmu_core2.c | 17 ----------------- xen/arch/x86/hvm/vpmu.c | 26 ++++++++++++++++++++++++++ xen/arch/x86/nmi.c | 4 ++-- xen/arch/x86/traps.c | 3 ++- xen/include/asm-x86/apic.h | 1 - xen/include/asm-x86/hvm/vpmu.h | 1 + 9 files changed, 36 insertions(+), 25 deletions(-)
Signature · 1 line
1.8.1.4
PATCH v3 1/3 x86/nmi: Cleanup usage of nmi_watchdog
Use NMI_NONE when testing whether NMI watchdog is off.
Remove unused NMI_INVALID macro.
--- xen/arch/x86/nmi.c | 4 ++-- xen/arch/x86/traps.c | 3 ++- xen/include/asm-x86/apic.h | 1 - 3 files changed, 4 insertions(+), 4 deletions(-)
xen/arch/x86/nmi.c +2 -2
@@ -148,7 +148,7 @@ int __init check_nmi_watchdog (void)int cpu;bool_t ok =1 ; -if ( !nmi_watchdog ) +if ( nmi_watchdog ==NMI_NONE )return 0 ;printk ("Testing NMI watchdog on all CPUs:" );
@@ -361,7 +361,7 @@ static int __pminit setup_p4_watchdog(void) void __pminit setup_apic_nmi_watchdog(void) { -if (!nmi_watchdog) +if ( nmi_watchdog ==NMI_NONE )return ;switch (boot_cpu_data.x86_vendor) {
xen/arch/x86/traps.c +2 -1
@@ -3385,7 +3385,8 @@ void do_nmi(const struct cpu_user_regs *regs)if (nmi_callback (regs, cpu) )return ; -if ( !nmi_watchdog || (!nmi_watchdog_tick (regs) && watchdog_force) ) +if ( (nmi_watchdog ==NMI_NONE ) || + (!nmi_watchdog_tick (regs) && watchdog_force) ) handle_unknown =1 ;/* Only the BSP gets external NMIs from the system. */
xen/include/asm-x86/apic.h +0 -1
@@ -221,7 +221,6 @@ extern unsigned int nmi_watchdog;#define NMI_NONE 0#define NMI_IO_APIC 1#define NMI_LOCAL_APIC 2 -#define NMI_INVALID 3#else /* !CONFIG_X86_LOCAL_APIC */ static inline int lapic_suspend (void ) {return 0 ;}
Signature · 1 line
1.8.1.4
Re: [PATCH v3 1/3] x86/nmi: Cleanup usage of nmi_watchdog
Quoted 5 lines · Boris Ostrovsky
Use
NMI_NONEwhen testing whether NMI watchdog is off.Remove unused
NMI_INVALIDmacro.Signed-off-by Boris Ostrovsky <[email protected]>
Quoted 54 lines
--- xen/arch/x86/nmi.c | 4 ++-- xen/arch/x86/traps.c | 3 ++- xen/include/asm-x86/apic.h | 1 - 3 files changed, 4 insertions(+), 4 deletions(-)xen/arch/x86/nmi.c +2
-2@@ -148,7 +148,7 @@ int __init check_nmi_watchdog (void)int cpu;bool_t ok =1 ; -if ( !nmi_watchdog ) +if ( nmi_watchdog ==NMI_NONE )return 0 ;printk ("Testing NMI watchdog on all CPUs:" );@@ -361,7 +361,7 @@ static int __pminit setup_p4_watchdog(void) void __pminit setup_apic_nmi_watchdog(void) { -if (!nmi_watchdog) +if ( nmi_watchdog ==NMI_NONE )return ;switch (boot_cpu_data.x86_vendor) {xen/arch/x86/traps.c +2
-1@@ -3385,7 +3385,8 @@ void do_nmi(const struct cpu_user_regs *regs)if (nmi_callback (regs, cpu) )return ; -if ( !nmi_watchdog || (!nmi_watchdog_tick (regs) && watchdog_force) ) +if ( (nmi_watchdog ==NMI_NONE ) || + (!nmi_watchdog_tick (regs) && watchdog_force) ) handle_unknown =1 ;/* Only the BSP gets external NMIs from the system. */ xen/include/asm-x86/apic.h +0
-1@@ -221,7 +221,6 @@ extern unsigned int nmi_watchdog;#define NMI_NONE 0#define NMI_IO_APIC 1#define NMI_LOCAL_APIC 2 -#define NMI_INVALID 3#else /* !CONFIG_X86_LOCAL_APIC */ static inline int lapic_suspend (void ) {return 0 ;}
PATCH v3 2/3 x86/VPMU: Disable VPMU when NMI watchdog is on
In reply to Boris OstrovskyNMI watchdog sets APIC_LVTPC register to generate an NMI when PMU counter overflow occurs. This may be overwritten by VPMU code later, effectively turning off the watchdog.
We should disable VPMU when NMI watchdog is running.
--- docs/misc/xen-command-line.markdown | 2 ++ xen/arch/x86/hvm/vpmu.c | 13 +++++++++++++ 2 files changed, 15 insertions(+)
docs/misc/xen-command-line.markdown +2 -0
@@ -1346,6 +1346,8 @@ wrong behaviour (see handle\_pmc\_quirk()). If 'vpmu=bts' is specified the virtualisation of the Branch Trace Store (BTS) feature is switched on on Intel processors supporting this feature. +Note that if **watchdog** option is also specified vpmu will be turned off. + *Warning:* As the BTS virtualisation is not 100% safe and because of the nehalem quirk don't use the vpmu flag on production systems with Intel cpus!
xen/arch/x86/hvm/vpmu.c +13 -0
@@ -24,6 +24,7 @@#include <asm/regs.h> #include <asm/types.h> #include <asm/msr.h> +#include <asm/nmi.h> #include <asm/hvm/support.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/vmx/vmcs.h>
@@ -288,3 +289,15 @@ void vpmu_dump(struct vcpu *v) vpmu->arch_vpmu_ops->arch_vpmu_dump (v); } +static int __init vpmu_init (void ) +{ +/* NMI watchdog uses LVTPC and HW counter */ +if ( opt_watchdog && opt_vpmu_enabled ) + { +printk (XENLOG_WARNING "NMI watchdog is enabled. Turning VPMU off.\n" ); + opt_vpmu_enabled =0 ; + } + +return 0 ; +} +__initcall (vpmu_init);
Signature · 1 line
1.8.1.4
Re: [PATCH v3 2/3] x86/VPMU: Disable VPMU when NMI watchdog is on
Quoted 7 lines · Boris Ostrovsky
NMI watchdog sets
APIC_LVTPCregister to generate an NMI when PMU counter overflow occurs. This may be overwritten by VPMU code later, effectively turning off the watchdog.We should disable VPMU when NMI watchdog is running.
Signed-off-by Boris Ostrovsky <[email protected]>
Quoted 46 lines
--- docs/misc/xen-command-line.markdown | 2 ++ xen/arch/x86/hvm/vpmu.c | 13 +++++++++++++ 2 files changed, 15 insertions(+)docs/misc/xen-command-line.markdown +2
-0@@ -1346,6 +1346,8 @@ wrong behaviour (see handle\_pmc\_quirk()). If 'vpmu=bts' is specified the virtualisation of the Branch Trace Store (BTS) feature is switched on on Intel processors supporting this feature. +Note that if **watchdog** option is also specified vpmu will be turned off. + *Warning:* As the BTS virtualisation is not 100% safe and because of the nehalem quirk don't use the vpmu flag on production systems with Intel cpus!xen/arch/x86/hvm/vpmu.c +13
-0@@ -24,6 +24,7 @@#include <asm/regs.h> #include <asm/types.h> #include <asm/msr.h> +#include <asm/nmi.h> #include <asm/hvm/support.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/vmx/vmcs.h> @@ -288,3 +289,15 @@ void vpmu_dump(struct vcpu *v) vpmu->arch_vpmu_ops->arch_vpmu_dump (v); } +static int __init vpmu_init (void ) +{ +/* NMI watchdog uses LVTPC and HW counter */ +if ( opt_watchdog && opt_vpmu_enabled ) + { +printk (XENLOG_WARNING "NMI watchdog is enabled. Turning VPMU off.\n" ); + opt_vpmu_enabled =0 ; + } + +return 0 ; +} +__initcall (vpmu_init);
PATCH v3 3/3 x86/VPMU: Handle APIC_LVTPC accesses
In reply to Boris OstrovskyDon't have the hypervisor update APIC_LVTPC when _it_ thinks the vector should be updated. Instead, handle guest's APIC_LVTPC accesses and write what the guest explicitly wanted (but only when VPMU is enabled).
This is updated version of commit 8097616fbdda that was reverted by cc3404093c85. Unlike the previous version, we don't update APIC_LVTPC when VPMU is disabled to avoid interfering with NMI watchdog (which runs only when VPMU is off).
--- xen/arch/x86/hvm/svm/vpmu.c | 4 ---- xen/arch/x86/hvm/vlapic.c | 3 +++ xen/arch/x86/hvm/vmx/vpmu_core2.c | 17 ----------------- xen/arch/x86/hvm/vpmu.c | 13 +++++++++++++ xen/include/asm-x86/hvm/vpmu.h | 1 + 5 files changed, 17 insertions(+), 21 deletions(-)
xen/arch/x86/hvm/svm/vpmu.c +0 -4
@@ -302,8 +302,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_vcpu (v) && !((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set )
@@ -314,8 +312,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_vcpu (v) && ((struct amd_vpmu_context *)vpmu->context)->msr_bitmap_set )
xen/arch/x86/hvm/vlapic.c +3 -0
@@ -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>
@@ -777,6 +778,8 @@ static int vlapic_reg_write(struct vcpu *v, }if ( (offset ==APIC_LVTT ) && !(val &APIC_LVT_MASKED ) )pt_may_unmask_irq (NULL , &vlapic->pt); +if ( offset ==APIC_LVTPC ) +vpmu_lvtpc_update (val);break ;case APIC_TMICT :
xen/arch/x86/hvm/vmx/vpmu_core2.c +0 -17
@@ -519,19 +519,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;
@@ -697,10 +684,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 +13 -0
@@ -65,6 +65,19 @@ static void __init parse_vpmu_param(char *s) } } +void vpmu_lvtpc_update (uint32_t val) +{ +struct vpmu_struct *vpmu; + +if ( !opt_vpmu_enabled ) +return ; + + 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,uint64_t supported) {struct vpmu_struct *vpmu =vcpu_vpmu (current);
xen/include/asm-x86/hvm/vpmu.h +1 -0
@@ -104,6 +104,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,uint64_t supported);int vpmu_do_rdmsr (unsigned int msr,uint64_t *msr_content);void vpmu_do_interrupt (struct cpu_user_regs *regs);
Signature · 1 line
1.8.1.4