(cover-letter update I forgot on v2:) This series now contains the two approches we've been discussing to avoid the TLS termination error on the multifd_recv threads.
The source machine now ends the TLS session with gnutls_bye() and the destination will consider a premature termination an error. The only exception is the src <9.1 case where there's a compatibility issue, in which case the presence of multifd-tls-clean-termination=false will cause the destination to (always) ignore a premature termination error. changes in v3: Reordered the patches to have the io/crypto stuff at the start and the compat property before the code that breaks compat. Commit message improvements. Turned assert into an warning when gnutls_bye() fails but migration succeeded (should never happen). Other minor fixes asked by Daniel. CI run: https://gitlab.com/farosas/qemu/-/pipelines/1661172595 v2: https://lore.kernel.org/r/20250207142758.6936-1-faro...@suse.de v1: https://lore.kernel.org/r/20250206175824.22664-1-faro...@suse.de Hi, We've been discussing a way to stop multifd recv threads from getting an error at the end of migration when the source threads close the iochannel without ending the TLS session. The original issue was introduced by commit 1d457daf86 ("migration/multifd: Further remove the SYNC on complete") which altered the synchronization of the source and destination in a manner that causes the destination to already be waiting at recv() when the source closes the connection. One approach would be to issue gnutls_bye() at the source after all the data has been sent. The destination would then gracefully exit when it gets EOF. Aside from stopping the recv thread from seeing an error, this also creates a contract that all connections should be closed only after the TLS session is ended. This helps to avoid masking a legitimate issue where the connection is closed prematurely. Fabiano Rosas (8): crypto: Allow gracefully ending the TLS session io: tls: Add qio_channel_tls_bye crypto: Remove qcrypto_tls_session_get_handshake_status io: Add flags argument to qio_channel_readv_full_all_eof io: Add a read flag for relaxed EOF migration/multifd: Terminate the TLS connection migration/multifd: Add a compat property for TLS termination migration: Check migration error after loadvm crypto/tlssession.c | 96 ++++++++++++++++++----------- hw/core/machine.c | 1 + hw/remote/mpqemu-link.c | 2 +- include/crypto/tlssession.h | 46 ++++++++------ include/io/channel-tls.h | 12 ++++ include/io/channel.h | 3 + io/channel-tls.c | 92 ++++++++++++++++++++++++++- io/channel.c | 9 ++- io/trace-events | 5 ++ migration/migration.h | 33 ++++++++++ migration/multifd.c | 53 +++++++++++++++- migration/multifd.h | 2 + migration/options.c | 2 + migration/savevm.c | 6 +- migration/tls.c | 5 ++ migration/tls.h | 2 +- tests/unit/test-crypto-tlssession.c | 12 ++-- 17 files changed, 305 insertions(+), 76 deletions(-) -- 2.35.3