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 X-Spam-Level: X-Spam-Status: No, score=-5.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE82DC433E0 for ; Wed, 20 Jan 2021 16:03:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 767652339E for ; Wed, 20 Jan 2021 16:03:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 767652339E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l2Fwn-00041M-I8 for qemu-devel@archiver.kernel.org; Wed, 20 Jan 2021 11:03:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l2Fuc-0002QY-0b for qemu-devel@nongnu.org; Wed, 20 Jan 2021 11:00:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32532) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l2FuT-0004aX-6s for qemu-devel@nongnu.org; Wed, 20 Jan 2021 11:00:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611158440; 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=DFCqmoWikWRDLDSmw2b0t8+shNC7DODZ5NDgS4pLGtg=; b=MzOnWB0TLd+z2cO7VpeK2Ny6H84VmzBVLwy8v6dLv31RO662MO0FOswtVFnf32cBmRa3i8 IsRIAtYSrJDHGUbWhzs3e6BkJIdWtYC6v96lyl1HMIx3F0wAbmEVOdGGVi2KHOf+X18sBr rJpjFY7gTLMkTSwCAtyvVQApWA2ugtI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-537--SLkILbTORqcPcSqO-xWXQ-1; Wed, 20 Jan 2021 11:00:36 -0500 X-MC-Unique: -SLkILbTORqcPcSqO-xWXQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 80E611005504; Wed, 20 Jan 2021 16:00:34 +0000 (UTC) Received: from dresden.str.redhat.com (ovpn-114-178.ams2.redhat.com [10.36.114.178]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1C3641A3D8; Wed, 20 Jan 2021 16:00:31 +0000 (UTC) Subject: Re: [PATCH v4 00/23] backup performance: block_status + async From: Max Reitz To: Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org References: <20210116214705.822267-1-vsementsov@virtuozzo.com> <3a5ea1b1-1137-4ac5-5aac-5bdec0b7b0d5@redhat.com> <29cccc86-a450-3326-2d70-f3022e32b5db@redhat.com> <3db87f48-b628-8000-a46a-6d07cdf1ccc3@redhat.com> <8522c1f5-9476-3596-abf0-7f2d83f8844c@redhat.com> Message-ID: Date: Wed, 20 Jan 2021 17:00:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <8522c1f5-9476-3596-abf0-7f2d83f8844c@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=216.205.24.124; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.094, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: kwolf@redhat.com, wencongyang2@huawei.com, xiechanglong.d@gmail.com, qemu-devel@nongnu.org, armbru@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 20.01.21 16:53, Max Reitz wrote: > On 20.01.21 15:44, Max Reitz wrote: >> On 20.01.21 15:34, Max Reitz wrote: > > [...] > >>>  From a glance, it looks to me like two coroutines are created >>> simultaneously in two threads, and so one thread sets up a special >>> SIGUSR2 action, then another reverts SIGUSR2 to the default, and then >>> the first one kills itself with SIGUSR2. >>> >>> Not sure what this has to do with backup, though it is interesting >>> that backup_loop() runs in two threads.  So perhaps some AioContext >>> problem. >> >> Oh, 256 runs two backups concurrently.  So it isn’t that interesting, >> but perhaps part of the problem still.  (I have no idea, still looking.) > > So this is what I found out: > > coroutine-sigaltstack, when creating a new coroutine, sets up a signal > handler for SIGUSR2, then kills itself with SIGUSR2, then uses the > signal handler context (with a sigaltstack) for the new coroutine, and > then (the signal handler returns after a sigsetjmp()) the old SIGUSR2 > behavior is restored. > > What I fail to understand is how this is thread-safe.  Setting up signal > handlers is a process-wide action.  When one thread changes what SIGUSR2 > does, this will affect all threads immediately, so when two threads run > coroutine-sigaltstack’s qemu_coroutine_new() concurrently, and one > thread reverts to the default action before the other has SIGUSR2’ed > itself, that later SIGUSR2 will kill the whole process. > > (I suppose it gets even more interesting when one thread has set up the > sigaltstack, then the other sets up its own sigaltstack, and then both > kill themselves with SIGUSR2, so both coroutines get the same stack...) > > I have no idea why this has never been hit before, but it makes sense > why block-copy backup makes it apparent: It creates 64+x coroutines in a > very short time span, and 256 makes it do so in two threads concurrently > (thanks to launching two backups in two AioContexts in a transaction). > > So...  Looks to me like a bug in coroutine-sigaltstack.  Not sure what > to do now, though.  I don’t think we can use block-copy for backup > before that backend is fixed.  (And that is assuming that it’s indeed > coroutine-sigaltstack’s fault.) > > I’ll try to add some locking, see what it does, and send a mail > concerning coroutine-sigaltstack to qemu-devel. Yeah, adding a mutex around the section where SIGUSR2 handling and the sigaltstack are non-default makes the problem go away. Max