Re: WARNING in timer_wait_running

From: Frederic Weisbecker
Date: Fri Apr 07 2023 - 10:49:18 EST


On Fri, Apr 07, 2023 at 09:46:20PM +0800, Hillf Danton wrote:
> On 5 Apr 2023 23:07:24 +0200 Marco Elver <elver@xxxxxxxxxx>
> > On Mon, Aug 31, 2020 at 10:07AM -0700, syzbot wrote:
> > > Hello,
> > >
> > > syzbot found the following issue on:
> > >
> > > HEAD commit: 1127b219 Merge tag 'fallthrough-fixes-5.9-rc3' of git://gi..
> > > git tree: upstream
> > > console output: https://syzkaller.appspot.com/x/log.txt?x=1501768e900000
> > > kernel config: https://syzkaller.appspot.com/x/.config?x=978db74cb30aa994
> > > dashboard link: https://syzkaller.appspot.com/bug?extid=3b14b2ed9b3d06dcaa07
> >
> > Dashboard has recent reports (also below) and reproducer (also attached).
>
> My 2c, with PREEMPT_RT enabled it simply waits by taking timer->it_lock.
>
> --- upstream/kernel/time/posix-cpu-timers.c
> +++ y/kernel/time/posix-cpu-timers.c
> @@ -1613,6 +1613,21 @@ static int thread_cpu_timer_create(struc
> return posix_cpu_timer_create(timer);
> }
>
> +static void posix_cpu_timer_wait_running(struct k_itimer *timer)
> +{
> +#ifdef CONFIG_PREEMPT_RT
> + int stop = 0;
> +
> + while (!stop) {
> + spin_lock(&timer->it_lock);
> + stop = timer->it.cpu.firing == 0;
> + spin_unlock(&timer->it_lock);
> + }

No, because there is a whole lot of preemptible area with timer->it_lock
not held between the time ctmr->firing is set to 1, and the actual handling
of that timer that holds the lock.

So no priority inheritance in that case.

There has to be a lock between the time it is set to 1 and the handling
of the timer.