Skip to contentSkip to conversation

cfg80211: Pass lockdep expression to RCU lists

PATCH In review Amol Grover 4 participants 6 messages Feb 19, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cfg80211: Pass lockdep expression to RCU lists

rdev->sched_scan_req_list maybe traversed using list_for_each_entry_rcu outside an RCU read-side critical section but under the protection of rtnl_mutex.

Hence, add corresponding lockdep expression to silence false-positive warnings, and harden RCU lists.

---
 net/wireless/scan.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
net/wireless/scan.c +2 -3
index aef240fdf8df..7f1af8f347b1 100644
@@ -556,9 +556,8 @@ cfg80211_find_sched_scan_req(struct cfg80211_registered_device *rdev, u64 reqid)
 {
 	struct cfg80211_sched_scan_request *pos;
 
-	WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_rtnl_is_held());
-
-	list_for_each_entry_rcu(pos, &rdev->sched_scan_req_list, list) {
+	list_for_each_entry_rcu(pos, &rdev->sched_scan_req_list, list,
+				lockdep_rtnl_is_held()) {
 		if (pos->reqid == reqid)
 			return pos;
 	}
Signature · 1 line
2.24.1
maintainer
#1 lore raw

net/wireless/scan.c cfg80211_find_sched_scan_req(struct cfg80211_registered_device *rdev, u64 reqid) · line 560

Quoted 6 lines · Amol Grover
net/wireless/scan.c +2 -3
-	WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_rtnl_is_held());
-
-	list_for_each_entry_rcu(pos, &rdev->sched_scan_req_list, list) {
+	list_for_each_entry_rcu(pos, &rdev->sched_scan_req_list, list,
+				lockdep_rtnl_is_held()) {

Huh, I didn't even know you _could_ do that :)

johannes

#2 lore raw
Quoted 9 lines · Johannes Berg

net/wireless/scan.c cfg80211_find_sched_scan_req(struct cfg80211_registered_device *rdev, u64 reqid) · line 560

Quoted 6 lines · Amol Grover
net/wireless/scan.c +2 -3
-	WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_rtnl_is_held());
-
-	list_for_each_entry_rcu(pos, &rdev->sched_scan_req_list, list) {
+	list_for_each_entry_rcu(pos, &rdev->sched_scan_req_list, list,
+				lockdep_rtnl_is_held()) {

Huh, I didn't even know you _could_ do that :)

It is a fairly recent addition, courtesy of Joel Fernandes. ;-)

Thanx, Paul

#3 lore raw
In reply to Johannes Berg
Quoted 9 lines · Johannes Berg

net/wireless/scan.c cfg80211_find_sched_scan_req(struct cfg80211_registered_device *rdev, u64 reqid) · line 560

Quoted 6 lines · Amol Grover
net/wireless/scan.c +2 -3
-	WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_rtnl_is_held());
-
-	list_for_each_entry_rcu(pos, &rdev->sched_scan_req_list, list) {
+	list_for_each_entry_rcu(pos, &rdev->sched_scan_req_list, list,
+				lockdep_rtnl_is_held()) {

Huh, I didn't even know you _could_ do that :)

Me neither ;-). Above you are removing the WARN_ON_ONCE() entirely. Would it not be good to keep the WARN_ON_ONCE() with only the !rcu_read_lock_held() check.

Regards,
Arend

maintainer
#4 lore raw
Quoted 11 lines · Arend Van Spriel
Quoted 9 lines · Johannes Berg

net/wireless/scan.c cfg80211_find_sched_scan_req(struct cfg80211_registered_device *rdev, u64 reqid) · line 560

Quoted 6 lines · Amol Grover
net/wireless/scan.c +2 -3
-	WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_rtnl_is_held());
-
-	list_for_each_entry_rcu(pos, &rdev->sched_scan_req_list, list) {
+	list_for_each_entry_rcu(pos, &rdev->sched_scan_req_list, list,
+				lockdep_rtnl_is_held()) {

Huh, I didn't even know you _could_ do that :)

Quoted 3 lines

Me neither ;-). Above you are removing the WARN_ON_ONCE() entirely. Would it not be good to keep the WARN_ON_ONCE() with only the !rcu_read_lock_held() check.

Not needed, the macro expansion will already contain rcu_read_lock_any_held() just like in all the other cases where you pass a lockdep condition to RCU helpers.

johannes

#5 lore raw
Quoted 12 lines · Johannes Berg
Quoted 11 lines · Arend Van Spriel
Quoted 9 lines · Johannes Berg

net/wireless/scan.c cfg80211_find_sched_scan_req(struct cfg80211_registered_device *rdev, u64 reqid) · line 560

Quoted 6 lines · Amol Grover
net/wireless/scan.c +2 -3
-	WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_rtnl_is_held());
-
-	list_for_each_entry_rcu(pos, &rdev->sched_scan_req_list, list) {
+	list_for_each_entry_rcu(pos, &rdev->sched_scan_req_list, list,
+				lockdep_rtnl_is_held()) {

Huh, I didn't even know you _could_ do that :)

Quoted 7 lines
Quoted 3 lines

Me neither ;-). Above you are removing the WARN_ON_ONCE() entirely. Would it not be good to keep the WARN_ON_ONCE() with only the !rcu_read_lock_held() check.

Not needed, the macro expansion will already contain rcu_read_lock_any_held() just like in all the other cases where you pass a lockdep condition to RCU helpers.

Ah, yes. I see it in __list_check_rcu().

Thanks,
Arend