Skip to contentSkip to conversation

tcp: Pass lockdep expression to RCU lists

PATCH In review Amol Grover 2 participants 3 messages Feb 19, 2020 – Feb 20, 2020

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

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

tcp_cong_list is traversed using list_for_each_entry_rcu outside an RCU read-side critical section but under the protection of tcp_cong_list_lock.

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

---
 net/ipv4/tcp_cong.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
net/ipv4/tcp_cong.c +6 -3
index 3737ec096650..8d4446ed309e 100644
@@ -25,7 +25,8 @@ static struct tcp_congestion_ops *tcp_ca_find(const char *name)
 {
 	struct tcp_congestion_ops *e;
 
-	list_for_each_entry_rcu(e, &tcp_cong_list, list) {
+	list_for_each_entry_rcu(e, &tcp_cong_list, list,
+				lockdep_is_held(&tcp_cong_list_lock)) {
 		if (strcmp(e->name, name) == 0)
 			return e;
 	}
@@ -55,7 +56,8 @@ struct tcp_congestion_ops *tcp_ca_find_key(u32 key)
 {
 	struct tcp_congestion_ops *e;
 
-	list_for_each_entry_rcu(e, &tcp_cong_list, list) {
+	list_for_each_entry_rcu(e, &tcp_cong_list, list,
+				lockdep_is_held(&tcp_cong_list_lock)) {
 		if (e->key == key)
 			return e;
 	}
@@ -317,7 +319,8 @@ int tcp_set_allowed_congestion_control(char *val)
 	}
 
 	/* pass 2 clear old values */
-	list_for_each_entry_rcu(ca, &tcp_cong_list, list)
+	list_for_each_entry_rcu(ca, &tcp_cong_list, list,
+				lockdep_is_held(&tcp_cong_list_lock))
 		ca->flags &= ~TCP_CONG_NON_RESTRICTED;
 
 	/* pass 3 mark as allowed */
Signature · 1 line
2.24.1
#1 lore raw
Quoted 4 lines · Amol Grover

tcp_cong_list is traversed using list_for_each_entry_rcu outside an RCU read-side critical section but under the protection of tcp_cong_list_lock.

This is not true.

There are cases where RCU read lock is held,
and others where the tcp_cong_list_lock is held.

I believe you need to be more precise in the changelog.

If there was a bug, net tree would be the target for this patch, with a required Fixes: tag.

Otherwise, if net-next tree is the intended target, you have to signal it, as instructed in Documentation/networking/netdev-FAQ.rst

Thanks.

Quoted 34 lines

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

---
 net/ipv4/tcp_cong.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
net/ipv4/tcp_cong.c +4 -2
index 3737ec096650..8d4446ed309e 100644
@@ -25,7 +25,8 @@ static struct tcp_congestion_ops *tcp_ca_find(const char *name)
 {
 	struct tcp_congestion_ops *e;
 
-	list_for_each_entry_rcu(e, &tcp_cong_list, list) {
+	list_for_each_entry_rcu(e, &tcp_cong_list, list,
+				lockdep_is_held(&tcp_cong_list_lock)) {
 		if (strcmp(e->name, name) == 0)
 			return e;
 	}
@@ -55,7 +56,8 @@ struct tcp_congestion_ops *tcp_ca_find_key(u32 key)
 {
 	struct tcp_congestion_ops *e;
 
-	list_for_each_entry_rcu(e, &tcp_cong_list, list) {
+	list_for_each_entry_rcu(e, &tcp_cong_list, list,
+				lockdep_is_held(&tcp_cong_list_lock)) {
 		if (e->key == key)
 			return e;
 	}

net/ipv4/tcp_cong.c int tcp_set_allowed_congestion_control(char *val) · line 326

Quoted 9 lines
net/ipv4/tcp_cong.c +2 -1
@@ -317,7 +319,8 @@ int tcp_set_allowed_congestion_control(char *val)
 	}
 
 	/* pass 2 clear old values */
-	list_for_each_entry_rcu(ca, &tcp_cong_list, list)
+	list_for_each_entry_rcu(ca, &tcp_cong_list, list,
+				lockdep_is_held(&tcp_cong_list_lock))
 		ca->flags &= ~TCP_CONG_NON_RESTRICTED;
 
 	/* pass 3 mark as allowed */

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#2 lore raw
Quoted 8 lines · Eric Dumazet
Quoted 4 lines · Amol Grover

tcp_cong_list is traversed using list_for_each_entry_rcu outside an RCU read-side critical section but under the protection of tcp_cong_list_lock.

Quoted 5 lines

This is not true.

There are cases where RCU read lock is held,
and others where the tcp_cong_list_lock is held.

That's true but this patch specifically fixes those occurences of list_for_each_entry_rcu() that are traversed under tcp_cong_list_lock. Moreover, an implicit check is done for being inside RCU read-side critical section along with testing for this newly added lockdep expression.

Quoted 8 lines

I believe you need to be more precise in the changelog.

If there was a bug, net tree would be the target for this patch, with a required Fixes: tag.

Otherwise, if net-next tree is the intended target, you have to signal it, as instructed in Documentation/networking/netdev-FAQ.rst

I don't think this fixes a "bug". However, this may fix potential bugs that may creep in. Should I send it against net-next tree?

Thanks
Amol

Quoted 46 lines

Thanks.

Quoted 43 lines

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

---
 net/ipv4/tcp_cong.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
net/ipv4/tcp_cong.c +6 -3
index 3737ec096650..8d4446ed309e 100644
@@ -25,7 +25,8 @@ static struct tcp_congestion_ops *tcp_ca_find(const char *name)
 {
 	struct tcp_congestion_ops *e;
 
-	list_for_each_entry_rcu(e, &tcp_cong_list, list) {
+	list_for_each_entry_rcu(e, &tcp_cong_list, list,
+				lockdep_is_held(&tcp_cong_list_lock)) {
 		if (strcmp(e->name, name) == 0)
 			return e;
 	}
@@ -55,7 +56,8 @@ struct tcp_congestion_ops *tcp_ca_find_key(u32 key)
 {
 	struct tcp_congestion_ops *e;
 
-	list_for_each_entry_rcu(e, &tcp_cong_list, list) {
+	list_for_each_entry_rcu(e, &tcp_cong_list, list,
+				lockdep_is_held(&tcp_cong_list_lock)) {
 		if (e->key == key)
 			return e;
 	}
@@ -317,7 +319,8 @@ int tcp_set_allowed_congestion_control(char *val)
 	}
 
 	/* pass 2 clear old values */
-	list_for_each_entry_rcu(ca, &tcp_cong_list, list)
+	list_for_each_entry_rcu(ca, &tcp_cong_list, list,
+				lockdep_is_held(&tcp_cong_list_lock))
 		ca->flags &= ~TCP_CONG_NON_RESTRICTED;
 
 	/* pass 3 mark as allowed */