From: Haseeb Ashraf Run the existing kvm-unit-tests smoke test with VHE hidden from the guest hypervisor through SYSREG_ID_AA64MMFR1_EL1_VH=0. The SYSREG_* properties are available only for the host CPU model with KVM, so select the accelerator and CPU model explicitly, and check that the guest kernel initialized its hypervisor in nVHE mode. The test is skipped when the host kernel cannot limit EL2 to nVHE. Signed-off-by: Haseeb Ashraf --- v2: - Select KVM and the host CPU model explicitly. - Verify the guest kernel reports nVHE mode. tests/functional/aarch64/test_kvm.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/functional/aarch64/test_kvm.py b/tests/functional/aarch64/test_kvm.py index c977e8c6d2..b7a4aceb66 100755 --- a/tests/functional/aarch64/test_kvm.py +++ b/tests/functional/aarch64/test_kvm.py @@ -30,7 +30,7 @@ class Aarch64VirtKVMTests(LinuxKernelTest): # base of tests KUT_BASE = "/usr/share/kvm-unit-tests/" - def _launch_guest(self, kvm_mode="nvhe"): + def _launch_guest(self, kvm_mode="nvhe", cpu="max", accel=None): self.set_machine('virt') kernel_path = self.ASSET_KVM_TEST_KERNEL.fetch() @@ -39,7 +39,9 @@ def _launch_guest(self, kvm_mode="nvhe"): kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + f"console=ttyAMA0 kvm-arm.mode={kvm_mode}") - self.vm.add_args("-cpu", "max") + if accel: + self.vm.add_args("-accel", accel) + self.vm.add_args("-cpu", cpu) self.vm.add_args("-machine", "virt,gic-version=3,virtualization=on", '-kernel', kernel_path, '-append', kernel_command_line) @@ -50,6 +52,9 @@ def _launch_guest(self, kvm_mode="nvhe"): except VMLaunchFailure as excp: if "does not support providing Virtualization" in excp.output: self.skipTest("accelerator has no virtualization support") + elif ("SYSREG_ID_AA64MMFR1_EL1_VH" in excp.output and + "not found" in excp.output): + self.skipTest("host KVM cannot limit EL2 to nVHE") else: self.log.info("unhandled launch failure: %s", excp.output) raise excp @@ -73,5 +78,18 @@ def test_aarch64_vhe_selftest(self): self._launch_guest("vhe") self._smoketest_kvm() + def test_aarch64_nvhe_only_selftest(self): + # Hiding VHE from the guest hypervisor is a KVM feature: the + # SYSREG_* properties only exist for the host CPU model with KVM. + self.require_accelerator("kvm") + self._launch_guest("nvhe", "host,SYSREG_ID_AA64MMFR1_EL1_VH=0", + accel="kvm") + # The guest kernel must run its hypervisor in nVHE mode + ec_and_wait(self, "dmesg | grep -Eq " + "'Hyp (nVHE )?mode initialized successfully' && " + "! dmesg | grep -q ' VHE mode initialized'", + self.OK_CMD) + self._smoketest_kvm() + if __name__ == '__main__': LinuxKernelTest.main() -- 2.34.1