linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] soc: fsl: dpio: protect smp_processor_id when get processor id
@ 2021-10-15  6:36 Meng.Li
  2021-10-15 13:39 ` Robin Murphy
  0 siblings, 1 reply; 3+ messages in thread
From: Meng.Li @ 2021-10-15  6:36 UTC (permalink / raw)
  To: Roy.Pledge, leoyang.li, ruxandra.radulescu, horia.geanta
  Cc: linux-kernel, linuxppc-dev, linux-arm-kernel, meng.li

From: Meng Li <meng.li@windriver.com>

When enable debug kernel configs,there will be calltrace as below:

BUG: using smp_processor_id() in preemptible [00000000] code: swapper/0/1
caller is debug_smp_processor_id+0x20/0x30
CPU: 6 PID: 1 Comm: swapper/0 Not tainted 5.10.63-yocto-standard #1
Hardware name: NXP Layerscape LX2160ARDB (DT)
Call trace:
 dump_backtrace+0x0/0x1a0
 show_stack+0x24/0x30
 dump_stack+0xf0/0x13c
 check_preemption_disabled+0x100/0x110
 debug_smp_processor_id+0x20/0x30
 dpaa2_io_query_fq_count+0xdc/0x154
 dpaa2_eth_stop+0x144/0x314
 __dev_close_many+0xdc/0x160
 __dev_change_flags+0xe8/0x220
 dev_change_flags+0x30/0x70
 ic_close_devs+0x50/0x78
 ip_auto_config+0xed0/0xf10
 do_one_initcall+0xac/0x460
 kernel_init_freeable+0x30c/0x378
 kernel_init+0x20/0x128
 ret_from_fork+0x10/0x38

Because smp_processor_id() should be invoked in preempt disable status.
So, add preempt_disable/enable() to protect smp_processor_id().

Fixes: c89105c9b390 ("staging: fsl-mc: Move DPIO from staging to drivers/soc/fsl")
Cc: stable@vger.kernel.org
Signed-off-by: Meng Li <Meng.Li@windriver.com>
---
 drivers/soc/fsl/dpio/dpio-service.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/soc/fsl/dpio/dpio-service.c b/drivers/soc/fsl/dpio/dpio-service.c
index 19f47ea9dab0..afc3b89b0fc5 100644
--- a/drivers/soc/fsl/dpio/dpio-service.c
+++ b/drivers/soc/fsl/dpio/dpio-service.c
@@ -58,8 +58,11 @@ static inline struct dpaa2_io *service_select_by_cpu(struct dpaa2_io *d,
 	 * If cpu == -1, choose the current cpu, with no guarantees about
 	 * potentially being migrated away.
 	 */
-	if (cpu < 0)
-		cpu = smp_processor_id();
+        if (cpu < 0) {
+                preempt_disable();
+                cpu = smp_processor_id();
+                preempt_enable();
+        }
 
 	/* If a specific cpu was requested, pick it up immediately */
 	return dpio_by_cpu[cpu];
-- 
2.17.1


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

* Re: [PATCH] soc: fsl: dpio: protect smp_processor_id when get processor id
  2021-10-15  6:36 [PATCH] soc: fsl: dpio: protect smp_processor_id when get processor id Meng.Li
@ 2021-10-15 13:39 ` Robin Murphy
  2021-10-15 16:37   ` Li, Meng
  0 siblings, 1 reply; 3+ messages in thread
From: Robin Murphy @ 2021-10-15 13:39 UTC (permalink / raw)
  To: Meng.Li, Roy.Pledge, leoyang.li, ruxandra.radulescu, horia.geanta
  Cc: linux-kernel, linuxppc-dev, linux-arm-kernel

On 2021-10-15 07:36, Meng.Li@windriver.com wrote:
> From: Meng Li <meng.li@windriver.com>
> 
> When enable debug kernel configs,there will be calltrace as below:
> 
> BUG: using smp_processor_id() in preemptible [00000000] code: swapper/0/1
> caller is debug_smp_processor_id+0x20/0x30
> CPU: 6 PID: 1 Comm: swapper/0 Not tainted 5.10.63-yocto-standard #1
> Hardware name: NXP Layerscape LX2160ARDB (DT)
> Call trace:
>   dump_backtrace+0x0/0x1a0
>   show_stack+0x24/0x30
>   dump_stack+0xf0/0x13c
>   check_preemption_disabled+0x100/0x110
>   debug_smp_processor_id+0x20/0x30
>   dpaa2_io_query_fq_count+0xdc/0x154
>   dpaa2_eth_stop+0x144/0x314
>   __dev_close_many+0xdc/0x160
>   __dev_change_flags+0xe8/0x220
>   dev_change_flags+0x30/0x70
>   ic_close_devs+0x50/0x78
>   ip_auto_config+0xed0/0xf10
>   do_one_initcall+0xac/0x460
>   kernel_init_freeable+0x30c/0x378
>   kernel_init+0x20/0x128
>   ret_from_fork+0x10/0x38
> 
> Because smp_processor_id() should be invoked in preempt disable status.
> So, add preempt_disable/enable() to protect smp_processor_id().

If preemption doesn't matter anyway, as the comment in the context 
implies, then it probably makes more sense just to use 
raw_smp_processor_id() instead.

Robin.

> Fixes: c89105c9b390 ("staging: fsl-mc: Move DPIO from staging to drivers/soc/fsl")
> Cc: stable@vger.kernel.org
> Signed-off-by: Meng Li <Meng.Li@windriver.com>
> ---
>   drivers/soc/fsl/dpio/dpio-service.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/soc/fsl/dpio/dpio-service.c b/drivers/soc/fsl/dpio/dpio-service.c
> index 19f47ea9dab0..afc3b89b0fc5 100644
> --- a/drivers/soc/fsl/dpio/dpio-service.c
> +++ b/drivers/soc/fsl/dpio/dpio-service.c
> @@ -58,8 +58,11 @@ static inline struct dpaa2_io *service_select_by_cpu(struct dpaa2_io *d,
>   	 * If cpu == -1, choose the current cpu, with no guarantees about
>   	 * potentially being migrated away.
>   	 */
> -	if (cpu < 0)
> -		cpu = smp_processor_id();
> +        if (cpu < 0) {
> +                preempt_disable();
> +                cpu = smp_processor_id();
> +                preempt_enable();
> +        }
>   
>   	/* If a specific cpu was requested, pick it up immediately */
>   	return dpio_by_cpu[cpu];
> 

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

* RE: [PATCH] soc: fsl: dpio: protect smp_processor_id when get processor id
  2021-10-15 13:39 ` Robin Murphy
