hc
2023-11-23 7d07b3ae8ddad407913c5301877e694430a3263f
kernel/net/xfrm/xfrm_ipcomp.c
....@@ -20,6 +20,7 @@
2020 #include <linux/list.h>
2121 #include <linux/module.h>
2222 #include <linux/mutex.h>
23
+#include <linux/locallock.h>
2324 #include <linux/percpu.h>
2425 #include <linux/slab.h>
2526 #include <linux/smp.h>
....@@ -36,6 +37,7 @@
3637
3738 static DEFINE_MUTEX(ipcomp_resource_mutex);
3839 static void * __percpu *ipcomp_scratches;
40
+static DEFINE_LOCAL_IRQ_LOCK(ipcomp_scratches_lock);
3941 static int ipcomp_scratch_users;
4042 static LIST_HEAD(ipcomp_tfms_list);
4143
....@@ -45,12 +47,15 @@
4547 const int plen = skb->len;
4648 int dlen = IPCOMP_SCRATCH_SIZE;
4749 const u8 *start = skb->data;
48
- const int cpu = get_cpu();
49
- u8 *scratch = *per_cpu_ptr(ipcomp_scratches, cpu);
50
- struct crypto_comp *tfm = *per_cpu_ptr(ipcd->tfms, cpu);
51
- int err = crypto_comp_decompress(tfm, start, plen, scratch, &dlen);
52
- int len;
50
+ u8 *scratch;
51
+ struct crypto_comp *tfm;
52
+ int err, len;
5353
54
+ local_lock(ipcomp_scratches_lock);
55
+
56
+ scratch = *this_cpu_ptr(ipcomp_scratches);
57
+ tfm = *this_cpu_ptr(ipcd->tfms);
58
+ err = crypto_comp_decompress(tfm, start, plen, scratch, &dlen);
5459 if (err)
5560 goto out;
5661
....@@ -103,7 +108,7 @@
103108 err = 0;
104109
105110 out:
106
- put_cpu();
111
+ local_unlock(ipcomp_scratches_lock);
107112 return err;
108113 }
109114
....@@ -146,6 +151,8 @@
146151 int err;
147152
148153 local_bh_disable();
154
+ local_lock(ipcomp_scratches_lock);
155
+
149156 scratch = *this_cpu_ptr(ipcomp_scratches);
150157 tfm = *this_cpu_ptr(ipcd->tfms);
151158 err = crypto_comp_compress(tfm, start, plen, scratch, &dlen);
....@@ -158,12 +165,14 @@
158165 }
159166
160167 memcpy(start + sizeof(struct ip_comp_hdr), scratch, dlen);
168
+ local_unlock(ipcomp_scratches_lock);
161169 local_bh_enable();
162170
163171 pskb_trim(skb, dlen + sizeof(struct ip_comp_hdr));
164172 return 0;
165173
166174 out:
175
+ local_unlock(ipcomp_scratches_lock);
167176 local_bh_enable();
168177 return err;
169178 }