Skip to contentSkip to conversation

KVM: selftests: Add ID reg test, update headers

PATCH Superseded Oliver Upton 3 participants 12 messages Oct 10, 2023 – Oct 11, 2023

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover KVM: selftests: Add ID reg test, update headers

The writable ID register test depends on the latest system register definitions, which cannot be trivially added to tools. In order to keep a single copy of sysreg gunk in tools all users (KVM selftests, perf) need to be updated to generate headers at build time.

Tested arm64 and x86 builds of both KVM selftests and perf tool.

v1 -> v2:
- Use the sysreg definition generation script instead of copying the output (broonie)
- Use a common Makefile for both KVM selftests as well as perf
- Include the KVM selftest responsible for the change

v1: https://lore.kernel.org/kvmarm/[email protected]/

Jing Zhang (2):
tools headers arm64: Update sysreg.h with kernel sources
KVM: arm64: selftests: Test for setting ID register from usersapce

Oliver Upton (3):
tools headers arm64: Copy sysreg-defs generation from kernel source perf build: Generate arm64's sysreg-defs.h and add to include path
KVM: selftests: Generate sysreg-defs.h and add to include path

 tools/arch/arm64/include/.gitignore           |    1 +
 tools/arch/arm64/include/asm/gpr-num.h        |   26 +
 tools/arch/arm64/include/asm/sysreg.h         |  839 ++----
 tools/arch/arm64/tools/Makefile               |   38 +
 tools/arch/arm64/tools/gen-sysreg.awk         |  336 +++
 tools/arch/arm64/tools/sysreg                 | 2497 +++++++++++++++++
 tools/perf/Makefile.perf                      |   15 +-
 tools/perf/check-headers.sh                   |    4 +
 tools/perf/util/Build                         |    2 +-
 tools/testing/selftests/kvm/Makefile          |   24 +-
 .../selftests/kvm/aarch64/aarch32_id_regs.c   |    4 +-
 .../selftests/kvm/aarch64/debug-exceptions.c  |   12 +-
 .../selftests/kvm/aarch64/page_fault_test.c   |    6 +-
 .../selftests/kvm/aarch64/set_id_regs.c       |  479 ++++
 .../selftests/kvm/lib/aarch64/processor.c     |    6 +-
 15 files changed, 3622 insertions(+), 667 deletions(-)
 create mode 100644 tools/arch/arm64/include/.gitignore
 create mode 100644 tools/arch/arm64/include/asm/gpr-num.h
 create mode 100644 tools/arch/arm64/tools/Makefile
 create mode 100755 tools/arch/arm64/tools/gen-sysreg.awk
 create mode 100644 tools/arch/arm64/tools/sysreg
 create mode 100644 tools/testing/selftests/kvm/aarch64/set_id_regs.c

base-commit: dafa493dd01d5992f1cb70b08d1741c3ab99e04a

Signature · 1 line
2.42.0.609.gbb76f46606-goog
#1 lore raw

PATCH v2 1/5 tools headers arm64: Copy sysreg-defs generation from kernel source

The system register definitions are now generated with a script over in the kernel sources. Pull a copy into tools in anticipation of updating dependent header files and add a common makefile for generating the header.

---
 tools/arch/arm64/include/.gitignore   |    1 +
 tools/arch/arm64/tools/Makefile       |   38 +
 tools/arch/arm64/tools/gen-sysreg.awk |  336 ++++
 tools/arch/arm64/tools/sysreg         | 2497 +++++++++++++++++++++++++
 tools/perf/check-headers.sh           |    4 +
 5 files changed, 2876 insertions(+)
 create mode 100644 tools/arch/arm64/include/.gitignore
 create mode 100644 tools/arch/arm64/tools/Makefile
 create mode 100755 tools/arch/arm64/tools/gen-sysreg.awk
 create mode 100644 tools/arch/arm64/tools/sysreg
