Skip to contentSkip to conversation

Suspicious RCU usage in mac80211

DISCUSSION Larry Finger 5 participants 25 messages Apr 10, 2012 – May 4, 2012 mac80211

lore
Share & tools
lore
#0 lore raw

When running kernel 3.4-rc2 from wireless testing, I got the following logged:

[ 2299.344437] ===============================
[ 2299.344443] [ INFO: suspicious RCU usage. ]
[ 2299.344452] 3.4.0-rc2-wl+ #222 Not tainted
[ 2299.344458] -------------------------------
[ 2299.344466] net/mac80211/sta_info.h:449 suspicious rcu_dereference_protected() usage!
[ 2299.344472]
[ 2299.344474] other info that might help us debug this:
[ 2299.344477]
[ 2299.344484]
[ 2299.344486] rcu_scheduler_active = 1, debug_locks = 0
[ 2299.344493] 1 lock held by swapper/1/0:
[ 2299.344499]  #0:  (&tid_tx->session_timer){+.-...}, at: [<ffffffff8104850a>] run_timer_softirq+0xfa/0x6e0
[ 2299.344533]
[ 2299.344535] stack backtrace:
[ 2299.344544] Pid: 0, comm: swapper/1 Not tainted 3.4.0-rc2-wl+ #222
[ 2299.344551] Call Trace:
[ 2299.344557]  <IRQ>  [<ffffffff81092fdd>] lockdep_rcu_suspicious+0xfd/0x130
[ 2299.344651]  [<ffffffffa05db673>] sta_tx_agg_session_timer_expired+0xe3/0x100 [mac80211]
[ 2299.344664]  [<ffffffff81048595>] run_timer_softirq+0x185/0x6e0
[ 2299.344676]  [<ffffffff8104850a>] ? run_timer_softirq+0xfa/0x6e0
[ 2299.344714]  [<ffffffffa05db590>] ? ieee80211_stop_tx_ba_session+0x240/0x240 [mac80211]
[ 2299.344732]  [<ffffffff81040156>] __do_softirq+0xc6/0x3f0
[ 2299.344748]  [<ffffffff8139c934>] ? _raw_spin_lock+0x44/0x50
[ 2299.344758]  [<ffffffff8139d0f6>] ? _raw_spin_unlock+0x26/0x40
[ 2299.344771]  [<ffffffff8139f24c>] call_softirq+0x1c/0x30
[ 2299.344785]  [<ffffffff81004785>] do_softirq+0x85/0xc0
[ 2299.344795]  [<ffffffff810407b6>] irq_exit+0xa6/0xe0
[ 2299.344806]  [<ffffffff8100424e>] do_IRQ+0x5e/0xd0
[ 2299.344816]  [<ffffffff8139d56c>] common_interrupt+0x6c/0x6c
[ 2299.344823]  <EOI>  [<ffffffff8100c042>] ? default_idle+0x62/0x4f0
[ 2299.344844]  [<ffffffff8100c040>] ? default_idle+0x60/0x4f0
[ 2299.344854]  [<ffffffff8100c524>] amd_e400_idle+0x54/0x100
[ 2299.344864]  [<ffffffff8100ce96>] cpu_idle+0x96/0xe0
[ 2299.344875]  [<ffffffff8138fbc6>] start_secondary+0x1b7/0x1bb

The wireless driver in use was rtl8192ce.

Larry

maintainer
#1 lore raw
Quoted 21 lines · Larry Finger

When running kernel 3.4-rc2 from wireless testing, I got the following logged:

[ 2299.344437] ===============================
[ 2299.344443] [ INFO: suspicious RCU usage. ]
[ 2299.344452] 3.4.0-rc2-wl+ #222 Not tainted
[ 2299.344458] -------------------------------
[ 2299.344466] net/mac80211/sta_info.h:449 suspicious rcu_dereference_protected() usage!
[ 2299.344472]
[ 2299.344474] other info that might help us debug this:
[ 2299.344477]
[ 2299.344484]
[ 2299.344486] rcu_scheduler_active = 1, debug_locks = 0
[ 2299.344493] 1 lock held by swapper/1/0:
[ 2299.344499]  #0:  (&tid_tx->session_timer){+.-...}, at: [<ffffffff8104850a>] 
run_timer_softirq+0xfa/0x6e0
[ 2299.344533]
[ 2299.344535] stack backtrace:
[ 2299.344544] Pid: 0, comm: swapper/1 Not tainted 3.4.0-rc2-wl+ #222
[ 2299.344551] Call Trace:
[ 2299.344557]  <IRQ>  [<ffffffff81092fdd>] lockdep_rcu_suspicious+0xfd/0x130
[ 2299.344651]  [<ffffffffa05db673>] sta_tx_agg_session_timer_expired+0xe3/0x100 
Quoted 1 line

[mac80211]

That's odd:

static inline struct tid_ampdu_tx * rcu_dereference_protected_tid_tx(struct sta_info *sta, int tid)

{
        return rcu_dereference_protected(sta->ampdu_mlme.tid_tx[tid],
                                         lockdep_is_held(&sta->lock) ||
                                         lockdep_is_held(&sta->ampdu_mlme.mtx));
} 

sta_tx_agg_session_timer_expired calls ieee80211_stop_tx_ba_session which does:

        spin_lock_bh(&sta->lock);
        tid_tx = rcu_dereference_protected_tid_tx(sta, tid);

So why would the message happen? Strange.

johannes

#2 lore raw
Quoted 34 lines · Johannes Berg
Quoted 21 lines · Larry Finger

When running kernel 3.4-rc2 from wireless testing, I got the following logged:

[ 2299.344437] ===============================
[ 2299.344443] [ INFO: suspicious RCU usage. ]
[ 2299.344452] 3.4.0-rc2-wl+ #222 Not tainted
[ 2299.344458] -------------------------------
[ 2299.344466] net/mac80211/sta_info.h:449 suspicious rcu_dereference_protected() usage!
[ 2299.344472]
[ 2299.344474] other info that might help us debug this:
[ 2299.344477]
[ 2299.344484]
[ 2299.344486] rcu_scheduler_active = 1, debug_locks = 0
[ 2299.344493] 1 lock held by swapper/1/0:
[ 2299.344499]  #0:  (&tid_tx->session_timer){+.-...}, at: [<ffffffff8104850a>]
run_timer_softirq+0xfa/0x6e0
[ 2299.344533]
[ 2299.344535] stack backtrace:
[ 2299.344544] Pid: 0, comm: swapper/1 Not tainted 3.4.0-rc2-wl+ #222
[ 2299.344551] Call Trace:
[ 2299.344557]<IRQ>   [<ffffffff81092fdd>] lockdep_rcu_suspicious+0xfd/0x130
[ 2299.344651]  [<ffffffffa05db673>] sta_tx_agg_session_timer_expired+0xe3/0x100
Quoted 1 line

