public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: batman-adv: Use built-in RCU list checking
@ 2020-02-16 14:47 madhuparnabhowmik10
  2020-02-16 15:22 ` Sven Eckelmann
  0 siblings, 1 reply; 7+ messages in thread
From: madhuparnabhowmik10 @ 2020-02-16 14:47 UTC (permalink / raw)
  To: mareklindner, sw, a, sven, davem
  Cc: b.a.t.m.a.n, netdev, linux-kernel, joel, frextrite,
	linux-kernel-mentees, Madhuparna Bhowmik

From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>

hlist_for_each_entry_rcu() has built-in RCU and lock checking.

Pass cond argument to hlist_for_each_entry_rcu() to silence
false lockdep warnings when CONFIG_PROVE_RCU_LIST is enabled
by default.

Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
---
 net/batman-adv/translation-table.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 8a482c5ec67b..0e3c31cbe0e8 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -862,7 +862,8 @@ batadv_tt_prepare_tvlv_global_data(struct batadv_orig_node *orig_node,
 	u8 *tt_change_ptr;
 
 	spin_lock_bh(&orig_node->vlan_list_lock);
-	hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) {
+	hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list,
+				lockdep_is_held(&orig_node->vlan_list_lock)) {
 		num_vlan++;
 		num_entries += atomic_read(&vlan->tt.num_entries);
 	}
@@ -888,7 +889,8 @@ batadv_tt_prepare_tvlv_global_data(struct batadv_orig_node *orig_node,
 	(*tt_data)->num_vlan = htons(num_vlan);
 
 	tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1);
-	hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) {
+	hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list,
+				lockdep_is_held(&orig_node->vlan_list_lock)) {
 		tt_vlan->vid = htons(vlan->vid);
 		tt_vlan->crc = htonl(vlan->tt.crc);
 
@@ -937,7 +939,8 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,
 	int change_offset;
 
 	spin_lock_bh(&bat_priv->softif_vlan_list_lock);
-	hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
+	hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list,
+				lockdep_is_held(&bat_priv->softif_vlan_list_lock)) {
 		vlan_entries = atomic_read(&vlan->tt.num_entries);
 		if (vlan_entries < 1)
 			continue;
@@ -967,7 +970,8 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,
 	(*tt_data)->num_vlan = htons(num_vlan);
 
 	tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1);
-	hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
+	hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list,
+				lockdep_is_held(&bat_priv->softif_vlan_list_lock)) {
 		vlan_entries = atomic_read(&vlan->tt.num_entries);
 		if (vlan_entries < 1)
 			continue;
-- 
2.17.1


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

* Re: [PATCH] net: batman-adv: Use built-in RCU list checking
  2020-02-16 14:47 [PATCH] net: batman-adv: Use built-in RCU list checking madhuparnabhowmik10
@ 2020-02-16 15:22 ` Sven Eckelmann
  2020-02-16 15:33   ` Madhuparna Bhowmik
  0 siblings, 1 reply; 7+ messages in thread
From: Sven Eckelmann @ 2020-02-16 15:22 UTC (permalink / raw)
  To: madhuparnabhowmik10
  Cc: mareklindner, sw, a, davem, b.a.t.m.a.n, netdev, linux-kernel,
	joel, frextrite, linux-kernel-mentees

[-- Attachment #1: Type: text/plain, Size: 778 bytes --]

On Sunday, 16 February 2020 15:47:18 CET madhuparnabhowmik10@gmail.com wrote:
> From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
> 
> hlist_for_each_entry_rcu() has built-in RCU and lock checking.
> 
> Pass cond argument to hlist_for_each_entry_rcu() to silence
> false lockdep warnings when CONFIG_PROVE_RCU_LIST is enabled
> by default.
> 
> Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
> ---
>  net/batman-adv/translation-table.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)

Added with alignment and line length codingstyle fixes [1].

Can you tell us how you've identified these four hlist_for_each_entry_rcu?

Thanks,
	Sven

[1] https://git.open-mesh.org/linux-merge.git/commit/967709ec53a07d1bccbc3716f7e979d3103bd7c5

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] net: batman-adv: Use built-in RCU list checking
  2020-02-16 15:22 ` Sven Eckelmann
@ 2020-02-16 15:33   ` Madhuparna Bhowmik
  2020-02-16 15:35     ` Sven Eckelmann
  0 siblings, 1 reply; 7+ messages in thread