tools/arch/arm64/include/.gitignore new file +1 -0
new file mode 100644
index 000000000000..9ab870da897d
@@ -0,0 +1 @@
+generated/
tools/arch/arm64/tools/Makefile new file +38 -0
new file mode 100644
index 000000000000..d4e652d072fa
@@ -0,0 +1,38 @@
+# SPDX-License-Identifier: GPL-2.0
+
+ifeq ($(srctree),)
+srctree := $(patsubst %/,%,$(dir $(CURDIR)))
+srctree := $(patsubst %/,%,$(dir $(srctree)))
+srctree := $(patsubst %/,%,$(dir $(srctree)))
+srctree := $(patsubst %/,%,$(dir $(srctree)))
+endif
+
+include $(srctree)/tools/scripts/Makefile.include
+
+AWK	?= awk
+MKDIR	?= mkdir
+RM	?= rm
+
+ifeq ($(V),1)
+Q =
+else
+Q = @
+endif
+
+arm64_tools_dir = $(srctree)/tools/arch/arm64/tools
+arm64_sysreg_tbl = $(arm64_tools_dir)/sysreg
+arm64_gen_sysreg = $(arm64_tools_dir)/gen-sysreg.awk
+arm64_generated_dir = $(srctree)/tools/arch/arm64/include/generated
+arm64_sysreg_defs = $(arm64_generated_dir)/asm/sysreg-defs.h
+
+all: $(arm64_sysreg_defs)
+	@:
+
+$(arm64_sysreg_defs): $(arm64_gen_sysreg) $(arm64_sysreg_tbl)
+	$(Q)$(MKDIR) -p $(dir $@)
+	$(QUIET_GEN)$(AWK) -f $^ > $@
+
+clean:
+	$(Q)$(RM) -rf $(arm64_generated_dir)
+
+.PHONY: all clean
tools/arch/arm64/tools/gen-sysreg.awk new file +336 -0

336 lines not on this page · raw message

tools/arch/arm64/tools/sysreg new file +2497 -0

2,497 lines not on this page · raw message

tools/perf/check-headers.sh +4 -0
index 4314c9197850..78e8b4cd06a1 100755
@@ -183,6 +183,10 @@ done
 check_2 tools/perf/util/hashmap.h tools/lib/bpf/hashmap.h
 check_2 tools/perf/util/hashmap.c tools/lib/bpf/hashmap.c
 