[mac80211]

That's odd:

static inline struct tid_ampdu_tx * rcu_dereference_protected_tid_tx(struct sta_info *sta, int tid)

{
         return rcu_dereference_protected(sta->ampdu_mlme.tid_tx[tid],
                                          lockdep_is_held(&sta->lock) ||
                                          lockdep_is_held(&sta->ampdu_mlme.mtx));
}
Quoted 8 lines

sta_tx_agg_session_timer_expired calls ieee80211_stop_tx_ba_session which does:

         spin_lock_bh(&sta->lock);
         tid_tx = rcu_dereference_protected_tid_tx(sta, tid);

So why would the message happen? Strange.

When I first saw the thread at http://lkml.indiana.edu/hypermail/linux/kernel/1204.1/01446.html, I thought it might be about the same problem, but that appears to be restricted to sparc64.

The problem does not happen every time - even more strangeness.

Larry

maintainer
#3 lore raw
Quoted 42 lines · Larry Finger
Quoted 41 lines · Johannes Berg
Quoted 21 lines · Larry Finger

When running kernel 3.4-rc2 from wireless testing, I got the following logged:

[ 2299.344437] ===============================
[ 2299.344443] [ INFO: suspicious RCU usage. ]
[ 2299.344452] 3.4.0-rc2-wl+ #222 Not tainted
[ 2299.344458] -------------------------------
[ 2299.344466] net/mac80211/sta_info.h:449 suspicious rcu_dereference_protected() usage!
[ 2299.344472]
[ 2299.344474] other info that might help us debug this:
[ 2299.344477]
[ 2299.344484]
[ 2299.344486] rcu_scheduler_active = 1, debug_locks = 0
[ 2299.344493] 1 lock held by swapper/1/0:
[ 2299.344499]  #0:  (&tid_tx->session_timer){+.-...}, at: [<ffffffff8104850a>]
run_timer_softirq+0xfa/0x6e0
[ 2299.344533]
[ 2299.344535] stack backtrace:
[ 2299.344544] Pid: 0, comm: swapper/1 Not tainted 3.4.0-rc2-wl+ #222
[ 2299.344551] Call Trace:
[ 2299.344557]<IRQ>   [<ffffffff81092fdd>] lockdep_rcu_suspicious+0xfd/0x130
[ 2299.344651]  [<ffffffffa05db673>] sta_tx_agg_session_timer_expired+0xe3/0x100
Quoted 1 line

[mac80211]

That's odd:

static inline struct tid_ampdu_tx * rcu_dereference_protected_tid_tx(struct sta_info *sta, int tid)

{
         return rcu_dereference_protected(sta->ampdu_mlme.tid_tx[tid],
                                          lockdep_is_held(&sta->lock) ||
                                          lockdep_is_held(&sta->ampdu_mlme.mtx));
}

sta_tx_agg_session_timer_expired calls ieee80211_stop_tx_ba_session which does:

         spin_lock_bh(&sta->lock);
         tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
Quoted 7 lines
Quoted 1 line

So why would the message happen? Strange.

When I first saw the thread at
http://lkml.indiana.edu/hypermail/linux/kernel/1204.1/01446.html, I thought it might be about the same problem, but that appears to be restricted to sparc64.

The problem does not happen every time - even more strangeness.

What do you mean by "every time"? I wouldn't expect the timer to fire every time you set up aggregation etc., the timer firing is a special case to start with.

johannes

#4 lore raw
Quoted 4 lines · Johannes Berg

What do you mean by "every time"? I wouldn't expect the timer to fire every time you set up aggregation etc., the timer firing is a special case to start with.

I meant it is intermittent, or it required some special setup that I have not duplicated, as I have seen the condition only once.

Larry

maintainer
#5 lore raw
Quoted 8 lines · Larry Finger
Quoted 4 lines · Johannes Berg

What do you mean by "every time"? I wouldn't expect the timer to fire every time you set up aggregation etc., the timer firing is a special case to start with.

I meant it is intermittent, or it required some special setup that I have not duplicated, as I have seen the condition only once.

Ok. I suspect that's explained by the fact that the timer is an error case anyway, so you've probably never seen that error case again. It's still puzzling though since the code looks fine to me.

johannes

#6 lore raw

hi Johannes and Larry,

Quoted 14 lines · Johannes Berg
Quoted 8 lines · Larry Finger
Quoted 4 lines · Johannes Berg

What do you mean by "every time"? I wouldn't expect the timer to fire every time you set up aggregation etc., the timer firing is a special case to start with.

I meant it is intermittent, or it required some special setup that I have not duplicated, as I have seen the condition only once.

Ok. I suspect that's explained by the fact that the timer is an error case anyway, so you've probably never seen that error case again. It's still puzzling though since the code looks fine to me.

Quoted 6 lines

johannes

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

