From patchwork Tue Feb 21 22:52:27 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: 655390 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp371203wrb; Tue, 21 Feb 2023 14:56:31 -0800 (PST) X-Google-Smtp-Source: AK7set+iVEypc43Af+cvF7q07AWmzYbFVAfwZaevVs0Qaxuer9oOoNem3c76hcu+T5qLYBSwV4Um X-Received: by 2002:a05:622a:138e:b0:3ba:1d8d:f6d0 with SMTP id o14-20020a05622a138e00b003ba1d8df6d0mr10905732qtk.23.1677020191169; Tue, 21 Feb 2023 14:56:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677020191; cv=none; d=google.com; s=arc-20160816; b=M8jaUxsPanZyGc0uSudotfTBEv1pckafRsCSv94R18N21UfeMZaa9yV/1NR68oGnLB xrFbpwJVTLiydG3atSfO+arRnY01q4nSLSTFgyPFvTtiCfBpbdBNiiOVwxYlhcVJOYRd e3qQal3SwiA4WsXN65dgaiI1DmlJDCHMCKcR8JdmPWrQZ3uwvJFDEFqv9Nh4VTT337/S B6sjSbSkoyXnkqy3rCqDUfpt35J3G5pGl8BnmhGLi/vC+W+RaumZhLdq42M4W4orxRZ7 tWntTDp/uhPCe5Zokeb/qoN+qoSR+MZ+FATs0WT76nyJkrF4bQPXE+NgHT0AABwFL4aB S5eg== 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=7X5ixi52u3q8mNTsDp+C9raeJcKQAq90J8thOzhSOf4=; b=AmTY8h6cJtlz2GNwgBs8zkTmn6gKNGmoEnqhDfzG9FNr+UkOgWkoXC7K0JHzhmq1xh shyGbTYrrPmlmaCN4DOBF9QMz0X+DSkFX69NWhlbDUqykNJ2jkMBEv/ii3iInsRIRINu Oibdv4BXKXYJv4BWHT3p0IU9yatzXSkSNOwRLS2oPb+KdFWAHssyRbODCK6uX2/U4E4W 6oVc6jJ+q3sdh4RVwwPQEAZUtXttiJ9cPYs/hmy4jJ7Gcc3X7b/odCqAhRNqOqxByo49 uGMyphFeQaektuN2PJ/FNdhI44N88mw5hIMLqGh7MdE6q7kabIZWwWpSTqufSdWZrVYY CYhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ocbfQBav; 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 p21-20020a05622a00d500b003b63c3333easi13302831qtw.158.2023.02.21.14.56.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Feb 2023 14:56:31 -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=ocbfQBav; 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 1pUbVb-00080w-D6; Tue, 21 Feb 2023 17:53:15 -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 1pUbVN-0007eo-9e for qemu-devel@nongnu.org; Tue, 21 Feb 2023 17:53:01 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUbV1-000434-0g for qemu-devel@nongnu.org; Tue, 21 Feb 2023 17:53:00 -0500 Received: by mail-wm1-x329.google.com with SMTP id j3so2436792wms.2 for ; Tue, 21 Feb 2023 14:52:36 -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=7X5ixi52u3q8mNTsDp+C9raeJcKQAq90J8thOzhSOf4=; b=ocbfQBavJ8WLxSRTQ2bnnLROw0gUfzJDpQjmcaxhRnhbKv95/lFgoeVeWmA7qjNdkQ sHe9vigPRSVLgYkyD4v4R9WiNSOqNjgUbNY/CDlwLsmz6XWOwpy9OmDGVdA7Ffa2cs5Z yaW/J5rSohdQgMnnAi4RXwWwvWCfQ7SHvKoA1QHqk0FW3i+kpZHJhOczr+eumYbQ3JW6 CW0Wq0+qT3TTnYQCk55QRLWa2KDNp5j7qd+4xdnwaXhBHHznS13fhr1C6UBBjzeI5M36 DXK8W1sA+L3mUEVnJL+fSc9jQwD2McsMsZ7+wbL+treKAGuEsIFYG6q6gMteUqy7NwgC 2GhQ== 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=7X5ixi52u3q8mNTsDp+C9raeJcKQAq90J8thOzhSOf4=; b=jJ/CNyXMY5go/jTJaPJaML0o1rlekAtCikZxp9k345mbYsZFy+F1cEqToyF28NfIBo CVZqPKh4q3jtkDDPnq22Re1mhc23aJo4wCmxrJvpHSKLUHsYIYqeCQr15AsmyDwKToeQ MaqZDzPl4cWvObfWl58DDwFZLLEOt7/Dcdiq/IlEVIFotkPTJ5uMVB3VDaMQI7tZ+l9O JHpXAUgv7O6sGYEaSdiBNIsb4h2fuStBtOXHGOWoKkoRaj9Z9+3Gw7RjJcCabnEKkNnu yT2Qd/MF0Ic5OMurD/C77JXHDVEuHZji9x7E5mhVvWOSuaug/j+cmMNL2OnJ8+ZnonKN RhDg== X-Gm-Message-State: AO0yUKX2wGwL3MQoLGykSgo9nvdnYmgiqfzbfDGkULuSg/oN+p9P2+hI ZWttIBuNxsXZt/1El8T4WcEw2Q== X-Received: by 2002:a05:600c:2ed2:b0:3df:eda1:43b9 with SMTP id q18-20020a05600c2ed200b003dfeda143b9mr4239776wmn.4.1677019956493; Tue, 21 Feb 2023 14:52:36 -0800 (PST) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id b4-20020adff904000000b002c54f39d34csm9059057wrr.111.2023.02.21.14.52.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 14:52:34 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 6793A1FFD2; Tue, 21 Feb 2023 22:52:31 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Thomas Huth , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Yoshinori Sato , nicolas.eder@lauterbach.com, Stafford Horne , Daniel Henrique Barboza , Mahmoud Mandour , Taylor Simpson , mads@ynddal.dk, Marek Vasut , Artyom Tarasenko , Alistair Francis , qemu-ppc@nongnu.org, Yanan Wang , Sunil Muthuswamy , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Eduardo Habkost , Bin Meng , Bastian Koppelmann , Palmer Dabbelt , Marcel Apfelbaum , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Michael Rolnik , Aleksandar Rikalo , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Aurelien Jarno , Xiaojuan Yang , Richard Henderson , Peter Maydell , Alexandre Iooss , Chris Wulff , Jiaxun Yang , David Gibson , "Edgar E. Iglesias" , Greg Kurz , David Hildenbrand , Song Gao , Ilya Leoshkevich , Max Filippov , Mark Cave-Ayland Subject: [PATCH v3 24/24] gdbstub: split out softmmu/user specifics for syscall handling Date: Tue, 21 Feb 2023 22:52:27 +0000 Message-Id: <20230221225227.3735319-25-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221225227.3735319-1-alex.bennee@linaro.org> References: <20230221225227.3735319-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x329.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 --- gdbstub/internals.h | 5 +++++ gdbstub/softmmu.c | 24 ++++++++++++++++++++++++ gdbstub/syscalls.c | 32 +++++++++++--------------------- gdbstub/user.c | 24 ++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 21 deletions(-) diff --git a/gdbstub/internals.h b/gdbstub/internals.h index fe82facaeb..dce7c4f66f 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -193,6 +193,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 b7e3829ca0..8f3c8ef449 100644 --- a/gdbstub/softmmu.c +++ b/gdbstub/softmmu.c @@ -101,6 +101,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 1b63a1d197..24eee38136 100644 --- a/gdbstub/syscalls.c +++ b/gdbstub/syscalls.c @@ -102,9 +102,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'; @@ -138,24 +139,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 cc7eeb9afb..a5227e23cf 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -467,3 +467,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); +}