git: 5920f99d2136 - main - ktls: Inline ktls_cleanup() into ktls_destroy().
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 12 Nov 2022 00:01:31 UTC
The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=5920f99d2136aa55ddb2bf1910c5757ee0ef6dc7 commit 5920f99d2136aa55ddb2bf1910c5757ee0ef6dc7 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2022-11-12 00:01:02 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2022-11-12 00:01:02 +0000 ktls: Inline ktls_cleanup() into ktls_destroy(). Reviewed by: gallatin, markj Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D37353 --- sys/kern/uipc_ktls.c | 136 ++++++++++++++++++++++++--------------------------- 1 file changed, 64 insertions(+), 72 deletions(-) diff --git a/sys/kern/uipc_ktls.c b/sys/kern/uipc_ktls.c index 8f3a204cbd84..3df1f2843c32 100644 --- a/sys/kern/uipc_ktls.c +++ b/sys/kern/uipc_ktls.c @@ -297,7 +297,6 @@ SYSCTL_COUNTER_U64(_kern_ipc_tls_toe, OID_AUTO, chacha20, CTLFLAG_RD, static MALLOC_DEFINE(M_KTLS, "ktls", "Kernel TLS"); -static void ktls_cleanup(struct ktls_session *tls); #if defined(INET) || defined(INET6) static void ktls_reset_receive_tag(void *context, int pending); static void ktls_reset_send_tag(void *context, int pending); @@ -784,76 +783,6 @@ ktls_clone_session(struct ktls_session *tls, int direction) return (tls_new); } -#endif - -static void -ktls_cleanup(struct ktls_session *tls) -{ - - counter_u64_add(ktls_offload_active, -1); - switch (tls->mode) { - case TCP_TLS_MODE_SW: - switch (tls->params.cipher_algorithm) { - case CRYPTO_AES_CBC: - counter_u64_add(ktls_sw_cbc, -1); - break; - case CRYPTO_AES_NIST_GCM_16: - counter_u64_add(ktls_sw_gcm, -1); - break; - case CRYPTO_CHACHA20_POLY1305: - counter_u64_add(ktls_sw_chacha20, -1); - break; - } - break; - case TCP_TLS_MODE_IFNET: - switch (tls->params.cipher_algorithm) { - case CRYPTO_AES_CBC: - counter_u64_add(ktls_ifnet_cbc, -1); - break; - case CRYPTO_AES_NIST_GCM_16: - counter_u64_add(ktls_ifnet_gcm, -1); - break; - case CRYPTO_CHACHA20_POLY1305: - counter_u64_add(ktls_ifnet_chacha20, -1); - break; - } - if (tls->snd_tag != NULL) - m_snd_tag_rele(tls->snd_tag); - if (tls->rx_ifp != NULL) - if_rele(tls->rx_ifp); - break; -#ifdef TCP_OFFLOAD - case TCP_TLS_MODE_TOE: - switch (tls->params.cipher_algorithm) { - case CRYPTO_AES_CBC: - counter_u64_add(ktls_toe_cbc, -1); - break; - case CRYPTO_AES_NIST_GCM_16: - counter_u64_add(ktls_toe_gcm, -1); - break; - case CRYPTO_CHACHA20_POLY1305: - counter_u64_add(ktls_toe_chacha20, -1); - break; - } - break; -#endif - } - if (tls->ocf_session != NULL) - ktls_ocf_free(tls); - if (tls->params.auth_key != NULL) { - zfree(tls->params.auth_key, M_KTLS); - tls->params.auth_key = NULL; - tls->params.auth_key_len = 0; - } - if (tls->params.cipher_key != NULL) { - zfree(tls->params.cipher_key, M_KTLS); - tls->params.cipher_key = NULL; - tls->params.cipher_key_len = 0; - } - explicit_bzero(tls->params.iv, sizeof(tls->params.iv)); -} - -#if defined(INET) || defined(INET6) #ifdef TCP_OFFLOAD static int @@ -1864,6 +1793,7 @@ ktls_modify_txrtlmt(struct ktls_session *tls, uint64_t max_pacing_rate) void ktls_destroy(struct ktls_session *tls) { + MPASS(tls->refcount == 0); if (tls->sequential_records) { struct mbuf *m, *n; @@ -1879,7 +1809,69 @@ ktls_destroy(struct ktls_session *tls) } } } - ktls_cleanup(tls); + + counter_u64_add(ktls_offload_active, -1); + switch (tls->mode) { + case TCP_TLS_MODE_SW: + switch (tls->params.cipher_algorithm) { + case CRYPTO_AES_CBC: + counter_u64_add(ktls_sw_cbc, -1); + break; + case CRYPTO_AES_NIST_GCM_16: + counter_u64_add(ktls_sw_gcm, -1); + break; + case CRYPTO_CHACHA20_POLY1305: + counter_u64_add(ktls_sw_chacha20, -1); + break; + } + break; + case TCP_TLS_MODE_IFNET: + switch (tls->params.cipher_algorithm) { + case CRYPTO_AES_CBC: + counter_u64_add(ktls_ifnet_cbc, -1); + break; + case CRYPTO_AES_NIST_GCM_16: + counter_u64_add(ktls_ifnet_gcm, -1); + break; + case CRYPTO_CHACHA20_POLY1305: + counter_u64_add(ktls_ifnet_chacha20, -1); + break; + } + if (tls->snd_tag != NULL) + m_snd_tag_rele(tls->snd_tag); + if (tls->rx_ifp != NULL) + if_rele(tls->rx_ifp); + break; +#ifdef TCP_OFFLOAD + case TCP_TLS_MODE_TOE: + switch (tls->params.cipher_algorithm) { + case CRYPTO_AES_CBC: + counter_u64_add(ktls_toe_cbc, -1); + break; + case CRYPTO_AES_NIST_GCM_16: + counter_u64_add(ktls_toe_gcm, -1); + break; + case CRYPTO_CHACHA20_POLY1305: + counter_u64_add(ktls_toe_chacha20, -1); + break; + } + break; +#endif + } + if (tls->ocf_session != NULL) + ktls_ocf_free(tls); + if (tls->params.auth_key != NULL) { + zfree(tls->params.auth_key, M_KTLS); + tls->params.auth_key = NULL; + tls->params.auth_key_len = 0; + } + if (tls->params.cipher_key != NULL) { + zfree(tls->params.cipher_key, M_KTLS); + tls->params.cipher_key = NULL; + tls->params.cipher_key_len = 0; + } + explicit_bzero(tls->params.iv, sizeof(tls->params.iv)); + uma_zfree(ktls_session_zone, tls); }