Skip to contentSkip to conversation

x86/pv: Improve code generation in async_exception_cleanup()

PATCH In review Andrew Cooper 2 participants 4 messages Nov 2 – Nov 4

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/pv: Improve code generation in async_exception_cleanup()

Use new helper functions to simplfiy the logic. This removes an alternative behind the scenes.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>

async_exception_cleanup() is complete nonsense. It's not remotely close to how interupt blocking works in x86.

---
 xen/arch/x86/pv/iret.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/pv/iret.c +2 -2
index 39ce316b8d91..0efc0c7f12f3 100644
@@ -31,8 +31,8 @@ static void async_exception_cleanup(struct vcpu *curr)
     if ( !curr->arch.async_exception_mask )
         return;
 
-    if ( !(curr->arch.async_exception_mask & (curr->arch.async_exception_mask - 1)) )
-        trap = __scanbit(curr->arch.async_exception_mask, VCPU_TRAP_NONE);
+    if ( !multiple_bits_set(curr->arch.async_exception_mask) )
+        trap = ffs(curr->arch.async_exception_mask) + 1;
     else
         for ( trap = VCPU_TRAP_NONE + 1; trap <= VCPU_TRAP_LAST; ++trap )
             if ( (curr->arch.async_exception_mask ^
Signature · 1 line
2.39.5
#1 lore raw
Quoted 22 lines · Andrew Cooper

Use new helper functions to simplfiy the logic. This removes an alternative behind the scenes.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>

async_exception_cleanup() is complete nonsense. It's not remotely close to how interupt blocking works in x86.

---
 xen/arch/x86/pv/iret.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/pv/iret.c +0 -0
index 39ce316b8d91..0efc0c7f12f3 100644

xen/arch/x86/pv/iret.c static void async_exception_cleanup(struct vcpu *curr) · line 35

Quoted 7 lines
xen/arch/x86/pv/iret.c +2 -2
@@ -31,8 +31,8 @@ static void async_exception_cleanup(struct vcpu *curr)
     if ( !curr->arch.async_exception_mask )
         return;
 
-    if ( !(curr->arch.async_exception_mask & (curr->arch.async_exception_mask - 1)) )
-        trap = __scanbit(curr->arch.async_exception_mask, VCPU_TRAP_NONE);
+    if ( !multiple_bits_set(curr->arch.async_exception_mask) )
+        trap = ffs(curr->arch.async_exception_mask) + 1;

This should of course be a -1 rather than +1.  Fixed locally.

~Andrew

Acked-by
#2 lore raw
Quoted 3 lines · Andrew Cooper
Quoted 2 lines · Andrew Cooper

Use new helper functions to simplfiy the logic. This removes an alternative behind the scenes.

Does it? __scanbit() engages an alternative only when its 2nd argument is BITS_PER_LONG.

Quoted 10 lines
Quoted 10 lines

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>

async_exception_cleanup() is complete nonsense. It's not remotely close to how interupt blocking works in x86.

Are you perhaps expecting something that (for PV) was never intended?

Quoted 6 lines
Quoted 6 lines
xen/arch/x86/pv/iret.c +0 -0
@@ -31,8 +31,8 @@ static void async_exception_cleanup(struct vcpu *curr)
     if ( !curr->arch.async_exception_mask )
         return;
 
Quoted 6 lines

xen/arch/x86/pv/iret.c static void async_exception_cleanup(struct vcpu *curr) · line 35

Quoted 4 lines
xen/arch/x86/pv/iret.c +2 -2
-    if ( !(curr->arch.async_exception_mask & (curr->arch.async_exception_mask - 1)) )
-        trap = __scanbit(curr->arch.async_exception_mask, VCPU_TRAP_NONE);
+    if ( !multiple_bits_set(curr->arch.async_exception_mask) )
+        trap = ffs(curr->arch.async_exception_mask) + 1;

This should of course be a -1 rather than +1.  Fixed locally.

(with the description corrected or you pointing out which other alternative you mean)

Jan

#3 lore raw
Quoted 6 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper
Quoted 2 lines · Andrew Cooper

Use new helper functions to simplfiy the logic. This removes an alternative behind the scenes.

Does it? __scanbit() engages an alternative only when its 2nd argument is BITS_PER_LONG.

Oh, yes.  I'll drop that sentence.

Quoted 11 lines
Quoted 10 lines
Quoted 10 lines

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>

async_exception_cleanup() is complete nonsense. It's not remotely close to how interupt blocking works in x86.

Are you perhaps expecting something that (for PV) was never intended?

I've long since given up being surprised at PV doing bizarre things.

This async_exception_state[].pending is used for HVM guests; this aspect does need to change.

async_exception_state[].old_mask is specific to PV and, AFAICT, interlocks both NMI and #MC together so they nest, with HYPERCALL_iret "refcounts" the unwinding.

Architecturally, NMIs are blocked until the next sequential IRET, while #MC has no blocking capabilities at all.

PV guests behaving the way they do violates the principle of least surprise.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/pv/iret.c +0 -0
@@ -31,8 +31,8 @@ static void async_exception_cleanup(struct vcpu *curr)
     if ( !curr->arch.async_exception_mask )
         return;
 
Quoted 8 lines
Quoted 5 lines

xen/arch/x86/pv/iret.c static void async_exception_cleanup(struct vcpu *curr) · line 35

Quoted 4 lines
xen/arch/x86/pv/iret.c +2 -2
-    if ( !(curr->arch.async_exception_mask & (curr->arch.async_exception_mask - 1)) )
-        trap = __scanbit(curr->arch.async_exception_mask, VCPU_TRAP_NONE);
+    if ( !multiple_bits_set(curr->arch.async_exception_mask) )
+        trap = ffs(curr->arch.async_exception_mask) + 1;

This should of course be a -1 rather than +1.  Fixed locally.

(with the description corrected or you pointing out which other alternative you mean)

Thanks.

~Andrew