diff mbox series

KVM: arm64: Use the reg_to_encoding() macro instead of sys_reg()

Message ID 20210106144218.110665-1-alexandru.elisei@arm.com (mailing list archive)
State New, archived
Headers show
Series KVM: arm64: Use the reg_to_encoding() macro instead of sys_reg() | expand

Commit Message

Alexandru Elisei Jan. 6, 2021, 2:42 p.m. UTC
The reg_to_encoding() macro is a wrapper over sys_reg() and conveniently
takes a sys_reg_desc or a sys_reg_params argument and returns the 32 bit
register encoding. Use it instead of calling sys_reg() directly.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
Patch was created on top of v5.11-rc2 with the patch that removes the
spurious semicolon from reg_to_encoding() [1] applied.

Tested on a rockpro64 with kvm-unit-tests, which exercise the
access_arch_timer() and id_visibility() functions. LORegion registers are
touched by the kernel when booting at EL2, so I couldn't find a test for
that code path, and writing my own seemed like overkill.

[1] https://www.spinics.net/lists/arm-kernel/msg865311.html

 arch/arm64/kvm/sys_regs.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

Comments

Marc Zyngier Jan. 15, 2021, 11:33 a.m. UTC | #1
On Wed, 6 Jan 2021 14:42:18 +0000, Alexandru Elisei wrote:
> The reg_to_encoding() macro is a wrapper over sys_reg() and conveniently
> takes a sys_reg_desc or a sys_reg_params argument and returns the 32 bit
> register encoding. Use it instead of calling sys_reg() directly.

Applied to next, thanks!

[1/1] KVM: arm64: Use the reg_to_encoding() macro instead of sys_reg()
      commit: 7ba8b4380afbdbb29d53c50bee6563cd7457fc34

Cheers,

	M.
diff mbox series

Patch

diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 00c119e8e8d3..048416c5636a 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -43,6 +43,10 @@ 
  * 64bit interface.
  */
 
+#define reg_to_encoding(x)						\
+	sys_reg((u32)(x)->Op0, (u32)(x)->Op1,				\
+		(u32)(x)->CRn, (u32)(x)->CRm, (u32)(x)->Op2)
+
 static bool read_from_write_only(struct kvm_vcpu *vcpu,
 				 struct sys_reg_params *params,
 				 const struct sys_reg_desc *r)
@@ -273,8 +277,7 @@  static bool trap_loregion(struct kvm_vcpu *vcpu,
 			  const struct sys_reg_desc *r)
 {
 	u64 val = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1);
-	u32 sr = sys_reg((u32)r->Op0, (u32)r->Op1,
-			 (u32)r->CRn, (u32)r->CRm, (u32)r->Op2);
+	u32 sr = reg_to_encoding(r);
 
 	if (!(val & (0xfUL << ID_AA64MMFR1_LOR_SHIFT))) {
 		kvm_inject_undefined(vcpu);
@@ -917,10 +920,6 @@  static bool access_pmuserenr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
 	return true;
 }
 
-#define reg_to_encoding(x)						\
-	sys_reg((u32)(x)->Op0, (u32)(x)->Op1,				\
-		(u32)(x)->CRn, (u32)(x)->CRm, (u32)(x)->Op2)
-
 /* Silly macro to expand the DBG{BCR,BVR,WVR,WCR}n_EL1 registers in one go */
 #define DBG_BCR_BVR_WCR_WVR_EL1(n)					\
 	{ SYS_DESC(SYS_DBGBVRn_EL1(n)),					\
@@ -1016,8 +1015,7 @@  static bool access_arch_timer(struct kvm_vcpu *vcpu,
 static u64 read_id_reg(const struct kvm_vcpu *vcpu,
 		struct sys_reg_desc const *r, bool raz)
 {
-	u32 id = sys_reg((u32)r->Op0, (u32)r->Op1,
-			 (u32)r->CRn, (u32)r->CRm, (u32)r->Op2);
+	u32 id = reg_to_encoding(r);
 	u64 val = raz ? 0 : read_sanitised_ftr_reg(id);
 
 	if (id == SYS_ID_AA64PFR0_EL1) {
@@ -1058,8 +1056,7 @@  static u64 read_id_reg(const struct kvm_vcpu *vcpu,
 static unsigned int id_visibility(const struct kvm_vcpu *vcpu,
 				  const struct sys_reg_desc *r)
 {
-	u32 id = sys_reg((u32)r->Op0, (u32)r->Op1,
-			 (u32)r->CRn, (u32)r->CRm, (u32)r->Op2);
+	u32 id = reg_to_encoding(r);
 
 	switch (id) {
 	case SYS_ID_AA64ZFR0_EL1: