From patchwork Wed May 30 14:42:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 137262 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp5415091lji; Wed, 30 May 2018 07:43:56 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKh9RtHrjwa62K+6CjROVSI08uFM7kjDhWyjyuRrgPzczfVyU19x0IkF0OIdYrRfRdpp2YT X-Received: by 2002:a37:b1c7:: with SMTP id a190-v6mr2615787qkf.155.1527691435968; Wed, 30 May 2018 07:43:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527691435; cv=none; d=google.com; s=arc-20160816; b=B2fpfUAICh+k1CgVBPSx9KVF8r04rthERf+Sjb3yETLj8oHhLkXnX907wiFKGK83us XRpHAEm8+P+AT1HHi9bwYZdITwtXHXkCrBt3wEz2FacF/Cc07e2cJtbmo8Hb73bEANoq wx3voT/8UNq+Sx1ZncvrrBO4IC9BlM2vUP6X6/uH1AbQxzQeYUnFvE5HFu8oSSHb01Xp WqGXrsQj/4OlG9V9KCBM1ADX/OEmMb34gjriLRjS0TPDk967x6XMLtpdxPsyWI2Fh2M2 FAHPcgDQ39GZoQnl3bgGgMS3RPo09Ft62AxFFU8oNh2vlr5DAPFp7xA6tOLIP6rjhe7W B42A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=3YQhDg3+q1M52Rhy5caaOTb7HIY4QV+aC2PWnXcjTxI=; b=nnu5Rkd7DhkY4EFvUCkrq0OdAIt66VQ48FzeduPZQ9+k2taRIuh9kdmKDxJPKhX03F h6PjTtYr/PIhkahazuKpJVg+OhAtCkDpqMJTyiJorQI9+rpMsOO6nFI04XYjEazOPogk 1mrzO8TnLC66pl6jZKn0fRvd66uRAwF3AliVClmFsPKbZSwvXj+BD9hZwLOLt5YZ/R/u QN5oBbe/CmLDnHI+8HOfRordrkkK3ocRV4yvAZe7gFbfx2TLd/2XnHs7T+HS2/wZbuMs FxkG5TQ3qp3zFsuTXXftI+7ioDWDF0ESKcmbqqTioqZUfNskEWdEQd/MbksEkWvc0Vow iiAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=FsfQa6kC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b5-v6si17190274qvo.203.2018.05.30.07.43.55 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 30 May 2018 07:43:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=FsfQa6kC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:39055 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fO2KR-0004gF-HN for patch@linaro.org; Wed, 30 May 2018 10:43:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fO2JB-0004Fc-1K for qemu-devel@nongnu.org; Wed, 30 May 2018 10:42:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fO2JA-0007bP-0L for qemu-devel@nongnu.org; Wed, 30 May 2018 10:42:37 -0400 Received: from mail-pl0-x242.google.com ([2607:f8b0:400e:c01::242]:35809) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fO2J4-0007Zq-FL; Wed, 30 May 2018 10:42:30 -0400 Received: by mail-pl0-x242.google.com with SMTP id i5-v6so11222278plt.2; Wed, 30 May 2018 07:42:30 -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=3YQhDg3+q1M52Rhy5caaOTb7HIY4QV+aC2PWnXcjTxI=; b=FsfQa6kCTw72Jko5pqshm5+gbbCZ7Y7ILkgEUU1NNYOPpzeLbXP40go3icbTa6eHBj t5wYb+eGTSdRkxJCiHb1uerbamUFg+N4X724tV6TpxlgH7MCPMDnkz6kS7OF4fi8dx5O glNeEUDLO7qu+aEV/FpUe82XJC5SrtneLpvLglRbpnbX2NzunsBqs9QifM/IiiskZhlg vrNIm7MdKtnBUEr3ZhDAX6X376HAOp/6yYuk+emSU4HO5Vo77U5TUdx21ip2TtS713RS fdT9qAyIYqbpv3iS5hS7z7YtRpDGxbhAA6dohNqspIzYd2pt0L0nP8q86UeSOm+th089 oNuw== 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=3YQhDg3+q1M52Rhy5caaOTb7HIY4QV+aC2PWnXcjTxI=; b=R02w9UpzCOt5Ee8tQFvZyAwgyx/XDEuWId8apB4fnvQlo/H5aL0izmVoWTH5fXpSq/ kpJRPbjOfaTLfqJWPHILgQibtwNBxetdvnVlyxsHTlhW22GuTeRVIfd3e+WayYEjSeAc twFXFZfVxhPLmW875E/0/0r0sz4g+/+Ub7jrMiEagUG8LJx6d98dvXwktRyXsnD53PoV sK6HgVuq5JG4tlgtKleajzeiyB4Wwk4Sr0wOwyKZ5tEGgy7Ow1/AQw3f9Rz4VrX4lvxX lbGeo0NTNulER8m5P4HbtUkECm59D3yGx+J+Z+Lhausc3LbvapFUdIpqSo0uXel2t8/O 0sXg== X-Gm-Message-State: ALKqPwfs5YqQIfu82CsYjh4OtehI8BbrJpDvqa7W2MAkLsta9fNv4UjZ lx3OinuwIPoLjYBkFvNwbuA= X-Received: by 2002:a17:902:56e:: with SMTP id 101-v6mr3159379plf.25.1527691349243; Wed, 30 May 2018 07:42:29 -0700 (PDT) Received: from aurora.jms.id.au ([45.124.203.19]) by smtp.gmail.com with ESMTPSA id u13-v6sm23111817pfn.59.2018.05.30.07.42.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 May 2018 07:42:28 -0700 (PDT) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Thu, 31 May 2018 00:12:21 +0930 From: Joel Stanley To: David Gibson , Alexander Graf , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Date: Thu, 31 May 2018 00:12:17 +0930 Message-Id: <20180530144217.8959-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:c01::242 Subject: [Qemu-devel] [PATCH] 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 Neuling , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Michael Ellerman Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- 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(-) -- 2.17.0 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..40c39d08ad14 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" @@ -186,6 +187,15 @@ void ppc_store_msr(CPUPPCState *env, target_ulong value) hreg_store_msr(env, value, 0); } +void helper_store_pcr(CPUPPCState *env, target_ulong value) +{ + if (value != 0) { + error_report("Unimplemented PCR value 0x"TARGET_FMT_lx, value); + return; + } + env->spr[SPR_PCR] = value; +} + /* This code is lifted from MacOnLinux. It is called whenever * THRM1,2 or 3 is read an fixes up the values in such a way * that will make MacOS not hang. These registers exist on some diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c index ab782cb32aaa..bebe6ec5333c 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -456,6 +456,10 @@ static void spr_write_hid0_601(DisasContext *ctx, int sprn, int gprn) /* Must stop the translation as endianness may have changed */ gen_stop_exception(ctx); } +static void spr_write_pcr(DisasContext *ctx, int sprn, int gprn) +{ + gen_helper_store_pcr(cpu_env, cpu_gpr[gprn]); +} #endif /* Unified bats */ @@ -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); }