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

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