From patchwork Tue Aug 22 04:24:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 804254 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; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.b="EkSFsCxX"; dkim-atps=neutral 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 3xbyCL00Y2z9t2V for ; Tue, 22 Aug 2017 14:25:17 +1000 (AEST) Received: from localhost ([::1]:35422 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk0kd-0000uF-7w for incoming@patchwork.ozlabs.org; Tue, 22 Aug 2017 00:25:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54610) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk0jp-0000rQ-Nk for qemu-devel@nongnu.org; Tue, 22 Aug 2017 00:24:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk0jm-00080G-V1 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 00:24:25 -0400 Received: from ozlabs.org ([103.22.144.67]:52653) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk0jm-0007yS-JV; Tue, 22 Aug 2017 00:24:22 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3xbyBD3X0Tz9t2d; Tue, 22 Aug 2017 14:24:20 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1503375860; bh=7vmon9MHCj523RmDa5A4nR1I3hcKB3xhBOUC8LubQuk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EkSFsCxXS+QCEh1oeT5q/nTtpuXF8mlkvQtqmngFBtAr86dWxurK4vHd+MBItgUWI BE/RIpq7xKnxbyl8o0v2eiZdd4heRw5SCZcry6ro5sSWzxFdbCi93e6r/cMrnmQPUF uUNCEBjgg1BVK9RCDCKFo9NOrHGRndb6qU9T4Kxc= From: David Gibson To: peter.maydell@linaro.org Date: Tue, 22 Aug 2017 14:24:12 +1000 Message-Id: <20170822042416.26758-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170822042416.26758-1-david@gibson.dropbear.id.au> References: <20170822042416.26758-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 3/7] ppc: fix ppc_set_compat() with KVM PR 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: lvivier@redhat.com, thuth@redhat.com, mdroth@linux.vnet.ibm.com, cohuck@redhat.com, qemu-devel@nongnu.org, agraf@suse.de, Greg Kurz , qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Greg Kurz When running in KVM PR mode, kvmppc_set_compat() always fail because the current PR implementation doesn't handle KVM_REG_PPC_ARCH_COMPAT. Now that the machine code inconditionally calls ppc_set_compat_all() at reset time to restore the compat mode default value (commit 66d5c492dd3a9), it is impossible to start a guest with PR: qemu-system-ppc64: Unable to set CPU compatibility mode in KVM: Invalid argument A tentative patch [1] was recently sent by Suraj to address the issue, but it would prevent the compat mode to be turned off on reset. And we really don't want to explicitely check for KVM PR. During the patch's review, David suggested that we should only call the KVM ioctl() if the compat PVR changes. This allows at least to run with KVM PR, provided no compat mode is requested from the command line (which should be the case when running PR nested). This is what this patch does. While here, we also fix the side effect where KVM would fail but we would change the CPU state in QEMU anyway. [1] http://patchwork.ozlabs.org/patch/782039/ Signed-off-by: Greg Kurz Reviewed-by: Suraj Jitindar Singh Signed-off-by: David Gibson --- target/ppc/compat.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/target/ppc/compat.c b/target/ppc/compat.c index f1b67faa97..f8729fe46d 100644 --- a/target/ppc/compat.c +++ b/target/ppc/compat.c @@ -140,16 +140,17 @@ void ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr, Error **errp) cpu_synchronize_state(CPU(cpu)); - cpu->compat_pvr = compat_pvr; - env->spr[SPR_PCR] = pcr & pcc->pcr_mask; - - if (kvm_enabled()) { + if (kvm_enabled() && cpu->compat_pvr != compat_pvr) { int ret = kvmppc_set_compat(cpu, cpu->compat_pvr); if (ret < 0) { error_setg_errno(errp, -ret, "Unable to set CPU compatibility mode in KVM"); + return; } } + + cpu->compat_pvr = compat_pvr; + env->spr[SPR_PCR] = pcr & pcc->pcr_mask; } typedef struct {