From patchwork Wed Aug 23 05:16:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1824445 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=KY9jrHfr; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RVvcJ6h4kz1ydy for ; Wed, 23 Aug 2023 15:17:52 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYgED-0004vN-R1; Wed, 23 Aug 2023 01:16:25 -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 1qYgEB-0004sj-6k for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:23 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYgE8-0000s7-QY for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:22 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68a4bcf8a97so2242398b3a.1 for ; Tue, 22 Aug 2023 22:16:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692767779; x=1693372579; 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=dcsO2dVLbPUl+GizLMpXodQLIxyTwrwgsESLGfn+SH8=; b=KY9jrHfrkOo0NzsIQTLJejbEcsfc0x/9Yf6qNffRYhYAdQXSAWpz5xpCmnX7V6FEt0 rzloc1NnvUsiSwcCfpVuIDabdJ3Rkfz/Nd3MwIah6eaEgRYZH+wiAv5mzFVFP1FNBDgE 9SPdZrzpyx+lOd+u1LmrWm2zi1XOzoRDA70DR3+S3NnhO8H5bkcLJdoqgz6vup1VNAec g7DetQrTJxZx/Ajil/WEcWfDG120uhwkw0pAqzct6dxdhIwcLtd2rxvZqGSCnNKe9SN9 J6reIgOy6+ubWdwYqx02fRV27oTRtDVDgsWAsz6UjRT39beEsLPtJF0tP3SjRKb/xcok 4xiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692767779; x=1693372579; 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=dcsO2dVLbPUl+GizLMpXodQLIxyTwrwgsESLGfn+SH8=; b=W6CrIjO37Fq5WJr+Pb1FXEb3AZrbODFemb3hdHUzLcr4tjHVXxTF3q58t5ASYLAq41 s25xJJ9Fu/OnG+5DrvIEu7PIxzmSORwefca3mcwKsu+qkkGknQ/RQCg4gkyJXF7sI9Ty iT6zXWZt60vpjm8ktB+a4reXjWvBOOpjjLaJn5gkXm+nEe10evUAdi61MSNXAhs6SE4d Eb76ktd8vgV7b6xwz8qu1Y+zxx8JvWXfvIanmKAJ7QSO5melxXPdYkRmfov8tQTOj9LX eSSHTOPOrlzWqxXwEOeYoNHpcpOE0g2DeslWuYyLwsYm2jJODgYNOMhI2u00ad/UOOas 8QXQ== X-Gm-Message-State: AOJu0Ywa+cuR5lm8YqCbawfgBS8qcsTWIPzCGDLvF1dR5jneutymCFt5 W3/4CGNCig1QSc5OvG4SHGEirXK7Ph9Ea+UL6p4= X-Google-Smtp-Source: AGHT+IGmniW6dPtBK4RaXrDeLZd6PmLIdBKxGXWhIBBaVrH59uldEHI7GVwEwhyys6WXsAhUDrRz9Q== X-Received: by 2002:a05:6a21:47c8:b0:134:2fd0:73d6 with SMTP id as8-20020a056a2147c800b001342fd073d6mr9150242pzc.31.1692767779222; Tue, 22 Aug 2023 22:16:19 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:4e3c:f4a4:b92a:b5ab]) by smtp.gmail.com with ESMTPSA id 5-20020a170902c24500b001bf044dc1a6sm9969402plg.39.2023.08.22.22.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 22:16:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de Subject: [PATCH v4 01/10] linux-user: Split out die_with_signal Date: Tue, 22 Aug 2023 22:16:06 -0700 Message-Id: <20230823051615.1297706-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823051615.1297706-1-richard.henderson@linaro.org> References: <20230823051615.1297706-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Because we trap so many signals for use by the guest, we have to take extra steps to exit properly. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- 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 748a98f3e5..e1cd111a1b 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -694,6 +694,33 @@ void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr, } /* abort execution with signal */ +static G_NORETURN +void die_with_signal(int sig) +{ + struct sigaction act = { + .sa_handler = 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(sig, &act, NULL); + + kill(getpid(), sig); + + /* Make sure the signal isn't masked (reusing the mask inside of act). */ + sigdelset(&act.sa_mask, sig); + sigsuspend(&act.sa_mask); + + /* unreachable */ + abort(); +} + static G_NORETURN void dump_core_and_abort(CPUArchState *cpu_env, int target_sig) { @@ -701,7 +728,6 @@ void dump_core_and_abort(CPUArchState *cpu_env, int target_sig) CPUArchState *env = cpu->env_ptr; TaskState *ts = (TaskState *)cpu->opaque; int host_sig, core_dumped = 0; - struct sigaction act; host_sig = target_to_host_signal(target_sig); trace_user_dump_core_and_abort(env, target_sig, host_sig); @@ -725,29 +751,7 @@ void dump_core_and_abort(CPUArchState *cpu_env, int target_sig) } preexit_cleanup(cpu_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 = SIG_DFL; - act.sa_flags = 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); } /* queue a signal so that it will be send to the virtual CPU as soon From patchwork Wed Aug 23 05:16:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1824450 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ltXosM/H; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RVvdz0Vc0z1ybW for ; Wed, 23 Aug 2023 15:19:18 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYgEE-0004vO-1v; Wed, 23 Aug 2023 01:16:26 -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 1qYgEC-0004uW-5e for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:24 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYgE9-0000sG-Pf for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:23 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1bc5acc627dso34761985ad.1 for ; Tue, 22 Aug 2023 22:16:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692767780; x=1693372580; 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=rQp++5N0yIEsVmUaGN89LifNvR6oAeooLY4sPs12hmU=; b=ltXosM/H8ad61vXFbAD+0NcohOg/gTFW/5O0IP0cXoANWU/vtXX6QjH5h3J1NduAPr GBa0ktqUus+wsLggxbcxoIDa45tgsbOs2AAv34W9U3S01SVMkIHIovwhFfuYuAprn5qt vNHb24wXKrzJfYou9ApF8DXwxISteViyzhOH/+tWWLlyPutTmTMPtc/nZ43R5xsQ7s45 zwIw8FEUltYKUpYOlk4Ese8KfAGVb2wWtfkqKTG9vZrYbTlqHpflUHVDdPIMLEvom2ze eCVUzSOt7FwvfXK/CpV8iJqzfc2rBNEgOAz0PEuQ1N+9mi/56kZEfTVHDaTm3B61OHV9 ZuPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692767780; x=1693372580; 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=rQp++5N0yIEsVmUaGN89LifNvR6oAeooLY4sPs12hmU=; b=X6XUNzKJl9/MzFOeIrElrsvmDIRfpLnB28m554habJdvTky6zUZ/5SVmdzHcTu5tOU 985Sb8Ql28FGQd3Yo86FPDQf4eegJ9GNtQhpJgZbnBeceZR27lri+rqrud4ayEeNBT6d khbl5Oo0HCt0/m2WefxbX7GucIsPA01jV7BJ4jEhmD7ugpqSxQTukWekvYQIL4+fUVfC XuuUS+47A5O17RqCCDKZa3IYmx56pfQZELF3DK5PHi/y5VmGewPiMhoutevryy+Xb1tk Jvxa0Y9itVdn7ujtPWlz90+/wOZ0hx+fn+StXj6Y2T+Vb1/mMHn14+eIOQtILk4NTIdx exMA== X-Gm-Message-State: AOJu0YyUWzW8M/79Md6RrT7rQ5nrClLTRUTLet1Ro+h2x1sMv6irEsHq z+Ol6yOB5QXv+WM8o8fIKqyZ12I2zXSFqssdW1U= X-Google-Smtp-Source: AGHT+IFTauG1nrGMroiXLHi/W89epAXW+ZYWGK7S7nRr9sZOu+s/jInsyJsJpH2ZZKiFeBU3PcVmMA== X-Received: by 2002:a17:902:d345:b0:1bb:1e69:28be with SMTP id l5-20020a170902d34500b001bb1e6928bemr8482759plk.42.1692767780473; Tue, 22 Aug 2023 22:16:20 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:4e3c:f4a4:b92a:b5ab]) by smtp.gmail.com with ESMTPSA id 5-20020a170902c24500b001bf044dc1a6sm9969402plg.39.2023.08.22.22.16.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 22:16:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de Subject: [PATCH v4 02/10] linux-user: Exit not abort in die_with_backtrace Date: Tue, 22 Aug 2023 22:16:07 -0700 Message-Id: <20230823051615.1297706-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823051615.1297706-1-richard.henderson@linaro.org> References: <20230823051615.1297706-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- 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 e1cd111a1b..57fbf2f58b 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -718,7 +718,7 @@ void die_with_signal(int sig) sigsuspend(&act.sa_mask); /* unreachable */ - abort(); + _exit(EXIT_FAILURE); } static G_NORETURN From patchwork Wed Aug 23 05:16:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1824444 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=tfL8+yP7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RVvc34Mx2z1ydy for ; Wed, 23 Aug 2023 15:17:39 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYgEF-0004vf-27; Wed, 23 Aug 2023 01:16:27 -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 1qYgED-0004uz-4g for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:25 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYgEA-0000sU-RR for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:24 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1bc83a96067so31822365ad.0 for ; Tue, 22 Aug 2023 22:16:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692767781; x=1693372581; 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=rn4m/BUkUlHqvAP+qKbf9mRxMLOIUsCoPFyrQpA+ZgA=; b=tfL8+yP7JXoUx4JsArTpdnOZb39LLyARNAWcOAgVJpcN83Mifc+RfioBe0EFQUjZ8k tawhjMtBZDHZwBGABM9NuX7JjvpLVwE0LgkUOn174Tw1fzNogTjuwrVtyFyxSqogtKp6 DV/rDp8oyvEXZ3Dh6U11k0wSwjIwA/5UmYsQIKWO9lnNrt78/k2OrWyTzgIkFuo3RoHT RwIEL9W3rTgqfHQj/XzmP5FQ1n1T3tzW7OQM4ZmVyUg6XzrGhl6uzayf2yZniFg2LJSD YcFstcmQ59+dIdHAVwx1syewOIgRqk9tYY1b3bD5RUumE138k6dToE9/Pq6jiSewO0dN +t+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692767781; x=1693372581; 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=rn4m/BUkUlHqvAP+qKbf9mRxMLOIUsCoPFyrQpA+ZgA=; b=DdW6IXUnASLNvi26OEZ1QUoYOc90KRdLlkm9S03XF9VOvc/KIqdTegtmgD10xlp/Zu t01CTw2JbuAAGCJguv2Czi+6EEKnXRMbubg52tiHyBLoi1Y51JHAHKYS+dSSMZZ8GpPf oTJHK7a5NVci+e6WIAliTan+IYFsqyJT1LhFiUKfZDMKH5MvnLHe2m+VNw4q26UY1HiO vGH8Og2qCrK1f7tpQV8MuV7r8Nf1un345g9e3syB7dVOCQEZVpL6dKwAieWDMGdrreua sW7QzqpaM0yhONmrrZXJvU299VXQ9FfUVwuY6mG9g5eRRJLFJv4gG1k3SRUYByt0ReGU 2QOQ== X-Gm-Message-State: AOJu0YynDp3O8HyU95uB9kN6QUvewffc08RgTpfLhQJVPw7m8SX8IxnS nzoYgU3t+uqZI0w7raggpnEUaCe0bWXLFvcN290= X-Google-Smtp-Source: AGHT+IHKwlIFJPDa6AKmYeLB3QnwfCR4qrDRqj+E4Ex4gngKhG6krHf+5gwKs1gJoS3b1BAG4eqdqg== X-Received: by 2002:a17:902:f546:b0:1b6:af1a:7dd3 with SMTP id h6-20020a170902f54600b001b6af1a7dd3mr10881380plf.23.1692767781506; Tue, 22 Aug 2023 22:16:21 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:4e3c:f4a4:b92a:b5ab]) by smtp.gmail.com with ESMTPSA id 5-20020a170902c24500b001bf044dc1a6sm9969402plg.39.2023.08.22.22.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 22:16:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de Subject: [PATCH v4 03/10] linux-user: Use die_with_signal with abort Date: Tue, 22 Aug 2023 22:16:08 -0700 Message-Id: <20230823051615.1297706-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823051615.1297706-1-richard.henderson@linaro.org> References: <20230823051615.1297706-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62f.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Describe the convoluted way by which we can see ERROR:../alt/accel/tcg/cpu-exec.c:532:cpu_exec_longjmp_cleanup: assertion failed: (cpu == current_cpu) Bail out! ERROR:../alt/accel/tcg/cpu-exec.c:532:cpu_exec_longjmp_cleanup: assertion failed: (cpu == current_cpu) for encountering an an abort() in qemu source. Signed-off-by: Richard Henderson --- linux-user/signal.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/linux-user/signal.c b/linux-user/signal.c index 57fbf2f58b..a77d003de6 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -721,6 +721,18 @@ void die_with_signal(int sig) _exit(EXIT_FAILURE); } +/* + * The system abort() will raise SIGABRT, which will get caught and deferred + * by host_signal_handler. Returning into system abort will try harder. + * Eventually, on x86, it will execute HLT, which raises SIGSEGV. This goes + * back into host_signal_handler, through a different path which may longjmp + * back to the main loop. This often explodes. + */ +void abort(void) +{ + die_with_signal(SIGABRT); +} + static G_NORETURN void dump_core_and_abort(CPUArchState *cpu_env, int target_sig) { From patchwork Wed Aug 23 05:16:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1824442 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=KDYu0rnb; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RVvbw1sshz26jN for ; Wed, 23 Aug 2023 15:17:31 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYgEG-0004wD-5f; Wed, 23 Aug 2023 01:16: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 1qYgEE-0004vQ-7N for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:26 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYgEB-0000sf-SX for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:25 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1bc5acc627dso34762075ad.1 for ; Tue, 22 Aug 2023 22:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692767782; x=1693372582; 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=p5gfbYEtQOxd0dUyPKXMEvc82rL/zzDhhmw3j/jKEBw=; b=KDYu0rnbCx64hAqW/5t5zoZ3MpDPhwSz1HXedEURdtp/KVwgm9xdZKB+VutdulVMsW MGjquymJMXEX0qxhgX3R/YaYuTCfKle0z9EDc5reLjUHyZSQaLLLGFH7HFEndKSkJ6P9 Wetpua2NjFaECp/zfLtcSZl2/pJAIuhEyr5F4QLNvbkQ0y6T/OViiaZrD3z45+pNuwGW HSqDhjHIbCRXKcNnVBk3LoOLdBqsTBIJucmP4ynX8yzGbfcDuLt14uvYPo6JXCYQ0Sey Y95bWDZmJjO6qgnFRtvH4ZOYjdvntZ4nY9u7iV/20JMnTzZQgJvFYTrDCpjmAqkOR0x5 7o3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692767782; x=1693372582; 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=p5gfbYEtQOxd0dUyPKXMEvc82rL/zzDhhmw3j/jKEBw=; b=O/y4+qLCU84tdMzFp8F1HTB8j2UgaKnnCWdXVBkVD3AjCPPB4jkKubWEnRoKlPrS+m xDNJ4K/KdFLe/ssGDbc9GVAizSiNfEDrot4Lqs82s0oRuFGxL+g1lU8W0cFa58RZ7WkB NY9NJgQnDLYPunNx0xr44pJozZ7Ae5sSq2nyZOSUJVcmoW6W6mgpT43Rwb8MpGqvGuQb BYU2Wo4z6HKItlxdPW3P5gXcDv9ph9yQtPtLe2YA57X186oLCuov+yS1M0q/U4LXz0ss 23OGUaBbYyFZInjwOlfosWaKO1z/lsN2Izb0L/r4tqVpgKhZ4p+xNJgg72WgZ3ycLkIM j4Vw== X-Gm-Message-State: AOJu0YwUHptWz+Bpzj6XhllGaT+2+1zvKXcNWXcA7Wklfg+HmOnz8Zud ERCGgwzr76POmp0296JYgYweYZ494XFHHddxZdM= X-Google-Smtp-Source: AGHT+IHiJJt+Ryamws1QeBAtockAs9MlLEwTT5M9rXSxVzkicxlPVd8CS7Nn/DLUt0l8i2waZYL9Ag== X-Received: by 2002:a17:902:e849:b0:1bd:eef1:41c0 with SMTP id t9-20020a170902e84900b001bdeef141c0mr10336507plg.29.1692767782359; Tue, 22 Aug 2023 22:16:22 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:4e3c:f4a4:b92a:b5ab]) by smtp.gmail.com with ESMTPSA id 5-20020a170902c24500b001bf044dc1a6sm9969402plg.39.2023.08.22.22.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 22:16:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de Subject: [PATCH v4 04/10] linux-user: Detect and report host crashes Date: Tue, 22 Aug 2023 22:16:09 -0700 Message-Id: <20230823051615.1297706-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823051615.1297706-1-richard.henderson@linaro.org> References: <20230823051615.1297706-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 {si_code=1, si_addr=(nil)} QEMU v8.1.50 target x86_64 running /usr/bin/cat QEMU backtrace: ./qemu-x86_64(+0xf83d9) [0x55c48587a3d9] ./qemu-x86_64(+0xf8663) [0x55c48587a663] /lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7f39eee42520] ./qemu-x86_64(+0x1132fa) [0x55c4858952fa] ./qemu-x86_64(+0x11396f) [0x55c48589596f] ./qemu-x86_64(+0x1140ef) [0x55c4858960ef] ./qemu-x86_64(+0x115796) [0x55c485897796] ./qemu-x86_64(+0x11f9dd) [0x55c4858a19dd] ./qemu-x86_64(+0x3f8da) [0x55c4857c18da] ./qemu-x86_64(+0xf3bfb) [0x55c485875bfb] /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7f39eee29d90] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7f39eee29e40] ./qemu-x86_64(+0x39075) [0x55c4857bb075] Aborted Signed-off-by: Helge Deller Message-Id: <20230812164314.352131-1-deller@gmx.de> [rth: Use in_code_gen_buffer and die_with_signal] Signed-off-by: Richard Henderson --- linux-user/signal.c | 53 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index a77d003de6..529fea8bba 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -23,6 +23,7 @@ #include #include +#include #include "qemu.h" #include "user-internals.h" @@ -32,6 +33,7 @@ #include "signal-common.h" #include "host-signal.h" #include "user/safe-syscall.h" +#include "tcg/tcg.h" static struct target_sigaction sigact_table[TARGET_NSIG]; @@ -797,6 +799,33 @@ static inline void rewind_if_in_safe_syscall(void *puc) } } +static G_NORETURN +void die_with_backtrace(siginfo_t *info) +{ + void *array[20]; + int size; + + fprintf(stderr, + "QEMU internal SIG%s {si_code=%d, si_addr=%p}\n" + "QEMU v" QEMU_VERSION " target " UNAME_MACHINE " running %s\n", + sigabbrev_np(info->si_signo), info->si_code, info->si_addr, + exec_path); + + size = backtrace(array, ARRAY_SIZE(array)); + if (size) { + char **strings = backtrace_symbols(array, size); + if (strings) { + fprintf(stderr, "QEMU backtrace:\n"); + for (int i = 0; i < size; ++i) { + fprintf(stderr, " %s\n", strings[i]); + } + free(strings); + } + } + + abort(); +} + static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) { CPUArchState *env = thread_cpu->env_ptr; @@ -832,16 +861,28 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) is_write = host_signal_write(info, uc); access_type = adjust_signal_pc(&pc, is_write); + /* If this was a write to a TB protected page, restart. */ + if (is_write + && host_sig == SIGSEGV + && info->si_code == 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 executable + * mapping of the generated code buffer, then it is a host bug. + */ + if (access_type != MMU_INST_FETCH + && !in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { + die_with_backtrace(info); + } + if (host_sig == SIGSEGV) { bool maperr = true; if (info->si_code == 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_addr)) { - return; - } - /* * With reserved_va, the whole address space is PROT_NONE, * which means that we may get ACCERR when we want MAPERR. From patchwork Wed Aug 23 05:16:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1824447 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=sQoq9fdj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RVvdF6GJ6z1ybW for ; Wed, 23 Aug 2023 15:18:41 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYgEH-0004wb-F0; Wed, 23 Aug 2023 01:16:29 -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 1qYgEE-0004vd-R4 for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:26 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYgEC-0000sv-Iw for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:26 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1bdca7cc28dso41695865ad.1 for ; Tue, 22 Aug 2023 22:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692767783; x=1693372583; 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=QVZ8TmDLEIACLc9a/Qe1Sv9+EQSNfIXJRPDML0Xg9Mk=; b=sQoq9fdjunWJscF2evV197uTf6fpJAOQAd/XpXpW8JheP8cbgKKlKRT+CQ+XEzXr8x R3I7U4vS25V4dEb24jAn40P5QoK7H4+bgkAwrbZN0auuxFxS4hXa1btg1IkyD5mZN03e x5mwEYGtbRXVWsLdKNz7B0hN2DhgLCNsX5Il2noTkmXYi179NMfpIXypuNitno3Zykrp gWI2vw+a3OyDgYzV3yLmMlW3+IsGHYkFGI3Svg2+B5t6xValivcQ+3DhQGXtO03s0SmB biNcIqWugYIIjvKHJnVDwqK/mJkdS4dXrJYPXEhY3d4iQhUKLdFbtBcG1VKA9mQ51TT4 v9wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692767783; x=1693372583; 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=QVZ8TmDLEIACLc9a/Qe1Sv9+EQSNfIXJRPDML0Xg9Mk=; b=PUBdCw8lNwxpfCjqY7meiGD8cD/3oUwKi19sEVottozlyPcsJmnorzp71En3e4LV0L Ct1urwjw5ppUJFq2Fnz7jxDJ+o641l5XLKVzY4f9unvTTIWO0ZKND2hYIncn2diWbCOv /0RyckPIm15CULwOy4xE28RK9I0TsOAvjTqhXCsh6J05OWGoT4/cpf/SdCCTf7H2N6wh +nHNyvTA59nl3DiKm1d6Yl1rHL/14x97O7HW5VfzIrvaWKHFav8ySU+9m2ZAcmN9dtuo 6Ad7Ayd3bJWrVpnCF5bZNFrRaK4Fbva1OuyWbWwCFQMClJfRt4k9gJoywVSch6MsY2kx qj/g== X-Gm-Message-State: AOJu0YygWZskfsEv8xO+BARCfT3DpkRqkbNEKHV7ZtljhzSEROUpjWYC 53KYLyySdOUvf7Nq0F1fwrMq9Bt4sAeztQA7+DE= X-Google-Smtp-Source: AGHT+IEPjHFjKhagvCE9Uu/227fkQhVgsYpRggL0lf6S61jPaefnEHIq6DDR1Skv0GjDGL9DeR7+6w== X-Received: by 2002:a17:903:1108:b0:1bc:1b01:8961 with SMTP id n8-20020a170903110800b001bc1b018961mr13766450plh.1.1692767783217; Tue, 22 Aug 2023 22:16:23 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:4e3c:f4a4:b92a:b5ab]) by smtp.gmail.com with ESMTPSA id 5-20020a170902c24500b001bf044dc1a6sm9969402plg.39.2023.08.22.22.16.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 22:16:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de Subject: [PATCH v4 05/10] linux-user: Only register handlers for core_dump_signal by default Date: Tue, 22 Aug 2023 22:16:10 -0700 Message-Id: <20230823051615.1297706-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823051615.1297706-1-richard.henderson@linaro.org> References: <20230823051615.1297706-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 529fea8bba..73f40699ad 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -489,26 +489,6 @@ void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo) info->si_value.sival_ptr = (void *)(long)sival_ptr; } -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) { @@ -608,8 +588,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); + } } } @@ -999,7 +980,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 = 0; @@ -1059,22 +1039,27 @@ int do_sigaction(int sig, const struct target_sigaction *act, return 0; } if (host_sig != SIGSEGV && host_sig != SIGBUS) { + struct sigaction act1; + sigfillset(&act1.sa_mask); act1.sa_flags = SA_SIGINFO; - if (k->sa_flags & TARGET_SA_RESTART) - act1.sa_flags |= SA_RESTART; - /* NOTE: it is important to update the host kernel signal - ignore state to avoid getting unexpected interrupted - syscalls */ if (k->_sa_handler == TARGET_SIG_IGN) { + /* + * It is important to update the host kernel signal ignore + * state to avoid getting unexpected interrupted syscalls. + */ act1.sa_sigaction = (void *)SIG_IGN; } else if (k->_sa_handler == TARGET_SIG_DFL) { - if (fatal_signal (sig)) + if (core_dump_signal(sig)) { act1.sa_sigaction = host_signal_handler; - else + } else { act1.sa_sigaction = (void *)SIG_DFL; + } } else { act1.sa_sigaction = host_signal_handler; + if (k->sa_flags & TARGET_SA_RESTART) { + act1.sa_flags |= SA_RESTART; + } } ret = sigaction(host_sig, &act1, NULL); } From patchwork Wed Aug 23 05:16:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1824446 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=RxAJjeNL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RVvdB4qPZz1ybW for ; Wed, 23 Aug 2023 15:18:38 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYgEJ-0004xW-D6; Wed, 23 Aug 2023 01:16: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 1qYgEG-0004wS-Ie for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:28 -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 1qYgEE-0000t9-0z for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:28 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1bc0d39b52cso34956655ad.2 for ; Tue, 22 Aug 2023 22:16:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692767784; x=1693372584; 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=TV1TciBhkf4DHVRrzToQTqKckAEQKZ4+I2kgg1P7TXM=; b=RxAJjeNLloBT6VR1NWFt/G/gTCHKVA7TdGYmAHhP7lrZj8DU9Zyfdl0OYlhi7B2Zaf BLSWDgnrQTj5PJDWjz4nKwHLFlXwEV9k4OTUUunW4xWJOChf796NNzOOOOIK8bSsvN2O od36PHx0+vVx/72QNxWr7jk0UvBOn3jK3nXRfKzI1JGExjT+Mg1D9FXRuZGFsueqhETD sKMOX1kY4+nDABnLPNYRjw77qa6f1+gok170wSeYKBkNUsWQDlXjpwweELgW3LdyB3PW dCY1KPaG3ytiD3c17tDjpJ9xeHMHIxXR/vY+U4cJZDCWk9FaB4jiBoneexf0z/2LYBlp nrxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692767784; x=1693372584; 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=TV1TciBhkf4DHVRrzToQTqKckAEQKZ4+I2kgg1P7TXM=; b=k2Q+UVktQIMReu0f6R4IhpKerBOZs4OJ+WTysM1VuS7Fsvt/JNw4yCyXbq3gROLKAB Sjet91H16J3VkYfwFceBRlTSIZ2VbXurc7H6RzN6ENRE0MeC/0V0kJd/Zm4qmSt8400x ebkTshsJ0ICMvE6xgwat5PYODHUEs3F3q/bANS51PWiFkdYuyws6iz/b2cz0Fpuf0o4y AWab5VTTAt62QGMGaw1V5PoKB8zq7eme+ED8QR1x7ozzZFERjzBy5AGefUbajKFPSgED obuw8jTBY7WhBrxM7qH+RdzOAQRdMVDTji7qyx7Qst7U9TcWL0VpZhoJKFxAnMrGcKQd MItg== X-Gm-Message-State: AOJu0Yw4st8gcMSpK95wQWot9Ztkcg5M5pSQGLnyC5iLlPthQZS3fhsq gMeRDZg93Eos74OHLhLZAqiX/6IVw4WW9IM9uys= X-Google-Smtp-Source: AGHT+IHh87DunGp0C41L5wcgeASrjmcDluc6P4AZIkHHyVBO6B+teC5ioPDX856Lpe/Ieb9hAUPWYQ== X-Received: by 2002:a17:903:4cd:b0:1bf:4185:ed1c with SMTP id jm13-20020a17090304cd00b001bf4185ed1cmr8172600plb.43.1692767784368; Tue, 22 Aug 2023 22:16:24 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:4e3c:f4a4:b92a:b5ab]) by smtp.gmail.com with ESMTPSA id 5-20020a170902c24500b001bf044dc1a6sm9969402plg.39.2023.08.22.22.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 22:16:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de Subject: [PATCH v4 06/10] linux-user: Map unsupported signals to an out-of-bounds value Date: Tue, 22 Aug 2023 22:16:11 -0700 Message-Id: <20230823051615.1297706-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823051615.1297706-1-richard.henderson@linaro.org> References: <20230823051615.1297706-1-richard.henderson@linaro.org> MIME-Version: 1.0 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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 73f40699ad..9d16e3c8c5 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -45,9 +45,8 @@ abi_ulong default_sigreturn; abi_ulong default_rt_sigreturn; /* - * 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. */ @@ -58,7 +57,6 @@ static uint8_t host_to_target_signal_table[_NSIG] = { #define MAKE_SIG_ENTRY(sig) [sig] = TARGET_##sig, MAKE_SIGNAL_LIST #undef MAKE_SIG_ENTRY - /* next signals stay the same */ }; static uint8_t target_to_host_signal_table[TARGET_NSIG + 1]; @@ -66,18 +64,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 >= _NSIG) { + if (sig < 1) { return sig; } + if (sig >= _NSIG) { + return TARGET_NSIG + 1; + } return host_to_target_signal_table[sig]; } /* 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]; } @@ -508,48 +512,48 @@ static int core_dump_signal(int sig) static void signal_table_init(void) { - int host_sig, target_sig, count; + int hsig, tsig, count; /* * 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 multiplexed - * 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 = SIGRTMIN; host_sig <= SIGRTMAX; host_sig++) { - target_sig = host_sig - SIGRTMIN + TARGET_SIGRTMIN; - if (target_sig <= TARGET_NSIG) { - host_to_target_signal_table[host_sig] = target_sig; + for (hsig = SIGRTMIN; hsig <= SIGRTMAX; hsig++) { + tsig = hsig - SIGRTMIN + TARGET_SIGRTMIN; + if (tsig <= TARGET_NSIG) { + host_to_target_signal_table[hsig] = tsig; } } - /* generate signal conversion tables */ - for (target_sig = 1; target_sig <= TARGET_NSIG; target_sig++) { - target_to_host_signal_table[target_sig] = _NSIG; /* poison */ - } - for (host_sig = 1; host_sig < _NSIG; host_sig++) { - if (host_to_target_signal_table[host_sig] == 0) { - host_to_target_signal_table[host_sig] = host_sig; - } - target_sig = host_to_target_signal_table[host_sig]; - if (target_sig <= TARGET_NSIG) { - target_to_host_signal_table[target_sig] = host_sig; + /* Invert the mapping that has already been assigned. */ + for (hsig = 1; hsig < _NSIG; hsig++) { + tsig = host_to_target_signal_table[hsig]; + if (tsig) { + assert(target_to_host_signal_table[tsig] == 0); + target_to_host_signal_table[tsig] = hsig; } } - if (trace_event_get_state_backends(TRACE_SIGNAL_TABLE_INIT)) { - for (target_sig = 1, count = 0; target_sig <= TARGET_NSIG; target_sig++) { - if (target_to_host_signal_table[target_sig] == _NSIG) { - count++; - } + /* Map everything else out-of-bounds. */ + for (hsig = 1; hsig < _NSIG; hsig++) { + if (host_to_target_signal_table[hsig] == 0) { + host_to_target_signal_table[hsig] = TARGET_NSIG + 1; } - trace_signal_table_init(count); } + for (count = 0, tsig = 1; tsig <= TARGET_NSIG; tsig++) { + if (target_to_host_signal_table[tsig] == 0) { + target_to_host_signal_table[tsig] = _NSIG; + count++; + } + } + + trace_signal_table_init(count); } void signal_init(void) From patchwork Wed Aug 23 05:16:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1824449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=MfpiO4YK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RVvdY5qHxz1ybW for ; Wed, 23 Aug 2023 15:18:57 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYgEJ-0004xU-Bm; Wed, 23 Aug 2023 01:16: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 1qYgEG-0004wa-Uu for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:29 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYgEE-0000tF-Md for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:28 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68a56401b9aso1962804b3a.1 for ; Tue, 22 Aug 2023 22:16:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692767785; x=1693372585; 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=MF9qpDyL1+Jx07it/Adc348RqrT40R2QZvOOKU6UpHk=; b=MfpiO4YKCTuzTwiXQH96DPVy+i7PG0zMdcQjNJuBJ07BfE746EEE81fGnWTl1fDyhB qUCnLojJIw+4QCNWSrX9sFIexkr5JfXOoSgcVEZ+YHZHM+C7/N5+8ff8pacVzZNsxpNy H/qssMS7UQMxcyigs18JHD+c5d9NnHBHzlKAKTPaciLf3gPc5LDqxV2/MTacpv00SfmX nDz1/ogc6gczBsRfXCWHTGp/hDwFFZgsck9cdcehLoabkKBZ+/cP33nM38CHMbnY+ZAQ DzLteF13pUVnXrrAYRVVT98Jno9OgflTtBsN06Yr+hwkLscI6VkI1YB8G6HB8blFrHoa eY6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692767785; x=1693372585; 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=MF9qpDyL1+Jx07it/Adc348RqrT40R2QZvOOKU6UpHk=; b=E5sOw/ZGa6n8xYuqIPaRW7/DhTAzf7dClDDp3nEo7lQhJNtJpdcg7OrDZxXx7vV4ax 0sSoDOM81gh6zlzYykuk3auQkPuWIGevBzEl9x9IvWD3u5E1Cl/itIrLR5ID8if3cZpV 86/r0GlyyvmP4llmcGRGOM11M5PZ1MRkTr7VCSX4xgXMEMsw0ukBOKalVslr3k0sxaV7 n6XOJR7eE+VciFUkEBF0FSePGa45bfyb2cqsmqiC3GJoDZp3701W3m/eNOfqhnGc5hml HKUoWkYxfZ9pjE5fwzEoif3B+xuE9R0tlIThz8bYqSSD5Q4coGlM4A6eBOg0XGCpwdTh 7umQ== X-Gm-Message-State: AOJu0Yw/1rPY7la3fBxnlI/Q/FeB0Bwz/Jsx8yT/W14xW1bIIOvo8Fa3 GjXXDFr5ZWoiUIhfSV0rJCsCW2oBZRK4JhnxnSM= X-Google-Smtp-Source: AGHT+IGBA7XsPzlw7Kxx/nGMMK5e/NNQfi0oos6rg3HeST9w8vdd6e3k/fI6szHy9qrJL3IFy+y6sg== X-Received: by 2002:a05:6a20:9148:b0:118:e70:6f7d with SMTP id x8-20020a056a20914800b001180e706f7dmr11353660pzc.10.1692767785351; Tue, 22 Aug 2023 22:16:25 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:4e3c:f4a4:b92a:b5ab]) by smtp.gmail.com with ESMTPSA id 5-20020a170902c24500b001bf044dc1a6sm9969402plg.39.2023.08.22.22.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 22:16:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de Subject: [PATCH v4 07/10] linux-user: Remap SIGPROF when CONFIG_GPROF Date: Tue, 22 Aug 2023 22:16:12 -0700 Message-Id: <20230823051615.1297706-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823051615.1297706-1-richard.henderson@linaro.org> References: <20230823051615.1297706-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Protect the host's use of SIGPROF by remapping TARGET_SIGPROF to one of the RT signals. Signed-off-by: Richard Henderson --- linux-user/signal.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 9d16e3c8c5..b8913968cc 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -523,8 +523,15 @@ static void signal_table_init(void) * multiplexed over a single host signal. * Attempts for configure "missing" signals via sigaction will be * silently ignored. + * + * If the host is using gprof, treat SIGPROF the same way. */ - for (hsig = SIGRTMIN; hsig <= SIGRTMAX; hsig++) { + hsig = SIGRTMIN; +#ifdef CONFIG_GPROF + host_to_target_signal_table[SIGPROF] = 0; + host_to_target_signal_table[hsig++] = TARGET_SIGPROF; +#endif + for (; hsig <= SIGRTMAX; hsig++) { tsig = hsig - SIGRTMIN + TARGET_SIGRTMIN; if (tsig <= TARGET_NSIG) { host_to_target_signal_table[hsig] = tsig; From patchwork Wed Aug 23 05:16:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1824448 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=We7Zcoyp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RVvdT6mfHz1ybW for ; Wed, 23 Aug 2023 15:18:53 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYgEJ-0004xF-0W; Wed, 23 Aug 2023 01:16: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 1qYgEI-0004x3-4h for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:30 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYgEF-0000tY-OV for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:29 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1bf092a16c9so41295065ad.0 for ; Tue, 22 Aug 2023 22:16:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692767786; x=1693372586; 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=M9nEQb22Vi1UF1dUb8GzU/CvfTl2MHdw8gP+pRmxf80=; b=We7ZcoypwsN83nU6AT5pA20G536fzY+1J2h4IpXAX71VdWXYQtHCAER4NrfgcjHio5 lCMJMcnHr2aadKYU7HPMAbFVcFNrjDESez0TNr4O8IdKmJL3OJpnrqhtbUZYJ69wXhyg hQO+1zZ8oQ+VF7DgH04DKAkYhF/Xjvebu3ioScYsH23nzRwaucuXvhQMNkvJ9NqoWhRp dJ1F5ztB7EbLXZez1xKxEMtL7igjP4K6sNqoF8yCxOuEBugliqp9IYgoO4Lk8TAuCtGm CyCUEbjTtyGLR2SiZibNxpEH8CLt5g5ggq5Q4pjgLDaxrzculvsujmaoZPvNrg/uOpsZ eAGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692767786; x=1693372586; 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=M9nEQb22Vi1UF1dUb8GzU/CvfTl2MHdw8gP+pRmxf80=; b=FV3zl3f+j0aN6VXqZnvw8izfg9Qey8Po6sX135mlk4bR0yR1o1fTHmRnEoe9/NT/0E /7gBaEx1i3eWGYiAbdZf9j0GdbzLYX4jkHySrDh2J5ThmGU1iY9FTUioDlCQ4m0ol1PJ yIgpKMEsmKJz4hogLmr9Xc9qWw+Qvyz3UcTo7JuRSnSYr/mEpLLMgPbOt3TpBQipeOTk jllBOnixtqCcOQBFsWc6ExDKcBk2SVSEkGS2Q5ZEbYbnLvwRMgATj5MBBNgqsv8qR4dK ZuG5RDFfGklz9nj5UoW7M/CaxMZSw5dzAfr5ne36ELPBD6GjsqPGmN+6E6o81UjlA/k+ znGw== X-Gm-Message-State: AOJu0YzNMmGF8x9amR/q8Hc5QNUdqfiKo7+nTK/8IM8wMbyXDMqHKt7G 8cvT5YBp4VvhkzYxaz2dNRqsrh0hms2kM0PmCrs= X-Google-Smtp-Source: AGHT+IGJWyotsnHwY8d/tMB6caCv3Eo6WunSEkwjO0X0HUmV2t06DDBOzNVVeNlkCt9G3esVPbJ2+Q== X-Received: by 2002:a17:902:e846:b0:1b9:e241:ad26 with SMTP id t6-20020a170902e84600b001b9e241ad26mr14829987plg.9.1692767786328; Tue, 22 Aug 2023 22:16:26 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:4e3c:f4a4:b92a:b5ab]) by smtp.gmail.com with ESMTPSA id 5-20020a170902c24500b001bf044dc1a6sm9969402plg.39.2023.08.22.22.16.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 22:16:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de Subject: [PATCH v4 08/10] linux-user: Simplify signal_init Date: Tue, 22 Aug 2023 22:16:13 -0700 Message-Id: <20230823051615.1297706-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823051615.1297706-1-richard.henderson@linaro.org> References: <20230823051615.1297706-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- linux-user/signal.c | 47 +++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index b8913968cc..a6917eadd8 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -566,10 +566,7 @@ static void signal_table_init(void) void signal_init(void) { TaskState *ts = (TaskState *)thread_cpu->opaque; - struct sigaction act; - struct sigaction oact; - int i; - int host_sig; + struct sigaction act, oact; /* initialize signal conversion tables */ signal_table_init(); @@ -580,28 +577,28 @@ void signal_init(void) sigfillset(&act.sa_mask); act.sa_flags = SA_SIGINFO; act.sa_sigaction = host_signal_handler; - for(i = 1; i <= TARGET_NSIG; i++) { -#ifdef CONFIG_GPROF - if (i == TARGET_SIGPROF) { - continue; - } -#endif - host_sig = target_to_host_signal(i); - sigaction(host_sig, NULL, &oact); - if (oact.sa_sigaction == (void *)SIG_IGN) { - sigact_table[i - 1]._sa_handler = TARGET_SIG_IGN; - } else if (oact.sa_sigaction == (void *)SIG_DFL) { - sigact_table[i - 1]._sa_handler = 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 = 1; tsig <= TARGET_NSIG; tsig++) { + int hsig = target_to_host_signal(tsig); + abi_ptr thand = TARGET_SIG_IGN; + + if (hsig < _NSIG) { + struct sigaction *iact = core_dump_signal(tsig) ? &act : NULL; + + sigaction(hsig, iact, &oact); + if (oact.sa_sigaction != (void *)SIG_IGN) { + thand = TARGET_SIG_DFL; + } } + sigact_table[tsig - 1]._sa_handler = thand; } } From patchwork Wed Aug 23 05:16:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1824443 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=sAzrnDjA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RVvbw1qslz1yh4 for ; Wed, 23 Aug 2023 15:17:31 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYgEL-0004yV-Qh; Wed, 23 Aug 2023 01:16:33 -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 1qYgEJ-0004xl-HE for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:31 -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 1qYgEG-0000tj-Tp for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:31 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bdca7cc28dso41696165ad.1 for ; Tue, 22 Aug 2023 22:16:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692767787; x=1693372587; 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=Rd/JAW+sPFhTSaNKV0zPbZhlNEehxWna67gnUamPROE=; b=sAzrnDjADtEPs0fYVdyi6WEIN4aZOB+g+alB9E/rM1uQKnNgU1lmsQpxXvas5RxAyQ iTsP1SIKaEn0Q4xByYZGhvQ/yMO4bCCfDOYLWyRL51nMxNoE1G3Bhmn3jHexz5ByHf2K xDsP5OuUXDp5BHvu780W5mMOlI3NQsijyjeUYcALXCTHSNf8XxCsIHHH1/MbirzEH2ZS CRu3/Fm7S5K7rIJ+me9ObIJwOZsfQnaw3XfM3HZ9FXmHjy7bpXI87FwulX3+9NNKIEzv FthY/EijNmFFpebbZMvCzKsLyr0lB4H8e8M+cNDohVoBMi5FssV2kl6cKsRNnDpJlVHb wAKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692767787; x=1693372587; 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=Rd/JAW+sPFhTSaNKV0zPbZhlNEehxWna67gnUamPROE=; b=gkcSN2d3tHk10AMTvyvgqaRlWJSa6nk5jCqgk3Dutk9jU5g+9cF5N/WHd0RsE3kX5U GzvDcqfNYwloPVLu4YJ7C2bVdENuEU4jODWIN0euwa2gX9giFve9Kmy/y0Cwqpqhxg6c aMCv7RtBr6RqLR4GhB6Caze8DYI9mDF8g8ONU9COQ0w4NhbVNurbXNYYCJMDq6msOlKe ZI0e3OKBWTJ72kQ3UReXCUOcZ84K55XqhA6WOIATp5Oph5aNiGSMgtvl5UbH2QA4msYk i6GLcn+Sddg4E9UrWUApaHXGWZVKAxfJPYaUGDx1lFHQ6V6GlojFMZiTLhC7ipOauwRA NIbQ== X-Gm-Message-State: AOJu0YwEjS7NL2uLoCAkrUS0F4C7cB63vRiETu+jShTsATWouNdGoNd+ ykBoPqEqjxvwLuajRBJqkQmeP4yeQth2dBmZXEI= X-Google-Smtp-Source: AGHT+IFpyvK8zj5rs7xP4w11xWk7fNgmCJ3etkImBYXLKN93Jp8wdYcGLBOj5CFebs1H2FIJ4qBW5g== X-Received: by 2002:a17:903:2446:b0:1b1:9233:bbf5 with SMTP id l6-20020a170903244600b001b19233bbf5mr13342984pls.57.1692767787471; Tue, 22 Aug 2023 22:16:27 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:4e3c:f4a4:b92a:b5ab]) by smtp.gmail.com with ESMTPSA id 5-20020a170902c24500b001bf044dc1a6sm9969402plg.39.2023.08.22.22.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 22:16:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de Subject: [PATCH v4 09/10] linux-user: Split out host_sig{segv,bus}_handler Date: Tue, 22 Aug 2023 22:16:14 -0700 Message-Id: <20230823051615.1297706-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823051615.1297706-1-richard.henderson@linaro.org> References: <20230823051615.1297706-1-richard.henderson@linaro.org> MIME-Version: 1.0 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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Make host_signal_handler slightly easier to read. Signed-off-by: Richard Henderson --- 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 a6917eadd8..68ceb2e4bd 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -815,6 +815,80 @@ void die_with_backtrace(siginfo_t *info) abort(); } +static void host_sigsegv_handler(CPUState *cpu, siginfo_t *info, + host_sigcontext *uc) +{ + uintptr_t host_addr = (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 = h2g_valid(host_addr); + abi_ptr guest_addr = h2g_nocheck(host_addr); + uintptr_t pc = host_signal_pc(uc); + bool is_write = host_signal_write(info, uc); + MMUAccessType access_type = 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 == 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 != MMU_INST_FETCH + && !in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { + die_with_backtrace(info); + } + + maperr = true; + if (is_valid && info->si_code == 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 = false; + } else { + info->si_code = 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 = host_signal_pc(uc); + bool is_write = host_signal_write(info, uc); + MMUAccessType access_type = 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_with_backtrace(info); + } + + if (info->si_code == BUS_ADRALN) { + uintptr_t host_addr = (uintptr_t)info->si_addr; + abi_ptr guest_addr = 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) { CPUArchState *env = thread_cpu->env_ptr; @@ -826,73 +900,23 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) int guest_sig; uintptr_t pc = 0; bool sync_sig = false; - void *sigmask = host_signal_mask(uc); + void *sigmask; /* * Non-spoofed SIGSEGV and SIGBUS are synchronous, and need special * handling wrt signal blocking and unwinding. */ - if ((host_sig == SIGSEGV || host_sig == SIGBUS) && info->si_code > 0) { - MMUAccessType access_type; - uintptr_t host_addr; - abi_ptr guest_addr; - bool is_write; - - host_addr = (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 = h2g_nocheck(host_addr); - - pc = host_signal_pc(uc); - is_write = host_signal_write(info, uc); - access_type = adjust_signal_pc(&pc, is_write); - - /* If this was a write to a TB protected page, restart. */ - if (is_write - && host_sig == SIGSEGV - && info->si_code == 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 = true; + break; } - - /* - * 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 != MMU_INST_FETCH - && !in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { - die_with_backtrace(info); - } - - if (host_sig == SIGSEGV) { - bool maperr = true; - - if (info->si_code == 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 = false; - } else { - info->si_code = 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 == BUS_ADRALN) { - cpu_loop_exit_sigbus(cpu, guest_addr, access_type, pc); - } - } - - sync_sig = true; } /* get target signal number */ @@ -933,6 +957,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 = host_signal_mask(uc); memset(sigmask, 0xff, SIGSET_T_SIZE); sigdelset(sigmask, SIGSEGV); sigdelset(sigmask, SIGBUS); From patchwork Wed Aug 23 05:16:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1824440 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ss8u766f; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RVvbw19fKz1ydy for ; Wed, 23 Aug 2023 15:17:31 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYgEN-0004yr-F9; Wed, 23 Aug 2023 01:16:35 -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 1qYgEJ-0004y3-QK for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:31 -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 1qYgEH-0000u1-KY for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:31 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1bdbf10333bso41523605ad.1 for ; Tue, 22 Aug 2023 22:16:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692767788; x=1693372588; 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=ONpVouFAHtBaoT5On3cpK1SzlinIIZiyWi2CcqB3oSk=; b=ss8u766f+o5EzqsSmtj8hJaYEymENBSIs2870Ow/WUjnu5HXxuCxSecokV1Wah7Izx F70tZN8+Vw06tfhV7RM+ea4qiPHPJe+Ziwr/hq6VT55A2O9VsAnn4QS76EJce67c5X/2 yKXHm4tnJKbvGqFOD1+P+DZZfPbKK7IBLK9JuaapiEVMaXpzlsVgA/s3GsW9BBkRWvhi 85mW9NSps3q+h8ftG+4r9W2uI3202Sw4FgUZ+L43Nl6HszJ0vV4zDkLGIcgBaSYwCX47 kZcl/8jJjaSWm62U6/afQ8PmXnDovDnFsFPakY6GSCPy+hyKp1UyGU3tfyXqtZMro3f/ RLNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692767788; x=1693372588; 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=ONpVouFAHtBaoT5On3cpK1SzlinIIZiyWi2CcqB3oSk=; b=B4Dm+Y6QmpggxGiMS0Lr/3ZXUsj0U1Zth9bt/mGzb0Gl0g6b5yMHiPxXYwcclQSHoD tURFcGM96nxMjM937SGS8THfDlcNKBzfNj/M/F0STvWmcxOfL9+GMaF+5D+CIGMG+1tG pHZoVjY5jQrEitQ8qIk+38trayZI51nO4oQVK2uFi9UlONtqrxQ5dNFlc6ExjqAukYqX WxzCcnrlz6GwVlu5I4u3RlrCLUON0C30aLVEeRfsehITE1634Xlt0yBPmTH87zSoGCG1 8jA1BolZSoJP1NMNrglKGOeEDaAEaspXk5XE2RtVGpQ8atT4kSbEBtAwDep650huf8zn k0aw== X-Gm-Message-State: AOJu0YwXoz2I/RbC00jhT1Kkp+leaAaaG59eDheWgA84bQysqw+8rfpY /V+cHnHFnzl+xt7YSudMLwuIyLOX2cnEHpcA2K8= X-Google-Smtp-Source: AGHT+IEFtVmk5VxxL0ATNmLp8/bvdzCpGv9+P0VSzhCgiwatyWeuWZYIn+MrK48qp+Z6cat/r2AEQg== X-Received: by 2002:a17:903:2344:b0:1bc:8394:daf with SMTP id c4-20020a170903234400b001bc83940dafmr15272526plh.19.1692767788392; Tue, 22 Aug 2023 22:16:28 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:4e3c:f4a4:b92a:b5ab]) by smtp.gmail.com with ESMTPSA id 5-20020a170902c24500b001bf044dc1a6sm9969402plg.39.2023.08.22.22.16.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 22:16:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de Subject: [PATCH v4 10/10] linux-user: Detect and report host SIGILL, SIGFPE, SIGTRAP Date: Tue, 22 Aug 2023 22:16:15 -0700 Message-Id: <20230823051615.1297706-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823051615.1297706-1-richard.henderson@linaro.org> References: <20230823051615.1297706-1-richard.henderson@linaro.org> MIME-Version: 1.0 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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org These signals, when not spoofed via kill(), are always bugs. Use die_with_backtrace to report this sensibly. Signed-off-by: Richard Henderson --- linux-user/signal.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 68ceb2e4bd..6d13b5c210 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -904,7 +904,8 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) /* * 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) { @@ -916,6 +917,10 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) host_sigbus_handler(cpu, info, uc); sync_sig = true; break; + case SIGILL: + case SIGFPE: + case SIGTRAP: + die_with_backtrace(info); } }