Skip to contentSkip to conversation

hw/intc/arm_gicv3_cpuif: Tolerate spurious EOIR writes

PATCH Superseded Jean-Philippe Brucker 4 participants 5 messages Jun 3, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/intc/arm_gicv3_cpuif: Tolerate spurious EOIR writes

Commit 382c7160d1cd ("hw/intc/arm_gicv3_cpuif: Fix EOIR write access check logic") added an assert_not_reached() if the guest writes the EOIR register while no interrupt is active.

It turns out some software does this: EDK2, in GicV3ExitBootServicesEvent(), unconditionally write EOIR for all interrupts that it manages. This now causes QEMU to abort when running UEFI on a VM with GICv3. Although it is UNPREDICTABLE behavior and EDK2 does need fixing, the punishment seems a little harsh, especially since icc_eoir_write() already tolerates writes of nonexistent interrupt numbers. Simply ignore spurious EOIR writes.

Fixes 382c7160d1cd ("hw/intc/arm_gicv3_cpuif: Fix EOIR write access check logic")
---
 hw/intc/arm_gicv3_cpuif.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/intc/arm_gicv3_cpuif.c +2 -1
index 81f94c7f4a..1d0964c9bf 100644
@@ -1357,7 +1357,8 @@ static void icc_eoir_write(CPUARMState *env, const ARMCPRegInfo *ri,
         }
         break;
     default:
-        g_assert_not_reached();
+        /* No interrupt was active, this is UNPREDICTABLE. Ignore it. */
+        return;
     }
 
     icc_drop_prio(cs, grp);
Signature · 1 line
2.31.1
#1 lore raw

Hi Jean-Philippe,

Quoted 23 lines · Jean-Philippe Brucker

Commit 382c7160d1cd ("hw/intc/arm_gicv3_cpuif: Fix EOIR write access check logic") added an assert_not_reached() if the guest writes the EOIR register while no interrupt is active.

It turns out some software does this: EDK2, in GicV3ExitBootServicesEvent(), unconditionally write EOIR for all interrupts that it manages. This now causes QEMU to abort when running UEFI on a VM with GICv3. Although it is UNPREDICTABLE behavior and EDK2 does need fixing, the punishment seems a little harsh, especially since icc_eoir_write() already tolerates writes of nonexistent interrupt numbers. Simply ignore spurious EOIR writes.

Fixes 382c7160d1cd ("hw/intc/arm_gicv3_cpuif: Fix EOIR write access check logic")
---
 hw/intc/arm_gicv3_cpuif.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/intc/arm_gicv3_cpuif.c +0 -0
index 81f94c7f4a..1d0964c9bf 100644

hw/intc/arm_gicv3_cpuif.c static void icc_eoir_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 1360

Quoted 5 lines
hw/intc/arm_gicv3_cpuif.c +1 -1
@@ -1357,7 +1357,8 @@ static void icc_eoir_write(CPUARMState *env, const ARMCPRegInfo *ri,
         }
         break;
     default:
-        g_assert_not_reached();
+        /* No interrupt was active, this is UNPREDICTABLE. Ignore it. */

A qemu_log_mask(LOG_GUEST_ERROR, ...) call here could be useful, do you mind adding it?

Quoted 5 lines
hw/intc/arm_gicv3_cpuif.c +1 -0
+        return;
     }
 
     icc_drop_prio(cs, grp);
#2 lore raw
Quoted 5 lines · Philippe Mathieu-Daudé
Quoted 5 lines
hw/intc/arm_gicv3_cpuif.c +0 -0
index 81f94c7f4a..1d0964c9bf 100644
@@ -1357,7 +1357,8 @@ static void icc_eoir_write(CPUARMState *env, const ARMCPRegInfo *ri,
Quoted 8 lines

hw/intc/arm_gicv3_cpuif.c static void icc_eoir_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 1360

Quoted 5 lines
hw/intc/arm_gicv3_cpuif.c +1 -1
         }
         break;
     default:
-        g_assert_not_reached();
+        /* No interrupt was active, this is UNPREDICTABLE. Ignore it. */