May  1 14:34:51 shafi-laptop kernel: [   83.216284]
===============================
May  1 14:34:51 shafi-laptop kernel: [   83.216286] [ INFO: suspicious
RCU usage. ]
May  1 14:34:51 shafi-laptop kernel: [   83.216289] 3.4.0-rc3-wl #16 Not tainted
May  1 14:34:51 shafi-laptop kernel: [   83.216291]
-------------------------------
May  1 14:34:51 shafi-laptop kernel: [   83.216293]
net/mac80211/sta_info.h:456 suspicious rcu_dereference_protected()
usage!
May  1 14:34:51 shafi-laptop kernel: [   83.216295]
May  1 14:34:51 shafi-laptop kernel: [   83.216296] other info that
might help us debug this:
May  1 14:34:51 shafi-laptop kernel: [   83.216297]
May  1 14:34:51 shafi-laptop kernel: [   83.216299]
May  1 14:34:51 shafi-laptop kernel: [   83.216299]
rcu_scheduler_active = 1, debug_locks = 1
May  1 14:34:51 shafi-laptop kernel: [   83.216302] 2 locks held by kmemleak/52:
May  1 14:34:51 shafi-laptop kernel: [   83.216303]  #0:
(scan_mutex){+.+...}, at: [<c024d343>] kmemleak_scan_thread+0x53/0xc0
May  1 14:34:51 shafi-laptop kernel: [   83.216313]  #1:
(&tid_tx->session_timer){+.-...}, at: [<c0144fdf>]
run_timer_softirq+0xcf/0x400
May  1 14:34:51 shafi-laptop kernel: [   83.216321]
May  1 14:34:51 shafi-laptop kernel: [   83.216322] stack backtrace:
May  1 14:34:51 shafi-laptop kernel: [   83.216325] Pid: 52, comm:
kmemleak Not tainted 3.4.0-rc3-wl #16
May  1 14:34:51 shafi-laptop kernel: [   83.216327] Call Trace:
May  1 14:34:51 shafi-laptop kernel: [   83.216332]  [<c0191726>]
lockdep_rcu_suspicious+0xc6/0x100
May  1 14:34:51 shafi-laptop kernel: [   83.216351]  [<f835b14d>]
sta_tx_agg_session_timer_expired+0xcd/0x100 [mac80211]
May  1 14:34:51 shafi-laptop kernel: [   83.216355]  [<c014506d>]
run_timer_softirq+0x15d/0x400
May  1 14:34:51 shafi-laptop kernel: [   83.216358]  [<c0144fdf>] ?
run_timer_softirq+0xcf/0x400
May  1 14:34:51 shafi-laptop kernel: [   83.216373]  [<f835b080>] ?
sta_addba_resp_timer_expired+0x240/0x240 [mac80211]
May  1 14:34:51 shafi-laptop kernel: [   83.216380]  [<c013d56f>]
__do_softirq+0xaf/0x310
May  1 14:34:51 shafi-laptop kernel: [   83.216384]  [<c013d4c0>] ?
__hrtimer_tasklet_trampoline+0x20/0x20
May  1 14:34:51 shafi-laptop kernel: [   83.216386]  <IRQ>
[<c013cc65>] ? irq_exit+0xb5/0xd0
May  1 14:34:51 shafi-laptop kernel: [   83.216393]  [<c06b74a9>] ?
smp_apic_timer_interrupt+0x59/0x88
May  1 14:34:51 shafi-laptop kernel: [   83.216398]  [<c03d8edc>] ?
trace_hardirqs_off_thunk+0xc/0x10
May  1 14:34:51 shafi-laptop kernel: [   83.216402]  [<c06afc36>] ?
apic_timer_interrupt+0x36/0x40
May  1 14:34:51 shafi-laptop kernel: [   83.216405]  [<c019007b>] ?
rcu_read_lock_sched_held+0x1b/0x70
May  1 14:34:51 shafi-laptop kernel: [   83.216409]  [<c06af58e>] ?
_raw_spin_unlock_irqrestore+0x3e/0x70
May  1 14:34:51 shafi-laptop kernel: [   83.216412]  [<c024bf4b>] ?
scan_gray_list+0x12b/0x180
May  1 14:34:51 shafi-laptop kernel: [   83.216415]  [<c024c815>] ?
kmemleak_scan+0x235/0x8c0
May  1 14:34:51 shafi-laptop kernel: [   83.216418]  [<c024c5e0>] ?
kmemleak_seq_next+0x130/0x130
May  1 14:34:51 shafi-laptop kernel: [   83.216422]  [<c024d2f0>] ?
kmemleak_write+0x450/0x450
May  1 14:34:51 shafi-laptop kernel: [   83.216425]  [<c024d2f0>] ?
kmemleak_write+0x450/0x450
May  1 14:34:51 shafi-laptop kernel: [   83.216428]  [<c024d348>] ?
kmemleak_scan_thread+0x58/0xc0
May  1 14:34:51 shafi-laptop kernel: [   83.216431]  [<c01590a4>] ?
kthread+0x84/0x90
May  1 14:34:51 shafi-laptop kernel: [   83.216435]  [<c0159020>] ?
__init_kthread_worker+0x60/0x60
May  1 14:34:51 shafi-laptop kernel: [   83.216438]  [<c06b7306>] ?
kernel_thread_helper+0x6/0x10
May  1 14:34:54 shafi-laptop kernel: [   86.692061] wlan0: no IPv6
routers present
May  1 14:34:58 shafi-laptop kernel: [   90.691571] cfg80211: Found

new beacon on frequency: 2467 MHz (Ch 12) on phy0

i just looked into the code and compared it with sta_addba_resp_timer_expired and thought whether we should do this..

net/mac80211/agg-tx.c +0 -0
index 5b7053c..e4da258 100644
@@ -421,21 +421,25 @@ static void

sta_tx_agg_session_timer_expired(unsigned long data)

        struct tid_ampdu_tx *tid_tx;
        unsigned long timeout;
+       rcu_read_lock();
        tid_tx = rcu_dereference_protected_tid_tx(sta, *ptid);
-       if (!tid_tx)
+       if (!tid_tx) {
+               rcu_read_unlock();
                return;

+ }

        timeout = tid_tx->last_tx + TU_TO_JIFFIES(tid_tx->timeout);
        if (time_is_after_jiffies(timeout)) {
                mod_timer(&tid_tx->session_timer, timeout);
+               rcu_read_unlock();
                return;
        }
 #ifdef CONFIG_MAC80211_HT_DEBUG
        printk(KERN_DEBUG "tx session timer expired on tid %d\n", (u16)*ptid);
 #endif
-
        ieee80211_stop_tx_ba_session(&sta->sta, *ptid);

+ rcu_read_unlock();
}

int i

Signature · 2 lines
thanks,
shafi
#7 lore raw
Quoted 4 lines · Mohammed Shafi

i just looked into the code and compared it with sta_addba_resp_timer_expired and thought whether we should do this..

Your patch does not help. I still get the following dump in the log:

===============================
[ INFO: suspicious RCU usage. ]
3.4.0-rc5-wl+ #287 Not tainted
-------------------------------
net/mac80211/sta_info.h:456 suspicious rcu_dereference_protected() usage!

other info that might help us debug this:

rcu_scheduler_active = 1, debug_locks = 0
3 locks held by kmemleak/622:

#0:  (scan_mutex){+.+...}, at: [<ffffffff8113b0d6>] kmemleak_scan_thread+0x56/0xd0
#1:  (&tid_tx->session_timer){+.-...}, at: [<ffffffff8104853a>] run_timer_softirq+0xfa/0x6e0
#2:  (rcu_read_lock){.+.+..}, at: [<ffffffffa0449ff0>] sta_tx_agg_session_timer_expired+0x0/0x2a0 [mac80211]
stack backtrace:
Pid: 622, comm: kmemleak Not tainted 3.4.0-rc5-wl+ #287
Call Trace:
 <IRQ>  [<ffffffff8109309d>] lockdep_rcu_suspicious+0xfd/0x130
 [<ffffffffa044a1cf>] sta_tx_agg_session_timer_expired+0x1df/0x2a0 [mac80211]
 [<ffffffffa0449ff0>] ? ieee80211_start_tx_ba_session+0x450/0x450 [mac80211]
 [<ffffffff810485c5>] run_timer_softirq+0x185/0x6e0

As kmemleak seems to be involved, I have added Catalin Marinas to the Cc list.

Larry

#8 lore raw
Quoted 9 lines · Larry Finger
Quoted 5 lines · Mohammed Shafi

