linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init()
@ 2024-12-13 14:57 Uros Bizjak
  2024-12-13 14:57 ` [PATCH 2/3] irqchip/gic: Correct declaration of *percpu_base pointer in union gic_base Uros Bizjak
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Uros Bizjak @ 2024-12-13 14:57 UTC (permalink / raw)
  To: linux-arm-kernel, kvmarm, linux-kernel
  Cc: Uros Bizjak, Marc Zyngier, Oliver Upton, Joey Gouly,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon

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;
-- 
2.42.0



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

* [PATCH 2/3] irqchip/gic: Correct declaration of *percpu_base pointer in union gic_base
  2024-12-13 14:57 [PATCH 1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init() Uros Bizjak
@ 2024-12-13 14:57 ` Uros Bizjak
  2024-12-13 17:05   ` Marc Zyngier
  2024-12-13 14:57 ` [PATCH 3/3] mailbox: zynqmp: Remove invalid __percpu annotation in zynqmp_ipi_probe() Uros Bizjak
  2024-12-13 17:15 ` [PATCH 1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init() Marc Zyngier
  2 siblings, 1 reply; 9+ messages in thread
From: Uros Bizjak @ 2024-12-13 14:57 UTC (permalink / raw)
  To: linux-arm-kernel, kvmarm, linux-kernel
  Cc: Uros Bizjak, Marc Zyngier, Thomas Gleixner

percpu_base is used in various percpu functions that expect variable in
__percpu address space. Correct the declaration of percpu_base to

void __iomem * __percpu *percpu_base;

to declare the variable as __percpu pointer.

The patch fixes several sparse warnings:

irq-gic.c:1172:44: warning: incorrect type in assignment (different address spaces)
irq-gic.c:1172:44:    expected void [noderef] __percpu *[noderef] __iomem *percpu_base
irq-gic.c:1172:44:    got void [noderef] __iomem *[noderef] __percpu *
...
irq-gic.c:1184:26: warning: incorrect type in initializer (different address spaces)
irq-gic.c:1184:26:    expected void const [noderef] __percpu *__vpp_verify
irq-gic.c:1184:26:    got void [noderef] __percpu *[noderef] __iomem *
...
irq-gic.c:1184:71: warning: incorrect type in assignment (different address spaces)
irq-gic.c:1184:71:    expected void [noderef] __percpu *
irq-gic.c:1184:71:    got void [noderef] __iomem *
...
irq-gic.c:1231:43: warning: incorrect type in argument 1 (different address spaces)
irq-gic.c:1231:43:    expected void [noderef] __percpu *__pdata
irq-gic.c:1231:43:    got void [noderef] __percpu *[noderef] __iomem *percpu_base

There were no changes in the resulting object files.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
---
 drivers/irqchip/irq-gic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
index 8fae6dc01024..6503573557fd 100644
--- a/drivers/irqchip/irq-gic.c
+++ b/drivers/irqchip/irq-gic.c
@@ -64,7 +64,7 @@ static void gic_check_cpu_features(void)
 
 union gic_base {
 	void __iomem *common_base;
-	void __percpu * __iomem *percpu_base;
+	void __iomem * __percpu *percpu_base;
 };
 
 struct gic_chip_data {
-- 
2.42.0



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

* [PATCH 3/3] mailbox: zynqmp: Remove invalid __percpu annotation in zynqmp_ipi_probe()
  2024-12-13 14:57 [PATCH 1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init() Uros Bizjak
  2024-12-13 14:57 ` [PATCH 2/3] irqchip/gic: Correct declaration of *percpu_base pointer in union gic_base Uros Bizjak
@ 2024-12-13 14:57 ` Uros Bizjak
  2024-12-13 15:05   ` Michal Simek
  2024-12-13 17:15 ` [PATCH 1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init() Marc Zyngier
  2 siblings, 1 reply; 9+ messages in thread
From: Uros Bizjak @ 2024-12-13 14:57 UTC (permalink / raw)
  To: linux-arm-kernel, kvmarm, linux-kernel
  Cc: Uros Bizjak, Jassi Brar, Michal Simek

struct zynqmp_ipi_pdata __percpu *pdata is not a per-cpu variable,
so it shoul not be annotated with __percpu annotation.

Remove invalid __percpu annotation to fix several

zynqmp-ipi-mailbox.c:920:15: warning: incorrect type in assignment (different address spaces)
zynqmp-ipi-mailbox.c:920:15:    expected struct zynqmp_ipi_pdata [noderef] __percpu *pdata
zynqmp-ipi-mailbox.c:920:15:    got void *
zynqmp-ipi-mailbox.c:927:56: warning: incorrect type in argument 3 (different address spaces)
zynqmp-ipi-mailbox.c:927:56:    expected unsigned int [usertype] *out_value
zynqmp-ipi-mailbox.c:927:56:    got unsigned int [noderef] __percpu *
...

and several

drivers/mailbox/zynqmp-ipi-mailbox.c:924:9: warning: dereference of noderef expression
...

sparse warnings.

There were no changes in the resulting object files.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Jassi Brar <jassisinghbrar@gmail.com>
Cc: Michal Simek <michal.simek@amd.com>
---
 drivers/mailbox/zynqmp-ipi-mailbox.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mailbox/zynqmp-ipi-mailbox.c b/drivers/mailbox/zynqmp-ipi-mailbox.c
index aa5249da59b2..0c143beaafda 100644
--- a/drivers/mailbox/zynqmp-ipi-mailbox.c
+++ b/drivers/mailbox/zynqmp-ipi-mailbox.c
@@ -905,7 +905,7 @@ static int zynqmp_ipi_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct device_node *nc, *np = pdev->dev.of_node;
-	struct zynqmp_ipi_pdata __percpu *pdata;
+	struct zynqmp_ipi_pdata *pdata;
 	struct of_phandle_args out_irq;
 	struct zynqmp_ipi_mbox *mbox;
 	int num_mboxes, ret = -EINVAL;
-- 
2.42.0



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

* Re: [PATCH 3/3] mailbox: zynqmp: Remove invalid __percpu annotation in zynqmp_ipi_probe()
  2024-12-13 14:57 ` [PATCH 3/3] mailbox: zynqmp: Remove invalid __percpu annotation in zynqmp_ipi_probe() Uros Bizjak
@ 2024-12-13 15:05   ` Michal Simek
  0 siblings, 0 replies; 9+ messages in thread
From: Michal Simek @ 2024-12-13 15:05 UTC (permalink / raw)
  To: Uros Bizjak, linux-arm-kernel, kvmarm, linux-kernel; +Cc: Jassi Brar



On 12/13/24 15:57, Uros Bizjak wrote:
> struct zynqmp_ipi_pdata __percpu *pdata is not a per-cpu variable,
> so it shoul not be annotated with __percpu annotation.

typo here.

> 
> Remove invalid __percpu annotation to fix several
> 
> zynqmp-ipi-mailbox.c:920:15: warning: incorrect type in assignment (different address spaces)
> zynqmp-ipi-mailbox.c:920:15:    expected struct zynqmp_ipi_pdata [noderef] __percpu *pdata
> zynqmp-ipi-mailbox.c:920:15:    got void *
> zynqmp-ipi-mailbox.c:927:56: warning: incorrect type in argument 3 (different address spaces)
> zynqmp-ipi-mailbox.c:927:56:    expected unsigned int [usertype] *out_value
> zynqmp-ipi-mailbox.c:927:56:    got unsigned int [noderef] __percpu *
> ...
> 
> and several
> 
> drivers/mailbox/zynqmp-ipi-mailbox.c:924:9: warning: dereference of noderef expression
> ...
> 
> sparse warnings.
> 
> There were no changes in the resulting object files.
> 
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> Cc: Jassi Brar <jassisinghbrar@gmail.com>
> Cc: Michal Simek <michal.simek@amd.com>
> ---
>   drivers/mailbox/zynqmp-ipi-mailbox.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mailbox/zynqmp-ipi-mailbox.c b/drivers/mailbox/zynqmp-ipi-mailbox.c
> index aa5249da59b2..0c143beaafda 100644
> --- a/drivers/mailbox/zynqmp-ipi-mailbox.c
> +++ b/drivers/mailbox/zynqmp-ipi-mailbox.c
> @@ -905,7 +905,7 @@ static int zynqmp_ipi_probe(struct platform_device *pdev)
>   {
>   	struct device *dev = &pdev->dev;
>   	struct device_node *nc, *np = pdev->dev.of_node;
> -	struct zynqmp_ipi_pdata __percpu *pdata;
> +	struct zynqmp_ipi_pdata *pdata;
>   	struct of_phandle_args out_irq;
>   	struct zynqmp_ipi_mbox *mbox;
>   	int num_mboxes, ret = -EINVAL;


Feel free to also find commit which introduced this issue and add
Fixes and cc: stable to v2.

Thanks,
Michal


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

* Re: [PATCH 2/3] irqchip/gic: Correct declaration of *percpu_base pointer in union gic_base
  2024-12-13 14:57 ` [PATCH 2/3] irqchip/gic: Correct declaration of *percpu_base pointer in union gic_base Uros Bizjak
