From nobody Fri May 3 02:51:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.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 1631220095787634.9839332965902; Thu, 9 Sep 2021 13:41:35 -0700 (PDT) Received: from localhost ([::1]:38038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOQrW-0005bo-Fi for importer@patchew.org; Thu, 09 Sep 2021 16:41:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47680) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOQlk-0004Xm-OZ; Thu, 09 Sep 2021 16:35:37 -0400 Received: from [201.28.113.2] (port=9947 helo=outlook.eldorado.org.br) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOQlj-0005xi-5N; Thu, 09 Sep 2021 16:35:36 -0400 Received: from power9a ([10.10.71.235]) by outlook.eldorado.org.br with Microsoft SMTPSVC(8.5.9600.16384); Thu, 9 Sep 2021 17:35:16 -0300 Received: from eldorado.org.br (unknown [10.10.70.45]) by power9a (Postfix) with ESMTP id 891D680121D; Thu, 9 Sep 2021 17:35:16 -0300 (-03) From: matheus.ferst@eldorado.org.br To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Subject: [PATCH 1/2] target/ppc: add LPCR[HR] to DisasContext and hflags Date: Thu, 9 Sep 2021 17:34:38 -0300 Message-Id: <20210909203439.4114179-2-matheus.ferst@eldorado.org.br> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210909203439.4114179-1-matheus.ferst@eldorado.org.br> References: <20210909203439.4114179-1-matheus.ferst@eldorado.org.br> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 09 Sep 2021 20:35:16.0930 (UTC) FILETIME=[3306C220:01D7A5BA] X-Host-Lookup-Failed: Reverse DNS lookup failed for 201.28.113.2 (failed) Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=201.28.113.2; envelope-from=matheus.ferst@eldorado.org.br; helo=outlook.eldorado.org.br X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leandro.lupori@eldorado.org.br, Matheus Ferst , richard.henderson@linaro.org, groug@kaod.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1631220096647100001 Content-Type: text/plain; charset="utf-8" From: Matheus Ferst Add a Host Radix field (hr) in DisasContext with LPCR[HR] value to allow us to decide between Radix and HPT while validating instructions arguments. Note that PowerISA v3.1 does not require LPCR[HR] and PATE.HR to match if the thread is in ultravisor/hypervisor real addressing mode, so ctx->hr may be invalid if ctx->hv and ctx->dr are set. Signed-off-by: Matheus Ferst Reviewed-by: Daniel Henrique Barboza --- target/ppc/cpu.h | 1 + target/ppc/helper_regs.c | 3 +++ target/ppc/translate.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 500205229c..e1b8d343cd 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -600,6 +600,7 @@ enum { HFLAGS_64 =3D 2, /* computed from MSR_CE and MSR_SF */ HFLAGS_GTSE =3D 3, /* computed from SPR_LPCR[GTSE] */ HFLAGS_DR =3D 4, /* MSR_DR */ + HFLAGS_HR =3D 5, /* computed from SPR_LPCR[HR] */ HFLAGS_SPE =3D 6, /* from MSR_SPE if cpu has SPE; avoid overlap w/ MS= R_VR */ HFLAGS_TM =3D 8, /* computed from MSR_TM */ HFLAGS_BE =3D 9, /* MSR_BE -- from elsewhere on embedded ppc */ diff --git a/target/ppc/helper_regs.c b/target/ppc/helper_regs.c index 405450d863..1bfb480ecf 100644 --- a/target/ppc/helper_regs.c +++ b/target/ppc/helper_regs.c @@ -106,6 +106,9 @@ static uint32_t hreg_compute_hflags_value(CPUPPCState *= env) if (env->spr[SPR_LPCR] & LPCR_GTSE) { hflags |=3D 1 << HFLAGS_GTSE; } + if (env->spr[SPR_LPCR] & LPCR_HR) { + hflags |=3D 1 << HFLAGS_HR; + } =20 #ifndef CONFIG_USER_ONLY if (!env->has_hv_mode || (msr & (1ull << MSR_HV))) { diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 171b216e17..909a092fde 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -175,6 +175,7 @@ struct DisasContext { bool spe_enabled; bool tm_enabled; bool gtse; + bool hr; ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */ int singlestep_enabled; uint32_t flags; @@ -8539,6 +8540,7 @@ static void ppc_tr_init_disas_context(DisasContextBas= e *dcbase, CPUState *cs) ctx->vsx_enabled =3D (hflags >> HFLAGS_VSX) & 1; ctx->tm_enabled =3D (hflags >> HFLAGS_TM) & 1; ctx->gtse =3D (hflags >> HFLAGS_GTSE) & 1; + ctx->hr =3D (hflags >> HFLAGS_HR) & 1; =20 ctx->singlestep_enabled =3D 0; if ((hflags >> HFLAGS_SE) & 1) { --=20 2.25.1 From nobody Fri May 3 02:51:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.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 1631219923825466.9396960692678; Thu, 9 Sep 2021 13:38:43 -0700 (PDT) Received: from localhost ([::1]:60304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOQok-0001Yv-R6 for importer@patchew.org; Thu, 09 Sep 2021 16:38:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOQlq-0004i3-2F; Thu, 09 Sep 2021 16:35:42 -0400 Received: from [201.28.113.2] (port=9947 helo=outlook.eldorado.org.br) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOQlo-0005xi-16; Thu, 09 Sep 2021 16:35:41 -0400 Received: from power9a ([10.10.71.235]) by outlook.eldorado.org.br with Microsoft SMTPSVC(8.5.9600.16384); Thu, 9 Sep 2021 17:35:17 -0300 Received: from eldorado.org.br (unknown [10.10.70.45]) by power9a (Postfix) with ESMTP id 850D080121D; Thu, 9 Sep 2021 17:35:17 -0300 (-03) From: matheus.ferst@eldorado.org.br To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Subject: [PATCH 2/2] target/ppc: Check privilege level based on PSR and LPCR[HR] in tlbie[l] Date: Thu, 9 Sep 2021 17:34:39 -0300 Message-Id: <20210909203439.4114179-3-matheus.ferst@eldorado.org.br> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210909203439.4114179-1-matheus.ferst@eldorado.org.br> References: <20210909203439.4114179-1-matheus.ferst@eldorado.org.br> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 09 Sep 2021 20:35:17.0915 (UTC) FILETIME=[339D0EB0:01D7A5BA] X-Host-Lookup-Failed: Reverse DNS lookup failed for 201.28.113.2 (failed) Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=201.28.113.2; envelope-from=matheus.ferst@eldorado.org.br; helo=outlook.eldorado.org.br X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leandro.lupori@eldorado.org.br, Matheus Ferst , richard.henderson@linaro.org, groug@kaod.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1631219924818100001 Content-Type: text/plain; charset="utf-8" From: Matheus Ferst PowerISA v3.0B made tlbie[l] hypervisor privileged when PSR=3D0 and HR=3D1. To allow the check at translation time, we'll use the HR bit of LPCR to check the MMU mode instead of the PATE.HR. Signed-off-by: Matheus Ferst --- target/ppc/translate.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 909a092fde..154ab26872 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -5517,7 +5517,15 @@ static void gen_tlbiel(DisasContext *ctx) #if defined(CONFIG_USER_ONLY) GEN_PRIV; #else - CHK_SV; + bool psr =3D (ctx->opcode >> 17) & 0x1; + + if (ctx->pr) { + GEN_PRIV; + } else if (!ctx->hv) { + if (!psr && ctx->hr) { + GEN_PRIV; + } + } =20 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); #endif /* defined(CONFIG_USER_ONLY) */ @@ -5529,12 +5537,15 @@ static void gen_tlbie(DisasContext *ctx) #if defined(CONFIG_USER_ONLY) GEN_PRIV; #else + bool psr =3D (ctx->opcode >> 17) & 0x1; TCGv_i32 t1; =20 - if (ctx->gtse) { - CHK_SV; /* If gtse is set then tlbie is supervisor privileged */ - } else { - CHK_HV; /* Else hypervisor privileged */ + if (ctx->pr) { + GEN_PRIV; + } else if (!ctx->hv) { + if (!ctx->gtse || (!psr && ctx->hr)) { + GEN_PRIV; + } } =20 if (NARROW_MODE(ctx)) { --=20 2.25.1