From nobody Sun Apr 28 10:29:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553830340783754.075907931647; Thu, 28 Mar 2019 20:32:20 -0700 (PDT) Received: from localhost ([127.0.0.1]:45554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iFd-0001M0-Pv for importer@patchew.org; Thu, 28 Mar 2019 23:32:17 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iD5-0007zH-KM for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9iD4-0008Aw-Ky for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:39 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:45945) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9iD3-0008A1-N4; Thu, 28 Mar 2019 23:29:38 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 44VnKT30Zbz9sQm; Fri, 29 Mar 2019 14:29:33 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1553830173; bh=QkDwik9WRfElPQQAOHnTn/+hCzBCVmsi1CmN+0lDd0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h83jM2aGPxABGk7rcSYDOrYmJAt0hLhtiXnZIWNLVXFYInKDNIil4w07G5R3ULHUT 1x302umRwevdfKDct0fj7kWY+5AzmrOJh6baT5mkPPaCtiIji3lvnXpS5qL/eph8F5 uqNtC2DxplTQ41F/tNUhTtXPvxjnPMvAiJ0g7RIg= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 29 Mar 2019 14:29:22 +1100 Message-Id: <20190329032929.21072-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190329032929.21072-1-david@gibson.dropbear.id.au> References: <20190329032929.21072-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 1/8] target/ppc: Fix TCG temporary leaks in gen_bcond() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, Suraj Jitindar Singh , imammedo@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Greg Kurz Signed-off-by: Greg Kurz Message-Id: <155327782047.1283071.10234727692461848972.stgit@bahia.lan> Tested-by: Suraj Jitindar Singh Signed-off-by: David Gibson --- target/ppc/translate.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 98b37cebc2..aaafa3a715 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -3749,6 +3749,8 @@ static void gen_bcond(DisasContext *ctx, int type) TCGv temp =3D tcg_temp_new(); if (unlikely(type =3D=3D BCOND_CTR)) { gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); + tcg_temp_free(temp); + tcg_temp_free(target); return; } tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1); --=20 2.20.1 From nobody Sun Apr 28 10:29:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553830332481964.0926820257104; Thu, 28 Mar 2019 20:32:12 -0700 (PDT) Received: from localhost ([127.0.0.1]:45550 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iFK-00016t-Kk for importer@patchew.org; Thu, 28 Mar 2019 23:31:58 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iD6-0007zs-5l for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9iD5-0008BI-0z for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:40 -0400 Received: from ozlabs.org ([203.11.71.1]:40767) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9iD3-0008A8-Nc; Thu, 28 Mar 2019 23:29:38 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 44VnKT1hVGz9sPS; Fri, 29 Mar 2019 14:29:33 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1553830173; bh=vZGarm0pwNkgaVgSQzugBVCtuJh7nDjwCpOs5A06ktU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aO+/1GhkZlm6oruEAmmm8uo5H41sz7avpARzFi0HjEJc3qD7w2Th/YQZx+7tOtowV Vpf4lnHZ4V9DSERrNmXVLoFi9wpRJ8iEb1j52SBMohdmWDCFvIjJhqe36iARo336Kx iyCjpMvRJwV1moqXx1CDnDUyQX0Cr4jpLJJSTSrM= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 29 Mar 2019 14:29:23 +1100 Message-Id: <20190329032929.21072-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190329032929.21072-1-david@gibson.dropbear.id.au> References: <20190329032929.21072-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PULL 2/8] target/ppc: Enable "decrement and test CTR" version of bcctr X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, Suraj Jitindar Singh , imammedo@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Greg Kurz Even if all ISAs up to v3 indeed mention: If the "decrement and test CTR" option is specified (BO2=3D0), the instruction form is invalid. The UMs of all existing 64-bit server class processors say: If BO[2] =3D 0, the contents of CTR (before any update) are used as the target address and for the test of the contents of CTR to resolve the branch. The contents of the CTR are then decremented and written back to the CTR. The linux kernel has spectre v2 mitigation code that relies on a BO[2] =3D 0 variant of bcctr, which is now activated by default on spapr, even with TCG. This causes linux guests to panic with the default machine type under TCG. Since any CPU model can provide its own behaviour for invalid forms, we could possibly introduce a new instruction flag to handle this. In practice, since the behaviour is shared by all 64-bit server processors starting with 970 up to POWER9, let's reuse the PPC_SEGMENT_64B flag. Caveat: this may have to be fixed later if POWER10 introduces a different behaviour. The existing behaviour of throwing a program interrupt is kept for all other CPU models. Signed-off-by: Greg Kurz Message-Id: <155327782604.1283071.10640596307206921951.stgit@bahia.lan> Tested-by: Suraj Jitindar Singh Signed-off-by: David Gibson --- target/ppc/translate.c | 52 ++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/target/ppc/translate.c b/target/ppc/translate.c index aaafa3a715..d3aaa6482c 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -3747,22 +3747,44 @@ static void gen_bcond(DisasContext *ctx, int type) if ((bo & 0x4) =3D=3D 0) { /* Decrement and test CTR */ TCGv temp =3D tcg_temp_new(); - if (unlikely(type =3D=3D BCOND_CTR)) { - gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); - tcg_temp_free(temp); - tcg_temp_free(target); - return; - } - tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1); - if (NARROW_MODE(ctx)) { - tcg_gen_ext32u_tl(temp, cpu_ctr); - } else { - tcg_gen_mov_tl(temp, cpu_ctr); - } - if (bo & 0x2) { - tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1); + + if (type =3D=3D BCOND_CTR) { + /* + * All ISAs up to v3 describe this form of bcctr as invalid but + * some processors, ie. 64-bit server processors compliant with + * arch 2.x, do implement a "test and decrement" logic instead, + * as described in their respective UMs. + */ + if (unlikely(!(ctx->insns_flags & PPC_SEGMENT_64B))) { + gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); + tcg_temp_free(temp); + tcg_temp_free(target); + return; + } + + if (NARROW_MODE(ctx)) { + tcg_gen_ext32u_tl(temp, cpu_ctr); + } else { + tcg_gen_mov_tl(temp, cpu_ctr); + } + if (bo & 0x2) { + tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1); + } else { + tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1); + } + tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1); } else { - tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1); + tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1); + if (NARROW_MODE(ctx)) { + tcg_gen_ext32u_tl(temp, cpu_ctr); + } else { + tcg_gen_mov_tl(temp, cpu_ctr); + } + if (bo & 0x2) { + tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1); + } else { + tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1); + } } tcg_temp_free(temp); } --=20 2.20.1 From nobody Sun Apr 28 10:29:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553830332467250.21957529871725; Thu, 28 Mar 2019 20:32:12 -0700 (PDT) Received: from localhost ([127.0.0.1]:45552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iFL-00017l-07 for importer@patchew.org; Thu, 28 Mar 2019 23:31:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50720) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iD5-0007zI-PM for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9iD4-0008Aq-Jh for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:39 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:39353) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9iD3-0008A9-T5; Thu, 28 Mar 2019 23:29:38 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 44VnKT48hHz9sPx; Fri, 29 Mar 2019 14:29:33 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1553830173; bh=iqeWr1J5tcMBPok8qbYQ93Kw6JdAolDyMHZmDb1/UuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QfeI1X8aryLVv/djAOS6iUOMgm+ScSiD43zGJGI9f20E2B1HjMrztflp+MnHT5FqM 2P+84V1iyNLeWoZ4ClLr4PzkuoFG/W5BLMzNDHcv9EFoakVivYap8IwRVdc1XXxZ/W afhSJVRYmRYjW9sZJJwVzQrVhd0ej6Sd2r4+L0tE= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 29 Mar 2019 14:29:24 +1100 Message-Id: <20190329032929.21072-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190329032929.21072-1-david@gibson.dropbear.id.au> References: <20190329032929.21072-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 3/8] target/ppc: Consolidate 64-bit server processor detection in a helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, Suraj Jitindar Singh , imammedo@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Greg Kurz We use PPC_SEGMENT_64B in various places to guard code that is specific to 64-bit server processors compliant with arch 2.x. Consolidate the logic in a helper macro with an explicit name. Signed-off-by: Greg Kurz Message-Id: <155327783157.1283071.3747129891004927299.stgit@bahia.lan> Tested-by: Suraj Jitindar Singh Signed-off-by: David Gibson --- hw/ppc/ppc.c | 2 +- target/ppc/cpu.h | 6 ++++++ target/ppc/helper_regs.h | 2 +- target/ppc/translate.c | 10 ++++------ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index 49d57469fb..ad20584f26 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -1101,7 +1101,7 @@ clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint3= 2_t freq) tb_env =3D g_malloc0(sizeof(ppc_tb_t)); env->tb_env =3D tb_env; tb_env->flags =3D PPC_DECR_UNDERFLOW_TRIGGERED; - if (env->insns_flags & PPC_SEGMENT_64B) { + if (is_book3s_arch2x(env)) { /* All Book3S 64bit CPUs implement level based DEC logic */ tb_env->flags |=3D PPC_DECR_UNDERFLOW_LEVEL; } diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index fc12b4688e..0707177584 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -2409,6 +2409,12 @@ enum { target_ulong cpu_read_xer(CPUPPCState *env); void cpu_write_xer(CPUPPCState *env, target_ulong xer); =20 +/* + * All 64-bit server processors compliant with arch 2.x, ie. 970 and newer, + * have PPC_SEGMENT_64B. + */ +#define is_book3s_arch2x(ctx) (!!((ctx)->insns_flags & PPC_SEGMENT_64B)) + static inline void cpu_get_tb_cpu_state(CPUPPCState *env, target_ulong *pc, target_ulong *cs_base, uint32_t *f= lags) { diff --git a/target/ppc/helper_regs.h b/target/ppc/helper_regs.h index a2205e1044..c863abc0bf 100644 --- a/target/ppc/helper_regs.h +++ b/target/ppc/helper_regs.h @@ -152,7 +152,7 @@ static inline int hreg_store_msr(CPUPPCState *env, targ= et_ulong value, * - 64-bit embedded implementations do not need any operation to be * performed when PR is set. */ - if ((env->insns_flags & PPC_SEGMENT_64B) && ((value >> MSR_PR) & 1)) { + if (is_book3s_arch2x(env) && ((value >> MSR_PR) & 1)) { value |=3D (1 << MSR_EE) | (1 << MSR_DR) | (1 << MSR_IR); } #endif diff --git a/target/ppc/translate.c b/target/ppc/translate.c index d3aaa6482c..576210d901 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -3755,7 +3755,7 @@ static void gen_bcond(DisasContext *ctx, int type) * arch 2.x, do implement a "test and decrement" logic instead, * as described in their respective UMs. */ - if (unlikely(!(ctx->insns_flags & PPC_SEGMENT_64B))) { + if (unlikely(!is_book3s_arch2x(ctx))) { gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); tcg_temp_free(temp); tcg_temp_free(target); @@ -3913,7 +3913,7 @@ static void gen_rfi(DisasContext *ctx) /* This instruction doesn't exist anymore on 64-bit server * processors compliant with arch 2.x */ - if (ctx->insns_flags & PPC_SEGMENT_64B) { + if (is_book3s_arch2x(ctx)) { gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); return; } @@ -6535,8 +6535,7 @@ static void gen_msgclr(DisasContext *ctx) GEN_PRIV; #else CHK_HV; - /* 64-bit server processors compliant with arch 2.x */ - if (ctx->insns_flags & PPC_SEGMENT_64B) { + if (is_book3s_arch2x(ctx)) { gen_helper_book3s_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]); } else { gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]); @@ -6550,8 +6549,7 @@ static void gen_msgsnd(DisasContext *ctx) GEN_PRIV; #else CHK_HV; - /* 64-bit server processors compliant with arch 2.x */ - if (ctx->insns_flags & PPC_SEGMENT_64B) { + if (is_book3s_arch2x(ctx)) { gen_helper_book3s_msgsnd(cpu_gpr[rB(ctx->opcode)]); } else { gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]); --=20 2.20.1 From nobody Sun Apr 28 10:29:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553830555828593.4591326512358; Thu, 28 Mar 2019 20:35:55 -0700 (PDT) Received: from localhost ([127.0.0.1]:45618 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iJ3-0004gA-G9 for importer@patchew.org; Thu, 28 Mar 2019 23:35:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iD8-00080A-62 for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9iD6-0008CO-Sa for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:42 -0400 Received: from ozlabs.org ([203.11.71.1]:37269) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9iD6-0008B8-Bu; Thu, 28 Mar 2019 23:29:40 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 44VnKT5063z9sQp; Fri, 29 Mar 2019 14:29:33 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1553830173; bh=SoEhZkBKiIPZu7rWFlk2xjY2aUZpD7G+/2EChDJDCvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hYa/mZFFEw3/v/ADKSeaACp5pALQQQsoVnTbHXPGXx7EsXHsywd5hnQqpp563ZNXI SjcToF95Z7B5iGEmeLe5F6lZ3iLehfVGB1/qDW7sW9S2rqTM6AJIet/8+GKrcG29xQ bihm3TbyZquwhHovtlx74sxeFR53nnaX6Toy+zt0= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 29 Mar 2019 14:29:25 +1100 Message-Id: <20190329032929.21072-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190329032929.21072-1-david@gibson.dropbear.id.au> References: <20190329032929.21072-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PULL 4/8] target/ppc: Improve comment of bcctr used for spectre v2 mitigation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, imammedo@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Greg Kurz Signed-off-by: Greg Kurz Message-Id: <155359567174.1794128.3183997593369465355.stgit@bahia.lan> Signed-off-by: David Gibson --- target/ppc/translate.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 576210d901..badc1ae1a3 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -3753,7 +3753,15 @@ static void gen_bcond(DisasContext *ctx, int type) * All ISAs up to v3 describe this form of bcctr as invalid but * some processors, ie. 64-bit server processors compliant with * arch 2.x, do implement a "test and decrement" logic instead, - * as described in their respective UMs. + * as described in their respective UMs. This logic involves C= TR + * to act as both the branch target and a counter, which makes + * it basically useless and thus never used in real code. + * + * This form was hence chosen to trigger extra micro-architect= ural + * side-effect on real HW needed for the Spectre v2 workaround. + * It is up to guests that implement such workaround, ie. linu= x, to + * use this form in a way it just triggers the side-effect wit= hout + * doing anything else harmful. */ if (unlikely(!is_book3s_arch2x(ctx))) { gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); --=20 2.20.1 From nobody Sun Apr 28 10:29:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553830622878401.8777781364853; Thu, 28 Mar 2019 20:37:02 -0700 (PDT) Received: from localhost ([127.0.0.1]:45636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iKA-0005dl-GI for importer@patchew.org; Thu, 28 Mar 2019 23:36:58 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iD8-00080L-RE for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9iD7-0008D3-D8 for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:42 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:57269) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9iD6-0008BQ-S9; Thu, 28 Mar 2019 23:29:41 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 44VnKT6zkMz9sRY; Fri, 29 Mar 2019 14:29:33 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1553830173; bh=ChIBBdeSNzG2VW/rP+cx3UB2rCmwCsh7pHdEUFn2SaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bBvYgXJNzWjE1Op/M5qkkOwnAzlPZr83mq27VMl2qEJpUGDF2WYIGYZG7tQbrgWbU A6xrqtMyGkPtkRx3DUqdNEgZFoNXYhD9kVbMVilfREOeVW41itUSAdg8qzIG61qpMS GG4TaWsLzSKwnEEUVcNt4MI2evhJc1zuviuBO7Q4= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 29 Mar 2019 14:29:26 +1100 Message-Id: <20190329032929.21072-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190329032929.21072-1-david@gibson.dropbear.id.au> References: <20190329032929.21072-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 5/8] target/ppc: Fix QEMU crash with stxsdx X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david@redhat.com, Mark Cave-Ayland , qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, imammedo@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Greg Kurz I've been hitting several QEMU crashes while running a fedora29 ppc64le guest under TCG. Each time, this would occur several minutes after the guest reached login: Fedora 29 (Twenty Nine) Kernel 4.20.6-200.fc29.ppc64le on an ppc64le (hvc0) Web console: https://localhost:9090/ localhost login: tcg/tcg.c:3211: tcg fatal error This happens because a bug crept up in the gen_stxsdx() helper when it was converted to use VSR register accessors by commit 8b3b2d75c7c04 "target/ppc: introduce get_cpu_vsr{l,h}() and set_cpu_vsr{l,h}() helpers for VSR register access". The code creates a temporary, passes it directly to gen_qemu_st64_i64() and then to set_cpu_vrsh()... which looks like this was mistakenly coded as a load instead of a store. Reverse the logic: read the VSR to the temporary first and then store it to memory. Fixes: 8b3b2d75c7c0481544e277dad226223245e058eb Signed-off-by: Greg Kurz Message-Id: <155371035249.2038502.12364252604337688538.stgit@bahia.lan> Reviewed-by: Mark Cave-Ayland Signed-off-by: David Gibson --- target/ppc/translate/vsx-impl.inc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/ppc/translate/vsx-impl.inc.c b/target/ppc/translate/vsx= -impl.inc.c index 508e9199c8..489b2436e4 100644 --- a/target/ppc/translate/vsx-impl.inc.c +++ b/target/ppc/translate/vsx-impl.inc.c @@ -356,8 +356,8 @@ static void gen_##name(DisasContext *ctx) = \ gen_set_access_type(ctx, ACCESS_INT); \ EA =3D tcg_temp_new(); \ gen_addr_reg_index(ctx, EA); \ + get_cpu_vsrh(t0, xS(ctx->opcode)); \ gen_qemu_##operation(ctx, t0, EA); \ - set_cpu_vsrh(xS(ctx->opcode), t0); \ tcg_temp_free(EA); \ tcg_temp_free_i64(t0); \ } --=20 2.20.1 From nobody Sun Apr 28 10:29:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553830703889394.73462894479087; Thu, 28 Mar 2019 20:38:23 -0700 (PDT) Received: from localhost ([127.0.0.1]:45644 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iLO-0006NT-J1 for importer@patchew.org; Thu, 28 Mar 2019 23:38:14 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iD9-00080j-9c for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9iD7-0008DI-MW for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:43 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:35471) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9iD6-0008BS-Vc; Thu, 28 Mar 2019 23:29:41 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 44VnKV0p1cz9sR3; Fri, 29 Mar 2019 14:29:33 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1553830174; bh=NPROTp9HS5m2yLP9UBX8vCFgsCmfXShfz5inJBOcbEc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BrtO8LLbTrWVHVM69wzFtlL1Mv0HFrbnVm300ZbzpZ8/h5FTCF7KnodbhVfa1md7g eyhW9nCKFOmsSFOilnv4f5k27qZOD8ltOJgvM+nm7mIOzsHHtxz1xoo7q64RXM6Lh7 faCWc9yCGA1bmac8yMNEnSAdtUbzwcTLNQ2nXwss= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 29 Mar 2019 14:29:27 +1100 Message-Id: <20190329032929.21072-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190329032929.21072-1-david@gibson.dropbear.id.au> References: <20190329032929.21072-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 6/8] spapr: Simplify handling of host-serial and host-model values X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, imammedo@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 27461d69a0f "ppc: add host-serial and host-model machine attributes (CVE-2019-8934)" introduced 'host-serial' and 'host-model' machine properties for spapr to explicitly control the values advertised to the guest in device tree properties with the same names. The previous behaviour on KVM was to unconditionally populate the device tree with the real host serial number and model, which leaks possibly sensitive information about the host to the guest. To maintain compatibility for old machine types, we allowed those props to be set to "passthrough" to take the value from the host as before. Or they could be set to "none" to explicitly omit the device tree items. Special casing specific values on what's otherwise a user supplied string is very ugly. So, this patch simplifies things by implementing the backwards compatibility in a different way: we have a machine class flag set for the older machines, and we only load the host values into the device tree if A) they're not set by the user and B) we have that flag set. This does mean that the "passthrough" functionality is no longer available with the current machine type. That's ok though: if a user or management layer really wants the information passed through they can read it themselves (OpenStack Nova already does something similar for x86). It also means the user can't explicitly ask for the values to be omitted on the old machine types. I think that's an acceptable trade-off: if you care enough about not leaking the host information you can either move to the new machine type, or use a dummy value for the properties. For the new machine type, this also removes an odd inconsistency between running on a POWER and non-POWER (or non-Linux) hosts: if the host information couldn't be read from where we expect (in the host's device tree as exposed by Linux), we'd fallback to omitting the guest device tree items. While we're there, improve some poorly worded comments, and the help text for the properties. Signed-off-by: David Gibson Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Greg Kurz Tested-by: Greg Kurz --- hw/ppc/spapr.c | 57 ++++++++++++++---------------------------- include/hw/ppc/spapr.h | 1 + 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 6c16d6cfaf..4fc711b5a8 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1252,38 +1252,8 @@ static void *spapr_build_fdt(SpaprMachineState *spap= r) _FDT(fdt_setprop_string(fdt, 0, "model", "IBM pSeries (emulated by qem= u)")); _FDT(fdt_setprop_string(fdt, 0, "compatible", "qemu,pseries")); =20 - /* - * Add info to guest to indentify which host is it being run on - * and what is the uuid of the guest - */ - if (spapr->host_model && !g_str_equal(spapr->host_model, "none")) { - if (g_str_equal(spapr->host_model, "passthrough")) { - /* -M host-model=3Dpassthrough */ - if (kvmppc_get_host_model(&buf)) { - _FDT(fdt_setprop_string(fdt, 0, "host-model", buf)); - g_free(buf); - } - } else { - /* -M host-model=3D */ - _FDT(fdt_setprop_string(fdt, 0, "host-model", spapr->host_mode= l)); - } - } - - if (spapr->host_serial && !g_str_equal(spapr->host_serial, "none")) { - if (g_str_equal(spapr->host_serial, "passthrough")) { - /* -M host-serial=3Dpassthrough */ - if (kvmppc_get_host_serial(&buf)) { - _FDT(fdt_setprop_string(fdt, 0, "host-serial", buf)); - g_free(buf); - } - } else { - /* -M host-serial=3D */ - _FDT(fdt_setprop_string(fdt, 0, "host-serial", spapr->host_ser= ial)); - } - } - + /* Guest UUID & Name*/ buf =3D qemu_uuid_unparse_strdup(&qemu_uuid); - _FDT(fdt_setprop_string(fdt, 0, "vm,uuid", buf)); if (qemu_uuid_set) { _FDT(fdt_setprop_string(fdt, 0, "system-id", buf)); @@ -1295,6 +1265,21 @@ static void *spapr_build_fdt(SpaprMachineState *spap= r) qemu_get_vm_name())); } =20 + /* Host Model & Serial Number */ + if (spapr->host_model) { + _FDT(fdt_setprop_string(fdt, 0, "host-model", spapr->host_model)); + } else if (smc->broken_host_serial_model && kvmppc_get_host_model(&buf= )) { + _FDT(fdt_setprop_string(fdt, 0, "host-model", buf)); + g_free(buf); + } + + if (spapr->host_serial) { + _FDT(fdt_setprop_string(fdt, 0, "host-serial", spapr->host_serial)= ); + } else if (smc->broken_host_serial_model && kvmppc_get_host_serial(&bu= f)) { + _FDT(fdt_setprop_string(fdt, 0, "host-serial", buf)); + g_free(buf); + } + _FDT(fdt_setprop_cell(fdt, 0, "#address-cells", 2)); _FDT(fdt_setprop_cell(fdt, 0, "#size-cells", 2)); =20 @@ -3352,12 +3337,12 @@ static void spapr_instance_init(Object *obj) spapr_get_host_model, spapr_set_host_model, &error_abort); object_property_set_description(obj, "host-model", - "Set host's model-id to use - none|passthrough|string", &error_abo= rt); + "Host model to advertise in guest device tree", &error_abort); object_property_add_str(obj, "host-serial", spapr_get_host_serial, spapr_set_host_serial, &error_abort); object_property_set_description(obj, "host-serial", - "Set host's system-id to use - none|passthrough|string", &error_ab= ort); + "Host serial number to advertise in guest device tree", &error_abo= rt); } =20 static void spapr_machine_finalizefn(Object *obj) @@ -4381,18 +4366,14 @@ DEFINE_SPAPR_MACHINE(4_0, "4.0", true); static void spapr_machine_3_1_class_options(MachineClass *mc) { SpaprMachineClass *smc =3D SPAPR_MACHINE_CLASS(mc); - static GlobalProperty compat[] =3D { - { TYPE_SPAPR_MACHINE, "host-model", "passthrough" }, - { TYPE_SPAPR_MACHINE, "host-serial", "passthrough" }, - }; =20 spapr_machine_4_0_class_options(mc); compat_props_add(mc->compat_props, hw_compat_3_1, hw_compat_3_1_len); - compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat)); =20 mc->default_cpu_type =3D POWERPC_CPU_TYPE_NAME("power8_v2.0"); smc->update_dt_enabled =3D false; smc->dr_phb_enabled =3D false; + smc->broken_host_serial_model =3D true; smc->default_caps.caps[SPAPR_CAP_CFPC] =3D SPAPR_CAP_BROKEN; smc->default_caps.caps[SPAPR_CAP_SBBC] =3D SPAPR_CAP_BROKEN; smc->default_caps.caps[SPAPR_CAP_IBS] =3D SPAPR_CAP_BROKEN; diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 2b4c05a2ec..5ea8081041 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -118,6 +118,7 @@ struct SpaprMachineClass { bool use_ohci_by_default; /* use USB-OHCI instead of XHCI */ bool pre_2_10_has_unused_icps; bool legacy_irq_allocation; + bool broken_host_serial_model; /* present real host info to the guest = */ =20 void (*phb_placement)(SpaprMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio,=20 --=20 2.20.1 From nobody Sun Apr 28 10:29:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553830490166346.5957734319975; Thu, 28 Mar 2019 20:34:50 -0700 (PDT) Received: from localhost ([127.0.0.1]:45582 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iI3-0003M1-0e for importer@patchew.org; Thu, 28 Mar 2019 23:34:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50801) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iD9-00080T-1Z for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9iD7-0008Cx-Ai for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:42 -0400 Received: from ozlabs.org ([203.11.71.1]:60121) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9iD6-0008BM-KA; Thu, 28 Mar 2019 23:29:41 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 44VnKT5sfpz9sR0; Fri, 29 Mar 2019 14:29:33 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1553830173; bh=2lda8LHLy9vdlHI+ynoGX78gJ61XPg7lv1pXw6mvjsc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JLhoE5alh/2vudhkY4pjXtjt7mefTDhnNB8q2Lc+uqGO36rZlLyGCcUHpKfWAWZ0T xzhnkGqeA41utBMtXiZbETk/1zdPxqMWEPSAG8fg8x8IfvDWwd2pWgFcOaiXzWb0aZ lMR2GlrzE4RSZDviUOS5Er8JKM/+M5GsXUh/M0Fc= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 29 Mar 2019 14:29:28 +1100 Message-Id: <20190329032929.21072-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190329032929.21072-1-david@gibson.dropbear.id.au> References: <20190329032929.21072-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PULL 7/8] spapr/irq: Add XIVE sanity checks on non-P9 machines X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , imammedo@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: C=C3=A9dric Le Goater On non-P9 machines, the XIVE interrupt mode is not advertised, see spapr_dt_ov5_platform_support(). Add a couple of checks on the machine configuration to filter bogus setups and prevent OS failures : Interrupt modes CPU/Compat XICS XIVE dual P8/P8 OK QEMU failure (1) OK (3) P9/P8 OK QEMU failure (2) OK (3) P9/P9 OK OK OK (1) CPU exception model is incompatible with XIVE and the presenters will fail to realize. (2) CPU exception model is compatible with XIVE, but the XIVE CAS advertisement is dropped when in POWER8 mode. So we could ended up booting with the XIVE DT properties but without the HCALLs. Avoid confusing Linux with such settings and fail under QEMU. (3) force XICS in machine init Remove the check on XIVE-only machines in spapr_machine_init(), which has now become redundant. Signed-off-by: C=C3=A9dric Le Goater Message-Id: <20190328100044.11408-1-clg@kaod.org> Reviewed-by: Greg Kurz Signed-off-by: David Gibson --- hw/ppc/spapr.c | 8 +------- hw/ppc/spapr_irq.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 4fc711b5a8..b52b82d298 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2780,13 +2780,7 @@ static void spapr_machine_init(MachineState *machine) =20 /* advertise XIVE on POWER9 machines */ if (spapr->irq->ov5 & (SPAPR_OV5_XIVE_EXPLOIT | SPAPR_OV5_XIVE_BOTH)) { - if (ppc_type_check_compat(machine->cpu_type, CPU_POWERPC_LOGICAL_3= _00, - 0, spapr->max_compat_pvr)) { - spapr_ovec_set(spapr->ov5, OV5_XIVE_EXPLOIT); - } else if (spapr->irq->ov5 & SPAPR_OV5_XIVE_EXPLOIT) { - error_report("XIVE-only machines require a POWER9 CPU"); - exit(1); - } + spapr_ovec_set(spapr->ov5, OV5_XIVE_EXPLOIT); } =20 /* init CPUs */ diff --git a/hw/ppc/spapr_irq.c b/hw/ppc/spapr_irq.c index 253e4de7fd..0a84e4cf63 100644 --- a/hw/ppc/spapr_irq.c +++ b/hw/ppc/spapr_irq.c @@ -16,6 +16,7 @@ #include "hw/ppc/spapr_xive.h" #include "hw/ppc/xics.h" #include "hw/ppc/xics_spapr.h" +#include "cpu-models.h" #include "sysemu/kvm.h" =20 #include "trace.h" @@ -582,12 +583,55 @@ SpaprIrq spapr_irq_dual =3D { .get_nodename =3D spapr_irq_get_nodename_dual, }; =20 + +static void spapr_irq_check(SpaprMachineState *spapr, Error **errp) +{ + MachineState *machine =3D MACHINE(spapr); + + /* + * Sanity checks on non-P9 machines. On these, XIVE is not + * advertised, see spapr_dt_ov5_platform_support() + */ + if (!ppc_type_check_compat(machine->cpu_type, CPU_POWERPC_LOGICAL_3_00, + 0, spapr->max_compat_pvr)) { + /* + * If the 'dual' interrupt mode is selected, force XICS as CAS + * negotiation is useless. + */ + if (spapr->irq =3D=3D &spapr_irq_dual) { + spapr->irq =3D &spapr_irq_xics; + return; + } + + /* + * Non-P9 machines using only XIVE is a bogus setup. We have two + * scenarios to take into account because of the compat mode: + * + * 1. POWER7/8 machines should fail to init later on when creating + * the XIVE interrupt presenters because a POWER9 exception + * model is required. + + * 2. POWER9 machines using the POWER8 compat mode won't fail and + * will let the OS boot with a partial XIVE setup : DT + * properties but no hcalls. + * + * To cover both and not confuse the OS, add an early failure in + * QEMU. + */ + if (spapr->irq =3D=3D &spapr_irq_xive) { + error_setg(errp, "XIVE-only machines require a POWER9 CPU"); + return; + } + } +} + /* * sPAPR IRQ frontend routines for devices */ void spapr_irq_init(SpaprMachineState *spapr, Error **errp) { MachineState *machine =3D MACHINE(spapr); + Error *local_err =3D NULL; =20 if (machine_kernel_irqchip_split(machine)) { error_setg(errp, "kernel_irqchip split mode not supported on pseri= es"); @@ -600,6 +644,12 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **= errp) return; } =20 + spapr_irq_check(spapr, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + /* Initialize the MSI IRQ allocator. */ if (!SPAPR_MACHINE_GET_CLASS(spapr)->legacy_irq_allocation) { spapr_irq_msi_init(spapr, spapr->irq->nr_msis); --=20 2.20.1 From nobody Sun Apr 28 10:29:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553830496486708.2524672379371; Thu, 28 Mar 2019 20:34:56 -0700 (PDT) Received: from localhost ([127.0.0.1]:45584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iI6-0003PH-GT for importer@patchew.org; Thu, 28 Mar 2019 23:34:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50777) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9iD8-00080C-Br for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9iD7-0008Ce-5h for qemu-devel@nongnu.org; Thu, 28 Mar 2019 23:29:42 -0400 Received: from ozlabs.org ([203.11.71.1]:53565) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9iD6-0008BO-LK; Thu, 28 Mar 2019 23:29:41 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 44VnKV1XgCz9sR7; Fri, 29 Mar 2019 14:29:33 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1553830174; bh=uXhG/9dBHCOynv+dn/9p3kL3JHQy7lMtlft++onejr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GT7sL9wRHDB/urEutGGmO079YXTVyt0/NeNU0AwU/o8jgo47pX97RwLwlWP41NWkA YCwFBSBjjaH7frvrr/JXYxDj7WynJ9tqxGKsLN+k0FDn8H1dlML/acDgQG0kmuElq8 e05v/w9+MkBTWo616bTBrlSA/b6a/oNf0lRRT6+w= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 29 Mar 2019 14:29:29 +1100 Message-Id: <20190329032929.21072-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190329032929.21072-1-david@gibson.dropbear.id.au> References: <20190329032929.21072-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PULL 8/8] exec: Only count mapped memory backends for qemu_getrampagesize() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, imammedo@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" qemu_getrampagesize() works out the minimum host page size backing any of guest RAM. This is required in a few places, such as for POWER8 PAPR KVM guests, because limitations of the hardware virtualization mean the guest can't use pagesizes larger than the host pages backing its memory. However, it currently checks against *every* memory backend, whether or not it is actually mapped into guest memory at the moment. This is incorrect. This can cause a problem attempting to add memory to a POWER8 pseries KVM guest which is configured to allow hugepages in the guest (e.g. -machine cap-hpt-max-page-size=3D16m). If you attempt to add non-hugepage, you can (correctly) create a memory backend, however it (correctly) will throw an error when you attempt to map that memory into the guest by 'device_add'ing a pc-dimm. What's not correct is that if you then reset the guest a startup check against qemu_getrampagesize() will cause a fatal error because of the new memory object, even though it's not mapped into the guest. This patch corrects the problem by adjusting find_max_supported_pagesize() (called from qemu_getrampagesize() via object_child_foreach) to exclude non-mapped memory backends. Signed-off-by: David Gibson Reviewed-by: Igor Mammedov Acked-by: David Hildenbrand --- exec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index 86a38d3b3b..6ab62f4eee 100644 --- a/exec.c +++ b/exec.c @@ -1692,9 +1692,10 @@ static int find_max_supported_pagesize(Object *obj, = void *opaque) long *hpsize_min =3D opaque; =20 if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) { - long hpsize =3D host_memory_backend_pagesize(MEMORY_BACKEND(obj)); + HostMemoryBackend *backend =3D MEMORY_BACKEND(obj); + long hpsize =3D host_memory_backend_pagesize(backend); =20 - if (hpsize < *hpsize_min) { + if (host_memory_backend_is_mapped(backend) && (hpsize < *hpsize_mi= n)) { *hpsize_min =3D hpsize; } } --=20 2.20.1