From nobody Mon May 6 08:10:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 ARC-Seal: i=1; a=rsa-sha256; t=1604643024; cv=none; d=zohomail.com; s=zohoarc; b=IjWpUZINGFnnSrLkN9jJ2dRJE+F2NPpcG+UYK2ugxsmy4TuVnQBRjAWxn+OfV6ddCSzxQaTqj3OAXbMqIWnI0ieph2OWeZDfBHjFK6SlFsgenDBzMSuTO/Rnyc5+SLablwjtycvgm7F09HvPI7wePuYsDBPeiK62W0JeT4t2X4M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604643024; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=BoOsMchyvcplhouBwUFDeZERMYwDISIkh0PAjfymhHI=; b=ftN6kI81UGfYqowXf821pOmDmAw3hNwQ4Ug610w/atArBBqamgudyMNsO4ng6WUAqMDkINHokV+t8fVmJtU2SAWpDJet6NDBLZUwuPuGV6PSoBewkfgmh1lehGw+pH5lNR0kABxNbScbkzax0AdLDPnQJymdiESzEESvwAAchtA= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604643024273527.6693414387603; Thu, 5 Nov 2020 22:10:24 -0800 (PST) Received: from localhost ([::1]:55350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kaux4-00029w-Pc for importer@patchew.org; Fri, 06 Nov 2020 01:10:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kauwR-0001kL-Vd for qemu-devel@nongnu.org; Fri, 06 Nov 2020 01:09:43 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2507) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kauwO-00060k-LG for qemu-devel@nongnu.org; Fri, 06 Nov 2020 01:09:43 -0500 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CS92T5Ghgzhd7y; Fri, 6 Nov 2020 14:09:21 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Fri, 6 Nov 2020 14:09:15 +0800 From: Chuan Zheng To: , , Subject: [PATCH] migration/multifd: fix hangup with TLS-Multifd due to blocking handshake Date: Fri, 6 Nov 2020 14:24:53 +0800 Message-ID: <1604643893-8223-1-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected 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=45.249.212.191; envelope-from=zhengchuan@huawei.com; helo=szxga05-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/06 01:09:28 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yubihong@huawei.com, zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, wanghao232@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" The qemu main loop could hang up forever when we enable TLS+Multifd. The Src multifd_send_0 invokes tls handshake, it sends hello to sever and wait response. However, the Dst main qemu loop has been waiting recvmsg() for multifd_recv= _1. Both of Src and Dst main qemu loop are blocking and waiting for reponse whi= ch results in hanging up forever. Src: (multifd_send_0) Dst: (mu= ltifd_recv_1) multifd_channel_connect migratio= n_channel_process_incoming multifd_tls_channel_connect migrat= ion_tls_channel_process_incoming multifd_tls_channel_connect qio_= channel_tls_handshake_task qio_channel_tls_handshake gn= utls_handshake qio_channel_tls_handshake_task = ... qcrypto_tls_session_handshake = ... gnutls_handshake = ... ... = ... recvmsg (Blocking I/O waiting for response) = recvmsg (Blocking I/O waiting for response) Fix this by offloadinig handshake work to a background thread. Reported-by: Yan Jin Suggested-by: Daniel P. Berrang=C3=A9 Signed-off-by: Chuan Zheng Reviewed-by: Daniel P. Berrang=C3=A9 --- migration/multifd.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 68b171f..88486b9 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -739,6 +739,19 @@ static void multifd_tls_outgoing_handshake(QIOTask *ta= sk, multifd_channel_connect(p, ioc, err); } =20 +static void *multifd_tls_handshake_thread(void *opaque) +{ + MultiFDSendParams *p =3D opaque; + QIOChannelTLS *tioc =3D QIO_CHANNEL_TLS(p->c); + + qio_channel_tls_handshake(tioc, + multifd_tls_outgoing_handshake, + p, + NULL, + NULL); + return NULL; +} + static void multifd_tls_channel_connect(MultiFDSendParams *p, QIOChannel *ioc, Error **errp) @@ -754,12 +767,10 @@ static void multifd_tls_channel_connect(MultiFDSendPa= rams *p, =20 trace_multifd_tls_outgoing_handshake_start(ioc, tioc, hostname); qio_channel_set_name(QIO_CHANNEL(tioc), "multifd-tls-outgoing"); - qio_channel_tls_handshake(tioc, - multifd_tls_outgoing_handshake, - p, - NULL, - NULL); - + p->c =3D QIO_CHANNEL(tioc); + qemu_thread_create(&p->thread, "multifd-tls-handshake-worker", + multifd_tls_handshake_thread, p, + QEMU_THREAD_JOINABLE); } =20 static bool multifd_channel_connect(MultiFDSendParams *p, --=20 1.8.3.1