Subject: [PATCH v1 04/26] KVM: arm64: Generalize kvm_cmp_feat_*()

From: Steffen Eiden <[email-masked]>
Date: Fri, 29 May 2026 17:55:37 +0200

Introduce an intermediate macro that extracts the value from a passed
parameter instead of reading the VM's ID register. Allow using other
sources of ID register values, i.e. read directly from the hardware or
during a sequence of sanitization steps.

Co-developed-by: Nina Schoetterl-Glausch <[email-masked]>
Signed-off-by: Nina Schoetterl-Glausch <[email-masked]>
Signed-off-by: Steffen Eiden <[email-masked]>
---
 arch/arm64/include/asm/kvm_feature.h | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_feature.h b/arch/arm64/include/asm/kvm_feature.h
index 067550d5b208..6dd7b4a4929c 100644
--- a/arch/arm64/include/asm/kvm_feature.h
+++ b/arch/arm64/include/asm/kvm_feature.h
@@ -15,6 +15,17 @@
 		sign_extend64(__val, id##_##fld##_WIDTH - 1);		\
 	})
 
+#define cmp_id_feat_signed(val, id, fld, op, limit)			\
+	(extract_id_field_signed((val), id, fld) op S64_SYS_FIELD_VALUE(id, fld, limit))
+
+#define cmp_id_feat_unsigned(val, id, fld, op, limit)			\
+	(extract_id_field_unsigned((val), id, fld) op (u64)SYS_FIELD_VALUE(id, fld, limit))
+
+#define cmp_id_feat(val, id, fld, op, limit)				\
+	(id##_##fld##_SIGNED ?						\
+	 cmp_id_feat_signed(val, id, fld, op, limit) :			\
+	 cmp_id_feat_unsigned(val, id, fld, op, limit))
+
 #define get_idreg_field_unsigned(kvm, id, fld)				\
 	extract_id_field_unsigned(kvm_read_vm_id_reg((kvm), SYS_##id), id, fld)
 
@@ -25,15 +36,13 @@
 	extract_id_field_unsigned(kvm_read_vm_id_reg((kvm), SYS_##id), id, fld)
 
 #define kvm_cmp_feat_signed(kvm, id, fld, op, limit)			\
-	(get_idreg_field_signed((kvm), id, fld) op S64_SYS_FIELD_VALUE(id, fld, limit))
+	cmp_id_feat_signed(kvm_read_vm_id_reg((kvm), SYS_##id), id, fld, op, limit)
 
 #define kvm_cmp_feat_unsigned(kvm, id, fld, op, limit)			\
-	(get_idreg_field_unsigned((kvm), id, fld) op (u64)SYS_FIELD_VALUE(id, fld, limit))
+	cmp_id_feat_unsigned(kvm_read_vm_id_reg((kvm), SYS_##id), id, fld, op, limit)
 
 #define kvm_cmp_feat(kvm, id, fld, op, limit)				\
-	(id##_##fld##_SIGNED ?						\
-	 kvm_cmp_feat_signed(kvm, id, fld, op, limit) :			\
-	 kvm_cmp_feat_unsigned(kvm, id, fld, op, limit))
+	cmp_id_feat(kvm_read_vm_id_reg((kvm), SYS_##id), id, fld, op, limit)
 
 #define __kvm_has_feat(kvm, id, fld, limit)				\
 	kvm_cmp_feat(kvm, id, fld, >=, limit)
-- 
2.53.0