aboutsummaryrefslogtreecommitdiffstats
path: root/net/xfrm
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2016-08-11 09:17:59 -0400
committerSteffen Klassert <steffen.klassert@secunet.com>2016-08-12 02:07:12 -0400
commit9d0380df6217e8dd014118fa1c99dda9974f3613 (patch)
treed3cb885fa28fcde230a154b465bb69bd22f9a29c /net/xfrm
parentd5b8f86dc7200d16e48bb3a6aaac29c0cdf621c9 (diff)
xfrm: policy: convert policy_lock to spinlock
After earlier patches conversions all spots acquire the writer lock and we can now convert this to a normal spinlock. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Diffstat (limited to 'net/xfrm')
-rw-r--r--net/xfrm/xfrm_policy.c68
1 files changed, 34 insertions, 34 deletions
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 35b85a9a358c..dd01fd2e55fa 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -484,7 +484,7 @@ static void xfrm_bydst_resize(struct net *net, int dir)
484 if (!ndst) 484 if (!ndst)
485 return; 485 return;
486 486
487 write_lock_bh(&net->xfrm.xfrm_policy_lock); 487 spin_lock_bh(&net->xfrm.xfrm_policy_lock);
488 write_seqcount_begin(&xfrm_policy_hash_generation); 488 write_seqcount_begin(&xfrm_policy_hash_generation);
489 489
490 odst = rcu_dereference_protected(net->xfrm.policy_bydst[dir].table, 490 odst = rcu_dereference_protected(net->xfrm.policy_bydst[dir].table,
@@ -500,7 +500,7 @@ static void xfrm_bydst_resize(struct net *net, int dir)
500 net->xfrm.policy_bydst[dir].hmask = nhashmask; 500 net->xfrm.policy_bydst[dir].hmask = nhashmask;
501 501
502 write_seqcount_end(&xfrm_policy_hash_generation); 502 write_seqcount_end(&xfrm_policy_hash_generation);
503 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 503 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
504 504
505 synchronize_rcu(); 505 synchronize_rcu();
506 506
@@ -519,7 +519,7 @@ static void xfrm_byidx_resize(struct net *net, int total)
519 if (!nidx) 519 if (!nidx)
520 return; 520 return;
521 521
522 write_lock_bh(&net->xfrm.xfrm_policy_lock); 522 spin_lock_bh(&net->xfrm.xfrm_policy_lock);
523 523
524 for (i = hmask; i >= 0; i--) 524 for (i = hmask; i >= 0; i--)
525 xfrm_idx_hash_transfer(oidx + i, nidx, nhashmask); 525 xfrm_idx_hash_transfer(oidx + i, nidx, nhashmask);
@@ -527,7 +527,7 @@ static void xfrm_byidx_resize(struct net *net, int total)
527 net->xfrm.policy_byidx = nidx; 527 net->xfrm.policy_byidx = nidx;
528 net->xfrm.policy_idx_hmask = nhashmask; 528 net->xfrm.policy_idx_hmask = nhashmask;
529 529
530 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 530 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
531 531
532 xfrm_hash_free(oidx, (hmask + 1) * sizeof(struct hlist_head)); 532 xfrm_hash_free(oidx, (hmask + 1) * sizeof(struct hlist_head));
533} 533}
@@ -617,7 +617,7 @@ static void xfrm_hash_rebuild(struct work_struct *work)
617 rbits6 = net->xfrm.policy_hthresh.rbits6; 617 rbits6 = net->xfrm.policy_hthresh.rbits6;
618 } while (read_seqretry(&net->xfrm.policy_hthresh.lock, seq)); 618 } while (read_seqretry(&net->xfrm.policy_hthresh.lock, seq));
619 619
620 write_lock_bh(&net->xfrm.xfrm_policy_lock); 620 spin_lock_bh(&net->xfrm.xfrm_policy_lock);
621 621
622 /* reset the bydst and inexact table in all directions */ 622 /* reset the bydst and inexact table in all directions */
623 for (dir = 0; dir < XFRM_POLICY_MAX; dir++) { 623 for (dir = 0; dir < XFRM_POLICY_MAX; dir++) {
@@ -659,7 +659,7 @@ static void xfrm_hash_rebuild(struct work_struct *work)
659 hlist_add_head(&policy->bydst, chain); 659 hlist_add_head(&policy->bydst, chain);
660 } 660 }
661 661
662 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 662 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
663 663
664 mutex_unlock(&hash_resize_mutex); 664 mutex_unlock(&hash_resize_mutex);
665} 665}
@@ -770,7 +770,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
770 struct hlist_head *chain; 770 struct hlist_head *chain;
771 struct hlist_node *newpos; 771 struct hlist_node *newpos;
772 772
773 write_lock_bh(&net->xfrm.xfrm_policy_lock); 773 spin_lock_bh(&net->xfrm.xfrm_policy_lock);
774 chain = policy_hash_bysel(net, &policy->selector, policy->family, dir); 774 chain = policy_hash_bysel(net, &policy->selector, policy->family, dir);
775 delpol = NULL; 775 delpol = NULL;
776 newpos = NULL; 776 newpos = NULL;
@@ -781,7 +781,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
781 xfrm_sec_ctx_match(pol->security, policy->security) && 781 xfrm_sec_ctx_match(pol->security, policy->security) &&
782 !WARN_ON(delpol)) { 782 !WARN_ON(delpol)) {
783 if (excl) { 783 if (excl) {
784 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 784 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
785 return -EEXIST; 785 return -EEXIST;
786 } 786 }
787 delpol = pol; 787 delpol = pol;
@@ -817,7 +817,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
817 policy->curlft.use_time = 0; 817 policy->curlft.use_time = 0;
818 if (!mod_timer(&policy->timer, jiffies + HZ)) 818 if (!mod_timer(&policy->timer, jiffies + HZ))
819 xfrm_pol_hold(policy); 819 xfrm_pol_hold(policy);
820 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 820 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
821 821
822 if (delpol) 822 if (delpol)
823 xfrm_policy_kill(delpol); 823 xfrm_policy_kill(delpol);
@@ -837,7 +837,7 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark, u8 type,
837 struct hlist_head *chain; 837 struct hlist_head *chain;
838 838
839 *err = 0; 839 *err = 0;
840 write_lock_bh(&net->xfrm.xfrm_policy_lock); 840 spin_lock_bh(&net->xfrm.xfrm_policy_lock);
841 chain = policy_hash_bysel(net, sel, sel->family, dir); 841 chain = policy_hash_bysel(net, sel, sel->family, dir);
842 ret = NULL; 842 ret = NULL;
843 hlist_for_each_entry(pol, chain, bydst) { 843 hlist_for_each_entry(pol, chain, bydst) {
@@ -850,7 +850,7 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark, u8 type,
850 *err = security_xfrm_policy_delete( 850 *err = security_xfrm_policy_delete(
851 pol->security); 851 pol->security);
852 if (*err) { 852 if (*err) {
853 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 853 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
854 return pol; 854 return pol;
855 } 855 }
856 __xfrm_policy_unlink(pol, dir); 856 __xfrm_policy_unlink(pol, dir);
@@ -859,7 +859,7 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark, u8 type,
859 break; 859 break;
860 } 860 }
861 } 861 }
862 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 862 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
863 863
864 if (ret && delete) 864 if (ret && delete)
865 xfrm_policy_kill(ret); 865 xfrm_policy_kill(ret);
@@ -878,7 +878,7 @@ struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8 type,
878 return NULL; 878 return NULL;
879 879
880 *err = 0; 880 *err = 0;
881 write_lock_bh(&net->xfrm.xfrm_policy_lock); 881 spin_lock_bh(&net->xfrm.xfrm_policy_lock);
882 chain = net->xfrm.policy_byidx + idx_hash(net, id); 882 chain = net->xfrm.policy_byidx + idx_hash(net, id);
883 ret = NULL; 883 ret = NULL;
884 hlist_for_each_entry(pol, chain, byidx) { 884 hlist_for_each_entry(pol, chain, byidx) {
@@ -889,7 +889,7 @@ struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8 type,
889 *err = security_xfrm_policy_delete( 889 *err = security_xfrm_policy_delete(
890 pol->security); 890 pol->security);
891 if (*err) { 891 if (*err) {
892 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 892 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
893 return pol; 893 return pol;
894 } 894 }
895 __xfrm_policy_unlink(pol, dir); 895 __xfrm_policy_unlink(pol, dir);
@@ -898,7 +898,7 @@ struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8 type,
898 break; 898 break;
899 } 899 }
900 } 900 }
901 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 901 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
902 902
903 if (ret && delete) 903 if (ret && delete)
904 xfrm_policy_kill(ret); 904 xfrm_policy_kill(ret);
@@ -956,7 +956,7 @@ int xfrm_policy_flush(struct net *net, u8 type, bool task_valid)
956{ 956{
957 int dir, err = 0, cnt = 0; 957 int dir, err = 0, cnt = 0;
958 958
959 write_lock_bh(&net->xfrm.xfrm_policy_lock); 959 spin_lock_bh(&net->xfrm.xfrm_policy_lock);
960 960
961 err = xfrm_policy_flush_secctx_check(net, type, task_valid); 961 err = xfrm_policy_flush_secctx_check(net, type, task_valid);
962 if (err) 962 if (err)
@@ -972,14 +972,14 @@ int xfrm_policy_flush(struct net *net, u8 type, bool task_valid)
972 if (pol->type != type) 972 if (pol->type != type)
973 continue; 973 continue;
974 __xfrm_policy_unlink(pol, dir); 974 __xfrm_policy_unlink(pol, dir);
975 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 975 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
976 cnt++; 976 cnt++;
977 977
978 xfrm_audit_policy_delete(pol, 1, task_valid); 978 xfrm_audit_policy_delete(pol, 1, task_valid);
979 979
980 xfrm_policy_kill(pol); 980 xfrm_policy_kill(pol);
981 981
982 write_lock_bh(&net->xfrm.xfrm_policy_lock); 982 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
983 goto again1; 983 goto again1;
984 } 984 }
985 985
@@ -991,13 +991,13 @@ int xfrm_policy_flush(struct net *net, u8 type, bool task_valid)
991 if (pol->type != type) 991 if (pol->type != type)
992 continue; 992 continue;
993 __xfrm_policy_unlink(pol, dir); 993 __xfrm_policy_unlink(pol, dir);
994 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 994 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
995 cnt++; 995 cnt++;
996 996
997 xfrm_audit_policy_delete(pol, 1, task_valid); 997 xfrm_audit_policy_delete(pol, 1, task_valid);
998 xfrm_policy_kill(pol); 998 xfrm_policy_kill(pol);
999 999
1000 write_lock_bh(&net->xfrm.xfrm_policy_lock); 1000 spin_lock_bh(&net->xfrm.xfrm_policy_lock);
1001 goto again2; 1001 goto again2;
1002 } 1002 }
1003 } 1003 }
@@ -1006,7 +1006,7 @@ int xfrm_policy_flush(struct net *net, u8 type, bool task_valid)
1006 if (!cnt) 1006 if (!cnt)
1007 err = -ESRCH; 1007 err = -ESRCH;
1008out: 1008out:
1009 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 1009 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
1010 return err; 1010 return err;
1011} 1011}
1012EXPORT_SYMBOL(xfrm_policy_flush); 1012EXPORT_SYMBOL(xfrm_policy_flush);
@@ -1026,7 +1026,7 @@ int xfrm_policy_walk(struct net *net, struct xfrm_policy_walk *walk,
1026 if (list_empty(&walk->walk.all) && walk->seq != 0) 1026 if (list_empty(&walk->walk.all) && walk->seq != 0)
1027 return 0; 1027 return 0;
1028 1028
1029 write_lock_bh(&net->xfrm.xfrm_policy_lock); 1029 spin_lock_bh(&net->xfrm.xfrm_policy_lock);
1030 if (list_empty(&walk->walk.all)) 1030 if (list_empty(&walk->walk.all))
1031 x = list_first_entry(&net->xfrm.policy_all, struct xfrm_policy_walk_entry, all); 1031 x = list_first_entry(&net->xfrm.policy_all, struct xfrm_policy_walk_entry, all);
1032 else 1032 else
@@ -1054,7 +1054,7 @@ int xfrm_policy_walk(struct net *net, struct xfrm_policy_walk *walk,
1054 } 1054 }
1055 list_del_init(&walk->walk.all); 1055 list_del_init(&walk->walk.all);
1056out: 1056out:
1057 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 1057 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
1058 return error; 1058 return error;
1059} 1059}
1060EXPORT_SYMBOL(xfrm_policy_walk); 1060EXPORT_SYMBOL(xfrm_policy_walk);
@@ -1073,9 +1073,9 @@ void xfrm_policy_walk_done(struct xfrm_policy_walk *walk, struct net *net)
1073 if (list_empty(&walk->walk.all)) 1073 if (list_empty(&walk->walk.all))
1074 return; 1074 return;
1075 1075
1076 write_lock_bh(&net->xfrm.xfrm_policy_lock); /*FIXME where is net? */ 1076 spin_lock_bh(&net->xfrm.xfrm_policy_lock); /*FIXME where is net? */
1077 list_del(&walk->walk.all); 1077 list_del(&walk->walk.all);
1078 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 1078 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
1079} 1079}
1080EXPORT_SYMBOL(xfrm_policy_walk_done); 1080EXPORT_SYMBOL(xfrm_policy_walk_done);
1081 1081
@@ -1321,9 +1321,9 @@ int xfrm_policy_delete(struct xfrm_policy *pol, int dir)
1321{ 1321{
1322 struct net *net = xp_net(pol); 1322 struct net *net = xp_net(pol);
1323 1323
1324 write_lock_bh(&net->xfrm.xfrm_policy_lock); 1324 spin_lock_bh(&net->xfrm.xfrm_policy_lock);
1325 pol = __xfrm_policy_unlink(pol, dir); 1325 pol = __xfrm_policy_unlink(pol, dir);
1326 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 1326 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
1327 if (pol) { 1327 if (pol) {
1328 xfrm_policy_kill(pol); 1328 xfrm_policy_kill(pol);
1329 return 0; 1329 return 0;
@@ -1342,7 +1342,7 @@ int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol)
1342 return -EINVAL; 1342 return -EINVAL;
1343#endif 1343#endif
1344 1344
1345 write_lock_bh(&net->xfrm.xfrm_policy_lock); 1345 spin_lock_bh(&net->xfrm.xfrm_policy_lock);
1346 old_pol = rcu_dereference_protected(sk->sk_policy[dir], 1346 old_pol = rcu_dereference_protected(sk->sk_policy[dir],
1347 lockdep_is_held(&net->xfrm.xfrm_policy_lock)); 1347 lockdep_is_held(&net->xfrm.xfrm_policy_lock));
1348 if (pol) { 1348 if (pol) {
@@ -1360,7 +1360,7 @@ int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol)
1360 */ 1360 */
1361 xfrm_sk_policy_unlink(old_pol, dir); 1361 xfrm_sk_policy_unlink(old_pol, dir);
1362 } 1362 }
1363 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 1363 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
1364 1364
1365 if (old_pol) { 1365 if (old_pol) {
1366 xfrm_policy_kill(old_pol); 1366 xfrm_policy_kill(old_pol);
@@ -1390,9 +1390,9 @@ static struct xfrm_policy *clone_policy(const struct xfrm_policy *old, int dir)
1390 newp->type = old->type; 1390 newp->type = old->type;
1391 memcpy(newp->xfrm_vec, old->xfrm_vec, 1391 memcpy(newp->xfrm_vec, old->xfrm_vec,
1392 newp->xfrm_nr*sizeof(struct xfrm_tmpl)); 1392 newp->xfrm_nr*sizeof(struct xfrm_tmpl));
1393 write_lock_bh(&net->xfrm.xfrm_policy_lock); 1393 spin_lock_bh(&net->xfrm.xfrm_policy_lock);
1394 xfrm_sk_policy_link(newp, dir); 1394 xfrm_sk_policy_link(newp, dir);
1395 write_unlock_bh(&net->xfrm.xfrm_policy_lock); 1395 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
1396 xfrm_pol_put(newp); 1396 xfrm_pol_put(newp);
1397 } 1397 }
1398 return newp; 1398 return newp;
@@ -3074,7 +3074,7 @@ static int __net_init xfrm_net_init(struct net *net)
3074 3074
3075 /* Initialize the per-net locks here */ 3075 /* Initialize the per-net locks here */
3076 spin_lock_init(&net->xfrm.xfrm_state_lock); 3076 spin_lock_init(&net->xfrm.xfrm_state_lock);
3077 rwlock_init(&net->xfrm.xfrm_policy_lock); 3077 spin_lock_init(&net->xfrm.xfrm_policy_lock);
3078 mutex_init(&net->xfrm.xfrm_cfg_mutex); 3078 mutex_init(&net->xfrm.xfrm_cfg_mutex);
3079 3079
3080 return 0; 3080 return 0;
@@ -3206,7 +3206,7 @@ static struct xfrm_policy *xfrm_migrate_policy_find(const struct xfrm_selector *
3206 struct hlist_head *chain; 3206 struct hlist_head *chain;
3207 u32 priority = ~0U; 3207 u32 priority = ~0U;
3208 3208
3209 read_lock_bh(&net->xfrm.xfrm_policy_lock); /*FIXME*/ 3209 spin_lock_bh(&net->xfrm.xfrm_policy_lock);
3210 chain = policy_hash_direct(net, &sel->daddr, &sel->saddr, sel->family, dir); 3210 chain = policy_hash_direct(net, &sel->daddr, &sel->saddr, sel->family, dir);
3211 hlist_for_each_entry(pol, chain, bydst) { 3211 hlist_for_each_entry(pol, chain, bydst) {
3212 if (xfrm_migrate_selector_match(sel, &pol->selector) && 3212 if (xfrm_migrate_selector_match(sel, &pol->selector) &&
@@ -3230,7 +3230,7 @@ static struct xfrm_policy *xfrm_migrate_policy_find(const struct xfrm_selector *
3230 3230
3231 xfrm_pol_hold(ret); 3231 xfrm_pol_hold(ret);
3232 3232
3233 read_unlock_bh(&net->xfrm.xfrm_policy_lock); 3233 spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
3234 3234
3235 return ret; 3235 return ret;
3236} 3236}