From nobody Thu Nov 28 10:46:05 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=1692767872; cv=none; d=zohomail.com; s=zohoarc; b=j14OgO+pUnxAKa19jP7UMlPvei6zvTtxSQTfH0sAvd5ZyG20N2b4kbpZav9YsUjrwC0P3bASGKtQqlvkEB8UP3aBRitoqYYsZ7I2OoxEG0CZSkxjZ/mr98s7Ip84UDR4/STpEjzVMbkyUlX/Q8FtMUHTyGRFy5tvQNWZAvpfZ4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692767872; 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=dcsO2dVLbPUl+GizLMpXodQLIxyTwrwgsESLGfn+SH8=; b=JZnnU6SMIyuNkUM7sv2pb/vtHR5dvS4XosmC3cEorbafQVt+dSfmFt8M7U81DURxAX3K1DjvDARGdvjWcZbUIVZDZiCKz2wpck5svrqIe2m+cLQRvm/ALAwCMt+kRw4e2O6PMY/MC3HM4RGzpR6FZJlv18DWOsop0plIZDo9lzU= 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 1692767871991972.2098157457394; Tue, 22 Aug 2023 22:17:51 -0700 (PDT) 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) 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) 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) 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 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::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692767872330100001 Content-Type: text/plain; charset="utf-8" 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=C3=A9 --- 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, } =20 /* abort execution with signal */ +static G_NORETURN +void die_with_signal(int 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(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 tar= get_sig) CPUArchState *env =3D cpu->env_ptr; 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); @@ -725,29 +751,7 @@ void dump_core_and_abort(CPUArchState *cpu_env, int ta= rget_sig) } =20 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 =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 Thu Nov 28 10:46:05 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=1692767968; cv=none; d=zohomail.com; s=zohoarc; b=PWTriDfsNL+MovnHfmZw1HqBAu4/Ohhg/ut1VDA44DKuFIfoJ4BEYHfAVCx+fWb6S7sPvEcld6+gZnsn6f/tIoKHszTNmnDipy8cKWWJQHBcHm52kwK2rTAAsMWKi7Xbvgk8XZ/H0cjRfvE6HYJHVrZ3V0YCU40kI7PsAqhZCb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692767968; 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=rQp++5N0yIEsVmUaGN89LifNvR6oAeooLY4sPs12hmU=; b=kFLdSRpMOX7oSfhJ1J6SH0dWR7CCxaz+9ajgFVD2ktKF1sYUCpxGd3KKA9+eY6LCzVgvwbQSkIHZ59RhB4CbkvfvL4Y2/TTNJzbyhssycMQJMiRqKZKsSv/O8umQTRP1XhTxVS1PM+2BMVrtb0Vyx6ubwL8QWMTY7gMQ2Esb1Qc= 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 SMTP id 1692767968762223.9788088629008; Tue, 22 Aug 2023 22:19:28 -0700 (PDT) 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) 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) 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) 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 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::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692767969344100001 Content-Type: text/plain; charset="utf-8" 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=C3=A9 --- 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); =20 /* unreachable */ - abort(); + _exit(EXIT_FAILURE); } =20 static G_NORETURN --=20 2.34.1 From nobody Thu Nov 28 10:46:05 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=1692767858; cv=none; d=zohomail.com; s=zohoarc; b=cZO5lSAOTYYVTP22bD7KYYzmMyjNCM6NLLEjaq/4gpFmK+Kts1fG6IsfTTImQ1aRNAxFF9ePweQzJNJJzwIot0lD7puwtOLaAVMEekwDI242PoVAbHIXyPDoo/XwD8iWtub7vnwXm5Jd+mEsT9kEd5NR3U02BcisGEaNoFDefH4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692767858; 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=rn4m/BUkUlHqvAP+qKbf9mRxMLOIUsCoPFyrQpA+ZgA=; b=ho5Ujec3Cn3l4Rm68ioMUTRSWuqO590igss6m91YbgxhDRUE7XcjR1Zr3HjNBF5aDD/yuHpSMZ23xSGasOsRz0jST+Yak2T+Q4Gy8GdXcSnOEUaMPVJgICWA3toqeYhG62a1gwiNMrkawoZqmxl5G4/AL7emNGBqNH0PExCmkEU= 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 1692767858732131.40541342147333; Tue, 22 Aug 2023 22:17:38 -0700 (PDT) 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) 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) 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) 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 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::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692767859178100001 Content-Type: text/plain; charset="utf-8" Describe the convoluted way by which we can see ERROR:../alt/accel/tcg/cpu-exec.c:532:cpu_exec_longjmp_cleanup: assertion f= ailed: (cpu =3D=3D current_cpu) Bail out! ERROR:../alt/accel/tcg/cpu-exec.c:532:cpu_exec_longjmp_cleanup: a= ssertion failed: (cpu =3D=3D 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); } =20 +/* + * The system abort() will raise SIGABRT, which will get caught and deferr= ed + * by host_signal_handler. Returning into system abort will try harder. + * Eventually, on x86, it will execute HLT, which raises SIGSEGV. This go= es + * back into host_signal_handler, through a different path which may longj= mp + * 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) { --=20 2.34.1 From nobody Thu Nov 28 10:46:05 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=1692767850; cv=none; d=zohomail.com; s=zohoarc; b=IqSMaaDWTiXM85kl9WNkDSLDSbd6JMe92GQZE/w1qijZQiKvoyV75lIRKALC9xn57qE8pu8CC7eV8Mqx3J9Y7tgA6dq42igfcpXgyciahx1XhnYJ/pWe8GBHvKODxwKdfFJReC7nC9QHQR/tOVRpxAhs/yALoHgdjY6pawpKRs0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692767850; 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=p5gfbYEtQOxd0dUyPKXMEvc82rL/zzDhhmw3j/jKEBw=; b=feXlYREMJiP7iBNzvh/dV4Tj3i9PrL1c08hUuMZ+hhQEgCYtO8g2cPllnVIv8p6zaQ7RiHFoKYQmQqcEHaoLXXXwrVdnE58d7ZNwMQ+LT8dB8OndiyBuI/zBH0q/dwsfEDCdm2j+suTpGc9fhbM2LHjX9gzlYANK18OYKpEf7lE= 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 1692767850372943.5419981469712; Tue, 22 Aug 2023 22:17:30 -0700 (PDT) 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) 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) 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) 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 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::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692767852232100003 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 {si_code=3D1, si_addr=3D(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 @@ =20 #include #include +#include =20 #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" =20 static struct target_sigaction sigact_table[TARGET_NSIG]; =20 @@ -797,6 +799,33 @@ static inline void rewind_if_in_safe_syscall(void *puc) } } =20 +static G_NORETURN +void die_with_backtrace(siginfo_t *info) +{ + void *array[20]; + int size; + + fprintf(stderr, + "QEMU internal SIG%s {si_code=3D%d, si_addr=3D%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 =3D backtrace(array, ARRAY_SIZE(array)); + if (size) { + char **strings =3D backtrace_symbols(array, size); + if (strings) { + fprintf(stderr, "QEMU backtrace:\n"); + for (int i =3D 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 =3D thread_cpu->env_ptr; @@ -832,16 +861,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_with_backtrace(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 Thu Nov 28 10:46:05 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=1692767921; cv=none; d=zohomail.com; s=zohoarc; b=gq4rUpbtFFUEJu0bASvxWCxwx4xvMc0iSygjffeVKuiYVdCKg4Qpt8AYnCETnu4MlR9wVHd1Cgo4jK8gKwwnvsNJI3S+9cVkikG9ZwXUMm8a1vF8xvK/fDtL7YTYkNbKwQn3oB9AHJ5LKmQqIt40F/EbRmfdxNMwCYpb5Dtpt+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692767921; 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=QVZ8TmDLEIACLc9a/Qe1Sv9+EQSNfIXJRPDML0Xg9Mk=; b=AyhCJOejGuY6eJYu2A+nFrSk0/5nmLzUNoNEK5mNPKrMFrxUbKp1uNedA2d73gvRneIGa//C5Dw7O6Ej0BRbbR4NCgUWfT1p2kN2/fHhcBGr7nnmNxRadfCLeWImCxY/08CPSqfOUFWguD40np96coyogeQ5t3IsRyemMSQjRGc= 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 1692767921189441.09286277212914; Tue, 22 Aug 2023 22:18:41 -0700 (PDT) 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) 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) 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) 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 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::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692767922571100007 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 --- 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 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) { @@ -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); + } } } =20 @@ -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 =3D 0; =20 @@ -1059,22 +1039,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 Thu Nov 28 10:46:05 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=1692767917; cv=none; d=zohomail.com; s=zohoarc; b=BhkVLNnmtqF2vkd8/yDJkrJulqzXwcDVchRaDz8s9W66dgy8+HSVP9DNaYPu0u8KFem7H/tmVwkdFMOK6f1K9S3j9DlFpOGi50yW9BWWxxFQrqGLTHwmcr0RerSjAUsTRlZrW8AgLAFNRboOvDOAA2CUJlv1oHi9bOA5KztfbfE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692767917; 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=TV1TciBhkf4DHVRrzToQTqKckAEQKZ4+I2kgg1P7TXM=; b=FQrXom1kJPoy2lmWTA1qze2gv+p1kTrCtUUq1U/N8HbNWaziMdor1eZmb0kkSLTlaJsUeKAx4H1Jeib4PMlHItvd4RtwpC5Py16WwmEnSzERFHBBzJzxNjRpZz/XxKO6s8ld0HRruzbAyeGzGdkX/A9UA3s+5MjWU/NSH8n8TJc= 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 1692767917727714.9179035620808; Tue, 22 Aug 2023 22:18:37 -0700 (PDT) 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) 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) 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) 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 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, 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: 1692767918083100001 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 --- 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; =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. */ @@ -58,7 +57,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]; @@ -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 >=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 @@ -508,48 +512,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 Thu Nov 28 10:46:05 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=1692767936; cv=none; d=zohomail.com; s=zohoarc; b=LW3BfEtLHe/d8hjjdPf/Kb/9cl/CCRiemO8GYDRBSE95ao5SmlzE2YAvsFDWsIwXjOSDYIWwuBqUp/tszFCcm85trzEER2PtSNyv7xUaAZoGSZ/36uIuqjZ/TpBSaQiEl+0vB6aVQFuxjrYnfa5xuXoOtquK253WwpX2m/+Ugmo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692767936; 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=MF9qpDyL1+Jx07it/Adc348RqrT40R2QZvOOKU6UpHk=; b=VGqWf9uDJatJ3MvqbUJNBVCgyEzdNDjU421qhfj2zVNWVD+a9as8ed3C/troz2ODq2bUqntcqBPfxofud/3UyY/kHukxUF58Hyk0WSYkSAbLYJQCpmv28lPvyu+/l5N78GhU1MUQgjw8lceE7uKX9uiorSsaW9RZnh/mVgpKaWs= 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 1692767936908249.20724621989496; Tue, 22 Aug 2023 22:18:56 -0700 (PDT) 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) 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) 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) 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 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::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692767937558100001 Content-Type: text/plain; charset="utf-8" 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 =3D SIGRTMIN; hsig <=3D SIGRTMAX; hsig++) { + hsig =3D SIGRTMIN; +#ifdef CONFIG_GPROF + host_to_target_signal_table[SIGPROF] =3D 0; + host_to_target_signal_table[hsig++] =3D TARGET_SIGPROF; +#endif + for (; hsig <=3D SIGRTMAX; hsig++) { tsig =3D hsig - SIGRTMIN + TARGET_SIGRTMIN; if (tsig <=3D TARGET_NSIG) { host_to_target_signal_table[hsig] =3D tsig; --=20 2.34.1 From nobody Thu Nov 28 10:46:05 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=1692767933; cv=none; d=zohomail.com; s=zohoarc; b=DONc/HI24d+8kDVQaeXJJOSkrK1b7sWGwbRDIPN0v9CwNpJxk+ghTcr11Cl2PLLI74PSOooxJyVArQowCNQrqu6H5aS+lzxk6jRth4V4aRiCEr9nJNPKVILBhOaHHgeWsmgZMo1KcQlC93hqIx06Conhfx1tlWTAdtBkfzfsUZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692767933; 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=M9nEQb22Vi1UF1dUb8GzU/CvfTl2MHdw8gP+pRmxf80=; b=fBIcFWEm+mfTSRvFSygapQ+NOHPwk3yhq7SajZS/Q31nRyTQaOO8ln5NEoqLkNotEDbn6HSx+s/hmS7779aOcfzmoW2YZf6KOPQz7zoN5Vvcq17NqcOQ+3Fovocy0h52oi7jlzRczoq70il6XRPD3m+DIxU6xY6ZQSAE2HRKxxY= 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 1692767933080686.2709058057147; Tue, 22 Aug 2023 22:18:53 -0700 (PDT) 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) 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) 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) 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 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::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692767933728100002 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 --- 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 =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(); @@ -580,28 +577,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++) { -#ifdef CONFIG_GPROF - if (i =3D=3D TARGET_SIGPROF) { - continue; - } -#endif - 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 Thu Nov 28 10:46:05 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=1692767850; cv=none; d=zohomail.com; s=zohoarc; b=D4reSGa2nxj3JAJBuLYW8Rm1vHlg9SRH2dqe3ZNMBdsJu/7yv20JMEffK9+0tGq37oNRDZEhcyKub15tAX2PiYcaT2Csr72pwGqUG7Y6w3eK11W/ZQ3pdR8/ukcCHVRrjgOahrYGWL1TeyhGCznQr3rEfaxw/Wc8lUyf0wAFuO8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692767850; 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=Rd/JAW+sPFhTSaNKV0zPbZhlNEehxWna67gnUamPROE=; b=lm1FQV1Jryv8G3DuNJI6sSo1k/Ha4Zt628n5AiMpsHi18beQMHjBlw3+dFaepbaAb57cXbVthxTlTzgYT/oxR8LE1aOW1LaRk7MMZfEGoCo0HMxt8whH1d+udyMUgRyTUK1un4eebkuElbMqd0VUJutPcFVClh9U7ig78Mbd+64= 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 1692767850151851.064448047117; Tue, 22 Aug 2023 22:17:30 -0700 (PDT) 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) 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) 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) 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 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, 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: 1692767851453100001 Content-Type: text/plain; charset="utf-8" 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(); } =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_with_backtrace(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_with_backtrace(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) { CPUArchState *env =3D 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 =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_with_backtrace(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 */ @@ -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 =3D host_signal_mask(uc); memset(sigmask, 0xff, SIGSET_T_SIZE); sigdelset(sigmask, SIGSEGV); sigdelset(sigmask, SIGBUS); --=20 2.34.1 From nobody Thu Nov 28 10:46:05 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=1692767850; cv=none; d=zohomail.com; s=zohoarc; b=jmVt4pQzspPeu/vXxpQfvueB2JXlQQzr05ThGY9n1xi8ySvqxwR4phApKz4tRy/a6MoEkOGJkKjMwHLoCSX+z5WX+tkMdKlXKx85t77TkRBEPh5SJxxvMP305St5Mg4o3KiCpCGwUisPqzRWigK/foB8qDu4h+GkmLkqk3aF8ME= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692767850; 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=ONpVouFAHtBaoT5On3cpK1SzlinIIZiyWi2CcqB3oSk=; b=KgEW/DvEK5uLlxbouG5bz3xxMItA2tmSC/4qgM4sf4iJruMUDZYZaX1SpvjfQV6cq0fdOpU88WNC5dLE4rhPyVyDEs/rIfE0HYR733mqhI/9K94OYnBTAVT0hO5vZygmw6ToR0ZzQOsQY9//bjWiJqPeywLYoO2oFTqVqoC0XC8= 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 1692767850312836.8593699879115; Tue, 22 Aug 2023 22:17:30 -0700 (PDT) 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) 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) 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) 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 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, 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: 1692767852393100012 Content-Type: text/plain; charset="utf-8" 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) =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) { @@ -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 =3D true; break; + case SIGILL: + case SIGFPE: + case SIGTRAP: + die_with_backtrace(info); } } =20 --=20 2.34.1