Skip to contentSkip to conversation

sched_ext: don't BUG_ON a destroyed DSQ in process_deferred_reenq_users

PATCH Superseded Tao Cui 2 participants 3 messages Aug 11 – Aug 15

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Tao Cui

author
#0 lore raw

PATCH 1/1 sched_ext: don't BUG_ON a destroyed DSQ in process_deferred_reenq_users

From: Tao Cui <[email protected]>

scx_bpf_dsq_reenq() queues a deferred reenq (dru) that runs from run_deferred(), not ops.dispatch(). If the DSQ is destroyed before the dru runs, process_deferred_reenq_users() sees dsq->id == SCX_DSQ_INVALID and hits the BUG_ON. destroy_dsq() doesn't flush pending drus, so just skip.

Fixes 84b1a0ea0b7c ("sched_ext: Implement scx_bpf_dsq_reenq() for user DSQs")
---
 kernel/sched/ext/ext.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched/ext/ext.c +3 -1
index 0bbe144c9811..604a05da41b9 100644
@@ -4531,7 +4531,9 @@ static void process_deferred_reenq_users(struct rq *rq)
 		/* see schedule_dsq_reenq() */
 		smp_mb();
 
-		BUG_ON(dsq->id & SCX_DSQ_FLAG_BUILTIN);
+		/* destroy_dsq() may race and invalidate @dsq; skip */
+		if (unlikely(dsq->id & SCX_DSQ_FLAG_BUILTIN))
+			continue;
 		reenq_user(rq, dsq, reenq_flags);
 	}
 }
Signature · 1 line
2.43.0
reviewer
#1 lore raw

Hello,

kernel/sched/ext/ext.c static void process_deferred_reenq_users(struct rq *rq) · line 4536

Quoted 4 lines · Tao Cui
kernel/sched/ext/ext.c +3 -1
-		BUG_ON(dsq->id & SCX_DSQ_FLAG_BUILTIN);
+		/* destroy_dsq() may race and invalidate @dsq; skip */
+		if (unlikely(dsq->id & SCX_DSQ_FLAG_BUILTIN))
+			continue;

Nice catch, but this also swallows states which can never occur legitimately. The only builtin-flagged value that can show up here is SCX_DSQ_INVALID from destroy_dsq(). Let's keep the BUG_ON for everything else:

	/* destroy_dsq() may have raced and invalidated @dsq, nothing to reenq */
	if (unlikely(dsq->id == SCX_DSQ_INVALID))
		continue;

	BUG_ON(dsq->id & SCX_DSQ_FLAG_BUILTIN);

Can you please spin v2? Also, please capitalize the subject after the prefix ("Don't ...") and remove the blank line between the tags.

Thanks.

--
tejun

author
#2 lore raw
Quoted 13 lines · Tejun Heo

Hello,

kernel/sched/ext/ext.c static void process_deferred_reenq_users(struct rq *rq) · line 4536

Quoted 4 lines · Tao Cui
kernel/sched/ext/ext.c +3 -1
-		BUG_ON(dsq->id & SCX_DSQ_FLAG_BUILTIN);
+		/* destroy_dsq() may race and invalidate @dsq; skip */
+		if (unlikely(dsq->id & SCX_DSQ_FLAG_BUILTIN))
+			continue;

Nice catch, but this also swallows states which can never occur legitimately. The only builtin-flagged value that can show up here is SCX_DSQ_INVALID from destroy_dsq(). Let's keep the BUG_ON for everything else:

Quoted 9 lines
	/* destroy_dsq() may have raced and invalidated @dsq, nothing to reenq */
	if (unlikely(dsq->id == SCX_DSQ_INVALID))
		continue;

	BUG_ON(dsq->id & SCX_DSQ_FLAG_BUILTIN);

Can you please spin v2? Also, please capitalize the subject after the prefix ("Don't ...") and remove the blank line between the tags.

Right, that was too broad. v2 skips only SCX_DSQ_INVALID and keeps the BUG_ON otherwise, as you suggested. Also fixed the subject capitalization and the blank line between the tags.

Thanks,
Tao

Quoted 4 lines

Thanks.

--
tejun