Message ID | 20241213145809.2918-1-ubizjak@gmail.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init() | expand |
On Fri, 13 Dec 2024 14:57:52 +0000, Uros Bizjak <ubizjak@gmail.com> wrote: > > Cast return value from kvm_get_running_vcpus() in the __percpu > address space to the generic address space via uintptr_t [1] > to fix a couple of: > > arch_timer.c:1395:66: warning: incorrect type in argument 2 (different address spaces) > arch_timer.c:1395:66: expected void *vcpu_info > arch_timer.c:1395:66: got struct kvm_vcpu *[noderef] __percpu * > > sparse warnings. > > There were no changes in the resulting object files. > > [1] https://sparse.docs.kernel.org/en/latest/annotations.html#address-space-name > > Signed-off-by: Uros Bizjak <ubizjak@gmail.com> > Cc: Marc Zyngier <maz@kernel.org> > Cc: Oliver Upton <oliver.upton@linux.dev> > Cc: Joey Gouly <joey.gouly@arm.com> > Cc: Suzuki K Poulose <suzuki.poulose@arm.com> > Cc: Zenghui Yu <yuzenghui@huawei.com> > Cc: Catalin Marinas <catalin.marinas@arm.com> > Cc: Will Deacon <will@kernel.org> > --- > arch/arm64/kvm/arch_timer.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c > index 1215df590418..a13bb9e8dc19 100644 > --- a/arch/arm64/kvm/arch_timer.c > +++ b/arch/arm64/kvm/arch_timer.c > @@ -1392,7 +1392,7 @@ int __init kvm_timer_hyp_init(bool has_gic) > > if (has_gic) { > err = irq_set_vcpu_affinity(host_vtimer_irq, > - kvm_get_running_vcpus()); > + (void *)(uintptr_t)kvm_get_running_vcpus()); > if (err) { > kvm_err("kvm_arch_timer: error setting vcpu affinity\n"); > goto out_free_vtimer_irq; > @@ -1416,7 +1416,7 @@ int __init kvm_timer_hyp_init(bool has_gic) > > if (has_gic) { > err = irq_set_vcpu_affinity(host_ptimer_irq, > - kvm_get_running_vcpus()); > + (void *)(uintptr_t)kvm_get_running_vcpus()); > if (err) { > kvm_err("kvm_arch_timer: error setting vcpu affinity\n"); > goto out_free_ptimer_irq; I think the fix is worse than the current code, because there is no real semantics behind the pointer being passed to irq_set_vcpu_affinity(). All that is required is that it is a non-NULL pointer. I expect the following hack to work just as well and not suffer from any sparse indigestion. Untested though. M. diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c index 1215df5904185..8058d92048fb4 100644 --- a/arch/arm64/kvm/arch_timer.c +++ b/arch/arm64/kvm/arch_timer.c @@ -1391,8 +1391,7 @@ int __init kvm_timer_hyp_init(bool has_gic) } if (has_gic) { - err = irq_set_vcpu_affinity(host_vtimer_irq, - kvm_get_running_vcpus()); + err = irq_set_vcpu_affinity(host_vtimer_irq, info); if (err) { kvm_err("kvm_arch_timer: error setting vcpu affinity\n"); goto out_free_vtimer_irq; @@ -1415,8 +1414,7 @@ int __init kvm_timer_hyp_init(bool has_gic) } if (has_gic) { - err = irq_set_vcpu_affinity(host_ptimer_irq, - kvm_get_running_vcpus()); + err = irq_set_vcpu_affinity(host_ptimer_irq, info); if (err) { kvm_err("kvm_arch_timer: error setting vcpu affinity\n"); goto out_free_ptimer_irq;
On Fri, Dec 13, 2024 at 6:15 PM Marc Zyngier <maz@kernel.org> wrote: > > On Fri, 13 Dec 2024 14:57:52 +0000, > Uros Bizjak <ubizjak@gmail.com> wrote: > > > > Cast return value from kvm_get_running_vcpus() in the __percpu > > address space to the generic address space via uintptr_t [1] > > to fix a couple of: > > > > arch_timer.c:1395:66: warning: incorrect type in argument 2 (different address spaces) > > arch_timer.c:1395:66: expected void *vcpu_info > > arch_timer.c:1395:66: got struct kvm_vcpu *[noderef] __percpu * > > > > sparse warnings. > > > > There were no changes in the resulting object files. > > > > [1] https://sparse.docs.kernel.org/en/latest/annotations.html#address-space-name > > > > Signed-off-by: Uros Bizjak <ubizjak@gmail.com> > > Cc: Marc Zyngier <maz@kernel.org> > > Cc: Oliver Upton <oliver.upton@linux.dev> > > Cc: Joey Gouly <joey.gouly@arm.com> > > Cc: Suzuki K Poulose <suzuki.poulose@arm.com> > > Cc: Zenghui Yu <yuzenghui@huawei.com> > > Cc: Catalin Marinas <catalin.marinas@arm.com> > > Cc: Will Deacon <will@kernel.org> > > --- > > arch/arm64/kvm/arch_timer.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c > > index 1215df590418..a13bb9e8dc19 100644 > > --- a/arch/arm64/kvm/arch_timer.c > > +++ b/arch/arm64/kvm/arch_timer.c > > @@ -1392,7 +1392,7 @@ int __init kvm_timer_hyp_init(bool has_gic) > > > > if (has_gic) { > > err = irq_set_vcpu_affinity(host_vtimer_irq, > > - kvm_get_running_vcpus()); > > + (void *)(uintptr_t)kvm_get_running_vcpus()); > > if (err) { > > kvm_err("kvm_arch_timer: error setting vcpu affinity\n"); > > goto out_free_vtimer_irq; > > @@ -1416,7 +1416,7 @@ int __init kvm_timer_hyp_init(bool has_gic) > > > > if (has_gic) { > > err = irq_set_vcpu_affinity(host_ptimer_irq, > > - kvm_get_running_vcpus()); > > + (void *)(uintptr_t)kvm_get_running_vcpus()); > > if (err) { > > kvm_err("kvm_arch_timer: error setting vcpu affinity\n"); > > goto out_free_ptimer_irq; > > I think the fix is worse than the current code, because there is no > real semantics behind the pointer being passed to > irq_set_vcpu_affinity(). All that is required is that it is a non-NULL > pointer. > > I expect the following hack to work just as well and not suffer from > any sparse indigestion. Untested though. The proposed hack also fixes sparse warnings and fixes my percpu checker errors, but as a functional change, I have no means of testing the proposed change on a target processor. So, I can just give: Acked-by: Uros Bizjak <ubizjak@gmail.com> from a percpu checker perspective. Thanks, Uros.
diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c index 1215df590418..a13bb9e8dc19 100644 --- a/arch/arm64/kvm/arch_timer.c +++ b/arch/arm64/kvm/arch_timer.c @@ -1392,7 +1392,7 @@ int __init kvm_timer_hyp_init(bool has_gic) if (has_gic) { err = irq_set_vcpu_affinity(host_vtimer_irq, - kvm_get_running_vcpus()); + (void *)(uintptr_t)kvm_get_running_vcpus()); if (err) { kvm_err("kvm_arch_timer: error setting vcpu affinity\n"); goto out_free_vtimer_irq; @@ -1416,7 +1416,7 @@ int __init kvm_timer_hyp_init(bool has_gic) if (has_gic) { err = irq_set_vcpu_affinity(host_ptimer_irq, - kvm_get_running_vcpus()); + (void *)(uintptr_t)kvm_get_running_vcpus()); if (err) { kvm_err("kvm_arch_timer: error setting vcpu affinity\n"); goto out_free_ptimer_irq;
Cast return value from kvm_get_running_vcpus() in the __percpu address space to the generic address space via uintptr_t [1] to fix a couple of: arch_timer.c:1395:66: warning: incorrect type in argument 2 (different address spaces) arch_timer.c:1395:66: expected void *vcpu_info arch_timer.c:1395:66: got struct kvm_vcpu *[noderef] __percpu * sparse warnings. There were no changes in the resulting object files. [1] https://sparse.docs.kernel.org/en/latest/annotations.html#address-space-name Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Cc: Marc Zyngier <maz@kernel.org> Cc: Oliver Upton <oliver.upton@linux.dev> Cc: Joey Gouly <joey.gouly@arm.com> Cc: Suzuki K Poulose <suzuki.poulose@arm.com> Cc: Zenghui Yu <yuzenghui@huawei.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will@kernel.org> --- arch/arm64/kvm/arch_timer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)