[PATCH v2] xen/events: fix get_global_virq_handler() usage without hardware domain

Juergen Gross posted 1 patch 2 days, 22 hours ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20250306161305.10236-1-jgross@suse.com
xen/common/event_channel.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
[PATCH v2] xen/events: fix get_global_virq_handler() usage without hardware domain
Posted by Juergen Gross 2 days, 22 hours ago
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).

Fixes: 980822c5edd1 ("xen/events: allow setting of global virq handler only for unbound virqs")
Signed-off-by: Juergen Gross <jgross@suse.com>
---
V2:
- fix use case of unlikely() (Jan Beulich)
- add test for NULL in unlock_dom_exc_handler() (Jan Beulich)
---
 xen/common/event_channel.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 4ee6b6b4ce..c68aa97135 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -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) || unlikely(!get_domain(d)) )
         return NULL;
 
     read_lock(&d->event_lock);
@@ -1101,6 +1103,9 @@ struct domain *lock_dom_exc_handler(void)
 
 void unlock_dom_exc_handler(struct domain *d)
 {
+    if ( likely(!d) )
+        return;
+
     read_unlock(&d->event_lock);
 
     put_domain(d);
-- 
2.43.0
Re: [PATCH v2] xen/events: fix get_global_virq_handler() usage without hardware domain
Posted by Jan Beulich 2 days, 22 hours ago
On 06.03.2025 17:13, Juergen Gross wrote:
> 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).
> 
> Fixes: 980822c5edd1 ("xen/events: allow setting of global virq handler only for unbound virqs")
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>