@@ -512,7 +512,8 @@ __lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned int id)
512
512
{
513
513
struct mptcp_pm_addr_entry * entry ;
514
514
515
- list_for_each_entry (entry , & pernet -> local_addr_list , list ) {
515
+ list_for_each_entry_rcu (entry , & pernet -> local_addr_list , list ,
516
+ lockdep_is_held (& pernet -> lock )) {
516
517
if (entry -> addr .id == id )
517
518
return entry ;
518
519
}
@@ -1142,17 +1143,13 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc
1142
1143
{
1143
1144
struct mptcp_pm_addr_entry * entry ;
1144
1145
struct pm_nl_pernet * pernet ;
1145
- int ret = -1 ;
1146
+ int ret ;
1146
1147
1147
1148
pernet = pm_nl_get_pernet_from_msk (msk );
1148
1149
1149
1150
rcu_read_lock ();
1150
- list_for_each_entry_rcu (entry , & pernet -> local_addr_list , list ) {
1151
- if (mptcp_addresses_equal (& entry -> addr , skc , entry -> addr .port )) {
1152
- ret = entry -> addr .id ;
1153
- break ;
1154
- }
1155
- }
1151
+ entry = __lookup_addr (pernet , skc );
1152
+ ret = entry ? entry -> addr .id : -1 ;
1156
1153
rcu_read_unlock ();
1157
1154
if (ret >= 0 )
1158
1155
return ret ;
@@ -1179,15 +1176,11 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc)
1179
1176
{
1180
1177
struct pm_nl_pernet * pernet = pm_nl_get_pernet_from_msk (msk );
1181
1178
struct mptcp_pm_addr_entry * entry ;
1182
- bool backup = false ;
1179
+ bool backup ;
1183
1180
1184
1181
rcu_read_lock ();
1185
- list_for_each_entry_rcu (entry , & pernet -> local_addr_list , list ) {
1186
- if (mptcp_addresses_equal (& entry -> addr , skc , entry -> addr .port )) {
1187
- backup = !!(entry -> flags & MPTCP_PM_ADDR_FLAG_BACKUP );
1188
- break ;
1189
- }
1190
- }
1182
+ entry = __lookup_addr (pernet , skc );
1183
+ backup = entry && !!(entry -> flags & MPTCP_PM_ADDR_FLAG_BACKUP );
1191
1184
rcu_read_unlock ();
1192
1185
1193
1186
return backup ;
@@ -1824,7 +1817,7 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)
1824
1817
goto fail ;
1825
1818
}
1826
1819
1827
- spin_lock_bh ( & pernet -> lock );
1820
+ rcu_read_lock ( );
1828
1821
entry = __lookup_addr_by_id (pernet , addr .addr .id );
1829
1822
if (!entry ) {
1830
1823
GENL_SET_ERR_MSG (info , "address not found" );
@@ -1838,11 +1831,11 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)
1838
1831
1839
1832
genlmsg_end (msg , reply );
1840
1833
ret = genlmsg_reply (msg , info );
1841
- spin_unlock_bh ( & pernet -> lock );
1834
+ rcu_read_unlock ( );
1842
1835
return ret ;
1843
1836
1844
1837
unlock_fail :
1845
- spin_unlock_bh ( & pernet -> lock );
1838
+ rcu_read_unlock ( );
1846
1839
1847
1840
fail :
1848
1841
nlmsg_free (msg );
@@ -1866,7 +1859,7 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
1866
1859
1867
1860
pernet = pm_nl_get_pernet (net );
1868
1861
1869
- spin_lock_bh ( & pernet -> lock );
1862
+ rcu_read_lock ( );
1870
1863
for (i = id ; i < MPTCP_PM_MAX_ADDR_ID + 1 ; i ++ ) {
1871
1864
if (test_bit (i , pernet -> id_bitmap )) {
1872
1865
entry = __lookup_addr_by_id (pernet , i );
@@ -1891,7 +1884,7 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
1891
1884
genlmsg_end (msg , hdr );
1892
1885
}
1893
1886
}
1894
- spin_unlock_bh ( & pernet -> lock );
1887
+ rcu_read_unlock ( );
1895
1888
1896
1889
cb -> args [0 ] = id ;
1897
1890
return msg -> len ;
0 commit comments