All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched: Use WARN_ON
@ 2021-07-01 12:50 ` Jason Wang
  0 siblings, 0 replies; 6+ messages in thread
From: Jason Wang @ 2021-07-01 12:50 UTC (permalink / raw)
  To: jk; +Cc: arnd, mpe, benh, paulus, linuxppc-dev, linux-kernel, Jason Wang

The BUG_ON macro simplifies the if condition followed by BUG, but it
will lead to the kernel crashing. Therefore, we can try using WARN_ON
instead of if condition followed by BUG.

Signed-off-by: Jason Wang <wangborong@cdjrlc.com>
---
 arch/powerpc/platforms/cell/spufs/sched.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/cell/spufs/sched.c b/arch/powerpc/platforms/cell/spufs/sched.c
index 369206489895..0f218d9e5733 100644
--- a/arch/powerpc/platforms/cell/spufs/sched.c
+++ b/arch/powerpc/platforms/cell/spufs/sched.c
@@ -904,8 +904,8 @@ static noinline void spusched_tick(struct spu_context *ctx)
 	struct spu_context *new = NULL;
 	struct spu *spu = NULL;
 
-	if (spu_acquire(ctx))
-		BUG();	/* a kernel thread never has signals pending */
+	/* a kernel thread never has signals pending */
+	WARN_ON(spu_acquire(ctx));
 
 	if (ctx->state != SPU_STATE_RUNNABLE)
 		goto out;
-- 
2.32.0




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

* [PATCH] sched: Use WARN_ON
@ 2021-07-01 12:50 ` Jason Wang
  0 siblings, 0 replies; 6+ messages in thread
From: Jason Wang @ 2021-07-01 12:50 UTC (permalink / raw)
  To: jk; +Cc: arnd, linux-kernel, Jason Wang, paulus, linuxppc-dev

The BUG_ON macro simplifies the if condition followed by BUG, but it
will lead to the kernel crashing. Therefore, we can try using WARN_ON
instead of if condition followed by BUG.

Signed-off-by: Jason Wang <wangborong@cdjrlc.com>
---
 arch/powerpc/platforms/cell/spufs/sched.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/cell/spufs/sched.c b/arch/powerpc/platforms/cell/spufs/sched.c
index 369206489895..0f218d9e5733 100644
--- a/arch/powerpc/platforms/cell/spufs/sched.c
+++ b/arch/powerpc/platforms/cell/spufs/sched.c
@@ -904,8 +904,8 @@ static noinline void spusched_tick(struct spu_context *ctx)
 	struct spu_context *new = NULL;
 	struct spu *spu = NULL;
 
-	if (spu_acquire(ctx))
-		BUG();	/* a kernel thread never has signals pending */
+	/* a kernel thread never has signals pending */
+	WARN_ON(spu_acquire(ctx));
 
 	if (ctx->state != SPU_STATE_RUNNABLE)
 		goto out;
-- 
2.32.0




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

* Re: [PATCH] sched: Use WARN_ON
  2021-07-01 12:50 ` Jason Wang
@ 2021-07-01 12:57   ` Christophe Leroy
  -1 siblings, 0 replies; 6+ messages in thread
From: Christophe Leroy @ 2021-07-01 12:57 UTC (permalink / raw)
  To: Jason Wang, jk; +Cc: arnd, linux-kernel, paulus, linuxppc-dev



Le 01/07/2021 à 14:50, Jason Wang a écrit :
> The BUG_ON macro simplifies the if condition followed by BUG, but it
> will lead to the kernel crashing. Therefore, we can try using WARN_ON
> instead of if condition followed by BUG.

But are you sure it is ok to continue if spu_acquire(ctx) returned false ?
Shouldn't there be at least for fallback handling ?

Something like:

	if (WARN_ON(spu_acquire(ctx)))
		return;


Christophe


> 
> Signed-off-by: Jason Wang <wangborong@cdjrlc.com>
> ---
>   arch/powerpc/platforms/cell/spufs/sched.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/cell/spufs/sched.c b/arch/powerpc/platforms/cell/spufs/sched.c
> index 369206489895..0f218d9e5733 100644
> --- a/arch/powerpc/platforms/cell/spufs/sched.c
> +++ b/arch/powerpc/platforms/cell/spufs/sched.c
> @@ -904,8 +904,8 @@ static noinline void spusched_tick(struct spu_context *ctx)
>   	struct spu_context *new = NULL;
>   	struct spu *spu = NULL;
>   
> -	if (spu_acquire(ctx))
> -		BUG();	/* a kernel thread never has signals pending */
> +	/* a kernel thread never has signals pending */
> +	WARN_ON(spu_acquire(ctx));
>   
>   	if (ctx->state != SPU_STATE_RUNNABLE)
>   		goto out;
> 

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