@ 2024-12-13 17:05   ` Marc Zyngier
  0 siblings, 0 replies; 9+ messages in thread
From: Marc Zyngier @ 2024-12-13 17:05 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: linux-arm-kernel, kvmarm, linux-kernel, Thomas Gleixner

On Fri, 13 Dec 2024 14:57:53 +0000,
Uros Bizjak <ubizjak@gmail.com> wrote:
> 
> percpu_base is used in various percpu functions that expect variable in
> __percpu address space. Correct the declaration of percpu_base to
> 
> void __iomem * __percpu *percpu_base;
> 
> to declare the variable as __percpu pointer.
> 
> The patch fixes several sparse warnings:
> 
> irq-gic.c:1172:44: warning: incorrect type in assignment (different address spaces)
> irq-gic.c:1172:44:    expected void [noderef] __percpu *[noderef] __iomem *percpu_base
> irq-gic.c:1172:44:    got void [noderef] __iomem *[noderef] __percpu *
> ...
> irq-gic.c:1184:26: warning: incorrect type in initializer (different address spaces)
> irq-gic.c:1184:26:    expected void const [noderef] __percpu *__vpp_verify
> irq-gic.c:1184:26:    got void [noderef] __percpu *[noderef] __iomem *
> ...
> irq-gic.c:1184:71: warning: incorrect type in assignment (different address spaces)
> irq-gic.c:1184:71:    expected void [noderef] __percpu *
> irq-gic.c:1184:71:    got void [noderef] __iomem *
> ...
> irq-gic.c:1231:43: warning: incorrect type in argument 1 (different address spaces)
> irq-gic.c:1231:43:    expected void [noderef] __percpu *__pdata
> irq-gic.c:1231:43:    got void [noderef] __percpu *[noderef] __iomem *percpu_base
> 
> There were no changes in the resulting object files.
> 
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> Cc: Marc Zyngier <maz@kernel.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> ---
>  drivers/irqchip/irq-gic.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
> index 8fae6dc01024..6503573557fd 100644
> --- a/drivers/irqchip/irq-gic.c
> +++ b/drivers/irqchip/irq-gic.c
> @@ -64,7 +64,7 @@ static void gic_check_cpu_features(void)
>  
>  union gic_base {
>  	void __iomem *common_base;
> -	void __percpu * __iomem *percpu_base;
> +	void __iomem * __percpu *percpu_base;
>  };
>  
>  struct gic_chip_data {

Acked-by: Marc Zyngier <maz@kernel.org>

	M.

-- 
Without deviation from the norm, progress is not possible.


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

* Re: [PATCH 1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init()
  2024-12-13 14:57 [PATCH 1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init() Uros Bizjak
  2024-12-13 14:57 ` [PATCH 2/3] irqchip/gic: Correct declaration of *percpu_base pointer in union gic_base Uros Bizjak
  2024-12-13 14:57 ` [PATCH 3/3] mailbox: zynqmp: Remove invalid __percpu annotation in zynqmp_ipi_probe() Uros Bizjak
@ 2024-12-13 17:15 ` Marc Zyngier
  2024-12-16  7:37   ` Uros Bizjak
  2025-01-16 14:25   ` Uros Bizjak
  2 siblings, 2 replies; 9+ messages in thread
From: Marc Zyngier @ 2024-12-13 17:15 UTC (permalink / raw)
  To: Uros Bizjak
  Cc: linux-arm-kernel, kvmarm, linux-kernel, Oliver Upton, Joey Gouly,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon

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;

-- 
Without deviation from the norm, progress is not possible.


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

