From nobody Wed Nov 5 07:16:04 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534178481107646.9816216730591; Mon, 13 Aug 2018 09:41:21 -0700 (PDT) Received: from localhost ([::1]:40434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpFuB-0006xM-TV for importer@patchew.org; Mon, 13 Aug 2018 12:41:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpFs7-0004kP-VB for qemu-devel@nongnu.org; Mon, 13 Aug 2018 12:39:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fpFs3-00011k-0y for qemu-devel@nongnu.org; Mon, 13 Aug 2018 12:39:11 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:57053) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fpFs2-000110-QI; Mon, 13 Aug 2018 12:39:06 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id ED0D021E31; Mon, 13 Aug 2018 12:39:04 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 13 Aug 2018 12:39:04 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id C6F8EE405D; Mon, 13 Aug 2018 12:39:02 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=mesmtp; bh=/ideQeRRjunNXD //L4a/EvNwvzFdoV8y6Dye+QoxrI0=; b=IOZx9krloCsS5pTXzgiu45ifoqMTLg vBPTI770p6nwb2BEdzZl09cExlYBsXrjwsSweu5Mgs3wyaJkIdT4pLY1LO9LS4c1 gx856MyAd9adxUpO0jDMRGLj8IOh7ETrl6SmpkLgJquwzbaLE8knK82vxh+dBqof ZRyGCQ/xxuq4o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=/ideQeRRjunNXD//L4a/EvNwvzFdoV8y6Dye+QoxrI0=; b=rxwGnHfz jbz6j9iZtCurmCuERV/ZtcQKfewPnbLpDBsNDhHgsL+RYrCkVS61rbHJomllJVTr 5Sao7OLGa39XpOWUxakypcMsAYl5Rvqg5KyPmC3jtWEBiHOIE4Sp0lCzHhGE29Ma Z0u7c2XqZrj64YgWHrSz020Js1P7XKsogk2ujp+X1XCt+eE5ri0tN3uhuG4hvnXs 3WVeKKoZjk0amuCAX/Jn2g1+n/GZwb34cq65BkuX1Yv3UTjkuZE1TwGHZ2amfcVA WCdIPfDKT8IdQQdExzGZiLXD8Rpd/roK4emThKOJFc3clls8M5mfJQJsv8Ty6XS3 7VdeKr4oMeO8Sw== X-ME-Proxy: X-ME-Sender: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Mon, 13 Aug 2018 12:38:57 -0400 Message-Id: <20180813163859.17964-2-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180813163859.17964-1-cota@braap.org> References: <20180813163859.17964-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.25 Subject: [Qemu-devel] [PATCH 1/3] qom: use cpu->in_cpu_list instead of QTAILQ_IN_USE 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: Peter Crosthwaite , Riku Voipio , Alexander Graf , Laurent Vivier , qemu-ppc@nongnu.org, Paolo Bonzini , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This paves the way for implementing the CPU list with an RCU QLIST. Signed-off-by: Emilio G. Cota --- cpus-common.c | 3 ++- include/qom/cpu.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cpus-common.c b/cpus-common.c index 59f751ecf9..6eaedae60b 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -85,6 +85,7 @@ void cpu_list_add(CPUState *cpu) assert(!cpu_index_auto_assigned); } QTAILQ_INSERT_TAIL(&cpus, cpu, node); + cpu->in_cpu_list =3D true; qemu_mutex_unlock(&qemu_cpu_list_lock); =20 finish_safe_work(cpu); @@ -93,7 +94,7 @@ void cpu_list_add(CPUState *cpu) void cpu_list_remove(CPUState *cpu) { qemu_mutex_lock(&qemu_cpu_list_lock); - if (!QTAILQ_IN_USE(cpu, node)) { + if (!cpu->in_cpu_list) { /* there is nothing to undo since cpu_exec_init() hasn't been call= ed */ qemu_mutex_unlock(&qemu_cpu_list_lock); return; diff --git a/include/qom/cpu.h b/include/qom/cpu.h index bd796579ee..aa555e27a7 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -411,6 +411,8 @@ struct CPUState { =20 bool ignore_memory_transaction_failures; =20 + bool in_cpu_list; /* protected by qemu_cpu_list_lock */ + /* Note that this is accessed at the start of every TB via a negative offset from AREG0. Leave this field at the end so as to make the (absolute value) offset as small as possible. This reduces code --=20 2.17.1 From nobody Wed Nov 5 07:16:04 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534178477967231.52582073772214; Mon, 13 Aug 2018 09:41:17 -0700 (PDT) Received: from localhost ([::1]:40433 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpFu8-0006x0-Py for importer@patchew.org; Mon, 13 Aug 2018 12:41:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43318) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpFs7-0004kN-Us for qemu-devel@nongnu.org; Mon, 13 Aug 2018 12:39:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fpFs2-00011T-U6 for qemu-devel@nongnu.org; Mon, 13 Aug 2018 12:39:11 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:48063) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fpFs2-000112-Lh; Mon, 13 Aug 2018 12:39:06 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id DAF1321E1C; Mon, 13 Aug 2018 12:39:04 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 13 Aug 2018 12:39:04 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 039AFE421C; Mon, 13 Aug 2018 12:39:03 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=mesmtp; bh=p4QplbzOEluEbN FLQmSwPc94mE9iNw5MGn/1/2B4s0A=; b=hjsFO0lWrBBD0A0myJhyZdV0wRXMmp zFZW1o0CBF7TYtwNV7yhqzg5yZGMzA0AIEu+DUlBxChHreOp5FLZ/xLZAvFSLTu+ 0Y3udgN97jeSZARNOs0lidW/C7Xka1F0nIAYW+M1RxRGJeXZGCti4RjVdUlK+Ico 5gSWWS5hGJKFE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=p4QplbzOEluEbNFLQmSwPc94mE9iNw5MGn/1/2B4s0A=; b=rjRU3tw1 CcPrreEnlSPOSKxRIL+rNxGQ4RRBcZU8mTfVeU5DoeoEZHETbyRkw6RBTPFA/PeK mSsMokBuAFjBGd7Jt7m8vsEDYoQs3AcSeH5C9hilHVHnECqnglTRhKpiMu29JyWT RUOwSpiYgN+pDFDAAXi/wzan9QNLzp3MqD5/nj+ggpZX6fcIVbAgNL0HLI9/HXGR GVfBuZNgbQkv4duXgbP6XhxNvxmBTV1UHqiZmUUG4K0HqUa79O9+wPXOdPmzpAhV rgXCUwI3DKKJ7D0UmbHbqDkStXIL5YlUMpNlgsXVxyHgKTQrAKs6L0EmJJwOe6CZ 4QwdsLFezUXYQg== X-ME-Proxy: X-ME-Sender: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Mon, 13 Aug 2018 12:38:58 -0400 Message-Id: <20180813163859.17964-3-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180813163859.17964-1-cota@braap.org> References: <20180813163859.17964-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.25 Subject: [Qemu-devel] [PATCH 2/3] spapr: do not use CPU_FOREACH_REVERSE 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: Peter Crosthwaite , Riku Voipio , Alexander Graf , Laurent Vivier , qemu-ppc@nongnu.org, Paolo Bonzini , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This paves the way for implementing the CPU list with an RCU QLIST, which cannot be traversed in reverse order. Note that this is the only caller of CPU_FOREACH_REVERSE. Signed-off-by: Emilio G. Cota Acked-by: David Gibson --- hw/ppc/spapr.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 421b2dd09b..2ef5be2790 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -622,9 +622,12 @@ static void spapr_populate_cpu_dt(CPUState *cs, void *= fdt, int offset, =20 static void spapr_populate_cpus_dt_node(void *fdt, sPAPRMachineState *spap= r) { + CPUState **rev; CPUState *cs; + int n_cpus; int cpus_offset; char *nodename; + int i; =20 cpus_offset =3D fdt_add_subnode(fdt, 0, "cpus"); _FDT(cpus_offset); @@ -635,8 +638,19 @@ static void spapr_populate_cpus_dt_node(void *fdt, sPA= PRMachineState *spapr) * We walk the CPUs in reverse order to ensure that CPU DT nodes * created by fdt_add_subnode() end up in the right order in FDT * for the guest kernel the enumerate the CPUs correctly. + * + * The CPU list cannot be traversed in reverse order, so we need + * to do extra work. */ - CPU_FOREACH_REVERSE(cs) { + n_cpus =3D 0; + rev =3D NULL; + CPU_FOREACH(cs) { + rev =3D g_renew(CPUState *, rev, n_cpus + 1); + rev[n_cpus++] =3D cs; + } + + for (i =3D n_cpus - 1; i >=3D 0; i--) { + CPUState *cs =3D rev[i]; PowerPCCPU *cpu =3D POWERPC_CPU(cs); int index =3D spapr_get_vcpu_id(cpu); DeviceClass *dc =3D DEVICE_GET_CLASS(cs); --=20 2.17.1 From nobody Wed Nov 5 07:16:04 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534178488706422.1681636904384; Mon, 13 Aug 2018 09:41:28 -0700 (PDT) Received: from localhost ([::1]:40435 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpFuC-0006yK-Vh for importer@patchew.org; Mon, 13 Aug 2018 12:41:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43323) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpFs7-0004kQ-Vf for qemu-devel@nongnu.org; Mon, 13 Aug 2018 12:39:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fpFs2-00011f-W6 for qemu-devel@nongnu.org; Mon, 13 Aug 2018 12:39:11 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:46859) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fpFs2-000111-QC; Mon, 13 Aug 2018 12:39:06 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id D95F621E07; Mon, 13 Aug 2018 12:39:04 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 13 Aug 2018 12:39:04 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 490C1E4695; Mon, 13 Aug 2018 12:39:03 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=mesmtp; bh=fT5SV38HN3bzav KifHZKt8TAy/X7pQ0qw0AHK2aL1M0=; b=Ix3JYDoBosuHL3PLiCECXZHuQz3z20 IzOSiN4w3w0VEdKLpbMccYQt0bQ+e1xTvundrb7oQ9wrC3d/efRbg6RQoL+fM17L EfMXACZjSBSBHCoR1elEWlym649Lyfmysdf7iMcEpRzc7hvcmZnMCcuXrdvN3bt6 hnMpOEGNfw9DI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=fT5SV38HN3bzavKifHZKt8TAy/X7pQ0qw0AHK2aL1M0=; b=eA1xt8jD AW4W1f0ErdqCwOcpreH6a7742NvdT5wj47hWOVp7R2vJVLOsnWh+aTOnuOOvmloN +d79m0U5QrZsJ9eP2KfGSCDkOf0DceAL0Cc53rEDsHBxnUFCE9njHKMauMbV7Z7e WJuhR0sbklV7FbsyEOba6ps7+/1Oyp+vcR9hdDMDU2AKrghFD8sAQJxAyp6MqY2G n0rBMkIuCOAgb4cWjT011nU38r0OZTetj4We60syUN+0bs67d7+/q6kNwr6mMISF +aifBCYXCXunGfZEOtwWya8ASctdPx/GTKuchH8sue7GX+RhMSoquuQ0S+hwlU2x rZs4rdP9an0I4w== X-ME-Proxy: X-ME-Sender: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Mon, 13 Aug 2018 12:38:59 -0400 Message-Id: <20180813163859.17964-4-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180813163859.17964-1-cota@braap.org> References: <20180813163859.17964-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.25 Subject: [Qemu-devel] [PATCH 3/3] qom: implement CPU list with an RCU QLIST 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: Peter Crosthwaite , Riku Voipio , Alexander Graf , Laurent Vivier , qemu-ppc@nongnu.org, Paolo Bonzini , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Iterating over the list without using atomics is undefined behaviour, since the list can be modified concurrently by other threads (e.g. every time a new thread is created in user-mode). Fix it by implementing the CPU list as an RCU QLIST. This requires a little bit of extra work to insert CPUs at the tail of the list and to iterate over the list in reverse order (see previous patch). One might be tempted to just insert new CPUs at the head of the list. However, I think this might lead to hard-to-debug issues, since it is possible that callers are assuming that CPUs are inserted at the tail (just like spapr code did in the previous patch). So instead of auditing all callers, this patch simply keeps the old behaviour. Signed-off-by: Emilio G. Cota --- cpus-common.c | 19 +++++++++++++++---- cpus.c | 2 +- exec.c | 2 +- include/qom/cpu.h | 15 +++++++-------- linux-user/main.c | 2 +- linux-user/syscall.c | 2 +- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/cpus-common.c b/cpus-common.c index 6eaedae60b..d8e8db48dd 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -77,6 +77,8 @@ static void finish_safe_work(CPUState *cpu) =20 void cpu_list_add(CPUState *cpu) { + CPUState *cs, *cs_next; + qemu_mutex_lock(&qemu_cpu_list_lock); if (cpu->cpu_index =3D=3D UNASSIGNED_CPU_INDEX) { cpu->cpu_index =3D cpu_get_free_index(); @@ -84,7 +86,18 @@ void cpu_list_add(CPUState *cpu) } else { assert(!cpu_index_auto_assigned); } - QTAILQ_INSERT_TAIL(&cpus, cpu, node); + /* poor man's tail insert */ + CPU_FOREACH_SAFE(cs, cs_next) { + if (cs_next =3D=3D NULL) { + break; + } + } + if (cs =3D=3D NULL) { + QLIST_INSERT_HEAD_RCU(&cpus, cpu, node); + } else { + g_assert(cs_next =3D=3D NULL); + QLIST_INSERT_AFTER_RCU(cs, cpu, node); + } cpu->in_cpu_list =3D true; qemu_mutex_unlock(&qemu_cpu_list_lock); =20 @@ -100,9 +113,7 @@ void cpu_list_remove(CPUState *cpu) return; } =20 - assert(!(cpu_index_auto_assigned && cpu !=3D QTAILQ_LAST(&cpus, CPUTai= lQ))); - - QTAILQ_REMOVE(&cpus, cpu, node); + QLIST_REMOVE_RCU(cpu, node); cpu->cpu_index =3D UNASSIGNED_CPU_INDEX; qemu_mutex_unlock(&qemu_cpu_list_lock); } diff --git a/cpus.c b/cpus.c index b5844b7103..82e298d825 100644 --- a/cpus.c +++ b/cpus.c @@ -1491,7 +1491,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) atomic_mb_set(&cpu->exit_request, 0); } =20 - qemu_tcg_rr_wait_io_event(cpu ? cpu : QTAILQ_FIRST(&cpus)); + qemu_tcg_rr_wait_io_event(cpu ? cpu : QLIST_FIRST_RCU(&cpus)); deal_with_unplugged_cpus(); } =20 diff --git a/exec.c b/exec.c index 4f5df07b6a..cab0da6919 100644 --- a/exec.c +++ b/exec.c @@ -114,7 +114,7 @@ int target_page_bits; bool target_page_bits_decided; #endif =20 -struct CPUTailQ cpus =3D QTAILQ_HEAD_INITIALIZER(cpus); +struct CPUTailQ cpus =3D QLIST_HEAD_INITIALIZER(cpus); /* current CPU in the current thread. It is only valid inside cpu_exec() */ __thread CPUState *current_cpu; diff --git a/include/qom/cpu.h b/include/qom/cpu.h index aa555e27a7..407c57254d 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -26,6 +26,7 @@ #include "exec/memattrs.h" #include "qapi/qapi-types-run-state.h" #include "qemu/bitmap.h" +#include "qemu/rcu_queue.h" #include "qemu/queue.h" #include "qemu/thread.h" =20 @@ -371,7 +372,7 @@ struct CPUState { struct GDBRegisterState *gdb_regs; int gdb_num_regs; int gdb_num_g_regs; - QTAILQ_ENTRY(CPUState) node; + QLIST_ENTRY(CPUState) node; =20 /* ice debug support */ QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints; @@ -436,15 +437,13 @@ struct CPUState { GArray *iommu_notifiers; }; =20 -QTAILQ_HEAD(CPUTailQ, CPUState); +QLIST_HEAD(CPUTailQ, CPUState); extern struct CPUTailQ cpus; -#define CPU_NEXT(cpu) QTAILQ_NEXT(cpu, node) -#define CPU_FOREACH(cpu) QTAILQ_FOREACH(cpu, &cpus, node) +#define CPU_NEXT(cpu) QLIST_NEXT_RCU(cpu, node) +#define CPU_FOREACH(cpu) QLIST_FOREACH_RCU(cpu, &cpus, node) #define CPU_FOREACH_SAFE(cpu, next_cpu) \ - QTAILQ_FOREACH_SAFE(cpu, &cpus, node, next_cpu) -#define CPU_FOREACH_REVERSE(cpu) \ - QTAILQ_FOREACH_REVERSE(cpu, &cpus, CPUTailQ, node) -#define first_cpu QTAILQ_FIRST(&cpus) + QLIST_FOREACH_SAFE_RCU(cpu, &cpus, node, next_cpu) +#define first_cpu QLIST_FIRST_RCU(&cpus) =20 extern __thread CPUState *current_cpu; =20 diff --git a/linux-user/main.c b/linux-user/main.c index ea00dd9057..99afb14ae5 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -126,7 +126,7 @@ void fork_end(int child) Discard information about the parent threads. */ CPU_FOREACH_SAFE(cpu, next_cpu) { if (cpu !=3D thread_cpu) { - QTAILQ_REMOVE(&cpus, cpu, node); + QLIST_REMOVE_RCU(cpu, node); } } qemu_init_cpu_list(); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index dfc851cc35..41b592dee3 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8040,7 +8040,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long = arg1, TaskState *ts; =20 /* Remove the CPU from the list. */ - QTAILQ_REMOVE(&cpus, cpu, node); + QLIST_REMOVE_RCU(cpu, node); =20 cpu_list_unlock(); =20 --=20 2.17.1