qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alistair Francis <alistair23@gmail.com>
To: "~yuming" <yumin686@andestech.com>
Cc: qemu-riscv@nongnu.org, qemu-devel@nongnu.org,
	 Palmer Dabbelt <palmer@dabbelt.com>,
	Alistair Francis <alistair.francis@wdc.com>,
	 Bin Meng <bmeng.cn@gmail.com>, Weiwei Li <liwei1518@gmail.com>,
	 Daniel Henrique Barboza <dbarboza@ventanamicro.com>,
	Liu Zhiwei <zhiwei_liu@linux.alibaba.com>
Subject: Re: [PATCH qemu v2] target/riscv: Check ext_zca for misaligned return address of mret/sret.
Date: Mon, 24 Feb 2025 13:45:19 +1000	[thread overview]
Message-ID: <CAKmqyKOOoYpdJVDk=7+iehteoOrPsHJ4FSWqqHAeWK3HiC0GHw@mail.gmail.com> (raw)
In-Reply-To: <173856049155.9683.4580810619712230382-0@git.sr.ht>

On Mon, Feb 3, 2025 at 3:34 PM ~yuming <yuming@git.sr.ht> wrote:
>
> From: Yu-Ming Chang <yumin686@andestech.com>
>
> We only check RVC to allow 16-bit aligned return addreses. This will
> cause issues when only ext_zca is enabled without RVC: 16-bit
> instructions are allowed, but 16-bit aligned return address are not.
> We should also check ext_zca to permit 16-bit aligned return addresses.
>
> Signed-off-by: Yu-Ming Chang <yumin686@andestech.com>
> ---
> The v2 has been updated to provide more explanation.
>
>  target/riscv/op_helper.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
> index eddedacf4b..891002f954 100644
> --- a/target/riscv/op_helper.c
> +++ b/target/riscv/op_helper.c
> @@ -269,8 +269,10 @@ target_ulong helper_sret(CPURISCVState *env)
>      }
>
>      target_ulong retpc = env->sepc;
> -    if (!riscv_has_ext(env, RVC) && (retpc & 0x3)) {
> -        riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, GETPC());
> +    if (!riscv_has_ext(env, RVC) && !env_archcpu(env)->cfg.ext_zca) {

You can just check ext_zca as C always implies Zca

Alistair

> +        if ((retpc & 0x3) != 0) {
> +            riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, GETPC());
> +        }
>      }
>
>      if (get_field(env->mstatus, MSTATUS_TSR) && !(env->priv >= PRV_M)) {
> @@ -328,8 +330,10 @@ target_ulong helper_mret(CPURISCVState *env)
>      }
>
>      target_ulong retpc = env->mepc;
> -    if (!riscv_has_ext(env, RVC) && (retpc & 0x3)) {
> -        riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, GETPC());
> +    if (!riscv_has_ext(env, RVC) && !env_archcpu(env)->cfg.ext_zca) {
> +        if ((retpc & 0x3) != 0) {
> +            riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, GETPC());
> +        }
>      }
>
>      uint64_t mstatus = env->mstatus;
> --
> 2.45.3
>


  reply	other threads:[~2025-02-24  3:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-16  2:40 [PATCH qemu v2] target/riscv: Check ext_zca for misaligned return address of mret/sret ~yuming
2025-02-24  3:45 ` Alistair Francis [this message]
2025-02-25  1:55   ` Yuming Yu-Ming Chang(張育銘)

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='CAKmqyKOOoYpdJVDk=7+iehteoOrPsHJ4FSWqqHAeWK3HiC0GHw@mail.gmail.com' \
    --to=alistair23@gmail.com \
    --cc=alistair.francis@wdc.com \
    --cc=bmeng.cn@gmail.com \
    --cc=dbarboza@ventanamicro.com \
    --cc=liwei1518@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=yumin686@andestech.com \
    --cc=zhiwei_liu@linux.alibaba.com \
    /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).