From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A3075C54F51 for ; Tue, 28 Jul 2026 21:30:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wopMz-0001lj-CF; Tue, 28 Jul 2026 17:29:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wopMy-0001lS-Bf for qemu-devel@nongnu.org; Tue, 28 Jul 2026 17:29:48 -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 1wopMw-0007xZ-BY for qemu-devel@nongnu.org; Tue, 28 Jul 2026 17:29:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785274184; 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=OxDVdIsxN8IKGNvSivF0AG9skCApqvHzO/0VPP4Sr8I=; b=dibEKljjHraTHRxILJv5yf/M+wYTsOREEU87KU+PPVV0TnbTKAOkyCxflzvnWp0iT3JC+e h2P6L7MXscZfyEFOoytMYoDhzgWGSiSu/+Tkdc4p96AeamHuPsmMOp9gmXmf5m0BxYPkHk owhTr9tSMr2sq03wWYhenFych2gF+n0= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-1-UJ-kJYPPNiiBixuxkQ5ctA-1; Tue, 28 Jul 2026 17:29:43 -0400 X-MC-Unique: UJ-kJYPPNiiBixuxkQ5ctA-1 X-Mimecast-MFC-AGG-ID: UJ-kJYPPNiiBixuxkQ5ctA_1785274183 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-8efad04d884so5394576d6.0 for ; Tue, 28 Jul 2026 14:29:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1785274183; x=1785878983; darn=nongnu.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=OxDVdIsxN8IKGNvSivF0AG9skCApqvHzO/0VPP4Sr8I=; b=o9acmI+MtM+Os4SfqUzMUPlbi19k3U2lbY24wHcz2OX8TwH3uZ6yResaDkS5JPUztW bh+8oVIpBl214nz2b3lnt8WtSQrYDeh0mbZJXq5QdSa20yCZf2fDUXUKOHWPl/3q3Tfi d30PjAO1rvSA7BuOz9V/ZFXZemqx4WIS0GHipxRJqR+emqdSR7VqwRtpp2BR5CgLUMBW 3EkxHzqQOXwKVFoDcG/KqIlRZVZED7Mq++k5vkBdmmi8pFbWA+TIsAiHf+jW0YxwLKM8 QK4hHWmmOIRRV8vEL0MdLLt2HnfMVhm4lqAVVf7cnVosgmftTuozCmelpEUuo8WWRHOQ 6xaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785274183; x=1785878983; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=OxDVdIsxN8IKGNvS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P1CM= X-Received: by 2002:a05:6214:54ca:b0:8fd:6dc5:94c with SMTP id 6a1803df08f44-90817429239mr47724196d6.65.1785274182725; Tue, 28 Jul 2026 14:29:42 -0700 (PDT) X-Received: by 2002:a05:6214:54ca:b0:8fd:6dc5:94c with SMTP id 6a1803df08f44-90817429239mr47723796d6.65.1785274182143; Tue, 28 Jul 2026 14:29:42 -0700 (PDT) Received: from x1.local (bras-vprn-aurron9134w-lp130-03-174-91-117-74.dsl.bell.ca. [174.91.117.74]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-9081dd3b56esm8685996d6.26.2026.07.28.14.29.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2026 14:29:41 -0700 (PDT) Date: Tue, 28 Jul 2026 17:29:35 -0400 From: Peter Xu To: qemu-devel@nongnu.org Cc: Fabiano Rosas , Juraj Marcin , Feifan Qian , Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= Subject: Re: [PATCH v2 4/5] migration: Fix rare hang of migration_channel_read_peek() Message-ID: References: <20260728210417.1925078-1-peterx@redhat.com> <20260728210417.1925078-5-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260728210417.1925078-5-peterx@redhat.com> 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: -36 X-Spam_score: -3.7 X-Spam_bar: --- X-Spam_report: (-3.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.58, 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_H2=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On Tue, Jul 28, 2026 at 05:04:16PM -0400, Peter Xu wrote: > In an unlikely case, when a migration stream is attached to the destination > QEMU and only send <4 bytes to the channel as magic, it's possible that > migration_channel_read_peek() may spin forever. > > Fix it by adding a manual sleep for partial read. > > Since the path isn't attached to a coroutine, it means when partial read > happens, there's yet not much we can do but hang the main thread, it will > happen even for len==0 case. It means monitors can hang due to this, > either partial read or no data arrived (but connection established). > > Leave this for later, the hope is this is extremely rare in production. > > Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3889 > Reported-by: Feifan Qian > Cc: Daniel P. Berrangé > Signed-off-by: Peter Xu > --- > migration/channel.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/migration/channel.c b/migration/channel.c > index 1e2935f926..f446561b59 100644 > --- a/migration/channel.c > +++ b/migration/channel.c > @@ -296,9 +296,16 @@ int migration_channel_read_peek(QIOChannel *ioc, > > if (len == buflen) { > break; > + } else if (len == 0) { I think this should be QIO_CHANNEL_ERR_BLOCK, not 0.. I'll fix it when I post v3, and I'll do some more tests. > + qio_channel_wait_cond(ioc, G_IO_IN); > + } else { > + /* > + * When partially ready, we can't use qio_channel_wait_cond() > + * because it will return immediately. Apply a manual wait. > + */ > + assert(!qemu_in_coroutine()); > + g_usleep(1000); > } > - > - qio_channel_wait_cond(ioc, G_IO_IN); > } > > return 0; > -- > 2.54.0 > -- Peter Xu