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

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