* Re: [PATCH] sched: Use WARN_ON
@ 2021-07-01 12:57   ` Christophe Leroy
  0 siblings, 0 replies; 6+ messages in thread
From: Christophe Leroy @ 2021-07-01 12:57 UTC (permalink / raw)
  To: Jason Wang, jk; +Cc: linuxppc-dev, paulus, linux-kernel, arnd



Le 01/07/2021 à 14:50, Jason Wang a écrit :
> The BUG_ON macro simplifies the if condition followed by BUG, but it
> will lead to the kernel crashing. Therefore, we can try using WARN_ON
> instead of if condition followed by BUG.

But are you sure it is ok to continue if spu_acquire(ctx) returned false ?
Shouldn't there be at least for fallback handling ?

Something like:

	if (WARN_ON(spu_acquire(ctx)))
		return;


Christophe


> 
> Signed-off-by: Jason Wang <wangborong@cdjrlc.com>
> ---
>   arch/powerpc/platforms/cell/spufs/sched.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/cell/spufs/sched.c b/arch/powerpc/platforms/cell/spufs/sched.c
> index 369206489895..0f218d9e5733 100644
> --- a/arch/powerpc/platforms/cell/spufs/sched.c
> +++ b/arch/powerpc/platforms/cell/spufs/sched.c
> @@ -904,8 +904,8 @@ static noinline void spusched_tick(struct spu_context *ctx)
>   	struct spu_context *new = NULL;
>   	struct spu *spu = NULL;
>   
> -	if (spu_acquire(ctx))
> -		BUG();	/* a kernel thread never has signals pending */
> +	/* a kernel thread never has signals pending */
> +	WARN_ON(spu_acquire(ctx));
>   
>   	if (ctx->state != SPU_STATE_RUNNABLE)
>   		goto out;
> 

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

* Re: [PATCH] sched: Use WARN_ON
  2021-07-01 12:57   ` Christophe Leroy
@ 2021-07-01 13:47     ` Arnd Bergmann
  -1 siblings, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2021-07-01 13:47 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Jason Wang, Jeremy Kerr, Linux Kernel Mailing List,
	Paul Mackerras, linuxppc-dev

On Thu, Jul 1, 2021 at 2:57 PM Christophe Leroy
<christophe.leroy@csgroup.eu> wrote:
> Le 01/07/2021 à 14:50, Jason Wang a écrit :
> > The BUG_ON macro simplifies the if condition followed by BUG, but it
> > will lead to the kernel crashing. Therefore, we can try using WARN_ON
> > instead of if condition followed by BUG.
>
> But are you sure it is ok to continue if spu_acquire(ctx) returned false ?
> Shouldn't there be at least for fallback handling ?
>
> Something like:
>
>         if (WARN_ON(spu_acquire(ctx)))
>                 return;

I think you get a crash in either case:

- with the existing BUG_ON() there is an immediate backtrace and it stops there
- with WARN_ON() and continuing, you operate on a context that is not
  valid
- with the 'return', you get an endless loop, as it keeps calling
spusched_tick()
  without sleeping.

Out of those options, the existing BUG_ON() seems best.

       Arnd

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

* Re: [PATCH] sched: Use WARN_ON
@ 2021-07-01 13:47     ` Arnd Bergmann
  0 siblings, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2021-07-01 13:47 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: linuxppc-dev, Paul Mackerras, Jeremy Kerr, Jason Wang,
	Linux Kernel Mailing List

On Thu, Jul 1, 2021 at 2:57 PM Christophe Leroy
<christophe.leroy@csgroup.eu> wrote:
> Le 01/07/2021 à 14:50, Jason Wang a écrit :
> > The BUG_ON macro simplifies the if condition followed by BUG, but it
> > will lead to the kernel crashing. Therefore, we can try using WARN_ON
> > instead of if condition followed by BUG.
>
> But are you sure it is ok to continue if spu_acquire(ctx) returned false ?
> Shouldn't there be at least for fallback handling ?
>
> Something like:
>
>         if (WARN_ON(spu_acquire(ctx)))
>                 return;

I think you get a crash in either case:

- with the existing BUG_ON() there is an immediate backtrace and it stops there
- with WARN_ON() and continuing, you operate on a context that is not
  valid
- with the 'return', you get an endless loop, as it keeps calling
spusched_tick()
  without sleeping.

Out of those options, the existing BUG_ON() seems best.

       Arnd

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

end of thread, other threads:[~2021-07-01 13:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-01 12:50 [PATCH] sched: Use WARN_ON Jason Wang
2021-07-01 12:50 ` Jason Wang
2021-07-01 12:57 ` Christophe Leroy
2021-07-01 12:57   ` Christophe Leroy
2021-07-01 13:47   ` Arnd Bergmann
2021-07-01 13:47     ` Arnd Bergmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.