From patchwork Wed Mar 6 14:40:20 2024 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: 778301 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:47:b0:33e:474f:8c56 with SMTP id k7csp325113wrx; Wed, 6 Mar 2024 06:42:23 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWqgv6uuYlBo5T+L3I/QNamTx5hqkuqzhQM1oTACx1EfzUaMNNbsKjdrRiTvbHk6LhpKV22YCGlmDScJKezjvvN X-Google-Smtp-Source: AGHT+IHdwSIppXFVUddVH6/MtarV4SEgk6a58IkxAREsXbXwJmxaJDNppAkE/ZQfCDxxyna4J0Uu X-Received: by 2002:a05:6214:284:b0:690:9a03:83b9 with SMTP id l4-20020a056214028400b006909a0383b9mr838829qvv.43.1709736142727; Wed, 06 Mar 2024 06:42:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709736142; cv=none; d=google.com; s=arc-20160816; b=fEsTEvg6shUbCvFzBK3R1ckToM6ch0JxHg8zDR/gHWysEZz4beZt3e+LwltFvZ8JYN iKX+l94pxIL7SozQVbcvce6vllbY4IKtYZlCNIb70zIkI6dzZImlsxfuB+X4g/gjg4TB r4BXP0/Khp39RQPa64v83TQCmVY64G+bueduwKArPnJu30/VrfcETVILEc1LH0UaeszE zYrmfc4FN3FzOUM9ZHOMTNZOH4/a7hQrZ1mU60bRXIibHef9TXN7jALEv6fZKaSA5Ns8 mSB2UrsWZfdrA18Qrq5irMy06WG3J0+LMiyd00m4W8cCtaHi3eoQsr7s8O7CP5Buh541 KbGg== 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=TfLkzlar7jFNAHdEcKzQrpi4P+XZLYByWr1iR6oEsZM=; fh=zThSDgYGIOVG8z7TLY6kj0qgqwLmcvT95XZqu917hRs=; b=wDhXRQ30Z4cqW8kH6cDIWXTcFkyEYlE8U5wQ6BRc3ozEATVUdcvtV8XsIW2vfmfEc3 8RHtnWaEFzw/ElNrRJHM6+/QsXXALVtstnJu1oLrE4lPCf3FMix6X6/PKiU/5kZ/1JFq xKtqFrtWBVRdF7Rj/9iDRJg6FFPtX07vjEU5+DsFb91dRFlAX6TtXRIHn+1haAIh1byR 6QgBTtm8WbE4j3ASZtfNTsr2LMlj3UOiGLr6R8ertPmQHQsJjqKI9De3JTCgm66Enmtn 2gDbJJnw0DoWUkFi/Z2zJWDJFquB/lpJTwNY46S/a9WvuV/Kur63g/U0EFK/q0rhyopL s5gA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nXCXTuQB; 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 q14-20020a056214194e00b006903ca2ae9fsi14572455qvk.273.2024.03.06.06.42.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Mar 2024 06:42:22 -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=nXCXTuQB; 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 1rhsS7-0007c0-Ef; Wed, 06 Mar 2024 09:41:03 -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 1rhsS4-0007Po-2N for qemu-devel@nongnu.org; Wed, 06 Mar 2024 09:41:00 -0500 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhsRx-0001U1-9C for qemu-devel@nongnu.org; Wed, 06 Mar 2024 09:40:59 -0500 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-412fe981ef1so2084735e9.1 for ; Wed, 06 Mar 2024 06:40:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709736049; x=1710340849; darn=nongnu.org; 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=TfLkzlar7jFNAHdEcKzQrpi4P+XZLYByWr1iR6oEsZM=; b=nXCXTuQBXiNCzY5ypn5ei1gd47hbyLj0+HmiziBDqcZTRY86Oj/OKn62ON4fr2Z5a9 bgZGT+OjhclWsdEpHWoMAtUoT3YoX383q6xzm1bZiPkSdPxqfQdYnzm7ZW+IfmANMce8 Bi4dZFIiY5Rk5nd93m9/3JIEKpMsDo0LHMg4bqE3QzYplL35KouHt2o2ew2ReHssq6kY Kc1JZyGWE/V6BitRXrBCH7axMdaomvmo14s7xkwgJGb1HfPNopB1Ex1KzsRd+M2qiXxj PLMtEELg1PGtdNKbtKrBFZNoOmoy1vm497iylxq9Umxh3xSdagw3zYqFOnizzdLRcs8P NaAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709736049; x=1710340849; 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=TfLkzlar7jFNAHdEcKzQrpi4P+XZLYByWr1iR6oEsZM=; b=hrE32IyVaJRkSSgFnr227aNsOLz8bsTMy0lvEy3ZTCTaROaXaySYEuOFSq53XpF6jD AM9ofL0Tq/uq4KvLbJXFdTghnzBqtRAxb+GdlRW7PHLUmsmideXOF64iP+zhXvLyy1Na YzigakzeBADBTGqtLeYa579RzTrERkf/+0R3HlPxIZwCBboMZbvgiVpIIPFZ0kjY5fE+ znxPjguTVUPEXZNXb+rVLruUMSGoEBSiBM/hBbG39dywp0pkssyD07cqpdQ3MtxV0s2b ECa6YndVa6B8qI51bVxMdVV2HqGlnpi3Zzr111mqfaJf7r9X/3Bo9i+yq9V+m5MTtq44 QYWA== X-Gm-Message-State: AOJu0YyERXNrRneEzlFIA0psKZdnlrPwATdfX+INOvL82KqKBRBUMo8z UH/zqcsizkFyF/ek04xaWLowBV0r1zz5fPaz9/PevYTazPaG5fn502TAa9sIx4o= X-Received: by 2002:a05:600c:3589:b0:412:e992:6c32 with SMTP id p9-20020a05600c358900b00412e9926c32mr5486655wmq.11.1709736049525; Wed, 06 Mar 2024 06:40:49 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a14-20020a05600c348e00b00412f74d25b6sm1772554wmq.39.2024.03.06.06.40.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 06:40:45 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 639525F9CB; Wed, 6 Mar 2024 14:40:42 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9?= =?utf-8?q?e?= , Warner Losh , Kyle Evans , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Laurent Vivier Subject: [PULL 08/29] gdbstub: Call gdbserver_fork() both in parent and in child Date: Wed, 6 Mar 2024 14:40:20 +0000 Message-Id: <20240306144041.3787188-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240306144041.3787188-1-alex.bennee@linaro.org> References: <20240306144041.3787188-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32c.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, T_SCC_BODY_TEXT_LINE=-0.01 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 From: Ilya Leoshkevich The upcoming follow-fork-mode child support requires post-fork message exchange between the parent and the child. Prepare gdbserver_fork() for this purpose. Rename it to gdbserver_fork_end() to better reflect its purpose. Reviewed-by: Richard Henderson Signed-off-by: Ilya Leoshkevich Message-Id: <20240219141628.246823-8-iii@linux.ibm.com> Signed-off-by: Alex Bennée Message-Id: <20240305121005.3528075-9-alex.bennee@linaro.org> diff --git a/include/gdbstub/user.h b/include/gdbstub/user.h index 3f9f45946e0..4c4e5c4c582 100644 --- a/include/gdbstub/user.h +++ b/include/gdbstub/user.h @@ -51,10 +51,11 @@ void gdb_signalled(CPUArchState *as, int sig); void gdbserver_fork_start(void); /** - * gdbserver_fork() - disable gdb stub for child processes. + * gdbserver_fork_end() - inform gdb of the completed fork() * @cs: CPU + * @pid: 0 if in child process, -1 if fork failed, child process pid otherwise */ -void gdbserver_fork(CPUState *cs, pid_t pid); +void gdbserver_fork_end(CPUState *cs, pid_t pid); /** * gdb_syscall_entry() - inform gdb of syscall entry and yield control to it diff --git a/bsd-user/main.c b/bsd-user/main.c index 0dbd1cf8801..3dc285e5b74 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -138,10 +138,11 @@ void fork_end(pid_t pid) */ qemu_init_cpu_list(); get_task_state(thread_cpu)->ts_tid = qemu_get_thread_id(); - gdbserver_fork(thread_cpu, pid); + gdbserver_fork_end(thread_cpu, pid); } else { mmap_fork_end(child); cpu_list_unlock(); + gdbserver_fork_end(thread_cpu, pid); end_exclusive(); } } diff --git a/gdbstub/user.c b/gdbstub/user.c index c61e1a0d1f6..866a25f9c06 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -374,10 +374,9 @@ static void disable_gdbstub(CPUState *thread_cpu) tb_flush(thread_cpu); } -/* Disable gdb stub for child processes. */ -void gdbserver_fork(CPUState *cpu, pid_t pid) +void gdbserver_fork_end(CPUState *cpu, pid_t pid) { - if (!gdbserver_state.init || gdbserver_user_state.fd < 0) { + if (pid != 0 || !gdbserver_state.init || gdbserver_user_state.fd < 0) { return; } disable_gdbstub(cpu); diff --git a/linux-user/main.c b/linux-user/main.c index 70314e0ab6a..41caa77cb52 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -165,10 +165,10 @@ void fork_end(pid_t pid) } qemu_init_cpu_list(); get_task_state(thread_cpu)->ts_tid = qemu_get_thread_id(); - gdbserver_fork(thread_cpu, pid); } else { cpu_list_unlock(); } + gdbserver_fork_end(thread_cpu, pid); /* * qemu_init_cpu_list() reinitialized the child exclusive state, but we * also need to keep current_cpu consistent, so call end_exclusive() for