Re: [syzbot] [kvm?] WARNING: locking bug in kvm_xen_set_evtchn_fast

From: Sebastian Andrzej Siewior
Date: Tue Nov 26 2024 - 10:04:15 EST


On 2024-11-26 14:49:40 [+0000], David Woodhouse wrote:
> On Tue, 2024-11-26 at 06:24 -0800, syzbot wrote:
> > syzbot has bisected this issue to:
> >
> > commit 560af5dc839eef08a273908f390cfefefb82aa04
> > Author: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
> > Date:   Wed Oct 9 15:45:03 2024 +0000
> >
> >     lockdep: Enable PROVE_RAW_LOCK_NESTING with PROVE_LOCKING.
>
> That's not it; this has always been broken with PREEMPT_RT I think.
> There was an attempt to fix it in
> https://lore.kernel.org/all/20240227115648.3104-8-dwmw2@xxxxxxxxxxxxx/
>
> I'll dust that off and try again.

Oh thank you. The timer has been made to always expire in hardirq due to
HRTIMER_MODE_ABS_HARD, this is why you see the splat. If the hardirq
invocation is needed/ possible then the callback needs to be updated.

The linked patch has this hunk:
|- read_lock_irqsave(&gpc->lock, flags);
|+ local_irq_save(flags);
|+ if (!read_trylock(&gpc->lock)) {

|+ if (in_interrupt())
|+ goto out;
|+
|+ read_lock(&gpc->lock);

This does not work. If interrupts are disabled (due to local_irq_save())
then read_lock() must not be used. in_interrupt() does not matter.

Side note: Using HRTIMER_MODE_ABS would avoid the splat at the cost that
on PREEMPT_RT the timer will be invoked in softirq context (as with
HRTIMER_MODE_ABS_SOFT on !PREEMPT_RT). There is no changed behaviour on
!PREEMPT_RT.

Sebastian