KVM: arm64: selftests: Tests for protected VMs
Fuad Tabba
reviewerv2 cover KVM: arm64: selftests: Tests for protected VMs
Hi folks,
Changes since v1 [1]:
- New patch 1, which hides generic PtrAuth from a protected VM without PtrAuth. The pkvm_id_regs test checks for it.
- New pkvm_sve test, and MOPS, PIE, POE and FPMR checks in pkvm_id_regs.
- Use the selftest syscall wrappers and vm_check_cap().
- Marked pkvm_hvc() as called from the guest. (Joey)
- Collected Reviewed-by from Joey on patches 3, 6 and 7. (thanks!)
This series adds selftests for protected VMs. A test skips on a host without pKVM, and so does any case where the host doesn't have the required feature, e.g., PtrAuth, SVE or hugetlb pages.
A couple of points:
- Patch 1 is a fix, included here so that pkvm_id_regs can check the correct behaviour. Without it, generic PtrAuth is advertised to a protected VM without PtrAuth.
- Each area gets its own test rather than cases folded into existing tests such as psci_test, hypercalls, set_id_regs, etc. A protected guest requires its own boot path, and has to share the ucall pool before its first ucall. On top of that, a protected guest gets the opposite result for many of those tests' checks.
- Cases for a feature a protected VM may not have follow what the VM is given, so they pass with or without the series that adds it [2], and run once it lands. The debug cases follow ID_AA64DFR0_EL1.DebugVer, the SVE cases KVM_CAP_ARM_SVE on a protected VM's fd, and the MOPS, PIE, POE and FPMR checks their ID register fields.
The series is structured as follows:
01: Hide generic PtrAuth from protected VMs without PtrAuth.
02: external_aborts: an abort injected before a vCPU's first run.
03-05: Generic selftest changes: creating a protected VM, the pKVM
function IDs and the ucall pool's address.
06-07: Protected-VM library: boot trampoline and helpers.
08-18: The tests, one per area.
19: MOPS, PIE, POE and FPMR checks in pkvm_id_regs.Based on Linux 7.4-rc1 (6628e7d4c6b25; also applies to 7.4-rc2 7475ea8b58616).
Cheers,
/fuad
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Fuad Tabba (18):
KVM: arm64: Hide generic ptrauth from protected VMs without ptrauth
KVM: arm64: selftests: Inject an abort before a vCPU's first run
KVM: selftests: Allow arm64 tests to create protected VMs
tools: arm-smccc: Add the pKVM memory sharing function IDs
KVM: selftests: Export the ucall pool's guest physical address
KVM: arm64: selftests: Add protected-VM library helpers
KVM: arm64: selftests: Add pkvm_host_abi host-interface test
KVM: arm64: selftests: Add pkvm_psci multi-vCPU PSCI test
KVM: arm64: selftests: Add pkvm_mem_share hypercall test
KVM: arm64: selftests: Add pkvm_smccc hypercall test
KVM: arm64: selftests: Add pkvm_id_regs register and trap test
KVM: arm64: selftests: Add pkvm_vcpu_regs register-state test
KVM: arm64: selftests: Add pkvm_irq interrupt test
KVM: arm64: selftests: Add pkvm_isolation host-access test
KVM: arm64: selftests: Add pkvm_lifecycle teardown test
KVM: arm64: selftests: Add pkvm_exceptions debug and SError test
KVM: arm64: selftests: Add pkvm_sve vector-length test
KVM: arm64: selftests: Check MOPS, PIE, POE and FPMR in a protected VM
Will Deacon (1):
KVM: arm64: selftests: Add protected-VM boot trampoline
arch/arm64/kvm/hyp/nvhe/sys_regs.c | 4 +- tools/include/linux/arm-smccc.h | 22 + tools/testing/selftests/kvm/Makefile.kvm | 13 + .../selftests/kvm/arm64/external_aborts.c | 21 + .../selftests/kvm/arm64/pkvm_exceptions.c | 261 ++++++++ .../selftests/kvm/arm64/pkvm_host_abi.c | 435 ++++++++++++ .../selftests/kvm/arm64/pkvm_id_regs.c | 394 +++++++++++ tools/testing/selftests/kvm/arm64/pkvm_irq.c | 268 ++++++++ .../selftests/kvm/arm64/pkvm_isolation.c | 225 +++++++ .../selftests/kvm/arm64/pkvm_lifecycle.c | 110 +++ .../selftests/kvm/arm64/pkvm_mem_share.c | 394 +++++++++++ tools/testing/selftests/kvm/arm64/pkvm_psci.c | 632 ++++++++++++++++++ .../testing/selftests/kvm/arm64/pkvm_smccc.c | 117 ++++ tools/testing/selftests/kvm/arm64/pkvm_sve.c | 357 ++++++++++ .../selftests/kvm/arm64/pkvm_vcpu_regs.c | 218 ++++++ .../selftests/kvm/include/arm64/pkvm.h | 75 +++ .../selftests/kvm/include/ucall_common.h | 1 + tools/testing/selftests/kvm/lib/arm64/pkvm.c | 255 +++++++ .../selftests/kvm/lib/arm64/pvm-entry.S | 57 ++ tools/testing/selftests/kvm/lib/kvm_util.c | 5 +- .../testing/selftests/kvm/lib/ucall_common.c | 9 +- 21 files changed, 3868 insertions(+), 5 deletions(-) create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_exceptions.c create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_host_abi.c create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_id_regs.c create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_irq.c create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_isolation.c create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_lifecycle.c create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_mem_share.c create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_psci.c create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_smccc.c create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_sve.c create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_vcpu_regs.c create mode 100644 tools/testing/selftests/kvm/include/arm64/pkvm.h create mode 100644 tools/testing/selftests/kvm/lib/arm64/pkvm.c create mode 100644 tools/testing/selftests/kvm/lib/arm64/pvm-entry.S
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 1/19 KVM: arm64: Hide generic ptrauth from protected VMs without ptrauth
A protected VM without the ptrauth vCPU features shouldn't have pointer authentication in its ID registers. Commit 3d7ff00700d1 ("KVM: arm64:
Rework specifying restricted features for protected VMs") gated APA, API, APA3 and GPA3 on vm_has_ptrauth(), but left GPA and GPI capped at IMP. So generic authentication is advertised to a protected guest without ptrauth, and PACGA UNDEFs.
Gate GPA and GPI on vm_has_ptrauth() too.
--- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kvm/hyp/nvhe/sys_regs.c +2 -2
@@ -157,8 +157,8 @@ static const struct pvm_ftr_bits pvmid_aa64isar1[] = {MAX_FEAT (ID_AA64ISAR1_EL1 ,JSCVT ,IMP ),MAX_FEAT (ID_AA64ISAR1_EL1 ,FCMA ,IMP ),MAX_FEAT (ID_AA64ISAR1_EL1 ,LRCPC ,LRCPC3 ), -MAX_FEAT (ID_AA64ISAR1_EL1 ,GPA ,IMP ), -MAX_FEAT (ID_AA64ISAR1_EL1 ,GPI ,IMP ), +MAX_FEAT_FUNC (ID_AA64ISAR1_EL1 ,GPA ,IMP , vm_has_ptrauth), +MAX_FEAT_FUNC (ID_AA64ISAR1_EL1 ,GPI ,IMP , vm_has_ptrauth),MAX_FEAT (ID_AA64ISAR1_EL1 ,FRINTTS ,IMP ),MAX_FEAT (ID_AA64ISAR1_EL1 ,SB ,IMP ), MAX_FEAT(ID_AA64ISAR1_EL1, SPECRES, COSP_RCTX),
Signature · 1 line
2.47.3
Marc Zyngier
maintainerRe: [PATCH v2 01/19] KVM: arm64: Hide generic ptrauth from protected VMs without ptrauth
Quoted 21 lines · Fuad Tabba
A protected VM without the ptrauth vCPU features shouldn't have pointer authentication in its ID registers. Commit
3d7ff00700d1("KVM: arm64:
Rework specifying restricted features for protected VMs") gated APA, API, APA3 and GPA3 onvm_has_ptrauth(), but left GPA and GPI capped at IMP. So generic authentication is advertised to a protected guest without ptrauth, and PACGA UNDEFs.Gate GPA and GPI on
vm_has_ptrauth()too.Fixes 3d7ff00700d1 ("KVM: arm64: Rework specifying restricted features for protected VMs")Signed-off-by Fuad Tabba <[email protected]>--- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/arm64/kvm/hyp/nvhe/sys_regs.c +0
-0
arch/arm64/kvm/hyp/nvhe/sys_regs.c static const struct pvm_ftr_bits pvmid_aa64isar1[] = { · line 164
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/sys_regs.c +2
-2@@ -157,8 +157,8 @@ static const struct pvm_ftr_bits pvmid_aa64isar1[] = {MAX_FEAT (ID_AA64ISAR1_EL1 ,JSCVT ,IMP ),MAX_FEAT (ID_AA64ISAR1_EL1 ,FCMA ,IMP ),MAX_FEAT (ID_AA64ISAR1_EL1 ,LRCPC ,LRCPC3 ), -MAX_FEAT (ID_AA64ISAR1_EL1 ,GPA ,IMP ), -MAX_FEAT (ID_AA64ISAR1_EL1 ,GPI ,IMP ), +MAX_FEAT_FUNC (ID_AA64ISAR1_EL1 ,GPA ,IMP , vm_has_ptrauth), +MAX_FEAT_FUNC (ID_AA64ISAR1_EL1 ,GPI ,IMP , vm_has_ptrauth),MAX_FEAT (ID_AA64ISAR1_EL1 ,FRINTTS ,IMP ),MAX_FEAT (ID_AA64ISAR1_EL1 ,SB ,IMP ), MAX_FEAT(ID_AA64ISAR1_EL1, SPECRES, COSP_RCTX),
Burying a fix in a selftest series is a recipe to make sure it is ignored for a full cycle... Why isn't that with the "massive feature set" series?
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Fuad Tabba
reviewerRe: [PATCH v2 01/19] KVM: arm64: Hide generic ptrauth from protected VMs without ptrauth
Hi Marc,
On Tue, 17 Nov 2026 19:41:54 +0000, Marc Zyngier <[email protected]> wrote:
[...]
Quoted 3 lines
Burying a fix in a selftest series is a recipe to make sure it is ignored for a full cycle... Why isn't that with the "massive feature set" series?
It's in this one because pkvm_id_regs depends on it. The test checks that GPA and GPI read 0 in a protected VM without ptrauth, and it fails without the fix.
Would you prefer that I send it on its own, or with the respin of the features series?
Cheers,
/fuad
Marc Zyngier
maintainerRe: [PATCH v2 01/19] KVM: arm64: Hide generic ptrauth from protected VMs without ptrauth
Quoted 5 lines · Fuad Tabba
Hi Marc,
On Tue, 17 Nov 2026 19:41:54 +0000, Marc Zyngier <[email protected]> wrote:
[...]
Quoted 7 lines
Quoted 3 lines
Burying a fix in a selftest series is a recipe to make sure it is ignored for a full cycle... Why isn't that with the "massive feature set" series?
It's in this one because
pkvm_id_regsdepends on it. The test checks that GPA and GPI read 0 in a protected VM without ptrauth, and it fails without the fix.
But that's a *test*. Nobody runs tests as a production workload. Delaying a fix to satisfy testing makes no sense to me. If someone screams that their tests are failing, let them scream, safe in the knowledge that you have fixed the problem rather than the symptom.
Quoted 2 lines
Would you prefer that I send it on its own, or with the respin of the features series?
I'll cherry-pick it directly.
Thanks,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Fuad Tabba
reviewerRe: [PATCH v2 01/19] KVM: arm64: Hide generic ptrauth from protected VMs without ptrauth
On Wed, 18 Nov 2026 at 10:55, Marc Zyngier <[email protected]> wrote:
[...]
Quoted 8 lines
Quoted 3 lines
It's in this one because
pkvm_id_regsdepends on it. The test checks that GPA and GPI read 0 in a protected VM without ptrauth, and it fails without the fix.But that's a *test*. Nobody runs tests as a production workload. Delaying a fix to satisfy testing makes no sense to me. If someone screams that their tests are failing, let them scream, safe in the knowledge that you have fixed the problem rather than the symptom.
Ack.
Quoted 4 lines
Quoted 2 lines
Would you prefer that I send it on its own, or with the respin of the features series?
I'll cherry-pick it directly.
Thanks Marc,
/fuad
Re: (subset) [PATCH v2 01/19] KVM: arm64: Hide generic ptrauth from protected VMs without ptrauth
In reply to Fuad TabbaQuoted 8 lines · Fuad Tabba
A protected VM without the ptrauth vCPU features shouldn't have pointer authentication in its ID registers. Commit
3d7ff00700d1("KVM: arm64:
Rework specifying restricted features for protected VMs") gated APA, API, APA3 and GPA3 onvm_has_ptrauth(), but left GPA and GPI capped at IMP. So generic authentication is advertised to a protected guest without ptrauth, and PACGA UNDEFs.[...]
Applied to fixes, thanks!
[01/19] KVM: arm64: Hide generic ptrauth from protected VMs without ptrauth
commit: 50e9e6b6eb3d9b2c318babce60abdf3b300cfb35
Cheers,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Fuad Tabba
reviewerPATCH v2 2/19 KVM: arm64: selftests: Inject an abort before a vCPU's first run
In reply to Fuad TabbaKVM commits an external abort injected with KVM_SET_VCPU_EVENTS immediately, even before the vCPU's first run. For a normal VM on a pKVM host that path panicked the hypervisor until commit a2bb5f5c67a95 ("KVM: arm64: Pin the host vCPU before adjusting its PC under pKVM"). No test injects before the first run.
Add one, checking that the guest takes the abort at its entry point.
--- .../selftests/kvm/arm64/external_aborts.c | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+)
tools/testing/selftests/kvm/arm64/external_aborts.c +21 -0
@@ -113,6 +113,26 @@ static void vcpu_run_expect_sync(struct kvm_vcpu *vcpu)__vcpu_run_expect (vcpu,UCALL_SYNC ); } +static void test_sea_before_run_guest (void ) +{ +GUEST_FAIL ("Guest ran before taking the injected abort" ); +} + +/* Test that an abort injected before the vCPU's first run is taken at its entry point. */ +static void test_sea_before_run (void ) +{ +struct kvm_vcpu *vcpu; +struct kvm_vm *vm =vm_create_with_dabt_handler (&vcpu, test_sea_before_run_guest, + expect_sea_handler); + + expected_abort_pc = (u64 )test_sea_before_run_guest; +sync_global_to_guest (vm, expected_abort_pc); + +vcpu_inject_sea (vcpu); +vcpu_run_expect_done (vcpu); +kvm_vm_free (vm); +} +extern char test_mmio_abort_insn; static noinline void test_mmio_abort_guest(void)
@@ -420,6 +440,7 @@ static void test_serror_amo(void)int main (void ) { +test_sea_before_run ();test_mmio_abort ();test_mmio_nisv ();test_mmio_nisv_abort ();
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 3/19 KVM: selftests: Allow arm64 tests to create protected VMs
In reply to Fuad TabbaOn arm64, the VM type passed to KVM_CREATE_VM carries the IPA size, which the selftest library fills in. The library rejects any type a test provides in vm_shape.type. A protected VM is created by setting KVM_VM_TYPE_ARM_PROTECTED in that type, so a test can't create one.
Accept KVM_VM_TYPE_ARM_PROTECTED from the test, and add the IPA size to it as for any other VM.
--- tools/testing/selftests/kvm/lib/kvm_util.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/lib/kvm_util.c +3 -2
@@ -400,9 +400,10 @@ struct kvm_vm *____vm_create(struct vm_shape shape) }#ifdef __aarch64__ -TEST_ASSERT (!vm->type,"ARM doesn't support test-provided types" ); +TEST_ASSERT (!(vm->type & ~KVM_VM_TYPE_ARM_PROTECTED ), +"ARM supports only KVM_VM_TYPE_ARM_PROTECTED as a test-provided type" );if (vm->pa_bits !=40 ) - vm->type =KVM_VM_TYPE_ARM_IPA_SIZE (vm->pa_bits); + vm->type |=KVM_VM_TYPE_ARM_IPA_SIZE (vm->pa_bits);#endif vm_open (vm);
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 4/19 tools: arm-smccc: Add the pKVM memory sharing function IDs
In reply to Fuad TabbaThe tools copy of arm-smccc.h lacks the pKVM guest hypercalls that the protected-VM selftests make.
The kernel's arm-smccc.h defines the vendor-hyp UID with UUID_INIT(), which requires linux/uuid.h, and tools doesn't have one. So rather than sync the whole header, copy the function numbers and IDs of HYP_MEMINFO, MEM_SHARE and MEM_UNSHARE from include/linux/arm-smccc.h.
--- tools/include/linux/arm-smccc.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
tools/include/linux/arm-smccc.h +22 -0
@@ -111,6 +111,10 @@/* KVM "vendor specific" services */ #define ARM_SMCCC_KVM_FUNC_FEATURES 0#define ARM_SMCCC_KVM_FUNC_PTP 1 +/* Start of pKVM hypercall range */ +#define ARM_SMCCC_KVM_FUNC_HYP_MEMINFO 2 +#define ARM_SMCCC_KVM_FUNC_MEM_SHARE 3 +#define ARM_SMCCC_KVM_FUNC_MEM_UNSHARE 4#define ARM_SMCCC_KVM_FUNC_FEATURES_2 127#define ARM_SMCCC_KVM_NUM_FUNCS 128
@@ -133,6 +137,24 @@ ARM_SMCCC_OWNER_VENDOR_HYP, \ ARM_SMCCC_KVM_FUNC_PTP) +#define ARM_SMCCC_VENDOR_HYP_KVM_HYP_MEMINFO_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_64, \ + ARM_SMCCC_OWNER_VENDOR_HYP, \ + ARM_SMCCC_KVM_FUNC_HYP_MEMINFO) + +#define ARM_SMCCC_VENDOR_HYP_KVM_MEM_SHARE_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_64, \ + ARM_SMCCC_OWNER_VENDOR_HYP, \ + ARM_SMCCC_KVM_FUNC_MEM_SHARE) + +#define ARM_SMCCC_VENDOR_HYP_KVM_MEM_UNSHARE_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_64, \ + ARM_SMCCC_OWNER_VENDOR_HYP, \ + ARM_SMCCC_KVM_FUNC_MEM_UNSHARE) +/* ptp_kvm counter type ID */ #define KVM_PTP_VIRT_COUNTER 0#define KVM_PTP_PHYS_COUNTER 1
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 5/19 KVM: selftests: Export the ucall pool's guest physical address
In reply to Fuad TabbaA protected guest's memory is private until the guest itself shares it, so the guest has to share the ucall pool before its first ucall. The host can't do that for it. Only the guest's copy of ucall_pool holds the pool's address.
Add get_ucall_pool_gpa(), which reads that copy, so that the host can pass the address to the guest.
--- tools/testing/selftests/kvm/include/ucall_common.h | 1 + tools/testing/selftests/kvm/lib/ucall_common.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/include/ucall_common.h +1 -0
@@ -41,6 +41,7 @@ __printf(5, 6) void ucall_assert(u64 cmd, const char *exp,u64 get_ucall (struct kvm_vcpu *vcpu,struct ucall *uc);void ucall_init (struct kvm_vm *vm,gpa_t mmio_gpa);int ucall_nr_pages_required (u64 page_size); +gpa_t get_ucall_pool_gpa (struct kvm_vm *vm);/* * Perform userspace call without any associated data. This bare call avoids
tools/testing/selftests/kvm/lib/ucall_common.c +8 -1
@@ -21,10 +21,17 @@ int ucall_nr_pages_required(u64 page_size)/* * ucall_pool holds per-VM values (global data is duplicated by each VM), it -* must not be accessed from host code. +* must not be accessed from host code. The host reads only a VM's copy. */ static struct ucall_header *ucall_pool; +gpa_t get_ucall_pool_gpa (struct kvm_vm *vm) +{ +struct ucall_header **pool =addr_gva2hva (vm, (gva_t)&ucall_pool); + +return addr_gva2gpa (vm, (gva_t)*pool); +} +void ucall_init (struct kvm_vm *vm,gpa_t mmio_gpa) {struct ucall_header *hdr;
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 6/19 KVM: arm64: selftests: Add protected-VM boot trampoline
In reply to Fuad TabbaFrom: Will Deacon <[email protected]>
EL2 takes only PC and X0 from the host when it boots a protected vCPU, and resets everything else. So the registers the selftest library sets before the first run never reach the guest.
Boot a protected guest through a trampoline that restores X0-X7, seven EL1 system registers and the stack pointer from a block X0 points to, then enables the MMU and branches to the guest's entry point.
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/include/arm64/pkvm.h | 49 ++++++++++++++++ .../selftests/kvm/lib/arm64/pvm-entry.S | 57 +++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 tools/testing/selftests/kvm/include/arm64/pkvm.h create mode 100644 tools/testing/selftests/kvm/lib/arm64/pvm-entry.S
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -35,6 +35,7 @@ LIBKVM_arm64 += lib/arm64/gic_v3.c LIBKVM_arm64 += lib/arm64/gic_v3_its.c LIBKVM_arm64 += lib/arm64/handlers.S LIBKVM_arm64 += lib/arm64/processor.c +LIBKVM_arm64 += lib/arm64/pvm-entry.S LIBKVM_arm64 += lib/arm64/spinlock.c LIBKVM_arm64 += lib/arm64/ucall.c LIBKVM_arm64 += lib/arm64/vgic.c
tools/testing/selftests/kvm/include/arm64/pkvm.h new file +49 -0
49 lines not on this page · raw message
tools/testing/selftests/kvm/lib/arm64/pvm-entry.S new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 7/19 KVM: arm64: selftests: Add protected-VM library helpers
In reply to Fuad TabbaA protected-VM test has to create the VM with the protected type and PSCI 0.2, boot each vCPU through the trampoline, and have the guest share the ucall pool before its first ucall.
Add lib/arm64/pkvm.c to do this. It also has a run loop, an SMCCC call for the guest and a reader of the locked-memory count. A secondary runs once with immediate_exit set, since a vCPU is a valid CPU_ON target only after its first KVM_RUN. No capability advertises pKVM, so pkvm_supported() tries to create a protected VM. The host filters capabilities per VM, so pkvm_has_cap() checks one on a protected VM's fd.
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/include/arm64/pkvm.h | 26 ++ tools/testing/selftests/kvm/lib/arm64/pkvm.c | 255 ++++++++++++++++++ 3 files changed, 282 insertions(+) create mode 100644 tools/testing/selftests/kvm/lib/arm64/pkvm.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -34,6 +34,7 @@ LIBKVM_arm64 += lib/arm64/gic.c LIBKVM_arm64 += lib/arm64/gic_v3.c LIBKVM_arm64 += lib/arm64/gic_v3_its.c LIBKVM_arm64 += lib/arm64/handlers.S +LIBKVM_arm64 += lib/arm64/pkvm.c LIBKVM_arm64 += lib/arm64/processor.c LIBKVM_arm64 += lib/arm64/pvm-entry.S LIBKVM_arm64 += lib/arm64/spinlock.c
tools/testing/selftests/kvm/include/arm64/pkvm.h +26 -0
@@ -8,6 +8,9 @@#define SELFTEST_KVM_ARM64_PKVM_H #ifndef __ASSEMBLER__ +#include "kvm_util.h" +#include "ucall_common.h" +/* * Register state the boot trampoline (pvm-entry.S) restores. Only PC and X0 * survive to a protected guest's first run, so X0 points at this block.
@@ -26,6 +29,29 @@ struct pvm_boot_args {u64 tpidr_el1;u64 sp_el1; }; + +/* Memslot of the trampoline's page. Test memslots start above it. */ +#define PKVM_IDMAP_MEMSLOT 1 + +bool pkvm_supported (void ); +bool pkvm_has_cap (long cap); +struct kvm_vm *pkvm_vm_create (unsigned int nr_vcpus,u32 features,struct kvm_vcpu *vcpus[]); +struct kvm_vm *pkvm_vm_create_with_one_vcpu (struct kvm_vcpu **vcpu,void *guest_code); + +/* Call after all register setup: later register writes don't reach the guest. */ +void pkvm_vcpu_setup_boot (struct kvm_vcpu *vcpu,void *guest_code); + +/* Call before the primary's first run. */ +gpa_t pkvm_vcpu_setup_boot_secondary (struct kvm_vcpu *vcpu,void *guest_code); +gpa_t pkvm_idmap_gpa (struct kvm_vm *vm); + +void pkvm_run_loop (struct kvm_vcpu *vcpu,void (*on_sync)(struct kvm_vcpu *vcpu,struct ucall *uc)); +size_t pkvm_host_locked_vm (void ); + +/* Called from the guest. */ +unsigned long pkvm_hvc (u32 func,u64 arg0,u64 arg1,u64 arg2); + +void pkvm_guest_init (void );#endif #define PVM_BOOT_ARGS_OFF_JUMP_TGT 0
tools/testing/selftests/kvm/lib/arm64/pkvm.c new file +255 -0
255 lines not on this page · raw message
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 8/19 KVM: arm64: selftests: Add pkvm_host_abi host-interface test
In reply to Fuad TabbaThe host isn't trusted with a protected guest's state, so once a protected vCPU has run, KVM rejects the ioctls that would read or change that state. The host can still inject a virtual SError and read back whether one is pending. The VM gets only the capabilities and vCPU features pKVM supports.
Check what the host's KVM interface allows and rejects for a protected VM, before and after the first run, and that the host accounts the VM's memory as locked until the VM is freed.
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/arm64/pkvm_host_abi.c | 435 ++++++++++++++++++ 2 files changed, 436 insertions(+) create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_host_abi.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -190,6 +190,7 @@ TEST_GEN_PROGS_arm64 += arm64/nv_pre_fault_memory_test TEST_GEN_PROGS_arm64 += arm64/external_aborts TEST_GEN_PROGS_arm64 += arm64/mmio_sign_ext TEST_GEN_PROGS_arm64 += arm64/page_fault_test +TEST_GEN_PROGS_arm64 += arm64/pkvm_host_abi TEST_GEN_PROGS_arm64 += arm64/psci_test TEST_GEN_PROGS_arm64 += arm64/sea_to_user TEST_GEN_PROGS_arm64 += arm64/set_id_regs
tools/testing/selftests/kvm/arm64/pkvm_host_abi.c new file +435 -0
435 lines not on this page · raw message
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 9/19 KVM: arm64: selftests: Add pkvm_psci multi-vCPU PSCI test
In reply to Fuad TabbaEL2 handles a protected guest's CPU_ON, CPU_OFF, PSCI_VERSION and PSCI_FEATURES, and forwards the rest to the host. So only the guest can power on its vCPUs.
Test each PSCI call, and that the host can't make a secondary runnable without a CPU_ON from the guest. Run the secondaries on their own threads to race CPU_ON against CPU_OFF and against another CPU_ON. A CPU_ON of a vCPU that has called CPU_OFF returns ALREADY_ON until the host powers it off.
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + tools/testing/selftests/kvm/arm64/pkvm_psci.c | 632 ++++++++++++++++++ 2 files changed, 633 insertions(+) create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_psci.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -191,6 +191,7 @@ TEST_GEN_PROGS_arm64 += arm64/external_aborts TEST_GEN_PROGS_arm64 += arm64/mmio_sign_ext TEST_GEN_PROGS_arm64 += arm64/page_fault_test TEST_GEN_PROGS_arm64 += arm64/pkvm_host_abi +TEST_GEN_PROGS_arm64 += arm64/pkvm_psci TEST_GEN_PROGS_arm64 += arm64/psci_test TEST_GEN_PROGS_arm64 += arm64/sea_to_user TEST_GEN_PROGS_arm64 += arm64/set_id_regs
tools/testing/selftests/kvm/arm64/pkvm_psci.c new file +632 -0
632 lines not on this page · raw message
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 10/19 KVM: arm64: selftests: Add pkvm_mem_share hypercall test
In reply to Fuad TabbaA protected guest gives the host access to one of its pages with MEM_SHARE and takes it back with MEM_UNSHARE. The page is a host page, whose size HYP_MEMINFO returns. At teardown EL2 zeroes every page the guest hasn't left shared.
Exercise the three calls, the host's access to shared and private pages, and the zeroing. Also check that KVM_RUN fails with EIO on hugetlb-backed memory, that sharing an IPA outside every memslot makes the guest take an external abort, and that faults each requiring new stage-2 tables succeed.
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/arm64/pkvm_mem_share.c | 394 ++++++++++++++++++ 2 files changed, 395 insertions(+) create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_mem_share.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -191,6 +191,7 @@ TEST_GEN_PROGS_arm64 += arm64/external_aborts TEST_GEN_PROGS_arm64 += arm64/mmio_sign_ext TEST_GEN_PROGS_arm64 += arm64/page_fault_test TEST_GEN_PROGS_arm64 += arm64/pkvm_host_abi +TEST_GEN_PROGS_arm64 += arm64/pkvm_mem_share TEST_GEN_PROGS_arm64 += arm64/pkvm_psci TEST_GEN_PROGS_arm64 += arm64/psci_test TEST_GEN_PROGS_arm64 += arm64/sea_to_user
tools/testing/selftests/kvm/arm64/pkvm_mem_share.c new file +394 -0
394 lines not on this page · raw message
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 11/19 KVM: arm64: selftests: Add pkvm_smccc hypercall test
In reply to Fuad TabbaEL2 handles a protected guest's SMCCC calls other than PSCI rather than forwarding them to the host. The vendor-hyp feature bitmap advertises only FEATURES and the three memory calls.
Check SMCCC_VERSION, the vendor-hyp UID and feature bitmap, that the calls EL2 doesn't implement (FF-A, TRNG, an unknown function) return NOT_SUPPORTED, and that an SMC makes the guest take an UNDEF.
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../testing/selftests/kvm/arm64/pkvm_smccc.c | 117 ++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_smccc.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -193,6 +193,7 @@ TEST_GEN_PROGS_arm64 += arm64/page_fault_test TEST_GEN_PROGS_arm64 += arm64/pkvm_host_abi TEST_GEN_PROGS_arm64 += arm64/pkvm_mem_share TEST_GEN_PROGS_arm64 += arm64/pkvm_psci +TEST_GEN_PROGS_arm64 += arm64/pkvm_smccc TEST_GEN_PROGS_arm64 += arm64/psci_test TEST_GEN_PROGS_arm64 += arm64/sea_to_user TEST_GEN_PROGS_arm64 += arm64/set_id_regs
tools/testing/selftests/kvm/arm64/pkvm_smccc.c new file +117 -0
117 lines not on this page · raw message
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 12/19 KVM: arm64: selftests: Add pkvm_id_regs register and trap test
In reply to Fuad TabbapKVM gives a protected guest its own view of the ID registers, hiding the features pKVM doesn't support. Their registers UNDEF, except some hidden debug registers, which are RAZ/WI.
Test that view and those UNDEFs from the guest, and the registers EL2 emulates with fixed values. The debug checks follow ID_AA64DFR0_EL1.DebugVer. The PtrAuth and SVE cases run when a protected VM's fd reports the capability, and the SVE case also compares ID_AA64ZFR0_EL1 with what host userspace reads.
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/arm64/pkvm_id_regs.c | 324 ++++++++++++++++++ 2 files changed, 325 insertions(+) create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_id_regs.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -191,6 +191,7 @@ TEST_GEN_PROGS_arm64 += arm64/external_aborts TEST_GEN_PROGS_arm64 += arm64/mmio_sign_ext TEST_GEN_PROGS_arm64 += arm64/page_fault_test TEST_GEN_PROGS_arm64 += arm64/pkvm_host_abi +TEST_GEN_PROGS_arm64 += arm64/pkvm_id_regs TEST_GEN_PROGS_arm64 += arm64/pkvm_mem_share TEST_GEN_PROGS_arm64 += arm64/pkvm_psci TEST_GEN_PROGS_arm64 += arm64/pkvm_smccc
tools/testing/selftests/kvm/arm64/pkvm_id_regs.c new file +324 -0
324 lines not on this page · raw message
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 13/19 KVM: arm64: selftests: Add pkvm_vcpu_regs register-state test
In reply to Fuad TabbaA protected vCPU's registers are held at EL2, which handles some exits itself and returns others to the host. The host can move the vCPU's thread to another CPU at any exit. The guest's registers have to keep their values through all of that.
Verify that x19-x28 and v0-v31 keep the values the guest loaded across each kind of exit, and across a host CPU migration at every MMIO exit.
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/arm64/pkvm_vcpu_regs.c | 218 ++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_vcpu_regs.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -195,6 +195,7 @@ TEST_GEN_PROGS_arm64 += arm64/pkvm_id_regs TEST_GEN_PROGS_arm64 += arm64/pkvm_mem_share TEST_GEN_PROGS_arm64 += arm64/pkvm_psci TEST_GEN_PROGS_arm64 += arm64/pkvm_smccc +TEST_GEN_PROGS_arm64 += arm64/pkvm_vcpu_regs TEST_GEN_PROGS_arm64 += arm64/psci_test TEST_GEN_PROGS_arm64 += arm64/sea_to_user TEST_GEN_PROGS_arm64 += arm64/set_id_regs
tools/testing/selftests/kvm/arm64/pkvm_vcpu_regs.c new file +218 -0
218 lines not on this page · raw message
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 14/19 KVM: arm64: selftests: Add pkvm_irq interrupt test
In reply to Fuad TabbaThe host emulates a protected guest's vGIC, so EL2 copies the list registers to and from the host each time the host runs the vCPU. EL2 also keeps its own copy of the guest's virtual timer state, which the host can't change.
Check that the virtual timer's PPI arrives exactly once, with CVAL and CTL kept across exits, that SGIs pass between two vCPUs, and that the timer wakes a vCPU in WFI.
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + tools/testing/selftests/kvm/arm64/pkvm_irq.c | 268 +++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_irq.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -192,6 +192,7 @@ TEST_GEN_PROGS_arm64 += arm64/mmio_sign_ext TEST_GEN_PROGS_arm64 += arm64/page_fault_test TEST_GEN_PROGS_arm64 += arm64/pkvm_host_abi TEST_GEN_PROGS_arm64 += arm64/pkvm_id_regs +TEST_GEN_PROGS_arm64 += arm64/pkvm_irq TEST_GEN_PROGS_arm64 += arm64/pkvm_mem_share TEST_GEN_PROGS_arm64 += arm64/pkvm_psci TEST_GEN_PROGS_arm64 += arm64/pkvm_smccc
tools/testing/selftests/kvm/arm64/pkvm_irq.c new file +268 -0
268 lines not on this page · raw message
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 15/19 KVM: arm64: selftests: Add pkvm_isolation host-access test
In reply to Fuad TabbaThe host keeps its userspace mapping of a protected guest's memory, but can't reach the data through it. The host kernel's copy_to_user() and copy_from_user() on that mapping fail. If the host kernel pins a page and accesses it through its own mapping, as process_vm_readv() does, EL2 zeroes and reclaims the page, and the guest loses it.
Test each of these, that MADV_DONTNEED and munmap() leave the guest's pages pinned and accounted, and that a normal VM's fault on them fails.
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/arm64/pkvm_isolation.c | 225 ++++++++++++++++++ 2 files changed, 226 insertions(+) create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_isolation.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -193,6 +193,7 @@ TEST_GEN_PROGS_arm64 += arm64/page_fault_test TEST_GEN_PROGS_arm64 += arm64/pkvm_host_abi TEST_GEN_PROGS_arm64 += arm64/pkvm_id_regs TEST_GEN_PROGS_arm64 += arm64/pkvm_irq +TEST_GEN_PROGS_arm64 += arm64/pkvm_isolation TEST_GEN_PROGS_arm64 += arm64/pkvm_mem_share TEST_GEN_PROGS_arm64 += arm64/pkvm_psci TEST_GEN_PROGS_arm64 += arm64/pkvm_smccc
tools/testing/selftests/kvm/arm64/pkvm_isolation.c new file +225 -0
225 lines not on this page · raw message
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 16/19 KVM: arm64: selftests: Add pkvm_lifecycle teardown test
In reply to Fuad TabbaEach protected VM holds an entry in EL2's table of KVM_MAX_PVMS (255) VMs until teardown has reclaimed its pages, so if teardown leaks entries, KVM_CREATE_VM eventually fails.
Create, run and free twice that many VMs, four alive at once and freed in random order. Check that each VM's memory survives the others' teardown, and that freeing a VM drops the process's locked memory by what its runs added.
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/arm64/pkvm_lifecycle.c | 110 ++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_lifecycle.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -194,6 +194,7 @@ TEST_GEN_PROGS_arm64 += arm64/pkvm_host_abi TEST_GEN_PROGS_arm64 += arm64/pkvm_id_regs TEST_GEN_PROGS_arm64 += arm64/pkvm_irq TEST_GEN_PROGS_arm64 += arm64/pkvm_isolation +TEST_GEN_PROGS_arm64 += arm64/pkvm_lifecycle TEST_GEN_PROGS_arm64 += arm64/pkvm_mem_share TEST_GEN_PROGS_arm64 += arm64/pkvm_psci TEST_GEN_PROGS_arm64 += arm64/pkvm_smccc
tools/testing/selftests/kvm/arm64/pkvm_lifecycle.c new file +110 -0
110 lines not on this page · raw message
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 17/19 KVM: arm64: selftests: Add pkvm_exceptions debug and SError test
In reply to Fuad TabbapKVM can hide self-hosted debug from a protected guest, which then reads ID_AA64DFR0_EL1.DebugVer as 0. A virtual SError the host injects has to be delivered by EL2, since the host can't see whether the guest has it masked.
Verify that the guest's own handler takes a hardware breakpoint, a watchpoint and a single step, and that an injected SError is pending in ISR_EL1.A while PSTATE.A masks it and is taken once unmasked. The debug cases skip while ID_AA64DFR0_EL1.DebugVer is 0.
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/arm64/pkvm_exceptions.c | 261 ++++++++++++++++++ 2 files changed, 262 insertions(+) create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_exceptions.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -190,6 +190,7 @@ TEST_GEN_PROGS_arm64 += arm64/nv_pre_fault_memory_test TEST_GEN_PROGS_arm64 += arm64/external_aborts TEST_GEN_PROGS_arm64 += arm64/mmio_sign_ext TEST_GEN_PROGS_arm64 += arm64/page_fault_test +TEST_GEN_PROGS_arm64 += arm64/pkvm_exceptions TEST_GEN_PROGS_arm64 += arm64/pkvm_host_abi TEST_GEN_PROGS_arm64 += arm64/pkvm_id_regs TEST_GEN_PROGS_arm64 += arm64/pkvm_irq
tools/testing/selftests/kvm/arm64/pkvm_exceptions.c new file +261 -0
261 lines not on this page · raw message
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 18/19 KVM: arm64: selftests: Add pkvm_sve vector-length test
In reply to Fuad TabbaEL2 saves and restores a protected guest's SVE registers at the vector length the host set before the first run. On every exit, it puts the host's own vector length back.
Run a protected guest at each vector length KVM supports, and check that it reads that length with RDVL, and that its predicates and FFR survive exits. At the largest length, check Z, P and FFR across moves to another host CPU. Check the host thread's vector length after every exit. The cases skip when a protected VM can't have SVE.
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + tools/testing/selftests/kvm/arm64/pkvm_sve.c | 357 +++++++++++++++++++ 2 files changed, 358 insertions(+) create mode 100644 tools/testing/selftests/kvm/arm64/pkvm_sve.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -199,6 +199,7 @@ TEST_GEN_PROGS_arm64 += arm64/pkvm_lifecycle TEST_GEN_PROGS_arm64 += arm64/pkvm_mem_share TEST_GEN_PROGS_arm64 += arm64/pkvm_psci TEST_GEN_PROGS_arm64 += arm64/pkvm_smccc +TEST_GEN_PROGS_arm64 += arm64/pkvm_sve TEST_GEN_PROGS_arm64 += arm64/pkvm_vcpu_regs TEST_GEN_PROGS_arm64 += arm64/psci_test TEST_GEN_PROGS_arm64 += arm64/sea_to_user
tools/testing/selftests/kvm/arm64/pkvm_sve.c new file +357 -0
357 lines not on this page · raw message
Signature · 1 line
2.47.3
Fuad Tabba
reviewerPATCH v2 19/19 KVM: arm64: selftests: Check MOPS, PIE, POE and FPMR in a protected VM
In reply to Fuad TabbaFor each of MOPS, S1PIE, S1POE and FPMR that a protected VM's ID registers advertise, EL2 has to set up the HCRX_EL2 enables, the fine-grained traps and the context switch to match.
Check from the guest that each feature works when its ID field is set and UNDEFs when it is clear. Working means the registers read back what the guest writes, and a SETP/SETM/SETE fill completes. At v7.4-rc1 pKVM advertises none of the four, so only the UNDEF cases run. Also check that ID_AA64PFR2_EL1, ID_AA64ISAR3_EL1 and ID_AA64MMFR3_EL1 expose nothing beyond the supported features, and that WFxT and the 128-bit System register features stay hidden.
--- .../selftests/kvm/arm64/pkvm_id_regs.c | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+)
tools/testing/selftests/kvm/arm64/pkvm_id_regs.c +70 -0
@@ -33,6 +33,11 @@#define DBGBCR_VAL ((0xfUL << 5) | (1UL << 1))#define DBGWCR_VAL ((0xffUL << 5) | (3UL << 3) | (1UL << 1)) +/* Allocated encodings only: a reserved one reads back UNKNOWN. */ +#define PIR_PATTERN 0xeca87653210eca87UL +#define POR_PATTERN 0x76543210UL +#define FPMR_PATTERN 0x2a5a55c000UL +extern unsigned char brk_insn;static volatile bool undef_seen;
@@ -132,6 +137,20 @@ static void assert_id_regs(void)GUEST_ASSERT_EQ (read_sysreg_s (SYS_ID_AA64ISAR2_EL1 ) & (ID_AA64ISAR2_EL1_APA3_MASK |ID_AA64ISAR2_EL1_GPA3_MASK ),0 ); +/* WFxT and the 128-bit System register and instruction features are hidden. */ +GUEST_ASSERT_EQ (read_sysreg_s (SYS_ID_AA64ISAR2_EL1 ) & + (ID_AA64ISAR2_EL1_WFxT_MASK |ID_AA64ISAR2_EL1_SYSREG_128_MASK | +ID_AA64ISAR2_EL1_SYSINSTR_128_MASK ),0 ); + +/* Of these registers, only the fields of the features pKVM supports can be set. */ +GUEST_ASSERT_EQ (read_sysreg_s (SYS_ID_AA64PFR2_EL1 ) & ~ID_AA64PFR2_EL1_FPMR_MASK ,0 ); +GUEST_ASSERT_EQ (read_sysreg_s (SYS_ID_AA64ISAR3_EL1 ) & + ~(ID_AA64ISAR3_EL1_FPRCVT_MASK |ID_AA64ISAR3_EL1_LSFE_MASK | +ID_AA64ISAR3_EL1_FAMINMAX_MASK |ID_AA64ISAR3_EL1_LSUI_MASK ),0 ); +GUEST_ASSERT_EQ (read_sysreg_s (SYS_ID_AA64MMFR3_EL1 ) & + ~(ID_AA64MMFR3_EL1_TCRX_MASK |ID_AA64MMFR3_EL1_SCTLRX_MASK | +ID_AA64MMFR3_EL1_S1PIE_MASK |ID_AA64MMFR3_EL1_S1POE_MASK ),0 ); +GUEST_ASSERT_EQ (read_sysreg_s (SYS_ID_AA64DFR1_EL1 ),0 );GUEST_ASSERT_EQ (read_sysreg_s (SYS_ID_AA64AFR0_EL1 ),0 );GUEST_ASSERT_EQ (read_sysreg_s (SYS_ID_AA64AFR1_EL1 ),0 );
@@ -217,6 +236,56 @@ static void assert_undef_regs(void)GUEST_ASSERT_UNDEF (asmvolatile (".arch_extension sve\n rdvl x0, #1" : : :"x0" )); } +/* setp [x0]!, x1!, x2; setm; sete */ +static void mops_set (void *dst,u64 len,u64 val) +{ + register void *d asm("x0") = dst; + register u64 n asm("x1") = len; + register u64 v asm("x2") = val; + + asmvolatile (".inst 0x19c20420\n\t.inst 0x19c24420\n\t.inst 0x19c28420" + :"+r" (d),"+r" (n) :"r" (v) :"cc" ,"memory" ); +} + +/* A feature's registers and instructions work when it's advertised and UNDEF when hidden. */ +static void assert_feature_access (void ) +{ +u64 mmfr3 =read_sysreg_s (SYS_ID_AA64MMFR3_EL1 ); +u64 buf[4 ] = {}; +int i; + +if (SYS_FIELD_GET (ID_AA64MMFR3_EL1 ,S1PIE , mmfr3)) { +GUEST_ASSERT_RW (SYS_PIR_EL1 ,PIR_PATTERN ); +GUEST_ASSERT_RW (SYS_PIRE0_EL1 ,PIR_PATTERN ); + }else { +GUEST_ASSERT_UNDEF ((void )read_sysreg_s (SYS_PIR_EL1 )); +GUEST_ASSERT_UNDEF ((void )read_sysreg_s (SYS_PIRE0_EL1 )); + } + +if (SYS_FIELD_GET (ID_AA64MMFR3_EL1 ,S1POE , mmfr3)) { +GUEST_ASSERT_RW (SYS_POR_EL1 ,POR_PATTERN ); +GUEST_ASSERT_RW (SYS_POR_EL0 ,POR_PATTERN ); + }else { +GUEST_ASSERT_UNDEF ((void )read_sysreg_s (SYS_POR_EL1 )); +GUEST_ASSERT_UNDEF ((void )read_sysreg_s (SYS_POR_EL0 )); + } + +if (SYS_FIELD_GET (ID_AA64PFR2_EL1 ,FPMR ,read_sysreg_s (SYS_ID_AA64PFR2_EL1 ))) +GUEST_ASSERT_RW (SYS_FPMR ,FPMR_PATTERN ); +else +GUEST_ASSERT_UNDEF ((void )read_sysreg_s (SYS_FPMR )); + +if (SYS_FIELD_GET (ID_AA64ISAR2_EL1 ,MOPS ,read_sysreg_s (SYS_ID_AA64ISAR2_EL1 ))) { + undef_seen = false; +mops_set (buf,sizeof (buf),0x5a ); +GUEST_ASSERT (!undef_seen); +for (i =0 ; i <ARRAY_SIZE (buf); i++) +GUEST_ASSERT_EQ (buf[i],0x5a5a5a5a5a5a5a5aUL ); + }else { +GUEST_ASSERT_UNDEF (mops_set (buf,sizeof (buf),0x5a )); + } +} +static void assert_host_handled (void ) {/* Host-handled registers reach the guest with no UNDEF. */
@@ -236,6 +305,7 @@ static void guest_baseline(void)else assert_debug_raz_wi ();assert_undef_regs (); +assert_feature_access ();assert_host_handled (); asmvolatile ("brk_insn: brk #0" );
Signature · 1 line
2.47.3
Hi Fuad,
Tested this series on top of v7.4-rc1 under QEMU TCG (-M virt, virtualization=on,gic-version=3 -cpu max -smp 4), booted with kvm-arm.mode=protected (protected hVHE mode).
- All pkvm_* selftests pass. The only skips are the self-hosted debug (breakpoint, watchpoint, single-step) and SVE cases, which pKVM doesn't expose to protected guests.
- pkvm_id_regs fails with patch 1 reverted and passes with it applied.
- Each patch builds individually.
Thanks,
Ștefania
Hi Fuad,
I have tested this series based on v7.4-rc1 in QEMU with gic-version=3, -cpu max, pauth=off, -smp 4, -m 8G
All pkvm_* selftests pass. I confirmed that the skips you mentioned are features that pKVM doesn't expose to protected guests. pkvm_id_regs fails with patch 1 reverted and passes with it applied. Each patch builds individually (tested with git rebase --exec).
Thanks,
Mihai