git: cb9e8ccf4ff0 - main - opencrypto: Do not requeue a re-dispatched request as ordered

From: R. Christian McDonald <rcm_at_FreeBSD.org>
Date: Wed, 18 Nov 2026 16:15:16 UTC
The branch main has been updated by rcm:

URL: https://cgit.FreeBSD.org/src/commit/?id=cb9e8ccf4ff0919a7b1e1801e3c0a5a0f4bc11a8

commit cb9e8ccf4ff0919a7b1e1801e3c0a5a0f4bc11a8
Author:     R. Christian McDonald <rcm@FreeBSD.org>
AuthorDate: 2026-11-18 16:10:24 +0000
Commit:     R. Christian McDonald <rcm@FreeBSD.org>
CommitDate: 2026-11-18 16:14:05 +0000

    opencrypto: Do not requeue a re-dispatched request as ordered
    
    crypto_dispatch_async() marks an ordered request with
    CRYPTO_F_ASYNC_ORDERED and gives it a sequence number.  The return
    thread runs the callbacks in sequence and only takes the head of its
    ordered queue when the head carries the next number.
    
    When a driver unregisters, the request completes with EAGAIN and the
    ESP and AH callbacks dispatch it again with crypto_dispatch().  The
    flag is still set, so crypto_done() puts the request back on the
    ordered queue under the number the return thread has already passed.
    The head of the queue never matches again, and no ordered request of
    any session on that return worker completes after that.
    
    Before crypto_dispatch_async() existed, crypto_dispatch() gave such a
    request a new sequence number.  Clear the flag when the return thread
    takes a request off the ordered queue, so a request that is dispatched
    again completes like any other.
    
    Reviewed by:            markj
    Fixes:                  68f6800ce05c ("opencrypto: Introduce...")
    MFC after:              1 week
    Sponsored by:           Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D61516
---
 sys/opencrypto/crypto.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/sys/opencrypto/crypto.c b/sys/opencrypto/crypto.c
index 9fa017902a19..b268d23ac223 100644
--- a/sys/opencrypto/crypto.c
+++ b/sys/opencrypto/crypto.c
@@ -1883,6 +1883,15 @@ crypto_ret_thread(void *arg)
 			if (crpt->crp_seq == ret_worker->reorder_cur_seq) {
 				TAILQ_REMOVE(&ret_worker->crp_ordered_ret_q, crpt, crp_next);
 				ret_worker->reorder_cur_seq++;
+
+				/*
+				 * The sequence number is spent.  A callback
+				 * that dispatches the request again, as
+				 * consumers do after EAGAIN, must not bring it
+				 * back to this queue under a number the
+				 * thread will never wait for again.
+				 */
+				crpt->crp_flags &= ~CRYPTO_F_ASYNC_ORDERED;
 			} else {
 				crpt = NULL;
 			}