2020-01-28 19:09:44

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH] [RFC] crypto: ccree - fix retry handling in cc_send_sync_request()

If cc_queues_status() indicates that the queue is full,
cc_send_sync_request() should loop and retry.

However, cc_queues_status() returns either 0 (for success), or -ENOSPC
(for queue full), while cc_send_sync_request() checks for real errors by
comparing with -EAGAIN. Hence -ENOSPC is always considered a real
error, and the code never retries the operation.

Fix this by just removing the check, as cc_queues_status() never returns
any other error value than -ENOSPC.

Signed-off-by: Geert Uytterhoeven <[email protected]>
---
I am not 100% sure what was intended originally.
Perhaps the second -ENOSPC error in cc_queues_status() should have been
-EAGAIN?
---
drivers/crypto/ccree/cc_request_mgr.c | 4 ----
1 file changed, 4 deletions(-)

diff --git a/drivers/crypto/ccree/cc_request_mgr.c b/drivers/crypto/ccree/cc_request_mgr.c
index 9d61e6f1247819e2..b2a18122f320b7b2 100644
--- a/drivers/crypto/ccree/cc_request_mgr.c
+++ b/drivers/crypto/ccree/cc_request_mgr.c
@@ -476,10 +476,6 @@ int cc_send_sync_request(struct cc_drvdata *drvdata,
break;

spin_unlock_bh(&mgr->hw_lock);
- if (rc != -EAGAIN) {
- cc_pm_put_suspend(dev);
- return rc;
- }
wait_for_completion_interruptible(&drvdata->hw_queue_avail);
reinit_completion(&drvdata->hw_queue_avail);
}
--
2.17.1


2020-01-29 09:12:15

by Gilad Ben-Yossef

[permalink] [raw]
Subject: Re: [PATCH] [RFC] crypto: ccree - fix retry handling in cc_send_sync_request()

On Tue, Jan 28, 2020 at 9:09 PM Geert Uytterhoeven
<[email protected]> wrote:
>
> If cc_queues_status() indicates that the queue is full,
> cc_send_sync_request() should loop and retry.
>
> However, cc_queues_status() returns either 0 (for success), or -ENOSPC
> (for queue full), while cc_send_sync_request() checks for real errors by
> comparing with -EAGAIN. Hence -ENOSPC is always considered a real
> error, and the code never retries the operation.
>
> Fix this by just removing the check, as cc_queues_status() never returns
> any other error value than -ENOSPC.

Thank you for spotting this!

The error is simply checking for the wrong error value.
We should be checking for -ENOSPC!

What this does aims to do is wait for the hardware queue to free up if
we were asked to queue a synchronous request and there was no room in
the hardware queue.
The cc_queue_status() function used to return -EAGAIN in this scenario
and this was missed in the change.

I'm curious as to how you found this - did you run into some problem
and traced it to this?
This can lead to a setkey() failing in very high load situations but I
expect this occurrence to be very rare indeed since cc_queue_status()
already loops several times waiting for the room to be freeed.


Gilad



--
Gilad Ben-Yossef
Chief Coffee Drinker

values of β will give rise to dom!

2020-01-29 09:19:16

by Gilad Ben-Yossef

[permalink] [raw]
Subject: Re: [PATCH] [RFC] crypto: ccree - fix retry handling in cc_send_sync_request()

On Wed, Jan 29, 2020 at 11:11 AM Gilad Ben-Yossef <[email protected]> wrote:
>
> On Tue, Jan 28, 2020 at 9:09 PM Geert Uytterhoeven
> <[email protected]> wrote:
> >
> > If cc_queues_status() indicates that the queue is full,
> > cc_send_sync_request() should loop and retry.
> >
> > However, cc_queues_status() returns either 0 (for success), or -ENOSPC
> > (for queue full), while cc_send_sync_request() checks for real errors by
> > comparing with -EAGAIN. Hence -ENOSPC is always considered a real
> > error, and the code never retries the operation.
> >
> > Fix this by just removing the check, as cc_queues_status() never returns
> > any other error value than -ENOSPC.
>

OK, it took me a minute but I now see what you mean... your patch does
the right thing.

Acked-by: Gilad Ben-Yossef <[email protected]>

Gilad

2020-01-29 09:25:35

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] [RFC] crypto: ccree - fix retry handling in cc_send_sync_request()

Hi Gilad,

On Wed, Jan 29, 2020 at 10:11 AM Gilad Ben-Yossef <[email protected]> wrote:
> On Tue, Jan 28, 2020 at 9:09 PM Geert Uytterhoeven
> <[email protected]> wrote:
> > If cc_queues_status() indicates that the queue is full,
> > cc_send_sync_request() should loop and retry.
> >
> > However, cc_queues_status() returns either 0 (for success), or -ENOSPC
> > (for queue full), while cc_send_sync_request() checks for real errors by
> > comparing with -EAGAIN. Hence -ENOSPC is always considered a real
> > error, and the code never retries the operation.
> >
> > Fix this by just removing the check, as cc_queues_status() never returns
> > any other error value than -ENOSPC.
>
> Thank you for spotting this!
>
> The error is simply checking for the wrong error value.
> We should be checking for -ENOSPC!
>
> What this does aims to do is wait for the hardware queue to free up if
> we were asked to queue a synchronous request and there was no room in
> the hardware queue.
> The cc_queue_status() function used to return -EAGAIN in this scenario
> and this was missed in the change.
>
> I'm curious as to how you found this - did you run into some problem
> and traced it to this?

I didn't run into a specific problem, but I'm working on cleaning up the driver
a bit.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds