Thread (29 messages) 29 messages, 6 authors, 2025-07-25

Re: [RFC PATCH v2 1/9] KVM: arm64: nv: selftests: Add support to run guest code in vEL2.

From: Marc Zyngier <maz@kernel.org>
Date: 2025-05-29 11:51:02
Also in: kvmarm, linux-kselftest, lkml

On Mon, 12 May 2025 11:52:43 +0100,
Ganapatrao Kulkarni [off-list ref] wrote:
quoted hunk ↗ jump to hunk
This patch adds required changes to vcpu init to run a guest code
in vEL2 context and also adds NV specific helper functions.

Signed-off-by: Ganapatrao Kulkarni <redacted>
---
 tools/testing/selftests/kvm/Makefile.kvm      |  2 +
 .../kvm/include/arm64/kvm_util_arch.h         |  3 +
 .../selftests/kvm/include/arm64/nv_util.h     | 45 ++++++++++++++
 .../selftests/kvm/include/arm64/vgic.h        |  1 +
 .../testing/selftests/kvm/include/kvm_util.h  |  3 +
 tools/testing/selftests/kvm/lib/arm64/nv.c    | 46 ++++++++++++++
 .../selftests/kvm/lib/arm64/processor.c       | 61 ++++++++++++++-----
 tools/testing/selftests/kvm/lib/arm64/vgic.c  |  8 +++
 8 files changed, 155 insertions(+), 14 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/include/arm64/nv_util.h
 create mode 100644 tools/testing/selftests/kvm/lib/arm64/nv.c
diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
index f773f8f99249..3348f729d3b2 100644
--- a/tools/testing/selftests/kvm/Makefile.kvm
+++ b/tools/testing/selftests/kvm/Makefile.kvm
@@ -37,6 +37,7 @@ LIBKVM_arm64 += lib/arm64/processor.c
 LIBKVM_arm64 += lib/arm64/spinlock.c
 LIBKVM_arm64 += lib/arm64/ucall.c
 LIBKVM_arm64 += lib/arm64/vgic.c
+LIBKVM_arm64 += lib/arm64/nv.c
 
 LIBKVM_s390 += lib/s390/diag318_test_handler.c
 LIBKVM_s390 += lib/s390/processor.c
@@ -155,6 +156,7 @@ TEST_GEN_PROGS_arm64 += arm64/vgic_irq
 TEST_GEN_PROGS_arm64 += arm64/vgic_lpi_stress
 TEST_GEN_PROGS_arm64 += arm64/vpmu_counter_access
 TEST_GEN_PROGS_arm64 += arm64/no-vgic-v3
+TEST_GEN_PROGS_arm64 += arm64/nv_guest_hypervisor
 TEST_GEN_PROGS_arm64 += access_tracking_perf_test
 TEST_GEN_PROGS_arm64 += arch_timer
 TEST_GEN_PROGS_arm64 += coalesced_io_test
diff --git a/tools/testing/selftests/kvm/include/arm64/kvm_util_arch.h b/tools/testing/selftests/kvm/include/arm64/kvm_util_arch.h
index e43a57d99b56..ab5279c24413 100644
--- a/tools/testing/selftests/kvm/include/arm64/kvm_util_arch.h
+++ b/tools/testing/selftests/kvm/include/arm64/kvm_util_arch.h
@@ -2,6 +2,9 @@
 #ifndef SELFTEST_KVM_UTIL_ARCH_H
 #define SELFTEST_KVM_UTIL_ARCH_H
 
+#define CurrentEL_EL1		(1 << 2)
+#define CurrentEL_EL2		(2 << 2)
+
 struct kvm_vm_arch {};
 
 #endif  // SELFTEST_KVM_UTIL_ARCH_H
diff --git a/tools/testing/selftests/kvm/include/arm64/nv_util.h b/tools/testing/selftests/kvm/include/arm64/nv_util.h
new file mode 100644
index 000000000000..622a17c9d142
--- /dev/null
+++ b/tools/testing/selftests/kvm/include/arm64/nv_util.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2025 Ampere Computing
+ */
+#ifndef SELFTEST_NV_UTIL_H
+#define SELFTEST_NV_UTIL_H
+
+#include <linux/bitmap.h>
+#include <vgic.h>
+
+#define HCR_NV2		(UL(1) << 45)
+#define HCR_AT		(UL(1) << 44)
+#define HCR_NV		(UL(1) << 42)
+#define HCR_E2H		(UL(1) << 34)
+#define HCR_TTLB        (UL(1) << 25)
+
+/* Enable NV2 and guest in VHE mode */
+#define HCR_EL2_NV_EANBLE (HCR_E2H | HCR_NV | HCR_NV2 | HCR_AT | HCR_TTLB)
+
What is the point of enabling NV and trapping all sort of things,
given that you're not even enabling a guest? How do you expect to deal
with EL0 without TGE being set?

	M.

-- 
Without deviation from the norm, progress is not possible.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help