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=-8.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 6D458C48BD1 for ; Wed, 9 Jun 2021 13:03:14 +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 02D74613AE for ; Wed, 9 Jun 2021 13:03:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 02D74613AE 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]:34890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqxrV-0007ni-5s for qemu-devel@archiver.kernel.org; Wed, 09 Jun 2021 09:03:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51316) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqxqi-0006lr-2B for qemu-devel@nongnu.org; Wed, 09 Jun 2021 09:02:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35305) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqxqb-0004Qr-8l for qemu-devel@nongnu.org; Wed, 09 Jun 2021 09:02:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623243736; 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: in-reply-to:in-reply-to:references:references; bh=JtZNgozJ6EBTBHxfjzp+NA47tr95/ImwKIjV5mpHh6s=; b=IsMucLSXLo/P654pY4pk8cJP2jNpL46kRmCi+ZcRCneQCT48uqb8OopaiabTIEqK0HmBu5 WeXaFjB/G0DtYjqKXFHPKY9xRU8RhfNDHDf+gZ2LC7gT+HDb50bQx7rPUgxRxV/rNSLAQA Q2pMR2WqTRSPyIVTwSez+ixGzcSIILg= 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-496-96UgFqchNuOcYSXfml6olQ-1; Wed, 09 Jun 2021 09:02:12 -0400 X-MC-Unique: 96UgFqchNuOcYSXfml6olQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A6937801B1F; Wed, 9 Jun 2021 13:02:11 +0000 (UTC) Received: from redhat.com (ovpn-114-230.ams2.redhat.com [10.36.114.230]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0FDEC18A9E; Wed, 9 Jun 2021 13:02:08 +0000 (UTC) Date: Wed, 9 Jun 2021 15:02:07 +0200 From: Kevin Wolf To: Paolo Bonzini Subject: Re: [PATCH v2] async: the main AioContext is only "current" if under the BQL Message-ID: References: <20210609122234.544153-1-pbonzini@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210609122234.544153-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.199, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=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: eesposit@redhat.com, vsementsov@virtuozzo.com, stefanha@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Am 09.06.2021 um 14:22 hat Paolo Bonzini geschrieben: > If we want to wake up a coroutine from a worker thread, aio_co_wake() > currently does not work. In that scenario, aio_co_wake() calls > aio_co_enter(), but there is no current AioContext and therefore > qemu_get_current_aio_context() returns the main thread. aio_co_wake() > then attempts to call aio_context_acquire() instead of going through > aio_co_schedule(). > > The default case of qemu_get_current_aio_context() was added to cover > synchronous I/O started from the vCPU thread, but the main and vCPU > threads are quite different. The main thread is an I/O thread itself, > only running a more complicated event loop; the vCPU thread instead > is essentially a worker thread that occasionally calls > qemu_mutex_lock_iothread(). It is only in those critical sections > that it acts as if it were the home thread of the main AioContext. > > Therefore, this patch detaches qemu_get_current_aio_context() from > iothreads, which is a useless complication. The AioContext pointer > is stored directly in the thread-local variable, including for the > main loop. Worker threads (including vCPU threads) optionally behave > as temporary home threads if they have taken the big QEMU lock, > but if that is not the case they will always schedule coroutines > on remote threads via aio_co_schedule(). > > With this change, qemu_mutex_iothread_locked() must be changed from > true to false. The previous value of true was needed because the > main thread did not have an AioContext in the thread-local variable, > but now it does have one. > > Reported-by: Vladimir Sementsov-Ogievskiy > Signed-off-by: Paolo Bonzini The commit message doesn't specify, but in the buggy case, are we talking about calling aio_co_wake() for a coroutine in the main context specifically, right? Could we have a unit test for this scenario? But the change looks reasonable to me. Kevin