Subject: [PATCH v1 02/26] KVM: arm64: Remove __expand_field_sign_(un)signed

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

__expand_field_sign_unsigned is a very small abstraction that makes it
harder to see what's happening when looking at the caller. Just inline
it. Create a macro S64_SYS_FIELD_VALUE that is a sign extended
SYS_FIELD_VALUE. Then also get rid of __expand_field_sign_signed.

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 | 13 ++-----------
 include/arch/arm64/asm/sysreg-defs.h |  8 ++++++++
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_feature.h b/arch/arm64/include/asm/kvm_feature.h
index 8d0c65246aa0..d580f4ffab34 100644
--- a/arch/arm64/include/asm/kvm_feature.h
+++ b/arch/arm64/include/asm/kvm_feature.h
@@ -6,15 +6,6 @@
 #include <linux/bitfield.h>
 #include <asm/sysreg-defs.h>
 
-#define __expand_field_sign_unsigned(id, fld, val)			\
-	((u64)SYS_FIELD_VALUE(id, fld, val))
-
-#define __expand_field_sign_signed(id, fld, val)			\
-	({								\
-		u64 __val = SYS_FIELD_VALUE(id, fld, val);		\
-		sign_extend64(__val, id##_##fld##_WIDTH - 1);		\
-	})
-
 #define get_idreg_field_unsigned(kvm, id, fld)				\
 	({								\
 		u64 __val = kvm_read_vm_id_reg((kvm), SYS_##id);	\
@@ -31,10 +22,10 @@
 	get_idreg_field_unsigned(kvm, id, fld)
 
 #define kvm_cmp_feat_signed(kvm, id, fld, op, limit)			\
-	(get_idreg_field_signed((kvm), id, fld) op __expand_field_sign_signed(id, fld, limit))
+	(get_idreg_field_signed((kvm), id, fld) op S64_SYS_FIELD_VALUE(id, fld, limit))
 
 #define kvm_cmp_feat_unsigned(kvm, id, fld, op, limit)			\
-	(get_idreg_field_unsigned((kvm), id, fld) op __expand_field_sign_unsigned(id, fld, limit))
+	(get_idreg_field_unsigned((kvm), id, fld) op (u64)SYS_FIELD_VALUE(id, fld, limit))
 
 #define kvm_cmp_feat(kvm, id, fld, op, limit)				\
 	(id##_##fld##_SIGNED ?						\
diff --git a/include/arch/arm64/asm/sysreg-defs.h b/include/arch/arm64/asm/sysreg-defs.h
index 27646c91e15c..3e280d4156ce 100644
--- a/include/arch/arm64/asm/sysreg-defs.h
+++ b/include/arch/arm64/asm/sysreg-defs.h
@@ -998,9 +998,17 @@
 
 #ifndef __ASSEMBLER__
 #include <linux/bitfield.h>
+#include <linux/bitops.h>
+#include <linux/types.h>
 
 #define SYS_FIELD_VALUE(reg, field, val)	reg##_##field##_##val
 
+#define S64_SYS_FIELD_VALUE(id, fld, val)				\
+	({								\
+		u64 __val = SYS_FIELD_VALUE(id, fld, val);		\
+		sign_extend64(__val, id##_##fld##_WIDTH - 1);		\
+	})
+
 #define SYS_FIELD_GET(reg, field, val)		\
 		 FIELD_GET(reg##_##field##_MASK, val)
 
-- 
2.53.0