qemu/include/crypto
Daniel P. Berrangé 24ad5e1995 crypto: implement workaround for GNUTLS thread safety problems
When TLS 1.3 is negotiated on a TLS session, GNUTLS will perform
automatic rekeying of the session after 16 million records. This
is done for all algorithms except CHACHA20_POLY1305 which does
not require rekeying.

Unfortunately the rekeying breaks GNUTLS' promise that it is safe
to use a gnutls_session_t object concurrently from multiple threads
if they are exclusively calling gnutls_record_send/recv.

This patch implements a workaround for QEMU that adds a mutex lock
around any gnutls_record_send/recv call to serialize execution
within GNUTLS code. When GNUTLS calls into the push/pull functions
we can release the lock so the OS level I/O calls can at least
have some parallelism.

The big downside of this is that the actual encryption/decryption
code is fully serialized, which will halve performance of that
cipher operations if two threads are contending.

The workaround is not enabled by default, since most use of GNUTLS
in QEMU does not tickle the problem, only non-multifd migration
with a return path open is affected. Fortunately the migration
code also won't trigger the halving of performance, since only
the outbound channel diretion needs to sustain high data rates,
the inbound direction is low volume.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Link: https://lore.kernel.org/qemu-devel/20250718150514.2635338-2-berrange@redhat.com
[add stub for qcrypto_tls_session_require_thread_safety; fix unused var]
Signed-off-by: Fabiano Rosas <farosas@suse.de>
2025-07-22 19:39:29 -03:00
..
aes-round.h crypto: Add aesdec_ISB_ISR_AK_IMC 2023-07-08 07:30:17 +01:00
aes.h target/riscv: Use existing lookup tables for MixColumns 2023-09-11 11:45:54 +10:00
afsplit.h qapi/crypto: Rename QCryptoHashAlgorithm to *Algo, and drop prefix 2024-09-10 14:02:16 +02:00
akcipher.h include/: spelling fixes 2023-09-08 13:08:52 +03:00
block.h qapi/crypto: Rename QCryptoHashAlgorithm to *Algo, and drop prefix 2024-09-10 14:02:16 +02:00
cipher.h qapi/crypto: Rename QCryptoCipherAlgorithm to *Algo, and drop prefix 2024-09-10 14:03:30 +02:00
clmul.h crypto: Add generic 64-bit carry-less multiply routine 2023-09-15 13:57:00 +00:00
desrfb.h replace TABs with spaces 2023-03-20 12:43:50 +01:00
hash.h crypto: Introduce SM3 hash hmac pbkdf algorithm 2024-11-05 18:37:18 +00:00
hmac.h include/crypto: clarify @result/@result_len for hash/hmac APIs 2024-10-22 11:44:23 +01:00
init.h crypto: Fix LGPL information in the file headers 2019-07-19 14:21:25 +01:00
ivgen.h qapi/crypto: Rename QCryptoIVGenAlgorithm to *Algo, and drop prefix 2024-09-10 14:03:30 +02:00
pbkdf.h qapi/crypto: Rename QCryptoCipherAlgorithm to *Algo, and drop prefix 2024-09-10 14:03:30 +02:00
random.h crypto: Fix LGPL information in the file headers 2019-07-19 14:21:25 +01:00
secret_common.h bulk: Do not declare function prototypes using 'extern' keyword 2023-08-31 19:47:43 +02:00
secret_keyring.h qom: Remove module_obj_name parameter from OBJECT_DECLARE* macros 2020-09-18 14:12:32 -04:00
secret.h Use DECLARE_*CHECKER* macros 2020-09-09 09:27:09 -04:00
sm4.h crypto: Add SM4 constant parameter CK 2023-09-11 11:45:55 +10:00
tls-cipher-suites.h Clean up header guards that don't match their file name 2022-05-11 16:49:06 +02:00
tlscreds.h crypto: Make QCryptoTLSCreds* structures private 2021-06-29 18:30:24 +01:00
tlscredsanon.h crypto: Make QCryptoTLSCreds* structures private 2021-06-29 18:30:24 +01:00
tlscredspsk.h crypto: Make QCryptoTLSCreds* structures private 2021-06-29 18:30:24 +01:00
tlscredsx509.h crypto: Make QCryptoTLSCreds* structures private 2021-06-29 18:30:24 +01:00
tlssession.h crypto: implement workaround for GNUTLS thread safety problems 2025-07-22 19:39:29 -03:00
x509-utils.h qapi/crypto: Rename QCryptoHashAlgorithm to *Algo, and drop prefix 2024-09-10 14:02:16 +02:00
xts.h crypto: Fix LGPL information in the file headers 2019-07-19 14:21:25 +01:00