Subject: [PATCH v1 03/26] KVM: arm64: Generalize get_idreg_field_*()

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

Introduce intermediate macros that extract 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, 11 insertions(+), 8 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_feature.h b/arch/arm64/include/asm/kvm_feature.h
index d580f4ffab34..067550d5b208 100644
--- a/arch/arm64/include/asm/kvm_feature.h
+++ b/arch/arm64/include/asm/kvm_feature.h
@@ -6,20 +6,23 @@
 #include <linux/bitfield.h>
 #include <asm/sysreg-defs.h>
 
-#define get_idreg_field_unsigned(kvm, id, fld)				\
-	({								\
-		u64 __val = kvm_read_vm_id_reg((kvm), SYS_##id);	\
-		FIELD_GET(id##_##fld##_MASK, __val);			\
-	})
+#define extract_id_field_unsigned(val, id, fld)				\
+	(FIELD_GET(id##_##fld##_MASK, (val)))
 
-#define get_idreg_field_signed(kvm, id, fld)				\
+#define extract_id_field_signed(val, id, fld)				\
 	({								\
-		u64 __val = get_idreg_field_unsigned(kvm, id, fld);	\
+		u64 __val = extract_id_field_unsigned((val), id, fld);	\
 		sign_extend64(__val, id##_##fld##_WIDTH - 1);		\
 	})
 
+#define get_idreg_field_unsigned(kvm, id, fld)				\
+	extract_id_field_unsigned(kvm_read_vm_id_reg((kvm), SYS_##id), id, fld)
+
+#define get_idreg_field_signed(kvm, id, fld)				\
+	extract_id_field_signed(kvm_read_vm_id_reg((kvm), SYS_##id), id, fld)
+
 #define get_idreg_field_enum(kvm, id, fld)				\
-	get_idreg_field_unsigned(kvm, id, fld)
+	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))
-- 
2.53.0