From: Colton Lewis <coltonlewis@google.com>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>
Cc: Leonardo Bras <leo.bras@arm.com>, Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Fuad Tabba <fuad.tabba@linux.dev>,
kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Colton Lewis <coltonlewis@google.com>
Subject: [PATCH v3 0/2] KVM: arm64: Force HCR_EL2.NV1 to RES0 unconditionally
Date: Wed, 18 Nov 2026 20:36:23 +0000 [thread overview]
Message-ID: <20261118203625.743428-1-coltonlewis@google.com> (raw)
When commit b2a324ff01fe ("KVM: arm64: Use HCR_EL2 feature map to drive
fixed-value bits") migrated HCR_EL2 fixed-bit masking to hcr_feat_map[],
feat_nv2_e2h0_ni() was written as !kvm_has_feat(kvm, FEAT_E2H0). Because
ID_AA64MMFR4_EL1.E2H0 is a signed 4-bit field where IMP is 0, NI is -1,
and NI_NV1 is -2, !kvm_has_feat(kvm, FEAT_E2H0) evaluates to true when
E2H0 < 0 (including NI_NV1), leaving HCR_EL2.NV1 writable instead of
RES0 for VHE-only nested guests where KVM advertises E2H0 = NI_NV1.
KVM never supports a configuration where HCR_EL2.NV1 is non-RES0
(limit_nv_id_reg() exposes either VHE-only EL2 with E2H0 = NI_NV1 where
E2H0 is not userspace-writable, or FEAT_E2H0 without FEAT_VHE or
FEAT_NV).
Patch 1 drops feat_nv2_e2h0_ni() and marks HCR_EL2.NV1 unconditionally
RES0 using NEEDS_FEAT_FLAG(HCR_EL2_NV1, FORCE_RESx).
Patch 2 extends the arm64 hello_el2 selftest to verify via
KVM_SET_ONE_REG and KVM_GET_ONE_REG that HCR_EL2.E2H remains RES1 and
HCR_EL2.NV1 remains RES0 when E2H0 is NI_NV1.
Changes in v3:
- Drop feat_nv2_nv1_not_res0() and force HCR_EL2.NV1 to RES0
unconditionally via NEEDS_FEAT_FLAG(HCR_EL2_NV1, FORCE_RESx) (Marc).
- Add Suggested-by: Marc Zyngier <maz@kernel.org> on patch 1.
- Add a comment in hello_el2.c explaining why RESx enforcement is
checked from userspace rather than inside the guest (Oliver).
- Link to v2: https://lore.kernel.org/r/20261117204535.4036191-1-coltonlewis@google.com
Tested under QEMU 11.1.2 TCG (arm64, kvm-arm.mode=nested): hello_el2
fails with "HCR_EL2.NV1 should be RES0" on unpatched v7.4-rc3 and passes
with this series applied, with no check_feature_map() warnings at boot.
Changes in v2:
- Rename feat_nv2_e2h0_ni() to feat_nv2_nv1_not_res0() (Leonardo).
- Drop the guest EL2 MSR/MRS HCR_EL2 check in hello_el2 (Marc).
- Link to v1: https://lore.kernel.org/r/20261116200418.3535619-1-coltonlewis@google.com
Colton Lewis (2):
KVM: arm64: Force HCR_EL2.NV1 to RES0 unconditionally
KVM: arm64: selftests: Verify HCR_EL2.NV1 is RES0 when E2H0 is NI_NV1
arch/arm64/kvm/config.c | 7 +------
tools/testing/selftests/kvm/arm64/hello_el2.c | 15 +++++++++++++++
2 files changed, 16 insertions(+), 6 deletions(-)
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.56.1.750.gf70dc682cf-goog
next reply other threads:[~2026-11-18 20:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 20:36 Colton Lewis [this message]
2026-11-18 20:36 ` [PATCH v3 1/2] " Colton Lewis
2026-11-18 20:36 ` [PATCH v3 2/2] KVM: arm64: selftests: Verify HCR_EL2.NV1 is RES0 when E2H0 is NI_NV1 Colton Lewis
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=20261118203625.743428-1-coltonlewis@google.com \
--to=coltonlewis@google.com \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=leo.bras@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=suzuki.poulose@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
all inboxes | Powered by JetHome®