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: scatterwalk - Change scatterwalk_next calling convention

Rather than returning the address and storing the length into an
argument pointer, add an address field to the walk struct and use
that to store the address. The length is returned directly.

Change the done functions to use this stored address instead of
getting them from the caller.

Split the address into two using a union. The user should only
access the const version so that it is never changed.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+78 -78
+3 -4
arch/arm/crypto/ghash-ce-glue.c
··· 460 460 461 461 do { 462 462 unsigned int n; 463 - const u8 *p; 464 463 465 - p = scatterwalk_next(&walk, len, &n); 466 - gcm_update_mac(dg, p, n, buf, &buf_count, ctx); 467 - scatterwalk_done_src(&walk, p, n); 464 + n = scatterwalk_next(&walk, len); 465 + gcm_update_mac(dg, walk.addr, n, buf, &buf_count, ctx); 466 + scatterwalk_done_src(&walk, n); 468 467 469 468 if (unlikely(len / SZ_4K > (len - n) / SZ_4K)) { 470 469 kernel_neon_end();
+4 -5
arch/arm64/crypto/aes-ce-ccm-glue.c
··· 157 157 158 158 do { 159 159 unsigned int n; 160 - const u8 *p; 161 160 162 - p = scatterwalk_next(&walk, len, &n); 163 - macp = ce_aes_ccm_auth_data(mac, p, n, macp, ctx->key_enc, 164 - num_rounds(ctx)); 165 - scatterwalk_done_src(&walk, p, n); 161 + n = scatterwalk_next(&walk, len); 162 + macp = ce_aes_ccm_auth_data(mac, walk.addr, n, macp, 163 + ctx->key_enc, num_rounds(ctx)); 164 + scatterwalk_done_src(&walk, n); 166 165 len -= n; 167 166 } while (len); 168 167 }
+3 -4
arch/arm64/crypto/ghash-ce-glue.c
··· 309 309 310 310 do { 311 311 unsigned int n; 312 - const u8 *p; 313 312 314 - p = scatterwalk_next(&walk, len, &n); 315 - gcm_update_mac(dg, p, n, buf, &buf_count, ctx); 316 - scatterwalk_done_src(&walk, p, n); 313 + n = scatterwalk_next(&walk, len); 314 + gcm_update_mac(dg, walk.addr, n, buf, &buf_count, ctx); 315 + scatterwalk_done_src(&walk, n); 317 316 len -= n; 318 317 } while (len); 319 318
+4 -4
arch/arm64/crypto/sm4-ce-ccm-glue.c
··· 113 113 114 114 do { 115 115 unsigned int n, orig_n; 116 - const u8 *p, *orig_p; 116 + const u8 *p; 117 117 118 - orig_p = scatterwalk_next(&walk, assoclen, &orig_n); 119 - p = orig_p; 118 + orig_n = scatterwalk_next(&walk, assoclen); 119 + p = walk.addr; 120 120 n = orig_n; 121 121 122 122 while (n > 0) { ··· 149 149 } 150 150 } 151 151 152 - scatterwalk_done_src(&walk, orig_p, orig_n); 152 + scatterwalk_done_src(&walk, orig_n); 153 153 assoclen -= orig_n; 154 154 } while (assoclen); 155 155 }
+4 -4
arch/arm64/crypto/sm4-ce-gcm-glue.c
··· 83 83 84 84 do { 85 85 unsigned int n, orig_n; 86 - const u8 *p, *orig_p; 86 + const u8 *p; 87 87 88 - orig_p = scatterwalk_next(&walk, assoclen, &orig_n); 89 - p = orig_p; 88 + orig_n = scatterwalk_next(&walk, assoclen); 89 + p = walk.addr; 90 90 n = orig_n; 91 91 92 92 if (n + buflen < GHASH_BLOCK_SIZE) { ··· 118 118 memcpy(&buffer[0], p, buflen); 119 119 } 120 120 121 - scatterwalk_done_src(&walk, orig_p, orig_n); 121 + scatterwalk_done_src(&walk, orig_n); 122 122 assoclen -= orig_n; 123 123 } while (assoclen); 124 124
+9 -12
arch/s390/crypto/aes_s390.c
··· 66 66 struct gcm_sg_walk { 67 67 struct scatter_walk walk; 68 68 unsigned int walk_bytes; 69 - u8 *walk_ptr; 70 69 unsigned int walk_bytes_remain; 71 70 u8 buf[AES_BLOCK_SIZE]; 72 71 unsigned int buf_bytes; ··· 788 789 { 789 790 if (gw->walk_bytes_remain == 0) 790 791 return 0; 791 - gw->walk_ptr = scatterwalk_next(&gw->walk, gw->walk_bytes_remain, 792 - &gw->walk_bytes); 792 + gw->walk_bytes = scatterwalk_next(&gw->walk, gw->walk_bytes_remain); 793 793 return gw->walk_bytes; 794 794 } 795 795 ··· 797 799 { 798 800 gw->walk_bytes_remain -= nbytes; 799 801 if (out) 800 - scatterwalk_done_dst(&gw->walk, gw->walk_ptr, nbytes); 802 + scatterwalk_done_dst(&gw->walk, nbytes); 801 803 else 802 - scatterwalk_done_src(&gw->walk, gw->walk_ptr, nbytes); 803 - gw->walk_ptr = NULL; 804 + scatterwalk_done_src(&gw->walk, nbytes); 804 805 } 805 806 806 807 static int gcm_in_walk_go(struct gcm_sg_walk *gw, unsigned int minbytesneeded) ··· 825 828 } 826 829 827 830 if (!gw->buf_bytes && gw->walk_bytes >= minbytesneeded) { 828 - gw->ptr = gw->walk_ptr; 831 + gw->ptr = gw->walk.addr; 829 832 gw->nbytes = gw->walk_bytes; 830 833 goto out; 831 834 } 832 835 833 836 while (1) { 834 837 n = min(gw->walk_bytes, AES_BLOCK_SIZE - gw->buf_bytes); 835 - memcpy(gw->buf + gw->buf_bytes, gw->walk_ptr, n); 838 + memcpy(gw->buf + gw->buf_bytes, gw->walk.addr, n); 836 839 gw->buf_bytes += n; 837 840 _gcm_sg_unmap_and_advance(gw, n, false); 838 841 if (gw->buf_bytes >= minbytesneeded) { ··· 866 869 } 867 870 868 871 if (gw->walk_bytes >= minbytesneeded) { 869 - gw->ptr = gw->walk_ptr; 872 + gw->ptr = gw->walk.addr; 870 873 gw->nbytes = gw->walk_bytes; 871 874 goto out; 872 875 } 873 876 874 - scatterwalk_unmap(gw->walk_ptr); 875 - gw->walk_ptr = NULL; 877 + /* XXX */ 878 + scatterwalk_unmap(gw->walk.addr); 876 879 877 880 gw->ptr = gw->buf; 878 881 gw->nbytes = sizeof(gw->buf); ··· 911 914 if (!_gcm_sg_clamp_and_map(gw)) 912 915 return i; 913 916 n = min(gw->walk_bytes, bytesdone - i); 914 - memcpy(gw->walk_ptr, gw->buf + i, n); 917 + memcpy(gw->walk.addr, gw->buf + i, n); 915 918 _gcm_sg_unmap_and_advance(gw, n, true); 916 919 } 917 920 } else
+3 -4
arch/x86/crypto/aegis128-aesni-glue.c
··· 71 71 72 72 scatterwalk_start(&walk, sg_src); 73 73 while (assoclen != 0) { 74 - unsigned int size; 75 - const u8 *mapped = scatterwalk_next(&walk, assoclen, &size); 74 + unsigned int size = scatterwalk_next(&walk, assoclen); 75 + const u8 *src = walk.addr; 76 76 unsigned int left = size; 77 - const u8 *src = mapped; 78 77 79 78 if (pos + size >= AEGIS128_BLOCK_SIZE) { 80 79 if (pos > 0) { ··· 96 97 pos += left; 97 98 assoclen -= size; 98 99 99 - scatterwalk_done_src(&walk, mapped, size); 100 + scatterwalk_done_src(&walk, size); 100 101 } 101 102 102 103 if (pos > 0) {
+4 -5
arch/x86/crypto/aesni-intel_glue.c
··· 1306 1306 scatterwalk_start(&walk, sg_src); 1307 1307 1308 1308 while (assoclen) { 1309 - unsigned int orig_len_this_step; 1310 - const u8 *orig_src = scatterwalk_next(&walk, assoclen, 1311 - &orig_len_this_step); 1309 + unsigned int orig_len_this_step = scatterwalk_next( 1310 + &walk, assoclen); 1312 1311 unsigned int len_this_step = orig_len_this_step; 1313 1312 unsigned int len; 1314 - const u8 *src = orig_src; 1313 + const u8 *src = walk.addr; 1315 1314 1316 1315 if (unlikely(pos)) { 1317 1316 len = min(len_this_step, 16 - pos); ··· 1334 1335 pos = len_this_step; 1335 1336 } 1336 1337 next: 1337 - scatterwalk_done_src(&walk, orig_src, orig_len_this_step); 1338 + scatterwalk_done_src(&walk, orig_len_this_step); 1338 1339 if (need_resched()) { 1339 1340 kernel_fpu_end(); 1340 1341 kernel_fpu_begin();
+3 -4
crypto/aegis128-core.c
··· 284 284 285 285 scatterwalk_start(&walk, sg_src); 286 286 while (assoclen != 0) { 287 - unsigned int size; 288 - const u8 *mapped = scatterwalk_next(&walk, assoclen, &size); 287 + unsigned int size = scatterwalk_next(&walk, assoclen); 288 + const u8 *src = walk.addr; 289 289 unsigned int left = size; 290 - const u8 *src = mapped; 291 290 292 291 if (pos + size >= AEGIS_BLOCK_SIZE) { 293 292 if (pos > 0) { ··· 307 308 308 309 pos += left; 309 310 assoclen -= size; 310 - scatterwalk_done_src(&walk, mapped, size); 311 + scatterwalk_done_src(&walk, size); 311 312 } 312 313 313 314 if (pos > 0) {
+6 -8
crypto/scatterwalk.c
··· 34 34 unsigned int nbytes) 35 35 { 36 36 do { 37 - const void *src_addr; 38 37 unsigned int to_copy; 39 38 40 - src_addr = scatterwalk_next(walk, nbytes, &to_copy); 41 - memcpy(buf, src_addr, to_copy); 42 - scatterwalk_done_src(walk, src_addr, to_copy); 39 + to_copy = scatterwalk_next(walk, nbytes); 40 + memcpy(buf, walk->addr, to_copy); 41 + scatterwalk_done_src(walk, to_copy); 43 42 buf += to_copy; 44 43 nbytes -= to_copy; 45 44 } while (nbytes); ··· 49 50 unsigned int nbytes) 50 51 { 51 52 do { 52 - void *dst_addr; 53 53 unsigned int to_copy; 54 54 55 - dst_addr = scatterwalk_next(walk, nbytes, &to_copy); 56 - memcpy(dst_addr, buf, to_copy); 57 - scatterwalk_done_dst(walk, dst_addr, to_copy); 55 + to_copy = scatterwalk_next(walk, nbytes); 56 + memcpy(walk->addr, buf, to_copy); 57 + scatterwalk_done_dst(walk, to_copy); 58 58 buf += to_copy; 59 59 nbytes -= to_copy; 60 60 } while (nbytes);
+7 -3
crypto/skcipher.c
··· 41 41 42 42 static inline void skcipher_map_src(struct skcipher_walk *walk) 43 43 { 44 - walk->src.virt.addr = scatterwalk_map(&walk->in); 44 + /* XXX */ 45 + walk->in.__addr = scatterwalk_map(&walk->in); 46 + walk->src.virt.addr = walk->in.addr; 45 47 } 46 48 47 49 static inline void skcipher_map_dst(struct skcipher_walk *walk) 48 50 { 49 - walk->dst.virt.addr = scatterwalk_map(&walk->out); 51 + /* XXX */ 52 + walk->out.__addr = scatterwalk_map(&walk->out); 53 + walk->dst.virt.addr = walk->out.addr; 50 54 } 51 55 52 56 static inline gfp_t skcipher_walk_gfp(struct skcipher_walk *walk) ··· 124 120 goto dst_done; 125 121 } 126 122 127 - scatterwalk_done_dst(&walk->out, walk->dst.virt.addr, n); 123 + scatterwalk_done_dst(&walk->out, n); 128 124 dst_done: 129 125 130 126 if (res > 0)
+3 -4
drivers/crypto/nx/nx.c
··· 154 154 struct scatter_walk walk; 155 155 struct nx_sg *nx_sg = nx_dst; 156 156 unsigned int n, len = *src_len; 157 - char *dst; 158 157 159 158 /* we need to fast forward through @start bytes first */ 160 159 scatterwalk_start_at_pos(&walk, sg_src, start); 161 160 162 161 while (len && (nx_sg - nx_dst) < sglen) { 163 - dst = scatterwalk_next(&walk, len, &n); 162 + n = scatterwalk_next(&walk, len); 164 163 165 - nx_sg = nx_build_sg_list(nx_sg, dst, &n, sglen - (nx_sg - nx_dst)); 164 + nx_sg = nx_build_sg_list(nx_sg, walk.addr, &n, sglen - (nx_sg - nx_dst)); 166 165 167 - scatterwalk_done_src(&walk, dst, n); 166 + scatterwalk_done_src(&walk, n); 168 167 len -= n; 169 168 } 170 169 /* update to_process */
+7
include/crypto/algapi.h
··· 54 54 struct scatterlist; 55 55 struct seq_file; 56 56 struct sk_buff; 57 + union crypto_no_such_thing; 57 58 58 59 struct crypto_instance { 59 60 struct crypto_alg alg; ··· 109 108 struct scatter_walk { 110 109 struct scatterlist *sg; 111 110 unsigned int offset; 111 + union { 112 + void *const addr; 113 + 114 + /* Private API field, do not touch. */ 115 + union crypto_no_such_thing *__addr; 116 + }; 112 117 }; 113 118 114 119 struct crypto_attr_alg {
+18 -17
include/crypto/scatterwalk.h
··· 120 120 * scatterwalk_next() - Get the next data buffer in a scatterlist walk 121 121 * @walk: the scatter_walk 122 122 * @total: the total number of bytes remaining, > 0 123 - * @nbytes_ret: (out) the next number of bytes available, <= @total 124 123 * 125 - * Return: A virtual address for the next segment of data from the scatterlist. 126 - * The caller must call scatterwalk_done_src() or scatterwalk_done_dst() 127 - * when it is done using this virtual address. 124 + * A virtual address for the next segment of data from the scatterlist will 125 + * be placed into @walk->addr. The caller must call scatterwalk_done_src() 126 + * or scatterwalk_done_dst() when it is done using this virtual address. 127 + * 128 + * Returns: the next number of bytes available, <= @total 128 129 */ 129 - static inline void *scatterwalk_next(struct scatter_walk *walk, 130 - unsigned int total, 131 - unsigned int *nbytes_ret) 130 + static inline unsigned int scatterwalk_next(struct scatter_walk *walk, 131 + unsigned int total) 132 132 { 133 - *nbytes_ret = scatterwalk_clamp(walk, total); 134 - return scatterwalk_map(walk); 133 + unsigned int nbytes = scatterwalk_clamp(walk, total); 134 + 135 + walk->__addr = scatterwalk_map(walk); 136 + return nbytes; 135 137 } 136 138 137 139 static inline void scatterwalk_unmap(const void *vaddr) ··· 151 149 /** 152 150 * scatterwalk_done_src() - Finish one step of a walk of source scatterlist 153 151 * @walk: the scatter_walk 154 - * @vaddr: the address returned by scatterwalk_next() 155 152 * @nbytes: the number of bytes processed this step, less than or equal to the 156 153 * number of bytes that scatterwalk_next() returned. 157 154 * 158 - * Use this if the @vaddr was not written to, i.e. it is source data. 155 + * Use this if the mapped address was not written to, i.e. it is source data. 159 156 */ 160 157 static inline void scatterwalk_done_src(struct scatter_walk *walk, 161 - const void *vaddr, unsigned int nbytes) 158 + unsigned int nbytes) 162 159 { 163 - scatterwalk_unmap(vaddr); 160 + scatterwalk_unmap(walk->addr); 164 161 scatterwalk_advance(walk, nbytes); 165 162 } 166 163 167 164 /** 168 165 * scatterwalk_done_dst() - Finish one step of a walk of destination scatterlist 169 166 * @walk: the scatter_walk 170 - * @vaddr: the address returned by scatterwalk_next() 171 167 * @nbytes: the number of bytes processed this step, less than or equal to the 172 168 * number of bytes that scatterwalk_next() returned. 173 169 * 174 - * Use this if the @vaddr may have been written to, i.e. it is destination data. 170 + * Use this if the mapped address may have been written to, i.e. it is 171 + * destination data. 175 172 */ 176 173 static inline void scatterwalk_done_dst(struct scatter_walk *walk, 177 - void *vaddr, unsigned int nbytes) 174 + unsigned int nbytes) 178 175 { 179 - scatterwalk_unmap(vaddr); 176 + scatterwalk_unmap(walk->addr); 180 177 /* 181 178 * Explicitly check ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE instead of just 182 179 * relying on flush_dcache_page() being a no-op when not implemented,