i just looked into the code and compared it with sta_addba_resp_timer_expired and thought whether we should do this..

Your patch does not help. I still get the following dump in the log:

Larry, thanks for trying it out. then there seems to be something else, which requires further debugging/understanding.

Quoted 34 lines

===============================
[ INFO: suspicious RCU usage. ]
3.4.0-rc5-wl+ #287 Not tainted
-------------------------------

net/mac80211/sta_info.h:456 suspicious rcu_dereference_protected() usage!

other info that might help us debug this:

rcu_scheduler_active = 1, debug_locks = 0
3 locks held by kmemleak/622:
#0:  (scan_mutex){+.+...}, at: [<ffffffff8113b0d6>] kmemleak_scan_thread+0x56/0xd0
#1:  (&tid_tx->session_timer){+.-...}, at: [<ffffffff8104853a>] run_timer_softirq+0xfa/0x6e0
#2:  (rcu_read_lock){.+.+..}, at: [<ffffffffa0449ff0>]

sta_tx_agg_session_timer_expired+0x0/0x2a0 [mac80211]

stack backtrace:
Pid: 622, comm: kmemleak Not tainted 3.4.0-rc5-wl+ #287
Call Trace:
 <IRQ>  [<ffffffff8109309d>] lockdep_rcu_suspicious+0xfd/0x130
 [<ffffffffa044a1cf>] sta_tx_agg_session_timer_expired+0x1df/0x2a0

[mac80211]
 [<ffffffffa0449ff0>] ? ieee80211_start_tx_ba_session+0x450/0x450 [mac80211] [<ffffffff810485c5>] run_timer_softirq+0x185/0x6e0

As kmemleak seems to be involved, I have added Catalin Marinas to the Cc list.

Larry

Signature · 2 lines
thanks,
shafi
#9 lore raw
In reply to Larry Finger
Quoted 31 lines · Larry Finger
Quoted 3 lines · Mohammed Shafi

i just looked into the code and compared it with sta_addba_resp_timer_expired and thought whether we should do this..

Your patch does not help. I still get the following dump in the log:

===============================
[ INFO: suspicious RCU usage. ]
3.4.0-rc5-wl+ #287 Not tainted
-------------------------------
net/mac80211/sta_info.h:456 suspicious rcu_dereference_protected() usage!

other info that might help us debug this:

rcu_scheduler_active = 1, debug_locks = 0
3 locks held by kmemleak/622:
#0: (scan_mutex){+.+...}, at: [<ffffffff8113b0d6>] kmemleak_scan_thread+0x56/0xd0 #1: (&tid_tx->session_timer){+.-...}, at: [<ffffffff8104853a>] run_timer_softirq+0xfa/0x6e0
#2: (rcu_read_lock){.+.+..}, at: [<ffffffffa0449ff0>]

sta_tx_agg_session_timer_expired+0x0/0x2a0 [mac80211]

stack backtrace:
Pid: 622, comm: kmemleak Not tainted 3.4.0-rc5-wl+ #287
Call Trace:
  <IRQ>  [<ffffffff8109309d>] lockdep_rcu_suspicious+0xfd/0x130
  [<ffffffffa044a1cf>] sta_tx_agg_session_timer_expired+0x1df/0x2a0 [mac80211]
  [<ffffffffa0449ff0>] ? ieee80211_start_tx_ba_session+0x450/0x450 [mac80211]
  [<ffffffff810485c5>] run_timer_softirq+0x185/0x6e0
Quoted 1 line

As kmemleak seems to be involved, I have added Catalin Marinas to the Cc list.

It doesn't look related to kmemleak. It just happens that sta_tx_agg_session_timer_expired() was called from a timer when the kmemleak scanning thread was running (pretty likely as this thread can take minutes to complete).

Looking at the code and the logs, ieee80211_start_tx_ba_session() calls rcu_dereference_protected_tid_tx() which calls rcu_dereference_protected() with the (lockdep_is_held(&sta->lock) || lockdep_is_held(&sta->ampdu_mlme.mtx)) condition which is false. As the kernel log says, none of these locks are held, hence the warning.

Either the rcu_dereference annotation is wrong (introduced by commit 40b275 "mac80211: sparse RCU annotations") or there is something wrong in the code and the RCU pointer is dereferenced without any of those locks held.

Signature · 1 line
Catalin
maintainer
#10 lore raw
Quoted 1 line · Catalin Marinas
Quoted 1 line

Your patch does not help. I still get the following dump in the log:

The patch is also wrong, we hold the mutex there and can't hold RCU read lock.

Quoted 14 lines
Quoted 14 lines

#0: (scan_mutex){+.+...}, at: [<ffffffff8113b0d6>] kmemleak_scan_thread+0x56/0xd0 #1: (&tid_tx->session_timer){+.-...}, at: [<ffffffff8104853a>] run_timer_softirq+0xfa/0x6e0
#2: (rcu_read_lock){.+.+..}, at: [<ffffffffa0449ff0>]

sta_tx_agg_session_timer_expired+0x0/0x2a0 [mac80211]

stack backtrace:
Pid: 622, comm: kmemleak Not tainted 3.4.0-rc5-wl+ #287
Call Trace:
  <IRQ>  [<ffffffff8109309d>] lockdep_rcu_suspicious+0xfd/0x130
  [<ffffffffa044a1cf>] sta_tx_agg_session_timer_expired+0x1df/0x2a0 [mac80211]
  [<ffffffffa0449ff0>] ? ieee80211_start_tx_ba_session+0x450/0x450 [mac80211]
  [<ffffffff810485c5>] run_timer_softirq+0x185/0x6e0
Quoted 3 lines
Quoted 1 line

As kmemleak seems to be involved, I have added Catalin Marinas to the Cc list.

Looking at the code and the logs, ieee80211_start_tx_ba_session() calls

I'm almost certain that ieee80211_start_tx_ba_session() is a bogus calltrace entry, since we're in a timer and that's not called from a timer.

Quoted 4 lines

rcu_dereference_protected_tid_tx() which calls rcu_dereference_protected() with the (lockdep_is_held(&sta->lock) || lockdep_is_held(&sta->ampdu_mlme.mtx)) condition which is false. As the kernel log says, none of these locks are held, hence the warning.

So does that just mean we need to add rcu_read_lock_held() to the conditions? I thought that wasn't necessary? +Paul.

johannes

#11 lore raw
Quoted 29 lines · Johannes Berg
Quoted 1 line · Catalin Marinas
Quoted 1 line

Your patch does not help. I still get the following dump in the log:

The patch is also wrong, we hold the mutex there and can't hold RCU read lock.

Quoted 14 lines
Quoted 14 lines

#0: (scan_mutex){+.+...}, at: [<ffffffff8113b0d6>] kmemleak_scan_thread+0x56/0xd0 #1: (&tid_tx->session_timer){+.-...}, at: [<ffffffff8104853a>] run_timer_softirq+0xfa/0x6e0
#2: (rcu_read_lock){.+.+..}, at: [<ffffffffa0449ff0>]

sta_tx_agg_session_timer_expired+0x0/0x2a0 [mac80211]

stack backtrace:
Pid: 622, comm: kmemleak Not tainted 3.4.0-rc5-wl+ #287
Call Trace:
  <IRQ>  [<ffffffff8109309d>] lockdep_rcu_suspicious+0xfd/0x130
  [<ffffffffa044a1cf>] sta_tx_agg_session_timer_expired+0x1df/0x2a0 [mac80211]
  [<ffffffffa0449ff0>] ? ieee80211_start_tx_ba_session+0x450/0x450 [mac80211]
  [<ffffffff810485c5>] run_timer_softirq+0x185/0x6e0
Quoted 3 lines
Quoted 1 line

As kmemleak seems to be involved, I have added Catalin Marinas to the Cc list.

Looking at the code and the logs, ieee80211_start_tx_ba_session() calls

I'm almost certain that ieee80211_start_tx_ba_session() is a bogus calltrace entry, since we're in a timer and that's not called from a timer.

Quoted 7 lines
Quoted 4 lines

rcu_dereference_protected_tid_tx() which calls rcu_dereference_protected() with the (lockdep_is_held(&sta->lock) || lockdep_is_held(&sta->ampdu_mlme.mtx)) condition which is false. As the kernel log says, none of these locks are held, hence the warning.

So does that just mean we need to add rcu_read_lock_held() to the conditions? I thought that wasn't necessary? +Paul.

If you are using rcu_dereference_protected(), you really would need to add rcu_read_lock_held(). Except that it is not legal to use rcu_dereference_protected() within an RCU read-side critical section because rcu_dereference_protected() does nothing to protect against misordering mischief from the compiler and the CPU. Actually, that sounds like a useful coccinelle check, now that you mention it.

So you should instead use rcu_dereference_check(). This may be used in an RCU read-side critical section, but may also be passed things like (lockdep_is_held(&sta->lock) || lockdep_is_held(&sta->ampdu_mlme.mtx)).

Thanx, Paul

maintainer
#12 lore raw
Quoted 45 lines · Paul E. McKenney
Quoted 29 lines · Johannes Berg
Quoted 1 line · Catalin Marinas
Quoted 1 line

Your patch does not help. I still get the following dump in the log:

The patch is also wrong, we hold the mutex there and can't hold RCU read lock.

Quoted 14 lines
Quoted 14 lines

#0: (scan_mutex){+.+...}, at: [<ffffffff8113b0d6>] kmemleak_scan_thread+0x56/0xd0 #1: (&tid_tx->session_timer){+.-...}, at: [<ffffffff8104853a>] run_timer_softirq+0xfa/0x6e0
#2: (rcu_read_lock){.+.+..}, at: [<ffffffffa0449ff0>]

sta_tx_agg_session_timer_expired+0x0/0x2a0 [mac80211]

stack backtrace:
Pid: 622, comm: kmemleak Not tainted 3.4.0-rc5-wl+ #287
Call Trace:
  <IRQ>  [<ffffffff8109309d>] lockdep_rcu_suspicious+0xfd/0x130
  [<ffffffffa044a1cf>] sta_tx_agg_session_timer_expired+0x1df/0x2a0 [mac80211]
  [<ffffffffa0449ff0>] ? ieee80211_start_tx_ba_session+0x450/0x450 [mac80211]
  [<ffffffff810485c5>] run_timer_softirq+0x185/0x6e0
Quoted 3 lines
Quoted 1 line

As kmemleak seems to be involved, I have added Catalin Marinas to the Cc list.

Looking at the code and the logs, ieee80211_start_tx_ba_session() calls

I'm almost certain that ieee80211_start_tx_ba_session() is a bogus calltrace entry, since we're in a timer and that's not called from a timer.

Quoted 7 lines
Quoted 4 lines

rcu_dereference_protected_tid_tx() which calls rcu_dereference_protected() with the (lockdep_is_held(&sta->lock) || lockdep_is_held(&sta->ampdu_mlme.mtx)) condition which is false. As the kernel log says, none of these locks are held, hence the warning.

So does that just mean we need to add rcu_read_lock_held() to the conditions? I thought that wasn't necessary? +Paul.

If you are using rcu_dereference_protected(), you really would need to add rcu_read_lock_held(). Except that it is not legal to use rcu_dereference_protected() within an RCU read-side critical section because rcu_dereference_protected() does nothing to protect against misordering mischief from the compiler and the CPU. Actually, that sounds like a useful coccinelle check, now that you mention it.

Quoted 3 lines

So you should instead use rcu_dereference_check(). This may be used in an RCU read-side critical section, but may also be passed things like (lockdep_is_held(&sta->lock) || lockdep_is_held(&sta->ampdu_mlme.mtx)).

Oops, of course, I should have seen that, thanks for pointing it out!

Now that I look at it, the problem actually seems to be something else entirely though: the rcu_dereference (whichever type) in sta_tx_agg_session_timer_expired() itself isn't protected at all, something like the patch below is needed. Larry, can you try that?

johannes

net/mac80211/agg-tx.c +8 -2
index 5b7053c..40d3ff4 100644
@@ -421,16 +421,22 @@ static void sta_tx_agg_session_timer_expired(unsigned long data)
 	struct tid_ampdu_tx *tid_tx;
 	unsigned long timeout;
 
-	tid_tx = rcu_dereference_protected_tid_tx(sta, *ptid);
-	if (!tid_tx)
+	rcu_read_lock();
+	tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[*ptid]);
+	if (!tid_tx) {
+		rcu_read_unlock();
 		return;
+	}
 
 	timeout = tid_tx->last_tx + TU_TO_JIFFIES(tid_tx->timeout);
 	if (time_is_after_jiffies(timeout)) {
 		mod_timer(&tid_tx->session_timer, timeout);
+		rcu_read_unlock();
 		return;
 	}
 
+	rcu_read_unlock();
+
 #ifdef CONFIG_MAC80211_HT_DEBUG
 	printk(KERN_DEBUG "tx session timer expired on tid %d\n", (u16)*ptid);
 #endif
#13 lore raw
Quoted 19 lines · Johannes Berg
net/mac80211/agg-tx.c +5 -2
index 5b7053c..40d3ff4 100644
@@ -421,16 +421,22 @@ static void sta_tx_agg_session_timer_expired(unsigned long data)
  	struct tid_ampdu_tx *tid_tx;
  	unsigned long timeout;
 
