Skip to contentSkip to conversation

target/ppc: Do not clear MSR[ME] on MCE interrupts to supervisor

PATCH In review Nicholas Piggin 2 participants 2 messages Mar 21, 2024 – Mar 22, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/ppc: Do not clear MSR[ME] on MCE interrupts to supervisor

Hardware clears the MSR[ME] bit when delivering a machine check interrupt, so that is what QEMU does.

The spapr environment runs in supervisor mode though, and receives machine check interrupts after they are processed by the hypervisor, and MSR[ME] must always be enabled in supervisor mode (otherwise it could checkstop the system). So MSR[ME] must not be cleared when delivering machine checks to the supervisor.

The fix to prevent supervisor mode from modifying MSR[ME] also prevented it from re-enabling the incorrectly cleared MSR[ME] bit when returning from handling the interrupt. Before that fix, the problem was not very noticable with well-behaved code. So the Fixes tag is not strictly correct, but practically they go together.

Found by kvm-unit-tests machine check tests (not yet upstream).

Fixes 678b6f1af75ef ("target/ppc: Prevent supervisor from modifying MSR[ME]")
---
 target/ppc/excp_helper.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
target/ppc/excp_helper.c +3 -2
index 80f584f933..674c05a2ce 100644
@@ -1345,9 +1345,10 @@ static void powerpc_excp_books(PowerPCCPU *cpu, int excp)
              * clear (e.g., see FWNMI in PAPR).
              */
             new_msr |= (target_ulong)MSR_HVB;
+
+            /* HV machine check exceptions don't have ME set */
+            new_msr &= ~((target_ulong)1 << MSR_ME);
         }
-        /* machine check exceptions don't have ME set */
-        new_msr &= ~((target_ulong)1 << MSR_ME);
 
         msr |= env->error_code;
         break;
Signature · 1 line
2.42.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Nicholas Piggin

Hardware clears the MSR[ME] bit when delivering a machine check interrupt, so that is what QEMU does.

The spapr environment runs in supervisor mode though, and receives machine check interrupts after they are processed by the hypervisor, and MSR[ME] must always be enabled in supervisor mode (otherwise it could checkstop the system). So MSR[ME] must not be cleared when delivering machine checks to the supervisor.

The fix to prevent supervisor mode from modifying MSR[ME] also prevented it from re-enabling the incorrectly cleared MSR[ME] bit when returning from handling the interrupt. Before that fix, the problem was not very noticable with well-behaved code. So the Fixes tag is not strictly correct, but practically they go together.

Quoted 4 lines

Found by kvm-unit-tests machine check tests (not yet upstream).

Fixes 678b6f1af75ef ("target/ppc: Prevent supervisor from modifying MSR[ME]")
Quoted 21 lines
---
  target/ppc/excp_helper.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
target/ppc/excp_helper.c +3 -2
index 80f584f933..674c05a2ce 100644
@@ -1345,9 +1345,10 @@ static void powerpc_excp_books(PowerPCCPU *cpu, int excp)
               * clear (e.g., see FWNMI in PAPR).
               */
              new_msr |= (target_ulong)MSR_HVB;
+
+            /* HV machine check exceptions don't have ME set */
+            new_msr &= ~((target_ulong)1 << MSR_ME);
          }
-        /* machine check exceptions don't have ME set */
-        new_msr &= ~((target_ulong)1 << MSR_ME);
 
          msr |= env->error_code;
          break;