From nobody Thu Nov 6 14:16:22 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15421959623748.657439349056517; Wed, 14 Nov 2018 03:46:02 -0800 (PST) Received: from localhost ([::1]:59626 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMtcO-0002nw-R8 for importer@patchew.org; Wed, 14 Nov 2018 06:46:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMtaY-0001pW-8g for qemu-devel@nongnu.org; Wed, 14 Nov 2018 06:44:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gMtaV-00038C-5e for qemu-devel@nongnu.org; Wed, 14 Nov 2018 06:44:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51958) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gMtaV-00037y-0z for qemu-devel@nongnu.org; Wed, 14 Nov 2018 06:44:03 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 235DB2D81A; Wed, 14 Nov 2018 11:44:02 +0000 (UTC) Received: from donizetti.mxp.redhat.com (unknown [10.32.181.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14C2560851; Wed, 14 Nov 2018 11:44:00 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 12:44:00 +0100 Message-Id: <20181114114400.15577-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 14 Nov 2018 11:44:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] cpus: run work items for all vCPUs if single-threaded X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cota@braap.org, alex.bennee@linaro.org, dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This avoids the following deadlock: 1) a thread calls run_on_cpu for CPU 2 from a timer, and single_tcg_halt_co= nd is signaled 2) CPU 1 is running and exits. It finds no work item and enters CPU 2 3) because the I/O thread is stuck in run_on_cpu, the round-robin kick timer never triggers, and CPU 2 never runs the work item 4) run_on_cpu never completes Signed-off-by: Paolo Bonzini Reviewed-by: Emilio G. Cota --- cpus.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cpus.c b/cpus.c index a2b33ccb29..0ddeeefc14 100644 --- a/cpus.c +++ b/cpus.c @@ -1220,16 +1220,20 @@ static void qemu_wait_io_event_common(CPUState *cpu) process_queued_cpu_work(cpu); } =20 -static void qemu_tcg_rr_wait_io_event(CPUState *cpu) +static void qemu_tcg_rr_wait_io_event(void) { + CPUState *cpu; + while (all_cpu_threads_idle()) { stop_tcg_kick_timer(); - qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex); + qemu_cond_wait(first_cpu->halt_cond, &qemu_global_mutex); } =20 start_tcg_kick_timer(); =20 - qemu_wait_io_event_common(cpu); + CPU_FOREACH(cpu) { + qemu_wait_io_event_common(cpu); + } } =20 static void qemu_wait_io_event(CPUState *cpu) @@ -1562,7 +1566,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) qemu_notify_event(); } =20 - qemu_tcg_rr_wait_io_event(cpu ? cpu : first_cpu); + qemu_tcg_rr_wait_io_event(); deal_with_unplugged_cpus(); } =20 --=20 2.17.1