* [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
* Re: [PATCH] KVM: arm64: fix u64_replace_bits() usage
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
1 sibling, 0 replies; 6+ messages in thread
From: Zenghui Yu @ 2025-07-11 8:02 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Marc Zyngier, Oliver Upton, Catalin Marinas, Will Deacon,
Arnd Bergmann, Joey Gouly, Suzuki K Poulose, Mark Brown,
James Morse, Sebastian Ott, linux-arm-kernel, kvmarm,
linux-kernel
On 2025/7/11 15:27, Arnd Bergmann wrote:
> 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);
Already fixed by Ben's patch [*], thanks!
[*]
https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git/commit/?h=fixes&id=2265c08ec393ef1f5ef5019add0ab1e3a7ee0b79
Zenghui
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] KVM: arm64: fix u64_replace_bits() usage
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
1 sibling, 1 reply; 6+ messages in thread
From: Marc Zyngier @ 2025-07-11 8:36 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Oliver Upton, Catalin Marinas, Will Deacon, Arnd Bergmann,
Joey Gouly, Suzuki K Poulose, Zenghui Yu, Mark Brown, James Morse,
Sebastian Ott, linux-arm-kernel, kvmarm, linux-kernel
On Fri, 11 Jul 2025 08:27:47 +0100,
Arnd Bergmann <arnd@kernel.org> wrote:
>
> 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);
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/20250709093808.920284-2-ben.horgan@arm.com
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] KVM: arm64: fix u64_replace_bits() usage
2025-07-11 8:36 ` Marc Zyngier
@ 2025-07-11 8:44 ` Arnd Bergmann
2025-07-11 8:53 ` Marc Zyngier
0 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2025-07-11 8:44 UTC (permalink / raw)
To: Marc Zyngier, Arnd Bergmann
Cc: Oliver Upton, Catalin Marinas, Will Deacon, Joey Gouly,
Suzuki K Poulose, Zenghui Yu, Mark Brown, James Morse,
Sebastian Ott, linux-arm-kernel, kvmarm, linux-kernel
On Fri, Jul 11, 2025, at 10:36, Marc Zyngier wrote:
> On Fri, 11 Jul 2025 08:27:47 +0100, Arnd Bergmann <arnd@kernel.org> wrote:
>> 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].
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] KVM: arm64: fix u64_replace_bits() usage
2025-07-11 8:44 ` Arnd Bergmann
@ 2025-07-11 8:53 ` Marc Zyngier
2025-07-11 9:13 ` Mark Brown
0 siblings, 1 reply; 6+ messages in thread
From: Marc Zyngier @ 2025-07-11 8:53 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Arnd Bergmann, Oliver Upton, Catalin Marinas, Will Deacon,
Joey Gouly, Suzuki K Poulose, Zenghui Yu, Mark Brown, James Morse,
Sebastian Ott, linux-arm-kernel, kvmarm, linux-kernel
On Fri, 11 Jul 2025 09:44:23 +0100,
"Arnd Bergmann" <arnd@arndb.de> wrote:
>
> On Fri, Jul 11, 2025, at 10:36, Marc Zyngier wrote:
> > On Fri, 11 Jul 2025 08:27:47 +0100, Arnd Bergmann <arnd@kernel.org> wrote:
> >> 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].
>
> 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.
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/20250711084835.2411230-1-maz@kernel.org
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] KVM: arm64: fix u64_replace_bits() usage
2025-07-11 8:53 ` Marc Zyngier
@ 2025-07-11 9:13 ` Mark Brown
0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2025-07-11 9:13 UTC (permalink / raw)
To: Marc Zyngier
Cc: Arnd Bergmann, Arnd Bergmann, Oliver Upton, Catalin Marinas,
Will Deacon, Joey Gouly, Suzuki K Poulose, Zenghui Yu,
James Morse, Sebastian Ott, linux-arm-kernel, kvmarm,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 791 bytes --]
On Fri, Jul 11, 2025 at 09:53:41AM +0100, Marc Zyngier wrote:
> "Arnd Bergmann" <arnd@arndb.de> wrote:
> > 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.
> 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.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-07-11 9:13 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;
as well as URLs for NNTP newsgroup(s).