From patchwork Tue Mar 7 21:21:34 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: 659870 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp2608777wrb; Tue, 7 Mar 2023 13:31:41 -0800 (PST) X-Google-Smtp-Source: AK7set9KDv4Cdty9pi+jNFKStN38k5qVxFHr+CVfxThdVrUPfKJvNg6433yGoDO/R0htXXlfSMTy X-Received: by 2002:a05:622a:1106:b0:3b9:bd05:bde1 with SMTP id e6-20020a05622a110600b003b9bd05bde1mr26894783qty.8.1678224701141; Tue, 07 Mar 2023 13:31:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678224701; cv=none; d=google.com; s=arc-20160816; b=hEa/m1NuK8NHhG4ZsKT8UTm64lUlVaabl+EaG9z+5cIKWux4xDGE8kry/uf1/9KoNt KhYh0C5IePqc6b02kxJwYXMxsuE/ze/TRz5WUCQT9pzhcX+STIV+s6MYVGgdtZu9REdk POOnk+VmozSkRAkuyLCkfa0sdHn8409jV7Eg+9jecidXVy3NYsyJ94mce4piqcDRlWwp YrFXkwN+QHJlnSoHipT6TGy7MuL0AZ218RD4GjFzRLu1JvGXJKkCZA6TeJfrujf0/utq CzZj2NmaFS6WE6VIDj7Q2r36pwqj4EnMvegEVo0LFH7kSsSAU6WGvd8vthhQU9R+QcT7 nIAg== 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=LZeCHk68iWaLLkMw4vDpg7elkprCEF+0ZWj+B5JRkJo=; b=vNJoLj91BlqSHkvNNECNPFfREmPer1JslrvQgiVkOjROWweqr5e6NoeIkne1PlWPnL MeESmpym/2XuDX7aLJN1C+k9kRtzB8I/4oV2g8f38eaQ1Xhdgni/v4dNBM6UU3wJ1WFM UwnwUzc/yHuhb6gOq5OUH2SDmLOFzHRdj2+7pxTkIJmAmhlqLjAWcWsLRL0naiqZhSl4 3KpYVUU9sDr6Qhl8QhbbUbj1Ge3t9400sUfBaJQPNNelblXJ2ziPIOz+VnT8I7jz2vM8 CVCsVikMUXg3ID+RKug7/YqRlv92bx+133ZoXdbxenOU7bo8wVm7E6h3jk5hCKU4YjOs KFjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kGCWJAap; 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 7-20020ac85747000000b003b868faafb1si10502607qtx.44.2023.03.07.13.31.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Mar 2023 13:31:41 -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=kGCWJAap; 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 1pZesD-0004k8-Kg; Tue, 07 Mar 2023 16:29:29 -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 1pZesB-0004im-Uf for qemu-devel@nongnu.org; Tue, 07 Mar 2023 16:29:27 -0500 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZes8-0000vs-OQ for qemu-devel@nongnu.org; Tue, 07 Mar 2023 16:29:27 -0500 Received: by mail-wr1-x42d.google.com with SMTP id j2so13507153wrh.9 for ; Tue, 07 Mar 2023 13:29:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678224563; 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=LZeCHk68iWaLLkMw4vDpg7elkprCEF+0ZWj+B5JRkJo=; b=kGCWJAapuCGA5FxAfCq1o0K4gq+Q2VmR32uprwF8uota1mHg8GtGr6L7xP1zlLVkVS WXn4J1tdjXWTNqwCNsQhVMh0JS83R0xNE3iLFeFAvdxG1kCDo3tAMg3Pkgg9jmpoIVWp ppz1hx69/gPrw8cegktXxkCV30EI0KhsQtyoDJannXB3uKLPhkbpHD0b1gxPY/uGuPiF WJeA9GEez8p/0R0gbpQ+DGrZnc4dMqO4I8sxG9yie3MK+ckYEQe4TuSXaJ0X9G95DL9O yF5fFX0fBSCN+7WJV1cpadUaqPHLLTqajANliLPohxegWLPN2G/3GOdKdt6IdgGrlQCF OP1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678224563; 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=LZeCHk68iWaLLkMw4vDpg7elkprCEF+0ZWj+B5JRkJo=; b=tS5Vn1oJ1X7aO/RfwvWtILxVU9ouD/5YzVj3Q/iK9O7+te0upXeDhhcgYdldieWWZE 57xs5uUKBHHN99SWweeIXLSWdDNLYZn/27Zze0bUIgyu/pYDNKvH/masOIppUTLGS6n0 GnVrNpXwrV0jMJU/V6PoUubdc+97f50mi5ccEEXxOzkm+c5bqXJt/hz/4EzjKyg9ckDw Q3ZGjbs7VEMHuCv3kME8xwY3VWGesyNbrB98p9HQy4h3mrQ73EvxjYtIyFw9ph7dfc1v jJmVqFL/rzVLBHWBXlf8CSh8BpwxFJeQlHEES8eD4hmq5XX55Xt39ZtVTzNnuXVty5GM a5Pg== X-Gm-Message-State: AO0yUKXauy3ElwuvQj25ZOKW0JehlatiB1/klnzkIN5VBw+sZAphaaEc QePWipRjhNRWkx5SEBNK2VrX6w== X-Received: by 2002:a5d:4006:0:b0:2c7:1c36:3c67 with SMTP id n6-20020a5d4006000000b002c71c363c67mr9765058wrp.23.1678224563215; Tue, 07 Mar 2023 13:29:23 -0800 (PST) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id e15-20020a5d500f000000b002c561805a4csm13562033wrt.45.2023.03.07.13.29.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 13:29:21 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id EAAF71FFD1; Tue, 7 Mar 2023 21:21:42 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= Subject: [PULL 25/30] gdbstub: split out softmmu/user specifics for syscall handling Date: Tue, 7 Mar 2023 21:21:34 +0000 Message-Id: <20230307212139.883112-26-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307212139.883112-1-alex.bennee@linaro.org> References: <20230307212139.883112-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42d.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=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+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 Reviewed-by: Richard Henderson Message-Id: <20230302190846.2593720-26-alex.bennee@linaro.org> Message-Id: <20230303025805.625589-26-richard.henderson@linaro.org> diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 8db61f7fb4..94ddff4495 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -195,6 +195,9 @@ bool gdb_handled_syscall(void); void gdb_disable_syscalls(void); void gdb_syscall_reset(void); +/* user/softmmu specific syscall handling */ +void gdb_syscall_handling(const char *syscall_packet); + /* * 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..22ecd09d04 100644 --- a/gdbstub/softmmu.c +++ b/gdbstub/softmmu.c @@ -103,6 +103,20 @@ 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_syscall_handling(const char *syscall_packet) +{ + vm_stop(RUN_STATE_DEBUG); + 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 46537938d5..6189940005 100644 --- a/gdbstub/syscalls.c +++ b/gdbstub/syscalls.c @@ -105,9 +105,7 @@ 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 + p = &gdbserver_syscall_state.syscall_buf[0]; p_end = &gdbserver_syscall_state.syscall_buf[sizeof(gdbserver_syscall_state.syscall_buf)]; *(p++) = 'F'; @@ -142,27 +140,8 @@ 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 + + gdb_syscall_handling(gdbserver_syscall_state.syscall_buf); } void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...) diff --git a/gdbstub/user.c b/gdbstub/user.c index 3da410e221..80488b6bb9 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -472,3 +472,17 @@ 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_syscall_handling(const char *syscall_packet) +{ + gdb_put_packet(syscall_packet); + gdb_handlesig(gdbserver_state.c_cpu, 0); +}