From patchwork Mon Sep 23 16:12:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809824 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id ECF1BCF9C6F for ; Mon, 23 Sep 2024 16:24:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpy-0007rO-Pz; Mon, 23 Sep 2024 12:22:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpW-0006TD-9A for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:30 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpQ-0000bD-9d for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:25 -0400 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48NEBjmJ018607; Mon, 23 Sep 2024 16:22:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=H/4pU4i5/TvIp LOuS2srJQ6STt98S9+c6PDZGCJOhcs=; b=D88uY6FZCf9y6dqnYhWp1VUK2+kFb EMz6jBsjklzpdgXBJi1VePQtE2c1LYo+z5KErW9Mga8gpuZhI23QHmxOx3Mx/6aV 3viTLMlazkxnbZD5qYfKauW+SsxgQC7YOiWHQBQRAF7+tRvGpg1eMSBT/olDcbR/ QDSkKqKXkC3373UXhjSlE3z7Rt9AFlHUIhpmF1AucFYRFKhDg59l1qsoTMkQc0qH 5mm+WK2IaFqEWNBUxsvqx5tZPIufsng0u6yGCG4rH/YJIS9x30AnvxB5lte9UZA6 Bqlf+z8WlXe9vj1DW4PQqKvfmFDS5ezNHeZJzNXVwj3qQwje/AieUBQPw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41skjrd0ed-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:20 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGMJuP024285; Mon, 23 Sep 2024 16:22:19 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41skjrd0e9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:19 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NEF4Sb012489; Mon, 23 Sep 2024 16:22:19 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 41t9fpqg06-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:19 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMHX349414524 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:17 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 18AF620043; Mon, 23 Sep 2024 16:22:17 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ADF2620040; Mon, 23 Sep 2024 16:22:16 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:16 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 01/18] gdbstub: Make gdb_get_char() static Date: Mon, 23 Sep 2024 18:12:56 +0200 Message-ID: <20240923162208.90745-2-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: hMpXotHra_VQdfz7B4WDiTsAqgEylC6I X-Proofpoint-ORIG-GUID: -9953Ptl3K7PnSGlBKiOWkYgTlKHvMUV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 priorityscore=1501 spamscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 clxscore=1015 malwarescore=0 mlxlogscore=931 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230117 Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 It's user-only since commit a7e0f9bd2ace ("gdbstub: abstract target specific details from gdb_put_packet_binary"). Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson --- gdbstub/internals.h | 2 -- gdbstub/user.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/gdbstub/internals.h b/gdbstub/internals.h index bf5a5c63029..5acc36846f3 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -142,8 +142,6 @@ void gdb_create_default_process(GDBState *s); int gdb_signal_to_target(int sig); int gdb_target_signal_to_gdb(int sig); -int gdb_get_char(void); /* user only */ - /** * gdb_continue() - handle continue in mode specific way. */ diff --git a/gdbstub/user.c b/gdbstub/user.c index b36033bc7a2..6a493c5ba3a 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -103,7 +103,7 @@ typedef struct { static GDBUserState gdbserver_user_state; -int gdb_get_char(void) +static int gdb_get_char(void) { uint8_t ch; int ret; From patchwork Mon Sep 23 16:12:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809822 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id DB7BECF9C72 for ; Mon, 23 Sep 2024 16:23:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpc-0006X2-2m; Mon, 23 Sep 2024 12:22:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpW-0006TE-9S for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:31 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpQ-0000bO-Mi for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:29 -0400 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48NCtDAh025675; Mon, 23 Sep 2024 16:22:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=pzYh8X61AcOIy slGUInFv/uLPzcvCXA28/NcWxm1j+U=; b=Lsaldixk0STnk+oeblgT17rFBSo+N FT9S/uAyc+gmiG5lnunPWGhe0keowVIVvozdqjcX2gycbbuFqwBgz4J7Z8EpS8ha ONvf1ZTAP3UwfXYawR5+r++2KESKF98+VwGZb17L2nCs7EzRmQ23exLk17aEEENx 1+Zr7en7EwJK+7OIeEYqtlnFMhLtey5ntR6ZBx44nRsSsAOUUBXzYufq8h7AIiBp RUwmjm92jA4XxPsrR3Xjl7iHxcP/aTJKwD8iogOm3tQ5scdh4okCXFTxOEOy7Kmq 0t/8h7Pr84td9JjZG/yQpuoB8x8bpPfCdPMzLmENgljxjbBOcR8Z/5znA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41sntw558m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:21 +0000 (GMT) Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGMLfE032081; Mon, 23 Sep 2024 16:22:21 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41sntw558g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:20 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NDhh9Y008707; Mon, 23 Sep 2024 16:22:19 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 41t8v0ym0d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:19 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMHRs49414526 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:17 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7FC0120043; Mon, 23 Sep 2024 16:22:17 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2B58820040; Mon, 23 Sep 2024 16:22:17 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:17 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 02/18] gdbstub: Move phy_memory_mode to GDBSystemState Date: Mon, 23 Sep 2024 18:12:57 +0200 Message-ID: <20240923162208.90745-3-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 2T6xRTnjojjEAELqIszvBUvxMcVRvHJn X-Proofpoint-GUID: pBESDwe66eSkFIzXN5gi8L_ej87KlQMW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 adultscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230121 Received-SPF: pass client-ip=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 Follow the convention that all the pieces of the global stub state must be inside a single struct. Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson --- gdbstub/system.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gdbstub/system.c b/gdbstub/system.c index 1ad87fe7fdf..5ce357c6c2b 100644 --- a/gdbstub/system.c +++ b/gdbstub/system.c @@ -35,6 +35,7 @@ typedef struct { CharBackend chr; Chardev *mon_chr; + int phy_memory_mode; } GDBSystemState; GDBSystemState gdbserver_system_state; @@ -445,14 +446,12 @@ void gdb_qemu_exit(int code) /* * Memory access */ -static int phy_memory_mode; - int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr, uint8_t *buf, int len, bool is_write) { CPUClass *cc; - if (phy_memory_mode) { + if (gdbserver_system_state.phy_memory_mode) { if (is_write) { cpu_physical_memory_write(addr, buf, len); } else { @@ -491,7 +490,8 @@ bool gdb_can_reverse(void) void gdb_handle_query_qemu_phy_mem_mode(GArray *params, void *ctx) { - g_string_printf(gdbserver_state.str_buf, "%d", phy_memory_mode); + g_string_printf(gdbserver_state.str_buf, "%d", + gdbserver_system_state.phy_memory_mode); gdb_put_strbuf(); } @@ -503,9 +503,9 @@ void gdb_handle_set_qemu_phy_mem_mode(GArray *params, void *ctx) } if (!gdb_get_cmd_param(params, 0)->val_ul) { - phy_memory_mode = 0; + gdbserver_system_state.phy_memory_mode = 0; } else { - phy_memory_mode = 1; + gdbserver_system_state.phy_memory_mode = 1; } gdb_put_packet("OK"); } From patchwork Mon Sep 23 16:12:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809823 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 3DCA3CF9C6F for ; Mon, 23 Sep 2024 16:23:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpc-0006XM-NP; Mon, 23 Sep 2024 12:22:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpW-0006TC-8m for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:30 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpQ-0000bH-QN for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:29 -0400 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48N7xkQ8012410; Mon, 23 Sep 2024 16:22:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=uMkf2IlyXZQN4 ANh6mm1/Fa3BXo2aYu81eFDQ0qfVGw=; b=jOueSf0wDe5LXWcEEPWMXO/D3ZTaW a+Xf4lg8KyNyHqqNjxLqfDg1CkjZ3BGTANmcI5mrDgQ8x4oxQYu4XrspA9HrKOO4 LykTj9wiEKPJQAi7zlEq6CE6ji00Itn9AePPbb7qzNg5mHNB3RFYiFEcXzlJNQo/ DSADgR4qa0vAIkWe5UNbfsEWdQXYbxecxt11XlKzixyhBVJmotcEGuSrCvzZQ4gm lGEC8FsTVMAibGbySZykIZeaeevqe6pDvRUwheNqrojfvGB3J3j48I86i5lQG6Gv gMLzbHt/O5xcGe8fl6dfNxzH9Pj5n4Z0zrC8M6JveKjGKBizcCX9S6RKg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41snt14pcf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:20 +0000 (GMT) Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGHZWS014888; Mon, 23 Sep 2024 16:22:20 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41snt14pcc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:20 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NFtG1o020820; Mon, 23 Sep 2024 16:22:19 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 41tb62y41d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:19 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMIWb34996876 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:18 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EC61120043; Mon, 23 Sep 2024 16:22:17 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 93F8020040; Mon, 23 Sep 2024 16:22:17 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:17 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 03/18] gdbstub: Move gdb_syscall_mode to GDBSyscallState Date: Mon, 23 Sep 2024 18:12:58 +0200 Message-ID: <20240923162208.90745-4-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: M_rOjN1FMfvqPioJZsSNErU0xhDxW20W X-Proofpoint-GUID: B6Rp2P3c-aMiM_eTlpfA_HUGod6nxFL5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxlogscore=999 priorityscore=1501 suspectscore=0 mlxscore=0 clxscore=1015 impostorscore=0 malwarescore=0 bulkscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230121 Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 Follow the convention that all the pieces of the global stub state must be inside a single struct. Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson --- gdbstub/syscalls.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gdbstub/syscalls.c b/gdbstub/syscalls.c index 4e1295b782d..42307f0abb1 100644 --- a/gdbstub/syscalls.c +++ b/gdbstub/syscalls.c @@ -24,6 +24,11 @@ typedef struct { char syscall_buf[256]; gdb_syscall_complete_cb current_syscall_cb; + enum { + GDB_SYS_UNKNOWN, + GDB_SYS_ENABLED, + GDB_SYS_DISABLED, + } mode; } GDBSyscallState; static GDBSyscallState gdbserver_syscall_state; @@ -37,12 +42,6 @@ static bool gdb_attached(void) return gdbserver_state.init && gdbserver_state.c_cpu; } -static enum { - GDB_SYS_UNKNOWN, - GDB_SYS_ENABLED, - GDB_SYS_DISABLED, -} gdb_syscall_mode; - /* Decide if either remote gdb syscalls or native file IO should be used. */ int use_gdb_syscalls(void) { @@ -57,16 +56,17 @@ int use_gdb_syscalls(void) /* -semihosting-config target=auto */ /* On the first call check if gdb is connected and remember. */ - if (gdb_syscall_mode == GDB_SYS_UNKNOWN) { - gdb_syscall_mode = gdb_attached() ? GDB_SYS_ENABLED : GDB_SYS_DISABLED; + if (gdbserver_syscall_state.mode == GDB_SYS_UNKNOWN) { + gdbserver_syscall_state.mode = gdb_attached() ? GDB_SYS_ENABLED : + GDB_SYS_DISABLED; } - return gdb_syscall_mode == GDB_SYS_ENABLED; + return gdbserver_syscall_state.mode == GDB_SYS_ENABLED; } /* called when the stub detaches */ void gdb_disable_syscalls(void) { - gdb_syscall_mode = GDB_SYS_DISABLED; + gdbserver_syscall_state.mode = GDB_SYS_DISABLED; } void gdb_syscall_reset(void) From patchwork Mon Sep 23 16:12:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809838 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 35998CF9C72 for ; Mon, 23 Sep 2024 16:29:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpi-0006ge-Hy; Mon, 23 Sep 2024 12:22:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpW-0006TF-A9 for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:31 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpQ-0000bL-9Z for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:26 -0400 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48NFT66b019038; Mon, 23 Sep 2024 16:22:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=Cgy2qk6HjG5JJ 0WOIKaJYPb+2l7viaNGKxXp7rBP3wA=; b=BY34Lw+Za2uXpz3BekbNO9Tocry5z HvNpyS/3UJtG27CQDK4mQ9OKma2oXyrpv/qHUN2j7Ict5Wy6RRkQ1nwH+TB+8s03 zBPXp1neVmjjM8rp4/kc+oojFxJto3mgBcFfKLoTilnSJup76pu4Hro/BX8JAvz4 Na2qzvXqzsU3+ovIj4O7hw5TeZS980PTGx/+S8rE8vhXbYESoEJS8nGYgSgj/xoB 5oNtKgikWYN2JXf88T2Dp62XaJvODGMhL2p/9IabbiE1Te9Z3JqvTr0MzTREpEJT JMCrRgT1QwFO0lzEuGA7CxhVNBu6cZBy2bCXgSMFqayTL1kTnBAg2d1XA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41skjrd0eh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:21 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGML0P024405; Mon, 23 Sep 2024 16:22:21 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41skjrd0ee-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:21 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NDoOSU000622; Mon, 23 Sep 2024 16:22:20 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 41t8fufp6m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:20 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMIjW34996878 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:18 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 63ABE20043; Mon, 23 Sep 2024 16:22:18 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0E11C20040; Mon, 23 Sep 2024 16:22:18 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:17 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 04/18] gdbstub: Factor out gdb_try_stop() Date: Mon, 23 Sep 2024 18:12:59 +0200 Message-ID: <20240923162208.90745-5-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: xakpJiLLpjgt5mD9eqLYmM4nzM1TwfPA X-Proofpoint-ORIG-GUID: D1d0S_wUiDJIIZLAL65EciPuO6IrQ_2R X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 priorityscore=1501 spamscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 clxscore=1015 malwarescore=0 mlxlogscore=878 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230117 Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 Move checking and setting allow_stop_reply into a function. Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson --- gdbstub/gdbstub.c | 15 +++++++++++---- gdbstub/internals.h | 2 ++ gdbstub/system.c | 6 ++---- gdbstub/user.c | 11 ++++------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index d08568cea0e..a096104b07a 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -1422,11 +1422,10 @@ static void handle_v_attach(GArray *params, void *user_ctx) gdbserver_state.g_cpu = cpu; gdbserver_state.c_cpu = cpu; - if (gdbserver_state.allow_stop_reply) { + if (gdb_try_stop()) { g_string_printf(gdbserver_state.str_buf, "T%02xthread:", GDB_SIGNAL_TRAP); gdb_append_thread_id(cpu, gdbserver_state.str_buf); g_string_append_c(gdbserver_state.str_buf, ';'); - gdbserver_state.allow_stop_reply = false; cleanup: gdb_put_strbuf(); } @@ -2016,12 +2015,11 @@ static void handle_gen_set(GArray *params, void *user_ctx) static void handle_target_halt(GArray *params, void *user_ctx) { - if (gdbserver_state.allow_stop_reply) { + if (gdb_try_stop()) { g_string_printf(gdbserver_state.str_buf, "T%02xthread:", GDB_SIGNAL_TRAP); gdb_append_thread_id(gdbserver_state.c_cpu, gdbserver_state.str_buf); g_string_append_c(gdbserver_state.str_buf, ';'); gdb_put_strbuf(); - gdbserver_state.allow_stop_reply = false; } /* * Remove all the breakpoints when this query is issued, @@ -2493,3 +2491,12 @@ void gdb_create_default_process(GDBState *s) process->target_xml = NULL; } +bool gdb_try_stop(void) +{ + if (!gdbserver_state.allow_stop_reply) { + return false; + } + + gdbserver_state.allow_stop_reply = false; + return true; +} diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 5acc36846f3..310861e581b 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -215,4 +215,6 @@ void gdb_breakpoint_remove_all(CPUState *cs); int gdb_target_memory_rw_debug(CPUState *cs, hwaddr addr, uint8_t *buf, int len, bool is_write); +bool gdb_try_stop(void); + #endif /* GDBSTUB_INTERNALS_H */ diff --git a/gdbstub/system.c b/gdbstub/system.c index 5ce357c6c2b..fbe9528569c 100644 --- a/gdbstub/system.c +++ b/gdbstub/system.c @@ -141,7 +141,7 @@ static void gdb_vm_state_change(void *opaque, bool running, RunState state) return; } - if (!gdbserver_state.allow_stop_reply) { + if (!gdb_try_stop()) { return; } @@ -211,7 +211,6 @@ static void gdb_vm_state_change(void *opaque, bool running, RunState state) send_packet: gdb_put_packet(buf->str); - gdbserver_state.allow_stop_reply = false; /* disable single step if it was enabled */ cpu_single_step(cpu, 0); @@ -428,10 +427,9 @@ void gdb_exit(int code) trace_gdbstub_op_exiting((uint8_t)code); - if (gdbserver_state.allow_stop_reply) { + if (gdb_try_stop()) { snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code); gdb_put_packet(buf); - gdbserver_state.allow_stop_reply = false; } qemu_chr_fe_deinit(&gdbserver_system_state.chr, true); diff --git a/gdbstub/user.c b/gdbstub/user.c index 6a493c5ba3a..77ba227fc3b 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -181,10 +181,9 @@ void gdb_exit(int code) trace_gdbstub_op_exiting((uint8_t)code); - if (gdbserver_state.allow_stop_reply) { + if (gdb_try_stop()) { snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code); gdb_put_packet(buf); - gdbserver_state.allow_stop_reply = false; } } @@ -222,7 +221,7 @@ int gdb_handlesig(CPUState *cpu, int sig, const char *reason, void *siginfo, if (sig != 0) { gdb_set_stop_cpu(cpu); - if (gdbserver_state.allow_stop_reply) { + if (gdb_try_stop()) { g_string_printf(gdbserver_state.str_buf, "T%02xthread:", gdb_target_signal_to_gdb(sig)); gdb_append_thread_id(cpu, gdbserver_state.str_buf); @@ -231,7 +230,6 @@ int gdb_handlesig(CPUState *cpu, int sig, const char *reason, void *siginfo, g_string_append(gdbserver_state.str_buf, reason); } gdb_put_strbuf(); - gdbserver_state.allow_stop_reply = false; } } /* @@ -276,13 +274,12 @@ void gdb_signalled(CPUArchState *env, int sig) char buf[4]; if (!gdbserver_state.init || gdbserver_user_state.fd < 0 || - !gdbserver_state.allow_stop_reply) { + !gdb_try_stop()) { return; } snprintf(buf, sizeof(buf), "X%02x", gdb_target_signal_to_gdb(sig)); gdb_put_packet(buf); - gdbserver_state.allow_stop_reply = false; } static void gdb_accept_init(int fd) @@ -502,7 +499,7 @@ void gdbserver_fork_end(CPUState *cpu, pid_t pid) gdbserver_user_state.fork_peer_pid = pid; gdbserver_user_state.fork_peer_tid = pid; - if (!gdbserver_state.allow_stop_reply) { + if (!gdb_try_stop()) { goto fail; } g_string_printf(gdbserver_state.str_buf, From patchwork Mon Sep 23 16:13:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809830 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 49FC0CF9C6F for ; Mon, 23 Sep 2024 16:24:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpo-000790-Vg; Mon, 23 Sep 2024 12:22:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpZ-0006XQ-NT for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:35 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpV-0000c9-6x for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:33 -0400 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48N3ge9T015793; Mon, 23 Sep 2024 16:22:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=ykbgOs+Qb6ZSM Dq+eqthx7Au/caWdgCO0evwfHJo8Ys=; b=T85k0tOAdv7MKW1YLGYse972Oo/sB 2nZsci/fiei/hn3PnITC0KUpUaDq6P4GaCHeOArNJhHszurb8GUrMQyzASIZYpFF 5R5NqZ8VV5jAk4kUDZe4JLslJ9aaPUcmKGdwOdk/LJzZHWCr8b8fW7wS+1DA71SU xwrXbIASbOuVvMtUkfXc0eKl25d8kmCHDtsdijW3xGY5bFX5icvmP8s8HwoVblKV atJgMsqOAzQDIqU6fh7V876SWY3T6gGnDl0up6kZhM0uQjx2OMYynG/g8fY3alld YegbnqhjJJEedKW7SwtLPp6pvqicjuc/ar8m2x+qKqVfg6gSJB4wBjYuw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41sntw558x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:24 +0000 (GMT) Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGMMpf032099; Mon, 23 Sep 2024 16:22:24 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41sntw558p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:24 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NDhh9Z008707; Mon, 23 Sep 2024 16:22:20 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 41t8v0ym0e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:20 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMIMF24773346 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:18 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CC22A20043; Mon, 23 Sep 2024 16:22:18 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 767442004D; Mon, 23 Sep 2024 16:22:18 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:18 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 05/18] accel/tcg: Factor out cpu_exec_user() Date: Mon, 23 Sep 2024 18:13:00 +0200 Message-ID: <20240923162208.90745-6-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Q1bTbAzMFirASzwuIpC_ZPj8dMONCBXA X-Proofpoint-GUID: ccqZCz8M9PKIMyXUIvRoXJCfQ7yZN_Xt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 adultscore=0 mlxlogscore=491 bulkscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230121 Received-SPF: pass client-ip=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 All linux-user cpu_loop() implementations contain the same sequence of function calls. Factor them out so that they can be changed in one place. Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson --- accel/tcg/user-exec.c | 12 ++++++++++++ bsd-user/aarch64/target_arch_cpu.h | 6 +----- bsd-user/arm/target_arch_cpu.h | 5 +---- bsd-user/i386/target_arch_cpu.h | 5 +---- bsd-user/x86_64/target_arch_cpu.h | 5 +---- include/exec/cpu-common.h | 2 ++ linux-user/aarch64/cpu_loop.c | 5 +---- linux-user/alpha/cpu_loop.c | 5 +---- linux-user/arm/cpu_loop.c | 5 +---- linux-user/hexagon/cpu_loop.c | 5 +---- linux-user/hppa/cpu_loop.c | 5 +---- linux-user/i386/cpu_loop.c | 5 +---- linux-user/loongarch64/cpu_loop.c | 5 +---- linux-user/m68k/cpu_loop.c | 5 +---- linux-user/microblaze/cpu_loop.c | 5 +---- linux-user/mips/cpu_loop.c | 5 +---- linux-user/openrisc/cpu_loop.c | 5 +---- linux-user/ppc/cpu_loop.c | 5 +---- linux-user/riscv/cpu_loop.c | 5 +---- linux-user/s390x/cpu_loop.c | 5 +---- linux-user/sh4/cpu_loop.c | 5 +---- linux-user/sparc/cpu_loop.c | 5 +---- linux-user/xtensa/cpu_loop.c | 5 +---- 23 files changed, 35 insertions(+), 85 deletions(-) diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 7ddc47b0ba4..ca3e8e988ee 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -1288,3 +1288,15 @@ static void *atomic_mmu_lookup(CPUState *cpu, vaddr addr, MemOpIdx oi, #define DATA_SIZE 16 #include "atomic_template.h" #endif + +int cpu_exec_user(CPUState *cs) +{ + int trapnr; + + cpu_exec_start(cs); + trapnr = cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + return trapnr; +} diff --git a/bsd-user/aarch64/target_arch_cpu.h b/bsd-user/aarch64/target_arch_cpu.h index b288e0d069b..6ab6c07e973 100644 --- a/bsd-user/aarch64/target_arch_cpu.h +++ b/bsd-user/aarch64/target_arch_cpu.h @@ -51,11 +51,7 @@ static inline void target_cpu_loop(CPUARMState *env) abi_long ret; for (;;) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - + trapnr = cpu_exec_user(cs); switch (trapnr) { case EXCP_SWI: /* See arm64/arm64/trap.c cpu_fetch_syscall_args() */ diff --git a/bsd-user/arm/target_arch_cpu.h b/bsd-user/arm/target_arch_cpu.h index 517d0087644..2fa97c168c0 100644 --- a/bsd-user/arm/target_arch_cpu.h +++ b/bsd-user/arm/target_arch_cpu.h @@ -43,10 +43,7 @@ static inline void target_cpu_loop(CPUARMState *env) CPUState *cs = env_cpu(env); for (;;) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch (trapnr) { case EXCP_UDEF: case EXCP_NOCP: diff --git a/bsd-user/i386/target_arch_cpu.h b/bsd-user/i386/target_arch_cpu.h index 9bf2c4244b7..cbc4d77daba 100644 --- a/bsd-user/i386/target_arch_cpu.h +++ b/bsd-user/i386/target_arch_cpu.h @@ -110,10 +110,7 @@ static inline void target_cpu_loop(CPUX86State *env) /* target_siginfo_t info; */ for (;;) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch (trapnr) { case 0x80: { diff --git a/bsd-user/x86_64/target_arch_cpu.h b/bsd-user/x86_64/target_arch_cpu.h index 4094d61da1a..5442056d009 100644 --- a/bsd-user/x86_64/target_arch_cpu.h +++ b/bsd-user/x86_64/target_arch_cpu.h @@ -118,10 +118,7 @@ static inline void target_cpu_loop(CPUX86State *env) /* target_siginfo_t info; */ for (;;) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch (trapnr) { case EXCP_SYSCALL: diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 2e1b499cb71..4a7b43f9aa3 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -226,6 +226,8 @@ G_NORETURN void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc); /* accel/tcg/cpu-exec.c */ int cpu_exec(CPUState *cpu); +/* accel/tcg/user-exec.c */ +int cpu_exec_user(CPUState *cs); /** * env_archcpu(env) diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index 71cdc8be50c..9104996fd46 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -83,10 +83,7 @@ void cpu_loop(CPUARMState *env) abi_long ret; for (;;) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch (trapnr) { case EXCP_SWI: diff --git a/linux-user/alpha/cpu_loop.c b/linux-user/alpha/cpu_loop.c index 2ea039aa71f..dda42aa9ee7 100644 --- a/linux-user/alpha/cpu_loop.c +++ b/linux-user/alpha/cpu_loop.c @@ -32,10 +32,7 @@ void cpu_loop(CPUAlphaState *env) while (1) { bool arch_interrupt = true; - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch (trapnr) { case EXCP_RESET: diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index ec665862d93..81fb01c4f95 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -325,10 +325,7 @@ void cpu_loop(CPUARMState *env) abi_ulong ret; for(;;) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch(trapnr) { case EXCP_UDEF: diff --git a/linux-user/hexagon/cpu_loop.c b/linux-user/hexagon/cpu_loop.c index d41159e52ad..678d8a42abb 100644 --- a/linux-user/hexagon/cpu_loop.c +++ b/linux-user/hexagon/cpu_loop.c @@ -33,10 +33,7 @@ void cpu_loop(CPUHexagonState *env) target_ulong ret; for (;;) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch (trapnr) { case EXCP_INTERRUPT: diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c index bc093b8fe8b..121763a56cb 100644 --- a/linux-user/hppa/cpu_loop.c +++ b/linux-user/hppa/cpu_loop.c @@ -114,10 +114,7 @@ void cpu_loop(CPUHPPAState *env) int trapnr; while (1) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch (trapnr) { case EXCP_SYSCALL: diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index 92beb6830cc..8707a3eaf25 100644 --- a/linux-user/i386/cpu_loop.c +++ b/linux-user/i386/cpu_loop.c @@ -210,10 +210,7 @@ void cpu_loop(CPUX86State *env) abi_ulong ret; for(;;) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch(trapnr) { case 0x80: diff --git a/linux-user/loongarch64/cpu_loop.c b/linux-user/loongarch64/cpu_loop.c index 73d7b6796a4..1735c1c4ff1 100644 --- a/linux-user/loongarch64/cpu_loop.c +++ b/linux-user/loongarch64/cpu_loop.c @@ -18,10 +18,7 @@ void cpu_loop(CPULoongArchState *env) abi_long ret; for (;;) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch (trapnr) { case EXCP_INTERRUPT: diff --git a/linux-user/m68k/cpu_loop.c b/linux-user/m68k/cpu_loop.c index f79b8e4ab05..8e2f9161c64 100644 --- a/linux-user/m68k/cpu_loop.c +++ b/linux-user/m68k/cpu_loop.c @@ -30,10 +30,7 @@ void cpu_loop(CPUM68KState *env) unsigned int n; for(;;) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch(trapnr) { case EXCP_ILLEGAL: diff --git a/linux-user/microblaze/cpu_loop.c b/linux-user/microblaze/cpu_loop.c index 212e62d0a62..3867a62c07b 100644 --- a/linux-user/microblaze/cpu_loop.c +++ b/linux-user/microblaze/cpu_loop.c @@ -29,10 +29,7 @@ void cpu_loop(CPUMBState *env) CPUState *cs = env_cpu(env); while (1) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch (trapnr) { case EXCP_INTERRUPT: diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c index 462387a0737..d14af50cbbe 100644 --- a/linux-user/mips/cpu_loop.c +++ b/linux-user/mips/cpu_loop.c @@ -71,10 +71,7 @@ void cpu_loop(CPUMIPSState *env) # endif for(;;) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch(trapnr) { case EXCP_SYSCALL: diff --git a/linux-user/openrisc/cpu_loop.c b/linux-user/openrisc/cpu_loop.c index a7aa586c8f9..f1eb799bd27 100644 --- a/linux-user/openrisc/cpu_loop.c +++ b/linux-user/openrisc/cpu_loop.c @@ -30,10 +30,7 @@ void cpu_loop(CPUOpenRISCState *env) abi_long ret; for (;;) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch (trapnr) { case EXCP_SYSCALL: diff --git a/linux-user/ppc/cpu_loop.c b/linux-user/ppc/cpu_loop.c index 02204ad8beb..53a6ad996f3 100644 --- a/linux-user/ppc/cpu_loop.c +++ b/linux-user/ppc/cpu_loop.c @@ -74,10 +74,7 @@ void cpu_loop(CPUPPCState *env) for(;;) { bool arch_interrupt; - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); arch_interrupt = true; switch (trapnr) { diff --git a/linux-user/riscv/cpu_loop.c b/linux-user/riscv/cpu_loop.c index 52c49c2e426..e9013b312d2 100644 --- a/linux-user/riscv/cpu_loop.c +++ b/linux-user/riscv/cpu_loop.c @@ -33,10 +33,7 @@ void cpu_loop(CPURISCVState *env) target_ulong ret; for (;;) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch (trapnr) { case EXCP_INTERRUPT: diff --git a/linux-user/s390x/cpu_loop.c b/linux-user/s390x/cpu_loop.c index 8b7ac2879ef..d8231403b65 100644 --- a/linux-user/s390x/cpu_loop.c +++ b/linux-user/s390x/cpu_loop.c @@ -61,10 +61,7 @@ void cpu_loop(CPUS390XState *env) abi_long ret; while (1) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch (trapnr) { case EXCP_INTERRUPT: diff --git a/linux-user/sh4/cpu_loop.c b/linux-user/sh4/cpu_loop.c index c805f9db110..282d955ee92 100644 --- a/linux-user/sh4/cpu_loop.c +++ b/linux-user/sh4/cpu_loop.c @@ -31,10 +31,7 @@ void cpu_loop(CPUSH4State *env) while (1) { bool arch_interrupt = true; - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch (trapnr) { case 0x160: diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c index 50424a54df5..8923a44d607 100644 --- a/linux-user/sparc/cpu_loop.c +++ b/linux-user/sparc/cpu_loop.c @@ -217,10 +217,7 @@ void cpu_loop (CPUSPARCState *env) abi_long ret; while (1) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); switch (trapnr) { case TARGET_TT_SYSCALL: diff --git a/linux-user/xtensa/cpu_loop.c b/linux-user/xtensa/cpu_loop.c index d51ce053926..7eb21415213 100644 --- a/linux-user/xtensa/cpu_loop.c +++ b/linux-user/xtensa/cpu_loop.c @@ -130,10 +130,7 @@ void cpu_loop(CPUXtensaState *env) int trapnr; while (1) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); + trapnr = cpu_exec_user(cs); env->sregs[PS] &= ~PS_EXCM; switch (trapnr) { From patchwork Mon Sep 23 16:13:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809834 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 2CE86CF9C6F for ; Mon, 23 Sep 2024 16:26:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpj-0006oC-3J; Mon, 23 Sep 2024 12:22:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpY-0006VF-1h for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:32 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpR-0000ba-G4 for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:30 -0400 Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48NDhnYQ009089; Mon, 23 Sep 2024 16:22:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=RMwQvc4/LXhI6 5BCHJMjiLWPkPYoTdB1dL47Q9tqml8=; b=NeDsAxIX5oeTb0G225S3Wtlxk7d+k xcmo/f+CxeuzB6HzbBSHHmHtlQNE/GU8RGtaK67KOdmwgVSIA62Uh0erZci78FsF cNlotAgbeFTYiISMa+GF/DysFX01EIL2YwUzPbPhkqiauiFB4PfoQblrdc/A99UL aO1v3+I57tpyR7DOHm5x9GRYJKe+gu1RLYugrARrcZf+0S87YWn1vEtz6tITBdbI pDPUdorAKulk2ANJRvKIqqHvf/9uZsQYOHxnquPlZ+2eu02tmLu7oFWDVI4juIlx eSUKHKMya5MKlwRUDqBxY56F5a1XEoJliuYuK9SW0M3Mdtcqid2mStzmA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41snvaw5jd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:23 +0000 (GMT) Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGMMcC026311; Mon, 23 Sep 2024 16:22:22 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41snvaw5ja-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:22 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NF3r5t014068; Mon, 23 Sep 2024 16:22:21 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 41t9ymqcy2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:21 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMJRw53543316 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:19 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 48CDD20040; Mon, 23 Sep 2024 16:22:19 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF02B2004B; Mon, 23 Sep 2024 16:22:18 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:18 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 06/18] qemu-thread: Introduce QEMU_MUTEX_INITIALIZER Date: Mon, 23 Sep 2024 18:13:01 +0200 Message-ID: <20240923162208.90745-7-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 1zuf4sd21qumwjUFOTb7badkxLThgt1w X-Proofpoint-GUID: yFCIomjKOWPk45JGLYdKB9y98Wbve8p6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 phishscore=0 clxscore=1015 spamscore=0 mlxscore=0 adultscore=0 impostorscore=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230121 Received-SPF: pass client-ip=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 Allow static initialization of mutexes. Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson --- include/qemu/thread-posix.h | 6 ++++++ include/qemu/thread-win32.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h index 5f2f3d1386b..fc0846bfa7c 100644 --- a/include/qemu/thread-posix.h +++ b/include/qemu/thread-posix.h @@ -13,6 +13,12 @@ struct QemuMutex { bool initialized; }; +#ifdef CONFIG_DEBUG_MUTEX +#define QEMU_MUTEX_INITIALIZER {PTHREAD_MUTEX_INITIALIZER, NULL, 0, true} +#else +#define QEMU_MUTEX_INITIALIZER {PTHREAD_MUTEX_INITIALIZER, true} +#endif + /* * QemuRecMutex cannot be a typedef of QemuMutex lest we have two * compatible cases in _Generic. See qemu/lockable.h. diff --git a/include/qemu/thread-win32.h b/include/qemu/thread-win32.h index d95af4498fc..ed1f2d0e733 100644 --- a/include/qemu/thread-win32.h +++ b/include/qemu/thread-win32.h @@ -12,6 +12,12 @@ struct QemuMutex { bool initialized; }; +#ifdef CONFIG_DEBUG_MUTEX +#define QEMU_MUTEX_INITIALIZER {SRWLOCK_INIT, NULL, 0, true} +#else +#define QEMU_MUTEX_INITIALIZER {SRWLOCK_INIT, true} +#endif + typedef struct QemuRecMutex QemuRecMutex; struct QemuRecMutex { CRITICAL_SECTION lock; From patchwork Mon Sep 23 16:13:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809833 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id BBEACCF9C6F for ; Mon, 23 Sep 2024 16:26:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpw-0007iR-It; Mon, 23 Sep 2024 12:22:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpb-0006Xh-TI for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:36 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpW-0000bh-0W for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:34 -0400 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48N76wSQ004443; Mon, 23 Sep 2024 16:22:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=N6zxJfcJaZ7LO kUC5FQaH52UCRfeJM/HvoMM9xuuUMY=; b=KgXYYJVKTb/cCYuAIxczc0S+s9v9z fmph7KqKwt2yQldC2DmD2M/wRivacBjzFbWsCGFBzwccSZG0UmsEpDoTTPKKFK5u BngBsI3vf+wjBZqaE9AgN88N4nrZ7mobRa5BLNyW4kDKx1Yl7spSevk8JLZkA6st XuIU638tpa68p81sLEUns6n4bowXZdtsMBaqBzDaOHIl6HPPvLlzDKrjW77977Jf eOTG8ZlxCj3UkaWK/C12qRYHzP5utHQzCVE1GVfMfP6Sxh+Xw5SE010RLmNsyeZj fPI9/60mwyXh79GW3cnE+sAvkHvNXx+0hurjGd3R7/vez49kIvF5IhE9A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41sntw558t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:22 +0000 (GMT) Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGMMpd032099; Mon, 23 Sep 2024 16:22:22 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41sntw558q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:22 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NFpLq2020843; Mon, 23 Sep 2024 16:22:21 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 41tb62y41f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:21 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMJJk53543318 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:19 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B9DB020040; Mon, 23 Sep 2024 16:22:19 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5AF2C20043; Mon, 23 Sep 2024 16:22:19 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:19 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 07/18] qemu-thread: Introduce QEMU_COND_INITIALIZER Date: Mon, 23 Sep 2024 18:13:02 +0200 Message-ID: <20240923162208.90745-8-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: oM7bmpjmiJw8kCYNan474ip3CVrBZWF0 X-Proofpoint-GUID: giDOyaNMFJQz6DB1_lHuOSZR0nUdeqcE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 adultscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230121 Received-SPF: pass client-ip=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 Allow static initialization of condition variables. Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson --- include/qemu/thread-posix.h | 2 ++ include/qemu/thread-win32.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h index fc0846bfa7c..ed08181a9c6 100644 --- a/include/qemu/thread-posix.h +++ b/include/qemu/thread-posix.h @@ -32,6 +32,8 @@ struct QemuCond { bool initialized; }; +#define QEMU_COND_INITIALIZER {PTHREAD_COND_INITIALIZER, true} + struct QemuSemaphore { QemuMutex mutex; QemuCond cond; diff --git a/include/qemu/thread-win32.h b/include/qemu/thread-win32.h index ed1f2d0e733..e1b014fcac4 100644 --- a/include/qemu/thread-win32.h +++ b/include/qemu/thread-win32.h @@ -29,6 +29,8 @@ struct QemuCond { bool initialized; }; +#define QEMU_COND_INITIALIZER {CONDITION_VARIABLE_INIT, true} + struct QemuSemaphore { HANDLE sema; bool initialized; From patchwork Mon Sep 23 16:13:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809820 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 13606CF9C6F for ; Mon, 23 Sep 2024 16:23:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpY-0006WW-Sa; Mon, 23 Sep 2024 12:22:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpW-0006TG-AG for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:31 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpQ-0000bX-PZ for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:27 -0400 Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48N7VKu9003950; Mon, 23 Sep 2024 16:22:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=6LuTJ7XZ1WjC3 WAFGOgII7433AsF/nIYoE/QHLxR5CA=; b=RM5yjuhLR6xGFNTLFs3R3Lsdtmd19 +dqkrNPXh6AmirA5XxnQOC5yEZWY56MDSSKXKn2pPdkPbsC2BWH9m9ypyLjxc4kU 3t8Z7Dd1z29p1yAXSww9EpOR+6ileOUlSsbpeqyPqt8VdPicQ3dIexDR3crFJL+a Ib1exRNvOVHiJSwF2rEA4VvhBzouGd9AcFnNvk1pZk0EJFlK7ZUIlX7u5y4dwg5T EFI+ylz+mU3te3b6cVIRjTqboBzuV+80AWtOr2jXUMeXCefTkskvMlFbaad2OF/L totnZJ/TFLQVrM+EmXXeQGdrFDgjOZavvGtPO3QG1a1Yf5aBuhtFG+BtA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41smjjmwd7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:23 +0000 (GMT) Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGMMNU026002; Mon, 23 Sep 2024 16:22:22 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41smjjmwd2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:22 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NETGbi012495; Mon, 23 Sep 2024 16:22:22 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 41t9fpqg0b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:22 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMKwU57999636 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:20 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2D3C920040; Mon, 23 Sep 2024 16:22:20 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CCBB620043; Mon, 23 Sep 2024 16:22:19 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:19 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 08/18] replay: Add replay_mutex_{lock, unlock}() stubs for qemu-user Date: Mon, 23 Sep 2024 18:13:03 +0200 Message-ID: <20240923162208.90745-9-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: IriPYQqzJOf8kLjEmQtldDwECNzckHyv X-Proofpoint-GUID: RxSmclyiGrhgn6MPaMHX7t1awLZ3bY5w X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 adultscore=0 malwarescore=0 suspectscore=0 bulkscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 phishscore=0 clxscore=1015 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230121 Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 Sharing pause_all_vcpus() with qemu-user requires providing no-op definitions of replay mutex functions. Make these functions available via replay-core.h and move the existing stubs to a separate file. Signed-off-by: Ilya Leoshkevich --- include/exec/replay-core.h | 13 +++++++++++++ include/sysemu/replay.h | 13 ------------- replay/stubs-system.c | 8 ++++++++ stubs/meson.build | 4 ++++ stubs/replay-mutex.c | 10 ++++++++++ stubs/replay-tools.c | 8 -------- 6 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 stubs/replay-mutex.c diff --git a/include/exec/replay-core.h b/include/exec/replay-core.h index 244c77acce5..74766bae90d 100644 --- a/include/exec/replay-core.h +++ b/include/exec/replay-core.h @@ -77,4 +77,17 @@ void replay_save_random(int ret, void *buf, size_t len); /* Loads the saved values for the random number generator */ int replay_read_random(void *buf, size_t len); +/* Replay locking + * + * The locks are needed to protect the shared structures and log file + * when doing record/replay. They also are the main sync-point between + * the main-loop thread and the vCPU thread. This was a role + * previously filled by the BQL which has been busy trying to reduce + * its impact across the code. This ensures blocks of events stay + * sequential and reproducible. + */ + +void replay_mutex_lock(void); +void replay_mutex_unlock(void); + #endif diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 8102fa54f01..d6e0342b27c 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -51,19 +51,6 @@ typedef struct ReplayNetState ReplayNetState; /* Name of the initial VM snapshot */ extern char *replay_snapshot; -/* Replay locking - * - * The locks are needed to protect the shared structures and log file - * when doing record/replay. They also are the main sync-point between - * the main-loop thread and the vCPU thread. This was a role - * previously filled by the BQL which has been busy trying to reduce - * its impact across the code. This ensures blocks of events stay - * sequential and reproducible. - */ - -void replay_mutex_lock(void); -void replay_mutex_unlock(void); - /* Processing the instructions */ /*! Returns number of executed instructions. */ diff --git a/replay/stubs-system.c b/replay/stubs-system.c index 50cefdb2d69..45984e3b098 100644 --- a/replay/stubs-system.c +++ b/replay/stubs-system.c @@ -94,3 +94,11 @@ void qmp_replay_seek(int64_t icount, Error **errp) error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, "replay support not available"); } + +void replay_mutex_lock(void) +{ +} + +void replay_mutex_unlock(void) +{ +} diff --git a/stubs/meson.build b/stubs/meson.build index 772a3e817df..ab4b98a0e18 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -46,6 +46,10 @@ if have_block or have_ga stub_ss.add(files('qmp-quit.c')) endif +if have_block or have_ga or have_user + stub_ss.add(files('replay-mutex.c')) +endif + if have_block or have_user stub_ss.add(files('qtest.c')) stub_ss.add(files('vm-stop.c')) diff --git a/stubs/replay-mutex.c b/stubs/replay-mutex.c new file mode 100644 index 00000000000..08c69139bcb --- /dev/null +++ b/stubs/replay-mutex.c @@ -0,0 +1,10 @@ +#include "qemu/osdep.h" +#include "exec/replay-core.h" + +void replay_mutex_lock(void) +{ +} + +void replay_mutex_unlock(void) +{ +} diff --git a/stubs/replay-tools.c b/stubs/replay-tools.c index 3e8ca3212d9..2bca8ab6657 100644 --- a/stubs/replay-tools.c +++ b/stubs/replay-tools.c @@ -41,14 +41,6 @@ bool replay_checkpoint(ReplayCheckpoint checkpoint) return true; } -void replay_mutex_lock(void) -{ -} - -void replay_mutex_unlock(void) -{ -} - void replay_register_char_driver(struct Chardev *chr) { } From patchwork Mon Sep 23 16:13:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809825 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 43564CF9C6F for ; Mon, 23 Sep 2024 16:24:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpz-0007vY-Rr; Mon, 23 Sep 2024 12:22:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpY-0006VA-1E for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:32 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpR-0000bd-EF for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:31 -0400 Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48N3wj6h003277; Mon, 23 Sep 2024 16:22:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=nNWVkv5mLwwcN NcNmuX3ooqqW+WAxupmxKS6va9bJB4=; b=MRoa7A4IUtG78DK7Mj/gcs5RvkIz9 ayc24nJL5RZqdp/R3Spn4F97dfEKcHHr7Yf05kfhTQwIQVqrMcXAkkLASA55Actx Wjwgju1lOAktT4J98d8echoaMt2rw1GOR2zv9/bZKEfzmT9na9KvVHBnTdn8iDpW Wp2IdC+aOg2CixKWRLZVP1gP8NfPbPT8AfAcHB9/6lqC0pPUceQwSLrktKp62ceC f8gH/7okd/rSWQo+qdkAcmvVh0wX3MKo2NIyQoLQHJir+BV0+CaiUxhiEfORXkSs 8X92cj8EQgCfCMbqTstp8cd1bkWPzUCy1HrRfkVz+78txb4AWvNT5sdgw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41smjjmwd9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:23 +0000 (GMT) Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGMNOb026030; Mon, 23 Sep 2024 16:22:23 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41smjjmwd4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:23 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NE2YCB008688; Mon, 23 Sep 2024 16:22:22 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 41t8v0ym0j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:22 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMK5i57999638 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:20 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9D49C20040; Mon, 23 Sep 2024 16:22:20 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3FAC02004B; Mon, 23 Sep 2024 16:22:20 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:20 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 09/18] qemu-timer: Provide qemu_clock_enable() stub for qemu-user Date: Mon, 23 Sep 2024 18:13:04 +0200 Message-ID: <20240923162208.90745-10-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 2mLLUPLqT0H6K1cmR3lDgLbE3ha58Cvh X-Proofpoint-GUID: bQGPXrUsNl-6tVsClkm71FPCVDUgHpxd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 adultscore=0 malwarescore=0 suspectscore=0 bulkscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 phishscore=0 clxscore=1015 mlxlogscore=627 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230121 Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 Sharing pause_all_vcpus() with qemu-user requires a no-op implementation of qemu_clock_enable(). Signed-off-by: Ilya Leoshkevich --- stubs/meson.build | 4 ++++ stubs/qemu-timer.c | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 stubs/qemu-timer.c diff --git a/stubs/meson.build b/stubs/meson.build index ab4b98a0e18..9e78a0b9745 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -46,6 +46,10 @@ if have_block or have_ga stub_ss.add(files('qmp-quit.c')) endif +if have_user + stub_ss.add(files('qemu-timer.c')) +endif + if have_block or have_ga or have_user stub_ss.add(files('replay-mutex.c')) endif diff --git a/stubs/qemu-timer.c b/stubs/qemu-timer.c new file mode 100644 index 00000000000..27b67f7b313 --- /dev/null +++ b/stubs/qemu-timer.c @@ -0,0 +1,6 @@ +#include "qemu/osdep.h" +#include "qemu/timer.h" + +void qemu_clock_enable(QEMUClockType type, bool enabled) +{ +} From patchwork Mon Sep 23 16:13:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809841 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 18738CF9C72 for ; Mon, 23 Sep 2024 16:30:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpu-0007OY-F1; Mon, 23 Sep 2024 12:22:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpZ-0006XT-O1 for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:36 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpT-0000bf-SH for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:32 -0400 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48NBUNKT004290; Mon, 23 Sep 2024 16:22:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=ne7ty8+8by6hh 4QQH+LzVTzQiJNeSI1v+LbvHsFyDGw=; b=bS7hUTlgdk39Zqw6XYRjrAA5/nz01 AYa3A1G7s11MwXSUhTOcCAz97GTx1Q32QeTRzXKB0h8ah5A6hgaXOY86iF9n78kb s0MQRGGl9pNy1uX6zV5zWIc2gqQPXqgNlNeGTFB6VMRJk2zwuFHW50SPCdw4GvUt EODZ4FkZrwQ82su7Qe+HEQORc3KxaDMAiPBUFlDMTgM/vq7uei05inWYd680tXP8 XDYJy6RGwGKqxYmz6XTfIaI3617M0Ws6mklq48R86hyee/frB5fFThZ+olxUqWBx 2xSZw85fdFM7d9oRVN6vn06RRLfclb0z46HyoeHpqLZE46rs/pMG03yAg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41skjrd0em-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:24 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGMN0M024482; Mon, 23 Sep 2024 16:22:23 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41skjrd0ej-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:23 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NFxshT020824; Mon, 23 Sep 2024 16:22:22 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 41tb62y41j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:22 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMLK221496144 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:21 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 131D020040; Mon, 23 Sep 2024 16:22:21 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B02AF20043; Mon, 23 Sep 2024 16:22:20 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:20 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 10/18] cpu: Use BQL in qemu-user Date: Mon, 23 Sep 2024 18:13:05 +0200 Message-ID: <20240923162208.90745-11-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: z4y0NKpUX9agzDfXjMm4q2HEVZLcz8TK X-Proofpoint-ORIG-GUID: lkP0S_xSyUNRdZww_YsNBeJEOZO9QuBl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 priorityscore=1501 spamscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 clxscore=1015 malwarescore=0 mlxlogscore=908 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230117 Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 Currently BQL is stubbed out in qemu-user. However, enabling the ability to pause and resume CPUs requires BQL, so introduce it. Signed-off-by: Ilya Leoshkevich --- accel/tcg/user-exec.c | 2 ++ bsd-user/freebsd/os-syscall.c | 6 ++++ bsd-user/main.c | 2 ++ cpu-common.c | 45 ++++++++++++++++++++++++++++++ gdbstub/user.c | 5 ++++ linux-user/main.c | 3 ++ linux-user/syscall.c | 6 ++++ system/cpus.c | 52 ++--------------------------------- 8 files changed, 72 insertions(+), 49 deletions(-) diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index ca3e8e988ee..d56882c87f3 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -1293,9 +1293,11 @@ int cpu_exec_user(CPUState *cs) { int trapnr; + bql_unlock(); cpu_exec_start(cs); trapnr = cpu_exec(cs); cpu_exec_end(cs); + bql_lock(); process_queued_cpu_work(cs); return trapnr; diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index ca2f6fdb66e..c2849d43223 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -32,6 +32,7 @@ #include "qemu.h" #include "signal-common.h" #include "user/syscall-trace.h" +#include "qemu/main-loop.h" /* BSD independent syscall shims */ #include "bsd-file.h" @@ -935,16 +936,21 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, { abi_long ret; + bql_unlock(); + if (do_strace) { print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); } ret = freebsd_syscall(cpu_env, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + if (do_strace) { print_freebsd_syscall_ret(num, ret); } + bql_lock(); + return ret; } diff --git a/bsd-user/main.c b/bsd-user/main.c index cc980e6f401..ba5b54c228d 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -48,6 +48,7 @@ #include "qemu/guest-random.h" #include "gdbstub/user.h" #include "exec/page-vary.h" +#include "qemu/main-loop.h" #include "host-os.h" #include "target_arch_cpu.h" @@ -616,6 +617,7 @@ int main(int argc, char **argv) target_cpu_init(env, regs); + bql_lock(); if (gdbstub) { gdbserver_start(gdbstub); gdb_handlesig(cpu, 0, NULL, NULL, 0); diff --git a/cpu-common.c b/cpu-common.c index 6b262233a3b..cb7c10a3915 100644 --- a/cpu-common.c +++ b/cpu-common.c @@ -452,3 +452,48 @@ void cpu_breakpoint_remove_all(CPUState *cpu, int mask) } } } + +/* The Big QEMU Lock (BQL) */ +static QemuMutex bql = QEMU_MUTEX_INITIALIZER; + +QEMU_DEFINE_STATIC_CO_TLS(bool, bql_locked) + +bool bql_locked(void) +{ + return get_bql_locked(); +} + +/* + * The BQL is taken from so many places that it is worth profiling the + * callers directly, instead of funneling them all through a single function. + */ +void bql_lock_impl(const char *file, int line) +{ + QemuMutexLockFunc bql_lock_fn = qatomic_read(&bql_mutex_lock_func); + + g_assert(!bql_locked()); + bql_lock_fn(&bql, file, line); + set_bql_locked(true); +} + +void bql_unlock(void) +{ + g_assert(bql_locked()); + set_bql_locked(false); + qemu_mutex_unlock(&bql); +} + +void qemu_cond_wait_bql(QemuCond *cond) +{ + qemu_cond_wait(cond, &bql); +} + +void qemu_cond_timedwait_bql(QemuCond *cond, int ms) +{ + qemu_cond_timedwait(cond, &bql, ms); +} + +void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) +{ + do_run_on_cpu(cpu, func, data, &bql); +} diff --git a/gdbstub/user.c b/gdbstub/user.c index 77ba227fc3b..82007b09db6 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -12,6 +12,7 @@ #include "qemu/osdep.h" #include "qemu/bitops.h" #include "qemu/cutils.h" +#include "qemu/main-loop.h" #include "qemu/sockets.h" #include "exec/hwaddr.h" #include "exec/tb-flush.h" @@ -169,6 +170,8 @@ void gdb_exit(int code) { char buf[4]; + BQL_LOCK_GUARD(); + if (!gdbserver_state.init) { return; } @@ -464,6 +467,8 @@ void gdbserver_fork_end(CPUState *cpu, pid_t pid) char b; int fd; + BQL_LOCK_GUARD(); + if (!gdbserver_state.init || gdbserver_user_state.fd < 0) { return; } diff --git a/linux-user/main.c b/linux-user/main.c index 8143a0d4b02..016f60bf3dc 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -57,6 +57,7 @@ #include "user-mmap.h" #include "tcg/perf.h" #include "exec/page-vary.h" +#include "qemu/main-loop.h" #ifdef CONFIG_SEMIHOSTING #include "semihosting/semihost.h" @@ -1011,6 +1012,8 @@ int main(int argc, char **argv, char **envp) target_cpu_copy_regs(env, regs); + bql_lock(); + if (gdbstub) { if (gdbserver_start(gdbstub) < 0) { fprintf(stderr, "qemu: could not open gdbserver on %s\n", diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b693aeff5bb..ff34ae11340 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -144,6 +144,7 @@ #include "qapi/error.h" #include "fd-trans.h" #include "cpu_loop-common.h" +#include "qemu/main-loop.h" #ifndef CLONE_IO #define CLONE_IO 0x80000000 /* Clone io context */ @@ -6529,6 +6530,7 @@ static void *clone_func(void *arg) /* Wait until the parent has finished initializing the tls state. */ pthread_mutex_lock(&clone_lock); pthread_mutex_unlock(&clone_lock); + bql_lock(); cpu_loop(env); /* never exits */ return NULL; @@ -13772,6 +13774,8 @@ abi_long do_syscall(CPUArchState *cpu_env, int num, abi_long arg1, record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + bql_unlock(); + if (unlikely(qemu_loglevel_mask(LOG_STRACE))) { print_syscall(cpu_env, num, arg1, arg2, arg3, arg4, arg5, arg6); } @@ -13784,6 +13788,8 @@ abi_long do_syscall(CPUArchState *cpu_env, int num, abi_long arg1, arg3, arg4, arg5, arg6); } + bql_lock(); + record_syscall_return(cpu, num, ret); return ret; } diff --git a/system/cpus.c b/system/cpus.c index 1c818ff6828..fe84b822798 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -65,9 +65,6 @@ #endif /* CONFIG_LINUX */ -/* The Big QEMU Lock (BQL) */ -static QemuMutex bql; - /* * The chosen accelerator is supposed to register this. */ @@ -420,16 +417,10 @@ void qemu_init_cpu_loop(void) qemu_init_sigbus(); qemu_cond_init(&qemu_cpu_cond); qemu_cond_init(&qemu_pause_cond); - qemu_mutex_init(&bql); qemu_thread_get_self(&io_thread); } -void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) -{ - do_run_on_cpu(cpu, func, data, &bql); -} - static void qemu_cpu_stop(CPUState *cpu, bool exit) { g_assert(qemu_cpu_is_self(cpu)); @@ -459,7 +450,7 @@ void qemu_wait_io_event(CPUState *cpu) slept = true; qemu_plugin_vcpu_idle_cb(cpu); } - qemu_cond_wait(cpu->halt_cond, &bql); + qemu_cond_wait_bql(cpu->halt_cond); } if (slept) { qemu_plugin_vcpu_resume_cb(cpu); @@ -512,48 +503,11 @@ bool qemu_in_vcpu_thread(void) return current_cpu && qemu_cpu_is_self(current_cpu); } -QEMU_DEFINE_STATIC_CO_TLS(bool, bql_locked) - -bool bql_locked(void) -{ - return get_bql_locked(); -} - bool qemu_in_main_thread(void) { return bql_locked(); } -/* - * The BQL is taken from so many places that it is worth profiling the - * callers directly, instead of funneling them all through a single function. - */ -void bql_lock_impl(const char *file, int line) -{ - QemuMutexLockFunc bql_lock_fn = qatomic_read(&bql_mutex_lock_func); - - g_assert(!bql_locked()); - bql_lock_fn(&bql, file, line); - set_bql_locked(true); -} - -void bql_unlock(void) -{ - g_assert(bql_locked()); - set_bql_locked(false); - qemu_mutex_unlock(&bql); -} - -void qemu_cond_wait_bql(QemuCond *cond) -{ - qemu_cond_wait(cond, &bql); -} - -void qemu_cond_timedwait_bql(QemuCond *cond, int ms) -{ - qemu_cond_timedwait(cond, &bql, ms); -} - /* signal CPU creation */ void cpu_thread_signal_created(CPUState *cpu) { @@ -613,7 +567,7 @@ void pause_all_vcpus(void) replay_mutex_unlock(); while (!all_vcpus_paused()) { - qemu_cond_wait(&qemu_pause_cond, &bql); + qemu_cond_wait_bql(&qemu_pause_cond); CPU_FOREACH(cpu) { qemu_cpu_kick(cpu); } @@ -684,7 +638,7 @@ void qemu_init_vcpu(CPUState *cpu) cpus_accel->create_vcpu_thread(cpu); while (!cpu->created) { - qemu_cond_wait(&qemu_cpu_cond, &bql); + qemu_cond_wait_bql(&qemu_cpu_cond); } } From patchwork Mon Sep 23 16:13:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809837 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 60FEBCF9C6F for ; Mon, 23 Sep 2024 16:28:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslq2-0007xx-1Y; Mon, 23 Sep 2024 12:23:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpb-0006Xg-Sy for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:36 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpV-0000c3-VM for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:35 -0400 Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48N8jNKx008714; Mon, 23 Sep 2024 16:22:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=tnLB7U4elm2AT jCyYDfTzyHKOBxzoRlyTNltYqbQWTY=; b=h0irbCAUVzQUsY7OyZm1h1XcKZJoI Jg5kOxaiTqAxXgKLdERQYd8VNb8ugT5hU2hrMYdCCGsW6RBb7mxeLAwUiGWlUFDU C+LG0GLEHhrT1FVKV2rQS9ImKwWI/mtwLnNF7Ts00oatsA+/Qcp6ltqq/rinQCRu sbM9lXCbAdxbovtx9TmWou9yblRQbmpxCVovyVv2Pph5OTUJOqHrkU/3AMMs1ru9 ++sEgDDt0PsZFYzoNApbv0nDCs7fXtF70x1hay7D20MVfqUlLk8MvgSHSBOURth0 tC8GqRlVKvS4gqHx3MU54HFQkTi0SIfwFjT85tIp2ToSZhdqbSQlkkDLw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41snvaw5jh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:24 +0000 (GMT) Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGMOeB026349; Mon, 23 Sep 2024 16:22:24 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41snvaw5je-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:24 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NDl7Gw000643; Mon, 23 Sep 2024 16:22:23 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 41t8fufp6t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:23 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMLPv21496146 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:21 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7A21520040; Mon, 23 Sep 2024 16:22:21 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 251FE2004B; Mon, 23 Sep 2024 16:22:21 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:21 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 11/18] accel/tcg: Unify user implementations of qemu_cpu_kick() Date: Mon, 23 Sep 2024 18:13:06 +0200 Message-ID: <20240923162208.90745-12-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: XXcVGCwq3l7KXshgY_oNVQdEjKoL6Z4I X-Proofpoint-GUID: FTUeao5GLDZ0uApgh90MW7w548esJLnl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 phishscore=0 clxscore=1015 spamscore=0 mlxscore=0 adultscore=0 impostorscore=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxlogscore=817 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230121 Received-SPF: pass client-ip=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 linux-user and bsd-user have the same implementation. Move it to user-exec.c. Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson --- accel/tcg/user-exec.c | 5 +++++ bsd-user/main.c | 5 ----- linux-user/main.c | 5 ----- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index d56882c87f3..7bd6e94b8e8 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -1302,3 +1302,8 @@ int cpu_exec_user(CPUState *cs) return trapnr; } + +void qemu_cpu_kick(CPUState *cpu) +{ + cpu_exit(cpu); +} diff --git a/bsd-user/main.c b/bsd-user/main.c index ba5b54c228d..b424a21f643 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -208,11 +208,6 @@ bool qemu_cpu_is_self(CPUState *cpu) return thread_cpu == cpu; } -void qemu_cpu_kick(CPUState *cpu) -{ - cpu_exit(cpu); -} - /* Assumes contents are already zeroed. */ static void init_task_state(TaskState *ts) { diff --git a/linux-user/main.c b/linux-user/main.c index 016f60bf3dc..60091cf3053 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -186,11 +186,6 @@ bool qemu_cpu_is_self(CPUState *cpu) return thread_cpu == cpu; } -void qemu_cpu_kick(CPUState *cpu) -{ - cpu_exit(cpu); -} - void task_settid(TaskState *ts) { if (ts->ts_tid == 0) { From patchwork Mon Sep 23 16:13:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809836 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 88A9BCF9C72 for ; Mon, 23 Sep 2024 16:27:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpj-0006pb-Hg; Mon, 23 Sep 2024 12:22:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpZ-0006XR-Mn for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:35 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpV-0000bw-OO for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:32 -0400 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48NDZhUv021374; Mon, 23 Sep 2024 16:22:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=G6WSdkmP42unl 7WPudmenQYEVSbWuO/h9ns2kNpxwXY=; b=ryLjvYlbKvjRZZHwrYQLN5RhyLDsD CljMHZ8Ks/EblcjefQSphXTDAnY2XW777Ue6/CrRiMf3SLNhPBFddauv33niE9AG b7ef5lj+rB/mlPmWE0xRvc9oQHW6pKwhGRj/Q+V78NAcENYWOLDF9/I8fDL/Kstl 6nIZlk48snTnE/3LWlBzfLXHNbA7fELZYOmlig26F1jZGnWoEdeUfU/9/6hw3F/z FpOSx5r4pk6fWWfkWQcSMyfiA/CrKQZBJx4bZjzuF3jE23OlhrZ1mZPkM4LJUT68 MgzC7u5rsUYnZJhQz3JwQWdYsnrhM4F7ux4AxZJieeFFlTn4cy2N7HLfA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41skjrd0er-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:24 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGIBVM014485; Mon, 23 Sep 2024 16:22:24 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41skjrd0en-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:24 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NFWlh2005810; Mon, 23 Sep 2024 16:22:23 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 41tapm77yt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:23 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMLfI21496148 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:22 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E167820040; Mon, 23 Sep 2024 16:22:21 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8CC0720043; Mon, 23 Sep 2024 16:22:21 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:21 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 12/18] cpu: Track CPUs executing syscalls Date: Mon, 23 Sep 2024 18:13:07 +0200 Message-ID: <20240923162208.90745-13-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: DX4hwG0DnGeVJpmGJiT_6smOjOohWR3k X-Proofpoint-ORIG-GUID: mRQOyG-HRFMncZnToMMkpkHygc50Bphy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 priorityscore=1501 spamscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 clxscore=1015 malwarescore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230117 Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 CPUs that execute syscalls should be considered paused by all_vcpus_paused(). Lay the groundwork by introducing a bool field in CPUState to track this. The field is not used by sysemu, but it's only one byte, so it should not be a problem. Signed-off-by: Ilya Leoshkevich --- accel/tcg/user-exec.c | 10 ++++++++++ bsd-user/freebsd/os-syscall.c | 4 ++++ include/exec/cpu-common.h | 2 ++ include/hw/core/cpu.h | 1 + linux-user/syscall.c | 5 +++++ 5 files changed, 22 insertions(+) diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 7bd6e94b8e8..3ebace1e833 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -1307,3 +1307,13 @@ void qemu_cpu_kick(CPUState *cpu) { cpu_exit(cpu); } + +void cpu_enter_syscall(CPUState *cs) +{ + cs->in_syscall = true; +} + +void cpu_exit_syscall(CPUState *cs) +{ + cs->in_syscall = false; +} diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index c2849d43223..9f54345e11b 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -936,6 +936,8 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, { abi_long ret; + cpu_enter_syscall(env_cpu(cpu_env)); + bql_unlock(); if (do_strace) { @@ -951,6 +953,8 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, bql_lock(); + cpu_exit_syscall(env_cpu(cpu_env)); + return ret; } diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 4a7b43f9aa3..32bd3cad83f 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -228,6 +228,8 @@ G_NORETURN void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc); int cpu_exec(CPUState *cpu); /* accel/tcg/user-exec.c */ int cpu_exec_user(CPUState *cs); +void cpu_enter_syscall(CPUState *cs); +void cpu_exit_syscall(CPUState *cs); /** * env_archcpu(env) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 1c9c775df65..d073a79731b 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -475,6 +475,7 @@ struct CPUState { bool created; bool stop; bool stopped; + bool in_syscall; /* Should CPU start in powered-off state? */ bool start_powered_off; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index ff34ae11340..344c2e65234 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -13771,6 +13771,8 @@ abi_long do_syscall(CPUArchState *cpu_env, int num, abi_long arg1, } #endif + cpu_enter_syscall(cpu); + record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); @@ -13791,5 +13793,8 @@ abi_long do_syscall(CPUArchState *cpu_env, int num, abi_long arg1, bql_lock(); record_syscall_return(cpu, num, ret); + + cpu_exit_syscall(cpu); + return ret; } From patchwork Mon Sep 23 16:13:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809842 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 84ACECF9C72 for ; Mon, 23 Sep 2024 16:30:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpu-0007S3-Fr; Mon, 23 Sep 2024 12:22:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpb-0006Xj-U9 for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:36 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpX-0000cn-P6 for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:34 -0400 Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48N8nkus021322; Mon, 23 Sep 2024 16:22:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=a19Q13gsnFLHt WGFByfdJRJnGzYniaISkm/mDVLQxWU=; b=VqmGNyx/BeDw/DyGWEZVFY6pU9puP 4xczTWB8ap6V4OfYAyAwvIZDtm7tuZN+87m73BBbf0ZB+MeuVHb5O49q5n5hgWXr hyJyTMElCOHStvfRC0Mi3lOyajwQ2mNqTbAdWGe3KGsXMOTIubVPxyg3LZRO5hel Z6M0ZKoEzmaLbl2zYnndzTraHoEVmjCsyJyWMRnYzr/MBH2FR+GFxlNZVFYIm04u 6Jp4upVFlhCGuBPDkEiGpJG0xmk/X2k/XN/2ZiVtoovK2X2mTTxJ1qFGfrtDR9fr nKFZkFNyvJtX6q6hw5ZBoea6VQgDxkZcFza48F/0A8AlZ6ptDSgy1z0Zg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41snvaw5ju-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:28 +0000 (GMT) Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGKSuw022836; Mon, 23 Sep 2024 16:22:27 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41snvaw5jk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:27 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NE0r4t008712; Mon, 23 Sep 2024 16:22:24 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 41t8v0ym0k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:24 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMMoQ49545572 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:22 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5488220040; Mon, 23 Sep 2024 16:22:22 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F406D20043; Mon, 23 Sep 2024 16:22:21 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:21 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 13/18] cpu: Implement cpu_thread_is_idle() for qemu-user Date: Mon, 23 Sep 2024 18:13:08 +0200 Message-ID: <20240923162208.90745-14-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: H1unpGehqrO8G9EApNiV1mjYh5yafUKj X-Proofpoint-GUID: YrAN4IlKWBOSBVA4SXcT3j0wTiQKe2fD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 phishscore=0 clxscore=1015 spamscore=0 mlxscore=0 adultscore=0 impostorscore=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxlogscore=926 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230121 Received-SPF: pass client-ip=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 Stopped CPUs are parked until cpu_thread_is_idle() is true, so implement it for qemu-user. Share a part of the qemu-system's implementation. Signed-off-by: Ilya Leoshkevich --- accel/tcg/user-exec.c | 12 ++++++++++++ cpu-common.c | 19 +++++++++++++++++++ include/exec/cpu-common.h | 3 +++ include/sysemu/cpus.h | 1 - system/cpus.c | 17 ++++------------- 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 3ebace1e833..57a13c81fc4 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -1317,3 +1317,15 @@ void cpu_exit_syscall(CPUState *cs) { cs->in_syscall = false; } + +bool cpu_is_stopped(CPUState *cpu) +{ + return cpu->stopped; +} + +bool cpu_thread_is_idle(CPUState *cpu) +{ + int ret = cpu_thread_is_idle_common(cpu); + + return ret == -1 ? true : ret; +} diff --git a/cpu-common.c b/cpu-common.c index cb7c10a3915..2822ee9373d 100644 --- a/cpu-common.c +++ b/cpu-common.c @@ -497,3 +497,22 @@ void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) { do_run_on_cpu(cpu, func, data, &bql); } + +bool cpu_work_list_empty(CPUState *cpu) +{ + return QSIMPLEQ_EMPTY_ATOMIC(&cpu->work_list); +} + +int cpu_thread_is_idle_common(CPUState *cpu) +{ + if (cpu->stop || !cpu_work_list_empty(cpu)) { + return 0; + } + if (cpu_is_stopped(cpu)) { + return 1; + } + if (!cpu->halted || cpu_has_work(cpu)) { + return 0; + } + return -1; +} diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 32bd3cad83f..d7fc24bc13d 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -231,6 +231,9 @@ int cpu_exec_user(CPUState *cs); void cpu_enter_syscall(CPUState *cs); void cpu_exit_syscall(CPUState *cs); +int cpu_thread_is_idle_common(CPUState *cpu); +bool cpu_thread_is_idle(CPUState *cpu); + /** * env_archcpu(env) * @env: The architecture environment diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h index b4a566cfe75..bfa3fd45650 100644 --- a/include/sysemu/cpus.h +++ b/include/sysemu/cpus.h @@ -21,7 +21,6 @@ void dummy_start_vcpu_thread(CPUState *); void cpus_kick_thread(CPUState *cpu); bool cpu_work_list_empty(CPUState *cpu); -bool cpu_thread_is_idle(CPUState *cpu); bool all_cpu_threads_idle(void); bool cpu_can_run(CPUState *cpu); void qemu_wait_io_event_common(CPUState *cpu); diff --git a/system/cpus.c b/system/cpus.c index fe84b822798..13072be26fa 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -75,21 +75,12 @@ bool cpu_is_stopped(CPUState *cpu) return cpu->stopped || !runstate_is_running(); } -bool cpu_work_list_empty(CPUState *cpu) -{ - return QSIMPLEQ_EMPTY_ATOMIC(&cpu->work_list); -} - bool cpu_thread_is_idle(CPUState *cpu) { - if (cpu->stop || !cpu_work_list_empty(cpu)) { - return false; - } - if (cpu_is_stopped(cpu)) { - return true; - } - if (!cpu->halted || cpu_has_work(cpu)) { - return false; + int ret = cpu_thread_is_idle_common(cpu); + + if (ret != -1) { + return ret; } if (cpus_accel->cpu_thread_is_idle) { return cpus_accel->cpu_thread_is_idle(cpu); From patchwork Mon Sep 23 16:13:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809819 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 160BDCF9C74 for ; Mon, 23 Sep 2024 16:23:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpj-0006qT-Op; Mon, 23 Sep 2024 12:22:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpb-0006Xi-Tq for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:36 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpV-0000cJ-Va for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:34 -0400 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48NDIrm7015231; Mon, 23 Sep 2024 16:22:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=4oMT0GZlyJvgn 2L4HOXrCiFpso5i/Pzu7DPF0kfbHT8=; b=FlAB/q4OVfoIO+8UY+2lG0+bfVSOJ 3IYs7i0HHYWRjHkzyJ1eDLuNk7XK2u26I1e+j13D7gnmsAldRze8I/mQldm65RBu vgOmoVl8WR/mx132TVuLTbFllv33aTueUhO+UOgVyi2alOgnYU2BdDLj8tDwwX+M 5hNriWq2sCiImz3RI88H+sUjzEarn+9N5/dZsZQZi2DkC76NZ9//a9+Cpd1MIdJK Ue+MPG3HbVM5I9Q+D2Nco3uDVsCKE9DRGvPBkuaxiSC+WBoQ/AVbIlJlLWFghg0i wDbyTrtTKz3NqmmQ1N/HRyGAv8FIgQ9TMWFOg1NP0R4r0W+5QYhIN6j5A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41sntw5592-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:26 +0000 (GMT) Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGMP3a032226; Mon, 23 Sep 2024 16:22:25 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41sntw558y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:25 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NG0Fcn020814; Mon, 23 Sep 2024 16:22:24 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 41tb62y41m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:24 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMMNb49545574 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:22 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BB12720040; Mon, 23 Sep 2024 16:22:22 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6727C20043; Mon, 23 Sep 2024 16:22:22 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:22 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 14/18] cpu: Introduce cpu_is_paused() Date: Mon, 23 Sep 2024 18:13:09 +0200 Message-ID: <20240923162208.90745-15-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: l_qiXPHN0cmCGPsIQpWXFEgGa00wfl09 X-Proofpoint-GUID: aJBNhVT0OsHHZNMySpPKPGuvxhTNlzjj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 adultscore=0 mlxlogscore=964 bulkscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230121 Received-SPF: pass client-ip=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 A qemu-system CPU is considered paused as a result of an external request. A qemu-user CPU, in addition to that, should be considered paused when it's executing a syscall. Signed-off-by: Ilya Leoshkevich --- accel/tcg/user-exec.c | 5 +++++ include/exec/cpu-common.h | 1 + system/cpus.c | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 57a13c81fc4..de4753cded7 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -1329,3 +1329,8 @@ bool cpu_thread_is_idle(CPUState *cpu) return ret == -1 ? true : ret; } + +bool cpu_is_paused(CPUState *cpu) +{ + return cpu->stopped || cpu->in_syscall; +} diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index d7fc24bc13d..e8b530ed889 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -233,6 +233,7 @@ void cpu_exit_syscall(CPUState *cs); int cpu_thread_is_idle_common(CPUState *cpu); bool cpu_thread_is_idle(CPUState *cpu); +bool cpu_is_paused(CPUState *cpu); /** * env_archcpu(env) diff --git a/system/cpus.c b/system/cpus.c index 13072be26fa..407140c41f6 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -530,12 +530,17 @@ void cpu_resume(CPUState *cpu) qemu_cpu_kick(cpu); } +bool cpu_is_paused(CPUState *cpu) +{ + return cpu->stopped; +} + static bool all_vcpus_paused(void) { CPUState *cpu; CPU_FOREACH(cpu) { - if (!cpu->stopped) { + if (!cpu_is_paused(cpu)) { return false; } } From patchwork Mon Sep 23 16:13:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809821 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 32A5DCF9C72 for ; Mon, 23 Sep 2024 16:23:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpl-0006qm-8e; Mon, 23 Sep 2024 12:22:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpb-0006Xl-VH for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:36 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpW-0000cL-0p for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:33 -0400 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48NAIFSe027592; Mon, 23 Sep 2024 16:22:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=WN3/U2+USrWvM Y+DeKvu28fORRmLsnH2CzE0ZonIXnk=; b=Ft3KeRToI2r8rzifjPFk5tR/Yi1Mw gTW8dH/zm5Vz7n6wtFSTGBpqlLu4SMDE0BdjnunqNSSWawxmuR3GUqLfMmX37tR8 jOh2kgrBgd5KcP/hvxIXKmqseZOy6HrmCP/RsFnZLbjn7ucc8Qv3ApNj8rzDQC37 ED6XWztdBNzVzKfsFfeEX+h0fMozZm2rEckBJf7GeM/p5e8NrnC+5z3c083Qi7/R T3YP0m/rLFnX5ITc79fbdUPlAgniZBkcYiWF7NP4zLuFHV2YU3MiogtLsYuBobFs MHPBe1NSCRay2JE90C/93xee7lOSi6NUmY4IUH3eTIM+Rk1+ijP8a2emg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41snt14pcq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:26 +0000 (GMT) Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGJFhW018370; Mon, 23 Sep 2024 16:22:25 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41snt14pcm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:25 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NEF4Sd012489; Mon, 23 Sep 2024 16:22:25 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 41t9fpqg0e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:25 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMN4J49611236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:23 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3393A20040; Mon, 23 Sep 2024 16:22:23 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CD63320043; Mon, 23 Sep 2024 16:22:22 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:22 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 15/18] cpu: Set current_cpu early in qemu-user Date: Mon, 23 Sep 2024 18:13:10 +0200 Message-ID: <20240923162208.90745-16-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Ccg1hI_Opm5eyXFZ-7BIrDFlOQ6cooJD X-Proofpoint-GUID: AhV3feqNPaNBasTvtutqeCZnAgkB0LIj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxlogscore=778 priorityscore=1501 suspectscore=0 mlxscore=0 clxscore=1015 impostorscore=0 malwarescore=0 bulkscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230121 Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 qemu_plugin_get_registers() may be called before cpu_exec(), and it requires current_cpu. Signed-off-by: Ilya Leoshkevich --- bsd-user/main.c | 1 + linux-user/main.c | 1 + linux-user/syscall.c | 1 + 3 files changed, 3 insertions(+) diff --git a/bsd-user/main.c b/bsd-user/main.c index b424a21f643..fb70aadbcee 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -617,6 +617,7 @@ int main(int argc, char **argv) gdbserver_start(gdbstub); gdb_handlesig(cpu, 0, NULL, NULL, 0); } + current_cpu = cpu; cpu_loop(env); /* never exits */ return 0; diff --git a/linux-user/main.c b/linux-user/main.c index 60091cf3053..4a794445d72 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -1022,6 +1022,7 @@ int main(int argc, char **argv, char **envp) qemu_semihosting_guestfd_init(); #endif + current_cpu = cpu; cpu_loop(env); /* never exits */ return 0; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 344c2e65234..46a8ba7098c 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6531,6 +6531,7 @@ static void *clone_func(void *arg) pthread_mutex_lock(&clone_lock); pthread_mutex_unlock(&clone_lock); bql_lock(); + current_cpu = cpu; cpu_loop(env); /* never exits */ return NULL; From patchwork Mon Sep 23 16:13:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809840 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id F089CCF9C6F for ; Mon, 23 Sep 2024 16:29:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpu-0007Ou-Ez; Mon, 23 Sep 2024 12:22:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpZ-0006XS-Nt for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:36 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpV-0000cN-OS for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:32 -0400 Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48N7Sq2L013386; Mon, 23 Sep 2024 16:22:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=lpKHUhaN9P+Pk xEJc8MSZinB2goxOOchK5QboD4Rig0=; b=me3oomKha/r+OyQzZAK6ffHIvUjKU TAsdQvonOQ+/23LZDxzISlDdWKpZeMlKMnpCcAIJeAVPaj1tGtQQhbTWiUm2SHHF nFqA26l7x3arMWP6FBzJKP575A+zVgao1aKZUv7ZCxZ2xHSGfByT7Rvn0BCKgky7 OiCdRz9MrwFRW88AZF0oYyWGG7vWkfJBpg9tQLoimSWZeRtdYS4wpEtX9pdNWYtu vDCOfqyW/4lq/TGi4hw5rtj3Q4F2NkrmSXjAIN+rsUbG0Nf77AXNdfRulj3wL0he 98nXOqwP9nIxM7Zkyh5CO82u/b6T6rhekIF3xPoso73IQox9JkJgT6zAw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41smjjmwdd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:26 +0000 (GMT) Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGMQ9g026049; Mon, 23 Sep 2024 16:22:26 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41smjjmwdb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:26 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NDl7Gx000643; Mon, 23 Sep 2024 16:22:25 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 41t8fufp6u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:25 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMNNk49611238 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:23 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A0B882004B; Mon, 23 Sep 2024 16:22:23 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 475FA20043; Mon, 23 Sep 2024 16:22:23 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:23 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 16/18] cpu: Allow pausing and resuming CPUs in qemu-user Date: Mon, 23 Sep 2024 18:13:11 +0200 Message-ID: <20240923162208.90745-17-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: GI3W6SA473lnD0rzaWwzoJqifIH-YqbJ X-Proofpoint-GUID: qkdC50Bh6vpbPCnsf5TAjf9f_SoXEMCT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 adultscore=0 malwarescore=0 suspectscore=0 bulkscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 phishscore=0 clxscore=1015 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230121 Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 Move the respective functions from sysemu to cpu-common. Signed-off-by: Ilya Leoshkevich --- accel/tcg/user-exec-stub.c | 4 -- accel/tcg/user-exec.c | 11 +++- cpu-common.c | 115 +++++++++++++++++++++++++++++++++++++ include/exec/cpu-common.h | 7 +++ include/sysemu/cpus.h | 5 -- system/cpus.c | 108 ---------------------------------- 6 files changed, 132 insertions(+), 118 deletions(-) diff --git a/accel/tcg/user-exec-stub.c b/accel/tcg/user-exec-stub.c index 4fbe2dbdc88..e79f2e88498 100644 --- a/accel/tcg/user-exec-stub.c +++ b/accel/tcg/user-exec-stub.c @@ -2,10 +2,6 @@ #include "hw/core/cpu.h" #include "exec/replay-core.h" -void cpu_resume(CPUState *cpu) -{ -} - void cpu_remove_sync(CPUState *cpu) { } diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index de4753cded7..3399b074485 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -1293,12 +1293,19 @@ int cpu_exec_user(CPUState *cs) { int trapnr; + do { + qemu_wait_io_event(cs); + } while (!cpu_can_run(cs)); + bql_unlock(); cpu_exec_start(cs); trapnr = cpu_exec(cs); cpu_exec_end(cs); bql_lock(); - process_queued_cpu_work(cs); + + do { + qemu_wait_io_event(cs); + } while (!cpu_can_run(cs)); return trapnr; } @@ -1306,11 +1313,13 @@ int cpu_exec_user(CPUState *cs) void qemu_cpu_kick(CPUState *cpu) { cpu_exit(cpu); + qemu_cond_broadcast(cpu->halt_cond); } void cpu_enter_syscall(CPUState *cs) { cs->in_syscall = true; + qemu_pause_cond_broadcast(); } void cpu_exit_syscall(CPUState *cs) diff --git a/cpu-common.c b/cpu-common.c index 2822ee9373d..979e3fe8806 100644 --- a/cpu-common.c +++ b/cpu-common.c @@ -24,6 +24,8 @@ #include "sysemu/cpus.h" #include "qemu/lockable.h" #include "trace/trace-root.h" +#include "exec/replay-core.h" +#include "qemu/plugin.h" QemuMutex qemu_cpu_list_lock; static QemuCond exclusive_cond; @@ -456,6 +458,9 @@ void cpu_breakpoint_remove_all(CPUState *cpu, int mask) /* The Big QEMU Lock (BQL) */ static QemuMutex bql = QEMU_MUTEX_INITIALIZER; +/* system init */ +static QemuCond qemu_pause_cond = QEMU_COND_INITIALIZER; + QEMU_DEFINE_STATIC_CO_TLS(bool, bql_locked) bool bql_locked(void) @@ -498,6 +503,105 @@ void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) do_run_on_cpu(cpu, func, data, &bql); } +static bool all_vcpus_paused(void) +{ + CPUState *cpu; + + CPU_FOREACH(cpu) { + if (!cpu_is_paused(cpu)) { + return false; + } + } + + return true; +} + +void pause_all_vcpus(void) +{ + CPUState *cpu; + + qemu_clock_enable(QEMU_CLOCK_VIRTUAL, false); + CPU_FOREACH(cpu) { + cpu_pause(cpu); + } + + /* We need to drop the replay_lock so any vCPU threads woken up + * can finish their replay tasks + */ + replay_mutex_unlock(); + + while (!all_vcpus_paused()) { + qemu_cond_wait_bql(&qemu_pause_cond); + CPU_FOREACH(cpu) { + qemu_cpu_kick(cpu); + } + } + + bql_unlock(); + replay_mutex_lock(); + bql_lock(); +} + +void qemu_pause_cond_broadcast(void) +{ + qemu_cond_broadcast(&qemu_pause_cond); +} + +static void qemu_cpu_stop(CPUState *cpu, bool exit) +{ + g_assert(qemu_cpu_is_self(cpu)); + cpu->stop = false; + cpu->stopped = true; + if (exit) { + cpu_exit(cpu); + } + qemu_pause_cond_broadcast(); +} + +void qemu_wait_io_event_common(CPUState *cpu) +{ + qatomic_set_mb(&cpu->thread_kicked, false); + if (cpu->stop) { + qemu_cpu_stop(cpu, false); + } + process_queued_cpu_work(cpu); +} + +void qemu_wait_io_event(CPUState *cpu) +{ + bool slept = false; + + while (cpu_thread_is_idle(cpu)) { + if (!slept) { + slept = true; + qemu_plugin_vcpu_idle_cb(cpu); + } + qemu_cond_wait_bql(cpu->halt_cond); + } + if (slept) { + qemu_plugin_vcpu_resume_cb(cpu); + } + + qemu_wait_io_event_common(cpu); +} + +void cpu_pause(CPUState *cpu) +{ + if (qemu_cpu_is_self(cpu)) { + qemu_cpu_stop(cpu, true); + } else { + cpu->stop = true; + qemu_cpu_kick(cpu); + } +} + +void cpu_resume(CPUState *cpu) +{ + cpu->stop = false; + cpu->stopped = false; + qemu_cpu_kick(cpu); +} + bool cpu_work_list_empty(CPUState *cpu) { return QSIMPLEQ_EMPTY_ATOMIC(&cpu->work_list); @@ -516,3 +620,14 @@ int cpu_thread_is_idle_common(CPUState *cpu) } return -1; } + +bool cpu_can_run(CPUState *cpu) +{ + if (cpu->stop) { + return false; + } + if (cpu_is_stopped(cpu)) { + return false; + } + return true; +} diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index e8b530ed889..a54368c5b69 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -234,6 +234,13 @@ void cpu_exit_syscall(CPUState *cs); int cpu_thread_is_idle_common(CPUState *cpu); bool cpu_thread_is_idle(CPUState *cpu); bool cpu_is_paused(CPUState *cpu); +bool cpu_can_run(CPUState *cpu); +void qemu_wait_io_event_common(CPUState *cpu); +void qemu_wait_io_event(CPUState *cpu); +void pause_all_vcpus(void); +void qemu_pause_cond_broadcast(void); +bool cpu_work_list_empty(CPUState *cpu); + /** * env_archcpu(env) diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h index bfa3fd45650..ebfd0b77bcd 100644 --- a/include/sysemu/cpus.h +++ b/include/sysemu/cpus.h @@ -20,11 +20,7 @@ void dummy_start_vcpu_thread(CPUState *); #define VCPU_THREAD_NAME_SIZE 16 void cpus_kick_thread(CPUState *cpu); -bool cpu_work_list_empty(CPUState *cpu); bool all_cpu_threads_idle(void); -bool cpu_can_run(CPUState *cpu); -void qemu_wait_io_event_common(CPUState *cpu); -void qemu_wait_io_event(CPUState *cpu); void cpu_thread_signal_created(CPUState *cpu); void cpu_thread_signal_destroyed(CPUState *cpu); void cpu_handle_guest_debug(CPUState *cpu); @@ -34,7 +30,6 @@ void cpu_handle_guest_debug(CPUState *cpu); bool qemu_in_vcpu_thread(void); void qemu_init_cpu_loop(void); void resume_all_vcpus(void); -void pause_all_vcpus(void); void cpu_stop_current(void); extern int icount_align_option; diff --git a/system/cpus.c b/system/cpus.c index 407140c41f6..9ad7bae056e 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -307,17 +307,6 @@ int vm_shutdown(void) return do_vm_stop(RUN_STATE_SHUTDOWN, false); } -bool cpu_can_run(CPUState *cpu) -{ - if (cpu->stop) { - return false; - } - if (cpu_is_stopped(cpu)) { - return false; - } - return true; -} - void cpu_handle_guest_debug(CPUState *cpu) { if (replay_running_debug()) { @@ -400,56 +389,15 @@ static QemuThread io_thread; /* cpu creation */ static QemuCond qemu_cpu_cond; -/* system init */ -static QemuCond qemu_pause_cond; void qemu_init_cpu_loop(void) { qemu_init_sigbus(); qemu_cond_init(&qemu_cpu_cond); - qemu_cond_init(&qemu_pause_cond); qemu_thread_get_self(&io_thread); } -static void qemu_cpu_stop(CPUState *cpu, bool exit) -{ - g_assert(qemu_cpu_is_self(cpu)); - cpu->stop = false; - cpu->stopped = true; - if (exit) { - cpu_exit(cpu); - } - qemu_cond_broadcast(&qemu_pause_cond); -} - -void qemu_wait_io_event_common(CPUState *cpu) -{ - qatomic_set_mb(&cpu->thread_kicked, false); - if (cpu->stop) { - qemu_cpu_stop(cpu, false); - } - process_queued_cpu_work(cpu); -} - -void qemu_wait_io_event(CPUState *cpu) -{ - bool slept = false; - - while (cpu_thread_is_idle(cpu)) { - if (!slept) { - slept = true; - qemu_plugin_vcpu_idle_cb(cpu); - } - qemu_cond_wait_bql(cpu->halt_cond); - } - if (slept) { - qemu_plugin_vcpu_resume_cb(cpu); - } - - qemu_wait_io_event_common(cpu); -} - void cpus_kick_thread(CPUState *cpu) { if (cpu->thread_kicked) { @@ -513,67 +461,11 @@ void cpu_thread_signal_destroyed(CPUState *cpu) qemu_cond_signal(&qemu_cpu_cond); } -void cpu_pause(CPUState *cpu) -{ - if (qemu_cpu_is_self(cpu)) { - qemu_cpu_stop(cpu, true); - } else { - cpu->stop = true; - qemu_cpu_kick(cpu); - } -} - -void cpu_resume(CPUState *cpu) -{ - cpu->stop = false; - cpu->stopped = false; - qemu_cpu_kick(cpu); -} - bool cpu_is_paused(CPUState *cpu) { return cpu->stopped; } -static bool all_vcpus_paused(void) -{ - CPUState *cpu; - - CPU_FOREACH(cpu) { - if (!cpu_is_paused(cpu)) { - return false; - } - } - - return true; -} - -void pause_all_vcpus(void) -{ - CPUState *cpu; - - qemu_clock_enable(QEMU_CLOCK_VIRTUAL, false); - CPU_FOREACH(cpu) { - cpu_pause(cpu); - } - - /* We need to drop the replay_lock so any vCPU threads woken up - * can finish their replay tasks - */ - replay_mutex_unlock(); - - while (!all_vcpus_paused()) { - qemu_cond_wait_bql(&qemu_pause_cond); - CPU_FOREACH(cpu) { - qemu_cpu_kick(cpu); - } - } - - bql_unlock(); - replay_mutex_lock(); - bql_lock(); -} - void resume_all_vcpus(void) { CPUState *cpu; From patchwork Mon Sep 23 16:13:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809832 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 81D38CF9C72 for ; Mon, 23 Sep 2024 16:25:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslpw-0007iV-Is; Mon, 23 Sep 2024 12:22:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpi-0006lW-BF for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:42 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpg-0000ce-0C for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:41 -0400 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48NDTSxS022624; Mon, 23 Sep 2024 16:22:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=4jKFaE+nAcKFG HgVUI61x15jdvMo3CEXemOHI19GnaM=; b=dz5ioy4NbwdoktqQxOFLsNmxQ3yrR HYBERNFsa3EpRWg2YnMXiQ1/icTwAtPxnUfa9WiQkPbVqkyoX2vIE7CfJTPSKCBV SKOb8WssbuTEAr35OQH6QyIvbXL0L4LM5hkDfdO0BYtKEJ5bBseK9NxkpbyEygO7 KcE/+E4cNvjsfdXA9Kchp4uuck/insboE6qu7/B+NHNPIWyWx/JDT6hlssaOPwKz e49afvQRxgYQLndo39KB+cw7TjfPFpXa4NctDSc6OfU8gu5tHAMlBPuWDKIgcLRR coTbPozizYTtFCahtwCrS8GArO3iUFMMxTbutrbQ63A6IBHe2lG/zOz6g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41skjrd0ey-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:27 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGML0R024405; Mon, 23 Sep 2024 16:22:26 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41skjrd0ev-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:26 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NEwlMC014009; Mon, 23 Sep 2024 16:22:26 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 41t9ymqcy6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:26 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMOPr52232600 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:24 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1422A2004E; Mon, 23 Sep 2024 16:22:24 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B31342004D; Mon, 23 Sep 2024 16:22:23 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:23 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 17/18] gdbstub: Pause all CPUs before sending stop replies Date: Mon, 23 Sep 2024 18:13:12 +0200 Message-ID: <20240923162208.90745-18-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: CFdM_Cj9pRsyXbBe-C7LFlP1tMGBXB3J X-Proofpoint-ORIG-GUID: DMKLeepD6df2pdo_EtWlC2JgrNJzXbGi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 priorityscore=1501 spamscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 clxscore=1015 malwarescore=0 mlxlogscore=489 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230117 Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 This is required by the GDB remote protocol. Signed-off-by: Ilya Leoshkevich --- gdbstub/gdbstub.c | 2 ++ gdbstub/user.c | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index a096104b07a..be632f8b214 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -2497,6 +2497,8 @@ bool gdb_try_stop(void) return false; } + pause_all_vcpus(); + gdbserver_state.allow_stop_reply = false; return true; } diff --git a/gdbstub/user.c b/gdbstub/user.c index 82007b09db6..3095c846a99 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -458,6 +458,7 @@ static void disable_gdbstub(CPUState *thread_cpu) cpu_breakpoint_remove_all(cpu, BP_GDB); /* no cpu_watchpoint_remove_all for user-mode */ cpu_single_step(cpu, 0); + cpu_resume(cpu); } tb_flush(thread_cpu); } @@ -650,9 +651,16 @@ int gdb_continue_partial(char *newstates) * previous situation, where only one CPU would be single-stepped. */ CPU_FOREACH(cpu) { - if (newstates[cpu->cpu_index] == 's') { + switch (newstates[cpu->cpu_index]) { + case 's': trace_gdbstub_op_stepping(cpu->cpu_index); cpu_single_step(cpu, gdbserver_state.sstep_flags); + QEMU_FALLTHROUGH; + case 'c': + case 'C': + case 'S': + cpu_resume(cpu); + break; } } gdbserver_user_state.running_state = 1; From patchwork Mon Sep 23 16:13:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13809835 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 284D8CF9C6F for ; Mon, 23 Sep 2024 16:26:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sslq2-00080U-2d; Mon, 23 Sep 2024 12:23:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpZ-0006XU-O1 for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:36 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sslpW-0000cX-05 for qemu-devel@nongnu.org; Mon, 23 Sep 2024 12:22:33 -0400 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48NCxHbN027664; Mon, 23 Sep 2024 16:22:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:mime-version; s=pp1; bh=IKh+tMgnefobp QcHLCDkFG0LTLlCEpBsVAWl2X8EoSg=; b=IiJlU0tz2lq2XVs9hfI3mcyD4Pus4 Of7U+8FGzsG1aFh4duyYQO6E4BQ17NyXiqtvwjn3D6hnqMpcH/0kKN9WLRnlb+mC 92Ing9c+Gjcly1yKefU7sdqNJBO8A/8m1FT4HRhLH2tsE+df3pVPVFyCFA7x/8CE 58wzF0lqy6SYdpr0n9O8nyvOC1U0ssaNQ9opuLycfuXOyChSb/qWfxoCJ/LymdQA D0ol8d5UBRrY0rmDA6ns4Uilov5mXlZfbP2N18Vws+cZZgstfPXVozZmZPvqSJvf JYvflvPKX4KV4XP25XyxLKp7lIScfxgIxixyEb0AmpIthH8STCFefY4tw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41snt14pcv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:27 +0000 (GMT) Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 48NGKwNU023341; Mon, 23 Sep 2024 16:22:27 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41snt14pcs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:26 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48NDl7H0000643; Mon, 23 Sep 2024 16:22:26 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 41t8fufp6v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2024 16:22:26 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48NGMOEh52232606 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:22:24 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7B97720043; Mon, 23 Sep 2024 16:22:24 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2736C20040; Mon, 23 Sep 2024 16:22:24 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.179.24.235]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Sep 2024 16:22:24 +0000 (GMT) From: Ilya Leoshkevich To: Richard Henderson , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH 18/18] tests/tcg: Stress test thread breakpoints Date: Mon, 23 Sep 2024 18:13:13 +0200 Message-ID: <20240923162208.90745-19-iii@linux.ibm.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923162208.90745-1-iii@linux.ibm.com> References: <20240923162208.90745-1-iii@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: _EpI72GVGbHpEqupnWVrFmUWPYP51zGV X-Proofpoint-GUID: 8MFafCs5dLQVfFA7GPdLHqL5gZPVboWv X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxlogscore=999 priorityscore=1501 suspectscore=0 mlxscore=0 clxscore=1015 impostorscore=0 malwarescore=0 bulkscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409230121 Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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 Add a test to prevent regressions. Signed-off-by: Ilya Leoshkevich --- tests/tcg/multiarch/Makefile.target | 13 ++- .../gdbstub/test-thread-breakpoint-stress.py | 28 ++++++ .../tcg/multiarch/thread-breakpoint-stress.c | 92 +++++++++++++++++++ 3 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/multiarch/gdbstub/test-thread-breakpoint-stress.py create mode 100644 tests/tcg/multiarch/thread-breakpoint-stress.c diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.target index 5e3391ec9d2..0a9cd037094 100644 --- a/tests/tcg/multiarch/Makefile.target +++ b/tests/tcg/multiarch/Makefile.target @@ -42,6 +42,9 @@ munmap-pthread: LDFLAGS+=-pthread vma-pthread: CFLAGS+=-pthread vma-pthread: LDFLAGS+=-pthread +thread-breakpoint-stress: CFLAGS+=-pthread +thread-breakpoint-stress: LDFLAGS+=-pthread + # The vma-pthread seems very sensitive on gitlab and we currently # don't know if its exposing a real bug or the test is flaky. ifneq ($(GITLAB_CI),) @@ -127,6 +130,13 @@ run-gdbstub-follow-fork-mode-parent: follow-fork-mode --bin $< --test $(MULTIARCH_SRC)/gdbstub/follow-fork-mode-parent.py, \ following parents on fork) +run-gdbstub-thread-breakpoint-stress: thread-breakpoint-stress + $(call run-test, $@, $(GDB_SCRIPT) \ + --gdb $(GDB) \ + --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \ + --bin $< --test $(MULTIARCH_SRC)/gdbstub/test-thread-breakpoint-stress.py, \ + hitting many breakpoints on different threads) + else run-gdbstub-%: $(call skip-test, "gdbstub test $*", "need working gdb with $(patsubst -%,,$(TARGET_NAME)) support") @@ -136,7 +146,8 @@ EXTRA_RUNS += run-gdbstub-sha1 run-gdbstub-qxfer-auxv-read \ run-gdbstub-registers run-gdbstub-prot-none \ run-gdbstub-catch-syscalls run-gdbstub-follow-fork-mode-child \ run-gdbstub-follow-fork-mode-parent \ - run-gdbstub-qxfer-siginfo-read + run-gdbstub-qxfer-siginfo-read \ + run-gdbstub-thread-breakpoint-stress # ARM Compatible Semi Hosting Tests # diff --git a/tests/tcg/multiarch/gdbstub/test-thread-breakpoint-stress.py b/tests/tcg/multiarch/gdbstub/test-thread-breakpoint-stress.py new file mode 100644 index 00000000000..489d238f02d --- /dev/null +++ b/tests/tcg/multiarch/gdbstub/test-thread-breakpoint-stress.py @@ -0,0 +1,28 @@ +"""Test multiple threads hitting breakpoints. + +SPDX-License-Identifier: GPL-2.0-or-later +""" +from test_gdbstub import main, report + + +N_BREAK_THREADS = 2 +N_BREAKS = 100 + + +def run_test(): + """Run through the tests one by one""" + if gdb.selected_inferior().architecture().name() == "MicroBlaze": + print("SKIP: Atomics are broken on MicroBlaze") + exit(0) + gdb.execute("break break_here") + gdb.execute("continue") + for _ in range(N_BREAK_THREADS * N_BREAKS): + counter1 = int(gdb.parse_and_eval("s->counter")) + counter2 = int(gdb.parse_and_eval("s->counter")) + report(counter1 == counter2, "{} == {}".format(counter1, counter2)) + gdb.execute("continue") + exitcode = int(gdb.parse_and_eval("$_exitcode")) + report(exitcode == 0, "{} == 0".format(exitcode)) + + +main(run_test) diff --git a/tests/tcg/multiarch/thread-breakpoint-stress.c b/tests/tcg/multiarch/thread-breakpoint-stress.c new file mode 100644 index 00000000000..1feed8577aa --- /dev/null +++ b/tests/tcg/multiarch/thread-breakpoint-stress.c @@ -0,0 +1,92 @@ +/* + * Test multiple threads hitting breakpoints. + * + * The main thread performs a lengthy syscall. The test verifies that this + * does not interfere with the ability to stop threads. + * + * The counter thread constantly increments a value by 1. The test verifies + * that it is stopped when another thread hits a breakpoint. + * + * The break threads constantly and simultaneously hit the same breakpoint. + * The test verifies that GDB and gdbstub do not lose any hits and do not + * deadlock. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include +#include +#include + +struct state { + int counter; + int done; + pthread_barrier_t barrier; + int break_counter; +}; + +static void *counter_loop(void *arg) +{ + struct state *s = arg; + + while (!__atomic_load_n(&s->done, __ATOMIC_SEQ_CST)) { + __atomic_add_fetch(&s->counter, 1, __ATOMIC_SEQ_CST); + } + + return NULL; +} + +#define N_BREAK_THREADS 2 +#define N_BREAKS 100 + +/* Non-static to avoid inlining. */ +void break_here(struct state *s) +{ + __atomic_add_fetch(&s->break_counter, 1, __ATOMIC_SEQ_CST); +} + +static void *break_loop(void *arg) +{ + struct state *s = arg; + int i; + + pthread_barrier_wait(&s->barrier); + for (i = 0; i < N_BREAKS; i++) { + break_here(s); + } + + return NULL; +} + +int main(void) +{ + pthread_t break_threads[N_BREAK_THREADS], counter_thread; + struct state s = {}; + int i, ret; + +#ifdef __MICROBLAZE__ + /* + * Microblaze has broken atomics. + * See https://github.com/Xilinx/meta-xilinx/blob/xlnx-rel-v2024.1/meta-microblaze/recipes-devtools/gcc/gcc-12/0009-Patch-microblaze-Fix-atomic-boolean-return-value.patch + */ + return EXIT_SUCCESS; +#endif + + ret = pthread_barrier_init(&s.barrier, NULL, N_BREAK_THREADS); + assert(ret == 0); + ret = pthread_create(&counter_thread, NULL, counter_loop, &s); + assert(ret == 0); + for (i = 0; i < N_BREAK_THREADS; i++) { + ret = pthread_create(&break_threads[i], NULL, break_loop, &s); + assert(ret == 0); + } + for (i = 0; i < N_BREAK_THREADS; i++) { + ret = pthread_join(break_threads[i], NULL); + assert(ret == 0); + } + __atomic_store_n(&s.done, 1, __ATOMIC_SEQ_CST); + ret = pthread_join(counter_thread, NULL); + assert(ret == 0); + assert(s.break_counter == N_BREAK_THREADS * N_BREAKS); + + return EXIT_SUCCESS; +}