From: Fabiano Rosas <farosas@linux.ibm.com>
To: matheus.ferst@eldorado.org.br, qemu-devel@nongnu.org,
qemu-ppc@nongnu.org
Cc: danielhb413@gmail.com, richard.henderson@linaro.org,
groug@kaod.org, clg@kaod.org,
Matheus Ferst <matheus.ferst@eldorado.org.br>,
david@gibson.dropbear.id.au
Subject: Re: [RFC PATCH v3 3/3] target/ppc: Fix gen_priv_exception error value in mfspr/mtspr
Date: Wed, 02 Feb 2022 16:12:02 -0300 [thread overview]
Message-ID: <8735l19j7h.fsf@linux.ibm.com> (raw)
In-Reply-To: <20220113170456.1796911-4-matheus.ferst@eldorado.org.br>
matheus.ferst@eldorado.org.br writes:
> From: Matheus Ferst <matheus.ferst@eldorado.org.br>
>
> The code in linux-user/ppc/cpu_loop.c expects POWERPC_EXCP_PRIV
> exception with error POWERPC_EXCP_PRIV_OPC or POWERPC_EXCP_PRIV_REG,
> while POWERPC_EXCP_INVAL_SPR is expected in POWERPC_EXCP_INVAL
> exceptions. This mismatch caused an EXCP_DUMP with the message "Unknown
> privilege violation (03)", as seen in [1].
>
> Fixes: 9b2fadda3e01 ("ppc: Rework generation of priv and inval interrupts")
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/588
>
> [1] https://gitlab.com/qemu-project/qemu/-/issues/588
>
> Signed-off-by: Matheus Ferst <matheus.ferst@eldorado.org.br>
This patch seems to do the right thing. So:
Reviewed-by: Fabiano Rosas <farosas@linux.ibm.com>
Now, I'm not sure if the code around it does the right thing. =)
Specifically the else blocks (read_cb == NULL) and (write_cb ==
NULL). From _spr_register I understand that cb == NULL means this is not
a recognized SPR by this processor*. So in my mind 100% of them should be
invalid SPR exceptions.
The reserved SPRs should be registered in cpu_init and handled as
"known, but privileged" or "known, but noop". Maybe using SPR_NOACCESS
and/or a new SPR_NOOP. It might be a bit tricky because they have no names,
but that is an implementation detail.
* - there's some nuance here because of the system vs. linux-user build
time configuration so I'm not entirely sure.
Let's think a bit more about this. Everything seems to work just fine
the way it is so there's no rush. But I think this code could perhaps be
simplified and some of these assumptions handled at build time with
spr_register.
> ---
> Is there any case where throwing a PRIV/INVAL exception with a
> INVAL/PRIV error makes sense? It seems wrong, but maybe I'm missing
> something... especially with the HV_EMU to program check conversion.
>
> Also, if this patch is correct, it seems that all invalid SPR access
> would be nop or privilege exceptions. In this case, is
> POWERPC_EXCP_INVAL_SPR still needed?
I agree that as it stands this is not needed. But we might want to bring
it back given the points I mentioned above. So let's keep it for now.
> ---
> target/ppc/translate.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/target/ppc/translate.c b/target/ppc/translate.c
> index 40232201bb..abbc3a5bb9 100644
> --- a/target/ppc/translate.c
> +++ b/target/ppc/translate.c
> @@ -4827,11 +4827,11 @@ static inline void gen_op_mfspr(DisasContext *ctx)
> */
> if (sprn & 0x10) {
> if (ctx->pr) {
> - gen_priv_exception(ctx, POWERPC_EXCP_INVAL_SPR);
> + gen_priv_exception(ctx, POWERPC_EXCP_PRIV_REG);
> }
> } else {
> if (ctx->pr || sprn == 0 || sprn == 4 || sprn == 5 || sprn == 6) {
> - gen_hvpriv_exception(ctx, POWERPC_EXCP_INVAL_SPR);
> + gen_hvpriv_exception(ctx, POWERPC_EXCP_PRIV_REG);
> }
> }
> }
> @@ -5014,11 +5014,11 @@ static void gen_mtspr(DisasContext *ctx)
> */
> if (sprn & 0x10) {
> if (ctx->pr) {
> - gen_priv_exception(ctx, POWERPC_EXCP_INVAL_SPR);
> + gen_priv_exception(ctx, POWERPC_EXCP_PRIV_REG);
> }
> } else {
> if (ctx->pr || sprn == 0) {
> - gen_hvpriv_exception(ctx, POWERPC_EXCP_INVAL_SPR);
> + gen_hvpriv_exception(ctx, POWERPC_EXCP_PRIV_REG);
> }
> }
> }
next prev parent reply other threads:[~2022-02-02 19:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-13 17:04 [PATCH v3 0/3] linux-user/ppc: Deliver SIGTRAP on tw[i]/td[i] matheus.ferst
2022-01-13 17:04 ` [PATCH v3 1/3] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP matheus.ferst
2022-03-04 13:27 ` Laurent Vivier
2022-01-13 17:04 ` [PATCH v3 2/3] tests/tcg/ppc64le: change signal_save_restore_xer to use SIGTRAP matheus.ferst
2022-03-04 13:28 ` Laurent Vivier
2022-01-13 17:04 ` [RFC PATCH v3 3/3] target/ppc: Fix gen_priv_exception error value in mfspr/mtspr matheus.ferst
2022-02-02 19:12 ` Fabiano Rosas [this message]
2022-03-04 14:42 ` Laurent Vivier
2022-03-10 16:26 ` Matheus K. Ferst
2022-02-01 19:02 ` [PATCH v3 0/3] linux-user/ppc: Deliver SIGTRAP on tw[i]/td[i] Matheus K. Ferst
2022-02-21 20:34 ` Matheus K. Ferst
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=8735l19j7h.fsf@linux.ibm.com \
--to=farosas@linux.ibm.com \
--cc=clg@kaod.org \
--cc=danielhb413@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=groug@kaod.org \
--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).