net: batman-adv: Use built-in RCU list checking
Subsystems (3)
PATCH 1/1 net: batman-adv: Use built-in RCU list checking
From: Madhuparna Bhowmik <[email protected]>
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.
--- net/batman-adv/translation-table.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
net/batman-adv/translation-table.c +8 -4
@@ -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 ;
Signature · 1 line
2.17.1
Sven Eckelmann
maintainerQuoted 4 lines · On Sunday, 16 February 2020 15:47:18 CET [email protected] wrote:
From: Madhuparna Bhowmik <[email protected]>
hlist_for_each_entry_rcu()has built-in RCU and lock checking.
Quoted 8 lines
Pass cond argument to
hlist_for_each_entry_rcu()to silence false lockdep warnings whenCONFIG_PROVE_RCU_LISTis enabled by default.Signed-off-by Madhuparna Bhowmik <[email protected]>--- 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
Quoted 9 lines · Sven Eckelmann
Quoted 8 lines · On Sunday, 16 February 2020 15:47:18 CET [email protected] wrote:
From: Madhuparna Bhowmik <[email protected]>
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 whenCONFIG_PROVE_RCU_LISTis enabled by default.
Quoted 9 lines
Quoted 4 lines
Signed-off-by Madhuparna Bhowmik <[email protected]>--- 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 whenhlist_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 ofrcu_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
Quoted 4 lines
Thanks,
Sven[1] https://git.open-mesh.org/linux-merge.git/commit/967709ec53a07d1bccbc3716f7e979d3103bd7c5
Sven Eckelmann
maintainerOn Sunday, 16 February 2020 16:33:24 CET Madhuparna Bhowmik wrote:
[...]
Quoted 11 lines
Quoted 1 line
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 ofrcu_read_lock(). We only need to pass the cond whenhlist_for_each_entry_rcu()is used under a
different lock (not underrcu_red_lock()) because according to the current scheme a lockdep splat is generated whenhlist_for_each_entry_rcu()is used outside ofrcu_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 ifrcu_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
Quoted 14 lines · Sven Eckelmann
On Sunday, 16 February 2020 16:33:24 CET Madhuparna Bhowmik wrote:
[...]Quoted 11 lines
Quoted 1 line
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 ofrcu_read_lock(). We only need to pass the cond whenhlist_for_each_entry_rcu()is used under a
different lock (not underrcu_red_lock()) because according to the current scheme a lockdep splat is generated whenhlist_for_each_entry_rcu()is used outside ofrcu_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 ifrcu_read_lock()
is used.
Quoted 3 lines
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
Quoted 2 lines
Kind regards,
Sven
Sven Eckelmann
maintainerOn Sunday, 16 February 2020 16:52:44 CET Madhuparna Bhowmik wrote:
[...]
Quoted 4 lines
Quoted 2 lines
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
Quoted 5 lines · Sven Eckelmann
On Sunday, 16 February 2020 16:52:44 CET Madhuparna Bhowmik wrote:
[...]Quoted 3 lines
Quoted 2 lines
I understand this part. I was asking how you've identified them. Did you use any tool for that? coccinelle, sparse, ...
Quoted 7 lines
Quoted 1 line
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_rcutohlist_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
Quoted 4 lines
KInd regards,
Sven[1] https://www.kernel.org/doc/html/v5.6-rc1/RCU/whatisRCU.html#analogy-with-reader-writer-locking