KVM: arm64: fix u64_replace_bits() usage
PATCH 1/1 KVM: arm64: fix u64_replace_bits() usage
From: Arnd Bergmann <[email protected]>
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.
--- arch/arm64/kvm/sys_regs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/sys_regs.c +1 -1
@@ -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);
Signature · 1 line
2.39.5
Zenghui Yu
reviewerQuoted 22 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
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 <[email protected]>--- arch/arm64/kvm/sys_regs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kvm/sys_regs.c +0
-0
arch/arm64/kvm/sys_regs.c static bool access_mdcr(struct kvm_vcpu *vcpu, · line 2657
Quoted 8 lines
arch/arm64/kvm/sys_regs.c +1
-1@@ -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);
Already fixed by Ben's patch [*], thanks!
Zenghui
Marc Zyngier
maintainerQuoted 23 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
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 <[email protected]>--- arch/arm64/kvm/sys_regs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kvm/sys_regs.c +0
-0
arch/arm64/kvm/sys_regs.c static bool access_mdcr(struct kvm_vcpu *vcpu, · line 2657
Quoted 8 lines
arch/arm64/kvm/sys_regs.c +1
-1@@ -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);
This is only in -next, right? Because I have a fix for this already queued for 6.16, as per [1].
Thanks,
M.
[1] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Without deviation from the norm, progress is not possible.
Quoted 11 lines · Marc Zyngier
arch/arm64/kvm/sys_regs.c static bool access_mdcr(struct kvm_vcpu *vcpu, · line 2657
Quoted 7 lines · Arnd Bergmann
arch/arm64/kvm/sys_regs.c +1
-1if (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);This is only in -next, right? Because I have a fix for this already queued for 6.16, as per [1].
Yes, as far as I can tell, the warning only showed up in linux-next after f66f9c3d09c1 ("bitfield: Ensure the return values of helper functions are checked").
As far as I can tell, Ben added the check in linux/bitfield.h when he sent you his version of the fix, they just ended up in linux-next in the wrong order, so I ended up recreating his original fix slightly differently.
Arnd
Marc Zyngier
maintainerQuoted 14 lines · Arnd Bergmann
Quoted 11 lines · Marc Zyngier
arch/arm64/kvm/sys_regs.c static bool access_mdcr(struct kvm_vcpu *vcpu, · line 2657
Quoted 7 lines · Arnd Bergmann
arch/arm64/kvm/sys_regs.c +1
-1if (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);This is only in -next, right? Because I have a fix for this already queued for 6.16, as per [1].
Quoted 8 lines
Yes, as far as I can tell, the warning only showed up in linux-next after
f66f9c3d09c1("bitfield: Ensure the return values of helper functions are checked").As far as I can tell, Ben added the check in
linux/bitfield.hwhen he sent you his version of the fix, they just ended up in linux-next in the wrong order, so I ended up recreating his original fix slightly differently.
I don't think Ben's fix is in -next, as I queued it in the kvmarm fixes branch, which isn't pulled by -next.
Hopefully Paolo will send this to Linus shortly (pull request here[1]), and -next will be clean again.
Thanks,
M.
[1] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Without deviation from the norm, progress is not possible.
Quoted 6 lines · Marc Zyngier
Quoted 3 lines · Arnd Bergmann
Yes, as far as I can tell, the warning only showed up in linux-next after
f66f9c3d09c1("bitfield: Ensure the return values of helper functions are checked").
Quoted 7 lines
Quoted 4 lines
As far as I can tell, Ben added the check in
linux/bitfield.hwhen he sent you his version of the fix, they just ended up in linux-next in the wrong order, so I ended up recreating his original fix slightly differently.I don't think Ben's fix is in -next, as I queued it in the kvmarm fixes branch, which isn't pulled by -next.
We should really get that added to -next, that'll ensure it gets covered in the pending-fixes testing coverage and avoid issues like this with the main -next tree.