Skip to content

Commit 422bf8f

Browse files
ebiggersherbertx
authored andcommitted
crypto: nx - use the new scatterwalk functions
- In nx_walk_and_build(), use scatterwalk_start_at_pos() instead of a more complex way to achieve the same result. - Also in nx_walk_and_build(), use the new functions scatterwalk_next() which consolidates scatterwalk_clamp() and scatterwalk_map(), and use scatterwalk_done_src() which consolidates scatterwalk_unmap(), scatterwalk_advance(), and scatterwalk_done(). Remove unnecessary code that seemed to be intended to advance to the next sg entry, which is already handled by the scatterwalk functions. Note that nx_walk_and_build() does not actually read or write the mapped virtual address, and thus it is misusing the scatter_walk API. It really should just access the scatterlist directly. This patch does not try to address this existing issue. - In nx_gca(), use memcpy_from_sglist() instead of a more complex way to achieve the same result. - In various functions, replace calls to scatterwalk_map_and_copy() with memcpy_from_sglist() or memcpy_to_sglist() as appropriate. Note that this eliminates the confusing 'out' argument (which this driver had tried to work around by defining the missing constants for it...) Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Naveen N Rao <naveen@kernel.org> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 8fd0eec commit 422bf8f

File tree

4 files changed

+17
-50
lines changed

4 files changed

+17
-50
lines changed

drivers/crypto/nx/nx-aes-ccm.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,11 @@ static int generate_pat(u8 *iv,
217217
memset(b1, 0, 16);
218218
if (assoclen <= 65280) {
219219
*(u16 *)b1 = assoclen;
220-
scatterwalk_map_and_copy(b1 + 2, req->src, 0,
221-
iauth_len, SCATTERWALK_FROM_SG);
220+
memcpy_from_sglist(b1 + 2, req->src, 0, iauth_len);
222221
} else {
223222
*(u16 *)b1 = (u16)(0xfffe);
224223
*(u32 *)&b1[2] = assoclen;
225-
scatterwalk_map_and_copy(b1 + 6, req->src, 0,
226-
iauth_len, SCATTERWALK_FROM_SG);
224+
memcpy_from_sglist(b1 + 6, req->src, 0, iauth_len);
227225
}
228226
}
229227

