From nobody Sun May 19 10:01:17 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696360944; cv=none; d=zohomail.com; s=zohoarc; b=FUj7X75F1n47lEV0Unv3P/Az3x6PlxqgoxyKROfDE183LJ2993Vc5LFe9J4/N7SKVhlVJSV7wl0bwYnefhK+g7p/pghhmLQ4qqPoH/+P4A+fCkUsw24WP8htcPRXZLALFAqtpEN9tSH3aNKr6l/fBfd0cncLN/MMmjNcXrZRnYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696360944; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bQFT1MeaWl1DywCggWsF6gUy0qHwX2/cAPNMuk55ZU0=; b=ULxyScCUyv+91xcf8DpSYM9e6d84I9zicFTejmWbHKQ39HKbvVRuHIsUfZ2g+6U+pEVFWMvVZ4e6mobdxF8WIE381IyciFJtohsSqzpoD6iTz+3qI1zdvmMI9J5pNrQrHj3rl001l3ZLM3MOx64Dpnb8o5YbwV2wflAboAS0uTo= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169636094426764.73880466113837; Tue, 3 Oct 2023 12:22:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkxO-00052p-DP; Tue, 03 Oct 2023 15:21:22 -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 1qnkwy-0004vT-LU for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:58 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004dS-Us for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:56 -0400 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-2773f2e599cso960203a91.1 for ; Tue, 03 Oct 2023 12:20:15 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360814; x=1696965614; 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=bQFT1MeaWl1DywCggWsF6gUy0qHwX2/cAPNMuk55ZU0=; b=pb99Swa/hbwJL/Zia60/yXd+Wn6OIj50niL5WoiCeSJf1//LuW3x5Qt94RapwsnGPz 2TtWcWhgWLPy3FqVV9sbP2YVQdvvfg7115VXvjLKupPSkAeJgaH9vIYgvpwwgRLBCsoS m2mqii+ztsUQVvAUE3Z0GN3Kyl0tejjhIRZHHDPBBFtT0xrYROkvzeqbski8iDOoUnD+ /C1Z9EYgctcMK+QfCvh+tYwi9c2wL3aF74NgGHk/Yh0HbicTOT5VTnx5SvUUirJ34P6E y9hGNrVeCnTGLMcmS1bBmVXUPEEeiqS2Zv9vgDe8d2eb18BSb677z7i2i4NoQDajj/kE SxzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360814; x=1696965614; 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=bQFT1MeaWl1DywCggWsF6gUy0qHwX2/cAPNMuk55ZU0=; b=ft9N1lK8VTgpF9sxzSfw7ct56tr9xgHMfqjlhBLis/Qv6e4H+pfZUkw7/F5DqF8ymz PRE6KMbecfeiG+X1Q5tyJjdJrOHqIb1m9+4CTJ1UEJrvxyZbYVtkFz7lT1zvJAhCeFA5 UOzwySlA+aRKYNHB2e7sx6s582r8nbZvvSNMeVD/ncHG5kb5QaAUhWuWFiq6uq0INk3r dtac750LEDYsUof96uJPB8T771uTyEpyMcBA56vqxdT4ybxzFbNhusroM1xrLlR8Bux5 XL2Zlk5YWs4SBbqIhHe9p0Nz3oSNq2vzEL/uywM3iNzGvsNXZ5bbgAPg7w8ya8Y2tmCk HTfw== X-Gm-Message-State: AOJu0Yykfy3ntCj0/uP5+n/RNQse6tY/CQW1qjyR/fzdV+dWcx2FLudq 4Zx4WeBh7j0jvs8yZsBfxphQnf6Y7FuHd44e1iU= X-Google-Smtp-Source: AGHT+IFUMfPxx5BInY+KcIxcybTMBOTy9MfMuXAtlNbH8QIvP6O5DRz4mTjEFMd5/Fr9iuOKozNiLw== X-Received: by 2002:a17:90b:224d:b0:274:566a:3477 with SMTP id hk13-20020a17090b224d00b00274566a3477mr240985pjb.39.1696360814503; Tue, 03 Oct 2023 12:20:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 1/9] linux-user: Split out die_with_signal Date: Tue, 3 Oct 2023 12:20:04 -0700 Message-Id: <20231003192012.1674888-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696360945529100023 Because we trap so many signals for use by the guest, we have to take extra steps to exit properly. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson Acked-by: Helge Deller --- linux-user/signal.c | 52 ++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index a67ab47d30..b7a2c47837 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -689,13 +689,39 @@ void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong= addr, } =20 /* abort execution with signal */ +static G_NORETURN +void die_with_signal(int host_sig) +{ + struct sigaction act =3D { + .sa_handler =3D SIG_DFL, + }; + + /* + * The proper exit code for dying from an uncaught signal is -. + * The kernel doesn't allow exit() or _exit() to pass a negative value. + * To get the proper exit code we need to actually die from an uncaught + * signal. Here the default signal handler is installed, we send + * the signal and we wait for it to arrive. + */ + sigfillset(&act.sa_mask); + sigaction(host_sig, &act, NULL); + + kill(getpid(), host_sig); + + /* Make sure the signal isn't masked (reusing the mask inside of act).= */ + sigdelset(&act.sa_mask, host_sig); + sigsuspend(&act.sa_mask); + + /* unreachable */ + abort(); +} + static G_NORETURN void dump_core_and_abort(CPUArchState *env, int target_sig) { CPUState *cpu =3D env_cpu(env); TaskState *ts =3D (TaskState *)cpu->opaque; int host_sig, core_dumped =3D 0; - struct sigaction act; =20 host_sig =3D target_to_host_signal(target_sig); trace_user_dump_core_and_abort(env, target_sig, host_sig); @@ -719,29 +745,7 @@ void dump_core_and_abort(CPUArchState *env, int target= _sig) } =20 preexit_cleanup(env, 128 + target_sig); - - /* The proper exit code for dying from an uncaught signal is - * -. The kernel doesn't allow exit() or _exit() to pass - * a negative value. To get the proper exit code we need to - * actually die from an uncaught signal. Here the default signal - * handler is installed, we send ourself a signal and we wait for - * it to arrive. */ - sigfillset(&act.sa_mask); - act.sa_handler =3D SIG_DFL; - act.sa_flags =3D 0; - sigaction(host_sig, &act, NULL); - - /* For some reason raise(host_sig) doesn't send the signal when - * statically linked on x86-64. */ - kill(getpid(), host_sig); - - /* Make sure the signal isn't masked (just reuse the mask inside - of act) */ - sigdelset(&act.sa_mask, host_sig); - sigsuspend(&act.sa_mask); - - /* unreachable */ - abort(); + die_with_signal(host_sig); } =20 /* queue a signal so that it will be send to the virtual CPU as soon --=20 2.34.1 From nobody Sun May 19 10:01:17 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696360943; cv=none; d=zohomail.com; s=zohoarc; b=b+JhlSz1tTK/otAAa/4cDPsrQqpT9B8vpruTuxqcw9Nf9eAqE95Pn7rTo3LlXS+HfeJL/8MFD6jMM2OOoenLjhoySo7yqGXgMA4atJjOI1oV8vzEPkVWSgAT+NeKyF1Wxy9cAe3r1UZLh7dSkQ/Pk+CrZtPwLIr+bwuNu6u28l4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696360943; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=H1WLp4iET98k15VXyaSQDw2efQeM3lo5zs7sjnpm5FA=; b=nGxvRSdFRpb7m8CraUlZGZdrzXkcTuCXvFaWq/vtg69Epma9NPSpvnILjO4BpwfgmNnPhmFB0fUDFHPeXdXiwNIsUHM/EyrEB8mrv4WM3m/AkFjb6lxvutU41TDh+tafxY+9UwCZQVvYKHEYn0MicvnK/nVhRsCRiU1S6CMY628= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696360943159790.1128790212051; Tue, 3 Oct 2023 12:22:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkxC-0004xs-De; Tue, 03 Oct 2023 15:21:11 -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 1qnkwk-0004r6-Gx for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:42 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004dU-RS for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:42 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1c62d61dc96so9651395ad.0 for ; Tue, 03 Oct 2023 12:20:16 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360815; x=1696965615; 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=H1WLp4iET98k15VXyaSQDw2efQeM3lo5zs7sjnpm5FA=; b=bSvjW6Tvwxksg7jvbD2IvrfMHyKJ/dpjCHxFIbF+MfxncUSjpxlDMlhMNNFVfxKPVE iTrhGQoZj13DCyiss0v7FzkQ2eLDkZMkIHXAni0imbU47bYheit9LbFzlhM5OdkiY1oN 2Cs0wde6D9rfVv7WZr13+8/SUUx8FYlcDb2gZehTsLO+3A3sa7AatyqVP/UXJi8EWIzS guIfJ4W3WanTRnHsaJnxlj6kZ5bcZcXuSLe4tsw46Zlji9XQSvamNY6l0Og+bxaSUxni xaZtfKUT2iKKGiO1R3hGWcS+SZwxcPC5Yq/OnlMa6VHPTU7IZsn7F3PdldFyryY+soWM 11Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360815; x=1696965615; 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=H1WLp4iET98k15VXyaSQDw2efQeM3lo5zs7sjnpm5FA=; b=BUKpo4ske9G/h/c6i60UAiP9TblHTwiX4YEfofY8XUlgIzq3OC6LDoxzDrhoONKMeN z+TWoqV9OT5EV57higVogQVHgsL8ye2+uZRznzirixthk3TYTI9G4NbbmswBMlk3FRqO 7zbtclzqIaDZZOMxS6ufZM9abR5L12Q8tNJJ91NfLGL2VhraGV2hSwj8h8gawq2TJQGc m70AJKJYQv2BaAvjsceMj7hbY9on4UyzrV0y2z05WrDOuhhy/m84DUR4yo7gBdhEU03A asl3UMYHCAjfQ1sxk8E/Fp02wQb0ux2MqXpYse9AU78MfLMH5EqhBLYmIwdtuO70Jtz2 7S+g== X-Gm-Message-State: AOJu0Ywn7sDsFKOLOoV/GtWi6/X4G0GAvfcv/ths1qeeITkXwdUkM0dd dXiwTizmUvXjQHKtpPlKDONfaADPl4rxV7ysGNw= X-Google-Smtp-Source: AGHT+IENiLJkzQBCXJDUnc6zOlESU126TTYR0iWxJzJKMLju25UfN1DOLpBPXt4Y6utRPJ4oaHLnAg== X-Received: by 2002:a17:902:7207:b0:1bd:ca80:6fe6 with SMTP id ba7-20020a170902720700b001bdca806fe6mr470637plb.41.1696360815299; Tue, 03 Oct 2023 12:20:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 2/9] linux-user: Exit not abort in die_with_backtrace Date: Tue, 3 Oct 2023 12:20:05 -0700 Message-Id: <20231003192012.1674888-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696360944885100017 This line is supposed to be unreachable, but if we're going to have it at all, SIGABRT via abort() is subject to the same signal peril that created this function in the first place. We can _exit immediately without peril. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson Acked-by: Helge Deller --- linux-user/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index b7a2c47837..84a56b76cc 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -713,7 +713,7 @@ void die_with_signal(int host_sig) sigsuspend(&act.sa_mask); =20 /* unreachable */ - abort(); + _exit(EXIT_FAILURE); } =20 static G_NORETURN --=20 2.34.1 From nobody Sun May 19 10:01:17 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696360944; cv=none; d=zohomail.com; s=zohoarc; b=mFFNWdHYX4JORsNCTE2rs+yayL1azorrYyjKZuG+ij+pZll9CEHqyWpY4FaeE73pVQIx7c2WjIl8xKL5V7Rp7lsmc2ohY4tz+iLtcjA1VhUyU/KH5DltGzNwsx1zv5Pgc/IRCb3uV3J6aiQI6dQuh0jsp5vqGIuguR8+S7CV0XE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696360944; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OQP2+HZbJmIj9sXXPBVMTwI7vC2S6c38AoM7akl90XU=; b=cE0tLDs2QCpn38rBK/1o3pX4leqqzC41Xku89A1G3SfcOOR6doyjZUULgDOkL8Zerp0JqfgqCt4D+NrEQf1tkqLgcUt/52PH4Ui6dplBJ00epG7DMsORMrgrGGbaKV459RQeR7VppsWVbdt/7DFCqs8YQKdyQaCQbEyc3xOBmh8= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696360944128262.6115888053654; Tue, 3 Oct 2023 12:22:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkwq-0004t3-Je; Tue, 03 Oct 2023 15:20:49 -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 1qnkwk-0004qs-Ju for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:43 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004dh-S8 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:40 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1c0ecb9a075so9979445ad.2 for ; Tue, 03 Oct 2023 12:20:17 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360816; x=1696965616; 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=OQP2+HZbJmIj9sXXPBVMTwI7vC2S6c38AoM7akl90XU=; b=lzog5Va2VVr3xhuo199ZJGARfS2H5rUovzlLFwuosMlYubSR8qyo1CvM7RP1E6BKZK dk/EDDyoJOlX5NfVFFZTemeajSFPg7bchO8JHbOvB0dstxI/owbd56KhGmiE19m2zab+ CVvp+uRVoaudipLppRMAs4u81EXYy1/8wjchnuwF2G1Vh5y/L6Xq6QXxJ4XBM2GB+5uW CQg70nvbWNV1idmAChMz3NYwVYW2S3Ny2xzfUqmQk3lT830kHwhkruM/hDK0tS0G9Q8Z Tpig7Z2mhm1ahJBRDnFp8eBjWRR6gKiBJpTiSg3y/ylJH60owaoROXy6dFDyNV6ALf5N FhZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360816; x=1696965616; 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=OQP2+HZbJmIj9sXXPBVMTwI7vC2S6c38AoM7akl90XU=; b=qXwucJNCRGlfUbZPuAI/ToplFngGMKAMPAvE6IowHo5hovvo6SowHLRm8rgowFjvJc qOPZ5BzpsJSThCan3gfYreFdbKcIzIBW5Xmb1hDv0S7J3zgYberjIc07i2oHniAEPPDi VtqxSWKtcGRxOCTCirRcpTK8MWqTwy4hpNPtIBmSJt4m9KCRfv5jNS17dzf8zOSUVZUf ehxJgpRzBajtg+RmLR1fOikBfUbt7Ib7JVTdtS95lb1GbFH8yXMkRN47pJjkn+m+QRie BJ3TvntzTVd9a/fZJK7RmiT7qqQcvJv1DhJGItalvh8pF3vMkD8ISKO7Gtx8l1bvmNvN n74Q== X-Gm-Message-State: AOJu0YzjtyDydC5JF9UlcQS/pbrG8urLOvkWmFijO8KXNnwMtvEZLUNM mbYGhPx2L9p6dOSd1bIA9Pyv9z1OQ7dLtVmdXmg= X-Google-Smtp-Source: AGHT+IEKXCU5jieZpkhL9CvgoX7Sk802ujtP/pCkUp636JdIT5gHloZ5f1yKUkkC2YdCIoGctmuY4g== X-Received: by 2002:a17:902:c946:b0:1c3:e3b1:98df with SMTP id i6-20020a170902c94600b001c3e3b198dfmr488534pla.52.1696360816134; Tue, 03 Oct 2023 12:20:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de Subject: [PATCH v5 3/9] linux-user: Detect and report host crashes Date: Tue, 3 Oct 2023 12:20:06 -0700 Message-Id: <20231003192012.1674888-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> 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: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696360946325100027 Content-Type: text/plain; charset="utf-8" From: Helge Deller If there is an internal program error in the qemu source code which raises SIGSEGV or SIGBUS, we currently assume the signal belongs to the guest. With an artificial error introduced, we will now print QEMU internal SIGSEGV {code=3DMAPERR, addr=3D(nil)} Signed-off-by: Helge Deller Message-Id: <20230812164314.352131-1-deller@gmx.de> [rth: Use in_code_gen_buffer and die_with_signal; drop backtrace] Signed-off-by: Richard Henderson Acked-by: Helge Deller --- linux-user/signal.c | 69 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 84a56b76cc..9fadc51347 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -32,6 +32,7 @@ #include "signal-common.h" #include "host-signal.h" #include "user/safe-syscall.h" +#include "tcg/tcg.h" =20 static struct target_sigaction sigact_table[TARGET_NSIG]; =20 @@ -779,6 +780,50 @@ static inline void rewind_if_in_safe_syscall(void *puc) } } =20 +static G_NORETURN +void die_from_signal(siginfo_t *info) +{ + char sigbuf[4], codebuf[12]; + const char *sig, *code =3D NULL; + + switch (info->si_signo) { + case SIGSEGV: + sig =3D "SEGV"; + switch (info->si_code) { + case SEGV_MAPERR: + code =3D "MAPERR"; + break; + case SEGV_ACCERR: + code =3D "ACCERR"; + break; + } + break; + case SIGBUS: + sig =3D "BUS"; + switch (info->si_code) { + case BUS_ADRALN: + code =3D "ADRALN"; + break; + case BUS_ADRERR: + code =3D "ADRERR"; + break; + } + break; + default: + snprintf(sigbuf, sizeof(sigbuf), "%d", info->si_signo); + sig =3D sigbuf; + break; + } + if (code =3D=3D NULL) { + snprintf(codebuf, sizeof(sigbuf), "%d", info->si_code); + code =3D codebuf; + } + + error_report("QEMU internal SIG%s {code=3D%s, addr=3D%p}", + sig, code, info->si_addr); + die_with_signal(info->si_signo); +} + static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) { CPUState *cpu =3D thread_cpu; @@ -814,16 +859,28 @@ static void host_signal_handler(int host_sig, siginfo= _t *info, void *puc) is_write =3D host_signal_write(info, uc); access_type =3D adjust_signal_pc(&pc, is_write); =20 + /* If this was a write to a TB protected page, restart. */ + if (is_write + && host_sig =3D=3D SIGSEGV + && info->si_code =3D=3D SEGV_ACCERR + && h2g_valid(host_addr) + && handle_sigsegv_accerr_write(cpu, sigmask, pc, guest_addr)) { + return; + } + + /* + * If the access was not on behalf of the guest, within the execut= able + * mapping of the generated code buffer, then it is a host bug. + */ + if (access_type !=3D MMU_INST_FETCH + && !in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { + die_from_signal(info); + } + if (host_sig =3D=3D SIGSEGV) { bool maperr =3D true; =20 if (info->si_code =3D=3D SEGV_ACCERR && h2g_valid(host_addr)) { - /* If this was a write to a TB protected page, restart. */ - if (is_write && - handle_sigsegv_accerr_write(cpu, sigmask, pc, guest_ad= dr)) { - return; - } - /* * With reserved_va, the whole address space is PROT_NONE, * which means that we may get ACCERR when we want MAPERR. --=20 2.34.1 From nobody Sun May 19 10:01:17 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696360942; cv=none; d=zohomail.com; s=zohoarc; b=mdFZxs6bQWgjgQNXrbQfU4RWtRKF2jlNbp+lyjGVvLW0df0rBBD+B5/jJx8mhRYUk1UuUSuhhyI/8ZCNUrYBEhCI8DwVHvbr+aWUNYnqTjTODKuIPTIGyifPKaKFhAfduW2Ioo0n6wCAAwdcXBa0QShSFIAdFAJqR/iAaMc8YVw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696360942; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wk7Bln+tqnBhQ7Rx4jjEi5WJUcqRNod/ibptYsj0x9Y=; b=hjGfF6fPxb/zLKp98chZrInrGAdq6gpf56naSGgLP172JJxQkScTwO/i5wErNQt3KkNb46YJwlQ7jI7ct9prYAXrL7PaJfEryDH7bqRkEfvgP72FRw14FQRKemIvnxv/6ZHshxfwDRn4wUh7Za+HW2m6BqFEBjdwxzx89pkrgLU= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696360942217777.2129776606695; Tue, 3 Oct 2023 12:22:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkwZ-0004km-L1; Tue, 03 Oct 2023 15:20:31 -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 1qnkwW-0004iD-VB for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:29 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004dp-S5 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:28 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1c3bd829b86so10636455ad.0 for ; Tue, 03 Oct 2023 12:20:18 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360817; x=1696965617; 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=wk7Bln+tqnBhQ7Rx4jjEi5WJUcqRNod/ibptYsj0x9Y=; b=SfZx7chibSlbVQIex+biKqqAYrZpLoHopZIlIEkXduCAEJFKmjAWKQsRVzL/soHdJD t/ZLHJfoi2PvLQjNaNl/k0Up/KauXIr0mwGtTedMEAsc4WgqGFiOLQ29JgC/Q1JSSFdO dy1UQxiqglIYkZutxwaUFDaecAz456t4PXtWmxzXdIwuHfJhRuwd+nUp48cvpOOdbyck pAFjf+Q9AsTqwnq2z7W++BD2UcVBRHrXpjydh1JhjKar1RjYwfPv7dUaNGv7bNiDgcEN NSJjEBkhgLht++l6iCOoPD0sbBseHWAxPCiXAr+Ux4Btgwu42WUDotMI3oMORjqYXmuJ o1zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360817; x=1696965617; 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=wk7Bln+tqnBhQ7Rx4jjEi5WJUcqRNod/ibptYsj0x9Y=; b=TAA9cV2YIeLnpPIz0RU9Pc4FV37zbqM8USV3l47sByMFetgAYREkk8cfZJSvf4e5jf HcUjWkiydav/6QHjcIbkDIoloHXt5Em2FSQr6BJjyS7DvQngt9Xr0qFIjbOAOEcIoAVW Yyh4rz8ryonyo4GlQYpOmHJaiwgDsySZ4UVRulLU7mwvJSXPwcw4RDoUaJXNcex4OBoT sbnvLwQ0EmYHQDD26qFtqghuv1u46JoGKU/cOZrJVs+8knf2JHZRl/FbsE61ypsZZp7B I8wFI6jSehsjVUXzLGQhiRI2jCdVKp5MF3u8kb/fu1Ows2WuZnDgpbFXAAc5XK4XKuNt GAeg== X-Gm-Message-State: AOJu0YwNhnERBGYmgNJD+YO2ysb0ZXYJ53Sr94xVaibWZKV+FNPK7k7w SNVKTk9dINy+1U9FyQiZauzPnwsxdrJ359fRFYg= X-Google-Smtp-Source: AGHT+IHp3qbunhvt1pl0RgtEoDR18J4AWpuOh0MOfn0fVW/JZLFzhTo9oA/ufowpZy20gyeCzY/KmQ== X-Received: by 2002:a17:902:d489:b0:1c3:cdf5:d891 with SMTP id c9-20020a170902d48900b001c3cdf5d891mr615392plg.46.1696360817040; Tue, 03 Oct 2023 12:20:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de Subject: [PATCH v5 4/9] linux-user: Only register handlers for core_dump_signal by default Date: Tue, 3 Oct 2023 12:20:07 -0700 Message-Id: <20231003192012.1674888-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> 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: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696360943152100001 Content-Type: text/plain; charset="utf-8" The set of fatal signals is really immaterial. If one arrives, and is unhandled, then the qemu process dies and the parent gets the correct signal. It is only for those signals which we would like to perform a guest core dump instead of a host core dump that we need to catch. Signed-off-by: Richard Henderson Acked-by: Helge Deller --- linux-user/signal.c | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 9fadc51347..aab05f8eec 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -488,26 +488,6 @@ void target_to_host_siginfo(siginfo_t *info, const tar= get_siginfo_t *tinfo) info->si_value.sival_ptr =3D (void *)(long)sival_ptr; } =20 -static int fatal_signal (int sig) -{ - switch (sig) { - case TARGET_SIGCHLD: - case TARGET_SIGURG: - case TARGET_SIGWINCH: - /* Ignored by default. */ - return 0; - case TARGET_SIGCONT: - case TARGET_SIGSTOP: - case TARGET_SIGTSTP: - case TARGET_SIGTTIN: - case TARGET_SIGTTOU: - /* Job control signals. */ - return 0; - default: - return 1; - } -} - /* returns 1 if given signal should dump core if not handled */ static int core_dump_signal(int sig) { @@ -602,8 +582,9 @@ void signal_init(void) SIGSEGV and SIGBUS, to detect exceptions. We can not just trap all signals because it affects syscall interrupt behavior. But do trap all default-fatal signals. */ - if (fatal_signal (i)) + if (core_dump_signal(i)) { sigaction(host_sig, &act, NULL); + } } } =20 @@ -997,7 +978,6 @@ int do_sigaction(int sig, const struct target_sigaction= *act, struct target_sigaction *oact, abi_ulong ka_restorer) { struct target_sigaction *k; - struct sigaction act1; int host_sig; int ret =3D 0; =20 @@ -1057,22 +1037,27 @@ int do_sigaction(int sig, const struct target_sigac= tion *act, return 0; } if (host_sig !=3D SIGSEGV && host_sig !=3D SIGBUS) { + struct sigaction act1; + sigfillset(&act1.sa_mask); act1.sa_flags =3D SA_SIGINFO; - if (k->sa_flags & TARGET_SA_RESTART) - act1.sa_flags |=3D SA_RESTART; - /* NOTE: it is important to update the host kernel signal - ignore state to avoid getting unexpected interrupted - syscalls */ if (k->_sa_handler =3D=3D TARGET_SIG_IGN) { + /* + * It is important to update the host kernel signal ignore + * state to avoid getting unexpected interrupted syscalls. + */ act1.sa_sigaction =3D (void *)SIG_IGN; } else if (k->_sa_handler =3D=3D TARGET_SIG_DFL) { - if (fatal_signal (sig)) + if (core_dump_signal(sig)) { act1.sa_sigaction =3D host_signal_handler; - else + } else { act1.sa_sigaction =3D (void *)SIG_DFL; + } } else { act1.sa_sigaction =3D host_signal_handler; + if (k->sa_flags & TARGET_SA_RESTART) { + act1.sa_flags |=3D SA_RESTART; + } } ret =3D sigaction(host_sig, &act1, NULL); } --=20 2.34.1 From nobody Sun May 19 10:01:17 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696360942; cv=none; d=zohomail.com; s=zohoarc; b=Fph8tR5vr67G+fxKwPtWijs+ddqVUH+JBb+j+U439TagRubqP3+5oKqMQJwoNy51TsS/73QH1MA8oxV77JcEcyxCp51qZKgDyq5+lbYeLOl0C5xcadFLcmLCVBm79CrcivZ7cK6m1b6lXlkztah4oQ2glPLhPfg5f3uUBw1Rmd0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696360942; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Z5UDBGcrrmujtcvRVyuE029O9vjXuHtI35qzP2H7Ibo=; b=kei+A2+JLTlkjvJ8ZSk8ZPjei3iFVm2GjkgSAlf6wnOj7/Mx/2KOfsx1NXxPGSZcXdHtqPCG/LriNQbSglmlPIVea3J4sRV4yizttugQveIg6fGeBt9jgTk1uZsS97TAht0KlpITBVG94WJ9Kb1O/c7vVoT2W1xpf/7QyUDVXos= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696360942197581.1859346552593; Tue, 3 Oct 2023 12:22:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkxN-00051q-ED; Tue, 03 Oct 2023 15:21:23 -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 1qnkws-0004ti-4A for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:52 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004dw-SQ for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:49 -0400 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-27777174297so877652a91.3 for ; Tue, 03 Oct 2023 12:20:20 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360818; x=1696965618; 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=Z5UDBGcrrmujtcvRVyuE029O9vjXuHtI35qzP2H7Ibo=; b=SCEY5LqOplL3tFiRC/WQJZuEHzkhqCEIT5/+M5GRhNhSJS3jiJrBFlWXPNoNX+F29L qOmYhb9nxFGKq6bXmrNyqAPL6YvZ2vnRr/odtIzYtcSfpFDt+fRqF1/0QsqjDY7GCEYs 7xCqOeEhmrpJDrfhlyi0yiIJWCXJ3/1iHUESYYjyt0wVa9CmvOq0cydJ+Hq3m9adnGP0 t+ToyjU5MDTaybsRRWpWn+GZOxWRa8aAkGPXHYu9wD7RMqXz9JlzxuohzMk+YE0EqTES +JZtSYrh+KDWFazV2ixo8S250wPTwdHNxvJlYtbfylLtCYv3VNiM1Vl6XvS9XaYmk90J sjig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360818; x=1696965618; 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=Z5UDBGcrrmujtcvRVyuE029O9vjXuHtI35qzP2H7Ibo=; b=C2yr5LmK1mQxOyNMg3aGXovLRtng/wyREg1dXLff8LN/qmu7YK3vuHNpOYLfjHP66d 1L5wwT5Dc/MSS8NmxZ/w2bXQgcBkwv2F5JT/MiWg1fEXKoVz6VkXluZ0ZiptSXrcPZNu 7kPUyBe+8zC0942qjwFU2q56TL9V6jtlzoLNMBlh7bEuWn5GoUCfsiTKD3Z6Ui5Xr3Pb iNvjqj8YyDMoKHGa40F/jitvqyoenvpnpy2EwvKrgJr5mBx0nZR16F0/A8A83P1ka5rK q22VHVTjMk91t+FszKyrdCFDMhpdKtxXH1PsyskYRWE91ggJyN2+5ugSlxVFyEtYxsZZ jdWQ== X-Gm-Message-State: AOJu0YyEBgxkTNpGpkK7cgoKBHCtNyXU7zg6jyv3BUrUX8g/do6Zi3X8 7KfO0MhKIrY8T9VGx4b7122N+3TvAn+oXCVOkbk= X-Google-Smtp-Source: AGHT+IGEMY1n7Fw3LkY86uhtjKMz5MATe9yndGfE2Lh4hNFq/QUy3Yi6LnbUdZSFBk0hFvKIS+/NPw== X-Received: by 2002:a17:90a:4f04:b0:274:77df:50d1 with SMTP id p4-20020a17090a4f0400b0027477df50d1mr295914pjh.21.1696360818159; Tue, 03 Oct 2023 12:20:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de Subject: [PATCH v5 5/9] linux-user: Map unsupported signals to an out-of-bounds value Date: Tue, 3 Oct 2023 12:20:08 -0700 Message-Id: <20231003192012.1674888-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> 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: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696360943693100005 Content-Type: text/plain; charset="utf-8" Do not return a valid signal number in one domain when given an invalid signal number in the other domain. Signed-off-by: Richard Henderson Acked-by: Helge Deller --- linux-user/signal.c | 72 ++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index aab05f8eec..653fd2f9fd 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -44,9 +44,8 @@ abi_ulong default_sigreturn; abi_ulong default_rt_sigreturn; =20 /* - * System includes define _NSIG as SIGRTMAX + 1, - * but qemu (like the kernel) defines TARGET_NSIG as TARGET_SIGRTMAX - * and the first signal is SIGHUP defined as 1 + * System includes define _NSIG as SIGRTMAX + 1, but qemu (like the kernel) + * defines TARGET_NSIG as TARGET_SIGRTMAX and the first signal is 1. * Signal number 0 is reserved for use as kill(pid, 0), to test whether * a process exists without sending it a signal. */ @@ -57,7 +56,6 @@ static uint8_t host_to_target_signal_table[_NSIG] =3D { #define MAKE_SIG_ENTRY(sig) [sig] =3D TARGET_##sig, MAKE_SIGNAL_LIST #undef MAKE_SIG_ENTRY - /* next signals stay the same */ }; =20 static uint8_t target_to_host_signal_table[TARGET_NSIG + 1]; @@ -65,18 +63,24 @@ static uint8_t target_to_host_signal_table[TARGET_NSIG = + 1]; /* valid sig is between 1 and _NSIG - 1 */ int host_to_target_signal(int sig) { - if (sig < 1 || sig >=3D _NSIG) { + if (sig < 1) { return sig; } + if (sig >=3D _NSIG) { + return TARGET_NSIG + 1; + } return host_to_target_signal_table[sig]; } =20 /* valid sig is between 1 and TARGET_NSIG */ int target_to_host_signal(int sig) { - if (sig < 1 || sig > TARGET_NSIG) { + if (sig < 1) { return sig; } + if (sig > TARGET_NSIG) { + return _NSIG; + } return target_to_host_signal_table[sig]; } =20 @@ -507,48 +511,48 @@ static int core_dump_signal(int sig) =20 static void signal_table_init(void) { - int host_sig, target_sig, count; + int hsig, tsig, count; =20 /* * Signals are supported starting from TARGET_SIGRTMIN and going up - * until we run out of host realtime signals. - * glibc at least uses only the lower 2 rt signals and probably - * nobody's using the upper ones. - * it's why SIGRTMIN (34) is generally greater than __SIGRTMIN (32) - * To fix this properly we need to do manual signal delivery multiplex= ed - * over a single host signal. + * until we run out of host realtime signals. Glibc uses the lower 2 + * RT signals and (hopefully) nobody uses the upper ones. + * This is why SIGRTMIN (34) is generally greater than __SIGRTMIN (32). + * To fix this properly we would need to do manual signal delivery + * multiplexed over a single host signal. * Attempts for configure "missing" signals via sigaction will be * silently ignored. */ - for (host_sig =3D SIGRTMIN; host_sig <=3D SIGRTMAX; host_sig++) { - target_sig =3D host_sig - SIGRTMIN + TARGET_SIGRTMIN; - if (target_sig <=3D TARGET_NSIG) { - host_to_target_signal_table[host_sig] =3D target_sig; + for (hsig =3D SIGRTMIN; hsig <=3D SIGRTMAX; hsig++) { + tsig =3D hsig - SIGRTMIN + TARGET_SIGRTMIN; + if (tsig <=3D TARGET_NSIG) { + host_to_target_signal_table[hsig] =3D tsig; } } =20 - /* generate signal conversion tables */ - for (target_sig =3D 1; target_sig <=3D TARGET_NSIG; target_sig++) { - target_to_host_signal_table[target_sig] =3D _NSIG; /* poison */ - } - for (host_sig =3D 1; host_sig < _NSIG; host_sig++) { - if (host_to_target_signal_table[host_sig] =3D=3D 0) { - host_to_target_signal_table[host_sig] =3D host_sig; - } - target_sig =3D host_to_target_signal_table[host_sig]; - if (target_sig <=3D TARGET_NSIG) { - target_to_host_signal_table[target_sig] =3D host_sig; + /* Invert the mapping that has already been assigned. */ + for (hsig =3D 1; hsig < _NSIG; hsig++) { + tsig =3D host_to_target_signal_table[hsig]; + if (tsig) { + assert(target_to_host_signal_table[tsig] =3D=3D 0); + target_to_host_signal_table[tsig] =3D hsig; } } =20 - if (trace_event_get_state_backends(TRACE_SIGNAL_TABLE_INIT)) { - for (target_sig =3D 1, count =3D 0; target_sig <=3D TARGET_NSIG; t= arget_sig++) { - if (target_to_host_signal_table[target_sig] =3D=3D _NSIG) { - count++; - } + /* Map everything else out-of-bounds. */ + for (hsig =3D 1; hsig < _NSIG; hsig++) { + if (host_to_target_signal_table[hsig] =3D=3D 0) { + host_to_target_signal_table[hsig] =3D TARGET_NSIG + 1; } - trace_signal_table_init(count); } + for (count =3D 0, tsig =3D 1; tsig <=3D TARGET_NSIG; tsig++) { + if (target_to_host_signal_table[tsig] =3D=3D 0) { + target_to_host_signal_table[tsig] =3D _NSIG; + count++; + } + } + + trace_signal_table_init(count); } =20 void signal_init(void) --=20 2.34.1 From nobody Sun May 19 10:01:17 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696360967; cv=none; d=zohomail.com; s=zohoarc; b=UmzmbGeE9HFVozDhn38+/dsYQpL9uzjZV0ZdTlKmRCwCOfFOQOCCxUGyUi3nPlVUYfXJl5tEUFSdULBfrGRUBkafqmOT3n+dfhLOtxuG29h2oBL/U2w55xR37kci4a5jmdgL0daDeglE+TPaCXFK1K8bvbX1l0A01qvl0jKKtfA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696360967; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZcBnZHSbuxu1CEXsD4rb1K43nNPKQuPu10A2c8iY0Bc=; b=GvfBO0ure8YgLJBsRnAOWc68dxcpGgHKb7AMdDsqKM4qcoJaNlA+O6AG/7t2KFNxfP2CkeOnxLrlcdn53joLJWbO72uSQgcaAHhAplpCnJo8qpHRH6/it2QvDncvDSnGmwt7Xw7jP6ucydMqBCiEUwivhbd4PFZXXgNvdjmN+4g= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696360967678861.9595544278747; Tue, 3 Oct 2023 12:22:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkxI-0004zp-4H; Tue, 03 Oct 2023 15:21:16 -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 1qnkwk-0004r7-Gx for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:42 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004dy-Rc for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:42 -0400 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-27740ce6c76so870336a91.0 for ; Tue, 03 Oct 2023 12:20:20 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360819; x=1696965619; 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=ZcBnZHSbuxu1CEXsD4rb1K43nNPKQuPu10A2c8iY0Bc=; b=r1aYU5NlP+xZlqrGUDDxtHGyqTfATH5e2Ij5QXBzHgE8iRMsIqb1WPpuVZE6gziJFY sX/qgWlI304bA2ZwqlYyU5sbcc8kb1lGlXfTHLdSvMEh+Oq9hdBaIt2FKHUGYDhFPaga Ny2ExgOk3fC1AS8bvn4mpeMX8Glni+Ak8ocgWLhSe3LoadWF5bHFl6vKP9f8c8aDYlDb DOpa2oIooO4N6PadtuGN/IZ0krmXbx87UC6ezoldaKlAzb7wUWkMGw6Wpizxo+lZVhJR pEY6olW74XG7F+tbInH35yRY2JLTX5FsEQa9OT3yQ1DXOTUEka8J9cMofibMah2pMYv4 n8mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360819; x=1696965619; 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=ZcBnZHSbuxu1CEXsD4rb1K43nNPKQuPu10A2c8iY0Bc=; b=pYMtkqP6Pj9VGiUhqkOhzr5kvF8gFPhSSoBWGmBCwYMMTJ4gI3pZNgrQPNc1u32g/x wdwtrToQE+a7W01XJhaL1xFsyvS/CVj45qLdhC3C7o4Fc9pzTMAOvJI46gI1udtLCn5F TfPkwoOcZdqU2c0issg0DqUH4o1mVXe+38aYqQ7WhbgEGCKORsdNgVjcOnxR+I1Y1b+Y 2N6x43Cb7aug8Am17tCjaQ3rDtqbwfh5rBi3ov9n/qEdI52A+8BEXXgV68MdbWKury3L s/YZS5Ict502c38i+yqzwgDRRGLZoCOhQmTTbSnFUmi9UD80GWg8FjFy8MnjvAPFa1y8 SzDA== X-Gm-Message-State: AOJu0YzqOvJy3pP7F0IYTSK0v0mdRTAVUPcH2CQNcQD/oVKkW0lUuTFS TMcASJsOUo/wB8Vx+Qd+DK5MF5vwtu+svjTiiIY= X-Google-Smtp-Source: AGHT+IFu3uQhXp2Z/aEj1BEH6L1UgC6JN2HUydmAXb/ZyJbKRAX3cbq51nCFz0C4eDlYKRmQl2uEQg== X-Received: by 2002:a17:90a:fa89:b0:273:ef1b:5a2 with SMTP id cu9-20020a17090afa8900b00273ef1b05a2mr208416pjb.47.1696360819194; Tue, 03 Oct 2023 12:20:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de Subject: [PATCH v5 6/9] linux-user: Simplify signal_init Date: Tue, 3 Oct 2023 12:20:09 -0700 Message-Id: <20231003192012.1674888-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> 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: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696360969068100002 Content-Type: text/plain; charset="utf-8" Install the host signal handler at the same time we are probing the target signals for SIG_IGN/SIG_DFL. Ignore unmapped target signals. Signed-off-by: Richard Henderson Acked-by: Helge Deller --- linux-user/signal.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 653fd2f9fd..09840b0eb0 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -558,10 +558,7 @@ static void signal_table_init(void) void signal_init(void) { TaskState *ts =3D (TaskState *)thread_cpu->opaque; - struct sigaction act; - struct sigaction oact; - int i; - int host_sig; + struct sigaction act, oact; =20 /* initialize signal conversion tables */ signal_table_init(); @@ -572,23 +569,28 @@ void signal_init(void) sigfillset(&act.sa_mask); act.sa_flags =3D SA_SIGINFO; act.sa_sigaction =3D host_signal_handler; - for(i =3D 1; i <=3D TARGET_NSIG; i++) { - host_sig =3D target_to_host_signal(i); - sigaction(host_sig, NULL, &oact); - if (oact.sa_sigaction =3D=3D (void *)SIG_IGN) { - sigact_table[i - 1]._sa_handler =3D TARGET_SIG_IGN; - } else if (oact.sa_sigaction =3D=3D (void *)SIG_DFL) { - sigact_table[i - 1]._sa_handler =3D TARGET_SIG_DFL; - } - /* If there's already a handler installed then something has - gone horribly wrong, so don't even try to handle that case. */ - /* Install some handlers for our own use. We need at least - SIGSEGV and SIGBUS, to detect exceptions. We can not just - trap all signals because it affects syscall interrupt - behavior. But do trap all default-fatal signals. */ - if (core_dump_signal(i)) { - sigaction(host_sig, &act, NULL); + + /* + * A parent process may configure ignored signals, but all other + * signals are default. For any target signals that have no host + * mapping, set to ignore. For all core_dump_signal, install our + * host signal handler so that we may invoke dump_core_and_abort. + * This includes SIGSEGV and SIGBUS, which are also need our signal + * handler for paging and exceptions. + */ + for (int tsig =3D 1; tsig <=3D TARGET_NSIG; tsig++) { + int hsig =3D target_to_host_signal(tsig); + abi_ptr thand =3D TARGET_SIG_IGN; + + if (hsig < _NSIG) { + struct sigaction *iact =3D core_dump_signal(tsig) ? &act : NUL= L; + + sigaction(hsig, iact, &oact); + if (oact.sa_sigaction !=3D (void *)SIG_IGN) { + thand =3D TARGET_SIG_DFL; + } } + sigact_table[tsig - 1]._sa_handler =3D thand; } } =20 --=20 2.34.1 From nobody Sun May 19 10:01:17 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696360975; cv=none; d=zohomail.com; s=zohoarc; b=EiU4Jb0C59wWPBGeNlkTuFqsGeLtuOmPSePRw7Ftz/bB2gaztEKjNE3uApG1mVQmhFRNaCg4k90ZihlMfXhr+srczOyNrcjULN9jGSAE64zqCYlzq5ve2KdwthLG8YCEU0MDhN1+eYwyKRRWjDWWVUTsoU5m4ax4gj6vTzv/rAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696360975; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=x2cyUxn+xuVK4D2wBUl4hDzhwAR15+4cIMS3lBIQ8QQ=; b=VPt0Mg0zS1d2DcUWc54tdwhR5DWMQGZ7VLp+yC0Rwm7djgQE2V57mXiZ29Og8g+t0k+6Gv7wl+VJkBn0NIvTwnenoDw0fKuO3sUCFyFqWegRQK3r1/C9XoQlHIXW9gBZ2kb/ZFCkrTfkiYZTHKgfvIctCD63Bj2gEY+w3KdSgw4= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696360975647544.7126097230408; Tue, 3 Oct 2023 12:22:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkxL-00051E-7d; Tue, 03 Oct 2023 15:21:19 -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 1qnkwo-0004sI-2x for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:47 -0400 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004e7-Uz for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:44 -0400 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3af65455e7cso864218b6e.1 for ; Tue, 03 Oct 2023 12:20:21 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360820; x=1696965620; 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=x2cyUxn+xuVK4D2wBUl4hDzhwAR15+4cIMS3lBIQ8QQ=; b=L1JHtDSUHev1yQBec6ka2VC3UPilNJisSYn9X506O0sTBoHtghmDwWnTLxuqF9HdqB tVQyVPpcaMCIvAv6eu4wSvi2SWKxuf+D+w1UGABremlEJpWvo4ZsArEEwoIVCExhAES/ XygsnroxxVJrBU0newSGmDT2yhirVBLpJYakk4ZQM3UfVgpxLEpyHnql6NCmeSnyrvTI vH3mIj23JkcjDpcpgyM9n/9RhBPdNbnA9YZr2w5/zY9DT9qf6opb0CoK2rvkU0SxNGIG WYJKmBsg9jip3Y3F6xLelLaDiZUZIXEeFSVH98DxRE+KrQEkBn6SHpC2vGsK/mmfzICP Ialg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360820; x=1696965620; 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=x2cyUxn+xuVK4D2wBUl4hDzhwAR15+4cIMS3lBIQ8QQ=; b=qg9feWb7VJAOiidUSdYKQjFbFg7okDInPOzITUNCSpdeZ4yfFnxOxPRWQ7LqsgLkuf gsn9tPOmKLx3zd1cCG+hct7KXb1GvqD8NXQ7rs0+yXV+OWnDrOG/cOaLHE/gQrKRj/3k q19rhlwzLz6lg/J1dUDhLlWg7Wf/i3PPO1j040qJcAT7H68ZstJ9/izJYM1rSqf0i6fG K/3bCCCvIJABFAfPfMs3+VJsNhrvTdj834ytqHQMKlst21bUjIgEGdiAv4s62+uW/Aco ayZFzHB/90RNmKvG8UHXyiMgrxCwQvkSHddj5As4Ch8LUUWZnF6v5eGhhgt3iwBH8DuW nL8g== X-Gm-Message-State: AOJu0YyyoQKwRwFf+uItHND8gNvEhkd3EVsDMEh8AYO9ZdvDQYGhZ4dn /96Q9E62OcIRPUwomZvY6M0nE6M8iTsVteQdScE= X-Google-Smtp-Source: AGHT+IFJDO/z3jw6PGt8Ss4mqTaUzMh91mfECjNuk8iDbDNSECrsfj3ucYyqndKJLWPwLDPkqiBdlw== X-Received: by 2002:a05:6808:13c5:b0:3a8:43d5:878b with SMTP id d5-20020a05680813c500b003a843d5878bmr604634oiw.2.1696360820120; Tue, 03 Oct 2023 12:20:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de Subject: [PATCH v5 7/9] linux-user: Split out host_sig{segv,bus}_handler Date: Tue, 3 Oct 2023 12:20:10 -0700 Message-Id: <20231003192012.1674888-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> 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: pass client-ip=2607:f8b0:4864:20::235; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x235.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696360977111100002 Content-Type: text/plain; charset="utf-8" Make host_signal_handler slightly easier to read. Signed-off-by: Richard Henderson Acked-by: Helge Deller --- linux-user/signal.c | 145 ++++++++++++++++++++++++++------------------ 1 file changed, 85 insertions(+), 60 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 09840b0eb0..706b8ac7a7 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -811,6 +811,80 @@ void die_from_signal(siginfo_t *info) die_with_signal(info->si_signo); } =20 +static void host_sigsegv_handler(CPUState *cpu, siginfo_t *info, + host_sigcontext *uc) +{ + uintptr_t host_addr =3D (uintptr_t)info->si_addr; + /* + * Convert forcefully to guest address space: addresses outside + * reserved_va are still valid to report via SEGV_MAPERR. + */ + bool is_valid =3D h2g_valid(host_addr); + abi_ptr guest_addr =3D h2g_nocheck(host_addr); + uintptr_t pc =3D host_signal_pc(uc); + bool is_write =3D host_signal_write(info, uc); + MMUAccessType access_type =3D adjust_signal_pc(&pc, is_write); + bool maperr; + + /* If this was a write to a TB protected page, restart. */ + if (is_write + && is_valid + && info->si_code =3D=3D SEGV_ACCERR + && handle_sigsegv_accerr_write(cpu, host_signal_mask(uc), + pc, guest_addr)) { + return; + } + + /* + * If the access was not on behalf of the guest, within the executable + * mapping of the generated code buffer, then it is a host bug. + */ + if (access_type !=3D MMU_INST_FETCH + && !in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { + die_from_signal(info); + } + + maperr =3D true; + if (is_valid && info->si_code =3D=3D SEGV_ACCERR) { + /* + * With reserved_va, the whole address space is PROT_NONE, + * which means that we may get ACCERR when we want MAPERR. + */ + if (page_get_flags(guest_addr) & PAGE_VALID) { + maperr =3D false; + } else { + info->si_code =3D SEGV_MAPERR; + } + } + + sigprocmask(SIG_SETMASK, host_signal_mask(uc), NULL); + cpu_loop_exit_sigsegv(cpu, guest_addr, access_type, maperr, pc); +} + +static void host_sigbus_handler(CPUState *cpu, siginfo_t *info, + host_sigcontext *uc) +{ + uintptr_t pc =3D host_signal_pc(uc); + bool is_write =3D host_signal_write(info, uc); + MMUAccessType access_type =3D adjust_signal_pc(&pc, is_write); + + /* + * If the access was not on behalf of the guest, within the executable + * mapping of the generated code buffer, then it is a host bug. + */ + if (!in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { + die_from_signal(info); + } + + if (info->si_code =3D=3D BUS_ADRALN) { + uintptr_t host_addr =3D (uintptr_t)info->si_addr; + abi_ptr guest_addr =3D h2g_nocheck(host_addr); + + sigprocmask(SIG_SETMASK, host_signal_mask(uc), NULL); + cpu_loop_exit_sigbus(cpu, guest_addr, access_type, pc); + } +} + static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) { CPUState *cpu =3D thread_cpu; @@ -822,73 +896,23 @@ static void host_signal_handler(int host_sig, siginfo= _t *info, void *puc) int guest_sig; uintptr_t pc =3D 0; bool sync_sig =3D false; - void *sigmask =3D host_signal_mask(uc); + void *sigmask; =20 /* * Non-spoofed SIGSEGV and SIGBUS are synchronous, and need special * handling wrt signal blocking and unwinding. */ - if ((host_sig =3D=3D SIGSEGV || host_sig =3D=3D SIGBUS) && info->si_co= de > 0) { - MMUAccessType access_type; - uintptr_t host_addr; - abi_ptr guest_addr; - bool is_write; - - host_addr =3D (uintptr_t)info->si_addr; - - /* - * Convert forcefully to guest address space: addresses outside - * reserved_va are still valid to report via SEGV_MAPERR. - */ - guest_addr =3D h2g_nocheck(host_addr); - - pc =3D host_signal_pc(uc); - is_write =3D host_signal_write(info, uc); - access_type =3D adjust_signal_pc(&pc, is_write); - - /* If this was a write to a TB protected page, restart. */ - if (is_write - && host_sig =3D=3D SIGSEGV - && info->si_code =3D=3D SEGV_ACCERR - && h2g_valid(host_addr) - && handle_sigsegv_accerr_write(cpu, sigmask, pc, guest_addr)) { + if (info->si_code > 0) { + switch (host_sig) { + case SIGSEGV: + /* Only returns on handle_sigsegv_accerr_write success. */ + host_sigsegv_handler(cpu, info, uc); return; + case SIGBUS: + host_sigbus_handler(cpu, info, uc); + sync_sig =3D true; + break; } - - /* - * If the access was not on behalf of the guest, within the execut= able - * mapping of the generated code buffer, then it is a host bug. - */ - if (access_type !=3D MMU_INST_FETCH - && !in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { - die_from_signal(info); - } - - if (host_sig =3D=3D SIGSEGV) { - bool maperr =3D true; - - if (info->si_code =3D=3D SEGV_ACCERR && h2g_valid(host_addr)) { - /* - * With reserved_va, the whole address space is PROT_NONE, - * which means that we may get ACCERR when we want MAPERR. - */ - if (page_get_flags(guest_addr) & PAGE_VALID) { - maperr =3D false; - } else { - info->si_code =3D SEGV_MAPERR; - } - } - - sigprocmask(SIG_SETMASK, sigmask, NULL); - cpu_loop_exit_sigsegv(cpu, guest_addr, access_type, maperr, pc= ); - } else { - sigprocmask(SIG_SETMASK, sigmask, NULL); - if (info->si_code =3D=3D BUS_ADRALN) { - cpu_loop_exit_sigbus(cpu, guest_addr, access_type, pc); - } - } - - sync_sig =3D true; } =20 /* get target signal number */ @@ -929,6 +953,7 @@ static void host_signal_handler(int host_sig, siginfo_t= *info, void *puc) * would write 0xff bytes off the end of the structure and trash * data on the struct. */ + sigmask =3D host_signal_mask(uc); memset(sigmask, 0xff, SIGSET_T_SIZE); sigdelset(sigmask, SIGSEGV); sigdelset(sigmask, SIGBUS); --=20 2.34.1 From nobody Sun May 19 10:01:17 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696360943; cv=none; d=zohomail.com; s=zohoarc; b=a5jjxn2ghMdoWgOGFz9Bp2pw8TNScBgPamEZZRY2dGjhymoiFe2TDXI+waFdwu0TsaaV/iib3tLv5Nl4XVhY1OQRtrFhQ6z9BagcnDSiGNpS0IFa3cZAy/+zXCK614S6X9XqrSKfveraqNPM6uaxxisFc2e60dhtfLWQWFHgHYM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696360943; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MD3OzDuuDGgXDQMB1J8iXNmpATULZDtwIUTwe03wb+E=; b=X9kH0YNpLLMwpiB28zCFJXztEfc49IE+lrA/lpiRA9y5DqRyLNR4bEa7X0ugJfvyRzFf0iKZ8oMLEcDBkWCsm4urXzwoxmoXLpFbnDU+oFVK9FSEvleek6zGPv4idoIqq91KMd29DAUiyrvVADiRgPinH74g/sGHDQ76G121FnE= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696360943092609.6550900455741; Tue, 3 Oct 2023 12:22:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkxR-00054Y-VP; Tue, 03 Oct 2023 15:21:28 -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 1qnkws-0004th-2a for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:53 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004eG-UK for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:49 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1c7373cff01so1235335ad.1 for ; Tue, 03 Oct 2023 12:20:22 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360821; x=1696965621; 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=MD3OzDuuDGgXDQMB1J8iXNmpATULZDtwIUTwe03wb+E=; b=ABfllLMSoaA4iPE8tJXyJl5SB2E/2UKGesTeXJrLzkg39n0xKwqVg8Pq/9ZtiQWijk 64uldqz/Sol8WbmmIxj2mHx9tQe6FqTVZM1tDNkd4NtHkh+xCeq5KWk6cHwajL3l7kzW qumOz/8PzWY3+H53lbzMooP7xfKuMLIwl61KnnnNCNx+kCeFLi8IQ7dErKl0i/taw0/d ttH26pFF+wF25bktr2JzVgCEwqROtUHGgH//scM8bQfEu9F3uSrYAjUp6ZAuarj4JuMV rEqN2fK5mzir36TtE+qbAI2+MKAn5pyzFry4I0pxIB2xHYKjrD6nP1/+COjpy1cfO05Z v6/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360821; x=1696965621; 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=MD3OzDuuDGgXDQMB1J8iXNmpATULZDtwIUTwe03wb+E=; b=Ij+auvVWAsjEX/LV6hLIUCcvMu/ObQ3UflWgT09NC0e6UoYLT8lmKdQbyL15rjTi1o 6/tH5oRj8+LvHip2uv5F3D7sNcFZ5huhw6EdM9hcdx3eLssIrasieShseeYwDtiGPggT +4sAYP0UOhXnMaqRWdrvesKQlt1hzzYam4XH/PQgGKoWywl8EmTgSaSSg5QarKhNtPKf 6UKiGcDen3kJwvyWcrG7+7tYM0prsDqY3DMCc2php82eZZhIY1wFmSkvJ0ybPfjc3aG7 xMIbhJqgIRdqorXbRSRmbgcsXJkesu1DtXor0wvl4SwH/6UsfqGxXoERsDN3JGVamxCT 6N4Q== X-Gm-Message-State: AOJu0YyIzcr05K9KnD2OF2wWJew1PHGGipz4Wcw8l5/+FVZg+NtTDwD+ AS2YceePLxCAfeebiEKuG8u5hHTfRV0wBkZ4ZXs= X-Google-Smtp-Source: AGHT+IFVaYDnWXK7NrIenxlou8rgkrTl0uM5OckObaqpHoyqmlBAQ3hoG0H6sUgDU7k+rht6vldtUQ== X-Received: by 2002:a17:902:db0a:b0:1c3:432f:9f69 with SMTP id m10-20020a170902db0a00b001c3432f9f69mr247445plx.23.1696360821237; Tue, 03 Oct 2023 12:20:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de Subject: [PATCH v5 8/9] linux-user: Detect and report host SIGILL, SIGFPE, SIGTRAP Date: Tue, 3 Oct 2023 12:20:11 -0700 Message-Id: <20231003192012.1674888-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> 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: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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, T_SPF_TEMPERROR=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696360944351100010 Content-Type: text/plain; charset="utf-8" These signals, when not spoofed via kill(), are always bugs. Use die_from_signal to report this sensibly. Signed-off-by: Richard Henderson Acked-by: Helge Deller --- linux-user/signal.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 706b8ac7a7..b67077f320 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -796,6 +796,43 @@ void die_from_signal(siginfo_t *info) break; } break; + case SIGILL: + sig =3D "ILL"; + switch (info->si_code) { + case ILL_ILLOPC: + code =3D "ILLOPC"; + break; + case ILL_ILLOPN: + code =3D "ILLOPN"; + break; + case ILL_ILLADR: + code =3D "ILLADR"; + break; + case ILL_PRVOPC: + code =3D "PRVOPC"; + break; + case ILL_PRVREG: + code =3D "PRVREG"; + break; + case ILL_COPROC: + code =3D "COPROC"; + break; + } + break; + case SIGFPE: + sig =3D "FPE"; + switch (info->si_code) { + case FPE_INTDIV: + code =3D "INTDIV"; + break; + case FPE_INTOVF: + code =3D "INTOVF"; + break; + } + break; + case SIGTRAP: + sig =3D "TRAP"; + break; default: snprintf(sigbuf, sizeof(sigbuf), "%d", info->si_signo); sig =3D sigbuf; @@ -900,7 +937,8 @@ static void host_signal_handler(int host_sig, siginfo_t= *info, void *puc) =20 /* * Non-spoofed SIGSEGV and SIGBUS are synchronous, and need special - * handling wrt signal blocking and unwinding. + * handling wrt signal blocking and unwinding. Non-spoofed SIGILL, + * SIGFPE, SIGTRAP are always host bugs. */ if (info->si_code > 0) { switch (host_sig) { @@ -912,6 +950,10 @@ static void host_signal_handler(int host_sig, siginfo_= t *info, void *puc) host_sigbus_handler(cpu, info, uc); sync_sig =3D true; break; + case SIGILL: + case SIGFPE: + case SIGTRAP: + die_from_signal(info); } } =20 --=20 2.34.1 From nobody Sun May 19 10:01:17 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696360943; cv=none; d=zohomail.com; s=zohoarc; b=Rd1bgdxpkT80IloDJx6oFWzVz15MQXS/IyXizm6299kIcGAFQovWAdZcHdeeHHVGdYjeDZNU8jFNjRej72B2pDzC3NTVPI43k04nqVNEhBE5rkv1gz9G4zfIfIx1vpVhibZHw8QwULu3l4H0l4/t29Dl+tW5uN0qUm+2Je1/Rt0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696360943; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1E71x8AOuJqRUKKSfRCBk7J7r5yvF1NZG8wQysx060w=; b=RXVkSJFXky8/6C70e87bfwi3BTt4wekaxCLlkYc+yIHNjXjsReZCeXNKzY6l7vLl/82fwhjHtzWp8DwGtkDlVxol/+JBxoE2s+wjtaEhYtLyfICeXc6mOLuGjCapuoRmS04bGZW1lDFVXr9U7hqfIphcBa7OD4BdOtqedayL6Js= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696360943148172.79089690117416; Tue, 3 Oct 2023 12:22:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnkwk-0004qu-4G; Tue, 03 Oct 2023 15:20:42 -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 1qnkwi-0004qY-Ek for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:40 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkwT-0004eP-SU for qemu-devel@nongnu.org; Tue, 03 Oct 2023 15:20:40 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1c760b34d25so9924595ad.3 for ; Tue, 03 Oct 2023 12:20:23 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id w5-20020a170902d3c500b001c5fd2a28d3sm1978497plb.28.2023.10.03.12.20.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:20:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696360822; x=1696965622; 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=1E71x8AOuJqRUKKSfRCBk7J7r5yvF1NZG8wQysx060w=; b=bTaY7M1IZio59YDb9lQ1LY2aWuQtcJFOpjPbqB4xE91rORLXP+5zC63K43ZyrMH3ai Xc0DHz5hVxHPnfTLRXS6qzxsvajTYkNZfr4LSPZgSUV7SA4TTsWWPiBFt2L4bhLEzVt4 IUobM8beRAPxKRiPE3QLBNaHhMiTfG5NKsnUT/JLpgMrD1N/0F2M3esvXxQAUUGI34Vo xpUZIyALjlVZX+EUMx3g7o4lj6Rzvcdn89UDT7x5vB6TRXm/erBuiF+bBwmT5HiG/oDi gWlTY08wYSTqN8OgmGv/wo35+oN6ne+Q+og4sYHqyqKdRN8kLZ72haeNsNKkIdVOk7y4 bSkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360822; x=1696965622; 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=1E71x8AOuJqRUKKSfRCBk7J7r5yvF1NZG8wQysx060w=; b=k9e5kVHZLHni8gW0YQY2EsdIP9UGd0EH+5m8ZSz+OxM5oRoliFlgZz4l1wbJYBpZoL 3ZRSN4gUN5HJbxPMauqp4Ys8CU2d6Ac0pXC+CQt4Nm1blL6OPuCZvbJiGNEWf4xvug8R HFn+0YpCsN2/awSVllkfcq3DLkhXR4jeoHN5midfdKvXg1y2d0kO1CxqhSFti+qA78e5 MvFI+LbqlKOwXMvywwTnulEt7SXEyak3EVf2x+STG7KXGHS0/lXPbejrcSECJ301SOIZ hyvdJXmNK2ypAuCV4WMadeiY+EKc/+XtciywzC3bYGXwCQB2eGamtcEGcoipByvql/yq WwFg== X-Gm-Message-State: AOJu0YxIA64eDrx7yw9PqjxsWc8w4xzMhezN3Cjq6qzzXlNpqemT7aPa GmIot8WkTIRh5S8LziUD5PYim5o2BqNUSXgcBKU= X-Google-Smtp-Source: AGHT+IEe1HzemXnkmotVP1i4wVnhz5opR30vnHt/7qoBRWHvT5KmYlEJRyjSB+wlvR2/1lDFNhzS9g== X-Received: by 2002:a17:902:d4cc:b0:1c3:c687:4793 with SMTP id o12-20020a170902d4cc00b001c3c6874793mr385252plg.63.1696360822094; Tue, 03 Oct 2023 12:20:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, deller@gmx.de Subject: [PATCH v5 9/9] linux-user: Remap guest SIGABRT Date: Tue, 3 Oct 2023 12:20:12 -0700 Message-Id: <20231003192012.1674888-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003192012.1674888-1-richard.henderson@linaro.org> References: <20231003192012.1674888-1-richard.henderson@linaro.org> 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: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696360944805100015 Content-Type: text/plain; charset="utf-8" Distinguish host SIGABRT from guest SIGABRT by mapping the guest signal onto one of the host RT signals. This prevents a cycle by which a host assertion failure is caught and handled by host_signal_handler, queued for the guest, and then we attempt to continue past the host abort. What happens next depends on the host libc, but is neither good nor helpful. Signed-off-by: Richard Henderson Acked-by: Helge Deller --- linux-user/signal.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index b67077f320..b7f4ce3cb9 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -522,8 +522,16 @@ static void signal_table_init(void) * multiplexed over a single host signal. * Attempts for configure "missing" signals via sigaction will be * silently ignored. + * + * Remap the target SIGABRT, so that we can distinguish host abort + * from guest abort. */ - for (hsig =3D SIGRTMIN; hsig <=3D SIGRTMAX; hsig++) { + + hsig =3D SIGRTMIN; + host_to_target_signal_table[SIGABRT] =3D 0; + host_to_target_signal_table[hsig++] =3D TARGET_SIGABRT; + + for (; hsig <=3D SIGRTMAX; hsig++) { tsig =3D hsig - SIGRTMIN + TARGET_SIGRTMIN; if (tsig <=3D TARGET_NSIG) { host_to_target_signal_table[hsig] =3D tsig; @@ -582,13 +590,21 @@ void signal_init(void) int hsig =3D target_to_host_signal(tsig); abi_ptr thand =3D TARGET_SIG_IGN; =20 - if (hsig < _NSIG) { - struct sigaction *iact =3D core_dump_signal(tsig) ? &act : NUL= L; + if (hsig >=3D _NSIG) { + continue; + } =20 + /* As we force remap SIGABRT, cannot probe and install in one step= . */ + if (tsig =3D=3D TARGET_SIGABRT) { + sigaction(SIGABRT, NULL, &oact); + sigaction(hsig, &act, NULL); + } else { + struct sigaction *iact =3D core_dump_signal(tsig) ? &act : NUL= L; sigaction(hsig, iact, &oact); - if (oact.sa_sigaction !=3D (void *)SIG_IGN) { - thand =3D TARGET_SIG_DFL; - } + } + + if (oact.sa_sigaction !=3D (void *)SIG_IGN) { + thand =3D TARGET_SIG_DFL; } sigact_table[tsig - 1]._sa_handler =3D thand; } @@ -711,7 +727,12 @@ void dump_core_and_abort(CPUArchState *env, int target= _sig) TaskState *ts =3D (TaskState *)cpu->opaque; int host_sig, core_dumped =3D 0; =20 - host_sig =3D target_to_host_signal(target_sig); + /* On exit, undo the remapping of SIGABRT. */ + if (target_sig =3D=3D TARGET_SIGABRT) { + host_sig =3D SIGABRT; + } else { + host_sig =3D target_to_host_signal(target_sig); + } trace_user_dump_core_and_abort(env, target_sig, host_sig); gdb_signalled(env, target_sig); =20 --=20 2.34.1