aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorDenis V. Lunev <den@openvz.org>2008-02-29 14:17:11 -0500
committerDavid S. Miller <davem@davemloft.net>2008-02-29 14:17:11 -0500
commit79c911595390c8fdc8d8a487ac1951d854b1cd09 (patch)
tree9688e154b321f6c976b2d43abbfd4bb929b18e1a /net
parent405666db84b984b68fc75794069f424c02e5796c (diff)
[ICMP]: Allocate data for __icmp(v6)_sk dynamically.
Own __icmp(v6)_sk should be present in each namespace. So, it should be allocated dynamically. Though, alloc_percpu does not fit the case as it implies additional dereferrence for no bonus. Allocate data for pointers just like __percpu_alloc_mask does and place pointers to struct sock into this array. Signed-off-by: Denis V. Lunev <den@openvz.org> Acked-by: Daniel Lezcano <dlezcano@fr.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/ipv4/icmp.c15
-rw-r--r--net/ipv6/icmp.c14
2 files changed, 19 insertions, 10 deletions
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 9bcf263f06ca..7c62a0da5264 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -229,8 +229,8 @@ static const struct icmp_control icmp_pointers[NR_ICMP_TYPES+1];
229 * 229 *
230 * On SMP we have one ICMP socket per-cpu. 230 * On SMP we have one ICMP socket per-cpu.
231 */ 231 */
232static DEFINE_PER_CPU(struct sock *, __icmp_sk) = NULL; 232static struct sock **__icmp_sk = NULL;
233#define icmp_sk __get_cpu_var(__icmp_sk) 233#define icmp_sk (__icmp_sk[smp_processor_id()])
234 234
235static inline int icmp_xmit_lock(struct sock *sk) 235static inline int icmp_xmit_lock(struct sock *sk)
236{ 236{
@@ -1149,18 +1149,23 @@ static void __exit icmp_exit(void)
1149 for_each_possible_cpu(i) { 1149 for_each_possible_cpu(i) {
1150 struct sock *sk; 1150 struct sock *sk;
1151 1151
1152 sk = per_cpu(__icmp_sk, i); 1152 sk = __icmp_sk[i];
1153 if (sk == NULL) 1153 if (sk == NULL)
1154 continue; 1154 continue;
1155 per_cpu(__icmp_sk, i) = NULL;
1156 sock_release(sk->sk_socket); 1155 sock_release(sk->sk_socket);
1157 } 1156 }
1157 kfree(__icmp_sk);
1158 __icmp_sk = NULL;
1158} 1159}
1159 1160
1160int __init icmp_init(void) 1161int __init icmp_init(void)
1161{ 1162{
1162 int i, err; 1163 int i, err;
1163 1164
1165 __icmp_sk = kzalloc(nr_cpu_ids * sizeof(struct sock *), GFP_KERNEL);
1166 if (__icmp_sk == NULL)
1167 return -ENOMEM;
1168
1164 for_each_possible_cpu(i) { 1169 for_each_possible_cpu(i) {
1165 struct sock *sk; 1170 struct sock *sk;
1166 struct socket *sock; 1171 struct socket *sock;
@@ -1170,7 +1175,7 @@ int __init icmp_init(void)
1170 if (err < 0) 1175 if (err < 0)
1171 goto fail; 1176 goto fail;
1172 1177
1173 per_cpu(__icmp_sk, i) = sk = sock->sk; 1178 __icmp_sk[i] = sk = sock->sk;
1174 sk->sk_allocation = GFP_ATOMIC; 1179 sk->sk_allocation = GFP_ATOMIC;
1175 1180
1176 /* Enough space for 2 64K ICMP packets, including 1181 /* Enough space for 2 64K ICMP packets, including
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index 18f220a04486..3368f32fe226 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -80,8 +80,8 @@ EXPORT_SYMBOL(icmpv6msg_statistics);
80 * 80 *
81 * On SMP we have one ICMP socket per-cpu. 81 * On SMP we have one ICMP socket per-cpu.
82 */ 82 */
83static DEFINE_PER_CPU(struct sock *, __icmpv6_sk) = NULL; 83static struct sock **__icmpv6_sk = NULL;
84#define icmpv6_sk __get_cpu_var(__icmpv6_sk) 84#define icmpv6_sk (__icmpv6_sk[smp_processor_id()])
85 85
86static int icmpv6_rcv(struct sk_buff *skb); 86static int icmpv6_rcv(struct sk_buff *skb);
87 87
@@ -785,6 +785,10 @@ int __init icmpv6_init(void)
785 struct sock *sk; 785 struct sock *sk;
786 int err, i, j; 786 int err, i, j;
787 787
788 __icmpv6_sk = kzalloc(nr_cpu_ids * sizeof(struct sock *), GFP_KERNEL);
789 if (__icmpv6_sk == NULL)
790 return -ENOMEM;
791
788 for_each_possible_cpu(i) { 792 for_each_possible_cpu(i) {
789 struct socket *sock; 793 struct socket *sock;
790 err = sock_create_kern(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6, 794 err = sock_create_kern(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6,
@@ -797,7 +801,7 @@ int __init icmpv6_init(void)
797 goto fail; 801 goto fail;
798 } 802 }
799 803
800 per_cpu(__icmpv6_sk, i) = sk = sock->sk; 804 __icmpv6_sk[i] = sk = sock->sk;
801 sk->sk_allocation = GFP_ATOMIC; 805 sk->sk_allocation = GFP_ATOMIC;
802 /* 806 /*
803 * Split off their lock-class, because sk->sk_dst_lock 807 * Split off their lock-class, because sk->sk_dst_lock
@@ -830,7 +834,7 @@ int __init icmpv6_init(void)
830 for (j = 0; j < i; j++) { 834 for (j = 0; j < i; j++) {
831 if (!cpu_possible(j)) 835 if (!cpu_possible(j))
832 continue; 836 continue;
833 sock_release(per_cpu(__icmpv6_sk, j)->sk_socket); 837 sock_release(__icmpv6_sk[j]->sk_socket);
834 } 838 }
835 839
836 return err; 840 return err;
@@ -841,7 +845,7 @@ void icmpv6_cleanup(void)
841 int i; 845 int i;
842 846
843 for_each_possible_cpu(i) { 847 for_each_possible_cpu(i) {
844 sock_release(per_cpu(__icmpv6_sk, i)->sk_socket); 848 sock_release(__icmpv6_sk[i]->sk_socket);
845 } 849 }
846 inet6_del_protocol(&icmpv6_protocol, IPPROTO_ICMPV6); 850 inet6_del_protocol(&icmpv6_protocol, IPPROTO_ICMPV6);
847} 851}