From nobody Sun May 19 01:26:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1594154963; cv=none; d=zohomail.com; s=zohoarc; b=J9qxDZHy3RDWRVzYAzKnlW8CUQFvEYHIc3iW3ERz/1yqvMDouF+Vx7yCVkfP5lOxGG4azye1qwAGHYasqlEqj22QCC+KqfKTBnmgS4JKf4LvyeD4uIyLvgdBNwbSDnBOXV7+k9viVYTfD4tndg78VKdTNCw0idJzNtSxsQQSO7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594154963; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=A3UDqfVxvu7xvpHMLujABKo/O7ANOWCd3jvPWrMZg84=; b=SQ6kBq3aOD+flaQPrIZRavx8fVqg/3NEtjU4qKva+ZNoK0/YealUuo/fIVUR0+cjmLgbf8aUwByNH+IWwAtTMZmJvya+y79T/L8d4RMqm1y5QxD8bpLkVGxLtn4lPyi4ZgH6nCjx3CoyPeRLzF+xV0Fqtf+cyJZPy+mhbZi7rdc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594154963699265.0538703014596; Tue, 7 Jul 2020 13:49:23 -0700 (PDT) Received: from localhost ([::1]:47860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jsuWo-0003xd-6M for importer@patchew.org; Tue, 07 Jul 2020 16:49:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jsuRk-0001Fe-9h; Tue, 07 Jul 2020 16:44:08 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:36266) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jsuRg-0008Bc-S7; Tue, 07 Jul 2020 16:44:07 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 067Kbtsw008917; Tue, 7 Jul 2020 16:43:57 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 324yysrby7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 07 Jul 2020 16:43:57 -0400 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 067KcJsh009800; Tue, 7 Jul 2020 16:43:56 -0400 Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com with ESMTP id 324yysrbxy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 07 Jul 2020 16:43:56 -0400 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 067KegDW026330; Tue, 7 Jul 2020 20:43:56 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma04dal.us.ibm.com with ESMTP id 324bugsur1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 07 Jul 2020 20:43:56 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 067Khtsa15729514 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 7 Jul 2020 20:43:55 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 43947AE060; Tue, 7 Jul 2020 20:43:55 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0CB32AE05C; Tue, 7 Jul 2020 20:43:53 +0000 (GMT) Received: from morokweng.localdomain.com (unknown [9.211.127.86]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 7 Jul 2020 20:43:52 +0000 (GMT) From: Thiago Jung Bauermann To: qemu-ppc@nongnu.org Subject: [PATCH] cpu: Add starts_halted() method Date: Tue, 7 Jul 2020 17:43:33 -0300 Message-Id: <20200707204333.261506-1-bauerman@linux.ibm.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-07-07_13:2020-07-07, 2020-07-07 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 suspectscore=1 priorityscore=1501 lowpriorityscore=0 impostorscore=0 cotscore=-2147483648 malwarescore=0 mlxlogscore=999 adultscore=0 mlxscore=0 spamscore=0 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007070134 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=bauerman@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/07 16:16:33 X-ACL-Warn: Detected OS = Linux 3.x [generic] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thiago Jung Bauermann , Eduardo Habkost , qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" PowerPC sPAPRs CPUs start in the halted state, but generic QEMU code assumes that CPUs start in the non-halted state. spapr_reset_vcpu() attempts to rectify this by setting CPUState::halted to 1. But that's too late for hotplugged CPUs in a machine configured with 2 or mor threads per core. By then, other parts of QEMU have already caused the vCPU to run in an unitialized state a couple of times. For example, ppc_cpu_reset() calls ppc_tlb_invalidate_all(), which ends up calling async_run_on_cpu(). This kicks the new vCPU while it has CPUState::halted =3D 0, causing QEMU to iss= ue a KVM_RUN ioctl on the new vCPU before the guest is able to make the start-cpu RTAS call to initialize its register state. This doesn't seem to cause visible issues for regular guests, but on a secure guest running under the Ultravisor it does. The Ultravisor relies on being able to snoop on the start-cpu RTAS call to map vCPUs to guests, and this issue causes it to see a stray vCPU that doesn't belong to any guest. Fix by adding a starts_halted() method to the CPUState class, and making it return 1 if the machine is an sPAPR guest. Signed-off-by: Thiago Jung Bauermann Tested-by: Thiago Jung Bauermann --- hw/core/cpu.c | 8 +++++++- hw/ppc/spapr_cpu_core.c | 5 ----- include/hw/core/cpu.h | 2 ++ target/ppc/translate_init.inc.c | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/hw/core/cpu.c b/hw/core/cpu.c index 0f23409f1d..8f9a3335d5 100644 --- a/hw/core/cpu.c +++ b/hw/core/cpu.c @@ -259,7 +259,7 @@ static void cpu_common_reset(DeviceState *dev) } =20 cpu->interrupt_request =3D 0; - cpu->halted =3D 0; + cpu->halted =3D cc->starts_halted(); cpu->mem_io_pc =3D 0; cpu->icount_extra =3D 0; atomic_set(&cpu->icount_decr_ptr->u32, 0); @@ -275,6 +275,11 @@ static void cpu_common_reset(DeviceState *dev) } } =20 +static uint32_t cpu_common_starts_halted(void) +{ + return 0; +} + static bool cpu_common_has_work(CPUState *cs) { return false; @@ -428,6 +433,7 @@ static void cpu_class_init(ObjectClass *klass, void *da= ta) k->cpu_exec_exit =3D cpu_common_noop; k->cpu_exec_interrupt =3D cpu_common_exec_interrupt; k->adjust_watchpoint_address =3D cpu_adjust_watchpoint_address; + k->starts_halted =3D cpu_common_starts_halted; set_bit(DEVICE_CATEGORY_CPU, dc->categories); dc->realize =3D cpu_common_realizefn; dc->unrealize =3D cpu_common_unrealizefn; diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 26ad566f42..d0ad92240c 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -36,11 +36,6 @@ static void spapr_reset_vcpu(PowerPCCPU *cpu) =20 cpu_reset(cs); =20 - /* All CPUs start halted. CPU0 is unhalted from the machine level - * reset code and the rest are explicitly started up by the guest - * using an RTAS call */ - cs->halted =3D 1; - env->spr[SPR_HIOR] =3D 0; =20 lpcr =3D env->spr[SPR_LPCR]; diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index b3f4b79318..7c9cd67e8d 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -219,6 +219,8 @@ typedef struct CPUClass { vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len); void (*tcg_initialize)(void); =20 + uint32_t (*starts_halted)(void); + /* Keep non-pointer data at the end to minimize holes. */ int gdb_num_core_regs; bool gdb_stop_before_watchpoint; diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.in= c.c index 49212bfd90..1dc1ebbdaf 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -36,6 +36,7 @@ #include "qapi/visitor.h" #include "hw/qdev-properties.h" #include "hw/ppc/ppc.h" +#include "hw/ppc/spapr.h" #include "mmu-book3s-v3.h" #include "sysemu/qtest.h" #include "qemu/cutils.h" @@ -10646,6 +10647,20 @@ static void ppc_cpu_set_pc(CPUState *cs, vaddr val= ue) cpu->env.nip =3D value; } =20 +static uint32_t ppc_cpu_starts_halted(void) +{ + SpaprMachineState *spapr =3D + (SpaprMachineState *) object_dynamic_cast(qdev_get_machine(), + TYPE_SPAPR_MACHINE); + + /* + * In sPAPR, all CPUs start halted. CPU0 is unhalted from the machine = level + * reset code and the rest are explicitly started up by the guest usin= g an + * RTAS call. + */ + return spapr !=3D NULL; +} + static bool ppc_cpu_has_work(CPUState *cs) { PowerPCCPU *cpu =3D POWERPC_CPU(cs); @@ -10922,6 +10937,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, voi= d *data) #endif =20 cc->disas_set_info =3D ppc_disas_set_info; + cc->starts_halted =3D ppc_cpu_starts_halted; =20 dc->fw_name =3D "PowerPC,UNKNOWN"; }