linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [syzbot] [kernel?] WARNING in hrtimer_forward (2)
       [not found] <000000000000b77a880615a0ed2a@google.com>
@ 2024-04-09 10:46 ` Thomas Gleixner
  2024-04-09 22:51   ` Hillf Danton
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Gleixner @ 2024-04-09 10:46 UTC (permalink / raw)
  To: syzbot, anna-maria, frederic, linux-kernel, netdev,
	syzkaller-bugs
  Cc: Johannes Berg, Kalle Valo, linux-wireless

On Mon, Apr 08 2024 at 19:46, syzbot wrote:
> ------------[ cut here ]------------
> WARNING: CPU: 1 PID: 11239 at kernel/time/hrtimer.c:1053 hrtimer_forward+0x210/0x2d0 kernel/time/hrtimer.c:1053
> RIP: 0010:hrtimer_forward+0x210/0x2d0 kernel/time/hrtimer.c:1053
> Call Trace:
>  <IRQ>
>  hrtimer_forward_now include/linux/hrtimer.h:355 [inline]
>  mac80211_hwsim_beacon+0x192/0x1f0 drivers/net/wireless/virtual/mac80211_hwsim.c:2335
>  __run_hrtimer kernel/time/hrtimer.c:1692 [inline]
>  __hrtimer_run_queues+0x595/0xd00 kernel/time/hrtimer.c:1756
>  hrtimer_run_softirq+0x19a/0x2c0 kernel/time/hrtimer.c:1773
>  __do_softirq+0x2bc/0x943 kernel/softirq.c:554
>  invoke_softirq kernel/softirq.c:428 [inline]
>  __irq_exit_rcu+0xf2/0x1c0 kernel/softirq.c:633
>  irq_exit_rcu+0x9/0x30 kernel/softirq.c:645
>  instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1043 [inline]
>  sysvec_apic_timer_interrupt+0xa6/0xc0 arch/x86/kernel/apic/apic.c:1043
>  </IRQ>

The code which arms the timer is not serialized against the callback so
the following can happen:

    CPU1                        CPU2

    __run_hrtimer(timer)
                                if (!hrtimer_queued(timer))
                                        hrtimer_start(timer);

       hrtimer_forward(timer)
         WARN_ON(hrtimer_queued(timer)

This really wants to use hrtimer_active() which takes the running
callback into account.

Thanks,

        tglx

--- a/drivers/net/wireless/virtual/mac80211_hwsim.c
+++ b/drivers/net/wireless/virtual/mac80211_hwsim.c
@@ -2422,7 +2422,7 @@ static int mac80211_hwsim_config(struct
 
 		if (!data->started || !link_data->beacon_int) {
 			hrtimer_cancel(&link_data->beacon_timer);
-		} else if (!hrtimer_is_queued(&link_data->beacon_timer)) {
+		} else if (!hrtimer_is_active(&link_data->beacon_timer)) {
 			u64 tsf = mac80211_hwsim_get_tsf(hw, NULL);
 			u32 bcn_int = link_data->beacon_int;
 			u64 until_tbtt = bcn_int - do_div(tsf, bcn_int);
@@ -2517,7 +2517,7 @@ static void mac80211_hwsim_link_info_cha
 			  info->enable_beacon, info->beacon_int);
 		vp->bcn_en = info->enable_beacon;
 		if (data->started &&
-		    !hrtimer_is_queued(&link_data->beacon_timer) &&
+		    !hrtimer_is_active(&link_data->beacon_timer) &&
 		    info->enable_beacon) {
 			u64 tsf, until_tbtt;
 			u32 bcn_int;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [syzbot] [kernel?] WARNING in hrtimer_forward (2)
  2024-04-09 10:46 ` [syzbot] [kernel?] WARNING in hrtimer_forward (2) Thomas Gleixner
@ 2024-04-09 22:51   ` Hillf Danton
  0 siblings, 0 replies; 2+ messages in thread
From: Hillf Danton @ 2024-04-09 22:51 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: syzbot, linux-kernel, netdev, syzkaller-bugs, Johannes Berg,
	Kalle Valo, linux-wireless

On Tue, 09 Apr 2024 12:46:31 +0200 Thomas Gleixner <tglx@linutronix.de>
> On Mon, Apr 08 2024 at 19:46, syzbot wrote:
> > ------------[ cut here ]------------
> > WARNING: CPU: 1 PID: 11239 at kernel/time/hrtimer.c:1053 hrtimer_forward+0x210/0x2d0 kernel/time/hrtimer.c:1053
> > RIP: 0010:hrtimer_forward+0x210/0x2d0 kernel/time/hrtimer.c:1053
> > Call Trace:
> >  <IRQ>
> >  hrtimer_forward_now include/linux/hrtimer.h:355 [inline]
> >  mac80211_hwsim_beacon+0x192/0x1f0 drivers/net/wireless/virtual/mac80211_hwsim.c:2335
> >  __run_hrtimer kernel/time/hrtimer.c:1692 [inline]
> >  __hrtimer_run_queues+0x595/0xd00 kernel/time/hrtimer.c:1756
> >  hrtimer_run_softirq+0x19a/0x2c0 kernel/time/hrtimer.c:1773
> >  __do_softirq+0x2bc/0x943 kernel/softirq.c:554
> >  invoke_softirq kernel/softirq.c:428 [inline]
> >  __irq_exit_rcu+0xf2/0x1c0 kernel/softirq.c:633
> >  irq_exit_rcu+0x9/0x30 kernel/softirq.c:645
> >  instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1043 [inline]
> >  sysvec_apic_timer_interrupt+0xa6/0xc0 arch/x86/kernel/apic/apic.c:1043
> >  </IRQ>
> 
> The code which arms the timer is not serialized against the callback so
> the following can happen:
> 
>     CPU1                        CPU2
> 
>     __run_hrtimer(timer)
>                                 if (!hrtimer_queued(timer))
>                                         hrtimer_start(timer);
> 
>        hrtimer_forward(timer)
>          WARN_ON(hrtimer_queued(timer)
> 
> This really wants to use hrtimer_active() which takes the running
> callback into account.
> 
Then the race window is still open with hrtimer_active() and serialization
outside hrtimer is needed.

	CPU1				CPU2
	---				---
					if (!hrtimer_is_active(timer))
	if (!hrtimer_is_active(timer))
		hrtimer_start(timer);
	__run_hrtimer(timer)
						hrtimer_start(timer);
	hrtimer_forward(timer)
	  WARN_ON(hrtimer_queued(timer))

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-09 22:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <000000000000b77a880615a0ed2a@google.com>
2024-04-09 10:46 ` [syzbot] [kernel?] WARNING in hrtimer_forward (2) Thomas Gleixner
2024-04-09 22:51   ` Hillf Danton

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).