-	tid_tx = rcu_dereference_protected_tid_tx(sta, *ptid);
-	if (!tid_tx)
+	rcu_read_lock();
+	tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[*ptid]);
+	if (!tid_tx) {
+		rcu_read_unlock();
  		return;
+	}
 
  	timeout = tid_tx->last_tx + TU_TO_JIFFIES(tid_tx->timeout);
  	if (time_is_after_jiffies(timeout)) {

net/mac80211/agg-tx.c static void sta_tx_agg_session_timer_expired(unsigned long data) · line 442

Quoted 10 lines
net/mac80211/agg-tx.c +3 -0
  		mod_timer(&tid_tx->session_timer, timeout);
+		rcu_read_unlock();
  		return;
  	}
 
+	rcu_read_unlock();
+
  #ifdef CONFIG_MAC80211_HT_DEBUG
  	printk(KERN_DEBUG "tx session timer expired on tid %d\n", (u16)*ptid);
  #endif

This patch is the same as was proposed by Mohammed on May 1. I must have messed up the testing as I thought it failed; however, it is now working.

Mohammed - I plan on submitting this to John with a "From:" from you along with your s-o-b. Is that OK. It will be submitted for inclusion in 3.5.

Larry

#14 lore raw

Hi Larry,

Quoted 27 lines · Larry Finger
Quoted 26 lines · Johannes Berg
net/mac80211/agg-tx.c +6 -2
index 5b7053c..40d3ff4 100644
@@ -421,16 +421,22 @@ static void
 sta_tx_agg_session_timer_expired(unsigned long data)
        struct tid_ampdu_tx *tid_tx;
        unsigned long timeout;
 
-       tid_tx = rcu_dereference_protected_tid_tx(sta, *ptid);
-       if (!tid_tx)
+       rcu_read_lock();
+       tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[*ptid]);
+       if (!tid_tx) {
+               rcu_read_unlock();
                return;
+       }
 
        timeout = tid_tx->last_tx + TU_TO_JIFFIES(tid_tx->timeout);
        if (time_is_after_jiffies(timeout)) {
                mod_timer(&tid_tx->session_timer, timeout);
+               rcu_read_unlock();
                return;
        }
 
Quoted 10 lines
Quoted 6 lines
net/mac80211/agg-tx.c +2 -0
+       rcu_read_unlock();
+
  #ifdef CONFIG_MAC80211_HT_DEBUG
        printk(KERN_DEBUG "tx session timer expired on tid %d\n",

(u16)*ptid);
 #endif

This patch is the same as was proposed by Mohammed on May 1. I must have messed up the testing as I thought it failed; however, it is now working.

honestly i am not sure about the technical details, but Johannes patch seems to follow almost similar
what's is done in 'sta_addba_resp_timer_expired'. while thought that is being also with mutex under hold
but the difference is the lock is unhold before ieee80211_stop_tx_ba_session is called.

Quoted 6 lines

Mohammed - I plan on submitting this to John with a "From:" from you along with your s-o-b. Is that OK. It will be submitted for inclusion in 3.5.

Larry

Signature · 2 lines
thanks,
shafi
#15 lore raw
Quoted 14 lines · Mohammed Shafi

Hi Larry,

Quoted 11 lines · Larry Finger
Quoted 10 lines · Johannes Berg
net/mac80211/agg-tx.c +0 -0
index 5b7053c..40d3ff4 100644
@@ -421,16 +421,22 @@ static void
 sta_tx_agg_session_timer_expired(unsigned long data)
        struct tid_ampdu_tx *tid_tx;
        unsigned long timeout;
 
Quoted 4 lines
Quoted 4 lines

net/mac80211/agg-tx.c static void sta_tx_agg_session_timer_expired(unsigned long data) · line 425

Quoted 4 lines
net/mac80211/agg-tx.c +2 -2
-       tid_tx = rcu_dereference_protected_tid_tx(sta, *ptid);
-       if (!tid_tx)
+       rcu_read_lock();
+       tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[*ptid]);

Larry, Johannes seems to use rcu_dereference straight way just like in 'sta_addba_resp_timer_expired'
and have it protected by rcu_read_locks

Quoted 41 lines
Quoted 20 lines
Quoted 16 lines
net/mac80211/agg-tx.c +6 -0
+       if (!tid_tx) {
+               rcu_read_unlock();
                return;
+       }
 
        timeout = tid_tx->last_tx + TU_TO_JIFFIES(tid_tx->timeout);
        if (time_is_after_jiffies(timeout)) {
                mod_timer(&tid_tx->session_timer, timeout);
+               rcu_read_unlock();
                return;
        }
 
+       rcu_read_unlock();
+
  #ifdef CONFIG_MAC80211_HT_DEBUG
        printk(KERN_DEBUG "tx session timer expired on tid %d\n",
Quoted 2 lines

(u16)*ptid);
 #endif

Quoted 2 lines

This patch is the same as was proposed by Mohammed on May 1. I must have messed up the testing as I thought it failed; however, it is now working.

honestly i am not sure about the technical details, but Johannes patch seems to follow almost similar
what's is done in 'sta_addba_resp_timer_expired'. while thought that is being also with mutex under hold
but the difference is  the lock is unhold before ieee80211_stop_tx_ba_session is called.

Quoted 6 lines

Mohammed - I plan on submitting this to John with a "From:" from you along with your s-o-b. Is that OK. It will be submitted for inclusion in 3.5.

Larry

--
thanks,
shafi

Signature · 2 lines
thanks,
shafi
#16 lore raw
Quoted 16 lines · Mohammed Shafi
Quoted 14 lines · Mohammed Shafi

Hi Larry,

Quoted 11 lines · Larry Finger
Quoted 10 lines · Johannes Berg
net/mac80211/agg-tx.c +0 -0
index 5b7053c..40d3ff4 100644
@@ -421,16 +421,22 @@ static void
 sta_tx_agg_session_timer_expired(unsigned long data)
        struct tid_ampdu_tx *tid_tx;
        unsigned long timeout;
 
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

net/mac80211/agg-tx.c static void sta_tx_agg_session_timer_expired(unsigned long data) · line 425

Quoted 4 lines
net/mac80211/agg-tx.c +2 -2
-       tid_tx = rcu_dereference_protected_tid_tx(sta, *ptid);
-       if (!tid_tx)
+       rcu_read_lock();
+       tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[*ptid]);

Larry, Johannes seems to use rcu_dereference straight way just like in 'sta_addba_resp_timer_expired'
and have it protected by rcu_read_locks

Sorry. I missed that subtle difference. Submitted "from Johannes".

Larry

#17 lore raw
Quoted 33 lines · Larry Finger
Quoted 21 lines · Mohammed Shafi
Quoted 18 lines · Mohammed Shafi

Hi Larry,

