Skip to content

Commit f38d2e5

Browse files
committed
Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto fixes from Herbert Xu: "This fixes a number of regressions in the marvell cesa driver caused by the chaining work, and a regression in lib/mpi that leads to a GFP_KERNEL allocation with preemption disabled" * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: crypto: marvell - Don't copy IV vectors from the _process op for ciphers lib/mpi: Fix SG miter leak crypto: marvell - Update cache with input sg only when it is unmapped crypto: marvell - Don't chain at DMA level when backlog is disabled crypto: marvell - Fix memory leaks in TDMA chain for cipher requests
2 parents aeb35d6 + 8cf740a commit f38d2e5

File tree

4 files changed

+24
-34
lines changed

4 files changed

+24
-34
lines changed

drivers/crypto/marvell/cesa.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,11 @@ int mv_cesa_queue_req(struct crypto_async_request *req,
180180
struct mv_cesa_engine *engine = creq->engine;
181181

182182
spin_lock_bh(&engine->lock);
183-
if (mv_cesa_req_get_type(creq) == CESA_DMA_REQ)
184-
mv_cesa_tdma_chain(engine, creq);
185-
186183
ret = crypto_enqueue_request(&engine->queue, req);
184+
if ((mv_cesa_req_get_type(creq) == CESA_DMA_REQ) &&
185+
(ret == -EINPROGRESS ||
186+
(ret == -EBUSY && req->flags & CRYPTO_TFM_REQ_MAY_BACKLOG)))
187+
mv_cesa_tdma_chain(engine, creq);
187188
spin_unlock_bh(&engine->lock);
188189

189190
if (ret != -EINPROGRESS)

drivers/crypto/marvell/cipher.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,11 @@ static int mv_cesa_ablkcipher_process(struct crypto_async_request *req,
139139
struct ablkcipher_request *ablkreq = ablkcipher_request_cast(req);
140140
struct mv_cesa_ablkcipher_req *creq = ablkcipher_request_ctx(ablkreq);
141141
struct mv_cesa_req *basereq = &creq->base;
142-
unsigned int ivsize;
143-
int ret;
144142

145143
if (mv_cesa_req_get_type(basereq) == CESA_STD_REQ)
146144
return mv_cesa_ablkcipher_std_process(ablkreq, status);
147145

148-
ret = mv_cesa_dma_process(basereq, status);
149-
if (ret)
150-
return ret;
151-
152-
ivsize = crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(ablkreq));
153-
memcpy_fromio(ablkreq->info, basereq->chain.last->data, ivsize);
154-
155-
return 0;
146+
return mv_cesa_dma_process(basereq, status);
156147
}
157148

158149
static void mv_cesa_ablkcipher_step(struct crypto_async_request *req)
@@ -320,7 +311,6 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req,
320311
GFP_KERNEL : GFP_ATOMIC;
321312
struct mv_cesa_req *basereq = &creq->base;
322313
struct mv_cesa_ablkcipher_dma_iter iter;
323-
struct mv_cesa_tdma_chain chain;
324314
bool skip_ctx = false;
325315
int ret;
326316
unsigned int ivsize;
@@ -347,13 +337,13 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req,
347337
return -ENOMEM;
348338
}
349339

350-
mv_cesa_tdma_desc_iter_init(&chain);
340+
mv_cesa_tdma_desc_iter_init(&basereq->chain);
351341
mv_cesa_ablkcipher_req_iter_init(&iter, req);
352342

