From: Marc Zyngier <maz@kernel.org>
To: Oliver Upton <oupton@kernel.org>
Cc: kvmarm@lists.linux.dev, Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Wei-Lin Chang <weilin.chang@arm.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Fuad Tabba <fuad.tabba@linux.dev>,
stable@vger.kernel.org
Subject: Re: [PATCH v2 7/8] KVM: arm64: nv: Enforce sysreg visibility before evaulating guest traps
Date: Tue, 17 Nov 2026 19:33:38 +0000 [thread overview]
Message-ID: <86cxs31cdp.wl-maz@kernel.org> (raw)
In-Reply-To: <20261106183154.3590825-8-oupton@kernel.org>
On Fri, 06 Nov 2026 18:31:53 +0000,
Oliver Upton <oupton@kernel.org> wrote:
>
> Not all sysregs / system instructions can be described by FGUs. Of
> these, there are some which may be not implemented for the VM (e.g. MTE
> cache maintenance instructions) yet intersect with valid trap bits for
> the VM (HCR_EL2.TPCP).
>
> This is annoying to deal with since most of our UNDEF infrastructure is
> built around traps being RESx for unimplemented features. Test the
> visibility of the sys_reg_desc to avoid injecting traps for non-existent
> system registers into the guest hypervisor.
>
> Cc: stable@vger.kernel.org
> Fixes: a7484c80e5ca ("KVM: arm64: Allow userspace to request KVM_ARM_VCPU_EL2*")
> Signed-off-by: Oliver Upton <oupton@kernel.org>
> ---
> arch/arm64/kvm/emulate-nested.c | 24 +++++++++++++++++++++---
> arch/arm64/kvm/sys_regs.c | 18 ++++++++++--------
> arch/arm64/kvm/sys_regs.h | 4 +++-
> 3 files changed, 34 insertions(+), 12 deletions(-)
I think I had an allergic reaction to this patch, mostly due to the
leaking of sys_reg_desc into triage_sysreg_trap(), which makes the
change a bit noisy. I ended up with the following hack instead, which
doesn't change triage_sysreg_trap() much.
Thoughts?
M.
diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c
index d04ac52034541..762f9f0b7b193 100644
--- a/arch/arm64/kvm/emulate-nested.c
+++ b/arch/arm64/kvm/emulate-nested.c
@@ -2661,6 +2661,16 @@ bool triage_sysreg_trap(struct kvm_vcpu *vcpu, int *sr_index)
if (!(b & BEHAVE_FORWARD_IN_HOST_EL0) && vcpu_is_host_el0(vcpu))
goto local;
+ /*
+ * Certain sysregs and system instructions could be UNDEF for the VM
+ * but lack a corresponding FGU description and intersect with a valid
+ * trap bit for the VM. Test the visibility the sysreg (if we have a
+ * sys_reg_desc) before determining the effects of the guest
+ * hypervisor's traps.
+ */
+ if (tc.sri && check_sysreg_hidden(vcpu, sysreg, tc.sri - 1))
+ return true;
+
if (((b & BEHAVE_FORWARD_READ) && is_read) ||
((b & BEHAVE_FORWARD_WRITE) && !is_read))
goto inject;
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 7f7a197a9ad6b..f21112d8d2950 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -5407,6 +5407,25 @@ void kvm_reset_sys_regs(struct kvm_vcpu *vcpu)
kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
}
+static const struct sys_reg_desc *kvm_sys_reg_idx_to_desc(u32 encoding, int sr_idx)
+{
+ /* System registers have Op0=={2,3}, as per DDI487 J.a C5.1.2 */
+ if (sys_reg_Op0(encoding) == 2 || sys_reg_Op0(encoding) == 3)
+ return &sys_reg_descs[sr_idx];
+ else
+ return &sys_insn_descs[sr_idx];
+}
+
+bool check_sysreg_hidden(struct kvm_vcpu *vcpu, u32 encoding, int sr_idx)
+{
+ if (sysreg_guest_hidden(vcpu, kvm_sys_reg_idx_to_desc(encoding, sr_idx))) {
+ kvm_inject_undefined(vcpu);
+ return true;
+ }
+
+ return false;
+}
+
/**
* kvm_handle_sys_reg -- handles a system instruction or mrs/msr instruction
* trap on a guest execution
@@ -5414,10 +5433,10 @@ void kvm_reset_sys_regs(struct kvm_vcpu *vcpu)
*/
int kvm_handle_sys_reg(struct kvm_vcpu *vcpu)
{
- const struct sys_reg_desc *desc = NULL;
struct sys_reg_params params;
unsigned long esr = kvm_vcpu_get_esr(vcpu);
int Rt = kvm_vcpu_sys_get_rt(vcpu);
+ u32 encoding = esr_sys64_to_sysreg(esr);
int sr_idx;
trace_kvm_handle_sys_reg(esr);
@@ -5428,13 +5447,7 @@ int kvm_handle_sys_reg(struct kvm_vcpu *vcpu)
params = esr_sys64_to_params(esr);
params.regval = vcpu_get_reg(vcpu, Rt);
- /* System registers have Op0=={2,3}, as per DDI487 J.a C5.1.2 */
- if (params.Op0 == 2 || params.Op0 == 3)
- desc = &sys_reg_descs[sr_idx];
- else
- desc = &sys_insn_descs[sr_idx];
-
- perform_access(vcpu, ¶ms, desc);
+ perform_access(vcpu, ¶ms, kvm_sys_reg_idx_to_desc(encoding, sr_idx));
/* Read from system register? */
if (!params.is_write &&
diff --git a/arch/arm64/kvm/sys_regs.h b/arch/arm64/kvm/sys_regs.h
index 50214271b24a2..7b24c2703b634 100644
--- a/arch/arm64/kvm/sys_regs.h
+++ b/arch/arm64/kvm/sys_regs.h
@@ -267,6 +267,8 @@ bool triage_sysreg_trap(struct kvm_vcpu *vcpu, int *sr_index);
int kvm_vcpu_finalize_sys_regs(struct kvm_vcpu *vcpu);
+bool check_sysreg_hidden(struct kvm_vcpu *vcpu, u32 encoding, int sr_idx);
+
#define AA32(_x) .aarch32_map = AA32_##_x
#define Op0(_x) .Op0 = _x
#define Op1(_x) .Op1 = _x
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2026-11-17 19:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261106183154.3590825-1-oupton@kernel.org>
2026-11-06 18:31 ` [PATCH v2 1/8] KVM: arm64: nv: Disallow KVM_CAP_ARM_MTE + FEAT_EL2 Oliver Upton
2026-11-08 5:30 ` Wei-Lin Chang
2026-11-06 18:31 ` [PATCH v2 7/8] KVM: arm64: nv: Enforce sysreg visibility before evaulating guest traps Oliver Upton
2026-11-17 19:33 ` Marc Zyngier [this message]
2026-11-06 18:31 ` [PATCH v2 8/8] KVM: arm64: Stop leaning on __kvm_inject_sea() for abort injection Oliver Upton
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=86cxs31cdp.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=oupton@kernel.org \
--cc=seiden@linux.ibm.com \
--cc=stable@vger.kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=weilin.chang@arm.com \
--cc=yuzenghui@huawei.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