From nobody Sun Sep 28 17:03:43 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1758228014; cv=none; d=zohomail.com; s=zohoarc; b=bpLxyV7o/kXRt2tZs7eWdtnNNAi7GkA+OlE/ol002Z+OGy+hElC3RPVVCda9CpK5d4NMu8hic9qt0HTS0U5Z7DYaGubdAG+8gbWtBB50BPhZJ0g5kL5GeU5wQoq3LzQPofC9dVv2gjDYTuUL09LsMa64G/cd2T8/f9PeBozuPyI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758228014; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PISZYNwNcqxmRdkv72aYDBIGvVd3XtWjapz0OTY+8IE=; b=dh8TMt8ZJyFXpGgOwXMMJNlm+V1tTwOqA+i/XpntE4Zmqd+SamY38GWbW3hFx2hjEQV6/o1obtMbOrotPT4tSVyNP3ilWMNLyA9FgruOvtlUNTkmCXhcARuOroUcTr+as2PbT8SvW5UeNfguLRdjI/dLddX85aI6aOCX9JcqyXE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758228014558298.7447715671336; Thu, 18 Sep 2025 13:40:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzLQ0-000664-63; Thu, 18 Sep 2025 16:39:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzLPx-00065Z-M5 for qemu-devel@nongnu.org; Thu, 18 Sep 2025 16:39:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzLPu-0005q6-Po for qemu-devel@nongnu.org; Thu, 18 Sep 2025 16:39:49 -0400 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-691--q56MP2AMgiVKTmJzMqeww-1; Thu, 18 Sep 2025 16:39:43 -0400 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-81312a26ea3so327517985a.0 for ; Thu, 18 Sep 2025 13:39:43 -0700 (PDT) Received: from x1.com (bras-base-aurron9134w-grc-11-174-89-135-121.dsl.bell.ca. [174.89.135.121]) by smtp.gmail.com with ESMTPSA id af79cd13be357-836278b8082sm226276285a.22.2025.09.18.13.39.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Sep 2025 13:39:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758227984; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PISZYNwNcqxmRdkv72aYDBIGvVd3XtWjapz0OTY+8IE=; b=NCt6t84YdxCBeZGebx4BABSGUuNLfB+m/KYRi/Kb4ROJl7qXdmEdGV46PTjO4z2zteYYoW XvmX/MyUIkVOu3s83Wjg2bRH1f95mYRCBTvKn+DxduJj1ZGH5GEHR1qd1pRyw6F0J4HP3H 6dyGIfdBtGqBDX8udNcCzI33VFDv0PU= X-MC-Unique: -q56MP2AMgiVKTmJzMqeww-1 X-Mimecast-MFC-AGG-ID: -q56MP2AMgiVKTmJzMqeww_1758227982 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758227981; x=1758832781; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PISZYNwNcqxmRdkv72aYDBIGvVd3XtWjapz0OTY+8IE=; b=QeZFwSS8bzRHoj2EaIWKi9YpVcRuq8NjsvXLxltGBOVEfG7J0YSpmC7pNPAhVHfHOu 8ZAVwszk5XSyZ5SOBFNEdzh/zUF4GAftocHxFwB1tySR4nger4PSJKHFjnwq4uJhmOuI WRrJx3ufOmpMXBP4oD7mUL2canfjgtrdGleV624Eejf/oQyL4IjAhz+JzPfEhCRAKCTf ZlGMxhTm/NjTXQACPcdDytQNTnf3raoIIeRGbwHiZoyeXoicHK3YajN4b0ELwMImQqPP VgGGjeTN2KgREU0uwbSNzDMxFEQv9eg3/9P+jHX2Ko81GLoPkNnSiYXWTG9Q9IKu7j2z TTLA== X-Gm-Message-State: AOJu0YwoZ5TVhYctPZC5cWV5Mkchxwl2RreJq4cDTzlNNFccwunATlHB MS0af4idF/ZVDjcK6VW1IiBZ5btMpz8ow9dCUDYLcqqKYnHxN0d5ulTwjTo3ifruqChE/nx2rYo CLndQ34Mv1Q6Q4DGaukjUo6pAvKJsa/jfpxbdA3LKAQtglJ7EqUcu0ASE82UwkpFdFsYbloHseR kjdCDoBR4uBpuRAT9FdqtZQ9yXfYlaeVePtYCxEQ== X-Gm-Gg: ASbGncsrGi/JgZFCup+YrcHGDtaaP2M0CqRZkEf+SLeLjBvlzLA72h8X+yImjKCc2L+ 2EOPDHKgGVi58Dt7D1Ujm/vVvTvsbWEitIoCRTLpHIX4PoLx8c7yYenr1vBSo6CEKxkByhBxi8j n4aAe9CEG9E7nXl9xYoSFaqDHwGm/Rhnfy5QaBb1hVbZZNrh2eWdyXQjHmOgxkJTfNbNrrPzcg6 Yz4QcON9HSrT/L++ONdDm1zTHtQ5VHUMU0bVc1ZKZU6qWOiWlphGduWMjm13dntTPkiajX5Y10t CsYPCsconvh27TzYhJmU8VJACGh6v29D1FO2gdz4j10wL25IR3Rg1wKB2zZAPlzMpd4XY5QKFYh HSbpYJ7K8fB3Jhfu1IUE= X-Received: by 2002:a05:620a:d:b0:80f:d62b:9b71 with SMTP id af79cd13be357-83bad30b1f5mr106220985a.75.1758227981432; Thu, 18 Sep 2025 13:39:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFq8SBijXHACg6W+t/CUmcA3c12RQaAXv8flXh9WnF5s9FzbutDIOYItqIc3Je55dAjjSUJZw== X-Received: by 2002:a05:620a:d:b0:80f:d62b:9b71 with SMTP id af79cd13be357-83bad30b1f5mr106218685a.75.1758227980939; Thu, 18 Sep 2025 13:39:40 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Fabiano Rosas , Juraj Marcin Subject: [PATCH v3 1/2] io/crypto: Move tls premature termination handling into QIO layer Date: Thu, 18 Sep 2025 16:39:36 -0400 Message-ID: <20250918203937.200833-2-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250918203937.200833-1-peterx@redhat.com> References: <20250918203937.200833-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.005, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1758228016802116600 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=3D./qemu-system-x86_64 ./tests/qtest/migration-test --ful= l -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=C3=A9 Reviewed-by: Juraj Marcin Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- include/crypto/tlssession.h | 10 +++------- crypto/tlssession.c | 7 ++----- io/channel-tls.c | 21 +++++++++++++++++++-- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/include/crypto/tlssession.h b/include/crypto/tlssession.h index 2f62ce2d67..2e9fe11cf6 100644 --- a/include/crypto/tlssession.h +++ b/include/crypto/tlssession.h @@ -110,6 +110,7 @@ typedef struct QCryptoTLSSession QCryptoTLSSession; =20 #define QCRYPTO_TLS_SESSION_ERR_BLOCK -2 +#define QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION -3 =20 /** * qcrypto_tls_session_new: @@ -259,7 +260,6 @@ ssize_t qcrypto_tls_session_write(QCryptoTLSSession *se= ss, * @sess: the TLS session object * @buf: to fill with plain text received * @len: the length of @buf - * @gracefulTermination: treat premature termination as graceful EOF * @errp: pointer to hold returned error object * * Receive up to @len bytes of data from the remote peer @@ -267,22 +267,18 @@ ssize_t qcrypto_tls_session_write(QCryptoTLSSession *= sess, * qcrypto_tls_session_set_callbacks(), decrypt it and * store it in @buf. * - * If @gracefulTermination is true, then a premature termination - * of the TLS session will be treated as indicating EOF, as - * opposed to an error. - * * It is an error to call this before * qcrypto_tls_session_handshake() returns * QCRYPTO_TLS_HANDSHAKE_COMPLETE * * Returns: the number of bytes received, * or QCRYPTO_TLS_SESSION_ERR_BLOCK if the receive would block, - * or -1 on error. + * or QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION if a premature termination + * is detected, or -1 on error. */ ssize_t qcrypto_tls_session_read(QCryptoTLSSession *sess, char *buf, size_t len, - bool gracefulTermination, Error **errp); =20 /** diff --git a/crypto/tlssession.c b/crypto/tlssession.c index 86d407a142..ac38c2121d 100644 --- a/crypto/tlssession.c +++ b/crypto/tlssession.c @@ -552,7 +552,6 @@ ssize_t qcrypto_tls_session_read(QCryptoTLSSession *session, char *buf, size_t len, - bool gracefulTermination, Error **errp) { ssize_t ret; @@ -570,9 +569,8 @@ qcrypto_tls_session_read(QCryptoTLSSession *session, if (ret < 0) { if (ret =3D=3D GNUTLS_E_AGAIN) { return QCRYPTO_TLS_SESSION_ERR_BLOCK; - } else if ((ret =3D=3D GNUTLS_E_PREMATURE_TERMINATION) && - gracefulTermination){ - return 0; + } else if (ret =3D=3D GNUTLS_E_PREMATURE_TERMINATION) { + return QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION; } else { if (session->rerr) { error_propagate(errp, session->rerr); @@ -789,7 +787,6 @@ ssize_t qcrypto_tls_session_read(QCryptoTLSSession *sess, char *buf, size_t len, - bool gracefulTermination, Error **errp) { error_setg(errp, "TLS requires GNUTLS support"); diff --git a/io/channel-tls.c b/io/channel-tls.c index a8248a9216..5a2c8188ce 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -346,6 +346,19 @@ static void qio_channel_tls_finalize(Object *obj) qcrypto_tls_session_free(ioc->session); } =20 +static bool +qio_channel_tls_allow_premature_termination(QIOChannelTLS *tioc, int flags) +{ + if (flags & QIO_CHANNEL_READ_FLAG_RELAXED_EOF) { + return true; + } + + if (qatomic_read(&tioc->shutdown) & QIO_CHANNEL_SHUTDOWN_READ) { + return true; + } + + return false; +} =20 static ssize_t qio_channel_tls_readv(QIOChannel *ioc, const struct iovec *iov, @@ -364,8 +377,6 @@ static ssize_t qio_channel_tls_readv(QIOChannel *ioc, tioc->session, iov[i].iov_base, iov[i].iov_len, - flags & QIO_CHANNEL_READ_FLAG_RELAXED_EOF || - qatomic_load_acquire(&tioc->shutdown) & QIO_CHANNEL_SHUTDOWN_R= EAD, errp); if (ret =3D=3D QCRYPTO_TLS_SESSION_ERR_BLOCK) { if (got) { @@ -373,6 +384,12 @@ static ssize_t qio_channel_tls_readv(QIOChannel *ioc, } else { return QIO_CHANNEL_ERR_BLOCK; } + } else if (ret =3D=3D QCRYPTO_TLS_SESSION_PREMATURE_TERMINATION) { + if (qio_channel_tls_allow_premature_termination(tioc, flags)) { + ret =3D 0; + } else { + return -1; + } } else if (ret < 0) { return -1; } --=20 2.50.1 From nobody Sun Sep 28 17:03:43 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1758228019; cv=none; d=zohomail.com; s=zohoarc; b=bdFu3hPnUz+PPVct0cQuaI3DMnDfdbW3VaJ3MPz8CiGCv/jOt2dMUQ+c+LMFY8QUFFffKYhbjV2rQSPQdor4XtzZ8nWj3oyAeX5NtB6Wbh0HD0waztcAihquvrQrbDMNgLjGH/aXZRO7qD8yzGZn8PtbEjDu3xYp6arpTICL6ZA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758228019; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DHtSrXZcVQINioTONBn/GrEMHeTFb5InPbuhxx5EyD0=; b=A8K3Dt9eC6WTUmLLTfbi3kkhmBf14PzgaM2VG6z+J3AYMPosB1ziY/K4BU88hwY2VQlJ3ckIjPlbFgR8+AEeGGQww+OkNqqL34V6wDQShi/1NDzxxXF7fjofnPGNnd4LyTeUGqDTaKQuQVzJOGyby+wj5Bx/cc8iHOU4bpTGc7U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758228019862131.09220682495982; Thu, 18 Sep 2025 13:40:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzLQ3-00066V-T6; Thu, 18 Sep 2025 16:39:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzLPw-00065J-3w for qemu-devel@nongnu.org; Thu, 18 Sep 2025 16:39:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uzLPu-0005qA-E6 for qemu-devel@nongnu.org; Thu, 18 Sep 2025 16:39:47 -0400 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-664-ZBMYZw4WOVyUI_hWyN_DyQ-1; Thu, 18 Sep 2025 16:39:43 -0400 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-81678866c0cso244489785a.2 for ; Thu, 18 Sep 2025 13:39:43 -0700 (PDT) Received: from x1.com (bras-base-aurron9134w-grc-11-174-89-135-121.dsl.bell.ca. [174.89.135.121]) by smtp.gmail.com with ESMTPSA id af79cd13be357-836278b8082sm226276285a.22.2025.09.18.13.39.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Sep 2025 13:39:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758227985; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DHtSrXZcVQINioTONBn/GrEMHeTFb5InPbuhxx5EyD0=; b=A/V3C9VjsFHc0lfYZT0yIuXD/u8XZhr+8sEZNE7dswPLvpzmpOoILw4terD3ityUe9NESV zJIAIqmAOM2IEeiqJEZOp0moQPWCDcGn9c4foagX1jv4iUIkO24LyYzysjzcve0Leloliq SpbYbxL3v8g3KPA/TPuBqEAkiyvQTGI= X-MC-Unique: ZBMYZw4WOVyUI_hWyN_DyQ-1 X-Mimecast-MFC-AGG-ID: ZBMYZw4WOVyUI_hWyN_DyQ_1758227983 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758227983; x=1758832783; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DHtSrXZcVQINioTONBn/GrEMHeTFb5InPbuhxx5EyD0=; b=mk3EYHFScSq5WUkXDJ8goSrH9oUkkLBtFAySgiRuhjY35Cgu4O3/Q1H9cBq5ICf3Mh m46kfHPpLr8MC043CrTnysDhdJQGC7SHpCnUv0xwtF/A2H0rg2OOlTIcXHY5pvjeyj/W iNP8GbQtbHcdjbWFB4+frdbn37V09eHL2IFqpR/2FLWzXk1bx9aWW/HKOBZs5gUryIX7 Iui1nCTyxkKEJ8zstjcwi2UOoZ7qghFSNPKZbh3VVAN7z9/QGaDG03Psrii5l+5MKcgI VswXWpFhABFLn6yFdzKI9DT81T6zK6/skCpzP5gXzG2jLTOoXLSz9EUwDQhw5XFar1Is r/OQ== X-Gm-Message-State: AOJu0YwPZFkTZQVnTNXGxkL+aMNUS7vl8Z/uhtxlqgSt5Ah1+FAN6VEf gxiZFzLY2c5qmiXBu5s5NFaiY7ANMAabZIzYPDUk1iRKXoDCxePRHq6zwx+vkxzOWLzW/rOep5g kNoNG6PT7E9FxSq5WTRnmkYfDraZVXItiMDZ5HajYzeL23dDyV3FTu7itkYemDVb440dxcs+TUs uDhrqChNHBGJbfY+qFb7ECrJhY2kVEhVqoM1vpQQ== X-Gm-Gg: ASbGnctVkAktRFp+z71hx79FXY4RoaxYPQHgl95GXXOrGkyXjfMOKRA9KK95lpMuTR2 z7PHHpX+eyW3ucNyn8OXvSOeR57mSIlm0EzVVDJ7Mf0JM8rCKqyE/+PVC1tEwF0dEpLep5JdVp2 7biIL3tkDbZ+Lh4k0N5GhSYESWxg7aPFFeN8OpCQV2i/oU+gitnRg3yh7iWtf1eagw5J8xZxZsK H97VWwLsF3uJkkFPRlN2ZT7KRvAivika0yEcfBxWeqtFCmO2WCow8kCFIoJgWaIXGHNvSm2DX2z 0v+rznrTtUTrayoX1+r3bZzOpBl/lqZOi0ZDz7VdrCdAYwe/4NGAdsVQV/IBrDL4ikKadwrMdby 4d3alqmhDBVo00dh3jKw= X-Received: by 2002:a05:620a:390b:b0:82a:4593:3089 with SMTP id af79cd13be357-83ba53d2b4dmr133611685a.33.1758227982733; Thu, 18 Sep 2025 13:39:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZkY33+47Pfwtb3zRly3iWPKq3iMa99MxmzW49cnwXPNuVGSlbzITLPZbEfWjZMbGURXA8Zg== X-Received: by 2002:a05:620a:390b:b0:82a:4593:3089 with SMTP id af79cd13be357-83ba53d2b4dmr133607485a.33.1758227982027; Thu, 18 Sep 2025 13:39:42 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Fabiano Rosas , Juraj Marcin Subject: [PATCH v3 2/2] migration: Make migration_has_failed() work even for CANCELLING Date: Thu, 18 Sep 2025 16:39:37 -0400 Message-ID: <20250918203937.200833-3-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250918203937.200833-1-peterx@redhat.com> References: <20250918203937.200833-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.005, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1758228020816116600 Content-Type: text/plain; charset="utf-8" No issue I hit, the change is only from code observation when I am looking at a TLS premature termination issue. We set CANCELLED very late, it means migration_has_failed() may not work correctly if it's invoked before updating CANCELLING to CANCELLED. Allow that state will make migration_has_failed() working as expected even if it's invoked slightly earlier. One current user is the multifd code for the TLS graceful termination, where it's before updating to CANCELLED. Reviewed-by: Juraj Marcin Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/migration.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index 10c216d25d..f6f6a6e202 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1702,7 +1702,8 @@ int migration_call_notifiers(MigrationState *s, Migra= tionEventType type, =20 bool migration_has_failed(MigrationState *s) { - return (s->state =3D=3D MIGRATION_STATUS_CANCELLED || + return (s->state =3D=3D MIGRATION_STATUS_CANCELLING || + s->state =3D=3D MIGRATION_STATUS_CANCELLED || s->state =3D=3D MIGRATION_STATUS_FAILED); } =20 --=20 2.50.1