hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/net/xfrm/xfrm_ipcomp.c
....@@ -1,13 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * IP Payload Compression Protocol (IPComp) - RFC3173.
34 *
45 * Copyright (c) 2003 James Morris <jmorris@intercode.com.au>
56 * Copyright (c) 2003-2008 Herbert Xu <herbert@gondor.apana.org.au>
6
- *
7
- * This program is free software; you can redistribute it and/or modify it
8
- * under the terms of the GNU General Public License as published by the Free
9
- * Software Foundation; either version 2 of the License, or (at your option)
10
- * any later version.
117 *
128 * Todo:
139 * - Tunable compression parameters.
....@@ -20,7 +16,6 @@
2016 #include <linux/list.h>
2117 #include <linux/module.h>
2218 #include <linux/mutex.h>
23
-#include <linux/locallock.h>
2419 #include <linux/percpu.h>
2520 #include <linux/slab.h>
2621 #include <linux/smp.h>
....@@ -37,7 +32,6 @@
3732
3833 static DEFINE_MUTEX(ipcomp_resource_mutex);
3934 static void * __percpu *ipcomp_scratches;
40
-static DEFINE_LOCAL_IRQ_LOCK(ipcomp_scratches_lock);
4135 static int ipcomp_scratch_users;
4236 static LIST_HEAD(ipcomp_tfms_list);
4337
....@@ -47,15 +41,12 @@
4741 const int plen = skb->len;
4842 int dlen = IPCOMP_SCRATCH_SIZE;
4943 const u8 *start = skb->data;
50
- u8 *scratch;
51
- struct crypto_comp *tfm;
52
- int err, len;
44
+ const int cpu = get_cpu();
45
+ u8 *scratch = *per_cpu_ptr(ipcomp_scratches, cpu);
46
+ struct crypto_comp *tfm = *per_cpu_ptr(ipcd->tfms, cpu);
47
+ int err = crypto_comp_decompress(tfm, start, plen, scratch, &dlen);
48
+ int len;
5349
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);
5950 if (err)
6051 goto out;
6152
....@@ -94,7 +85,7 @@
9485 if (dlen < len)
9586 len = dlen;
9687
97
- frag->page_offset = 0;
88
+ skb_frag_off_set(frag, 0);
9889 skb_frag_size_set(frag, len);
9990 memcpy(skb_frag_address(frag), scratch, len);
10091
....@@ -108,7 +99,7 @@
10899 err = 0;
109100
110101 out:
111
- local_unlock(ipcomp_scratches_lock);
102
+ put_cpu();
112103 return err;
113104 }
114105
....@@ -151,8 +142,6 @@
151142 int err;
152143
153144 local_bh_disable();
154
- local_lock(ipcomp_scratches_lock);
155
-
156145 scratch = *this_cpu_ptr(ipcomp_scratches);
157146 tfm = *this_cpu_ptr(ipcd->tfms);
158147 err = crypto_comp_compress(tfm, start, plen, scratch, &dlen);
....@@ -165,14 +154,12 @@
165154 }
166155
167156 memcpy(start + sizeof(struct ip_comp_hdr), scratch, dlen);
168
- local_unlock(ipcomp_scratches_lock);
169157 local_bh_enable();
170158
171159 pskb_trim(skb, dlen + sizeof(struct ip_comp_hdr));
172160 return 0;
173161
174162 out:
175
- local_unlock(ipcomp_scratches_lock);
176163 local_bh_enable();
177164 return err;
178165 }
....@@ -225,6 +212,7 @@
225212 vfree(*per_cpu_ptr(scratches, i));
226213
227214 free_percpu(scratches);
215
+ ipcomp_scratches = NULL;
228216 }
229217
230218 static void * __percpu *ipcomp_alloc_scratches(void)
....@@ -263,7 +251,7 @@
263251 break;
264252 }
265253
266
- WARN_ON(!pos);
254
+ WARN_ON(list_entry_is_head(pos, &ipcomp_tfms_list, list));
267255
268256 if (--pos->users)
269257 return;