353343
do {
354344
struct mv_cesa_op_ctx *op;
355345

356-
op = mv_cesa_dma_add_op(&chain, op_templ, skip_ctx, flags);
346+
op = mv_cesa_dma_add_op(&basereq->chain, op_templ, skip_ctx, flags);
357347
if (IS_ERR(op)) {
358348
ret = PTR_ERR(op);
359349
goto err_free_tdma;
@@ -363,18 +353,18 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req,
363353
mv_cesa_set_crypt_op_len(op, iter.base.op_len);
364354

365355
/* Add input transfers */
366-
ret = mv_cesa_dma_add_op_transfers(&chain, &iter.base,
356+
ret = mv_cesa_dma_add_op_transfers(&basereq->chain, &iter.base,
367357
&iter.src, flags);
368358
if (ret)
369359
goto err_free_tdma;
370360

371361
/* Add dummy desc to launch the crypto operation */
372-
ret = mv_cesa_dma_add_dummy_launch(&chain, flags);
362+
ret = mv_cesa_dma_add_dummy_launch(&basereq->chain, flags);
373363
if (ret)
374364
goto err_free_tdma;
375365

376366
/* Add output transfers */
377-
ret = mv_cesa_dma_add_op_transfers(&chain, &iter.base,
367+
ret = mv_cesa_dma_add_op_transfers(&basereq->chain, &iter.base,
378368
&iter.dst, flags);
379369
if (ret)
380370
goto err_free_tdma;
@@ -383,13 +373,12 @@ static int mv_cesa_ablkcipher_dma_req_init(struct ablkcipher_request *req,
383373

384374
/* Add output data for IV */
385375
ivsize = crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(req));
386-
ret = mv_cesa_dma_add_iv_op(&chain, CESA_SA_CRYPT_IV_SRAM_OFFSET,
376+
ret = mv_cesa_dma_add_iv_op(&basereq->chain, CESA_SA_CRYPT_IV_SRAM_OFFSET,
387377
ivsize, CESA_TDMA_SRC_IN_SRAM, flags);
388378

389379
if (ret)
390380
goto err_free_tdma;
391381

392-
basereq->chain = chain;
393382
basereq->chain.last->flags |= CESA_TDMA_END_OF_REQ;
394383

395384
return 0;

drivers/crypto/marvell/hash.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,6 @@ static void mv_cesa_ahash_complete(struct crypto_async_request *req)
315315
for (i = 0; i < digsize / 4; i++)
316316
creq->state[i] = readl_relaxed(engine->regs + CESA_IVDIG(i));
317317

318-
if (creq->cache_ptr)
319-
sg_pcopy_to_buffer(ahashreq->src, creq->src_nents,
320-
creq->cache,
321-
creq->cache_ptr,
322-
ahashreq->nbytes - creq->cache_ptr);
323-
324318
if (creq->last_req) {
325319
/*
326320
* Hardware's MD5 digest is in little endian format, but
@@ -365,6 +359,12 @@ static void mv_cesa_ahash_req_cleanup(struct crypto_async_request *req)
365359
mv_cesa_ahash_last_cleanup(ahashreq);
366360

367361
mv_cesa_ahash_cleanup(ahashreq);
362+
363+
if (creq->cache_ptr)
364+
sg_pcopy_to_buffer(ahashreq->src, creq->src_nents,
365+
creq->cache,
366+
creq->cache_ptr,
367+
ahashreq->nbytes - creq->cache_ptr);
368368
}
369369

370370
static const struct mv_cesa_req_ops mv_cesa_ahash_req_ops = {

lib/mpi/mpicoder.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int nbytes)
363363
lzeros = 0;
364364
}
365365

366+
miter.consumed = lzeros;
367+
sg_miter_stop(&miter);
368+
366369
nbytes -= lzeros;
367370
nbits = nbytes * 8;
368371
if (nbits > MAX_EXTERN_MPI_BITS) {
@@ -390,7 +393,10 @@ MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int nbytes)
390393
z = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB;
391394
z %= BYTES_PER_MPI_LIMB;
392395

393-
for (;;) {
396+
while (sg_miter_next(&miter)) {
397+
buff = miter.addr;
398+
len = miter.length;
399+
394400
for (x = 0; x < len; x++) {
395401
a <<= 8;
396402
a |= *buff++;
@@ -400,12 +406,6 @@ MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int nbytes)
400406
}
401407
}
402408
z += x;
403-
404-
if (!sg_miter_next(&miter))
405-
break;
406-
407-
buff = miter.addr;
408-
len = miter.length;
409409
}
410410

411411
return val;

0 commit comments

Comments
 (0)