A qemu_log_mask(LOG_GUEST_ERROR, ...) call here could be useful, do you mind adding it?

No problem. I had it at first, but then wondered if that meant I should update similar cases in the GIC device that silently ignore guest errors at the moment (e.g. the guest writes a number > 1023 to EOIR) and decided against it. I'll resend with only this error report if there is no objection.

Thanks,
Jean

Quoted 6 lines
Quoted 5 lines
hw/intc/arm_gicv3_cpuif.c +1 -0
+        return;
     }
 
     icc_drop_prio(cs, grp);
Reviewed-by on v1 1/1
#3 lore raw
In reply to Jean-Philippe Brucker
Quoted 24 lines · Jean-Philippe Brucker

Commit 382c7160d1cd ("hw/intc/arm_gicv3_cpuif: Fix EOIR write access check logic") added an assert_not_reached() if the guest writes the EOIR register while no interrupt is active.

It turns out some software does this: EDK2, in GicV3ExitBootServicesEvent(), unconditionally write EOIR for all interrupts that it manages. This now causes QEMU to abort when running UEFI on a VM with GICv3. Although it is UNPREDICTABLE behavior and EDK2 does need fixing, the punishment seems a little harsh, especially since icc_eoir_write() already tolerates writes of nonexistent interrupt numbers. Simply ignore spurious EOIR writes.

Fixes 382c7160d1cd ("hw/intc/arm_gicv3_cpuif: Fix EOIR write access check logic")
---
 hw/intc/arm_gicv3_cpuif.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/intc/arm_gicv3_cpuif.c +0 -0
index 81f94c7f4a..1d0964c9bf 100644

hw/intc/arm_gicv3_cpuif.c static void icc_eoir_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 1362

Quoted 7 lines
hw/intc/arm_gicv3_cpuif.c +2 -1
@@ -1357,7 +1357,8 @@ static void icc_eoir_write(CPUARMState *env, const ARMCPRegInfo *ri,
         }
         break;
     default:
-        g_assert_not_reached();
+        /* No interrupt was active, this is UNPREDICTABLE. Ignore it. */
+        return;
 

Makes sense (and looking at the comment in icc_highest_active_group() that says "return -1 so the caller ignores the spurious EOI attempt" it is what the code originally intended).

Shashi, I guess this also fixes the assert you were seeing here ?

thanks
-- PMM

#4 lore raw

Yes it does.

Thanks
Shashi

Quoted 43 lines · Peter Maydell
Quoted 26 lines · Jean-Philippe Brucker

Commit 382c7160d1cd ("hw/intc/arm_gicv3_cpuif: Fix EOIR write access check logic") added an assert_not_reached() if the guest writes the EOIR register while no interrupt is active.

It turns out some software does this: EDK2, in GicV3ExitBootServicesEvent(), unconditionally write EOIR for all interrupts that it manages. This now causes QEMU to abort when running UEFI on a VM with GICv3. Although it is UNPREDICTABLE behavior and EDK2 does need fixing, the punishment seems a little harsh, especially since icc_eoir_write() already tolerates writes of nonexistent interrupt numbers. Simply ignore spurious EOIR writes.

Fixes 382c7160d1cd ("hw/intc/arm_gicv3_cpuif: Fix EOIR write access check logic")

---
hw/intc/arm_gicv3_cpuif.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
hw/intc/arm_gicv3_cpuif.c +0 -0
index 81f94c7f4a..1d0964c9bf 100644
@@ -1357,7 +1357,8 @@ static void icc_eoir_write(CPUARMState *env, const ARMCPRegInfo *ri,
 }
 break;
Quoted 5 lines

default:
- g_assert_not_reached();
+ /* No interrupt was active, this is UNPREDICTABLE. Ignore it. */
+ return;

Makes sense (and looking at the comment in icc_highest_active_group() that says "return -1 so the caller ignores the spurious EOI attempt" it is what the code originally intended).

Shashi, I guess this also fixes the assert you were seeing here ? thanks
-- PMM