xen/events: fix get_global_virq_handler() usage without hardware domain
PATCH 1/1 xen/events: fix get_global_virq_handler() usage without hardware domain
Some use cases of get_global_virq_handler() didn't account for the case of running without hardware domain.
Fix that by testing get_global_virq_handler() returning NULL where needed (e.g. when directly dereferencing the result).
--- xen/common/event_channel.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
xen/common/event_channel.c +4 -2
@@ -1036,7 +1036,9 @@ int set_global_virq_handler(struct domain *d, uint32_t virq) { old = global_virq_handlers[virq]; hdl =get_global_virq_handler (virq); -if ( hdl != d ) +if ( !hdl ) + global_virq_handlers[virq] = d; +else if ( hdl != d ) {read_lock (&hdl->event_lock);
@@ -1091,7 +1093,7 @@ struct domain *lock_dom_exc_handler(void)struct domain *d; d =get_global_virq_handler (VIRQ_DOM_EXC ); -if (unlikely (!get_domain (d)) ) +if (unlikely (!d || !get_domain (d)) )return NULL ;read_lock (&d->event_lock);
Signature · 1 line
2.43.0
Quoted 14 lines · Juergen Gross
xen/common/event_channel.c +3
-1@@ -1036,7 +1036,9 @@ int set_global_virq_handler(struct domain *d, uint32_t virq) { old = global_virq_handlers[virq]; hdl =get_global_virq_handler (virq); -if ( hdl != d ) +if ( !hdl ) + global_virq_handlers[virq] = d; +else if ( hdl != d ) {read_lock (&hdl->event_lock);
xen/common/event_channel.c struct domain *lock_dom_exc_handler(void) · line 1096
Quoted 5 lines
xen/common/event_channel.c +1
-1@@ -1091,7 +1093,7 @@ struct domain *lock_dom_exc_handler(void)struct domain *d; d =get_global_virq_handler (VIRQ_DOM_EXC ); -if (unlikely (!get_domain (d)) ) +if (unlikely (!d || !get_domain (d)) )
According to my understanding of how unlikely() works this wants to be
if ( unlikely(!d) || unlikely(!get_domain(d)) )
Of course I could also live with being given an explanation of why my understanding is wrong.
xen/common/event_channel.c struct domain *lock_dom_exc_handler(void) · line 1099
Quoted 3 lines
xen/common/event_channel.c +0
-0return NULL ;read_lock (&d->event_lock);
There's one more change needed: get_domain_state() needs to avoid calling unlock_dom_exc_handler() when "hdl" is NULL.
Jan
Quoted 23 lines · Jan Beulich
Quoted 14 lines · Juergen Gross
xen/common/event_channel.c +3
-1@@ -1036,7 +1036,9 @@ int set_global_virq_handler(struct domain *d, uint32_t virq) { old = global_virq_handlers[virq]; hdl =get_global_virq_handler (virq); -if ( hdl != d ) +if ( !hdl ) + global_virq_handlers[virq] = d; +else if ( hdl != d ) {read_lock (&hdl->event_lock);xen/common/event_channel.c struct domain *lock_dom_exc_handler(void) · line 1096
Quoted 5 lines
xen/common/event_channel.c +1
-1@@ -1091,7 +1093,7 @@ struct domain *lock_dom_exc_handler(void)struct domain *d; d =get_global_virq_handler (VIRQ_DOM_EXC ); -if (unlikely (!get_domain (d)) ) +if (unlikely (!d || !get_domain (d)) )According to my understanding of how
unlikely()works this wants to be
Quoted 4 lines
if ( unlikely(!d) || unlikely(!get_domain(d)) )Of course I could also live with being given an explanation of why my understanding is wrong.
I was unsure, so I looked through the code until I found a case where 2 conditions were tested as "unlikely". I might have found a wrong example. I'll change it as you are suggesting.
Quoted 7 lines
xen/common/event_channel.c struct domain *lock_dom_exc_handler(void) · line 1099
Quoted 4 lines
xen/common/event_channel.c +0
-0return NULL ;read_lock (&d->event_lock);There's one more change needed:
get_domain_state()needs to avoid callingunlock_dom_exc_handler()when "hdl" is NULL.
Oh, right. Will add.
Juergen