Skip to content

Commit 4140aaf

Browse files
bacol89herbertx
authored andcommitted
crypto: engine - fix crypto_queue backlog handling
CRYPTO_TFM_REQ_MAY_BACKLOG tells the crypto driver that it should internally backlog requests until the crypto hw's queue becomes full. At that point, crypto_engine backlogs the request and returns -EBUSY. Calling driver such as dm-crypt then waits until the complete() function is called with a status of -EINPROGRESS before sending a new request. The problem lies in the call to complete() with a value of -EINPROGRESS that is made when a backlog item is present on the queue. The call is done before the successful execution of the crypto request. In the case that do_one_request() returns < 0 and the retry support is available, the request is put back in the queue. This leads upper drivers to send a new request even if the queue is still full. The problem can be reproduced by doing a large dd into a crypto dm-crypt device. This is pretty easy to see when using Freescale CAAM crypto driver and SWIOTLB dma. Since the actual amount of requests that can be hold in the queue is unlimited we get IOs error and dma allocation. The fix is to call complete with a value of -EINPROGRESS only if the request is not enqueued back in crypto_queue. This is done by calling complete() later in the code. In order to delay the decision, crypto_queue is modified to correctly set the backlog pointer when a request is enqueued back. Fixes: 6a89f49 ("crypto: engine - support for parallel requests based on retry mechanism") Co-developed-by: Sylvain Ouellet <souellet@genetec.com> Signed-off-by: Sylvain Ouellet <souellet@genetec.com> Signed-off-by: Olivier Bacon <obacon@genetec.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 8fd9115 commit 4140aaf

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

crypto/algapi.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,9 @@ EXPORT_SYMBOL_GPL(crypto_enqueue_request);
961961
void crypto_enqueue_request_head(struct crypto_queue *queue,
962962
struct crypto_async_request *request)
963963
{
964+
if (unlikely(queue->qlen >= queue->max_qlen))
965+
queue->backlog = queue->backlog->prev;
966+
964967
queue->qlen++;
965968
list_add(&request->list, &queue->list);
966969
}

crypto/crypto_engine.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ static void crypto_pump_requests(struct crypto_engine *engine,
129129
if (!engine->retry_support)
130130
engine->cur_req = async_req;
131131

132-
if (backlog)
133-
crypto_request_complete(backlog, -EINPROGRESS);
134-
135132
if (engine->busy)
136133
was_busy = true;
137134
else
@@ -217,6 +214,9 @@ static void crypto_pump_requests(struct crypto_engine *engine,
217214
crypto_request_complete(async_req, ret);
218215

219216
retry:
217+
if (backlog)
218+
crypto_request_complete(backlog, -EINPROGRESS);
219+
220220
/* If retry mechanism is supported, send new requests to engine */
221221
if (engine->retry_support) {
222222
spin_lock_irqsave(&engine->queue_lock, flags);

0 commit comments

Comments
 (0)