@@ -341,9 +339,8 @@ static int ccm_nx_decrypt(struct aead_request *req,
341339
nbytes -= authsize;
342340

343341
/* copy out the auth tag to compare with later */
344-
scatterwalk_map_and_copy(priv->oauth_tag,
345-
req->src, nbytes + req->assoclen, authsize,
346-
SCATTERWALK_FROM_SG);
342+
memcpy_from_sglist(priv->oauth_tag, req->src, nbytes + req->assoclen,
343+
authsize);
347344

348345
rc = generate_pat(iv, req, nx_ctx, authsize, nbytes, assoclen,
349346
csbcpb->cpb.aes_ccm.in_pat_or_b0);
@@ -465,9 +462,8 @@ static int ccm_nx_encrypt(struct aead_request *req,
465462
} while (processed < nbytes);
466463

467464
/* copy out the auth tag */
468-
scatterwalk_map_and_copy(csbcpb->cpb.aes_ccm.out_pat_or_mac,
469-
req->dst, nbytes + req->assoclen, authsize,
470-
SCATTERWALK_TO_SG);
465+
memcpy_to_sglist(req->dst, nbytes + req->assoclen,
466+
csbcpb->cpb.aes_ccm.out_pat_or_mac, authsize);
471467

472468
out:
473469
spin_unlock_irqrestore(&nx_ctx->lock, irq_flags);

drivers/crypto/nx/nx-aes-gcm.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,13 @@ static int nx_gca(struct nx_crypto_ctx *nx_ctx,
103103
{
104104
int rc;
105105
struct nx_csbcpb *csbcpb_aead = nx_ctx->csbcpb_aead;
106-
struct scatter_walk walk;
107106
struct nx_sg *nx_sg = nx_ctx->in_sg;
108107
unsigned int nbytes = assoclen;
109108
unsigned int processed = 0, to_process;
110109
unsigned int max_sg_len;
111110

112111
if (nbytes <= AES_BLOCK_SIZE) {
113-
scatterwalk_start(&walk, req->src);
114-
scatterwalk_copychunks(out, &walk, nbytes, SCATTERWALK_FROM_SG);
115-
scatterwalk_done(&walk, SCATTERWALK_FROM_SG, 0);
112+
memcpy_from_sglist(out, req->src, 0, nbytes);
116113
return 0;
117114
}
118115

@@ -391,19 +388,17 @@ static int gcm_aes_nx_crypt(struct aead_request *req, int enc,
391388
mac:
392389
if (enc) {
393390
/* copy out the auth tag */
394-
scatterwalk_map_and_copy(
395-
csbcpb->cpb.aes_gcm.out_pat_or_mac,
391+
memcpy_to_sglist(
396392
req->dst, req->assoclen + nbytes,
397-
crypto_aead_authsize(crypto_aead_reqtfm(req)),
398-
SCATTERWALK_TO_SG);
393+
csbcpb->cpb.aes_gcm.out_pat_or_mac,
394+
crypto_aead_authsize(crypto_aead_reqtfm(req)));
399395
} else {
400396
u8 *itag = nx_ctx->priv.gcm.iauth_tag;
401397
u8 *otag = csbcpb->cpb.aes_gcm.out_pat_or_mac;
402398

403-
scatterwalk_map_and_copy(
399+
memcpy_from_sglist(
404400
itag, req->src, req->assoclen + nbytes,
405-
crypto_aead_authsize(crypto_aead_reqtfm(req)),
406-
SCATTERWALK_FROM_SG);
401+
crypto_aead_authsize(crypto_aead_reqtfm(req)));
407402
rc = crypto_memneq(itag, otag,
408403
crypto_aead_authsize(crypto_aead_reqtfm(req))) ?
409404
-EBADMSG : 0;

drivers/crypto/nx/nx.c

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -153,40 +153,19 @@ struct nx_sg *nx_walk_and_build(struct nx_sg *nx_dst,
153153
{
154154
struct scatter_walk walk;
155155
struct nx_sg *nx_sg = nx_dst;
156-
unsigned int n, offset = 0, len = *src_len;
156+
unsigned int n, len = *src_len;
157157
char *dst;
158158

159159
/* we need to fast forward through @start bytes first */
160-
for (;;) {
161-
scatterwalk_start(&walk, sg_src);
162-
163-
if (start < offset + sg_src->length)
164-
break;
165-
166-
offset += sg_src->length;
167-
sg_src = sg_next(sg_src);
168-
}
169-
170-
/* start - offset is the number of bytes to advance in the scatterlist
171-
* element we're currently looking at */
172-
scatterwalk_advance(&walk, start - offset);
160+
scatterwalk_start_at_pos(&walk, sg_src, start);
173161

174162
while (len && (nx_sg - nx_dst) < sglen) {
175-
n = scatterwalk_clamp(&walk, len);
176-
if (!n) {
177-
/* In cases where we have scatterlist chain sg_next
178-
* handles with it properly */
179-
scatterwalk_start(&walk, sg_next(walk.sg));
180-
n = scatterwalk_clamp(&walk, len);
181-
}
182-
dst = scatterwalk_map(&walk);
163+
dst = scatterwalk_next(&walk, len, &n);
183164

184165
nx_sg = nx_build_sg_list(nx_sg, dst, &n, sglen - (nx_sg - nx_dst));
185-
len -= n;
186166

187-
scatterwalk_unmap(dst);
188-
scatterwalk_advance(&walk, n);
189-
scatterwalk_done(&walk, SCATTERWALK_FROM_SG, len);
167+
scatterwalk_done_src(&walk, dst, n);
168+
len -= n;
190169
}
191170
/* update to_process */
192171
*src_len -= len;

drivers/crypto/nx/nx.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,4 @@ extern struct shash_alg nx_shash_sha256_alg;
189189

190190
extern struct nx_crypto_driver nx_driver;
191191

192-
#define SCATTERWALK_TO_SG 1
193-
#define SCATTERWALK_FROM_SG 0
194-
195192
#endif

0 commit comments

Comments
 (0)