Skip to contentSkip to conversation

x86/vmx: reorder code in vmx_deliver_posted_intr

PATCH In review Roger Pau Monne 3 participants 4 messages Jul 30, 2020 – Aug 14, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/vmx: reorder code in vmx_deliver_posted_intr

Remove the unneeded else branch, which allows to reduce the indentation of a larger block of code, while making the flow of the function more obvious.

No functional change intended.

---
 xen/arch/x86/hvm/vmx/vmx.c | 55 ++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 29 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +26 -29
index eb54aadfba..7773dcae1b 100644
@@ -2003,6 +2003,8 @@ static void __vmx_deliver_posted_interrupt(struct vcpu *v)
 
 static void vmx_deliver_posted_intr(struct vcpu *v, u8 vector)
 {
+    struct pi_desc old, new, prev;
+
     if ( pi_test_and_set_pir(vector, &v->arch.hvm.vmx.pi_desc) )
         return;
 
@@ -2014,41 +2016,36 @@ static void vmx_deliver_posted_intr(struct vcpu *v, u8 vector)
          * VMEntry as it used to be.
          */
         pi_set_on(&v->arch.hvm.vmx.pi_desc);
+        vcpu_kick(v);
+        return;
     }
-    else
-    {
-        struct pi_desc old, new, prev;
 
-        prev.control = v->arch.hvm.vmx.pi_desc.control;
+    prev.control = v->arch.hvm.vmx.pi_desc.control;
 
-        do {
-            /*
-             * Currently, we don't support urgent interrupt, all
-             * interrupts are recognized as non-urgent interrupt,
-             * Besides that, if 'ON' is already set, no need to
-             * sent posted-interrupts notification event as well,
-             * according to hardware behavior.
-             */
-            if ( pi_test_sn(&prev) || pi_test_on(&prev) )
-            {
-                vcpu_kick(v);
-                return;
-            }
-
-            old.control = v->arch.hvm.vmx.pi_desc.control &
-                          ~((1 << POSTED_INTR_ON) | (1 << POSTED_INTR_SN));
-            new.control = v->arch.hvm.vmx.pi_desc.control |
-                          (1 << POSTED_INTR_ON);
+    do {
+        /*
+         * Currently, we don't support urgent interrupt, all
+         * interrupts are recognized as non-urgent interrupt,
+         * Besides that, if 'ON' is already set, no need to
+         * sent posted-interrupts notification event as well,
+         * according to hardware behavior.
+         */
+        if ( pi_test_sn(&prev) || pi_test_on(&prev) )
+        {
+            vcpu_kick(v);
+            return;
+        }
 
-            prev.control = cmpxchg(&v->arch.hvm.vmx.pi_desc.control,
-                                   old.control, new.control);
-        } while ( prev.control != old.control );
+        old.control = v->arch.hvm.vmx.pi_desc.control &
+                      ~((1 << POSTED_INTR_ON) | (1 << POSTED_INTR_SN));
+        new.control = v->arch.hvm.vmx.pi_desc.control |
+                      (1 << POSTED_INTR_ON);
 
-        __vmx_deliver_posted_interrupt(v);
-        return;
-    }
+        prev.control = cmpxchg(&v->arch.hvm.vmx.pi_desc.control,
+                               old.control, new.control);
+    } while ( prev.control != old.control );
 
-    vcpu_kick(v);
+    __vmx_deliver_posted_interrupt(v);
 }
 
 static void vmx_sync_pir_to_irr(struct vcpu *v)
Signature · 1 line
2.28.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Roger Pau Monne

Remove the unneeded else branch, which allows to reduce the indentation of a larger block of code, while making the flow of the function more obvious.

No functional change intended.

One minor request (could likely be taken care of while committing):

Quoted 30 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -20
@@ -2014,41 +2016,36 @@ static void vmx_deliver_posted_intr(struct vcpu *v, u8 vector)
          * VMEntry as it used to be.
          */
         pi_set_on(&v->arch.hvm.vmx.pi_desc);
+        vcpu_kick(v);
+        return;
     }
