From: Peter Zijlstra <peterz@infradead.org>
To: Juri Lelli <juri.lelli@redhat.com>
Cc: mingo@redhat.com, linux-kernel@vger.kernel.org,
vincent.guittot@linaro.org, rostedt@goodmis.org,
dietmar.eggemann@arm.com, bristot@redhat.com, bsegall@google.com,
mgorman@suse.de, Mark Simmons <msimmons@redhat.com>
Subject: Re: [PATCH v2] sched/rt: Fix double enqueue caused by rt_effective_prio
Date: Tue, 3 Aug 2021 16:56:11 +0200 [thread overview]
Message-ID: <YQlZCwcrEvuZ6f1n@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20210803104501.38333-1-juri.lelli@redhat.com>
On Tue, Aug 03, 2021 at 12:45:01PM +0200, Juri Lelli wrote:
> From: Peter Zijlstra <peterz@infradead.org>
>
> Double enqueues in rt runqueues (list) have been reported while running
> a simple test that spawns a number of threads doing a short sleep/run
> pattern while being concurrently setscheduled between rt and fair class.
>
> WARNING: CPU: 3 PID: 2825 at kernel/sched/rt.c:1294 enqueue_task_rt+0x355/0x360
> CPU: 3 PID: 2825 Comm: setsched__13
> RIP: 0010:enqueue_task_rt+0x355/0x360
> Call Trace:
> __sched_setscheduler+0x581/0x9d0
> _sched_setscheduler+0x63/0xa0
> do_sched_setscheduler+0xa0/0x150
> __x64_sys_sched_setscheduler+0x1a/0x30
> do_syscall_64+0x33/0x40
> entry_SYSCALL_64_after_hwframe+0x44/0xae
>
> list_add double add: new=ffff9867cb629b40, prev=ffff9867cb629b40,
> next=ffff98679fc67ca0.
> kernel BUG at lib/list_debug.c:31!
> invalid opcode: 0000 [#1] PREEMPT_RT SMP PTI
> CPU: 3 PID: 2825 Comm: setsched__13
> RIP: 0010:__list_add_valid+0x41/0x50
> Call Trace:
> enqueue_task_rt+0x291/0x360
> __sched_setscheduler+0x581/0x9d0
> _sched_setscheduler+0x63/0xa0
> do_sched_setscheduler+0xa0/0x150
> __x64_sys_sched_setscheduler+0x1a/0x30
> do_syscall_64+0x33/0x40
> entry_SYSCALL_64_after_hwframe+0x44/0xae
>
> __sched_setscheduler() uses rt_effective_prio() to handle proper queuing
> of priority boosted tasks that are setscheduled while being boosted.
> rt_effective_prio() is however called twice per each
> __sched_setscheduler() call: first directly by __sched_setscheduler()
> before dequeuing the task and then by __setscheduler() to actually do
> the priority change. If the priority of the pi_top_task is concurrently
> being changed however, it might happen that the two calls return
> different results. If, for example, the first call returned the same rt
> priority the task was running at and the second one a fair priority, the
> task won't be removed by the rt list (on_list still set) and then
> enqueued in the fair runqueue. When eventually setscheduled back to rt
> it will be seen as enqueued already and the WARNING/BUG be issued.
>
> Fix this by calling rt_effective_prio() only once and then reusing the
> return value. While at it refactor code as well for clarity. Concurrent
> priority inheritance handling is still safe and will eventually converge
> to a new state by following the inheritance chain(s).
>
> Fixes: 0782e63bc6fe ("sched: Handle priority boosted tasks proper in setscheduler()")
> Reported-by: Mark Simmons <msimmons@redhat.com>
> Signed-off-by: Peter Zijlstra <peterz@infradead.org>
> [squashed Peterz changes; added changelog]
> Signed-off-by: Juri Lelli <juri.lelli@redhat.com>
Thanks!
next prev parent reply other threads:[~2021-08-03 14:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-03 10:45 [PATCH v2] sched/rt: Fix double enqueue caused by rt_effective_prio Juri Lelli
2021-08-03 14:56 ` Peter Zijlstra [this message]
2021-08-05 9:34 ` [tip: sched/urgent] " tip-bot2 for Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YQlZCwcrEvuZ6f1n@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=msimmons@redhat.com \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).