qemu-cr16/include/crypto
Peter Xu 7e0c22d585 io/crypto: Move tls premature termination handling into QIO layer
QCryptoTLSSession allows TLS premature termination in two cases, one of the
case is when the channel shutdown() is invoked on READ side.

It's possible the shutdown() happened after the read thread blocked at
gnutls_record_recv().  In this case, we should allow the premature
termination to happen.

The problem is by the time qcrypto_tls_session_read() was invoked,
tioc->shutdown may not have been set, so this may instead be treated as an
error if there is concurrent shutdown() calls.

To allow the flag to reflect the latest status of tioc->shutdown, move the
check upper into the QIOChannel level, so as to read the flag only after
QEMU gets an GNUTLS_E_PREMATURE_TERMINATION.

When at it, introduce qio_channel_tls_allow_premature_termination() helper
to make the condition checks easier to read.  When doing so, change the
qatomic_load_acquire() to qatomic_read(): here we don't need any ordering
of memory accesses, but reading a flag.  qatomic_read() would suffice
because it guarantees fetching from memory.  Nothing else we should need to
order on memory access.

This patch will fix a qemu qtest warning when running the preempt tls test,
reporting premature termination:

QTEST_QEMU_BINARY=./qemu-system-x86_64 ./tests/qtest/migration-test --full -r /x86_64/migration/postcopy/preempt/tls/psk
...
qemu-kvm: Cannot read from TLS channel: The TLS connection was non-properly terminated.
...

In this specific case, the error was set by postcopy_preempt_thread, which
normally will be concurrently shutdown()ed by the main thread.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Juraj Marcin <jmarcin@redhat.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Link: https://lore.kernel.org/r/20250918203937.200833-2-peterx@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
2025-10-03 09:48:02 -04: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 crypto/hmac: Allow to build hmac over multiple qcrypto_gnutls_hmac_bytes[v] calls 2025-09-02 17:58:05 +02: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.h Use DECLARE_*CHECKER* macros 2020-09-09 09:27:09 -04: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
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 io/crypto: Move tls premature termination handling into QIO layer 2025-10-03 09:48:02 -04: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