+# check duplicated scripts
+check_2 tools/arch/arm64/tools/sysreg arch/arm64/tools/sysreg
+check_2 tools/arch/arm64/tools/gen-sysreg.awk arch/arm64/tools/gen-sysreg.awk
+
 cd tools/perf || exit
 
 if [ ${#FAILURES[@]} -gt 0 ]
Signature · 1 line
2.42.0.609.gbb76f46606-goog
Reviewed-by on v2 1/5
#2 lore raw

Re: [PATCH v2 1/5] tools headers arm64: Copy sysreg-defs generation from kernel source

Quoted 4 lines · Oliver Upton

The system register definitions are now generated with a script over in the kernel sources. Pull a copy into tools in anticipation of updating dependent header files and add a common makefile for generating the header.

maintainer
#3 lore raw

Re: [PATCH v2 1/5] tools headers arm64: Copy sysreg-defs generation from kernel source

In reply to Oliver Upton
Quoted 5 lines · Oliver Upton

The system register definitions are now generated with a script over in the kernel sources. Pull a copy into tools in anticipation of updating dependent header files and add a common makefile for generating the header.

Rather than a copy, which makes the maintenance pretty horrible, why don't you just symlink it? Git is perfectly capable of storing them, last time I checked.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#4 lore raw

Re: [PATCH v2 1/5] tools headers arm64: Copy sysreg-defs generation from kernel source

Quoted 10 lines · Marc Zyngier
Quoted 4 lines · Oliver Upton

The system register definitions are now generated with a script over in the kernel sources. Pull a copy into tools in anticipation of updating dependent header files and add a common makefile for generating the header.

Rather than a copy, which makes the maintenance pretty horrible, why don't you just symlink it? Git is perfectly capable of storing them, last time I checked.

Do we even need to symlink - as I suggested on the previous version can we not just reference the script and data file directly in the main kernel tree? Like I said then there may be some use case for building the tools directory outside the kernel source that I'm not aware of but otherwise I'm not clear that the motivations for copying the actual headers for use in tools/ apply to these files.

I think the current approach is *fine* (hence my reviewed by) given the amount of other copying but it would save a bit of work to not copy.

#5 lore raw

Re: [PATCH v2 1/5] tools headers arm64: Copy sysreg-defs generation from kernel source

Quoted 19 lines · Mark Brown
Quoted 10 lines · Marc Zyngier
Quoted 4 lines · Oliver Upton

The system register definitions are now generated with a script over in the kernel sources. Pull a copy into tools in anticipation of updating dependent header files and add a common makefile for generating the header.

Rather than a copy, which makes the maintenance pretty horrible, why don't you just symlink it? Git is perfectly capable of storing them, last time I checked.

Do we even need to symlink - as I suggested on the previous version can we not just reference the script and data file directly in the main kernel tree? Like I said then there may be some use case for building the tools directory outside the kernel source that I'm not aware of but otherwise I'm not clear that the motivations for copying the actual headers for use in tools/ apply to these files.

Quoted 3 lines

I think the current approach is *fine* (hence my reviewed by) given the amount of other copying but it would save a bit of work to not copy.

So long as we aren't going to do any further renames I don't have an issue with this approach.

Signature · 2 lines
Thanks,
Oliver
#6 lore raw

Re: [PATCH v2 1/5] tools headers arm64: Copy sysreg-defs generation from kernel source

Quoted 7 lines · Oliver Upton
Quoted 5 lines · Mark Brown
Quoted 3 lines · Marc Zyngier

Rather than a copy, which makes the maintenance pretty horrible, why don't you just symlink it? Git is perfectly capable of storing them, last time I checked.

Quoted 6 lines
Quoted 3 lines

Do we even need to symlink - as I suggested on the previous version can we not just reference the script and data file directly in the main kernel tree? Like I said then there may be some use case for building

So long as we aren't going to do any further renames I don't have an issue with this approach.

It doesn't seem likely, and it feels like it's reasonable to ask anyone who wants to do them to ensure they take care of the tools/ directory as part of it.

#7 lore raw

PATCH v2 2/5 perf build: Generate arm64's sysreg-defs.h and add to include path

In reply to Oliver Upton

Start generating sysreg-defs.h in anticipation of updating sysreg.h to a version that needs the generated output.

---
 tools/perf/Makefile.perf | 15 +++++++++++++--
 tools/perf/util/Build    |  2 +-
 2 files changed, 14 insertions(+), 3 deletions(-)
tools/perf/Makefile.perf +13 -2
index 37af6df7b978..14dedd11a1f5 100644
@@ -443,6 +443,15 @@ drm_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/drm_ioctl.sh
 # Create output directory if not already present
 _dummy := $(shell [ -d '$(beauty_ioctl_outdir)' ] || mkdir -p '$(beauty_ioctl_outdir)')
 
+arm64_gen_sysreg_dir := $(srctree)/tools/arch/arm64/tools
+
+arm64-sysreg-defs: FORCE
+	$(Q)$(MAKE) -C $(arm64_gen_sysreg_dir)
+
+arm64-sysreg-defs-clean:
+	$(call QUIET_CLEAN,arm64-sysreg-defs)
+	$(Q)$(MAKE) -C $(arm64_gen_sysreg_dir) clean > /dev/null
+
 $(drm_ioctl_array): $(drm_hdr_dir)/drm.h $(drm_hdr_dir)/i915_drm.h $(drm_ioctl_tbl)
 	$(Q)$(SHELL) '$(drm_ioctl_tbl)' $(drm_hdr_dir) > $@
 
@@ -716,7 +725,9 @@ endif
 __build-dir = $(subst $(OUTPUT),,$(dir $@))
 build-dir   = $(or $(__build-dir),.)
 
-prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders $(drm_ioctl_array) \
+prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders \
+	arm64-sysreg-defs \
+	$(drm_ioctl_array) \
 	$(fadvise_advice_array) \
 	$(fsconfig_arrays) \
 	$(fsmount_arrays) \
@@ -1125,7 +1136,7 @@ endif # BUILD_BPF_SKEL
 bpf-skel-clean:
 	$(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS)
 
-clean:: $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBSYMBOL)-clean $(LIBPERF)-clean fixdep-clean python-clean bpf-skel-clean tests-coresight-targets-clean
+clean:: $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBSYMBOL)-clean $(LIBPERF)-clean arm64-sysreg-defs-clean fixdep-clean python-clean bpf-skel-clean tests-coresight-targets-clean
 	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIBPERF_A) $(OUTPUT)perf-archive $(OUTPUT)perf-iostat $(LANG_BINDINGS)
 	$(Q)find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
 	$(Q)$(RM) $(OUTPUT).config-detected