From: Madhuparna Bhowmik @ 2020-02-16 15:33 UTC (permalink / raw)
  To: Sven Eckelmann
  Cc: madhuparnabhowmik10, mareklindner, sw, a, davem, b.a.t.m.a.n,
	netdev, linux-kernel, joel, frextrite, linux-kernel-mentees

On Sun, Feb 16, 2020 at 04:22:51PM +0100, Sven Eckelmann wrote:
> On Sunday, 16 February 2020 15:47:18 CET madhuparnabhowmik10@gmail.com wrote:
> > From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
> > 
> > hlist_for_each_entry_rcu() has built-in RCU and lock checking.
> > 
> > Pass cond argument to hlist_for_each_entry_rcu() to silence
> > false lockdep warnings when CONFIG_PROVE_RCU_LIST is enabled
> > by default.
> > 
> > Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
> > ---
> >  net/batman-adv/translation-table.c | 12 ++++++++----
> >  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> Added with alignment and line length codingstyle fixes [1].
> 
> Can you tell us how you've identified these four hlist_for_each_entry_rcu?
>
Hi Sven,

Thank you for the fixes.
The other hlist_for_each_entry_rcu() are used under the protection of
rcu_read_lock(). We only need to pass the cond when
hlist_for_each_entry_rcu() is used under a
different lock (not under rcu_red_lock()) because according to the current scheme a lockdep splat
is generated when hlist_for_each_entry_rcu() is used outside of
rcu_read_lock() or the lockdep condition (the cond argument) evaluates
to false. So, we need to pass this cond when it is used under the
protection of spinlock or mutex etc. and not required if rcu_read_lock()
is used.

Thank you,
Madhuparna
> Thanks,
> 	Sven
> 
> [1] https://git.open-mesh.org/linux-merge.git/commit/967709ec53a07d1bccbc3716f7e979d3103bd7c5



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

* Re: [PATCH] net: batman-adv: Use built-in RCU list checking
  2020-02-16 15:33   ` Madhuparna Bhowmik
@ 2020-02-16 15:35     ` Sven Eckelmann
  2020-02-16 15:52       ` Madhuparna Bhowmik
  0 siblings, 1 reply; 7+ messages in thread
From: Sven Eckelmann @ 2020-02-16 15:35 UTC (permalink / raw)
  To: Madhuparna Bhowmik
  Cc: mareklindner, sw, a, davem, b.a.t.m.a.n, netdev, linux-kernel,
	joel, frextrite, linux-kernel-mentees

[-- Attachment #1: Type: text/plain, Size: 861 bytes --]

On Sunday, 16 February 2020 16:33:24 CET Madhuparna Bhowmik wrote:
[...]
> > Can you tell us how you've identified these four hlist_for_each_entry_rcu?
>
> The other hlist_for_each_entry_rcu() are used under the protection of
> rcu_read_lock(). We only need to pass the cond when
> hlist_for_each_entry_rcu() is used under a
> different lock (not under rcu_red_lock()) because according to the current scheme a lockdep splat
> is generated when hlist_for_each_entry_rcu() is used outside of
> rcu_read_lock() or the lockdep condition (the cond argument) evaluates
> to false. So, we need to pass this cond when it is used under the
> protection of spinlock or mutex etc. and not required if rcu_read_lock()
> is used.

I understand this part. I was asking how you've identified them. Did you use 
any tool for that? coccinelle, sparse, ...

Kind regards,
	Sven

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] net: batman-adv: Use built-in RCU list checking
  2020-02-16 15:35     ` Sven Eckelmann
@ 2020-02-16 15:52       ` Madhuparna Bhowmik
  2020-02-16 16:17         ` Sven Eckelmann
  0 siblings, 1 reply; 7+ messages in thread
From: Madhuparna Bhowmik @ 2020-02-16 15:52 UTC (permalink / raw)
  To: Sven Eckelmann
  Cc: Madhuparna Bhowmik, mareklindner, sw, a, davem, b.a.t.m.a.n,
	netdev, linux-kernel, joel, frextrite, linux-kernel-mentees

