From: Daniel Henrique Barboza <danielhb413@gmail.com>
To: matheus.ferst@eldorado.org.br, qemu-devel@nongnu.org,
qemu-ppc@nongnu.org
Cc: richard.henderson@linaro.org, leandro.lupori@eldorado.org.br,
groug@kaod.org, david@gibson.dropbear.id.au
Subject: Re: [PATCH 2/2] target/ppc: Check privilege level based on PSR and LPCR[HR] in tlbie[l]
Date: Mon, 13 Sep 2021 16:38:04 -0300 [thread overview]
Message-ID: <5c143f6d-dd0e-54a8-682f-0810cfaef955@gmail.com> (raw)
In-Reply-To: <20210909203439.4114179-3-matheus.ferst@eldorado.org.br>
On 9/9/21 5:34 PM, matheus.ferst@eldorado.org.br wrote:
> From: Matheus Ferst <matheus.ferst@eldorado.org.br>
>
> PowerISA v3.0B made tlbie[l] hypervisor privileged when PSR=0 and HR=1.
> 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 <matheus.ferst@eldorado.org.br>
> ---
> 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 = (ctx->opcode >> 17) & 0x1;
> +
> + if (ctx->pr) {
> + GEN_PRIV;
> + } else if (!ctx->hv) {
> + if (!psr && ctx->hr) {
> + GEN_PRIV;
> + }
> + }
You can avoid the third 'if' clause by adding all the conditions of the
second GEN_PRIV in the second if:
> + if (ctx->pr) {
> + GEN_PRIV;
> + } else if (!ctx->hv && !psr && ctx->hr) {
> + GEN_PRIV;
> + }
Or, since all the code is doing is executing GEN_PRIV anyways:
> + if (ctx->pr || (!ctx->hv && !psr && ctx->hr)) {
> + GEN_PRIV;
> + }
I think this is clearer than chaining 'if' clauses.
>
> 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 = (ctx->opcode >> 17) & 0x1;
> TCGv_i32 t1;
>
> - 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;
> + }
> }
The same idea I mentioned above could be done here as well, but these are
not straightforward conditions to be done in a single IF clause and will
impact code reading. This is fine as is.
Thanks,
Daniel
>
> if (NARROW_MODE(ctx)) {
>
prev parent reply other threads:[~2021-09-13 19:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-09 20:34 [PATCH 0/2] Require hypervisor privilege for tlbie[l] when PSR=0 and HR=1 matheus.ferst
2021-09-09 20:34 ` [PATCH 1/2] target/ppc: add LPCR[HR] to DisasContext and hflags matheus.ferst
2021-09-13 19:24 ` Daniel Henrique Barboza
2021-09-09 20:34 ` [PATCH 2/2] target/ppc: Check privilege level based on PSR and LPCR[HR] in tlbie[l] matheus.ferst
2021-09-13 19:38 ` Daniel Henrique Barboza [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5c143f6d-dd0e-54a8-682f-0810cfaef955@gmail.com \
--to=danielhb413@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=groug@kaod.org \
--cc=leandro.lupori@eldorado.org.br \
--cc=matheus.ferst@eldorado.org.br \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).