Skip to contentSkip to conversation

x86/irq: Skip unmap_domain_pirq XSM during destruction

PATCH In review Jason Andryuk 3 participants 5 messages Apr 7, 2022 – Apr 8, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/irq: Skip unmap_domain_pirq XSM during destruction

xsm_unmap_domain_irq was seen denying unmap_domain_pirq when called from complete_domain_destroy as an RCU callback. The source context was an unexpected, random domain. Since this is a xen-internal operation, going through the XSM hook is inapproriate.

Check d->is_dying and skip the XSM hook when set since this is a cleanup operation for a domain being destroyed.

---
v2:
Style fixes
Rely on ret=0 initialization

---
 xen/arch/x86/irq.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
xen/arch/x86/irq.c +8 -2
index 285ac399fb..de30ee7779 100644
@@ -2340,8 +2340,14 @@ int unmap_domain_pirq(struct domain *d, int pirq)
         nr = msi_desc->msi.nvec;
     }
 
-    ret = xsm_unmap_domain_irq(XSM_HOOK, d, irq,
-                               msi_desc ? msi_desc->dev : NULL);
+    /*
+     * When called by complete_domain_destroy via RCU, current is a random
+     * domain.  Skip the XSM check since this is a Xen-initiated action.
+     */
+    if ( !d->is_dying )
+        ret = xsm_unmap_domain_irq(XSM_HOOK, d, irq,
+                                   msi_desc ? msi_desc->dev : NULL);
+
     if ( ret )
         goto done;
 
Signature · 1 line
2.35.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Jason Andryuk

xsm_unmap_domain_irq was seen denying unmap_domain_pirq when called from complete_domain_destroy as an RCU callback. The source context was an unexpected, random domain. Since this is a xen-internal operation, going through the XSM hook is inapproriate.

Check d->is_dying and skip the XSM hook when set since this is a cleanup operation for a domain being destroyed.

Reviewed-by on v2 1/1
#2 lore raw
In reply to Jason Andryuk
Quoted 27 lines · Jason Andryuk

xsm_unmap_domain_irq was seen denying unmap_domain_pirq when called from complete_domain_destroy as an RCU callback. The source context was an unexpected, random domain. Since this is a xen-internal operation, going through the XSM hook is inapproriate.

Check d->is_dying and skip the XSM hook when set since this is a cleanup operation for a domain being destroyed.

---
v2:
Style fixes
Rely on ret=0 initialization

---
 xen/arch/x86/irq.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
xen/arch/x86/irq.c +0 -0
index 285ac399fb..de30ee7779 100644
@@ -2340,8 +2340,14 @@ int unmap_domain_pirq(struct domain *d, int pirq)
         nr = msi_desc->msi.nvec;
     }
 

xen/arch/x86/irq.c int unmap_domain_pirq(struct domain *d, int pirq) · line 2350

Quoted 10 lines
xen/arch/x86/irq.c +8 -2
-    ret = xsm_unmap_domain_irq(XSM_HOOK, d, irq,
-                               msi_desc ? msi_desc->dev : NULL);
+    /*
+     * When called by complete_domain_destroy via RCU, current is a random
+     * domain.  Skip the XSM check since this is a Xen-initiated action.
+     */
+    if ( !d->is_dying )
+        ret = xsm_unmap_domain_irq(XSM_HOOK, d, irq,
+                                   msi_desc ? msi_desc->dev : NULL);
+

Nit: I would remove the extra space here, but that's a question of taste...

I wonder if long term we could make this cleaner, maybe by moving the unbind so it always happen in the context of the caller of the destroy hypercall instead of in the RCU context?

Thanks, Roger.

#3 lore raw
Quoted 28 lines · Roger Pau Monné
Quoted 27 lines · Jason Andryuk

xsm_unmap_domain_irq was seen denying unmap_domain_pirq when called from complete_domain_destroy as an RCU callback. The source context was an unexpected, random domain. Since this is a xen-internal operation, going through the XSM hook is inapproriate.

Check d->is_dying and skip the XSM hook when set since this is a cleanup operation for a domain being destroyed.

