Skip to contentSkip to conversation

KVM: arm64: Add endian casting to kvm_swap_s[12]_desc()

PATCH Applied Marc Zyngier 2 participants 2 messages Nov 25, 2025

Subsystems (3)
lore
Share & tools
lore

Marc Zyngier

author maintainer
#0 lore raw

PATCH v2 1/1 KVM: arm64: Add endian casting to kvm_swap_s[12]_desc()

Keep sparse quiet by explicitly casting endianness conversion when swapping S1 and S2 descriptors.

Fixes c59ca4b5b0c3f ("KVM: arm64: Implement HW access flag management in stage-1 SW PTW")
Fixes 39db933ba67f8 ("KVM: arm64: nv: Implement HW access flag management in stage-2 SW PTW")

---

Notes:
Missed the S2 issue the first time, and only caught up with the robot's email.

 arch/arm64/kvm/at.c     | 8 ++++----
 arch/arm64/kvm/nested.c | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)
arch/arm64/kvm/at.c +4 -4
index f774a02d9393b..d25fef0f66e21 100644
@@ -386,11 +386,11 @@ static int kvm_swap_s1_desc(struct kvm_vcpu *vcpu, u64 pa, u64 old, u64 new,
 			    struct s1_walk_info *wi)
 {
 	if (wi->be) {
-		old = cpu_to_be64(old);
-		new = cpu_to_be64(new);
+		old = (__force u64)cpu_to_be64(old);
+		new = (__force u64)cpu_to_be64(new);
 	} else {
-		old = cpu_to_le64(old);
-		new = cpu_to_le64(new);
+		old = (__force u64)cpu_to_le64(old);
+		new = (__force u64)cpu_to_le64(new);
 	}
 
 	return __kvm_at_swap_desc(vcpu->kvm, pa, old, new);
arch/arm64/kvm/nested.c +4 -4
index c3033d1fe718c..cdeeb8f09e722 100644
@@ -224,11 +224,11 @@ static int swap_guest_s2_desc(struct kvm_vcpu *vcpu, phys_addr_t pa, u64 old, u6
 			      struct s2_walk_info *wi)
 {
 	if (wi->be) {
-		old = cpu_to_be64(old);
-		new = cpu_to_be64(new);
+		old = (__force u64)cpu_to_be64(old);
+		new = (__force u64)cpu_to_be64(new);
 	} else {
-		old = cpu_to_le64(old);
-		new = cpu_to_le64(new);
+		old = (__force u64)cpu_to_le64(old);
+		new = (__force u64)cpu_to_le64(new);
 	}
 
 	return __kvm_at_swap_desc(vcpu->kvm, pa, old, new);
Signature · 1 line
2.47.3