public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] KVM: arm64: fix u64_replace_bits() usage
@ 2025-07-11  7:27 Arnd Bergmann
  2025-07-11  8:02 ` Zenghui Yu
  2025-07-11  8:36 ` Marc Zyngier
  0 siblings, 2 replies; 6+ messages in thread
From: Arnd Bergmann @ 2025-07-11  7:27 UTC (permalink / raw)
  To: Marc Zyngier, Oliver Upton, Catalin Marinas, Will Deacon
  Cc: Arnd Bergmann, Joey Gouly, Suzuki K Poulose, Zenghui Yu,
	Mark Brown, James Morse, Sebastian Ott, linux-arm-kernel, kvmarm,
	linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

u64_replace_bits() returns a modified word but does not actually modify
its argument, as pointed out by this new warning:

arch/arm64/kvm/sys_regs.c: In function 'access_mdcr':
arch/arm64/kvm/sys_regs.c:2654:17: error: ignoring return value of 'u64_replace_bits' declared with attribute 'warn_unused_result' [-Werror=unused-result]
 2654 |                 u64_replace_bits(val, hpmn, MDCR_EL2_HPMN);

The intention here must have been to update 'val', so do that instead.

Fixes: efff9dd2fee7 ("KVM: arm64: Handle out-of-bound write to MDCR_EL2.HPMN")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/arm64/kvm/sys_regs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 33aa4f5071b8..793fb19bebd6 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -2651,7 +2651,7 @@ static bool access_mdcr(struct kvm_vcpu *vcpu,
 	 */
 	if (hpmn > vcpu->kvm->arch.nr_pmu_counters) {
 		hpmn = vcpu->kvm->arch.nr_pmu_counters;
-		u64_replace_bits(val, hpmn, MDCR_EL2_HPMN);
+		val = u64_replace_bits(val, hpmn, MDCR_EL2_HPMN);
 	}
 
 	__vcpu_assign_sys_reg(vcpu, MDCR_EL2, val);
-- 
2.39.5



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-07-11 11:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-11  7:27 [PATCH] KVM: arm64: fix u64_replace_bits() usage Arnd Bergmann
2025-07-11  8:02 ` Zenghui Yu
2025-07-11  8:36 ` Marc Zyngier
2025-07-11  8:44   ` Arnd Bergmann
2025-07-11  8:53     ` Marc Zyngier
2025-07-11  9:13       ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox