From: Jia He <justin.he@arm.com>
To: maz@kernel.org, oupton@kernel.org
Cc: fuad.tabba@linux.dev, joey.gouly@arm.com, seiden@linux.ibm.com,
suzuki.poulose@arm.com, yuzenghui@huawei.com,
catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com,
pbonzini@redhat.com, seanjc@google.com, shuah@kernel.org,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, Jia He <justin.he@arm.com>,
Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH v3 1/4] KVM: arm64: nv: Locate the VNCR page in the host page from its PA
Date: Sat, 28 Nov 2026 01:14:44 +0000 [thread overview]
Message-ID: <20261128011447.3588988-2-justin.he@arm.com> (raw)
In-Reply-To: <20261128011447.3588988-1-justin.he@arm.com>
VNCR_EL2 only needs to be 4K aligned. On a host with 16K or 64K pages,
kvm_translate_vncr() records the host page that contains the guest
hypervisor's VNCR page, and that host page is mapped at the VNCR fixmap.
__compute_hcr() then takes the offset of the VNCR page in the host page
from bits [PAGE_SHIFT-1:12] of the guest's VNCR_EL2, which is a VA.
If the guest hypervisor uses a stage-1 granule smaller than the host
page, these bits of the VA and of the PA can differ. The nested context
then accesses another 4K page of the guest instead of the VNCR page.
Take the offset from the PA that the walk returns, and keep it in
vt->hpa. Use it only while the VNCR page is mapped. Otherwise the
fixmap is clear, the access faults and KVM translates VNCR_EL2 again,
so the offset does not matter.
Tested on a Neoverse-N2 host running 16K and 64K page kernels, with the
selftest added later in this series. The test maps the VNCR page at a VA
whose bits [15:12] differ from those of its PA. With the offset taken
from the VA, the nested context reads 0 instead of the value in the VNCR
page. With this patch, it reads the expected value.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-232440@kernel.org/
Fixes: 73e1b621b25d ("KVM: arm64: nv: Program host's VNCR_EL2 to the fixmap address")
Signed-off-by: Jia He <justin.he@arm.com>
---
arch/arm64/include/asm/kvm_nested.h | 1 +
arch/arm64/kvm/hyp/vhe/switch.c | 9 +++++++--
arch/arm64/kvm/nested.c | 8 +++++++-
3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/include/asm/kvm_nested.h b/arch/arm64/include/asm/kvm_nested.h
index 0f899addafa8..bc54a4b2e863 100644
--- a/arch/arm64/include/asm/kvm_nested.h
+++ b/arch/arm64/include/asm/kvm_nested.h
@@ -432,6 +432,7 @@ int __kvm_find_s1_desc_level(struct kvm_vcpu *vcpu, u64 va, u64 ipa,
/* VNCR management */
int kvm_vcpu_allocate_vncr_tlb(struct kvm_vcpu *vcpu);
int kvm_handle_vncr_abort(struct kvm_vcpu *vcpu);
+unsigned long kvm_vncr_page_offset(struct kvm_vcpu *vcpu);
void kvm_handle_s1e2_tlbi(struct kvm_vcpu *vcpu, u32 inst, u64 val);
u16 get_asid_by_regime(struct kvm_vcpu *vcpu, enum trans_regime regime);
diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c
index 3f2390a13173..0d15beea418c 100644
--- a/arch/arm64/kvm/hyp/vhe/switch.c
+++ b/arch/arm64/kvm/hyp/vhe/switch.c
@@ -94,8 +94,13 @@ static u64 __compute_hcr(struct kvm_vcpu *vcpu)
if (guest_hcr & HCR_EL2_NV) {
u64 va = __fix_to_virt(vncr_fixmap(smp_processor_id()));
- /* Inherit the low bits from the actual register */
- va |= __vcpu_sys_reg(vcpu, VNCR_EL2) & GENMASK(PAGE_SHIFT - 1, 0);
+ /*
+ * The fixmap maps the host page that contains the VNCR
+ * page. Locate the VNCR page in it from its PA: with a
+ * smaller guest granule, the VA may have another offset.
+ */
+ if (host_data_test_flag(L1_VNCR_MAPPED))
+ va |= kvm_vncr_page_offset(vcpu);
write_sysreg_s(va, SYS_VNCR_EL2);
/* Force NV2 in case the guest is forgetful... */
diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
index 4d83281a7a28..08582fbc09d5 100644
--- a/arch/arm64/kvm/nested.c
+++ b/arch/arm64/kvm/nested.c
@@ -1643,7 +1643,7 @@ static int kvm_translate_vncr(struct kvm_vcpu *vcpu, bool *is_gmem)
}
vt->gva = va;
- vt->hpa = pfn << PAGE_SHIFT;
+ vt->hpa = (pfn << PAGE_SHIFT) | offset_in_page(vt->wr.pa);
vt->hpa_writable = writable;
vt->valid = true;
atomic_set(&vt->cpu, -1);
@@ -1683,6 +1683,12 @@ static void handle_vncr_perm(struct kvm_vcpu *vcpu)
kvm_inject_nested_sync(vcpu, esr);
}
+/* Offset of the VNCR page in the host page mapped at the VNCR fixmap */
+unsigned long kvm_vncr_page_offset(struct kvm_vcpu *vcpu)
+{
+ return offset_in_page(vcpu->arch.vncr_tlb->hpa);
+}
+
int kvm_handle_vncr_abort(struct kvm_vcpu *vcpu)
{
struct vncr_tlb *vt = vcpu->arch.vncr_tlb;
--
2.34.1
next prev parent reply other threads:[~2026-11-28 1:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 1:14 [PATCH v3 0/4] KVM: arm64: nv: VNCR page mapping fixes Jia He
2026-11-28 1:14 ` Jia He [this message]
2026-11-28 1:14 ` [PATCH v3 2/4] KVM: arm64: nv: Inject an SEA when the VNCR walk cannot set the AF Jia He
2026-11-28 1:14 ` [PATCH v3 3/4] KVM: arm64: selftests: Add a test for VNCR_EL2 translation faults Jia He
2026-11-28 1:14 ` [PATCH v3 4/4] KVM: arm64: nv: Allow the L1 VNCR page in cacheable PFNMAP memory Jia He
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=20261128011447.3588988-2-justin.he@arm.com \
--to=justin.he@arm.com \
--cc=catalin.marinas@arm.com \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=pbonzini@redhat.com \
--cc=sashiko-bot@kernel.org \
--cc=seanjc@google.com \
--cc=seiden@linux.ibm.com \
--cc=shuah@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--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®