Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: skcipher - remove support for physical address walks

Since the physical address support in skcipher_walk is not used anymore,
remove all the code associated with it. This includes:

- The skcipher_walk_async() and skcipher_walk_complete() functions;

- The SKCIPHER_WALK_PHYS flag and everything conditional on it;

- The buffers, phys, and virt.page fields in struct skcipher_walk;

- struct skcipher_walk_buffer.

As a result, skcipher_walk now just supports virtual addresses.
Physical address support in skcipher_walk is unneeded because drivers
that need physical addresses just use the scatterlists directly.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Eric Biggers and committed by
Herbert Xu
07d58e0a 9cda46ba

+25 -172
+25 -160
crypto/skcipher.c
··· 17 17 #include <linux/cryptouser.h> 18 18 #include <linux/err.h> 19 19 #include <linux/kernel.h> 20 - #include <linux/list.h> 21 20 #include <linux/mm.h> 22 21 #include <linux/module.h> 23 22 #include <linux/seq_file.h> ··· 28 29 #define CRYPTO_ALG_TYPE_SKCIPHER_MASK 0x0000000e 29 30 30 31 enum { 31 - SKCIPHER_WALK_PHYS = 1 << 0, 32 - SKCIPHER_WALK_SLOW = 1 << 1, 33 - SKCIPHER_WALK_COPY = 1 << 2, 34 - SKCIPHER_WALK_DIFF = 1 << 3, 35 - SKCIPHER_WALK_SLEEP = 1 << 4, 36 - }; 37 - 38 - struct skcipher_walk_buffer { 39 - struct list_head entry; 40 - struct scatter_walk dst; 41 - unsigned int len; 42 - u8 *data; 43 - u8 buffer[]; 32 + SKCIPHER_WALK_SLOW = 1 << 0, 33 + SKCIPHER_WALK_COPY = 1 << 1, 34 + SKCIPHER_WALK_DIFF = 1 << 2, 35 + SKCIPHER_WALK_SLEEP = 1 << 3, 44 36 }; 45 37 46 38 static const struct crypto_type crypto_skcipher_type; ··· 85 95 86 96 addr = (u8 *)ALIGN((unsigned long)walk->buffer, walk->alignmask + 1); 87 97 addr = skcipher_get_spot(addr, bsize); 88 - scatterwalk_copychunks(addr, &walk->out, bsize, 89 - (walk->flags & SKCIPHER_WALK_PHYS) ? 2 : 1); 98 + scatterwalk_copychunks(addr, &walk->out, bsize, 1); 90 99 return 0; 91 100 } 92 101 ··· 102 113 nbytes = walk->total - n; 103 114 } 104 115 105 - if (likely(!(walk->flags & (SKCIPHER_WALK_PHYS | 106 - SKCIPHER_WALK_SLOW | 116 + if (likely(!(walk->flags & (SKCIPHER_WALK_SLOW | 107 117 SKCIPHER_WALK_COPY | 108 118 SKCIPHER_WALK_DIFF)))) { 109 119 unmap_src: ··· 150 162 if (!((unsigned long)walk->buffer | (unsigned long)walk->page)) 151 163 goto out; 152 164 153 - if (walk->flags & SKCIPHER_WALK_PHYS) 154 - goto out; 155 - 156 165 if (walk->iv != walk->oiv) 157 166 memcpy(walk->oiv, walk->iv, walk->ivsize); 158 167 if (walk->buffer != walk->page) ··· 162 177 } 163 178 EXPORT_SYMBOL_GPL(skcipher_walk_done); 164 179 165 - void skcipher_walk_complete(struct skcipher_walk *walk, int err) 166 - { 167 - struct skcipher_walk_buffer *p, *tmp; 168 - 169 - list_for_each_entry_safe(p, tmp, &walk->buffers, entry) { 170 - u8 *data; 171 - 172 - if (err) 173 - goto done; 174 - 175 - data = p->data; 176 - if (!data) { 177 - data = PTR_ALIGN(&p->buffer[0], walk->alignmask + 1); 178 - data = skcipher_get_spot(data, walk->stride); 179 - } 180 - 181 - scatterwalk_copychunks(data, &p->dst, p->len, 1); 182 - 183 - if (offset_in_page(p->data) + p->len + walk->stride > 184 - PAGE_SIZE) 185 - free_page((unsigned long)p->data); 186 - 187 - done: 188 - list_del(&p->entry); 189 - kfree(p); 190 - } 191 - 192 - if (!err && walk->iv != walk->oiv) 193 - memcpy(walk->oiv, walk->iv, walk->ivsize); 194 - if (walk->buffer != walk->page) 195 - kfree(walk->buffer); 196 - if (walk->page) 197 - free_page((unsigned long)walk->page); 198 - } 199 - EXPORT_SYMBOL_GPL(skcipher_walk_complete); 200 - 201 - static void skcipher_queue_write(struct skcipher_walk *walk, 202 - struct skcipher_walk_buffer *p) 203 - { 204 - p->dst = walk->out; 205 - list_add_tail(&p->entry, &walk->buffers); 206 - } 207 - 208 180 static int skcipher_next_slow(struct skcipher_walk *walk, unsigned int bsize) 209 181 { 210 - bool phys = walk->flags & SKCIPHER_WALK_PHYS; 211 182 unsigned alignmask = walk->alignmask; 212 - struct skcipher_walk_buffer *p; 213 183 unsigned a; 214 184 unsigned n; 215 185 u8 *buffer; 216 - void *v; 217 186 218 - if (!phys) { 219 - if (!walk->buffer) 220 - walk->buffer = walk->page; 221 - buffer = walk->buffer; 222 - if (buffer) 223 - goto ok; 224 - } 187 + if (!walk->buffer) 188 + walk->buffer = walk->page; 189 + buffer = walk->buffer; 190 + if (buffer) 191 + goto ok; 225 192 226 193 /* Start with the minimum alignment of kmalloc. */ 227 194 a = crypto_tfm_ctx_alignment() - 1; 228 195 n = bsize; 229 196 230 - if (phys) { 231 - /* Calculate the minimum alignment of p->buffer. */ 232 - a &= (sizeof(*p) ^ (sizeof(*p) - 1)) >> 1; 233 - n += sizeof(*p); 234 - } 235 - 236 - /* Minimum size to align p->buffer by alignmask. */ 197 + /* Minimum size to align buffer by alignmask. */ 237 198 n += alignmask & ~a; 238 199 239 - /* Minimum size to ensure p->buffer does not straddle a page. */ 200 + /* Minimum size to ensure buffer does not straddle a page. */ 240 201 n += (bsize - 1) & ~(alignmask | a); 241 202 242 - v = kzalloc(n, skcipher_walk_gfp(walk)); 243 - if (!v) 203 + buffer = kzalloc(n, skcipher_walk_gfp(walk)); 204 + if (!buffer) 244 205 return skcipher_walk_done(walk, -ENOMEM); 245 - 246 - if (phys) { 247 - p = v; 248 - p->len = bsize; 249 - skcipher_queue_write(walk, p); 250 - buffer = p->buffer; 251 - } else { 252 - walk->buffer = v; 253 - buffer = v; 254 - } 255 - 206 + walk->buffer = buffer; 256 207 ok: 257 208 walk->dst.virt.addr = PTR_ALIGN(buffer, alignmask + 1); 258 209 walk->dst.virt.addr = skcipher_get_spot(walk->dst.virt.addr, bsize); ··· 204 283 205 284 static int skcipher_next_copy(struct skcipher_walk *walk) 206 285 { 207 - struct skcipher_walk_buffer *p; 208 286 u8 *tmp = walk->page; 209 287 210 288 skcipher_map_src(walk); ··· 212 292 213 293 walk->src.virt.addr = tmp; 214 294 walk->dst.virt.addr = tmp; 215 - 216 - if (!(walk->flags & SKCIPHER_WALK_PHYS)) 217 - return 0; 218 - 219 - p = kmalloc(sizeof(*p), skcipher_walk_gfp(walk)); 220 - if (!p) 221 - return -ENOMEM; 222 - 223 - p->data = walk->page; 224 - p->len = walk->nbytes; 225 - skcipher_queue_write(walk, p); 226 - 227 - if (offset_in_page(walk->page) + walk->nbytes + walk->stride > 228 - PAGE_SIZE) 229 - walk->page = NULL; 230 - else 231 - walk->page += walk->nbytes; 232 - 233 295 return 0; 234 296 } 235 297 ··· 219 317 { 220 318 unsigned long diff; 221 319 222 - walk->src.phys.page = scatterwalk_page(&walk->in); 223 - walk->src.phys.offset = offset_in_page(walk->in.offset); 224 - walk->dst.phys.page = scatterwalk_page(&walk->out); 225 - walk->dst.phys.offset = offset_in_page(walk->out.offset); 226 - 227 - if (walk->flags & SKCIPHER_WALK_PHYS) 228 - return 0; 229 - 230 - diff = walk->src.phys.offset - walk->dst.phys.offset; 231 - diff |= walk->src.virt.page - walk->dst.virt.page; 320 + diff = offset_in_page(walk->in.offset) - 321 + offset_in_page(walk->out.offset); 322 + diff |= (u8 *)scatterwalk_page(&walk->in) - 323 + (u8 *)scatterwalk_page(&walk->out); 232 324 233 325 skcipher_map_src(walk); 234 326 walk->dst.virt.addr = walk->src.virt.addr; ··· 239 343 { 240 344 unsigned int bsize; 241 345 unsigned int n; 242 - int err; 243 346 244 347 walk->flags &= ~(SKCIPHER_WALK_SLOW | SKCIPHER_WALK_COPY | 245 348 SKCIPHER_WALK_DIFF); ··· 253 358 return skcipher_walk_done(walk, -EINVAL); 254 359 255 360 slow_path: 256 - err = skcipher_next_slow(walk, bsize); 257 - goto set_phys_lowmem; 361 + return skcipher_next_slow(walk, bsize); 258 362 } 259 363 260 364 if (unlikely((walk->in.offset | walk->out.offset) & walk->alignmask)) { ··· 268 374 walk->nbytes = min_t(unsigned, n, 269 375 PAGE_SIZE - offset_in_page(walk->page)); 270 376 walk->flags |= SKCIPHER_WALK_COPY; 271 - err = skcipher_next_copy(walk); 272 - goto set_phys_lowmem; 377 + return skcipher_next_copy(walk); 273 378 } 274 379 275 380 walk->nbytes = n; 276 381 277 382 return skcipher_next_fast(walk); 278 - 279 - set_phys_lowmem: 280 - if (!err && (walk->flags & SKCIPHER_WALK_PHYS)) { 281 - walk->src.phys.page = virt_to_page(walk->src.virt.addr); 282 - walk->dst.phys.page = virt_to_page(walk->dst.virt.addr); 283 - walk->src.phys.offset &= PAGE_SIZE - 1; 284 - walk->dst.phys.offset &= PAGE_SIZE - 1; 285 - } 286 - return err; 287 383 } 288 384 289 385 static int skcipher_copy_iv(struct skcipher_walk *walk) ··· 291 407 /* Minimum size to align buffer by alignmask. */ 292 408 size = alignmask & ~a; 293 409 294 - if (walk->flags & SKCIPHER_WALK_PHYS) 295 - size += ivsize; 296 - else { 297 - size += aligned_bs + ivsize; 410 + size += aligned_bs + ivsize; 298 411 299 - /* Minimum size to ensure buffer does not straddle a page. */ 300 - size += (bs - 1) & ~(alignmask | a); 301 - } 412 + /* Minimum size to ensure buffer does not straddle a page. */ 413 + size += (bs - 1) & ~(alignmask | a); 302 414 303 415 walk->buffer = kmalloc(size, skcipher_walk_gfp(walk)); 304 416 if (!walk->buffer) ··· 364 484 365 485 might_sleep_if(req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP); 366 486 367 - walk->flags &= ~SKCIPHER_WALK_PHYS; 368 - 369 487 err = skcipher_walk_skcipher(walk, req); 370 488 371 489 walk->flags &= atomic ? ~SKCIPHER_WALK_SLEEP : ~0; ··· 371 493 return err; 372 494 } 373 495 EXPORT_SYMBOL_GPL(skcipher_walk_virt); 374 - 375 - int skcipher_walk_async(struct skcipher_walk *walk, 376 - struct skcipher_request *req) 377 - { 378 - walk->flags |= SKCIPHER_WALK_PHYS; 379 - 380 - INIT_LIST_HEAD(&walk->buffers); 381 - 382 - return skcipher_walk_skcipher(walk, req); 383 - } 384 - EXPORT_SYMBOL_GPL(skcipher_walk_async); 385 496 386 497 static int skcipher_walk_aead_common(struct skcipher_walk *walk, 387 498 struct aead_request *req, bool atomic) ··· 384 517 385 518 if (unlikely(!walk->total)) 386 519 return 0; 387 - 388 - walk->flags &= ~SKCIPHER_WALK_PHYS; 389 520 390 521 scatterwalk_start(&walk->in, req->src); 391 522 scatterwalk_start(&walk->out, req->dst);
-12
include/crypto/internal/skcipher.h
··· 11 11 #include <crypto/algapi.h> 12 12 #include <crypto/internal/cipher.h> 13 13 #include <crypto/skcipher.h> 14 - #include <linux/list.h> 15 14 #include <linux/types.h> 16 15 17 16 /* ··· 57 58 struct skcipher_walk { 58 59 union { 59 60 struct { 60 - struct page *page; 61 - unsigned long offset; 62 - } phys; 63 - 64 - struct { 65 - u8 *page; 66 61 void *addr; 67 62 } virt; 68 63 } src, dst; ··· 66 73 67 74 struct scatter_walk out; 68 75 unsigned int total; 69 - 70 - struct list_head buffers; 71 76 72 77 u8 *page; 73 78 u8 *buffer; ··· 200 209 int skcipher_walk_virt(struct skcipher_walk *walk, 201 210 struct skcipher_request *req, 202 211 bool atomic); 203 - int skcipher_walk_async(struct skcipher_walk *walk, 204 - struct skcipher_request *req); 205 212 int skcipher_walk_aead_encrypt(struct skcipher_walk *walk, 206 213 struct aead_request *req, bool atomic); 207 214 int skcipher_walk_aead_decrypt(struct skcipher_walk *walk, 208 215 struct aead_request *req, bool atomic); 209 - void skcipher_walk_complete(struct skcipher_walk *walk, int err); 210 216 211 217 static inline void skcipher_walk_abort(struct skcipher_walk *walk) 212 218 {