]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tls: rx: simplify async wait
authorJakub Kicinski <kuba@kernel.org>
Fri, 8 Apr 2022 18:31:27 +0000 (11:31 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 25 May 2024 14:20:17 +0000 (16:20 +0200)
commit 37943f047bfb88ba4dfc7a522563f57c86d088a0 upstream.

Since we are protected from async completions by decrypt_compl_lock
we can drop the async_notify and reinit the completion before we
start waiting.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Stable-dep-of: aec7961916f3 ("tls: fix race between async notify and socket close")
Signed-off-by: Shaoying Xu <shaoyi@amazon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/net/tls.h
net/tls/tls_sw.c

index ea0aeae26cf76388aa44b070ce47c7c960f02655..dcd6aa08c06788b39026b9f6ec0cc1cc426c82bb 100644 (file)
@@ -150,7 +150,6 @@ struct tls_sw_context_rx {
        atomic_t decrypt_pending;
        /* protect crypto_wait with decrypt_pending*/
        spinlock_t decrypt_compl_lock;
-       bool async_notify;
 };
 
 struct tls_record_info {
index fc55b65695e5ce0f170b79528ba1627e86ba5b02..9c443646417e4874c38766efa902add618b2b0a3 100644 (file)
@@ -174,7 +174,6 @@ static void tls_decrypt_done(struct crypto_async_request *req, int err)
        struct scatterlist *sg;
        struct sk_buff *skb;
        unsigned int pages;
-       int pending;
 
        skb = (struct sk_buff *)req->data;
        tls_ctx = tls_get_ctx(skb->sk);
@@ -222,9 +221,7 @@ static void tls_decrypt_done(struct crypto_async_request *req, int err)
        kfree(aead_req);
 
        spin_lock_bh(&ctx->decrypt_compl_lock);
-       pending = atomic_dec_return(&ctx->decrypt_pending);
-
-       if (!pending && ctx->async_notify)
+       if (!atomic_dec_return(&ctx->decrypt_pending))
                complete(&ctx->async_wait.completion);
        spin_unlock_bh(&ctx->decrypt_compl_lock);
 }
@@ -1917,7 +1914,7 @@ recv_end:
 
                /* Wait for all previously submitted records to be decrypted */
                spin_lock_bh(&ctx->decrypt_compl_lock);
-               ctx->async_notify = true;
+               reinit_completion(&ctx->async_wait.completion);
                pending = atomic_read(&ctx->decrypt_pending);
                spin_unlock_bh(&ctx->decrypt_compl_lock);
                if (pending) {
@@ -1929,15 +1926,8 @@ recv_end:
                                decrypted = 0;
                                goto end;
                        }
-               } else {
-                       reinit_completion(&ctx->async_wait.completion);
                }
 
-               /* There can be no concurrent accesses, since we have no
-                * pending decrypt operations
-                */
-               WRITE_ONCE(ctx->async_notify, false);
-
                /* Drain records from the rx_list & copy if required */
                if (is_peek || is_kvec)
                        err = process_rx_list(ctx, msg, &control, copied,