From: Andrew Jones <ajones@ventanamicro.com>
To: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Cc: 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>,
Peter Maydell <peter.maydell@linaro.org>,
qemu-riscv@nongnu.org, qemu-devel@nongnu.org,
kvm-riscv@lists.infradead.org
Subject: Re: [PATCH v2 1/1] target/riscv: enable floating point unit
Date: Wed, 25 Sep 2024 13:06:35 +0200 [thread overview]
Message-ID: <20240925-27610830c7f6c0235bc8b1a1@orel> (raw)
In-Reply-To: <20240925061704.12440-1-heinrich.schuchardt@canonical.com>
On Wed, Sep 25, 2024 at 08:17:04AM GMT, Heinrich Schuchardt wrote:
> The status and mstatus CSRs contain bit field FS, which control if the
> floating point unit of RISC-V hart is enabled.
>
> There seems to be no specification prescribing the value of the field when
> entering S-mode from M-mode. But OpenSBI, as the leading SBI M-mode
> firmware, has set a precedent by enabling the FPU by setting the value of
> FS to 3 (dirty).
>
> In TCG mode, QEMU uses OpenSBI by default. Users can reasonably expect that
> software running QEMU in TCG mode and in KVM mode behaves similarly.
>
> When QEMU in KVM mode creates a vCPU, Linux' KVM code sets FS=1 (initial)
> in kvm_riscv_vcpu_fp_reset(). However, QEMU internally keeps a value of
> FS=0 (off) and then synchronizes this value into KVM. Thus VS-mode software
> is invoked with a disabled floating point unit.
>
> One example of software being impacted is EDK II with TLS enabled. It
> crashes when hitting the first floating point instruction while running
> QEMU with --accel kvm, and runs fine with --accel tcg.
>
> With this patch the FPU will be enabled when entering S-mode in KVM mode
> and when entering M-mode in TCG mode.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
> v2:
> Rewrite the commit message as suggested in the v1 thread
> https://lore.kernel.org/qemu-riscv/20240916181633.366449-1-heinrich.schuchardt@canonical.com/
> ---
> target/riscv/cpu.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index 4bda754b01..c32e2721d4 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -923,6 +923,13 @@ static void riscv_cpu_reset_hold(Object *obj, ResetType type)
> if (mcc->parent_phases.hold) {
> mcc->parent_phases.hold(obj, type);
> }
> + if (riscv_has_ext(env, RVF) || riscv_has_ext(env, RVD)) {
> + env->mstatus = set_field(env->mstatus, MSTATUS_FS, env->misa_mxl);
> + for (int regnr = 0; regnr < 32; ++regnr) {
> + env->fpr[regnr] = 0;
> + }
> + riscv_csrrw(env, CSR_FCSR, NULL, 0, -1);
> + }
> #ifndef CONFIG_USER_ONLY
> env->misa_mxl = mcc->misa_mxl_max;
> env->priv = PRV_M;
> --
> 2.45.2
>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
next prev parent reply other threads:[~2024-09-25 11:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-25 6:17 [PATCH v2 1/1] target/riscv: enable floating point unit Heinrich Schuchardt
2024-09-25 11:06 ` Andrew Jones [this message]
2024-10-03 18:40 ` Richard Henderson
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=20240925-27610830c7f6c0235bc8b1a1@orel \
--to=ajones@ventanamicro.com \
--cc=alistair.francis@wdc.com \
--cc=bmeng.cn@gmail.com \
--cc=dbarboza@ventanamicro.com \
--cc=heinrich.schuchardt@canonical.com \
--cc=kvm-riscv@lists.infradead.org \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--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).