Blame SOURCES/kvm-spapr-Set-LPCR-to-current-AIL-mode-when-starting-a-n.patch

1072c8
From 28794dca79a94d01c8732b84fe6ac6ba2986ce45 Mon Sep 17 00:00:00 2001
1072c8
From: Laurent Vivier <lvivier@redhat.com>
1072c8
Date: Wed, 9 Jun 2021 10:05:01 -0400
1072c8
Subject: [PATCH 4/4] spapr: Set LPCR to current AIL mode when starting a new
1072c8
 CPU
1072c8
MIME-Version: 1.0
1072c8
Content-Type: text/plain; charset=UTF-8
1072c8
Content-Transfer-Encoding: 8bit
1072c8
1072c8
RH-Author: Laurent Vivier <lvivier@redhat.com>
1072c8
Message-id: <20210609100501.427096-3-lvivier@redhat.com>
1072c8
Patchwork-id: 101683
1072c8
O-Subject: [RHEL-8.5.0 qemu-kvm PATCH 2/2] spapr: Set LPCR to current AIL mode when starting a new CPU
1072c8
Bugzilla: 1969768
1072c8
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
1072c8
RH-Acked-by: David Gibson <dgibson@redhat.com>
1072c8
RH-Acked-by: Greg Kurz <gkurz@redhat.com>
1072c8
1072c8
From: Nicholas Piggin <npiggin@gmail.com>
1072c8
1072c8
TCG does not keep track of AIL mode in a central place, it's based on
1072c8
the current LPCR[AIL] bits. Synchronize the new CPU's LPCR to the
1072c8
current LPCR in rtas_start_cpu(), similarly to the way the ILE bit is
1072c8
synchronized.
1072c8
1072c8
Open-code the ILE setting as well now that the caller's LPCR is
1072c8
available directly, there is no need for the indirection.
1072c8
1072c8
Without this, under both TCG and KVM, adding a POWER8/9/10 class CPU
1072c8
with a new core ID after a modern Linux has booted results in the new
1072c8
CPU's LPCR missing the LPCR[AIL]=0b11 setting that the other CPUs have.
1072c8
This can cause crashes and unexpected behaviour.
1072c8
1072c8
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
1072c8
Message-Id: <20210526091626.3388262-3-npiggin@gmail.com>
1072c8
Reviewed-by: Cédric Le Goater <clg@kaod.org>
1072c8
Reviewed-by: Greg Kurz <groug@kaod.org>
1072c8
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
1072c8
(cherry picked from commit ac559ecbea2649819e7b3fdd09f4e0243e0128db)
1072c8
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
1072c8
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
1072c8
---
1072c8
 hw/ppc/spapr_rtas.c | 14 +++++++++-----
1072c8
 1 file changed, 9 insertions(+), 5 deletions(-)
1072c8
1072c8
diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
1072c8
index 295eac986e..5acb7c1f10 100644
1072c8
--- a/hw/ppc/spapr_rtas.c
1072c8
+++ b/hw/ppc/spapr_rtas.c
1072c8
@@ -132,8 +132,8 @@ static void rtas_start_cpu(PowerPCCPU *callcpu, SpaprMachineState *spapr,
1072c8
     target_ulong id, start, r3;
1072c8
     PowerPCCPU *newcpu;
1072c8
     CPUPPCState *env;
1072c8
-    PowerPCCPUClass *pcc;
1072c8
     target_ulong lpcr;
1072c8
+    target_ulong caller_lpcr;
1072c8
 
1072c8
     if (nargs != 3 || nret != 1) {
1072c8
         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
1072c8
@@ -152,7 +152,6 @@ static void rtas_start_cpu(PowerPCCPU *callcpu, SpaprMachineState *spapr,
1072c8
     }
1072c8
 
1072c8
     env = &newcpu->env;
1072c8
-    pcc = POWERPC_CPU_GET_CLASS(newcpu);
1072c8
 
1072c8
     if (!CPU(newcpu)->halted) {
1072c8
         rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
1072c8
@@ -163,10 +162,15 @@ static void rtas_start_cpu(PowerPCCPU *callcpu, SpaprMachineState *spapr,
1072c8
 
1072c8
     env->msr = (1ULL << MSR_SF) | (1ULL << MSR_ME);
1072c8
 
1072c8
+    caller_lpcr = callcpu->env.spr[SPR_LPCR];
1072c8
     lpcr = env->spr[SPR_LPCR];
1072c8
-    if (!pcc->interrupts_big_endian(callcpu)) {
1072c8
-        lpcr |= LPCR_ILE;
1072c8
-    }
1072c8
+
1072c8
+    /* Set ILE the same way */
1072c8
+    lpcr = (lpcr & ~LPCR_ILE) | (caller_lpcr & LPCR_ILE);
1072c8
+
1072c8
+    /* Set AIL the same way */
1072c8
+    lpcr = (lpcr & ~LPCR_AIL) | (caller_lpcr & LPCR_AIL);
1072c8
+
1072c8
     if (env->mmu_model == POWERPC_MMU_3_00) {
1072c8
         /*
1072c8
          * New cpus are expected to start in the same radix/hash mode
1072c8
-- 
1072c8
2.27.0
1072c8