@ 2021-10-15 16:37   ` Li, Meng
  0 siblings, 0 replies; 3+ messages in thread
From: Li, Meng @ 2021-10-15 16:37 UTC (permalink / raw)
  To: Robin Murphy, Roy.Pledge, leoyang.li, ruxandra.radulescu, horia.geanta
  Cc: linux-kernel, linuxppc-dev, linux-arm-kernel



> -----Original Message-----
> From: Robin Murphy <robin.murphy@arm.com>
> Sent: Friday, October 15, 2021 9:40 PM
> To: Li, Meng <Meng.Li@windriver.com>; Roy.Pledge@nxp.com;
> leoyang.li@nxp.com; ruxandra.radulescu@nxp.com; horia.geanta@nxp.com
> Cc: linux-kernel@vger.kernel.org; linuxppc-dev@lists.ozlabs.org; linux-arm-
> kernel@lists.infradead.org
> Subject: Re: [PATCH] soc: fsl: dpio: protect smp_processor_id when get
> processor id
> 
> [Please note: This e-mail is from an EXTERNAL e-mail address]
> 
> On 2021-10-15 07:36, Meng.Li@windriver.com wrote:
> > From: Meng Li <meng.li@windriver.com>
> >
> > When enable debug kernel configs,there will be calltrace as below:
> >
> > BUG: using smp_processor_id() in preemptible [00000000] code:
> > swapper/0/1 caller is debug_smp_processor_id+0x20/0x30
> > CPU: 6 PID: 1 Comm: swapper/0 Not tainted 5.10.63-yocto-standard #1
> > Hardware name: NXP Layerscape LX2160ARDB (DT) Call trace:
> >   dump_backtrace+0x0/0x1a0
> >   show_stack+0x24/0x30
> >   dump_stack+0xf0/0x13c
> >   check_preemption_disabled+0x100/0x110
> >   debug_smp_processor_id+0x20/0x30
> >   dpaa2_io_query_fq_count+0xdc/0x154
> >   dpaa2_eth_stop+0x144/0x314
> >   __dev_close_many+0xdc/0x160
> >   __dev_change_flags+0xe8/0x220
> >   dev_change_flags+0x30/0x70
> >   ic_close_devs+0x50/0x78
> >   ip_auto_config+0xed0/0xf10
> >   do_one_initcall+0xac/0x460
> >   kernel_init_freeable+0x30c/0x378
> >   kernel_init+0x20/0x128
> >   ret_from_fork+0x10/0x38
> >
> > Because smp_processor_id() should be invoked in preempt disable status.
> > So, add preempt_disable/enable() to protect smp_processor_id().
> 
> If preemption doesn't matter anyway, as the comment in the context implies,
> then it probably makes more sense just to use
> raw_smp_processor_id() instead.
> 

Thanks for your professional suggest, I will raw_smp_processor_id() and test.
If works fine, I will send v2 patch.

Thanks,
Limeng

> Robin.
> 
> > Fixes: c89105c9b390 ("staging: fsl-mc: Move DPIO from staging to
> > drivers/soc/fsl")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Meng Li <Meng.Li@windriver.com>
> > ---
> >   drivers/soc/fsl/dpio/dpio-service.c | 7 +++++--
> >   1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/soc/fsl/dpio/dpio-service.c
> > b/drivers/soc/fsl/dpio/dpio-service.c
> > index 19f47ea9dab0..afc3b89b0fc5 100644
> > --- a/drivers/soc/fsl/dpio/dpio-service.c
> > +++ b/drivers/soc/fsl/dpio/dpio-service.c
> > @@ -58,8 +58,11 @@ static inline struct dpaa2_io
> *service_select_by_cpu(struct dpaa2_io *d,
> >        * If cpu == -1, choose the current cpu, with no guarantees about
> >        * potentially being migrated away.
> >        */
> > -     if (cpu < 0)
> > -             cpu = smp_processor_id();
> > +        if (cpu < 0) {
> > +                preempt_disable();
> > +                cpu = smp_processor_id();
> > +                preempt_enable();
> > +        }
> >
> >       /* If a specific cpu was requested, pick it up immediately */
> >       return dpio_by_cpu[cpu];
> >

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

end of thread, other threads:[~2021-10-15 16:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-15  6:36 [PATCH] soc: fsl: dpio: protect smp_processor_id when get processor id Meng.Li
2021-10-15 13:39 ` Robin Murphy
2021-10-15 16:37   ` Li, Meng

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