tools/perf/util/Build +1 -1
index 6d657c9927f7..2f76230958ad 100644
@@ -345,7 +345,7 @@ CFLAGS_rbtree.o        += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ET
 CFLAGS_libstring.o     += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
 CFLAGS_hweight.o       += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
 CFLAGS_header.o        += -include $(OUTPUT)PERF-VERSION-FILE
-CFLAGS_arm-spe.o       += -I$(srctree)/tools/arch/arm64/include/
+CFLAGS_arm-spe.o       += -I$(srctree)/tools/arch/arm64/include/ -I$(srctree)/tools/arch/arm64/include/generated/
 
 $(OUTPUT)util/argv_split.o: ../lib/argv_split.c FORCE
 	$(call rule_mkdir)
Signature · 1 line
2.42.0.609.gbb76f46606-goog
#8 lore raw

PATCH v2 3/5 KVM: selftests: Generate sysreg-defs.h and add to include path

In reply to Oliver Upton

Start generating sysreg-defs.h for arm64 builds in anticipation of updating sysreg.h to a version that depends on it.

---
 tools/testing/selftests/kvm/Makefile | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
tools/testing/selftests/kvm/Makefile +20 -3
index a3bb36fb3cfc..07b3f4dc1a77 100644
@@ -17,6 +17,17 @@ else
 	ARCH_DIR := $(ARCH)
 endif
 
+ifeq ($(ARCH),arm64)
+arm64_tools_dir := $(top_srcdir)/tools/arch/arm64/tools/
+GEN_HDRS := $(top_srcdir)/tools/arch/arm64/include/generated/
+CFLAGS += -I$(GEN_HDRS)
+
+prepare:
+	$(MAKE) -C $(arm64_tools_dir)
+else
+prepare:
+endif
+
 LIBKVM += lib/assert.c
 LIBKVM += lib/elf.c
 LIBKVM += lib/guest_modes.c
@@ -256,13 +267,18 @@ $(TEST_GEN_OBJ): $(OUTPUT)/%.o: %.c
 $(SPLIT_TESTS_TARGETS): %: %.o $(SPLIT_TESTS_OBJS)
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@
 
-EXTRA_CLEAN += $(LIBKVM_OBJS) $(TEST_DEP_FILES) $(TEST_GEN_OBJ) $(SPLIT_TESTS_OBJS) cscope.*
+EXTRA_CLEAN += $(GEN_HDRS) \
+	       $(LIBKVM_OBJS) \
+	       $(SPLIT_TESTS_OBJS) \
+	       $(TEST_DEP_FILES) \
+	       $(TEST_GEN_OBJ) \
+	       cscope.*
 
 x := $(shell mkdir -p $(sort $(dir $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ))))
-$(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c
+$(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c prepare
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
 
-$(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S
+$(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S prepare
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
 
 # Compile the string overrides as freestanding to prevent the compiler from
@@ -274,6 +290,7 @@ $(LIBKVM_STRING_OBJ): $(OUTPUT)/%.o: %.c
 x := $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS))))
 $(TEST_GEN_PROGS): $(LIBKVM_OBJS)
 $(TEST_GEN_PROGS_EXTENDED): $(LIBKVM_OBJS)
+$(TEST_GEN_OBJ): prepare
 
 cscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib ..
 cscope:
Signature · 1 line
2.42.0.609.gbb76f46606-goog
Reviewed-by on v2 3/5
#9 lore raw

Re: [PATCH v2 3/5] KVM: selftests: Generate sysreg-defs.h and add to include path

Quoted 2 lines · Oliver Upton

Start generating sysreg-defs.h for arm64 builds in anticipation of updating sysreg.h to a version that depends on it.

tools/testing/selftests/kvm/Makefile else · line 23

Quoted 4 lines
tools/testing/selftests/kvm/Makefile +4 -0
+ifeq ($(ARCH),arm64)
+arm64_tools_dir := $(top_srcdir)/tools/arch/arm64/tools/
+GEN_HDRS := $(top_srcdir)/tools/arch/arm64/include/generated/
+CFLAGS += -I$(GEN_HDRS)

We might want to hoist this up to the top level lib.mk at some point if other kselftests want it too but let's not worry about it until it's a practical issue.

#10 lore raw

PATCH v2 4/5 tools headers arm64: Update sysreg.h with kernel sources

In reply to Oliver Upton

