From patchwork Thu Mar 2 19:08:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 658149 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp68209wrb; Thu, 2 Mar 2023 11:18:04 -0800 (PST) X-Google-Smtp-Source: AK7set8B5BXOEsk9C0rCdKfOwn0QvPJ2jC+nJCqpehKbsCLYOPQaiyGWImD6STNqFpdt8OJM2f7K X-Received: by 2002:a05:622a:1650:b0:3b8:2a6c:d1e3 with SMTP id y16-20020a05622a165000b003b82a6cd1e3mr20347503qtj.21.1677784684711; Thu, 02 Mar 2023 11:18:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677784684; cv=none; d=google.com; s=arc-20160816; b=jGs1uVOIrUUVYMlG0YmMpeMxw9oeTY1AM2ZisJnu71izb7kCAELp33kYm+H2HROWgM cuXATQnx441fM6wtqcCAWPMU6Gat6Mn/Oyqj3qosBboURgym4azjcz4vlyJrKRU2c7Ub oMAzGXlZ/xGpDnLaEFM6W5PBax8mO1TQz1yFiTH6UHBVtq/FYAhagErX8qzbZzh30z2n AHXQ1O0sNOOF/l1YuoVuePSyzkoMO+pvHmNWvjf3a2MkBUi3VCTBkbCE2AdbuqzeNxOI 4/JY8wJXaFFDBC/8ROX/7lqRsVk7EFsMYtpw5b8odP5Y26upyNQyDWC/S6kZtkIO4p/u g6Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KZ1bzurdoC+jowRyfZk2dA2rPNkKxibvGc1imFmhxks=; b=the5jKFrTiBmYyEuwp6lgghaBPhhOgMfOP9ew+E5oUtI4wVRNRG1iFQUymySRFu4ia mqgzVsxOrUYQU9Jfyq8MVZvOe9sjB782dcKY248Al4O2EpBMOIY+Sg2AyKXdjYvXEw2l NyVSq3CKHnFM8OeSzby0V8j2pR4mzrHV05jZI3ExjabnlbNC2O80dJXeTvldliIHF7OL tFuxRNlHx3pb4rJ7z1zqlCLwDfDvFi/Vp8OIBS0WBSprC3KLCp913rHajj51uwXyN0xo iZUfcLX5lnrcal+vucbbcwXZ8JJnJKodL8mY4ZfIrzt0tD8x/IetRCp6+weEdnVLxwhC yvSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iiyS5GMc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t2-20020a05622a01c200b003b9b98b50dfsi289842qtw.185.2023.03.02.11.18.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Mar 2023 11:18:04 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iiyS5GMc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXoNy-00072T-Iw; Thu, 02 Mar 2023 14:14:38 -0500 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 1pXoNv-0006qj-Js for qemu-devel@nongnu.org; Thu, 02 Mar 2023 14:14:35 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXoNo-0000nR-Cw for qemu-devel@nongnu.org; Thu, 02 Mar 2023 14:14:35 -0500 Received: by mail-wr1-x42b.google.com with SMTP id bx12so122286wrb.11 for ; Thu, 02 Mar 2023 11:14:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KZ1bzurdoC+jowRyfZk2dA2rPNkKxibvGc1imFmhxks=; b=iiyS5GMcA7ksWgSh+I6plVtuEIoHFQ45VTTszckDYqHLaDajTxYx/sX1Rvfxhy69YG SAVS4/Kz4ggxsyxJuBu++OU6bnNYPQoDGeGVxXu2dawFC0KpWt+2gKdMb2NPmYiTvTPI 5xzWhVn/ZdC2waLe67u6QYICfXz6YMZ8mROwKmFfyLoFWNUQCXW23788s8mmgoXev51L iMKsdeZ6qGP720vAIx/P4B68YxCvgvkt/FQFG+4GLunKZ2frwmsInKsVWeKuHYl8nHSp WvtdfztrP6FJf1hEjmFfV1J9gjnqmATd9f45fdlo4h01KmX/aQS+uSWvpAJ/Dj+7Y4Pg lvVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KZ1bzurdoC+jowRyfZk2dA2rPNkKxibvGc1imFmhxks=; b=UzVI14yDOeXJkZUIAQm1+4KrWVdl3KE+P5yFA+gmu98OUjG0vd8yDcVbxHgvJElHa6 PG94I2KlqY9yBIewqGi4Yw70CuFAEhN7Gky2yptBaEE+6zrZw3escrL552WpHJpq6m04 fORYTB6pqBM/HGScI7mov9uwlC12d98MUQ3wmjuHcF6D+FnutFzvbDRI87tWVmPSU0pA EnjiUivk7zSVFHNzNG0VdRE1c3KF/noeXXAtNXlbI0udzrvdn/o30YJnoL2JkDKdlkey Dnw0Z7XNk5YBcITRzVPBCbOv3cauY21p8bMFgwAZ25z5drgxrcc0AkmPDUApSvBwlDMo GUgA== X-Gm-Message-State: AO0yUKXL7RmP0As1VKpoDLn6VH18Nkt/svqh5R7ZODfMHkJX9vVMSHoC r/cL1Newg0S25007aPfRiOt3EA== X-Received: by 2002:adf:ef0c:0:b0:2c7:d56:777b with SMTP id e12-20020adfef0c000000b002c70d56777bmr8047214wro.64.1677784464789; Thu, 02 Mar 2023 11:14:24 -0800 (PST) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id h18-20020a5d4312000000b002c7107ce17fsm186010wrq.3.2023.03.02.11.14.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 11:14:23 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 80B491FFCA; Thu, 2 Mar 2023 19:08:50 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Weiwei Li , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Palmer Dabbelt , Laurent Vivier , nicolas.eder@lauterbach.com, Ilya Leoshkevich , kvm@vger.kernel.org, "Edgar E. Iglesias" , David Gibson , Max Filippov , Sunil Muthuswamy , qemu-s390x@nongnu.org, Stafford Horne , Bin Meng , Marek Vasut , Greg Kurz , Song Gao , Aleksandar Rikalo , Liu Zhiwei , Alistair Francis , Chris Wulff , qemu-riscv@nongnu.org, Michael Rolnik , qemu-arm@nongnu.org, Cleber Rosa , Artyom Tarasenko , Marcel Apfelbaum , Eduardo Habkost , Yoshinori Sato , Alexandre Iooss , Daniel Henrique Barboza , Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , mads@ynddal.dk, Mark Cave-Ayland , qemu-ppc@nongnu.org, Richard Henderson , John Snow , Xiaojuan Yang , Thomas Huth , Paolo Bonzini , Mahmoud Mandour , Aurelien Jarno , Bastian Koppelmann , Yanan Wang , David Hildenbrand , Taylor Simpson , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v4 25/26] gdbstub: split out softmmu/user specifics for syscall handling Date: Thu, 2 Mar 2023 19:08:45 +0000 Message-Id: <20230302190846.2593720-26-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230302190846.2593720-1-alex.bennee@linaro.org> References: <20230302190846.2593720-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Most of the syscall code is config agnostic aside from the size of target_ulong. In preparation for the next patch move the final bits of specialisation into the appropriate user and softmmu helpers. Signed-off-by: Alex Bennée --- v4 - checkpatch cleanups --- gdbstub/internals.h | 5 +++++ gdbstub/softmmu.c | 24 ++++++++++++++++++++++++ gdbstub/syscalls.c | 35 +++++++++++------------------------ gdbstub/user.c | 24 ++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 24 deletions(-) diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 8db61f7fb4..65d75d9435 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -195,6 +195,11 @@ bool gdb_handled_syscall(void); void gdb_disable_syscalls(void); void gdb_syscall_reset(void); +/* user/softmmu specific signal handling */ +void gdb_pre_syscall_handling(void); +bool gdb_send_syscall_now(void); +void gdb_post_syscall_handling(void); + /* * Break/Watch point support - there is an implementation for softmmu * and user mode. diff --git a/gdbstub/softmmu.c b/gdbstub/softmmu.c index d3152fb6e7..02f3b41095 100644 --- a/gdbstub/softmmu.c +++ b/gdbstub/softmmu.c @@ -103,6 +103,30 @@ static void gdb_chr_event(void *opaque, QEMUChrEvent event) } } +/* + * In softmmu mode we stop the VM and wait to send the syscall packet + * until notification that the CPU has stopped. This must be done + * because if the packet is sent now the reply from the syscall + * request could be received while the CPU is still in the running + * state, which can cause packets to be dropped and state transition + * 'T' packets to be sent while the syscall is still being processed. + */ + +void gdb_pre_syscall_handling(void) +{ + vm_stop(RUN_STATE_DEBUG); +} + +bool gdb_send_syscall_now(void) +{ + return false; +} + +void gdb_post_syscall_handling(void) +{ + qemu_cpu_kick(gdbserver_state.c_cpu); +} + static void gdb_vm_state_change(void *opaque, bool running, RunState state) { CPUState *cpu = gdbserver_state.c_cpu; diff --git a/gdbstub/syscalls.c b/gdbstub/syscalls.c index f15b210958..1ca3d81305 100644 --- a/gdbstub/syscalls.c +++ b/gdbstub/syscalls.c @@ -104,9 +104,10 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va) } gdbserver_syscall_state.current_syscall_cb = cb; -#ifndef CONFIG_USER_ONLY - vm_stop(RUN_STATE_DEBUG); -#endif + + /* user/softmmu specific handling */ + gdb_pre_syscall_handling(); + p = &gdbserver_syscall_state.syscall_buf[0]; p_end = &gdbserver_syscall_state.syscall_buf[sizeof(gdbserver_syscall_state.syscall_buf)]; *(p++) = 'F'; @@ -141,27 +142,13 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va) } } *p = 0; -#ifdef CONFIG_USER_ONLY - gdb_put_packet(gdbserver_syscall_state.syscall_buf); - /* - * Return control to gdb for it to process the syscall request. - * Since the protocol requires that gdb hands control back to us - * using a "here are the results" F packet, we don't need to check - * gdb_handlesig's return value (which is the signal to deliver if - * execution was resumed via a continue packet). - */ - gdb_handlesig(gdbserver_state.c_cpu, 0); -#else - /* - * In this case wait to send the syscall packet until notification that - * the CPU has stopped. This must be done because if the packet is sent - * now the reply from the syscall request could be received while the CPU - * is still in the running state, which can cause packets to be dropped - * and state transition 'T' packets to be sent while the syscall is still - * being processed. - */ - qemu_cpu_kick(gdbserver_state.c_cpu); -#endif + + if (gdb_send_syscall_now()) { /* true only for *-user */ + gdb_put_packet(gdbserver_syscall_state.syscall_buf); + } + + /* user/softmmu specific handling */ + gdb_post_syscall_handling(); } void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...) diff --git a/gdbstub/user.c b/gdbstub/user.c index 3da410e221..583cc83898 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -472,3 +472,27 @@ void gdb_breakpoint_remove_all(CPUState *cs) { cpu_breakpoint_remove_all(cs, BP_GDB); } + +/* + * For user-mode syscall support we send the system call immediately + * and then return control to gdb for it to process the syscall request. + * Since the protocol requires that gdb hands control back to us + * using a "here are the results" F packet, we don't need to check + * gdb_handlesig's return value (which is the signal to deliver if + * execution was resumed via a continue packet). + */ + +void gdb_pre_syscall_handling(void) +{ + return; +} + +bool gdb_send_syscall_now(void) +{ + return true; +} + +void gdb_post_syscall_handling(void) +{ + gdb_handlesig(gdbserver_state.c_cpu, 0); +}