From patchwork Thu May 31 13:04:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 10441073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A3036602BD for ; Thu, 31 May 2018 13:06:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9725529359 for ; Thu, 31 May 2018 13:06:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AF0A29373; Thu, 31 May 2018 13:06:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9FF1229359 for ; Thu, 31 May 2018 13:06:22 +0000 (UTC) Received: from localhost ([::1]:44003 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fONHZ-0003aD-P3 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 31 May 2018 09:06:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50644) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fONGD-00039Q-Af for qemu-devel@nongnu.org; Thu, 31 May 2018 09:05:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fONG9-0000MM-2U for qemu-devel@nongnu.org; Thu, 31 May 2018 09:04:57 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:40945) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fONG2-0000HD-Eb; Thu, 31 May 2018 09:04:46 -0400 Received: by mail-pf0-x244.google.com with SMTP id f189-v6so10774271pfa.7; Thu, 31 May 2018 06:04:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=qYgyfs535/w+0mSKE1A8PizkIRYnst7sTt7MhrJQg6k=; b=ppHocqFor3DwXUZdFnf37rhzQwV8XVYiQ0uH0o6KtBLIUxqsrOJQRSGdrFEUWcEN1X eUdXh/XqX3y62hSRBm4DVQqEmmHMLcq3A8gH0Mv04OstNedrTBIrl4Q1/qn+kM0+Linm UMF5t8s8v0/4Tie/SubqFMUaz7eGtSrEGg2jbH7qh00YroXtYCb0mG7WgWPUvcj45myw hn3gJNnhKRIObKSmW/gDDA5+0r5nwstHYtHeZuU5MlsJXfaTzh4VQ/2rOQGwZmZ1w4vh hRP9U/4xjenaKUvLCDpD2UXTr1JAE+E+GITcbNdJMU7LPwXKDKATUA62ond59fS//vL5 OHRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=qYgyfs535/w+0mSKE1A8PizkIRYnst7sTt7MhrJQg6k=; b=FnXBGeci4rFCw/eqJ1A5VUUDoD2cG7Ywe4glTRgsWfs0sVIQgz3/fDUhUE5wGCOa2a kLaujT3UTQ//0rRa55RljvoIYi4s6wMfytCoWYiHbfZgth5rdDogENmKOUE6ELMw0Qur GSRgt/FLhqvfI1HgHaGtPXE8SvcamkK7ikaC5xDXAObojdPsLtZxnZk+G02yFTJhUMQx 3RCnbK4GQFPjIArYLsC8ztayN7aZEKLVlDlhP8rCODLHIA7Vv8a02Dhr1FB/ZM8mXLhQ Zt+USEP/mMqOU0pCR1AhDtR21u7Yz+eQuKKJ7PBOCqEcHg0dtpQ7WzHoLHFhTzFSBz4y VsPQ== X-Gm-Message-State: ALKqPwcMzy28zVVNRja9Qa0Mz+bw8ibhJU8k0cJsQ2EJ9yOKpPtHaRqy irf/obyv6xUhIJKhnsKrQVU= X-Google-Smtp-Source: ADUXVKKqY7dW6MjFXbtC934IFeLRywO5UrEnOFJxGcBQPna2seU46q+XjbpFJ1OcXqEuQUlk6iULRg== X-Received: by 2002:a65:5d51:: with SMTP id e17-v6mr5479004pgt.100.1527771884891; Thu, 31 May 2018 06:04:44 -0700 (PDT) Received: from aurora.jms.id.au ([45.124.203.19]) by smtp.gmail.com with ESMTPSA id k129-v6sm24997381pga.94.2018.05.31.06.04.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 May 2018 06:04:44 -0700 (PDT) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Thu, 31 May 2018 22:34:36 +0930 From: Joel Stanley To: David Gibson , Alexander Graf , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Date: Thu, 31 May 2018 22:34:29 +0930 Message-Id: <20180531130429.24911-1-joel@jms.id.au> X-Mailer: git-send-email 2.17.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::244 Subject: [Qemu-devel] [PATCH v2] target/ppc: Allow privileged access to SPR_PCR 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: Michael Ellerman , Michael Neuling , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Greg Kurz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The powerpc Linux kernel[1] and skiboot firmware[2] recently gained changes that cause the Processor Compatibility Register (PCR) SPR to be cleared. These changes cause Linux to fail to boot on the Qemu powernv machine with an error: Trying to write privileged spr 338 (0x152) at 0000000030017f0c With this patch Qemu makes this register available as a hypervisor privileged register. Note that bits set in this register disable features of the processor. Currently the only register state that is supported is when the register is zeroed (enable all features). This is sufficient for guests to once again boot. [1] https://lkml.kernel.org/r/20180518013742.24095-1-mikey@neuling.org [2] https://patchwork.ozlabs.org/patch/915932/ Signed-off-by: Joel Stanley Reviewed-by: Greg Kurz --- v2: - Change error message to say Invalid instead of Unimplemented - Fix compile warning on other powerpc targets, thanks patchew --- target/ppc/helper.h | 1 + target/ppc/misc_helper.c | 10 ++++++++++ target/ppc/translate_init.inc.c | 9 +++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/target/ppc/helper.h b/target/ppc/helper.h index 19453c68138a..d751f0e21909 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -17,6 +17,7 @@ DEF_HELPER_2(pminsn, void, env, i32) DEF_HELPER_1(rfid, void, env) DEF_HELPER_1(hrfid, void, env) DEF_HELPER_2(store_lpcr, void, env, tl) +DEF_HELPER_2(store_pcr, void, env, tl) #endif DEF_HELPER_1(check_tlb_flush_local, void, env) DEF_HELPER_1(check_tlb_flush_global, void, env) diff --git a/target/ppc/misc_helper.c b/target/ppc/misc_helper.c index 8c8cba5cc6f1..1870f4c47f1a 100644 --- a/target/ppc/misc_helper.c +++ b/target/ppc/misc_helper.c @@ -20,6 +20,7 @@ #include "cpu.h" #include "exec/exec-all.h" #include "exec/helper-proto.h" +#include "qemu/error-report.h" #include "helper_regs.h" @@ -98,6 +99,15 @@ void helper_store_ptcr(CPUPPCState *env, target_ulong val) tlb_flush(CPU(cpu)); } } + +void helper_store_pcr(CPUPPCState *env, target_ulong value) +{ + if (value != 0) { + error_report("Invalid PCR value 0x"TARGET_FMT_lx, value); + return; + } + env->spr[SPR_PCR] = value; +} #endif /* defined(TARGET_PPC64) */ void helper_store_pidr(CPUPPCState *env, target_ulong val) diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c index ab782cb32aaa..1a89017ddea8 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -424,6 +424,10 @@ static void spr_write_ptcr(DisasContext *ctx, int sprn, int gprn) gen_helper_store_ptcr(cpu_env, cpu_gpr[gprn]); } +static void spr_write_pcr(DisasContext *ctx, int sprn, int gprn) +{ + gen_helper_store_pcr(cpu_env, cpu_gpr[gprn]); +} #endif #endif @@ -7957,11 +7961,12 @@ static void gen_spr_power6_common(CPUPPCState *env) #endif /* * Register PCR to report POWERPC_EXCP_PRIV_REG instead of - * POWERPC_EXCP_INVAL_SPR. + * POWERPC_EXCP_INVAL_SPR in userspace. Permit hypervisor access. */ - spr_register(env, SPR_PCR, "PCR", + spr_register_hv(env, SPR_PCR, "PCR", SPR_NOACCESS, SPR_NOACCESS, SPR_NOACCESS, SPR_NOACCESS, + &spr_read_generic, &spr_write_pcr, 0x00000000); }