From: Jing Zhang <[email protected]>

The users of sysreg.h (perf, KVM selftests) are now generating the necessary sysreg-defs.h; sync sysreg.h with the kernel sources and fix the KVM selftests that use macros which suffered a rename.

---
 tools/arch/arm64/include/asm/gpr-num.h        |  26 +
 tools/arch/arm64/include/asm/sysreg.h         | 839 ++++--------------
 .../selftests/kvm/aarch64/aarch32_id_regs.c   |   4 +-
 .../selftests/kvm/aarch64/debug-exceptions.c  |  12 +-
 .../selftests/kvm/aarch64/page_fault_test.c   |   6 +-
 .../selftests/kvm/lib/aarch64/processor.c     |   6 +-
 6 files changed, 232 insertions(+), 661 deletions(-)
 create mode 100644 tools/arch/arm64/include/asm/gpr-num.h
tools/arch/arm64/include/asm/gpr-num.h new file +26 -0
new file mode 100644
index 000000000000..05da4a7c5788
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_GPR_NUM_H
+#define __ASM_GPR_NUM_H
+
+#ifdef __ASSEMBLY__
+
+	.irp	num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30
+	.equ	.L__gpr_num_x\num, \num
+	.equ	.L__gpr_num_w\num, \num
+	.endr
+	.equ	.L__gpr_num_xzr, 31
+	.equ	.L__gpr_num_wzr, 31
+
+#else /* __ASSEMBLY__ */
+
+#define __DEFINE_ASM_GPR_NUMS					\
+"	.irp	num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\n" \
+"	.equ	.L__gpr_num_x\\num, \\num\n"			\
+"	.equ	.L__gpr_num_w\\num, \\num\n"			\
+"	.endr\n"						\
+"	.equ	.L__gpr_num_xzr, 31\n"				\
+"	.equ	.L__gpr_num_wzr, 31\n"
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* __ASM_GPR_NUM_H */
tools/arch/arm64/include/asm/sysreg.h +192 -647

1,107 lines not on this page · raw message

tools/testing/selftests/kvm/aarch64/aarch32_id_regs.c +2 -2
index b90580840b22..8e5bd07a3727 100644
@@ -146,8 +146,8 @@ static bool vcpu_aarch64_only(struct kvm_vcpu *vcpu)
 
 	vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR0_EL1), &val);
 
-	el0 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL0), val);
-	return el0 == ID_AA64PFR0_ELx_64BIT_ONLY;
+	el0 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_EL0), val);
+	return el0 == ID_AA64PFR0_EL1_ELx_64BIT_ONLY;
 }
 
 int main(void)
tools/testing/selftests/kvm/aarch64/debug-exceptions.c +6 -6
index f5b6cb3a0019..866002917441 100644
@@ -116,12 +116,12 @@ static void reset_debug_state(void)
 
 	/* Reset all bcr/bvr/wcr/wvr registers */
 	dfr0 = read_sysreg(id_aa64dfr0_el1);
-	brps = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_BRPS), dfr0);
+	brps = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_BRPs), dfr0);
 	for (i = 0; i <= brps; i++) {
 		write_dbgbcr(i, 0);
 		write_dbgbvr(i, 0);
 	}
-	wrps = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_WRPS), dfr0);
+	wrps = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_WRPs), dfr0);
 	for (i = 0; i <= wrps; i++) {
 		write_dbgwcr(i, 0);
 		write_dbgwvr(i, 0);
@@ -418,7 +418,7 @@ static void guest_code_ss(int test_cnt)
 
 static int debug_version(uint64_t id_aa64dfr0)
 {
-	return FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER), id_aa64dfr0);
+	return FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_DebugVer), id_aa64dfr0);
 }
 
 static void test_guest_debug_exceptions(uint8_t bpn, uint8_t wpn, uint8_t ctx_bpn)
@@ -539,14 +539,14 @@ void test_guest_debug_exceptions_all(uint64_t aa64dfr0)
 	int b, w, c;
 
 	/* Number of breakpoints */
-	brp_num = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_BRPS), aa64dfr0) + 1;
+	brp_num = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_BRPs), aa64dfr0) + 1;
 	__TEST_REQUIRE(brp_num >= 2, "At least two breakpoints are required");
 
 	/* Number of watchpoints */
