From nobody Thu Sep 19 01:12:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1721758394; cv=none; d=zohomail.com; s=zohoarc; b=CnDHuf/Lzb/pUDNVmdudYzczt/ZLyz4QULIvVNeEmGK38px+8tQ5WZYvMtWZQE0nvLncl7eVKsQYkjaCJMOUdJ2DVDcIoNIKTCAwIjeEi9bOJkmuaEOCcc+g4ifV9TnsShkMHmbMKlM5YbPoXFV2mcTs9VEL2nLyjzzYulY7c+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721758394; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Fc1iffmEOa89zbsiVdbsLtEsb0Kc5g9RfeOgTm7uMho=; b=NvfJsT0JNSHp1wRcP8cQr3WBCECGjihX17mwsnMn8ZN2ZYOUbViPh0IHc560f89l4XNhd2CXugE9xhX4Ui89P/lkPmVVnsOp5xpYd4NIMcMHfsn0mlAB/Eh7kC9b0kCF6JbtxbDDbHGvuiHjMztaTGLQwEvCk594S+4Gm0y7EPc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1721758394007146.77945852138555; Tue, 23 Jul 2024 11:13:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sWJxS-0002ZU-H1; Tue, 23 Jul 2024 14:09:54 -0400 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 1sWJws-0001Bt-Mk for qemu-devel@nongnu.org; Tue, 23 Jul 2024 14:09:19 -0400 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sWJwo-0001DQ-Lj for qemu-devel@nongnu.org; Tue, 23 Jul 2024 14:09:18 -0400 Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-398039f8b7bso20029445ab.3 for ; Tue, 23 Jul 2024 11:09:09 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-397f7a2827csm33361775ab.53.2024.07.23.11.09.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 11:09:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1721758148; x=1722362948; 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=Fc1iffmEOa89zbsiVdbsLtEsb0Kc5g9RfeOgTm7uMho=; b=TlbP/ejfJrtjHXmWuqqRF8Z3//TAyHUPtkc8fQt3gZLdiBGOBTkIY+43oJ1QlwoeZk kC+4iRyFziKuRcdkRqQATXZaNNQW+cU0zTWTt9tn+K8p0xEdCN+ZoG7sB2tiIFZnzb3e y7QbXMzYBdKWRn9Uiq9tpv/yyoYbq1cwqW5phOwC9HfIcVWsxetepD2gBj3SGnNEwM0Z OQTA2n7PDLz2Zjmg3yK2rxURrpj9lrYYQrJs4VmIR+dqcUJ07Qs1dSG/EhRwfacsGcGu lrnmgOXY9FirPgWKAWw1pe9Ta1rtxWjsU2DmBkAFjvZee1n/PJlIT9ue1lE2scgIHcKW wOzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721758148; x=1722362948; 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=Fc1iffmEOa89zbsiVdbsLtEsb0Kc5g9RfeOgTm7uMho=; b=vaYKzqKN+powyxpnlX3fmRekZpXxVDO9qo+5K80wLXnw7hTpxAQLd3ig4KTS333b16 qk0f5KX+KdlSfFe/tVpj/laLfHZjj6pNsbsnWQR+ntpM5m1CpH+tq1XOGjKGp4MvFkeh ub6EZ0grbq1aHkgpJPI0q8GpA0cUB7AMNVV1nCZ902MTqvniMEdrPPIe8QlIkzSxRpkJ VkrG2CQ9DXDe5whjqx9XGlxGUEgcjzebT9PnYyAZPacm58n8n0IMcyj5jjyrhjVwzg4B V+zkLHvj9FPf7JMLC1eNBqMO7tGhTN8P5N8EQ6fF0ib9yqyZPbaflzLO8fgfAZOBsnUo fSuQ== X-Gm-Message-State: AOJu0Yz+cne0fi1ZQ/I74uxDo7iSDb/yWzjILNNdzQhcZyLxsEk3m5NC PwhOL0TvneZOD/QXbtsDIZxK/pw48TZ7IISN4k6DCvtsc5RX2xJRC3Vu+zn6gs33tiikuS5/sGQ oWBY= X-Google-Smtp-Source: AGHT+IH44/gLNSHqUwjcKFYqaXbfK+JEdA/jTWdHKHxs46AFWqUvx7YIuG4KGvG0Yrb5tGfK4UzieQ== X-Received: by 2002:a05:6e02:1aa3:b0:378:5d14:f426 with SMTP id e9e14a558f8ab-3993ff5b8d8mr153514485ab.1.1721758148369; Tue, 23 Jul 2024 11:09:08 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Warner Losh , Peter Maydell , Kyle Evans , qemu-arm@nongnu.org, Jessica Clarke , Richard Henderson Subject: [PULL 11/14] bsd-user: Sync fork_start/fork_end with linux-user Date: Tue, 23 Jul 2024 12:07:22 -0600 Message-ID: <20240723180725.99114-12-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240723180725.99114-1-imp@bsdimp.com> References: <20240723180725.99114-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::12f; envelope-from=imp@bsdimp.com; helo=mail-il1-x12f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1721758395666116600 Content-Type: text/plain; charset="utf-8" From: Jessica Clarke This reorders some of the calls, deduplicates code between branches and, most importantly, fixes a double end_exclusive call in the parent that will cause exclusive_context_count to go negative. Signed-off-by: Jessica Clarke Pull-Request: https://github.com/qemu-bsd-user/qemu-bsd-user/pull/52 Reviewed-by: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/main.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 82e94a03160..cc980e6f401 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -35,6 +35,7 @@ #include "qemu/path.h" #include "qemu/help_option.h" #include "qemu/module.h" +#include "qemu/plugin.h" #include "exec/exec-all.h" #include "user/guest-base.h" #include "tcg/startup.h" @@ -103,8 +104,9 @@ unsigned long target_sgrowsiz =3D TARGET_SGROWSIZ; /* a= mount to grow stack */ void fork_start(void) { start_exclusive(); - cpu_list_lock(); mmap_fork_start(); + cpu_list_lock(); + qemu_plugin_user_prefork_lock(); gdbserver_fork_start(); } =20 @@ -112,31 +114,31 @@ void fork_end(pid_t pid) { bool child =3D pid =3D=3D 0; =20 + qemu_plugin_user_postfork(child); + mmap_fork_end(child); if (child) { CPUState *cpu, *next_cpu; /* - * Child processes created by fork() only have a single thread. D= iscard - * information about the parent threads. + * Child processes created by fork() only have a single thread. + * Discard information about the parent threads. */ CPU_FOREACH_SAFE(cpu, next_cpu) { if (cpu !=3D thread_cpu) { QTAILQ_REMOVE_RCU(&cpus_queue, cpu, node); } } - mmap_fork_end(child); - /* - * qemu_init_cpu_list() takes care of reinitializing the exclusive - * state, so we don't need to end_exclusive() here. - */ qemu_init_cpu_list(); get_task_state(thread_cpu)->ts_tid =3D qemu_get_thread_id(); - gdbserver_fork_end(thread_cpu, pid); } else { - mmap_fork_end(child); cpu_list_unlock(); - gdbserver_fork_end(thread_cpu, pid); - end_exclusive(); } + 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() f= or + * both child and parent. + */ + end_exclusive(); } =20 void cpu_loop(CPUArchState *env) --=20 2.45.1