* Re: [PATCH 1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init()
  2024-12-13 17:15 ` [PATCH 1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init() Marc Zyngier
@ 2024-12-16  7:37   ` Uros Bizjak
  2025-01-16 14:25   ` Uros Bizjak
  1 sibling, 0 replies; 9+ messages in thread
From: Uros Bizjak @ 2024-12-16  7:37 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: linux-arm-kernel, kvmarm, linux-kernel, Oliver Upton, Joey Gouly,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon

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.


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

* Re: [PATCH 1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init()
  2024-12-13 17:15 ` [PATCH 1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init() Marc Zyngier
  2024-12-16  7:37   ` Uros Bizjak
@ 2025-01-16 14:25   ` Uros Bizjak
  2025-01-16 15:09     ` Marc Zyngier
  1 sibling, 1 reply; 9+ messages in thread
From: Uros Bizjak @ 2025-01-16 14:25 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: linux-arm-kernel, kvmarm, linux-kernel, Oliver Upton, Joey Gouly,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon

[-- Attachment #1: Type: text/plain, Size: 4254 bytes --]

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.

If this is the case, we can just remove dependence on the pointer in
the called function.

Something like in the attached patch.

Uros.

> 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;
>
> --
> Without deviation from the norm, progress is not possible.

[-- Attachment #2: arch_timer.diff.txt --]
[-- Type: text/plain, Size: 1255 bytes --]

diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
index 1215df590418..10c293c2d2f5 100644
--- a/arch/arm64/kvm/arch_timer.c
+++ b/arch/arm64/kvm/arch_timer.c
@@ -1238,12 +1238,10 @@ void kvm_arm_timer_write_sysreg(struct kvm_vcpu *vcpu,
 	}
 }
 
-static int timer_irq_set_vcpu_affinity(struct irq_data *d, void *vcpu)
+static int timer_irq_set_vcpu_affinity(struct irq_data *d,
+				       void __always_unused *vcpu)
 {
-	if (vcpu)
-		irqd_set_forwarded_to_vcpu(d);
-	else
-		irqd_clr_forwarded_to_vcpu(d);
+	irqd_set_forwarded_to_vcpu(d);
 
 	return 0;
 }
@@ -1391,8 +1389,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, NULL);
 		if (err) {
 			kvm_err("kvm_arch_timer: error setting vcpu affinity\n");
 			goto out_free_vtimer_irq;
@@ -1415,8 +1412,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, NULL);
 			if (err) {
 				kvm_err("kvm_arch_timer: error setting vcpu affinity\n");
 				goto out_free_ptimer_irq;

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

* Re: [PATCH 1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init()
  2025-01-16 14:25   ` Uros Bizjak
@ 2025-01-16 15:09     ` Marc Zyngier
  0 siblings, 0 replies; 9+ messages in thread
From: Marc Zyngier @ 2025-01-16 15:09 UTC (permalink / raw)
  To: Uros Bizjak
  Cc: linux-arm-kernel, kvmarm, linux-kernel, Oliver Upton, Joey Gouly,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon

On Thu, 16 Jan 2025 14:25:09 +0000,
Uros Bizjak <ubizjak@gmail.com> wrote:
> 
> 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.
> 
> If this is the case, we can just remove dependence on the pointer in
> the called function.

No, we can't.

> 
> Something like in the attached patch.

[...]

> diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
> index 1215df590418..10c293c2d2f5 100644
> --- a/arch/arm64/kvm/arch_timer.c
> +++ b/arch/arm64/kvm/arch_timer.c
> @@ -1238,12 +1238,10 @@ void kvm_arm_timer_write_sysreg(struct kvm_vcpu *vcpu,
>  	}
>  }
>  
> -static int timer_irq_set_vcpu_affinity(struct irq_data *d, void *vcpu)
> +static int timer_irq_set_vcpu_affinity(struct irq_data *d,
> +				       void __always_unused *vcpu)
>  {
> -	if (vcpu)
> -		irqd_set_forwarded_to_vcpu(d);
> -	else
> -		irqd_clr_forwarded_to_vcpu(d);
> +	irqd_set_forwarded_to_vcpu(d);
>  
>  	return 0;
>  }
> @@ -1391,8 +1389,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, NULL);
>  		if (err) {
>  			kvm_err("kvm_arch_timer: error setting vcpu affinity\n");
>  			goto out_free_vtimer_irq;
> @@ -1415,8 +1412,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, NULL);

And now you breaking everything by ignoring the semantics of
irq_set_vcpu_affinity(), which uses a NULL pointer to *stop* the
forwarding.

Congratulations, KVM doesn't work anymore, except on systems such as
the Apple stuff (which are the only systems requiring the
timer_irq_set_vcpu_affinity() hack). Just look at what the irqchips
are implementing to convince yourself.

	M.

-- 
Without deviation from the norm, progress is not possible.


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

end of thread, other threads:[~2025-01-16 15:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-13 14:57 [PATCH 1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init() Uros Bizjak
2024-12-13 14:57 ` [PATCH 2/3] irqchip/gic: Correct declaration of *percpu_base pointer in union gic_base Uros Bizjak
2024-12-13 17:05   ` Marc Zyngier
2024-12-13 14:57 ` [PATCH 3/3] mailbox: zynqmp: Remove invalid __percpu annotation in zynqmp_ipi_probe() Uros Bizjak
2024-12-13 15:05   ` Michal Simek
2024-12-13 17:15 ` [PATCH 1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init() Marc Zyngier
2024-12-16  7:37   ` Uros Bizjak
2025-01-16 14:25   ` Uros Bizjak
2025-01-16 15:09     ` Marc Zyngier

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).