From patchwork Tue Jun 12 16:27:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 928407 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kaod.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 414wLb695rz9s0w for ; Wed, 13 Jun 2018 02:28:55 +1000 (AEST) Received: from localhost ([::1]:57297 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSmA9-0001V5-Hg for incoming@patchwork.ozlabs.org; Tue, 12 Jun 2018 12:28:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55452) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSm9X-0001SP-2c for qemu-devel@nongnu.org; Tue, 12 Jun 2018 12:28:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSm9S-0003nH-Q4 for qemu-devel@nongnu.org; Tue, 12 Jun 2018 12:28:14 -0400 Received: from 10.mo178.mail-out.ovh.net ([46.105.76.150]:33078) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSm9S-0003mW-JN for qemu-devel@nongnu.org; Tue, 12 Jun 2018 12:28:10 -0400 Received: from player778.ha.ovh.net (unknown [10.109.122.43]) by mo178.mail-out.ovh.net (Postfix) with ESMTP id 07E0B1A56E for ; Tue, 12 Jun 2018 18:28:08 +0200 (CEST) Received: from bahia.lab.toulouse-stg.fr.ibm.com (deibp9eh1--blueice1n4.emea.ibm.com [195.212.29.166]) (Authenticated sender: groug@kaod.org) by player778.ha.ovh.net (Postfix) with ESMTPA id 97DAE18009D; Tue, 12 Jun 2018 18:28:03 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Tue, 12 Jun 2018 18:27:54 +0200 Message-ID: <152882087494.112322.15549780953419438229.stgit@bahia.lab.toulouse-stg.fr.ibm.com> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 X-Ovh-Tracer-Id: 17624555669951846739 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrkeekgdekjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.76.150 Subject: [Qemu-devel] [PATCH 1/3] target/ppc: drop empty #if/#endif block 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: qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Commit 9d6f106552fa moved the last line in this block to somewhere else, but it forgot to remove the now useless #if/#endif. Signed-off-by: Greg Kurz Reviewed-by: Philippe Mathieu-Daudé --- target/ppc/cpu.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 0247c1f04c37..a91f1a8777eb 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1300,8 +1300,6 @@ void ppc_store_ptcr(CPUPPCState *env, target_ulong value); void ppc_store_msr (CPUPPCState *env, target_ulong value); void ppc_cpu_list (FILE *f, fprintf_function cpu_fprintf); -#if defined(TARGET_PPC64) -#endif /* Time-base and decrementer management */ #ifndef NO_CPU_IO_DEFS From patchwork Tue Jun 12 17:01:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 928419 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kaod.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 414x4z0ywjz9s1B for ; Wed, 13 Jun 2018 03:02:11 +1000 (AEST) Received: from localhost ([::1]:57460 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSmgK-0003p4-Ps for incoming@patchwork.ozlabs.org; Tue, 12 Jun 2018 13:02:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSmfv-0003jN-UD for qemu-devel@nongnu.org; Tue, 12 Jun 2018 13:01:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSmfs-0007r6-Ri for qemu-devel@nongnu.org; Tue, 12 Jun 2018 13:01:44 -0400 Received: from 8.mo68.mail-out.ovh.net ([46.105.74.219]:49222) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSmfs-0007q2-LJ for qemu-devel@nongnu.org; Tue, 12 Jun 2018 13:01:40 -0400 Received: from player760.ha.ovh.net (unknown [10.109.122.59]) by mo68.mail-out.ovh.net (Postfix) with ESMTP id 6460AE4437 for ; Tue, 12 Jun 2018 19:01:38 +0200 (CEST) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player760.ha.ovh.net (Postfix) with ESMTPA id 34DFA20084; Tue, 12 Jun 2018 19:01:32 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Tue, 12 Jun 2018 19:01:26 +0200 Message-ID: <152882288685.114328.8550617676763950480.stgit@bahia.lan> In-Reply-To: <152882087494.112322.15549780953419438229.stgit@bahia.lab.toulouse-stg.fr.ibm.com> References: <152882087494.112322.15549780953419438229.stgit@bahia.lab.toulouse-stg.fr.ibm.com> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 X-Ovh-Tracer-Id: 18190320373902252371 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrkeekgdelfecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.74.219 Subject: [Qemu-devel] [PATCH 2/3] spapr: fix leak in h_client_architecture_support() 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: qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" If the negotiated compat mode can't be set, but raw mode is supported, we decide to ignore the error. An so, we should free it to prevent a memory leak. Signed-off-by: Greg Kurz Reviewed-by: Philippe Mathieu-Daudé --- hw/ppc/spapr_hcall.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 022f6d810182..8b9a4b577fbf 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1547,6 +1547,7 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu, error_report_err(local_err); return H_HARDWARE; } + error_free(local_err); local_err = NULL; } } From patchwork Tue Jun 12 17:04:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 928420 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kaod.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 414x8Z6JfWz9ryk for ; Wed, 13 Jun 2018 03:05:18 +1000 (AEST) Received: from localhost ([::1]:57469 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSmjM-0005Xc-Ki for incoming@patchwork.ozlabs.org; Tue, 12 Jun 2018 13:05:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36343) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSmib-0005H1-Ju for qemu-devel@nongnu.org; Tue, 12 Jun 2018 13:04:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSmiY-0000X2-B7 for qemu-devel@nongnu.org; Tue, 12 Jun 2018 13:04:29 -0400 Received: from 13.mo1.mail-out.ovh.net ([178.33.253.128]:43460) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSmiY-0000WN-44 for qemu-devel@nongnu.org; Tue, 12 Jun 2018 13:04:26 -0400 Received: from player731.ha.ovh.net (unknown [10.109.120.91]) by mo1.mail-out.ovh.net (Postfix) with ESMTP id 73B481075D3 for ; Tue, 12 Jun 2018 19:04:24 +0200 (CEST) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player731.ha.ovh.net (Postfix) with ESMTPA id 2E6ED42009D; Tue, 12 Jun 2018 19:04:21 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Tue, 12 Jun 2018 19:04:15 +0200 Message-ID: <152882305541.114463.3137854902721347235.stgit@bahia.lan> In-Reply-To: <152882087494.112322.15549780953419438229.stgit@bahia.lab.toulouse-stg.fr.ibm.com> References: <152882087494.112322.15549780953419438229.stgit@bahia.lab.toulouse-stg.fr.ibm.com> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 X-Ovh-Tracer-Id: 18237326692749121875 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrkeekgdelfecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.33.253.128 Subject: [Qemu-devel] [PATCH 3/3] target/ppc: filter out non-zero PCR values when using TCG 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: qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Bits set in the PCR disable features of the processor. TCG currently doesn't implement that, ie, we always act like if PCR is all zeros. But it is still possible for the PCR to have a non-null value. This may confuse the guest. There are three distinct cases: 1) a powernv guest doing mtspr SPR_PCR 2) reset of a pseries guest if the max-cpu-compat machine property is set 3) CAS of a pseries guest This patch adds a ppc_store_pcr() helper that ensures we cannot put a non-null value in the PCR when using TCG. This helper also has error propagation support, so that each case listed above can be handled appropriately: 1) since the powernv machine is mostly used for OpenPOWER FW devel, we just print an error and let QEMU continue execution 2) an error is printed and QEMU exits, ie, same behaviour as when KVM doesn't support the requested compat mode 3) an error is printed and QEMU reports H_HARDWARE to the guest Signed-off-by: Greg Kurz --- target/ppc/compat.c | 26 ++++++++++++++++++++++++-- target/ppc/cpu.h | 3 +++ target/ppc/misc_helper.c | 9 ++++++--- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/target/ppc/compat.c b/target/ppc/compat.c index 807c906f6848..08aa99e6ad47 100644 --- a/target/ppc/compat.c +++ b/target/ppc/compat.c @@ -138,8 +138,8 @@ void ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr, Error **errp) { const CompatInfo *compat = compat_by_pvr(compat_pvr); CPUPPCState *env = &cpu->env; - PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); uint64_t pcr; + Error *local_err = NULL; if (!compat_pvr) { pcr = 0; @@ -165,8 +165,30 @@ void ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr, Error **errp) } } + ppc_store_pcr(env, pcr, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + cpu->compat_pvr = compat_pvr; - env->spr[SPR_PCR] = pcr & pcc->pcr_mask; +} + +void ppc_store_pcr(CPUPPCState *env, target_ulong value, Error **errp) +{ + PowerPCCPU *cpu = ppc_env_get_cpu(env); + PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); + + /* TODO: this check should go away once we actually put the proper PCR + * checks in the various bits of TCG that should have them. + */ + if (!kvm_enabled() && value != 0) { + error_setg(errp, "TCG doesn't support PCR value 0x"TARGET_FMT_lx, + value); + return; + } + + env->spr[SPR_PCR] = value & pcc->pcr_mask; } typedef struct { diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index a91f1a8777eb..fdaae34feffb 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1296,6 +1296,9 @@ int ppc_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int size, int rw, #if !defined(CONFIG_USER_ONLY) void ppc_store_sdr1 (CPUPPCState *env, target_ulong value); void ppc_store_ptcr(CPUPPCState *env, target_ulong value); +#if defined(TARGET_PPC64) +void ppc_store_pcr(CPUPPCState *env, target_ulong value, Error **errp); +#endif #endif /* !defined(CONFIG_USER_ONLY) */ void ppc_store_msr (CPUPPCState *env, target_ulong value); diff --git a/target/ppc/misc_helper.c b/target/ppc/misc_helper.c index b88493009609..7a9b45a01453 100644 --- a/target/ppc/misc_helper.c +++ b/target/ppc/misc_helper.c @@ -21,6 +21,7 @@ #include "exec/exec-all.h" #include "exec/helper-proto.h" #include "qemu/error-report.h" +#include "qapi/error.h" #include "helper_regs.h" @@ -102,10 +103,12 @@ void helper_store_ptcr(CPUPPCState *env, target_ulong val) void helper_store_pcr(CPUPPCState *env, target_ulong value) { - PowerPCCPU *cpu = ppc_env_get_cpu(env); - PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); + Error *local_err = NULL; - env->spr[SPR_PCR] = value & pcc->pcr_mask; + ppc_store_pcr(env, value, &local_err); + if (local_err) { + error_report_err(local_err); + } } #endif /* defined(TARGET_PPC64) */