Xen paravirtual watchdog device [0/4]
Hi all,
As I've previously mentioned, I've been tinkering with a Xen-based virtual watchdog device and I think it's about time I put out some patches for discussion. The principle of the watchdog device is to provide a simple, high-assurance watchdog to domains running on Xen. The goal is to give better assurance than an in-kernel software watchdog.
The patches were developed for 2.6.16.33, but I've done what fixups I could see were necessary to make them apply against tip but I still need to test it works there correctly. I'm primarily just putting these out here for people to eyeball and argue about, but if you do try them out please let me know how you get on.
Under Linux, a watchdog daemon is typically run in userspace. This talks to the watchdog device driver through /dev/watchdog, which is responsible for resetting the timeout on the watchdog device whenever the daemon kicks it. The reliance on the userspace daemon ensures that scheduling, etc, is still occurring correctly in the system, and makes it easy for different functionality to be implemented on top of the basic watchdog feature.
The XenLinux watchdog driver sets up the in-Xen watchdog for the current domain using a simple hypercall interface. The watchdog timer is implemented within Xen itself, isolating it from any guest bugs that might take out a normal software watchdog. Standard interfaces to userspace are supported so that any watchdog-aware software should be able to interact with it without modification.
The patchset also includes some watchdog-awareness enhancements for the dom0 toolset (more of these are possible in the future).
Comments, questions, abuse, anyone?
Cheers,
Mark
Signature · 4 lines
Dave: Just a question. What use is a unicyle with no seat? And no pedals! Mark: To answer a question with a question: What use is a skateboard? Dave: Skateboards have wheels. Mark: My wheel has a wheel!
RFC 1/1 Xen paravirtual watchdog device [1/4]
Add Kconfig configuration option for watchdog.
Cheers,
Mark
Signature · 4 lines
Dave: Just a question. What use is a unicyle with no seat? And no pedals! Mark: To answer a question with a question: What use is a skateboard? Dave: Skateboards have wheels. Mark: My wheel has a wheel!
linux-2.6-xen-sparse/drivers/xen/Kconfig +11 -0
@@ -195,6 +195,17 @@ config XEN_KEYBOARD domain. If you've said Y to CONFIG_XEN_FRAMEBUFFER, you probably want to say Y here. +config XEN_WATCHDOG + tristate "Xen Watchdog device support" + depends on XEN + default y + help + The Xen watchdog is a software implementation of a watchdog device, + provided by the Xen hypervisor. It will be able to reboot the guest + operating system even if the OS kernel itself is completely + non-functional and therefore offers greater assurance than the Linux + software watchdog. + config XEN_SCRUB_PAGES bool "Scrub memory before freeing it to Xen" default y
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
RFC 1/1 Xen paravirtual watchdog device [2/4]
In reply to Mark WilliamsonXenLinux driver for Xen virtual watchdog device.
This is based on the Linux softdog driver, but features slightly more functionality and omits all the internal timer logic since it has moved to Xen.
Cheers,
Mark
Signature · 4 lines
Dave: Just a question. What use is a unicyle with no seat? And no pedals! Mark: To answer a question with a question: What use is a skateboard? Dave: Skateboards have wheels. Mark: My wheel has a wheel!
linux-2.6-xen-sparse/drivers/xen/Makefile +1 -0
@@ -18,3 +18,4 @@ obj-$(CONFIG_XEN_PCIDEV_BACKEND) += pcib obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += pcifront/ obj-$(CONFIG_XEN_FRAMEBUFFER) += fbfront/ obj-$(CONFIG_XEN_KEYBOARD) += fbfront/ +obj-$(CONFIG_XEN_WATCHDOG) += watchdog/
linux-2.6-xen-sparse/drivers/xen/watchdog/Makefile +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_XEN_WATCHDOG) := xen_watchdog.o
linux-2.6-xen-sparse/drivers/xen/watchdog/xen_watchdog.c +409 -0
409 lines not on this page · raw message
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h +5 -1
@@ -402,6 +402,10 @@ HYPERVISOR_kexec_op( return _hypercall2(int, kexec_op, op, args); } - +static inline int +HYPERVISOR_watchdog_op (unsigned long cmd,void *arg) +{ +return _hypercall2 (int, watchdog_op, cmd, arg); +}#endif /* __HYPERCALL_H__ */
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypervisor.h +1 -0
@@ -43,6 +43,7 @@#include <xen/interface/physdev.h> #include <xen/interface/sched.h> #include <xen/interface/nmi.h> +#include <xen/interface/watchdog.h> #include <asm/ptrace.h> #include <asm/page.h> #if defined(__i386__)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
RFC 1/1 Xen paravirtual watchdog device [3/4]
In reply to Mark WilliamsonTools support for the virtual watchdog device.
Currently, this is used to support some extra status information for the guest, which may be useful in some circumstances. The tools could usefully be extended to have more interaction with the watchdog for management purposes.
Cheers,
Mark
Signature · 4 lines
Dave: Just a question. What use is a unicyle with no seat? And no pedals! Mark: To answer a question with a question: What use is a skateboard? Dave: Skateboards have wheels. Mark: My wheel has a wheel!
tools/libxc/xc_domain.c +48 -0
@@ -9,6 +9,7 @@#include "xc_private.h" #include <xen/memory.h> #include <xen/hvm/hvm_op.h> +#include <xen/watchdog.h> int xc_domain_create(int xc_handle, uint32_t ssidref,
@@ -696,6 +697,53 @@ int xc_get_hvm_param(int handle, domid_treturn rc; } + + + +int xc_query_watchdog (int xc_handle,uint32_t domid, +unsigned long *timeout,uint64_t *features,uint64_t *status) +{ +DECLARE_HYPERCALL ; +xen_query_watchdog_op_t q_op; +int ret; + + hypercall.op = __HYPERVISOR_watchdog_op; + hypercall.arg[0 ] =XEN_WATCHDOG_CMD_QUERY ; + hypercall.arg[1 ] = (unsigned long )&q_op; + + q_op.domid = domid; + + ret =do_xen_hypercall (xc_handle, &hypercall); + +if ( ret !=0 ) +return ret; + + *timeout = q_op.timeout; + *features = q_op.features; + *status = q_op.status; + +return 0 ; +} + +int xc_set_watchdog (int xc_handle,uint32_t domid,u64 status) +{ +DECLARE_HYPERCALL ; +xen_set_watchdog_op_t s_op; +int ret; + + hypercall.op = __HYPERVISOR_watchdog_op; + hypercall.arg[0 ] =XEN_WATCHDOG_CMD_SET ; + hypercall.arg[1 ] = (unsigned long )&s_op; + + s_op.domid = domid; + s_op.status = status; + + ret =do_xen_hypercall (xc_handle, &hypercall); + +return ret; +} + +/* * Local variables: * mode: C
tools/libxc/xenctrl.h +8 -0
@@ -29,6 +29,8 @@#include <xen/acm.h> #include <xen/acm_ops.h> +typedef uint64_t u64 ;/* MAW: this is a bit gross, anyone know a better way? */ +#ifdef __ia64__#define XC_PAGE_SHIFT 14#else
@@ -528,6 +530,12 @@ int xc_domain_iomem_permission(int xc_haunsigned long nr_mfns, uint8_t allow_access); +int xc_query_watchdog (int xc_handle,uint32_t domid, +unsigned long *timeout,uint64_t *features, +uint64_t *status); + +int xc_set_watchdog (int xc_handle,uint32_t domid,uint64_t status); +unsigned long xc_make_page_below_4G (int xc_handle,uint32_t domid,unsigned long mfn);
tools/python/xen/lowlevel/xc/xc.c +25 -0
@@ -19,6 +19,7 @@#include "xenctrl.h" #include <xen/elfnote.h> +#include <xen/watchdog.h> #include "xc_dom.h" #include <xen/hvm/hvm_info_table.h> #include <xen/hvm/params.h>
@@ -1077,6 +1078,23 @@ static PyObject *pyxc_domain_send_triggereturn zero; } +static PyObject *pyxc_domain_watchdog_set_lastboot (XcObject *self,PyObject *args) +{ +int bool; +uint32_t dom; + +if (!PyArg_ParseTuple (args,"ii" , &dom, &bool)) +return NULL ; + +if (xc_set_watchdog (self->xc_handle, dom, bool ?XEN_WATCHDOG_LASTBOOT :0 ) !=0 ) +return pyxc_error_to_exception (); + +Py_INCREF (zero); +return zero; +} + + +static PyObject *pyxc_send_debug_keys (XcObject *self,PyObject *args,PyObject *kwds)
@@ -1488,6 +1506,13 @@ static PyMethodDef pyxc_methods[] = {" trigger [int]: Trigger type number.\n" " vcpu [int]: VCPU to be sent trigger.\n" "Returns: [int] 0 on success; -1 on error.\n" }, + { "domain_watchdog_set_lastboot", + (PyCFunction )pyxc_domain_watchdog_set_lastboot, +METH_VARARGS |METH_KEYWORDS ,"\n" +"Set a domain's lastboot watchdog flag\n" +" dom [int]: Domain whose watchdog flag is to be set\n" +" val [bool]: Whether the flag should be set true or false.\n" + "Returns: [int] 0 on success; -1 on error.\n"}, { "send_debug_keys", (PyCFunction)pyxc_send_debug_keys,
tools/python/xen/xend/XendAPI.py +8 -2
@@ -1161,6 +1161,7 @@ class XendAPI(object): 'actions_after_reboot', 'actions_after_suspend', 'actions_after_crash', + 'actions_after_watchdog', 'PV_bootloader', 'PV_kernel', 'PV_ramdisk',
@@ -1221,6 +1222,7 @@ class XendAPI(object): 'actions_after_reboot', 'actions_after_suspend', 'actions_after_crash', + 'actions_after_watchdog', 'PV_bootloader', 'PV_kernel', 'PV_ramdisk',
@@ -1338,6 +1340,10 @@ class XendAPI(object): dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_on_crash()) + def VM_get_actions_after_watchdog(self, session, vm_ref): + dom = XendDomain.instance().get_vm_by_uuid(vm_ref) + return xen_api_success(dom.get_on_crash()) + def VM_get_PV_bootloader(self, session, vm_ref): return self.VM_get('PV_bootloader', session, vm_ref)
@@ -1515,12 +1521,11 @@ class XendAPI(object): return self.VM_set('HVM_boot_params', session, vm_ref, value) def VM_add_to_HVM_boot_params(self, session, vm_ref, key, value): - dom = XendDomain.instance().get_vm_by_uuid(vm_ref) if 'HVM_boot_params' not in dom.info: dom.info['HVM_boot_params'] = {} dom.info['HVM_boot_params'][key] = value return self._VM_save(dom) - + return xen_api_todo() def VM_remove_from_HVM_boot_params(self, session, vm_ref, key): dom = XendDomain.instance().get_vm_by_uuid(vm_ref) if 'HVM_boot_params' in dom.info \
@@ -1631,6 +1636,7 @@ class XendAPI(object): 'actions_after_reboot': xeninfo.get_on_reboot(), 'actions_after_suspend': xeninfo.get_on_suspend(), 'actions_after_crash': xeninfo.get_on_crash(), + 'actions_after_watchdog': xeninfo.get_on_watchdog(), 'consoles': xeninfo.get_consoles(), 'VIFs': xeninfo.get_vifs(), 'VBDs': xeninfo.get_vbds(),
tools/python/xen/xend/XendConfig.py +8 -2
@@ -110,6 +110,7 @@ XENAPI_CFG_TO_LEGACY_CFG = { 'actions_after_shutdown': 'on_poweroff', 'actions_after_reboot': 'on_reboot', 'actions_after_crash': 'on_crash', + 'actions_after_watchdog': 'on_watchdog', 'PV_bootloader': 'bootloader', 'PV_bootloader_args': 'bootloader_args', }
@@ -146,6 +147,7 @@ XENAPI_CFG_TYPES = { 'actions_after_shutdown': str, 'actions_after_reboot': str, 'actions_after_crash': str, + 'actions_after_watchdog': str, 'PV_bootloader': str, 'PV_kernel': str, 'PV_ramdisk': str,
@@ -201,6 +203,7 @@ LEGACY_CFG_TYPES = { 'on_poweroff': str, 'on_reboot': str, 'on_crash': str, + 'on_watchdog': str, 'on_xend_stop': str, 'on_xend_start': str, 'online_vcpus': int,
@@ -223,6 +226,7 @@ LEGACY_XENSTORE_VM_PARAMS = [ 'on_poweroff', 'on_crash', 'on_reboot', + 'on_watchdog', 'on_xend_start', 'on_xend_stop', ]
@@ -301,6 +305,7 @@ class XendConfig(dict): 'actions_after_crash': 'restart', 'actions_after_suspend': '', 'is_a_template': False, + 'actions_after_watchdog': 'restart', 'is_control_domain': False, 'features': '', 'PV_bootloader': '',
@@ -464,11 +469,12 @@ class XendConfig(dict): cfg['on_poweroff'] = 'destroy' cfg['on_reboot'] = 'restart' cfg['on_crash'] = 'destroy' + cfg['on_watchdog'] = 'restart' elif restart == 'always': - for opt in ('on_poweroff', 'on_reboot', 'on_crash'): + for opt in ('on_poweroff', 'on_reboot', 'on_crash', 'on_watchdog'): cfg[opt] = 'restart' elif restart == 'never': - for opt in ('on_poweroff', 'on_reboot', 'on_crash'): + for opt in ('on_poweroff', 'on_reboot', 'on_crash', 'on_watchdog'): cfg[opt] = 'never' else: log.warn('Ignoring unrecognised value for deprecated option:'
tools/python/xen/xend/XendConstants.py +3 -1
@@ -26,13 +26,15 @@ DOMAIN_REBOOT = 1 DOMAIN_SUSPEND = 2 DOMAIN_CRASH = 3 DOMAIN_HALT = 4 +DOMAIN_WATCHDOG = 5 DOMAIN_SHUTDOWN_REASONS = { DOMAIN_POWEROFF: "poweroff", DOMAIN_REBOOT : "reboot", DOMAIN_SUSPEND : "suspend", DOMAIN_CRASH : "crash", - DOMAIN_HALT : "halt" + DOMAIN_HALT : "halt", + DOMAIN_WATCHDOG : "watchdog" } REVERSE_DOMAIN_SHUTDOWN_REASONS = \ dict([(y, x) for x, y in DOMAIN_SHUTDOWN_REASONS.items()])
tools/python/xen/xend/XendDomainInfo.py +21 -1
@@ -367,6 +367,8 @@ class XendDomainInfo: self.state_updated = threading.Condition() self.refresh_shutdown_lock = threading.Condition() self._stateSet(DOM_STATE_HALTED) + if not info.has_key('watchdog_lastboot'): + self.info['watchdog_lastboot'] = False self._deviceControllers = {}
@@ -871,7 +873,7 @@ class XendDomainInfo: # Check whether values in the configuration have # changed in Xenstore. - cfg_vm = ['name', 'on_poweroff', 'on_reboot', 'on_crash', + cfg_vm = ['name', 'on_poweroff', 'on_reboot', 'on_crash', 'on_watchdog', 'rtc/timeoffset'] vm_details = self._readVMDetails([(k,XendConfig.LEGACY_CFG_TYPES[k])
@@ -1103,9 +1105,12 @@ class XendDomainInfo: else: reason = shutdown_reason(xeninfo['shutdown_reason']) + log.info log.info('Domain has shutdown: name=%s id=%d reason=%s.', self.info['name_label'], self.domid, reason) + + # Set the domain's watchdog / lastreboot flag here, if appropriate. self._writeVm(LAST_SHUTDOWN_REASON, reason) self._clearRestart()
@@ -1118,6 +1123,10 @@ class XendDomainInfo: # watch for the old domain, and one for the new. self._unwatchVm() elif reason in ('poweroff', 'reboot'): + self.info['watchdog_lastboot'] = False + restart_reason = reason + elif reason == 'watchdog': + self.info['watchdog_lastboot'] = True restart_reason = reason else: self.destroy()
@@ -1147,6 +1156,7 @@ class XendDomainInfo: self.refresh_shutdown_lock.release() if restart_reason: + log.debug("Restarted with a reason!") threading.Thread(target = self._maybeRestart, args = (restart_reason,)).start()
@@ -1171,6 +1181,7 @@ class XendDomainInfo: 'poweroff': 'actions_after_shutdown', 'reboot': 'actions_after_reboot', 'crash': 'actions_after_crash', + 'watchdog': 'actions_after_watchdog' } action_target = self.info.get(action_conf.get(reason))
@@ -1494,6 +1505,9 @@ class XendDomainInfo: xc.domain_setcpuweight(self.domid, self.info['cpu_weight']) + r = xc.domain_watchdog_set_lastboot(self.domid, + self.info['watchdog_lastboot']) + # repin domain vcpus if a restricted cpus list is provided # this is done prior to memory allocation to aide in memory # distribution for NUMA systems.
@@ -2220,6 +2234,12 @@ class XendDomainInfo: return XEN_API_ON_CRASH_BEHAVIOUR[0] return after_crash + def get_on_watchdog(self): + after_watchdog = self.info.get('action_after_watchdog') + if not after_watchdog or after_watchdog not in XEN_API_ON_NORMAL_EXIT: + return XEN_API_ON_NORMAL_EXIT[-1] + return after_watchdog + def get_dev_config_by_uuid(self, dev_class, dev_uuid): """ Get's a device configuration either from XendConfig or from the DevController.
tools/python/xen/xm/create.py +12 -1
@@ -262,6 +262,17 @@ gopts.var('on_crash', val='destroy|resta renamed and a new domain started in its place. """) +gopts.var('on_watchdog', val='destroy|restart|preserve|rename-restart', + fn=set_value, default=None, + use="""Behaviour when a domain exits with reason 'watchdog'. + - destroy: the domain is cleaned up as normal; + - restart: a new domain is started in place of the old one; + - preserve: no clean-up is done until the domain is manually + destroyed (using xm destroy, for example); + - rename-restart: the old domain is not cleaned up, but is + renamed and a new domain started in its place. + """) + gopts.var('blkif', val='no|yes', fn=set_bool, default=0, use="Make the domain a block device backend.")
@@ -747,7 +758,7 @@ def make_config(vals): map(add_conf, ['name', 'memory', 'maxmem', 'shadow_memory', 'restart', 'on_poweroff', - 'on_reboot', 'on_crash', 'vcpus', 'vcpu_avail', 'features', + 'on_reboot', 'on_crash', 'on_watchdog', 'vcpus', 'vcpu_avail', 'features', 'on_xend_start', 'on_xend_stop']) if vals.uuid is not None:
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [RFC] Xen paravirtual watchdog device [4/4]
In reply to Mark WilliamsonXen virtual watchdog - hypervisor code.
A Xen-internal software watchdog service for paravirt domains including dom0 and driver domains. Ideally dom0 would use a hardware watchdog device, but this is still a higher assurance design than a kernel-based software watchdog.
Cheers,
Mark
Signature · 4 lines
Dave: Just a question. What use is a unicyle with no seat? And no pedals! Mark: To answer a question with a question: What use is a skateboard? Dave: Skateboards have wheels. Mark: My wheel has a wheel!
Re: [RFC] Xen paravirtual watchdog device [4/4]
And as if that description wasn't enough, for your pleasure and enjoyment I present ... the actual patch!
Quoted 9 lines · Mark Williamson
Xen virtual watchdog - hypervisor code.
A Xen-internal software watchdog service for paravirt domains including dom0 and driver domains. Ideally dom0 would use a hardware watchdog device, but this is still a higher assurance design than a kernel-based software watchdog.
Cheers,
Mark
Signature · 4 lines
Dave: Just a question. What use is a unicyle with no seat? And no pedals! Mark: To answer a question with a question: What use is a skateboard? Dave: Skateboards have wheels. Mark: My wheel has a wheel!
xen/arch/x86/x86_32/entry.S +2 -0
@@ -673,6 +673,7 @@ ENTRY(hypercall_table) .long do_sysctl /* 35 */ .long do_domctl .long do_kexec_op + .long do_watchdog_op .rept NR_hypercalls-((.-hypercall_table)/4) .long do_ni_hypercall .endr
@@ -716,6 +717,7 @@ ENTRY(hypercall_args_table) .byte 1 /* do_sysctl */ /* 35 */ .byte 1 /* do_domctl */ .byte 2 /* do_kexec_op */ + .byte 1 /* do_watchdog_op */ .rept NR_hypercalls-(.-hypercall_args_table) .byte 0 /* do_ni_hypercall */ .endr
xen/common/domain.c +1 -0
@@ -61,6 +61,7 @@ struct domain *alloc_domain(domid_t domispin_lock_init (&d->big_lock);spin_lock_init (&d->page_alloc_lock);spin_lock_init (&d->shutdown_lock); +spin_lock_init (&d->watchdog.lock);INIT_LIST_HEAD (&d->page_list);INIT_LIST_HEAD (&d->xenpage_list);
xen/common/Makefile +1 -0
@@ -27,6 +27,7 @@ obj-y += version.o obj-y += vsprintf.o obj-y += xmalloc.o obj-y += rcupdate.o +obj-y += watchdog.o obj-$(perfc) += perfc.o obj-$(crash_debug) += gdbstub.o
xen/common/watchdog.c +290 -0
290 lines not on this page · raw message
xen/include/public/sched.h +1 -0
@@ -107,6 +107,7 @@ DEFINE_XEN_GUEST_HANDLE(sched_remote_shu#define SHUTDOWN_reboot 1/* Clean up, kill, and then restart. */ #define SHUTDOWN_suspend 2/* Clean up, save suspend info, kill. */ #define SHUTDOWN_crash 3/* Tell controller we've crashed. */ +#define SHUTDOWN_watchdog 5/* The watchdog triggered a reboot. */ #endif /* __XEN_PUBLIC_SCHED_H__ */
xen/include/public/watchdog.h +66 -0
66 lines not on this page · raw message
xen/include/public/xen.h +1 -0
@@ -80,6 +80,7 @@#define __HYPERVISOR_sysctl 35#define __HYPERVISOR_domctl 36#define __HYPERVISOR_kexec_op 37 +#define __HYPERVISOR_watchdog_op 38/* Architecture-specific hypercall definitions. */ #define __HYPERVISOR_arch_0 48
xen/include/xen/sched.h +2 -0
@@ -19,6 +19,7 @@#include <xen/xenoprof.h> #include <xen/rcupdate.h> #include <xen/irq.h> +#include <xen/watchdog.h> #ifdef CONFIG_COMPAT #include <compat/vcpu.h>
@@ -223,6 +224,7 @@ struct domainstruct xenoprof *xenoprof;int32_t time_offset_seconds; +xen_watchdog_state_t watchdog;struct rcu_head rcu; };
xen/include/xen/watchdog.h +15 -0
@@ -0,0 +1,15 @@ +#ifndef __XEN_WATCHDOG_H__ +#define __XEN_WATCHDOG_H__ + +#include <public/watchdog.h> +#include <xen/timer.h> + +typedef struct xen_watchdog_state { +spinlock_t lock;/* Serialises access to the other fields in +* this struct. */ +u64 status; +unsigned long timeout;/* Watchdog timeout, in seconds. */ +struct timer timer;/* Watchdog timer, for use when active. */ +}xen_watchdog_state_t ; + +#endif /* __XEN_WATCHDOG_H__ */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 1 line · Mark Williamson
The XenLinux watchdog driver sets up the in-Xen watchdog for the current domain using a simple hypercall interface. The watchdog timer is implemented within Xen itself, isolating it from any guest bugs that might take out a normal software watchdog. Standard interfaces to userspace are supported so that any watchdog-aware software should be able to interact with it without modification.
Sounds like an excellent idea! I really need a box running unstable so I can test this (and other things) out! :)
------------------------------------------------------------------------
| nate carlson | [email protected] | http://www.natecarlson.com | | depriving some poor village of its idiot since 1981 |
------------------------------------------------------------------------