xen/watchdog: Identify which domain watchdog fired
PATCH 1/1 xen/watchdog: Identify which domain watchdog fired
When a watchdog fires, the domain is crashed and can't dump any state.
Xen allows a domain to have two separate watchdogs. Therefore, for a domain running multiple watchdogs (e.g. one based around network, one for disk), it is important for diagnostics to know which watchdog fired.
As the printk() is in a timer callback, this is a bit awkward to arrange, but there are 12 spare bits in the bottom of the domain pointer owing to its alignment.
Reuse these bits to encode the watchdog id too, so the one which fired is identified when the domain is crashed.
---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
In XenServer's case, it's two different watchdogs for dom0, so this printk() is the final piece of useful information out of the system which has deemed itself to have lost connectivity.
--- xen/common/sched/core.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
xen/common/sched/core.c +18 -3
@@ -1534,12 +1534,17 @@ long vcpu_yield(void) static void cf_check domain_watchdog_timeout(void *data) { -struct domain *d = data; +/* +* The data parameter encodes the watchdog id in the low bits of +* the domain pointer. +*/ +struct domain *d =_p ((unsigned long )data &PAGE_MASK ); +unsigned int id = (unsigned long )data & ~PAGE_MASK ;if ( d->is_shutting_down || d->is_dying )return ; -printk ("Watchdog timer fired for domain %u\n" , d->domain_id); +printk ("Watchdog timer %u fired for %pd\n" , id, d);domain_shutdown (d, SHUTDOWN_watchdog); }
@@ -1593,7 +1598,17 @@ void watchdog_domain_init(struct domain *d) d->watchdog_inuse_map =0 ;for ( i =0 ; i <NR_DOMAIN_WATCHDOG_TIMERS ; i++ ) -init_timer (&d->watchdog_timer[i], domain_watchdog_timeout, d,0 ); + { +void *data = d; + +BUILD_BUG_ON (NR_DOMAIN_WATCHDOG_TIMERS >=PAGE_SIZE ); + +/* +* For the timer callback parameter, encode the watchdog id in +* the low bits of the domain pointer. +*/ +init_timer (&d->watchdog_timer[i], domain_watchdog_timeout, data + i,0 ); + } }void watchdog_domain_destroy (struct domain *d)
Signature · 1 line
2.34.1
Quoted 14 lines · Andrew Cooper
When a watchdog fires, the domain is crashed and can't dump any state.
Xen allows a domain to have two separate watchdogs. Therefore, for a domain running multiple watchdogs (e.g. one based around network, one for disk), it is important for diagnostics to know which watchdog fired.
As the
printk()is in a timer callback, this is a bit awkward to arrange, but there are 12 spare bits in the bottom of the domain pointer owing to its alignment.Reuse these bits to encode the watchdog id too, so the one which fired is identified when the domain is crashed.
Quoted 8 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
You'll eventually need a scheduler maintainer's ack, yet you didn't Cc any of them.
Quoted 9 lines
xen/common/sched/core.c +2
-1@@ -1534,12 +1534,17 @@ long vcpu_yield(void) static void cf_check domain_watchdog_timeout(void *data) { -struct domain *d = data; +/* +* The data parameter encodes the watchdog id in the low bits of
xen/common/sched/core.c long vcpu_yield(void) · line 1547
Quoted 10 lines
xen/common/sched/core.c +5
-1+* the domain pointer. +*/ +struct domain *d =_p ((unsigned long )data &PAGE_MASK ); +unsigned int id = (unsigned long )data & ~PAGE_MASK ;if ( d->is_shutting_down || d->is_dying )return ; -printk ("Watchdog timer fired for domain %u\n" , d->domain_id); +printk ("Watchdog timer %u fired for %pd\n" , id, d);
And apriori knowledge will be required to associate the number with whichever watchdog it was (network or disk in your example)? (No question that logging the number is better than not doing so.)
Quoted 6 lines
xen/common/sched/core.c +1
-1@@ -1593,7 +1598,17 @@ void watchdog_domain_init(struct domain *d) d->watchdog_inuse_map =0 ;for ( i =0 ; i <NR_DOMAIN_WATCHDOG_TIMERS ; i++ ) -init_timer (&d->watchdog_timer[i], domain_watchdog_timeout, d,0 ); + {
xen/common/sched/core.c void watchdog_domain_init(struct domain *d) · line 1611
Quoted 10 lines
xen/common/sched/core.c +10
-0+void *data = d; + +BUILD_BUG_ON (NR_DOMAIN_WATCHDOG_TIMERS >=PAGE_SIZE ); + +/* +* For the timer callback parameter, encode the watchdog id in +* the low bits of the domain pointer. +*/ +init_timer (&d->watchdog_timer[i], domain_watchdog_timeout, data + i,0 ); + }
This way we'll be promising to ourselves that we're never going to alter the allocation mechanism of struct domain instances, always requiring them to have at least page alignment. If someone wanted to change that, they'll have a hard time spotting the logic here. Sadly I have no good suggestion towards improving the situation.
Jan
Quoted 23 lines · Jan Beulich
Quoted 14 lines · Andrew Cooper
When a watchdog fires, the domain is crashed and can't dump any state.
Xen allows a domain to have two separate watchdogs. Therefore, for a domain running multiple watchdogs (e.g. one based around network, one for disk), it is important for diagnostics to know which watchdog fired.
As the
printk()is in a timer callback, this is a bit awkward to arrange, but there are 12 spare bits in the bottom of the domain pointer owing to its alignment.Reuse these bits to encode the watchdog id too, so the one which fired is identified when the domain is crashed.
Quoted 8 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
Quoted 2 lines
You'll eventually need a scheduler maintainer's ack, yet you didn't Cc any of them.
Oops yes. Although really SCHEDOP and the scheduler shouldn't be mixed like this.
Quoted 15 lines
Quoted 15 lines
xen/common/sched/core.c +6
-1@@ -1534,12 +1534,17 @@ long vcpu_yield(void) static void cf_check domain_watchdog_timeout(void *data) { -struct domain *d = data; +/* +* The data parameter encodes the watchdog id in the low bits of +* the domain pointer. +*/ +struct domain *d =_p ((unsigned long )data &PAGE_MASK ); +unsigned int id = (unsigned long )data & ~PAGE_MASK ;
Quoted 8 lines
xen/common/sched/core.c long vcpu_yield(void) · line 1547
Quoted 5 lines
xen/common/sched/core.c +1
-1if ( d->is_shutting_down || d->is_dying )return ; -printk ("Watchdog timer fired for domain %u\n" , d->domain_id); +printk ("Watchdog timer %u fired for %pd\n" , id, d);And apriori knowledge will be required to associate the number with whichever watchdog it was (network or disk in your example)? (No question that logging the number is better than not doing so.)
Indeed, but that's up to the entities in the domain requesting the watchdog.
(Yes, we do have this logged.)
Quoted 14 lines
Quoted 14 lines
xen/common/sched/core.c +8
-1@@ -1593,7 +1598,17 @@ void watchdog_domain_init(struct domain *d) d->watchdog_inuse_map =0 ;for ( i =0 ; i <NR_DOMAIN_WATCHDOG_TIMERS ; i++ ) -init_timer (&d->watchdog_timer[i], domain_watchdog_timeout, d,0 ); + { +void *data = d; + +BUILD_BUG_ON (NR_DOMAIN_WATCHDOG_TIMERS >=PAGE_SIZE ); + +/* +* For the timer callback parameter, encode the watchdog id in +* the low bits of the domain pointer.
Quoted 8 lines
xen/common/sched/core.c void watchdog_domain_init(struct domain *d) · line 1611
Quoted 3 lines
xen/common/sched/core.c +3
-0+*/ +init_timer (&d->watchdog_timer[i], domain_watchdog_timeout, data + i,0 ); + }This way we'll be promising to ourselves that we're never going to alter the allocation mechanism of struct domain instances, always requiring them to have at least page alignment. If someone wanted to change that, they'll have a hard time spotting the logic here. Sadly I have no good suggestion towards improving the situation.
I wasn't terribly happy either, but something has occurred to me.
For both struct domain and vcpu, we could have an __aligned(PAGE_SIZE) attribute. It's accurate and unlikely to change (and helps x86 code generation at least).
Then, we can use:
BUILD_BUG_ON((NR_DOMAIN_WATCHDOG_TIMERS > alignof(d));
which should trigger cleanly if the precondition is violated.
For watchdog specifically, we only actually need uint16_t alignment to be safe, and there's no way that's going to break in practice.
~Andrew
Quoted 30 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Andrew Cooper
xen/common/sched/core.c +8
-1@@ -1593,7 +1598,17 @@ void watchdog_domain_init(struct domain *d) d->watchdog_inuse_map =0 ;for ( i =0 ; i <NR_DOMAIN_WATCHDOG_TIMERS ; i++ ) -init_timer (&d->watchdog_timer[i], domain_watchdog_timeout, d,0 ); + { +void *data = d; + +BUILD_BUG_ON (NR_DOMAIN_WATCHDOG_TIMERS >=PAGE_SIZE ); + +/* +* For the timer callback parameter, encode the watchdog id in +* the low bits of the domain pointer. Quoted 8 lines
xen/common/sched/core.c void watchdog_domain_init(struct domain *d) · line 1611
Quoted 3 lines
xen/common/sched/core.c +3
-0+*/ +init_timer (&d->watchdog_timer[i], domain_watchdog_timeout, data + i,0 ); + }This way we'll be promising to ourselves that we're never going to alter the allocation mechanism of struct domain instances, always requiring them to have at least page alignment. If someone wanted to change that, they'll have a hard time spotting the logic here. Sadly I have no good suggestion towards improving the situation.
I wasn't terribly happy either, but something has occurred to me.
For both struct domain and vcpu, we could have an
__aligned(PAGE_SIZE)attribute. It's accurate and unlikely to change (and helps x86 code generation at least).
Quoted 5 lines
Then, we can use:
BUILD_BUG_ON((NR_DOMAIN_WATCHDOG_TIMERS > alignof(d));
which should trigger cleanly if the precondition is violated.
Hmm, yes, why not. That would establish the missing link.
Quoted 2 lines
For watchdog specifically, we only actually need
uint16_talignment to be safe, and there's no way that's going to break in practice.
Right.
Jan