From: Wei-Lin Chang <weilin.chang@arm.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
linux-kselftest@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Shuah Khan <shuah@kernel.org>, Marc Zyngier <maz@kernel.org>,
Oliver Upton <oupton@kernel.org>, Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Itaru Kitayama <itaru.kitayama@fujitsu.com>,
Wei-Lin Chang <weilin.chang@arm.com>
Subject: [PATCH v3 9/9] KVM: arm64: selftests: shadow_stage2: Turn on stage-2 translation for the nested guest
Date: Sat, 16 May 2026 19:30:03 +0100 [thread overview]
Message-ID: <20260516183003.799058-10-weilin.chang@arm.com> (raw)
In-Reply-To: <20260516183003.799058-1-weilin.chang@arm.com>
Utilize the stage-2 library functions to initialize a s2_mmu, build a
stage-2 page table, and turn on stage-2 translation for the nested
guest. This better tests out the shadow page table code in KVM.
Signed-off-by: Wei-Lin Chang <weilin.chang@arm.com>
---
.../selftests/kvm/arm64/shadow_stage2.c | 23 ++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/kvm/arm64/shadow_stage2.c b/tools/testing/selftests/kvm/arm64/shadow_stage2.c
index 2b274b810dcf..5bce55abdea7 100644
--- a/tools/testing/selftests/kvm/arm64/shadow_stage2.c
+++ b/tools/testing/selftests/kvm/arm64/shadow_stage2.c
@@ -51,9 +51,11 @@ static void l2_guest_code(void)
static void guest_code(void)
{
struct vcpu vcpu;
+ struct s2_mmu mmu;
struct hyp_data hyp_data;
int ret, i = 0;
- gpa_t l2_pc, l2_stack_top;
+ gpa_t l2_pc, l2_stack_start, l2_stack_top, s2_pgd;
+ gpa_t do_hvc_gpa;
struct page_pool pp;
u64 mmfr0 = read_sysreg(id_aa64mmfr0_el1);
@@ -68,11 +70,20 @@ static void guest_code(void)
if (!has_tgran_2(mmfr0, pp.page_size))
GUEST_SYNC1(TGRAN2NOSUP);
- l2_stack_top = alloc_page(&pp) + pp.page_size;
+ l2_stack_start = alloc_page(&pp);
+ l2_stack_top = l2_stack_start + pp.page_size;
l2_pc = ucall_translate_to_gpa(l2_guest_code);
+ do_hvc_gpa = ucall_translate_to_gpa(do_hvc);
+
+ s2_pgd = alloc_page(&pp);
init_vcpu(&vcpu, l2_pc, l2_stack_top);
- prepare_hyp_no_s2();
+ init_s2_mmu(&mmu, 0, s2_pgd, pp.page_size, 40);
+ create_s2_mapping(&mmu, l2_pc, l2_pc, pp.page_size * 2, &pp);
+ create_s2_mapping(&mmu, do_hvc_gpa, do_hvc_gpa, pp.page_size, &pp);
+ create_s2_mapping(&mmu, l2_stack_start, l2_stack_start, pp.page_size, &pp);
+
+ prepare_hyp(&mmu);
while (true) {
GUEST_PRINTF("L2 enter\n");
@@ -113,6 +124,12 @@ int main(void)
vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS,
L2_PAGE_POOL_ADDR, L2_PAGE_POOL_MEMSLOT,
L2_PAGE_POOL_NPAGES, 0);
+ /*
+ * This idmap allows L1 to traverse and build its guest stage-2, where
+ * it must do a PA to VA conversion in order to descend to the next
+ * level.
+ */
+ virt_map(vm, L2_PAGE_POOL_ADDR, L2_PAGE_POOL_ADDR, L2_PAGE_POOL_NPAGES);
while (true) {
vcpu_run(vcpu);
--
2.43.0
next prev parent reply other threads:[~2026-05-16 18:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-16 18:29 [PATCH v3 0/9] KVM: arm64: selftests: Basic nested guest support Wei-Lin Chang
2026-05-16 18:29 ` [PATCH v3 1/9] KVM: arm64: selftests: Add GPR save/restore functions for NV Wei-Lin Chang
2026-05-16 18:29 ` [PATCH v3 2/9] KVM: arm64: selftests: Add helpers for guest hypervisors Wei-Lin Chang
2026-05-16 18:29 ` [PATCH v3 3/9] KVM: arm64: selftests: Add hello_nested basic NV selftest Wei-Lin Chang
2026-05-16 18:29 ` [PATCH v3 4/9] KVM: arm64: selftests: Enhance hello_nested test Wei-Lin Chang
2026-05-16 18:29 ` [PATCH v3 5/9] KVM: arm64: selftests: Add shadow_stage2 test Wei-Lin Chang
2026-05-16 18:30 ` [PATCH v3 6/9] KVM: arm64: selftests: shadow_stage2: Allocate L2 stack from dedicated pool Wei-Lin Chang
2026-05-16 18:30 ` [PATCH v3 7/9] KVM: arm64: selftests: shadow_stage2: Check supported stage-2 granule size Wei-Lin Chang
2026-05-16 18:30 ` [PATCH v3 8/9] KVM: arm64: selftests: Add infrastructure for using stage-2 in guest Wei-Lin Chang
2026-05-16 18:30 ` Wei-Lin Chang [this message]
2026-05-19 21:31 ` [PATCH v3 0/9] KVM: arm64: selftests: Basic nested guest support 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=20260516183003.799058-10-weilin.chang@arm.com \
--to=weilin.chang@arm.com \
--cc=catalin.marinas@arm.com \
--cc=itaru.kitayama@fujitsu.com \
--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=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=pbonzini@redhat.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