wdt_i6300esb: register a reset function
PATCH 1/1 wdt_i6300esb: register a reset function
The device shall set its default hardware state after each reset. This includes that the timer is stopped which is especially important if the guest does a reboot independantly of a watchdog bite. I moved the initialization of the state variables completely from the init to the reset function which is called right after init during the first boot and afterwards during each reboot.
--- hw/wdt_i6300esb.c | 39 +++++++++++++++++++++------------------ 1 files changed, 21 insertions(+), 18 deletions(-)
hw/wdt_i6300esb.c +21 -18
@@ -140,14 +140,26 @@ static void i6300esb_disable_timer(I6300State *d)qemu_del_timer (d->timer); } -static void i6300esb_reset (I6300State *d) +static void i6300esb_reset (DeviceState *dev) { -/* XXX We should probably reset other parts of the state here, -* but we should also reset our state on general machine reset -* too. For now just disable the timer so it doesn't fire -* again after the reboot. -*/ +PCIDevice *pdev =DO_UPCAST (PCIDevice, qdev, dev); +I6300State *d =DO_UPCAST (I6300State, dev, pdev); + +i6300esb_debug ("I6300State = %p\n" , d); +i6300esb_disable_timer (d); + + d->reboot_enabled =1 ; + d->clock_scale =CLOCK_SCALE_1KHZ ; + d->int_type =INT_TYPE_IRQ ; + d->free_run =0 ; + d->locked =0 ; + d->enabled =0 ; + d->timer1_preload =0xfffff ; + d->timer2_preload =0xfffff ; + d->stage =1 ; + d->unlock_state =0 ; + d->previous_reboot_flag =0 ; }/* This function is called when the watchdog expires. Note that
@@ -181,7 +193,6 @@ static void i6300esb_timer_expired(void *vp)if (d->reboot_enabled) { d->previous_reboot_flag =1 ;watchdog_perform_action ();/* This reboots, exits, etc */ -i6300esb_reset (d); }/* In "free running mode" we start stage 1 again. */
@@ -394,18 +405,9 @@ static int i6300esb_init(PCIDevice *dev)I6300State *d =DO_UPCAST (I6300State, dev, dev);uint8_t *pci_conf; - d->reboot_enabled =1 ; - d->clock_scale =CLOCK_SCALE_1KHZ ; - d->int_type =INT_TYPE_IRQ ; - d->free_run =0 ; - d->locked =0 ; - d->enabled =0 ; +i6300esb_debug ("I6300State = %p\n" , d); + d->timer =qemu_new_timer (vm_clock, i6300esb_timer_expired, d); - d->timer1_preload =0xfffff ; - d->timer2_preload =0xfffff ; - d->stage =1 ; - d->unlock_state =0 ; - d->previous_reboot_flag =0 ; pci_conf = d->dev.config;pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_INTEL );
@@ -427,6 +429,7 @@ static PCIDeviceInfo i6300esb_info = { .qdev.name = "i6300esb", .qdev.size = sizeof(I6300State), .qdev.vmsd = &vmstate_i6300esb, + .qdev.reset = i6300esb_reset, .config_read = i6300esb_config_read, .config_write = i6300esb_config_write, .init = i6300esb_init,
Signature · 1 line
1.7.2.3
Blue Swirl
AppliedThanks, applied.
Quoted 91 lines · Bernhard Kohl
The device shall set its default hardware state after each reset. This includes that the timer is stopped which is especially important if the guest does a reboot independantly of a watchdog bite. I moved the initialization of the state variables completely from the init to the reset function which is called right after init during the first boot and afterwards during each reboot.
Signed-off-by Bernhard Kohl <[email protected]>---
hw/wdt_i6300esb.c | 39 +++++++++++++++++++++------------------1 files changed, 21 insertions(+), 18 deletions(-)hw/wdt_i6300esb.c +18
-6@@ -140,14 +140,26 @@ static void i6300esb_disable_timer(I6300State *d) qemu_del_timer(d->timer); } -static void i6300esb_reset (I6300State *d) +static void i6300esb_reset (DeviceState *dev) { - /* XXX We should probably reset other parts of the state here, - * but we should also reset our state on general machine reset - * too. For now just disable the timer so it doesn't fire - * again after the reboot. - */ + PCIDevice *pdev = DO_UPCAST(PCIDevice, qdev, dev); + I6300State *d = DO_UPCAST(I6300State, dev, pdev); + + i6300esb_debug("I6300State = %p\n", d); + i6300esb_disable_timer(d); + + d->reboot_enabled = 1; + d->clock_scale = CLOCK_SCALE_1KHZ; + d->int_type = INT_TYPE_IRQ; + d->free_run = 0; + d->locked = 0; + d->enabled = 0; + d->timer1_preload = 0xfffff; + d->timer2_preload = 0xfffff; + d->stage = 1; + d->unlock_state = 0; + d->previous_reboot_flag = 0; } /* This function is called when the watchdog expires. Note that@@ -181,7 +193,6 @@ static void i6300esb_timer_expired(void *vp) if (d->reboot_enabled) { d->previous_reboot_flag = 1;
watchdog_perform_action(); /* This reboots, exits, etc */
- i6300esb_reset(d);
}/* In "free running mode" we start stage 1 again. */
hw/wdt_i6300esb.c +3
-12@@ -394,18 +405,9 @@ static int i6300esb_init(PCIDevice *dev) I6300State *d = DO_UPCAST(I6300State, dev, dev); uint8_t *pci_conf; - d->reboot_enabled = 1; - d->clock_scale = CLOCK_SCALE_1KHZ; - d->int_type = INT_TYPE_IRQ; - d->free_run = 0; - d->locked = 0; - d->enabled = 0; + i6300esb_debug("I6300State = %p\n", d); + d->timer = qemu_new_timer(vm_clock, i6300esb_timer_expired, d); - d->timer1_preload = 0xfffff; - d->timer2_preload = 0xfffff; - d->stage = 1; - d->unlock_state = 0; - d->previous_reboot_flag = 0; pci_conf = d->dev.config; pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);@@ -427,6 +429,7 @@ static PCIDeviceInfo i6300esb_info = { .qdev.name = "i6300esb", .qdev.size = sizeof(I6300State), .qdev.vmsd = &vmstate_i6300esb, + .qdev.reset = i6300esb_reset, .config_read = i6300esb_config_read, .config_write = i6300esb_config_write, .init = i6300esb_init, --1.7.2.3
Quoted 1 line · Blue Swirl
Thanks, applied.
Wait! This patch is incomplete.
I already posted a complete patch already some months ago (twice) but it was ignored both times:
http://www.mail-archive.com/[email protected]/msg42716.html
http://www.mail-archive.com/[email protected]/msg43142.html
Rich.
Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v
Quoted 10 lines · Richard W.M. Jones
Quoted 1 line · Blue Swirl
Thanks, applied.
Wait! This patch is incomplete.
I already posted a complete patch already some months ago (twice) but it was ignored both times:
http://www.mail-archive.com/[email protected]/msg42716.html
http://www.mail-archive.com/[email protected]/msg43142.html
The difference is that previous_reboot_flag should not be cleared in reset, right?
Could you make a new patch, please?
Quoted 6 lines · Blue Swirl
Quoted 5 lines · Richard W.M. Jones
Quoted 1 line · Blue Swirl
Thanks, applied.
Wait! This patch is incomplete.
Quoted 8 lines
Quoted 5 lines
I already posted a complete patch already some months ago (twice) but it was ignored both times:
http://www.mail-archive.com/[email protected]/msg42716.html
http://www.mail-archive.com/[email protected]/msg43142.htmlThe difference is that
previous_reboot_flagshould not be cleared in reset, right?
Yes, and:
- Bernhard removed the call to i6300esb_reset after the watchdog fires. I'm not sure why this was done, since AFAIK the watchdog should be completely reset by this event (as in a real machine).
- The same change is needed to IB700 as well.
Quoted 1 line
Could you make a new patch, please?
New patch attached.
Rich.
Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v
Quoted 1 line
From
313589d5bfb7458566eb9cfadfeaa7038f0a1622Mon Sep 17 00:00:00 2001
From: Richard W.M. Jones <[email protected]>
Date: Fri, 24 Sep 2010 16:08:06 +0100
Subject: [PATCH] Watchdog: disable watchdog timer when hard-rebooting a guest.
This commit causes the watchdog timer to be reset when a guest is hard-rebooted.
The failure case previously was as follows:
(a) guest boots, watchdog is enabled
(b) guest does a reset eg:
echo 'b' > /proc/sysrq-trigger
(note that an ordinary /sbin/reboot wouldn't hit this case since as the watchdog daemon is shut down, the daemon would properly disable the watchdog device)
(c) the reboot takes longer than the remaining time on the watchdog
(d) the watchdog therefore fires during the reboot
(e) probably the VM would just reboot again at this point which is pretty benign, but it could depend on the action that the user had selected for the watchdog
Now we use the qdev reset function to register a reset handler which disables the timer. Note the handler is called _either_ just after init _or_ when the guest reboots.
In the i6300esb case there is a small refactoring of the code so that the device's internal state is now fully restored to defaults on a reboot.
--- hw/wdt_i6300esb.c | 5 ++++- hw/wdt_ib700.c | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-)
hw/wdt_i6300esb.c +4 -1
@@ -149,6 +149,8 @@ static void i6300esb_reset(DeviceState *dev)i6300esb_disable_timer (d); +/* NB: Don't change d->previous_reboot_flag in this function. */ + d->reboot_enabled =1 ; d->clock_scale =CLOCK_SCALE_1KHZ ; d->int_type =INT_TYPE_IRQ ;
@@ -159,7 +161,6 @@ static void i6300esb_reset(DeviceState *dev) d->timer2_preload =0xfffff ; d->stage =1 ; d->unlock_state =0 ; - d->previous_reboot_flag =0 ; }/* This function is called when the watchdog expires. Note that
@@ -193,6 +194,7 @@ static void i6300esb_timer_expired(void *vp)if (d->reboot_enabled) { d->previous_reboot_flag =1 ;watchdog_perform_action ();/* This reboots, exits, etc */ +i6300esb_reset (&d->dev.qdev); }/* In "free running mode" we start stage 1 again. */
@@ -409,6 +411,7 @@ static int i6300esb_init(PCIDevice *dev)i6300esb_debug ("I6300State = %p\n" , d); d->timer =qemu_new_timer (vm_clock, i6300esb_timer_expired, d); + d->previous_reboot_flag =0 ; pci_conf = d->dev.config;pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_INTEL );
hw/wdt_ib700.c +16 -4
@@ -97,6 +97,8 @@ static int wdt_ib700_init(ISADevice *dev) {IB700State *s =DO_UPCAST (IB700State, dev, dev); +ib700_debug ("watchdog init\n" ); + s->timer =qemu_new_timer (vm_clock, ib700_timer_expired, s);register_ioport_write (0x441 ,2 ,1 , ib700_write_disable_reg, s);register_ioport_write (0x443 ,2 ,1 , ib700_write_enable_reg, s);
@@ -104,16 +106,26 @@ static int wdt_ib700_init(ISADevice *dev)return 0 ; } +static void wdt_ib700_reset (DeviceState *dev) +{ +IB700State *s =DO_UPCAST (IB700State, dev.qdev, dev); + +ib700_debug ("watchdog reset\n" ); + +qemu_del_timer (s->timer); +} +static WatchdogTimerModel model = { .wdt_name ="ib700" , .wdt_description ="iBASE 700" , };static ISADeviceInfo wdt_ib700_info = { - .qdev.name ="ib700" , - .qdev.size =sizeof (IB700State), - .qdev.vmsd = &vmstate_ib700, - .init = wdt_ib700_init, + .qdev.name ="ib700" , + .qdev.size =sizeof (IB700State), + .qdev.vmsd = &vmstate_ib700, + .qdev.reset = wdt_ib700_reset, + .init = wdt_ib700_init, };static void wdt_ib700_register_devices (void )
Signature · 1 line
1.7.3.2
Blue Swirl
AppliedThanks, applied.
Quoted 36 lines · Richard W.M. Jones
Quoted 6 lines · Blue Swirl
Quoted 5 lines · Richard W.M. Jones
Quoted 1 line · Blue Swirl
Thanks, applied.
Wait! This patch is incomplete.
Quoted 8 lines
Quoted 5 lines
I already posted a complete patch already some months ago (twice) but it was ignored both times:
http://www.mail-archive.com/[email protected]/msg42716.html
http://www.mail-archive.com/[email protected]/msg43142.htmlThe difference is that
previous_reboot_flagshould not be cleared in reset, right?Yes, and:
- Bernhard removed the call to
i6300esb_resetafter the watchdog fires. I'm not sure why this was done, since AFAIK the watchdog should be completely reset by this event (as in a real machine).- The same change is needed to IB700 as well.
Quoted 1 line
Could you make a new patch, please?
New patch attached.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v