-    else
-    {
-        struct pi_desc old, new, prev;
 
-        prev.control = v->arch.hvm.vmx.pi_desc.control;
+    prev.control = v->arch.hvm.vmx.pi_desc.control;
 
-        do {
-            /*
-             * Currently, we don't support urgent interrupt, all
-             * interrupts are recognized as non-urgent interrupt,
-             * Besides that, if 'ON' is already set, no need to
-             * sent posted-interrupts notification event as well,
-             * according to hardware behavior.
-             */
-            if ( pi_test_sn(&prev) || pi_test_on(&prev) )
-            {
-                vcpu_kick(v);
-                return;
-            }
-
-            old.control = v->arch.hvm.vmx.pi_desc.control &
-                          ~((1 << POSTED_INTR_ON) | (1 << POSTED_INTR_SN));

xen/arch/x86/hvm/vmx/vmx.c static void vmx_deliver_posted_intr(struct vcpu *v, u8 vector) · line 2032

Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +8 -2
-            new.control = v->arch.hvm.vmx.pi_desc.control |
-                          (1 << POSTED_INTR_ON);
+    do {
+        /*
+         * Currently, we don't support urgent interrupt, all
+         * interrupts are recognized as non-urgent interrupt,
+         * Besides that, if 'ON' is already set, no need to
+         * sent posted-interrupts notification event as well,
+         * according to hardware behavior.
+         */

Would be nice to s/sent/send/ here as you move it (maybe also remove the plural from "posted-interrupts") and - if possible - re-flow for the now increased space on the right side.

Jan

#2 lore raw
Quoted 50 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne

Remove the unneeded else branch, which allows to reduce the indentation of a larger block of code, while making the flow of the function more obvious.

No functional change intended.

One minor request (could likely be taken care of while committing):

Quoted 36 lines
xen/arch/x86/hvm/vmx/vmx.c +7 -22
@@ -2014,41 +2016,36 @@ static void vmx_deliver_posted_intr(struct vcpu *v, u8 vector)
          * VMEntry as it used to be.
          */
         pi_set_on(&v->arch.hvm.vmx.pi_desc);
+        vcpu_kick(v);
+        return;
     }
-    else
-    {
-        struct pi_desc old, new, prev;
 
-        prev.control = v->arch.hvm.vmx.pi_desc.control;
+    prev.control = v->arch.hvm.vmx.pi_desc.control;
 
-        do {
-            /*
-             * Currently, we don't support urgent interrupt, all
-             * interrupts are recognized as non-urgent interrupt,
-             * Besides that, if 'ON' is already set, no need to
-             * sent posted-interrupts notification event as well,
-             * according to hardware behavior.
-             */
-            if ( pi_test_sn(&prev) || pi_test_on(&prev) )
-            {
-                vcpu_kick(v);
-                return;
-            }
-
-            old.control = v->arch.hvm.vmx.pi_desc.control &
-                          ~((1 << POSTED_INTR_ON) | (1 << POSTED_INTR_SN));
-            new.control = v->arch.hvm.vmx.pi_desc.control |
-                          (1 << POSTED_INTR_ON);
+    do {
+        /*
+         * Currently, we don't support urgent interrupt, all
+         * interrupts are recognized as non-urgent interrupt,
Quoted 8 lines

xen/arch/x86/hvm/vmx/vmx.c static void vmx_deliver_posted_intr(struct vcpu *v, u8 vector) · line 2032

Quoted 4 lines
xen/arch/x86/hvm/vmx/vmx.c +4 -0
+         * Besides that, if 'ON' is already set, no need to
+         * sent posted-interrupts notification event as well,
+         * according to hardware behavior.
+         */

Would be nice to s/sent/send/ here as you move it (maybe also remove the plural from "posted-interrupts") and - if possible - re-flow for the now increased space on the right side.

Oh, sure, I should have realized myself. Feel free to adjust at commit if you don't mind. I would also adjust 'non-urgent interrupts'.

Thanks, Roger.

Reviewed-by on v1 1/1
#3 lore raw
In reply to Roger Pau Monne
Quoted 10 lines

From: Roger Pau Monne <[email protected]>
Sent: Thursday, July 30, 2020 10:03 PM

Remove the unneeded else branch, which allows to reduce the indentation of a larger block of code, while making the flow of the function more obvious.

No functional change intended.

Quoted 87 lines
---
 xen/arch/x86/hvm/vmx/vmx.c | 55 ++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 29 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +26 -29
index eb54aadfba..7773dcae1b 100644
@@ -2003,6 +2003,8 @@ static void __vmx_deliver_posted_interrupt(struct
 vcpu *v)
 
 static void vmx_deliver_posted_intr(struct vcpu *v, u8 vector)
 {
+    struct pi_desc old, new, prev;
+
     if ( pi_test_and_set_pir(vector, &v->arch.hvm.vmx.pi_desc) )
         return;
@@ -2014,41 +2016,36 @@ static void vmx_deliver_posted_intr(struct vcpu
 *v, u8 vector)
          * VMEntry as it used to be.
          */
         pi_set_on(&v->arch.hvm.vmx.pi_desc);
+        vcpu_kick(v);
+        return;
     }
-    else
-    {
-        struct pi_desc old, new, prev;
 
-        prev.control = v->arch.hvm.vmx.pi_desc.control;
+    prev.control = v->arch.hvm.vmx.pi_desc.control;
 
-        do {
-            /*
-             * Currently, we don't support urgent interrupt, all
-             * interrupts are recognized as non-urgent interrupt,
-             * Besides that, if 'ON' is already set, no need to
-             * sent posted-interrupts notification event as well,
-             * according to hardware behavior.
-             */
-            if ( pi_test_sn(&prev) || pi_test_on(&prev) )
-            {
-                vcpu_kick(v);
-                return;
-            }
-
-            old.control = v->arch.hvm.vmx.pi_desc.control &
-                          ~((1 << POSTED_INTR_ON) | (1 << POSTED_INTR_SN));
-            new.control = v->arch.hvm.vmx.pi_desc.control |
-                          (1 << POSTED_INTR_ON);
+    do {
+        /*
+         * Currently, we don't support urgent interrupt, all
+         * interrupts are recognized as non-urgent interrupt,
+         * Besides that, if 'ON' is already set, no need to
+         * sent posted-interrupts notification event as well,
+         * according to hardware behavior.
+         */
+        if ( pi_test_sn(&prev) || pi_test_on(&prev) )
+        {
+            vcpu_kick(v);
+            return;
+        }
 
-            prev.control = cmpxchg(&v->arch.hvm.vmx.pi_desc.control,
-                                   old.control, new.control);
-        } while ( prev.control != old.control );
+        old.control = v->arch.hvm.vmx.pi_desc.control &
+                      ~((1 << POSTED_INTR_ON) | (1 << POSTED_INTR_SN));
+        new.control = v->arch.hvm.vmx.pi_desc.control |
+                      (1 << POSTED_INTR_ON);
 
-        __vmx_deliver_posted_interrupt(v);
-        return;
-    }
+        prev.control = cmpxchg(&v->arch.hvm.vmx.pi_desc.control,
+                               old.control, new.control);
+    } while ( prev.control != old.control );
 
-    vcpu_kick(v);
+    __vmx_deliver_posted_interrupt(v);
 }
 

static void vmx_sync_pir_to_irr(struct vcpu *v)
--
2.28.0