Quoted 13 lines · Larry Finger
Quoted 11 lines · Johannes Berg
net/mac80211/agg-tx.c +0 -0
index 5b7053c..40d3ff4 100644
@@ -421,16 +421,22 @@ static void
 sta_tx_agg_session_timer_expired(unsigned long data)
        struct tid_ampdu_tx *tid_tx;
        unsigned long timeout;
 
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines

net/mac80211/agg-tx.c static void sta_tx_agg_session_timer_expired(unsigned long data) · line 425

Quoted 4 lines
net/mac80211/agg-tx.c +2 -2
-       tid_tx = rcu_dereference_protected_tid_tx(sta, *ptid);
-       if (!tid_tx)
+       rcu_read_lock();
+       tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[*ptid]);

Larry, Johannes seems to use rcu_dereference straight way just like in 'sta_addba_resp_timer_expired'
and have it protected by rcu_read_locks

Quoted 1 line

Sorry. I missed that subtle difference. Submitted "from Johannes".

no problem thanks! yeah but it seems my gmail seems to be identify those changes!!

Signature · 2 lines
thanks,
shafi
#18 lore raw
In reply to Johannes Berg
Quoted 29 lines · Johannes Berg
Quoted 1 line · Catalin Marinas
Quoted 1 line

Your patch does not help. I still get the following dump in the log:

The patch is also wrong, we hold the mutex there and can't hold RCU read lock.

Quoted 14 lines
Quoted 14 lines

#0: (scan_mutex){+.+...}, at: [<ffffffff8113b0d6>] kmemleak_scan_thread+0x56/0xd0 #1: (&tid_tx->session_timer){+.-...}, at: [<ffffffff8104853a>] run_timer_softirq+0xfa/0x6e0
#2: (rcu_read_lock){.+.+..}, at: [<ffffffffa0449ff0>]

sta_tx_agg_session_timer_expired+0x0/0x2a0 [mac80211]

stack backtrace:
Pid: 622, comm: kmemleak Not tainted 3.4.0-rc5-wl+ #287
Call Trace:
   <IRQ>   [<ffffffff8109309d>] lockdep_rcu_suspicious+0xfd/0x130
   [<ffffffffa044a1cf>] sta_tx_agg_session_timer_expired+0x1df/0x2a0 [mac80211]
   [<ffffffffa0449ff0>] ? ieee80211_start_tx_ba_session+0x450/0x450 [mac80211]
   [<ffffffff810485c5>] run_timer_softirq+0x185/0x6e0
Quoted 3 lines
Quoted 1 line

As kmemleak seems to be involved, I have added Catalin Marinas to the Cc list.

Looking at the code and the logs, ieee80211_start_tx_ba_session() calls

I'm almost certain that ieee80211_start_tx_ba_session() is a bogus calltrace entry, since we're in a timer and that's not called from a timer.

Quoted 7 lines
Quoted 4 lines

rcu_dereference_protected_tid_tx() which calls rcu_dereference_protected() with the (lockdep_is_held(&sta->lock) || lockdep_is_held(&sta->ampdu_mlme.mtx)) condition which is false. As the kernel log says, none of these locks are held, hence the warning.

So does that just mean we need to add rcu_read_lock_held() to the conditions? I thought that wasn't necessary? +Paul.

If you meant the following

net/mac80211/sta_info.h +2 -1
Index: wireless-testing-new/net/mac80211/sta_info.h
===================================================================
@@ -453,7 +453,8 @@ rcu_dereference_protected_tid_tx(struct
 {
        return rcu_dereference_protected(sta->ampdu_mlme.tid_tx[tid],
                                         lockdep_is_held(&sta->lock) ||
-                                        lockdep_is_held(&sta->ampdu_mlme.mtx));
+                                        lockdep_is_held(&sta->ampdu_mlme.mtx) ||
+                                        rcu_read_lock_held());
 }
 
 #define STA_HASH_SIZE 256

It does not help.

Larry

#19 lore raw
Quoted 45 lines · Larry Finger
Quoted 29 lines · Johannes Berg
Quoted 1 line · Catalin Marinas
Quoted 1 line

Your patch does not help. I still get the following dump in the log:

The patch is also wrong, we hold the mutex there and can't hold RCU read lock.

Quoted 14 lines
Quoted 14 lines

#0: (scan_mutex){+.+...}, at: [<ffffffff8113b0d6>] kmemleak_scan_thread+0x56/0xd0 #1: (&tid_tx->session_timer){+.-...}, at: [<ffffffff8104853a>] run_timer_softirq+0xfa/0x6e0
#2: (rcu_read_lock){.+.+..}, at: [<ffffffffa0449ff0>]

sta_tx_agg_session_timer_expired+0x0/0x2a0 [mac80211]

stack backtrace:
Pid: 622, comm: kmemleak Not tainted 3.4.0-rc5-wl+ #287
Call Trace:
   <IRQ>   [<ffffffff8109309d>] lockdep_rcu_suspicious+0xfd/0x130
   [<ffffffffa044a1cf>] sta_tx_agg_session_timer_expired+0x1df/0x2a0 [mac80211]
   [<ffffffffa0449ff0>] ? ieee80211_start_tx_ba_session+0x450/0x450 [mac80211]
   [<ffffffff810485c5>] run_timer_softirq+0x185/0x6e0
Quoted 3 lines
Quoted 1 line

As kmemleak seems to be involved, I have added Catalin Marinas to the Cc list.

Looking at the code and the logs, ieee80211_start_tx_ba_session() calls

I'm almost certain that ieee80211_start_tx_ba_session() is a bogus calltrace entry, since we're in a timer and that's not called from a timer.

Quoted 7 lines
Quoted 4 lines

rcu_dereference_protected_tid_tx() which calls rcu_dereference_protected() with the (lockdep_is_held(&sta->lock) || lockdep_is_held(&sta->ampdu_mlme.mtx)) condition which is false. As the kernel log says, none of these locks are held, hence the warning.

So does that just mean we need to add rcu_read_lock_held() to the conditions? I thought that wasn't necessary? +Paul.

If you meant the following

Index: wireless-testing-new/net/mac80211/sta_info.h
===================================================================

