[PATCH] sched: Use WARN_ON

Subsystems: cell broadband engine architecture, linux for powerpc (32-bit and 64-bit), spu file system, the rest

STALE1859d

3 messages, 3 authors, 2021-07-01 · open the first message on its own page

[PATCH] sched: Use WARN_ON

From: Jason Wang <hidden>
Date: 2021-07-01 12:51:43

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 <redacted>
---
 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


Re: [PATCH] sched: Use WARN_ON

From: Christophe Leroy <hidden>
Date: 2021-07-01 13:20:29


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

quoted hunk
Signed-off-by: Jason Wang <redacted>
---
  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;

Re: [PATCH] sched: Use WARN_ON

From: Arnd Bergmann <arnd@arndb.de>
Date: 2021-07-01 13:48:37

On Thu, Jul 1, 2021 at 2:57 PM Christophe Leroy
[off-list ref] wrote:
Le 01/07/2021 à 14:50, Jason Wang a écrit :
quoted
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help