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 - use the new scatterwalk functions

Convert skcipher_walk to use the new scatterwalk functions.

This includes a few changes to exactly where the different parts of the
iteration happen. For example the dcache flush that previously happened
in scatterwalk_done() now happens in scatterwalk_dst_done() or in
memcpy_to_scatterwalk(). Advancing to the next sg entry now happens
just-in-time in scatterwalk_clamp() instead of in scatterwalk_done().

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
95dbd711 6be051ce

+19 -32
+19 -32
crypto/skcipher.c
··· 49 49 walk->dst.virt.addr = scatterwalk_map(&walk->out); 50 50 } 51 51 52 - static inline void skcipher_unmap_src(struct skcipher_walk *walk) 53 - { 54 - scatterwalk_unmap(walk->src.virt.addr); 55 - } 56 - 57 - static inline void skcipher_unmap_dst(struct skcipher_walk *walk) 58 - { 59 - scatterwalk_unmap(walk->dst.virt.addr); 60 - } 61 - 62 52 static inline gfp_t skcipher_walk_gfp(struct skcipher_walk *walk) 63 53 { 64 54 return walk->flags & SKCIPHER_WALK_SLEEP ? GFP_KERNEL : GFP_ATOMIC; ··· 58 68 struct crypto_alg *alg) 59 69 { 60 70 return container_of(alg, struct skcipher_alg, base); 61 - } 62 - 63 - static int skcipher_done_slow(struct skcipher_walk *walk, unsigned int bsize) 64 - { 65 - u8 *addr = PTR_ALIGN(walk->buffer, walk->alignmask + 1); 66 - 67 - scatterwalk_copychunks(addr, &walk->out, bsize, 1); 68 - return 0; 69 71 } 70 72 71 73 /** ··· 94 112 if (likely(!(walk->flags & (SKCIPHER_WALK_SLOW | 95 113 SKCIPHER_WALK_COPY | 96 114 SKCIPHER_WALK_DIFF)))) { 97 - unmap_src: 98 - skcipher_unmap_src(walk); 115 + scatterwalk_advance(&walk->in, n); 99 116 } else if (walk->flags & SKCIPHER_WALK_DIFF) { 100 - skcipher_unmap_dst(walk); 101 - goto unmap_src; 117 + scatterwalk_unmap(walk->src.virt.addr); 118 + scatterwalk_advance(&walk->in, n); 102 119 } else if (walk->flags & SKCIPHER_WALK_COPY) { 120 + scatterwalk_advance(&walk->in, n); 103 121 skcipher_map_dst(walk); 104 122 memcpy(walk->dst.virt.addr, walk->page, n); 105 - skcipher_unmap_dst(walk); 106 123 } else { /* SKCIPHER_WALK_SLOW */ 107 124 if (res > 0) { 108 125 /* ··· 112 131 */ 113 132 res = -EINVAL; 114 133 total = 0; 115 - } else 116 - n = skcipher_done_slow(walk, n); 134 + } else { 135 + u8 *buf = PTR_ALIGN(walk->buffer, walk->alignmask + 1); 136 + 137 + memcpy_to_scatterwalk(&walk->out, buf, n); 138 + } 139 + goto dst_done; 117 140 } 141 + 142 + scatterwalk_done_dst(&walk->out, walk->dst.virt.addr, n); 143 + dst_done: 118 144 119 145 if (res > 0) 120 146 res = 0; 121 147 122 148 walk->total = total; 123 149 walk->nbytes = 0; 124 - 125 - scatterwalk_advance(&walk->in, n); 126 - scatterwalk_advance(&walk->out, n); 127 - scatterwalk_done(&walk->in, 0, total); 128 - scatterwalk_done(&walk->out, 1, total); 129 150 130 151 if (total) { 131 152 if (walk->flags & SKCIPHER_WALK_SLEEP) ··· 175 192 walk->dst.virt.addr = PTR_ALIGN(buffer, alignmask + 1); 176 193 walk->src.virt.addr = walk->dst.virt.addr; 177 194 178 - scatterwalk_copychunks(walk->src.virt.addr, &walk->in, bsize, 0); 195 + memcpy_from_scatterwalk(walk->src.virt.addr, &walk->in, bsize); 179 196 180 197 walk->nbytes = bsize; 181 198 walk->flags |= SKCIPHER_WALK_SLOW; ··· 189 206 190 207 skcipher_map_src(walk); 191 208 memcpy(tmp, walk->src.virt.addr, walk->nbytes); 192 - skcipher_unmap_src(walk); 209 + scatterwalk_unmap(walk->src.virt.addr); 210 + /* 211 + * walk->in is advanced later when the number of bytes actually 212 + * processed (which might be less than walk->nbytes) is known. 213 + */ 193 214 194 215 walk->src.virt.addr = tmp; 195 216 walk->dst.virt.addr = tmp;