---
v2:
Style fixes
Rely on ret=0 initialization

---
 xen/arch/x86/irq.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
xen/arch/x86/irq.c +0 -0
index 285ac399fb..de30ee7779 100644
@@ -2340,8 +2340,14 @@ int unmap_domain_pirq(struct domain *d, int pirq)
         nr = msi_desc->msi.nvec;
     }
 
Quoted 13 lines

xen/arch/x86/irq.c int unmap_domain_pirq(struct domain *d, int pirq) · line 2350

Quoted 10 lines
xen/arch/x86/irq.c +8 -2
-    ret = xsm_unmap_domain_irq(XSM_HOOK, d, irq,
-                               msi_desc ? msi_desc->dev : NULL);
+    /*
+     * When called by complete_domain_destroy via RCU, current is a random
+     * domain.  Skip the XSM check since this is a Xen-initiated action.
+     */
+    if ( !d->is_dying )
+        ret = xsm_unmap_domain_irq(XSM_HOOK, d, irq,
+                                   msi_desc ? msi_desc->dev : NULL);
+

Nit: I would remove the extra space here, but that's a question of taste...

Which extra space are you referring to? The only candidate I can spot are the two adjacent spaces in the comment, between the two sentences. But that's several lines up. And I think we have examples of both single and double spaces in the code base for such cases. I know I'm not even consistent myself in this regard - the longer a comment gets, the more likely I am to use two spaces between sentences.

Quoted 5 lines

I wonder if long term we could make this cleaner, maybe by moving the unbind so it always happen in the context of the caller of the destroy hypercall instead of in the RCU context?

This would be nice, but when I looked at this long ago it didn't seem straightforward to achieve.

Jan

#4 lore raw
Quoted 29 lines · Jan Beulich
Quoted 28 lines · Roger Pau Monné
Quoted 27 lines · Jason Andryuk

xsm_unmap_domain_irq was seen denying unmap_domain_pirq when called from complete_domain_destroy as an RCU callback. The source context was an unexpected, random domain. Since this is a xen-internal operation, going through the XSM hook is inapproriate.

Check d->is_dying and skip the XSM hook when set since this is a cleanup operation for a domain being destroyed.

---
v2:
Style fixes
Rely on ret=0 initialization

---
 xen/arch/x86/irq.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
xen/arch/x86/irq.c +0 -0
index 285ac399fb..de30ee7779 100644
@@ -2340,8 +2340,14 @@ int unmap_domain_pirq(struct domain *d, int pirq)
         nr = msi_desc->msi.nvec;
     }
 
Quoted 13 lines
Quoted 11 lines

xen/arch/x86/irq.c int unmap_domain_pirq(struct domain *d, int pirq) · line 2350

Quoted 10 lines
xen/arch/x86/irq.c +8 -2
-    ret = xsm_unmap_domain_irq(XSM_HOOK, d, irq,
-                               msi_desc ? msi_desc->dev : NULL);
+    /*
+     * When called by complete_domain_destroy via RCU, current is a random
+     * domain.  Skip the XSM check since this is a Xen-initiated action.
+     */
+    if ( !d->is_dying )
+        ret = xsm_unmap_domain_irq(XSM_HOOK, d, irq,
+                                   msi_desc ? msi_desc->dev : NULL);
+
Quoted 2 lines

Nit: I would remove the extra space here, but that's a question of taste...

Er, sorry, s/space/newline/.

Quoted 7 lines

Which extra space are you referring to? The only candidate I can spot are the two adjacent spaces in the comment, between the two sentences. But that's several lines up. And I think we have examples of both single and double spaces in the code base for such cases. I know I'm not even consistent myself in this regard - the longer a comment gets, the more likely I am to use two spaces between sentences.

Quoted 8 lines
Quoted 5 lines

I wonder if long term we could make this cleaner, maybe by moving the unbind so it always happen in the context of the caller of the destroy hypercall instead of in the RCU context?

This would be nice, but when I looked at this long ago it didn't seem straightforward to achieve.

Right, I don't doubt it.

Thanks, Roger.