From patchwork Wed Mar 6 14:40:18 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: 778307 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:47:b0:33e:474f:8c56 with SMTP id k7csp325754wrx; Wed, 6 Mar 2024 06:44:01 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUYWJ3ZwcxxXCQnq60zYYnLvdU7P9UUxlT3nyNp9sEC4WUP6UeXDIHBY+opxUgLJk7AzjIqkMSN8mihEBsrG1OH X-Google-Smtp-Source: AGHT+IF7QpPvn0udbpJDn5LWmtK/HLizoDrIs/ZxE18Mnb/5CnmweeabtzZs+Ojrjp0Cv1kOZ5+C X-Received: by 2002:ac8:5701:0:b0:42e:e644:6a1b with SMTP id 1-20020ac85701000000b0042ee6446a1bmr5511809qtw.1.1709736241089; Wed, 06 Mar 2024 06:44:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709736241; cv=none; d=google.com; s=arc-20160816; b=s6kSOHEIFlBIm8UB0o8jiPYoQ9dDLHbtJhmZQUicCtec5yyuQrlAdnnkaOWA7k2pLQ wxeiCHsOZoKzDaOYWuQRcbICrkXg5gMaj4E92lyCiukxnl4KzdVu0bN+lTbyMdi5GLcx SioOIvnn1zqnloNxMfDwQUMlWoFUP5Gcr7hjQbUjAzA/25iifH3AICVyhrb54nM8trsg rNerqu5KjoJneDGmPHDOuZ0iVapal6ttcZbdoyM68QEMBF1YW6N4A2my43NRgkdC7vNZ fej3FjGjMAddx+EmR5isw9Q1yiFOfRd+z2OEHsf9x/Tvv5OaqROLHKiE0rf8b5hYUMZx 1v+g== 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=Y0njWMdZJbPD5cZgXS+g7eH7Y9rT90hV9Vq0dFBAOsE=; fh=7qG5Fm/AiLdgV0did8CUgQs47rrxg7vHsU27wvP0+A0=; b=H3kcWczUO0Qbjv1AXXADuduFlWecftDYIQvXSXtnEGAKNqOk3mGYcy/1x/sO3sJEwl ognf9MjcE1zUMTIFjITwBWBhPKu+oNEXPiNVQAkq41RMSYfgGQ9rG3m0mOi5p07ujjg3 HRpLviLiGLSUL6FFM/tRDP+KHKTxHPQCY7QXedoIFy25ggurGJ+ruVfkFw1lcGeQED9w atuMUHeUjsZREqkfubJqoFL1ObJNdgCfZMCu1nYLUp0HjJSW7W1imxKFn2TkL9pXLIwU sHXJG3aGJQhfWv1ObY76TTR9avCN+lNWsD4XbiyoQKkkztfyD2Tgvw9dpJtUDsf5K7F6 48bA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FAOjv5bm; 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 h18-20020ac85e12000000b0042ef107571csi1244932qtx.638.2024.03.06.06.44.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Mar 2024 06:44:01 -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=FAOjv5bm; 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 1rhsS4-0007QO-Sx; Wed, 06 Mar 2024 09:41:00 -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 1rhsS1-0007IK-Qq for qemu-devel@nongnu.org; Wed, 06 Mar 2024 09:40:57 -0500 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhsRx-0001TZ-9B for qemu-devel@nongnu.org; Wed, 06 Mar 2024 09:40:57 -0500 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-412f5e905e2so5481805e9.3 for ; Wed, 06 Mar 2024 06:40:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709736045; x=1710340845; 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=Y0njWMdZJbPD5cZgXS+g7eH7Y9rT90hV9Vq0dFBAOsE=; b=FAOjv5bmqnLfHxjoJmra29Mo4KZa+DM5csDN0yPWUenYhLAFwALjZwITdgPpgaR8TP WMBAY1Wc+qq7lCr3BnehTypkAUBTpuWjw0vicD+SKKSS1Fov4XwG4kuZoov0kcwjFxzV JwsZkVXcz9pdNNW3/dXJGVF6yXkDLUtXrZi0LBFadr8BaaQyOaoqJx4Ns3DSpcBd+lsX uPZys1HsNu00FGFn+kdL364MSr4eRCmTjFXtoWSTVt3yGwE1PsU+mBEoV0j6Nr5omuqY d3cLrFreUbbF/xh+pLvgGAgQ2Z/0jRTjPanfnge2VjU2h27a23sYPq9a4GGoqdu108cB UcUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709736045; x=1710340845; 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=Y0njWMdZJbPD5cZgXS+g7eH7Y9rT90hV9Vq0dFBAOsE=; b=g6IhseXmBw935NskSp9TSrvLYb3XGe3Z6DbKiKUp4NclR/l7zZ4hBhX3R2wRaFO0B0 L+tsO8tFPbpD6TZurvhZsYPtwZvC+MfqJFntWO+PWHUV48IEgNweCKZO45IDnibZ+LG6 xc3kPgBP4N5UM8eBtgZdB06yzRT3ukC7dizk2KPurlP9GF/Cxk+anBtT/1Jg913bI0uE j+uSl0E6O60W+f5MR5w6ZsneYV0PABPgwrcYgiRFQ/sbM9Ov4TlqP1v47D2Eyy8aRGDH 4Ft932Xkm2Z+UtM8lS3yIax2x3XBHPBzo9zEfEfg2ErwEtOtTDd2sjPzeLGo3qbApXJG 2BHQ== X-Gm-Message-State: AOJu0YxSexefMc9FYc/YYID+CDTBfdUiLhAdwW4pOyZjHz7dM2mMXMT9 SkptTZDdGfU6X0dB3mqdBjNWZbzTjzoehjIr7umM+k4IZQQ1uB4BGFrZjpvG+ZU= X-Received: by 2002:a05:600c:a002:b0:412:e339:14d9 with SMTP id jg2-20020a05600ca00200b00412e33914d9mr6221735wmb.0.1709736045329; Wed, 06 Mar 2024 06:40:45 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id bq26-20020a5d5a1a000000b0033e2777f313sm12942842wrb.72.2024.03.06.06.40.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 06:40:43 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 373E25F958; 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 , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , Warner Losh , Kyle Evans , Laurent Vivier Subject: [PULL 06/29] {linux,bsd}-user: Pass pid to fork_end() Date: Wed, 6 Mar 2024 14:40:18 +0000 Message-Id: <20240306144041.3787188-7-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::336; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x336.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 knowing the child pid. Pass it down. Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson Signed-off-by: Ilya Leoshkevich Message-Id: <20240219141628.246823-6-iii@linux.ibm.com> Signed-off-by: Alex Bennée Message-Id: <20240305121005.3528075-7-alex.bennee@linaro.org> diff --git a/bsd-user/freebsd/os-proc.h b/bsd-user/freebsd/os-proc.h index d6418780344..3003c8cb637 100644 --- a/bsd-user/freebsd/os-proc.h +++ b/bsd-user/freebsd/os-proc.h @@ -208,7 +208,7 @@ static inline abi_long do_freebsd_fork(void *cpu_env) */ set_second_rval(cpu_env, child_flag); - fork_end(child_flag); + fork_end(ret); return ret; } @@ -252,7 +252,7 @@ static inline abi_long do_freebsd_rfork(void *cpu_env, abi_long flags) * value: 0 for parent process, 1 for child process. */ set_second_rval(cpu_env, child_flag); - fork_end(child_flag); + fork_end(ret); return ret; @@ -285,7 +285,7 @@ static inline abi_long do_freebsd_pdfork(void *cpu_env, abi_ulong target_fdp, * value: 0 for parent process, 1 for child process. */ set_second_rval(cpu_env, child_flag); - fork_end(child_flag); + fork_end(ret); return ret; } diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 4adb75d19ff..1b0a591d2d2 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -192,7 +192,7 @@ void cpu_loop(CPUArchState *env); char *target_strerror(int err); int get_osversion(void); void fork_start(void); -void fork_end(int child); +void fork_end(pid_t pid); #include "qemu/log.h" diff --git a/linux-user/user-internals.h b/linux-user/user-internals.h index c63ef45fc78..ce11d9e21c1 100644 --- a/linux-user/user-internals.h +++ b/linux-user/user-internals.h @@ -71,7 +71,7 @@ const char *target_strerror(int err); int get_osversion(void); void init_qemu_uname_release(void); void fork_start(void); -void fork_end(int child); +void fork_end(pid_t pid); /** * probe_guest_base: diff --git a/bsd-user/main.c b/bsd-user/main.c index 517c6b3ec2f..fca9b302043 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -116,8 +116,10 @@ void fork_start(void) gdbserver_fork_start(); } -void fork_end(int child) +void fork_end(pid_t pid) { + bool child = pid == 0; + if (child) { CPUState *cpu, *next_cpu; /* diff --git a/linux-user/main.c b/linux-user/main.c index 755c566d6d2..cab95f5b0aa 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -148,8 +148,10 @@ void fork_start(void) gdbserver_fork_start(); } -void fork_end(int child) +void fork_end(pid_t pid) { + bool child = pid == 0; + qemu_plugin_user_postfork(child); mmap_fork_end(child); if (child) { diff --git a/linux-user/syscall.c b/linux-user/syscall.c index c233d4eb30a..7f30defcb13 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6669,7 +6669,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, if (ret == 0) { /* Child Process. */ cpu_clone_regs_child(env, newsp, flags); - fork_end(1); + fork_end(ret); /* There is a race condition here. The parent process could theoretically read the TID in the child process before the child tid is set. This would require using either ptrace @@ -6700,8 +6700,8 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, } #endif put_user_u32(pid_fd, parent_tidptr); - } - fork_end(0); + } + fork_end(ret); } g_assert(!cpu_in_exclusive_context(cpu)); }