net/mac80211/sta_info.h rcu_dereference_protected_tid_tx(struct · line 454

Quoted 2 lines
net/mac80211/sta_info.h +0 -0
@@ -453,7 +453,8 @@ rcu_dereference_protected_tid_tx(struct
  {
         return rcu_dereference_protected(sta->ampdu_mlme.tid_tx[tid],

IIUC, Paul suggested that you should use rcu_dereference_check() here instead as the protected one is not safe in this context.

Signature · 1 line
Catalin
#20 lore raw
Quoted 3 lines · Catalin Marinas

IIUC, Paul suggested that you should use rcu_dereference_check() here instead as the protected one is not safe in this context.

This patch also fails to fix the problem. Did I do what Paul suggested?

net/mac80211/sta_info.h +1 -1
Index: wireless-testing-new/net/mac80211/sta_info.h
===================================================================
@@ -452,7 +452,7 @@ void ieee80211_assign_tid_tx(struct sta_
 static inline struct tid_ampdu_tx *
 rcu_dereference_protected_tid_tx(struct sta_info *sta, int tid)
 {
-       return rcu_dereference_protected(sta->ampdu_mlme.tid_tx[tid],
+       return rcu_dereference_check(sta->ampdu_mlme.tid_tx[tid],
                                         lockdep_is_held(&sta->lock) ||
                                         lockdep_is_held(&sta->ampdu_mlme.mtx));
 }
#21 lore raw
Quoted 6 lines · Larry Finger
Quoted 3 lines · Catalin Marinas

IIUC, Paul suggested that you should use rcu_dereference_check() here instead as the protected one is not safe in this context.

This patch also fails to fix the problem. Did I do what Paul suggested?

That is indeed what I suggested!

What locks does lockdep say are held?

Thanx, Paul

Quoted 14 lines

Index: wireless-testing-new/net/mac80211/sta_info.h
===================================================================

net/mac80211/sta_info.h +1 -1
@@ -452,7 +452,7 @@ void ieee80211_assign_tid_tx(struct sta_
 static inline struct tid_ampdu_tx *
 rcu_dereference_protected_tid_tx(struct sta_info *sta, int tid)
 {
-       return rcu_dereference_protected(sta->ampdu_mlme.tid_tx[tid],
+       return rcu_dereference_check(sta->ampdu_mlme.tid_tx[tid],
                                         lockdep_is_held(&sta->lock) ||
                                         lockdep_is_held(&sta->ampdu_mlme.mtx));
 }
#22 lore raw
Quoted 11 lines · Paul E. McKenney
Quoted 6 lines · Larry Finger
Quoted 3 lines · Catalin Marinas

IIUC, Paul suggested that you should use rcu_dereference_check() here instead as the protected one is not safe in this context.

This patch also fails to fix the problem. Did I do what Paul suggested?

That is indeed what I suggested!

What locks does lockdep say are held?

It varies from instance to instance. I have seen 1, 2, or 3. Those are the following:

#0:  (scan_mutex){+.+...}, at: [<ffffffff8113b0d6>] kmemleak_scan_thread+0x56/0xd0
#1:  (&tid_tx->session_timer){+.-...}, at: [<ffffffff8104853a>] run_timer_softirq+0xfa/0x6e0
#2:  (rcu_read_lock){.+.+..}, at: [<ffffffffa03c1ff0>] sta_tx_agg_session_timer_expired+0x0/0x2a0 [mac80211]

When only 1 lock is held, it is "&tid_tx->session_timer", and that one is held in every case. I think that means we need to OR it with the other lockdep_is_held() arguments in the rcu_dereference_xxxxx() call, but I did not seem to get the syntax right.

Larry

#23 lore raw
Quoted 23 lines · Larry Finger
Quoted 11 lines · Paul E. McKenney
Quoted 6 lines · Larry Finger
Quoted 3 lines · Catalin Marinas

IIUC, Paul suggested that you should use rcu_dereference_check() here instead as the protected one is not safe in this context.

This patch also fails to fix the problem. Did I do what Paul suggested?

That is indeed what I suggested!

What locks does lockdep say are held?

It varies from instance to instance. I have seen 1, 2, or 3. Those are the following:

#0: (scan_mutex){+.+...}, at: [<ffffffff8113b0d6>] kmemleak_scan_thread+0x56/0xd0 #1: (&tid_tx->session_timer){+.-...}, at: [<ffffffff8104853a>] run_timer_softirq+0xfa/0x6e0
#2: (rcu_read_lock){.+.+..}, at: [<ffffffffa03c1ff0>] sta_tx_agg_session_timer_expired+0x0/0x2a0 [mac80211]

Quoted 4 lines

When only 1 lock is held, it is "&tid_tx->session_timer", and that one is held in every case. I think that means we need to OR it with the other lockdep_is_held() arguments in the rcu_dereference_xxxxx() call, but I did not seem to get the syntax right.

If any one of several locks (call them a, b, and c) is sufficient to protect the data, and if an rcu_read_lock() also suffices, then something like the following would work:

	return rcu_dereference_check(sta->ampdu_mlme.tid_tx[tid],
				     lockdep_is_held(&a) ||
				     lockdep_is_held(&b) ||
				     lockdep_is_held(&c));

But I must defer to the developers and maintainers of that code as to exactly which combinations of locks and RCU are required. The rcu_read_lock_held() is supplied by rcu_dereference_check(), so I am surprised that you got a splat that included rcu_read_lock.

Thanx, Paul

#24 lore raw
Quoted 38 lines · Paul E. McKenney
Quoted 23 lines · Larry Finger
Quoted 11 lines · Paul E. McKenney
Quoted 6 lines · Larry Finger
Quoted 3 lines · Catalin Marinas

IIUC, Paul suggested that you should use rcu_dereference_check() here instead as the protected one is not safe in this context.

This patch also fails to fix the problem. Did I do what Paul suggested?

That is indeed what I suggested!

What locks does lockdep say are held?

It varies from instance to instance. I have seen 1, 2, or 3. Those are the following:

#0: (scan_mutex){+.+...}, at: [<ffffffff8113b0d6>] kmemleak_scan_thread+0x56/0xd0 #1: (&tid_tx->session_timer){+.-...}, at: [<ffffffff8104853a>] run_timer_softirq+0xfa/0x6e0
#2: (rcu_read_lock){.+.+..}, at: [<ffffffffa03c1ff0>] sta_tx_agg_session_timer_expired+0x0/0x2a0 [mac80211]

Quoted 4 lines

When only 1 lock is held, it is "&tid_tx->session_timer", and that one is held in every case. I think that means we need to OR it with the other lockdep_is_held() arguments in the rcu_dereference_xxxxx() call, but I did not seem to get the syntax right.

If any one of several locks (call them a, b, and c) is sufficient to protect the data, and if an rcu_read_lock() also suffices, then something like the following would work:

	return rcu_dereference_check(sta->ampdu_mlme.tid_tx[tid],
				     lockdep_is_held(&a) ||
				     lockdep_is_held(&b) ||
				     lockdep_is_held(&c));
Quoted 4 lines

But I must defer to the developers and maintainers of that code as to exactly which combinations of locks and RCU are required. The rcu_read_lock_held() is supplied by rcu_dereference_check(), so I am surprised that you got a splat that included rcu_read_lock.

That was before I switched to rcu_dereference_check(). Sorry if that misled you.

Larry