From: Zenghui Yu <zenghui.yu@linux.dev>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, agraf@csgraf.de
Subject: Re: [PATCH] hvf: arm: Emulate ICC_RPR_EL1 accesses properly
Date: Sun, 22 Jun 2025 16:56:27 +0800 [thread overview]
Message-ID: <816aeea6-34c3-461c-b596-f8701a9d1557@linux.dev> (raw)
In-Reply-To: <d9c8d200-4453-48d7-b14a-8e15a7cf6602@linux.dev>
Hi Peter,
Sorry for the long delay..
On 2025/3/21 00:55, Zenghui Yu wrote:
> On 2025/3/19 00:56, Peter Maydell wrote:
> >
> > ICC_RPR_EL1 is a read-only register.
>
> Yup! Writes to it should result in an UNDEFINED exception. I completely
> missed that point..
>
> > But hvf_sysreg_read_cp()
> > and hvf_sysreg_write_cp() do not check the .access field of the
> > ARMCPRegInfo to ensure that they forbid writes to registers that
> > are marked with a .access field that says they're read-only
> > (and ditto reads to write-only registers). So either we should
> > not list ICC_RPR_EL1 in this list in hvf_sysreg_write(), or
> > else we should add the .access checks to hvf_sysreg_read_cp()
> > and hvf_sysreg_write_cp().
> >
> > I would favour the second of those two options, because it's
> > more robust and means we only need to care about the access
> > permissions of a register in one place. Plus we already get
> > this wrong for some registers: for instance ICC_SGI1R_EL1
> > is write-only but we will permit the guest to read it.
> >
> > So I suggest a 2-patch series:
> > * patch 1: add the checks on .access to hvf_sysreg_read_cp()
> > and hvf_sysreg_write_cp(): they need to call
> > cp_access_ok() to check this
>
> Thanks for your detailed suggestion Peter! I come up with something like
>
> diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
> index 650b7f4256..a7ca7975e0 100644
> --- a/target/arm/hvf/hvf.c
> +++ b/target/arm/hvf/hvf.c
> @@ -1264,6 +1264,9 @@ static bool hvf_sysreg_read_cp(CPUState *cpu, uint32_t reg, uint64_t *val)
>
> ri = get_arm_cp_reginfo(arm_cpu->cp_regs, hvf_reg2cp_reg(reg));
> if (ri) {
> + if (!cp_access_ok(arm_current_el(env), ri, true)) {
I wonder if arm_current_el() can be used at it to determine the current
exception EL.
|static inline int arm_current_el(CPUARMState *env)
|{
| // ...
|
| if (is_a64(env)) {
| return extract32(env->pstate, 2, 2);
| }
I failed to find where env->pstate gets updated on vcpu exit. Please fix
me up if I've missed any obvious points.
> + return false;
> + }
> if (ri->accessfn) {
> if (ri->accessfn(env, ri, true) != CP_ACCESS_OK) {
> return false;
> @@ -1545,6 +1548,9 @@ static bool hvf_sysreg_write_cp(CPUState *cpu, uint32_t reg, uint64_t val)
> ri = get_arm_cp_reginfo(arm_cpu->cp_regs, hvf_reg2cp_reg(reg));
>
> if (ri) {
> + if (!cp_access_ok(arm_current_el(env), ri, false)) {
> + return false;
> + }
> if (ri->accessfn) {
> if (ri->accessfn(env, ri, false) != CP_ACCESS_OK) {
> return false;
Thanks,
Zenghui
prev parent reply other threads:[~2025-06-22 8:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-15 13:20 [PATCH] hvf: arm: Emulate ICC_RPR_EL1 accesses properly Zenghui Yu
2025-03-18 16:56 ` Peter Maydell
2025-03-20 16:55 ` Zenghui Yu
2025-06-22 8:56 ` Zenghui Yu [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=816aeea6-34c3-461c-b596-f8701a9d1557@linux.dev \
--to=zenghui.yu@linux.dev \
--cc=agraf@csgraf.de \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.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).