-	wrp_num = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_WRPS), aa64dfr0) + 1;
+	wrp_num = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_WRPs), aa64dfr0) + 1;
 
 	/* Number of context aware breakpoints */
-	ctx_brp_num = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_CTX_CMPS), aa64dfr0) + 1;
+	ctx_brp_num = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_CTX_CMPs), aa64dfr0) + 1;
 
 	pr_debug("%s brp_num:%d, wrp_num:%d, ctx_brp_num:%d\n", __func__,
 		 brp_num, wrp_num, ctx_brp_num);
tools/testing/selftests/kvm/aarch64/page_fault_test.c +3 -3
index 47bb914ab2fa..975d28be3cca 100644
@@ -96,14 +96,14 @@ static bool guest_check_lse(void)
 	uint64_t isar0 = read_sysreg(id_aa64isar0_el1);
 	uint64_t atomic;
 
-	atomic = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64ISAR0_ATOMICS), isar0);
+	atomic = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_ATOMIC), isar0);
 	return atomic >= 2;
 }
 
 static bool guest_check_dc_zva(void)
 {
 	uint64_t dczid = read_sysreg(dczid_el0);
-	uint64_t dzp = FIELD_GET(ARM64_FEATURE_MASK(DCZID_DZP), dczid);
+	uint64_t dzp = FIELD_GET(ARM64_FEATURE_MASK(DCZID_EL0_DZP), dczid);
 
 	return dzp == 0;
 }
@@ -196,7 +196,7 @@ static bool guest_set_ha(void)
 	uint64_t hadbs, tcr;
 
 	/* Skip if HA is not supported. */
-	hadbs = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR1_HADBS), mmfr1);
+	hadbs = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR1_EL1_HAFDBS), mmfr1);
 	if (hadbs == 0)
 		return false;
 
tools/testing/selftests/kvm/lib/aarch64/processor.c +3 -3
index 3a0259e25335..6fe12e985ba5 100644
@@ -518,9 +518,9 @@ void aarch64_get_supported_page_sizes(uint32_t ipa,
 	err = ioctl(vcpu_fd, KVM_GET_ONE_REG, &reg);
 	TEST_ASSERT(err == 0, KVM_IOCTL_ERROR(KVM_GET_ONE_REG, vcpu_fd));
 
-	*ps4k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_TGRAN4), val) != 0xf;
-	*ps64k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_TGRAN64), val) == 0;
-	*ps16k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_TGRAN16), val) != 0;
+	*ps4k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_TGRAN4), val) != 0xf;
+	*ps64k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_TGRAN64), val) == 0;
+	*ps16k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_TGRAN16), val) != 0;
 
 	close(vcpu_fd);
 	close(vm_fd);
Signature · 1 line
2.42.0.609.gbb76f46606-goog
#11 lore raw

PATCH v2 5/5 KVM: arm64: selftests: Test for setting ID register from usersapce

In reply to Oliver Upton

From: Jing Zhang <[email protected]>

Add tests to verify setting ID registers from userspace is handled correctly by KVM. Also add a test case to use ioctl KVM_ARM_GET_REG_WRITABLE_MASKS to get writable masks.

---
 tools/testing/selftests/kvm/Makefile          |   1 +
 .../selftests/kvm/aarch64/set_id_regs.c       | 479 ++++++++++++++++++
 2 files changed, 480 insertions(+)
 create mode 100644 tools/testing/selftests/kvm/aarch64/set_id_regs.c
tools/testing/selftests/kvm/Makefile +1 -0
index 07b3f4dc1a77..4f4f6ad025f4 100644
@@ -156,6 +156,7 @@ TEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions
 TEST_GEN_PROGS_aarch64 += aarch64/hypercalls
 TEST_GEN_PROGS_aarch64 += aarch64/page_fault_test
 TEST_GEN_PROGS_aarch64 += aarch64/psci_test
+TEST_GEN_PROGS_aarch64 += aarch64/set_id_regs
 TEST_GEN_PROGS_aarch64 += aarch64/smccc_filter
 TEST_GEN_PROGS_aarch64 += aarch64/vcpu_width_config
 TEST_GEN_PROGS_aarch64 += aarch64/vgic_init
tools/testing/selftests/kvm/aarch64/set_id_regs.c new file +479 -0

479 lines not on this page · raw message

Signature · 1 line
2.42.0.609.gbb76f46606-goog