On Sun, Feb 16, 2020 at 04:35:54PM +0100, Sven Eckelmann wrote:
> On Sunday, 16 February 2020 16:33:24 CET Madhuparna Bhowmik wrote:
> [...]
> > > Can you tell us how you've identified these four hlist_for_each_entry_rcu?
> >
> > The other hlist_for_each_entry_rcu() are used under the protection of
> > rcu_read_lock(). We only need to pass the cond when
> > hlist_for_each_entry_rcu() is used under a
> > different lock (not under rcu_red_lock()) because according to the current scheme a lockdep splat
> > is generated when hlist_for_each_entry_rcu() is used outside of
> > rcu_read_lock() or the lockdep condition (the cond argument) evaluates
> > to false. So, we need to pass this cond when it is used under the
> > protection of spinlock or mutex etc. and not required if rcu_read_lock()
> > is used.
> 
> I understand this part. I was asking how you've identified them. Did you use 
> any tool for that? coccinelle, sparse, ...
>
Hi,

Not really, I did it manually by inspecting each occurence.
Thank you,
Madhuparna

> Kind regards,
> 	Sven



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

* Re: [PATCH] net: batman-adv: Use built-in RCU list checking
  2020-02-16 15:52       ` Madhuparna Bhowmik
@ 2020-02-16 16:17         ` Sven Eckelmann
  2020-02-17 12:05           ` Madhuparna Bhowmik
  0 siblings, 1 reply; 7+ messages in thread
From: Sven Eckelmann @ 2020-02-16 16:17 UTC (permalink / raw)
  To: Madhuparna Bhowmik
  Cc: mareklindner, sw, a, davem, b.a.t.m.a.n, netdev, linux-kernel,
	joel, frextrite, linux-kernel-mentees

[-- Attachment #1: Type: text/plain, Size: 622 bytes --]

On Sunday, 16 February 2020 16:52:44 CET Madhuparna Bhowmik wrote:
[...]
> > I understand this part. I was asking how you've identified them. Did you use 
> > any tool for that? coccinelle, sparse, ...
> 
> Not really, I did it manually by inspecting each occurence.

In that case, I don't understand why you didn't convert the occurrences from 
hlist_for_each_entry_rcu to hlist_for_each_entry [1]. Because a manual
inspection should have noticed that there will always be the lock around
these ones.

KInd regards,
	Sven

[1] https://www.kernel.org/doc/html/v5.6-rc1/RCU/whatisRCU.html#analogy-with-reader-writer-locking

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] net: batman-adv: Use built-in RCU list checking
  2020-02-16 16:17         ` Sven Eckelmann
@ 2020-02-17 12:05           ` Madhuparna Bhowmik
  0 siblings, 0 replies; 7+ messages in thread
From: Madhuparna Bhowmik @ 2020-02-17 12:05 UTC (permalink / raw)
  To: Sven Eckelmann
  Cc: Madhuparna Bhowmik, mareklindner, sw, a, davem, b.a.t.m.a.n,
	netdev, linux-kernel, joel, frextrite, linux-kernel-mentees

On Sun, Feb 16, 2020 at 05:17:36PM +0100, Sven Eckelmann wrote:
> On Sunday, 16 February 2020 16:52:44 CET Madhuparna Bhowmik wrote:
> [...]
> > > I understand this part. I was asking how you've identified them. Did you use 
> > > any tool for that? coccinelle, sparse, ...
> > 
> > Not really, I did it manually by inspecting each occurence.
> 
> In that case, I don't understand why you didn't convert the occurrences from 
> hlist_for_each_entry_rcu to hlist_for_each_entry [1]. Because a manual
> inspection should have noticed that there will always be the lock around
> these ones.
>
Hi Sven,
I have been working on similar issues (passing cond argument to
list_for_each_entry_Rcu()). That's why may be I didn't notice that in
this case rcu variant is not required.
Thank you for taking a closer look and fixing it the right way.

Regards,
Madhuparna

> KInd regards,
> 	Sven
> 
> [1] https://www.kernel.org/doc/html/v5.6-rc1/RCU/whatisRCU.html#analogy-with-reader-writer-locking



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

end of thread, other threads:[~2020-02-17 12:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-16 14:47 [PATCH] net: batman-adv: Use built-in RCU list checking madhuparnabhowmik10
2020-02-16 15:22 ` Sven Eckelmann
2020-02-16 15:33   ` Madhuparna Bhowmik
2020-02-16 15:35     ` Sven Eckelmann
2020-02-16 15:52       ` Madhuparna Bhowmik
2020-02-16 16:17         ` Sven Eckelmann
2020-02-17 12:05           ` Madhuparna Bhowmik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox