Skip to contentSkip to conversation

hw/intc: Handle software disabling of APIC correctly

PATCH Superseded Jay Khandkar 3 participants 6 messages Jul 12, 2022 – Sep 7, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/intc: Handle software disabling of APIC correctly

When the local APIC is in a software disabled state, all local interrupt sources must be masked and all attempts to unmask them should be ignored. Currently, we don't do either. Fix this by handling it correctly in apic_mem_write().

---
 hw/intc/apic.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
hw/intc/apic.c +13 -3
index 3df11c34d6..493c70af62 100644
@@ -792,9 +792,16 @@ static void apic_mem_write(void *opaque, hwaddr addr, uint64_t val,
         s->dest_mode = val >> 28;
         break;
     case 0x0f:
-        s->spurious_vec = val & 0x1ff;
-        apic_update_irq(s);
-        break;
+        {
+            s->spurious_vec = val & 0x1ff;
+            if (!(val & APIC_SPURIO_ENABLED)) {
+                for (int i = 0; i < APIC_LVT_NB; i++) {
+                    s->lvt[i] |= APIC_LVT_MASKED;
+                }
+            }
+            apic_update_irq(s);
+            break;
+        }
     case 0x10 ... 0x17:
     case 0x18 ... 0x1f:
     case 0x20 ... 0x27:
@@ -812,6 +819,9 @@ static void apic_mem_write(void *opaque, hwaddr addr, uint64_t val,
     case 0x32 ... 0x37:
         {
             int n = index - 0x32;
+            if (!(s->spurious_vec & APIC_SPURIO_ENABLED)) {
+                val |= APIC_LVT_MASKED;
+            }
             s->lvt[n] = val;
             if (n == APIC_LVT_TIMER) {
                 apic_timer_update(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
Signature · 1 line
2.37.0
#1 lore raw

Ping?

Quoted 51 lines · On Tue, 12 Jul 2022, 19:49 Jay Khandkar, <[email protected]> wrote:

When the local APIC is in a software disabled state, all local interrupt sources must be masked and all attempts to unmask them should be ignored. Currently, we don't do either. Fix this by handling it correctly in apic_mem_write().

---
 hw/intc/apic.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
hw/intc/apic.c +10 -3
index 3df11c34d6..493c70af62 100644
@@ -792,9 +792,16 @@ static void apic_mem_write(void *opaque, hwaddr addr,
 uint64_t val,
         s->dest_mode = val >> 28;
         break;
     case 0x0f:
-        s->spurious_vec = val & 0x1ff;
-        apic_update_irq(s);
-        break;
+        {
+            s->spurious_vec = val & 0x1ff;
+            if (!(val & APIC_SPURIO_ENABLED)) {
+                for (int i = 0; i < APIC_LVT_NB; i++) {
+                    s->lvt[i] |= APIC_LVT_MASKED;
+                }
+            }
+            apic_update_irq(s);
+            break;
+        }
     case 0x10 ... 0x17:
     case 0x18 ... 0x1f:
     case 0x20 ... 0x27:
hw/intc/apic.c +3 -0
@@ -812,6 +819,9 @@ static void apic_mem_write(void *opaque, hwaddr addr,
 uint64_t val,
     case 0x32 ... 0x37:
         {
             int n = index - 0x32;
+            if (!(s->spurious_vec & APIC_SPURIO_ENABLED)) {
+                val |= APIC_LVT_MASKED;
+            }
             s->lvt[n] = val;
             if (n == APIC_LVT_TIMER) {

apic_timer_update(s,
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
--
2.37.0

#2 lore raw
In reply to Jay Khandkar
Quoted 22 lines · Jay Khandkar

When the local APIC is in a software disabled state, all local interrupt sources must be masked and all attempts to unmask them should be ignored. Currently, we don't do either. Fix this by handling it correctly in apic_mem_write().

---
 hw/intc/apic.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
hw/intc/apic.c +0 -3
index 3df11c34d6..493c70af62 100644
@@ -792,9 +792,16 @@ static void apic_mem_write(void *opaque, hwaddr addr, uint64_t val,
         s->dest_mode = val >> 28;
         break;
     case 0x0f:
-        s->spurious_vec = val & 0x1ff;
-        apic_update_irq(s);
-        break;

hw/intc/apic.c static void apic_mem_write(void *opaque, hwaddr addr, uint64_t val, · line 804

Quoted 10 lines
hw/intc/apic.c +10 -0
+        {
+            s->spurious_vec = val & 0x1ff;
+            if (!(val & APIC_SPURIO_ENABLED)) {
+                for (int i = 0; i < APIC_LVT_NB; i++) {
+                    s->lvt[i] |= APIC_LVT_MASKED;
+                }
+            }
+            apic_update_irq(s);
+            break;
+        }

What are the braces for here ? There's no local variable declaration...

thanks
-- PMM

#3 lore raw
Quoted 36 lines · Peter Maydell
Quoted 22 lines · Jay Khandkar

When the local APIC is in a software disabled state, all local interrupt sources must be masked and all attempts to unmask them should be ignored. Currently, we don't do either. Fix this by handling it correctly in apic_mem_write().

---
 hw/intc/apic.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
hw/intc/apic.c +0 -3
index 3df11c34d6..493c70af62 100644
@@ -792,9 +792,16 @@ static void apic_mem_write(void *opaque, hwaddr addr, uint64_t val,
         s->dest_mode = val >> 28;
         break;
     case 0x0f:
-        s->spurious_vec = val & 0x1ff;
-        apic_update_irq(s);
-        break;

hw/intc/apic.c static void apic_mem_write(void *opaque, hwaddr addr, uint64_t val, · line 804

Quoted 10 lines
hw/intc/apic.c +10 -0
+        {
+            s->spurious_vec = val & 0x1ff;
+            if (!(val & APIC_SPURIO_ENABLED)) {
+                for (int i = 0; i < APIC_LVT_NB; i++) {
+                    s->lvt[i] |= APIC_LVT_MASKED;
+                }
+            }
+            apic_update_irq(s);
+            break;
+        }

What are the braces for here ? There's no local variable declaration...

Quoted 2 lines

thanks
-- PMM

You are right, the braces are unnecessary for that part. I just put them in to create a neat visually separate block. Can get rid of them.

Thanks,
Jay

#4 lore raw
Quoted 37 lines · Jay Khandkar
Quoted 36 lines · Peter Maydell
Quoted 22 lines · Jay Khandkar

When the local APIC is in a software disabled state, all local interrupt sources must be masked and all attempts to unmask them should be ignored. Currently, we don't do either. Fix this by handling it correctly in apic_mem_write().

---
 hw/intc/apic.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
hw/intc/apic.c +0 -3
index 3df11c34d6..493c70af62 100644
@@ -792,9 +792,16 @@ static void apic_mem_write(void *opaque, hwaddr addr, uint64_t val,
         s->dest_mode = val >> 28;
         break;
     case 0x0f:
-        s->spurious_vec = val & 0x1ff;
-        apic_update_irq(s);
-        break;

hw/intc/apic.c static void apic_mem_write(void *opaque, hwaddr addr, uint64_t val, · line 804

Quoted 10 lines
hw/intc/apic.c +10 -0
+        {
+            s->spurious_vec = val & 0x1ff;
+            if (!(val & APIC_SPURIO_ENABLED)) {
+                for (int i = 0; i < APIC_LVT_NB; i++) {
+                    s->lvt[i] |= APIC_LVT_MASKED;
+                }
+            }
+            apic_update_irq(s);
+            break;
+        }

What are the braces for here ? There's no local variable declaration...

Quoted 7 lines
Quoted 2 lines

thanks
-- PMM

You are right, the braces are unnecessary for that part. I just put them in to create a neat visually separate block. Can get rid of them.

Thanks,
Jay

Did you intend to send v2 of this?

Signature · 1 line
MST
#5 lore raw

Have sent in v2.

Quoted 56 lines · Michael S. Tsirkin
Quoted 2 lines · Jay Khandkar
Quoted 1 line · Peter Maydell

On Tue, 12 Jul 2022 at 19:38, Jay Khandkar <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines

When the local APIC is in a software disabled state, all local

interrupt

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

sources must be masked and all attempts to unmask them should be ignored. Currently, we don't do either. Fix this by handling it correctly in apic_mem_write().

---
 hw/intc/apic.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
Quoted 5 lines
Quoted 5 lines

hw/intc/apic.c static void apic_mem_write(void *opaque, hwaddr

Quoted 5 lines
hw/intc/apic.c +0 -0
index 3df11c34d6..493c70af62 100644
@@ -792,9 +792,16 @@ static void apic_mem_write(void *opaque, hwaddr

addr, uint64_t val,

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
hw/intc/apic.c +10 -3
         s->dest_mode = val >> 28;
         break;
     case 0x0f:
-        s->spurious_vec = val & 0x1ff;
-        apic_update_irq(s);
-        break;
+        {
+            s->spurious_vec = val & 0x1ff;
+            if (!(val & APIC_SPURIO_ENABLED)) {
+                for (int i = 0; i < APIC_LVT_NB; i++) {
+                    s->lvt[i] |= APIC_LVT_MASKED;
+                }
+            }
+            apic_update_irq(s);
+            break;
+        }
Quoted 5 lines
Quoted 4 lines

What are the braces for here ? There's no local variable declaration...

thanks
-- PMM

You are right, the braces are unnecessary for that part. I just put them

in to

Quoted 4 lines

create a neat visually separate block. Can get rid of them.

Thanks,
Jay

Did you intend to send v2 of this?

--
MST