Xen watchdog improvements
This series offers some improvements to Xen watchdogs.
Patch 1 moves the concept of a watchdog from x86 specific code to common. Patch 2 tweaks the x86 implementation, given the common implementation. Patch 3 is a bugfix for certain cases where the watchdog code interacts badly with console_force_unlock().
PATCH 1/3 xen/watchdog: Move watchdog from being x86 specific to common code.
Augment watchdog_setup() to be able to possibly return an error, and introduce watchdog_enabled() as a better alternative to knowing the architectures internal details.
This patch does not change the x86 implementaion, beyond making it compile.
For header files, some includes of xen/nmi.h were only for the watchdog functions, so are replaced rather than adding an extra include of xen/watchdog.h
--- xen/arch/x86/nmi.c | 8 +++++++- xen/arch/x86/setup.c | 1 + xen/arch/x86/shutdown.c | 2 +- xen/arch/x86/traps.c | 1 + xen/arch/x86/x86_64/traps.c | 1 + xen/common/kexec.c | 2 +- xen/common/keyhandler.c | 2 +- xen/common/shutdown.c | 2 +- xen/drivers/char/console.c | 2 +- xen/include/asm-x86/config.h | 1 + xen/include/asm-x86/nmi.h | 4 ---- xen/include/xen/watchdog.h | 35 +++++++++++++++++++++++++++++++++++ 12 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 xen/include/xen/watchdog.h
xen/arch/x86/nmi.c +7 -1
@@ -410,7 +410,12 @@ void watchdog_enable(void)atomic_dec (&watchdog_disable_count); } -void __init watchdog_setup (void ) +bool_t watchdog_enabled (void ) +{ +return !atomic_read (&watchdog_disable_count); +} + +int __init watchdog_setup (void ) {unsigned int cpu;
@@ -423,6 +428,7 @@ void __init watchdog_setup(void)register_cpu_notifier (&cpu_nmi_nfb);watchdog_enable (); +return 0 ; }void nmi_watchdog_tick (struct cpu_user_regs * regs)
xen/arch/x86/setup.c +1 -0
@@ -26,6 +26,7 @@#include <xen/pfn.h> #include <xen/nodemask.h> #include <xen/tmem_xen.h> /* for opt_tmem only */ +#include <xen/watchdog.h> #include <public/version.h> #include <compat/platform.h> #include <compat/xen.h>
xen/arch/x86/shutdown.c +1 -1
@@ -12,7 +12,7 @@#include <xen/delay.h> #include <xen/dmi.h> #include <xen/irq.h> -#include <xen/nmi.h> +#include <xen/watchdog.h> #include <xen/console.h> #include <xen/shutdown.h> #include <xen/acpi.h>
xen/arch/x86/traps.c +1 -0
@@ -49,6 +49,7 @@#include <xen/kexec.h> #include <xen/trace.h> #include <xen/paging.h> +#include <xen/watchdog.h> #include <asm/system.h> #include <asm/io.h> #include <asm/atomic.h>
xen/arch/x86/x86_64/traps.c +1 -0
@@ -13,6 +13,7 @@#include <xen/shutdown.h> #include <xen/nmi.h> #include <xen/guest_access.h> +#include <xen/watchdog.h> #include <asm/current.h> #include <asm/flushtlb.h> #include <asm/traps.h>
xen/common/kexec.c +1 -1
@@ -12,7 +12,7 @@#include <xen/ctype.h> #include <xen/errno.h> #include <xen/guest_access.h> -#include <xen/nmi.h> +#include <xen/watchdog.h> #include <xen/sched.h> #include <xen/types.h> #include <xen/hypercall.h>
xen/common/keyhandler.c +1 -1
@@ -16,7 +16,7 @@#include <xen/ctype.h> #include <xen/perfc.h> #include <xen/mm.h> -#include <xen/nmi.h> +#include <xen/watchdog.h> #include <xen/init.h> #include <asm/debugger.h> #include <asm/div64.h>
xen/common/shutdown.c +1 -1
@@ -4,7 +4,7 @@#include <xen/sched.h> #include <xen/domain.h> #include <xen/delay.h> -#include <xen/nmi.h> +#include <xen/watchdog.h> #include <xen/shutdown.h> #include <xen/console.h> #ifdef CONFIG_KEXEC
xen/drivers/char/console.c +1 -1
@@ -20,7 +20,7 @@#include <xen/keyhandler.h> #include <xen/delay.h> #include <xen/guest_access.h> -#include <xen/nmi.h> +#include <xen/watchdog.h> #include <xen/shutdown.h> #include <xen/video.h> #include <xen/kexec.h>
xen/include/asm-x86/config.h +1 -0
@@ -49,6 +49,7 @@#define CONFIG_XENOPROF 1#define CONFIG_KEXEC 1 +#define CONFIG_WATCHDOG 1#define HZ 100
xen/include/asm-x86/nmi.h +0 -4
@@ -41,8 +41,4 @@ long register_guest_nmi_callback(unsigned long address);*/ long unregister_guest_nmi_callback (void ); -void watchdog_disable (void ); -void watchdog_enable (void ); -void watchdog_setup (void ); -#endif /* ASM_NMI_H */
xen/include/xen/watchdog.h new file +35 -0
@@ -0,0 +1,35 @@ +/****************************************************************************** +* watchdog.h +* +* Common watchdog code +*/ + +#ifndef __XEN_WATCHDOG_H__ +#define __XEN_WATCHDOG_H__ + +#include <xen/types.h> + +#ifdef CONFIG_WATCHDOG + +/* Try to set up a watchdog. */ +int watchdog_setup (void ); + +/* Enable the watchdog. */ +void watchdog_enable (void ); + +/* Disable the watchdog. */ +void watchdog_disable (void ); + +/* Is the watchdog currently enabled. */ +bool_t watchdog_enabled (void ); + +#else + +#define watchdog_setup () ((void)0) +#define watchdog_enable () ((void)0) +#define watchdog_disable () ((void)0) +#define watchdog_enabled () ((void)0) + +#endif + +#endif /* __XEN_WATCHDOG_H__ */
Signature · 1 line
1.7.10.4
PATCH 2/3 x86/watchdog: Tweak implementation given new common code.
In reply to Andrew Cooper--- xen/arch/x86/nmi.c | 6 ++++-- xen/arch/x86/setup.c | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-)
xen/arch/x86/nmi.c +4 -2
@@ -419,6 +419,9 @@ int __init watchdog_setup(void) {unsigned int cpu; +if ( !opt_watchdog ) +return 0 ; +/* * Activate periodic heartbeats. We cannot do this earlier during * setup because the timer infrastructure is not available.
@@ -435,8 +438,7 @@ void nmi_watchdog_tick(struct cpu_user_regs * regs) {unsigned int sum =this_cpu (nmi_timer_ticks); -if ( (this_cpu (last_irq_sums) == sum) && - !atomic_read (&watchdog_disable_count) ) +if ( (this_cpu (last_irq_sums) == sum) &&watchdog_enabled () ) {/* * Ayiee, looks like this CPU is stuck ... wait for the timeout
xen/arch/x86/setup.c +1 -2
@@ -1310,8 +1310,7 @@ void __init __start_xen(unsigned long mbi_p)do_initcalls (); -if ( opt_watchdog ) -watchdog_setup (); +watchdog_setup ();if ( !tboot_protect_mem_regions () )panic ("Could not protect TXT memory regions\n" );
Signature · 1 line
1.7.10.4
Re: [PATCH 2/3] x86/watchdog: Tweak implementation given new common code.
xen/arch/x86/nmi.c int __init watchdog_setup(void) · line 427
Quoted 13 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
xen/arch/x86/nmi.c +3
-0@@ -419,6 +419,9 @@ int __init watchdog_setup(void) {unsigned int cpu; +if ( !opt_watchdog ) +return 0 ; +/* * Activate periodic heartbeats. We cannot do this earlier during * setup because the timer infrastructure is not available.
This and the last hunk below look pretty pointless, i.e. in fact the patch could consist of just the middle one.
Jan
Quoted 26 lines
xen/arch/x86/nmi.c +1
-2@@ -435,8 +438,7 @@ void nmi_watchdog_tick(struct cpu_user_regs * regs) {unsigned int sum =this_cpu (nmi_timer_ticks); -if ( (this_cpu (last_irq_sums) == sum) && - !atomic_read (&watchdog_disable_count) ) +if ( (this_cpu (last_irq_sums) == sum) &&watchdog_enabled () ) {/* * Ayiee, looks like this CPU is stuck ... wait for the timeout xen/arch/x86/setup.c +1
-2@@ -1310,8 +1310,7 @@ void __init __start_xen(unsigned long mbi_p)do_initcalls (); -if ( opt_watchdog ) -watchdog_setup (); +watchdog_setup ();if ( !tboot_protect_mem_regions () )panic ("Could not protect TXT memory regions\n" );Signature · 1 line
1.7.10.4
Re: [PATCH 2/3] x86/watchdog: Tweak implementation given new common code.
Quoted 16 lines · Jan Beulich
xen/arch/x86/nmi.c int __init watchdog_setup(void) · line 427
Quoted 13 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
xen/arch/x86/nmi.c +3
-0@@ -419,6 +419,9 @@ int __init watchdog_setup(void) {unsigned int cpu; +if ( !opt_watchdog ) +return 0 ; +/* * Activate periodic heartbeats. We cannot do this earlier during * setup because the timer infrastructure is not available. This and the last hunk below look pretty pointless, i.e. in fact the patch could consist of just the middle one.
Quoted 1 line
Jan
I had intended to do more with it, but it turned out I couldn't
I shall drop it down to just the middle hunk.
~Andrew
Quoted 29 lines
Quoted 27 lines
xen/arch/x86/nmi.c +1
-2@@ -435,8 +438,7 @@ void nmi_watchdog_tick(struct cpu_user_regs * regs) {unsigned int sum =this_cpu (nmi_timer_ticks); -if ( (this_cpu (last_irq_sums) == sum) && - !atomic_read (&watchdog_disable_count) ) +if ( (this_cpu (last_irq_sums) == sum) &&watchdog_enabled () ) {/* * Ayiee, looks like this CPU is stuck ... wait for the timeout xen/arch/x86/setup.c +1
-2@@ -1310,8 +1310,7 @@ void __init __start_xen(unsigned long mbi_p)do_initcalls (); -if ( opt_watchdog ) -watchdog_setup (); +watchdog_setup ();if ( !tboot_protect_mem_regions () )panic ("Could not protect TXT memory regions\n" );Signature · 1 line
1.7.10.4
PATCH v2 2/3 x86/watchdog: Tweak implementation given new common code.
---
Changes since v1:
* Drop functionally useless changes to watchdog_setup()
--- xen/arch/x86/nmi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/x86/nmi.c +1 -2
@@ -435,8 +435,7 @@ void nmi_watchdog_tick(struct cpu_user_regs * regs) {unsigned int sum =this_cpu (nmi_timer_ticks); -if ( (this_cpu (last_irq_sums) == sum) && - !atomic_read (&watchdog_disable_count) ) +if ( (this_cpu (last_irq_sums) == sum) &&watchdog_enabled () ) {/* * Ayiee, looks like this CPU is stuck ... wait for the timeout
Signature · 1 line
1.7.10.4
PATCH 3/3 watchdog/crash: Always disable watchdog in console_force_unlock()
In reply to Andrew CooperDepending on the state of the conring and serial_tx_buffer, console_force_unlock() can be a long running operation, usually because of serial_start_sync()
XenServer testing has found a reliable case where console_force_unlock() on one PCPU takes long enough for another PCPU to timeout due to the watchdog (such as waiting for a tlb flush callin).
The watchdog timeout causes the second PCPU to repeat the console_force_unlock(), at which point the first PCPU typically fails an assertion in spin_unlock_irqrestore(&port->tx_lock) (because the tx_lock has been unlocked behind itself).
console_force_unlock() is only on emergency paths, so one way or another the host is going down. Disable the watchdog before forcing the console lock to help prevent having pcpus completing with each other to bring the host down.
--- xen/arch/x86/x86_64/traps.c | 2 -- xen/drivers/char/console.c | 1 + 2 files changed, 1 insertion(+), 2 deletions(-)
xen/arch/x86/x86_64/traps.c +0 -2
@@ -227,8 +227,6 @@ void do_double_fault(struct cpu_user_regs *regs)unsigned int cpu;unsigned long crs[8 ]; -watchdog_disable (); -console_force_unlock (); asm ("lsll %1, %0" :"=r" (cpu) :"rm" (PER_CPU_GDT_ENTRY <<3 ) );
xen/drivers/char/console.c +1 -0
@@ -737,6 +737,7 @@ void console_end_log_everything(void)void console_force_unlock (void ) { +watchdog_disable ();spin_lock_init (&console_lock);serial_force_unlock (sercon_handle); console_locks_busted =1 ;
Signature · 1 line
1.7.10.4
Hi Andrew,
What's the Watchdog used for in Xen?
Josh
2013/8/12 Andrew Cooper <[email protected]>
Quoted 13 lines
This series offers some improvements to Xen watchdogs.
Patch 1 moves the concept of a watchdog from x86 specific code to common. Patch 2 tweaks the x86 implementation, given the common implementation. Patch 3 is a bugfix for certain cases where the watchdog code interacts badly with
console_force_unlock().Signed-off-by Andrew Cooper <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>CC Tim Deegan <[email protected]>
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 4 lines · Josh Zhao
Hi Andrew,
What's the Watchdog used for in Xen?Josh
Xen can set up a hardware watchdog on each pcpu, to help ensure that it doesn't get stuck in loops. It is extra defence against bugs in Xen.
~Andrew
Quoted 21 lines
2013/8/12 Andrew Cooper <[email protected] <mailto:[email protected]>>
This series offers some improvements to Xen watchdogs.
Patch 1 moves the concept of a watchdog from x86 specific code to common.
Patch 2 tweaks the x86 implementation, given the common implementation.
Patch 3 is a bugfix for certain cases where the watchdog code interacts badly with
console_force_unlock().Signed-off-by Andrew Cooper <[email protected]<mailto:[email protected]>>
CC: Keir Fraser <[email protected] <mailto:[email protected]>>
CC: Jan Beulich <[email protected] <mailto:[email protected]>>
CC: Tim Deegan <[email protected] <mailto:[email protected]>>
Quoted 6 lines
_______________________________________________
Xen-devel mailing list
[email protected] <mailto:[email protected]>
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Jan Beulich
Reviewed-byQuoted 10 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
This series offers some improvements to Xen watchdogs.
Patch 1 moves the concept of a watchdog from x86 specific code to common. Patch 2 tweaks the x86 implementation, given the common implementation. Patch 3 is a bugfix for certain cases where the watchdog code interacts badly with
console_force_unlock().Signed-off-by Andrew Cooper <[email protected]>
Pending clarification on the need of the two apparently pointless hunks in patch 2:
Keir Fraser
Acked-byQuoted 8 lines · Andrew Cooper
This series offers some improvements to Xen watchdogs.
Patch 1 moves the concept of a watchdog from x86 specific code to common. Patch 2 tweaks the x86 implementation, given the common implementation. Patch 3 is a bugfix for certain cases where the watchdog code interacts badly with
console_force_unlock().
Quoted 4 lines
Signed-off-by Andrew Cooper <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>CC Tim Deegan <[email protected]>
With v2 of patch 2: