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: 716076 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp622289wrp; Tue, 22 Aug 2023 22:17:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGIO7/WGO71iFpLRSq6FwRaXuA5ZG7p27f4aTFzR8VBphP5FZvD2ZqKmbgKSnNWYtsKgsfm X-Received: by 2002:ac8:7fcf:0:b0:40f:bec4:7179 with SMTP id b15-20020ac87fcf000000b0040fbec47179mr16246603qtk.2.1692767871660; Tue, 22 Aug 2023 22:17:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692767871; cv=none; d=google.com; s=arc-20160816; b=xmVQ380+OA3Y2IMiEPgS0hRusoGMSc7HjlGC2QZf3nkIH4R6V7RglnxanESBwUuRp/ 3dGW/oRXO+9Kpg6IBHlwR3t6Dk9A+QTcm5Sprp1Rk5TgudhW53YIcPNNaRY7AloWDZhw 0xt1zODCSvbb2rlPImt+SQlZdpwAL4WO6dMzV5wZkDglh5YnS5L20PLmG8HulGC81g6c 0I9Wgj6wwZqsdrMMb6lInMJIKy3OI+3nEQLxzj5/PfOGkftChoK5aoeUWcDm4VTA4wm2 JxsnPCrImsWen+MsIVeFoiKGQgqTdLxjlH3giG0CK+yuAhNcMYrxsbWLtZAMlVlaqqr3 Z7xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dcsO2dVLbPUl+GizLMpXodQLIxyTwrwgsESLGfn+SH8=; fh=uta8CuNdWwEUIsmWLQQIuZWY0GOyjYTd4DbN32nR8cE=; b=BLvqxlt8G3jZ67sLLdfP1esA3vq4viU/gX0s1CigmM48RfwUBAZXaLrYGCkuOszOYg KQkE3PWka4EPj5K+4b+t0hspKwVIU/GezEJsa4zp2sJoCIpCH2Xo0fuBx4E9OmgDIwtT tQG73Ze/800o2zkBQdaKYBUD44c1kZZnMWqTtUa1Zc4xS+8KhDZonDCNYSF5cAiYWP5z CwdMMYeGlogNYhKEHTaZC/gcdrbqBsOrw2718Yh64fxs/OOst5jfb5Y/gLauTLXrVBwt OlDdOChP+JVYrm5sYXKwoa/NDk/YQiAGjStX2CyUANEsxQBAyXJaAkZ8uJoOYKG/OZ7X vDrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KY9jrHfr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j19-20020ac85c53000000b0040348b08cc6si2271878qtj.300.2023.08.22.22.17.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 22:17:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KY9jrHfr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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: 716081 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp622677wrp; Tue, 22 Aug 2023 22:19:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUvBt77r2FsST/j31wTrhVlnWzgrLKpkdYQSBx077YCuYT9NEXoBk4S8NBoSUkxa6AXo37 X-Received: by 2002:ac8:7c44:0:b0:40f:a358:46b4 with SMTP id o4-20020ac87c44000000b0040fa35846b4mr15260484qtv.13.1692767959175; Tue, 22 Aug 2023 22:19:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692767959; cv=none; d=google.com; s=arc-20160816; b=uKqv66Zxd2teY4LTz3F/Uh/zh7kSS0Lk3PnTGHKfmJZClw+PuUTxpX1qizms9V41+h a4UAua6XuyTLwJcx/jVoVSUa4oyom+FUeXFuLX3qYqesJrufdb0S2cBTD6wm46bd4nOZ QX2IXdd7Ni8wL24AmdHwLlQYblBSSyFqMLEJU086Gj61maiWczhp9B3Y5F30L+vsVTff qevdAzNTdlBWSKtY82pDXaS/qlQ0QTUuuRxqdDfNppZcPHLryVpwd7/Yfw+hoOLqV1bZ 44sdNGfeFH673uh4WilMq39yPgQMWPnvwK2DNEJ4fj1P+LqPXwLLCcm9vE9gv77NuCxy mx6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rQp++5N0yIEsVmUaGN89LifNvR6oAeooLY4sPs12hmU=; fh=uta8CuNdWwEUIsmWLQQIuZWY0GOyjYTd4DbN32nR8cE=; b=V+S8RaQexwZBF1VFPuS/dB56ippHHDxTl/dPbFHdGbp6fRMmcU4CWuKfKrKz21mCR0 cSkGnoPFgoSm29eBgeZGnV/zsKeTnmVz8r2o999O/7JM+/VkLsRn/bdBIBHFXFVYiXO0 lr9qZe6MOE2oie9o1ys/F6KE88HGqbO1hEXcVdb20hnG7VqAVhneAzUsVbxXgiHT8R4m 3VuYe9QMEqJxQUNG6GuUdVM+pOdO98wpLHFwPDcMC+ZWt0n0FJPb2PBCjXTEpGhw+faV lPJKeK+cIowWNSjgMMfWS1IhhMUY2LTNb12KGWiYi7H/VuD2ynT4vaEZ7HMV4MesY4e/ Icbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ltXosM/H"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q11-20020a05622a04cb00b00403456965fbsi7356556qtx.610.2023.08.22.22.19.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 22:19:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ltXosM/H"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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: 716075 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp622242wrp; Tue, 22 Aug 2023 22:17:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHwTk8yMUCJtkV0EUJeDmkZ8zv+cB4J4gXbPdY61W+10ZFpVIqmXaSsox8tFXE7IUmHip5c X-Received: by 2002:a0c:e551:0:b0:64d:b496:7cb9 with SMTP id n17-20020a0ce551000000b0064db4967cb9mr9294673qvm.27.1692767858410; Tue, 22 Aug 2023 22:17:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692767858; cv=none; d=google.com; s=arc-20160816; b=P5x2DFa9HAFiLIdOyDitQE1UH/kM9QQTnx2fggY6aB8wNKBvC1glr/zQhVmJrDmiv6 iWXJzKLu7lla80IreC5IpJZqB7RSbZb6aspWeKa1WS2UEOtygELFzIqRF6S2aEQC8Nny Ku0r+1f9kMdMbwE3xHNvZ1U1ZmtSJze235xOdA2Dgf8uMXEAse5nq1rEvuT/OI0e79n9 vl/iP6IBJzmAJiXCo6CB1Ogz8ltS8eY9OMQw0gOkm0Kg+n22kMf0rScVEcDM5Z2DHQ3R rwEhYUt6bFeSKMR9VgUkHj1T919WYf2GUd5jDtdu/6AGywuRFZnYwLDRCayxLGcHqZgi DOfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rn4m/BUkUlHqvAP+qKbf9mRxMLOIUsCoPFyrQpA+ZgA=; fh=uta8CuNdWwEUIsmWLQQIuZWY0GOyjYTd4DbN32nR8cE=; b=N5R8ri8I3JbTApesCYjRDrNwJ4RfMAo59ZFVQbIXwVqJVYB5ZLwBhB3tEsIZQlVdSL +V2KsjLLzv0f00TPeK16JDwSgfvS+rHU0Zq99do0gvZ3zD2xDQA8uJO5dQCvsRuhXCGB ZDr8Z5+/wWonQ5wMQKLnA6pfVOwqrer1FfL0SvsOwSg+0wd3YRamGfSOvPuRs1FKFxQl j/68S/N9oxvtzNE5tY93IwkJM5iFgCngwsskhQ2BocFH/LT55h2UDBbmTtpdjkjmCmqq F8CQin+V+14ytmKrEo5emgDmf6j5JSQjPgaPBx3Rh6XogHkMh7fDLHxPguUauamxE/YV anYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tfL8+yP7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m15-20020a0cf18f000000b0064f42b1ab16si3435829qvl.154.2023.08.22.22.17.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 22:17:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tfL8+yP7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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: 716074 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp622207wrp; Tue, 22 Aug 2023 22:17:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1ZIlCWmYG4b3aKBGk+0qeO0FJaUx9w3sxzL4Zb8NPGbMW8kHhmDellrN+yFkz6+sVdV+w X-Received: by 2002:a05:622a:144a:b0:410:97fb:38ef with SMTP id v10-20020a05622a144a00b0041097fb38efmr8679652qtx.2.1692767850102; Tue, 22 Aug 2023 22:17:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692767850; cv=none; d=google.com; s=arc-20160816; b=FNINmLyqL9/lYSPcWzDnRLszUFpMGSAMONAzG4cvaSs3pgubOhMuwPyhlgZsg3kdOc kj6Pe6xWDS6lmDfH430zcMqkGxC+dQXoO7R2T8e1SVYNSKQmCKiXAbbtk9KF7RNndMOd 8r0NEtBHa7XFlnDTWayGJBm7lWMEUbgvWe+HPx+ltH1/Sg1PSC4QLN2bJvTp4fFu3Z6o Ga7PoFqi1Ap7m06wnKvcKyTwNSCTl+QgfjJZ3H79LR1AET8dWWAwzXdRaTR5HRKADcm5 FEuSHvE0EFRi4dq/b1UA7PxQhcl/rkFzlRIOKEgM/MCEsVCMNwGUQkFoqJKZ4R/JdbG0 6kcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=p5gfbYEtQOxd0dUyPKXMEvc82rL/zzDhhmw3j/jKEBw=; fh=uta8CuNdWwEUIsmWLQQIuZWY0GOyjYTd4DbN32nR8cE=; b=mWOQ2clgZ4eoBFwSsicODh7VZBzZCT90d8aY1TpKYfQr1n9AhrsmRSfoQDHbToivQ2 nj4jEAMAqCIfyNIbCN9cugGMi/0FfWkH6t9daUJicghMU51YAB1ftC4c9RT4XvFMWbqP Rxci9w8md2CNM+WfCoSWpZuuvFDfOk7NaTqq5qfdqFh1vMhjIIAm8NaHjBb9i1NT576F I6ux60kT2qyhV72AOOOMez2+0sGU1RucZqLUEcfhzGzjyclAhRXhlkpU569bUkK/TCIa YCz5bifQ1Ct8fsmNtmNmxSkHsRGjsEIrwqnB78Y98n+xkNFEP3NZ0kQgNR10ahhAcVst Goaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KDYu0rnb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o16-20020a05622a139000b004053df1583bsi3049064qtk.180.2023.08.22.22.17.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 22:17:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KDYu0rnb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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: 716078 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp622506wrp; Tue, 22 Aug 2023 22:18:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkRwQHnYgIHzlFAd7KOq3iwE+E0V7uu0nHytgAi1nUiq9RSsTm8jGUKLYPqkYetVV7Mx0r X-Received: by 2002:a0c:aadb:0:b0:64f:3f26:6879 with SMTP id g27-20020a0caadb000000b0064f3f266879mr8856520qvb.2.1692767921039; Tue, 22 Aug 2023 22:18:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692767921; cv=none; d=google.com; s=arc-20160816; b=IilGfHd76ldcrK3xLcp80TO22tIRYD1ayNwY6nxnwg9U63d765a5fFS2U38SDyOSYK Cd/IAiwYea8g7H6g2mKto25qNtbmg5J8sswcuTNfl/40/AOwUXxcwq0FMjy4qkeUnzyQ EChXFeJYRSfnHQTXvlK6zfeQcdRJHGlH/FXYZpylbIOUG1oLNE7mWEKK3oMHsefMMtB7 MHZ++eHmbtWmCK6PqSp7ol9KWDy8012hnCS8Oh3EwSsgYP2DeSFaENs6+Q07zCw76ARV P/Ur+VJAEk8BfLkh8pIBgvnpPoVoDfBE0IKvmwWa1pxPg+0nFT7O2xvgey4APxIzXTM1 KS3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QVZ8TmDLEIACLc9a/Qe1Sv9+EQSNfIXJRPDML0Xg9Mk=; fh=uta8CuNdWwEUIsmWLQQIuZWY0GOyjYTd4DbN32nR8cE=; b=TsTXg24yKSEPpzoKWh5FaI7HGXA9ielw14PeDvcu9Mr9VhIjw3WbcfQFYFJB8OZHaw fSznrorcDLPk2/vj+4BecChgkEvTjl6uFWU3Y8QA3ImzURN7w7I54oUs3ZURzIH90Dxt 2xvs8zENZsT8eMe6bKWXUDoc7z3pblxeriLIWboiOclexs35owDG2aY1WyAWp3my8Wls MK5pswhSpO+nIp2H7Rh04ya7x0et3nj1saScncKO86rxBR5z7j11mfVxAgOAyRIrpo8+ TyIiYeLJGaS5+hICT+kIMkvAIbtGH+Qj7f7MZTZJxsTlZ/9iSaCqSZ/FfS++HNzu+PvJ j1KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sQoq9fdj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g6-20020a05620a40c600b00767ee53f0absi7325781qko.340.2023.08.22.22.18.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 22:18:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sQoq9fdj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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: 716077 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp622491wrp; Tue, 22 Aug 2023 22:18:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZgeD/qqxqhhAwsTSQW5491ThEH72ibWAB4CNiDCWkjsuo+ClkeZCpLya+JnvslV2L9v+u X-Received: by 2002:a05:622a:178f:b0:403:ef0a:ac69 with SMTP id s15-20020a05622a178f00b00403ef0aac69mr14875834qtk.62.1692767917690; Tue, 22 Aug 2023 22:18:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692767917; cv=none; d=google.com; s=arc-20160816; b=JQ24iSAJ6Uhkj6TOkDV6W1dpBXUKLUwIuVkSFbVX3gpALAVQ5wFKcBBT1YZgNp1kco LtAmWvGnSGEtjtHZshQfS9M6JVxROignU84t0SqFBkpzeBFp77zc86AJLk7bCknwG3fA 3YGD2UL1tYeIBUH5pNXblX42Jk3Oj2OC7WmS/CSrxfAiSYvP1AMdXZ1amYHI/M9Dxrpc 4Iwyqr51rxV0kl+20xsXuawyunHAivvJpUDUKcOWfVh87lonfsd/Y45HCL3V+RMcNcrU NEzqume7p818g8ufP/rjod6r2cC0VXt2oFt4JQaPMj/aiWjTtqW1nEbU7j1zqvEZJLqv 9c0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TV1TciBhkf4DHVRrzToQTqKckAEQKZ4+I2kgg1P7TXM=; fh=uta8CuNdWwEUIsmWLQQIuZWY0GOyjYTd4DbN32nR8cE=; b=CUuFp0qGGG4N3lNS0bj1ANnBSYwqD7sIY+YqFg+bDVZ+/o41r3KtPY+DfdFqxYvUnG MYpmPRkjlRC7yR8Ps2r3ap9prO9pIHtKJNCEuEo3ElujeU9SO28aw9qSF7mglGk2BnX9 yG8YMg11/toXBnRkPyI1C01zApFR/ZqwT964h8rKy/n3N9m+0R15QQaF83/VZ+vBjWZT qjNfb30rZGe8R0elympSBdOqViqRHuLIdA64bmqilzRF9L9mwYSu9gEr9xifehKxCApF ZX6L+74fbEnD42RN5pmUgY2MhlR1jMGEjmSCCTwWYjWXi6VmNcb8vYm3idk7sZTsxKV2 5ytA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RxAJjeNL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b16-20020ac87fd0000000b0040325117d5csi2139751qtk.405.2023.08.22.22.18.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 22:18:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RxAJjeNL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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: 716080 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp622582wrp; Tue, 22 Aug 2023 22:18:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGAWwe8W9o2/X0agsw+hpuqSK0mVmXQebx4gTvfdQt7FNZ7QsdEbI2jNaP34QlSmLiorma+ X-Received: by 2002:a05:622a:134f:b0:403:996c:9fa7 with SMTP id w15-20020a05622a134f00b00403996c9fa7mr17547196qtk.60.1692767936564; Tue, 22 Aug 2023 22:18:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692767936; cv=none; d=google.com; s=arc-20160816; b=woTcwNogOOQuuRGfK0bE4wWYzk6uGEC2ogIrL2uUvcqBXLb8t5wpYqgDyoScEQOmKc TPAuh8YsmeRNaCrbbr8mVHSyAobWRVKr9m5RAdzu9980deI/xwRIIMcRRK8nfzFq8sQp OlAMhY36M1o6a1fHcySmLZO/uOXIzh6PNVNFwRikyHlsbJnLa/YfsS69qU98qZUZrdBa TR4JeIqW1UZd0XI3wTwtgGXHbwJsu69eJ7ZM3+ulffIWAsfPgnbzh8vWA3V/GzEji5AX WbCsZyZrNybsFsnQd3Gr06Wqdnmjn1GHjKkSE6nuWfFExoENlJzqK+L0PyUxEDG4vph4 7l9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MF9qpDyL1+Jx07it/Adc348RqrT40R2QZvOOKU6UpHk=; fh=uta8CuNdWwEUIsmWLQQIuZWY0GOyjYTd4DbN32nR8cE=; b=qqYp657DlJ0oOrFvh2fvgzo2MJMzdzlxq/jOVpqZSm+DB5pNYT2Hotv0J07lirA9Vn 29MNpmRcDd/Hjib6F1rG9c8x70pBMdYkUP7m2tVP4QOKGCIzup3vpPA8qmwJIH4onivk agcyobVESqiCTmojFfDrvhltIU6388TAC8I5xznxn7Qun7yiRJdiJqxevByAB0DPxYYQ mD/X3FkvVT8GUst2KBj42cTnF0ECwmUwsxqMQhc05P/KOWwpcGEYnracnU9THVTz8aCy Q6yu3Yv+cl/wUs2weBvLQ9E7giD/jIl+ep66dwbqKSwvnXTxCoOAqCPSYGHPi7xkt6bn rXxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MfpiO4YK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s18-20020a05622a179200b00403f3141703si6696160qtk.619.2023.08.22.22.18.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 22:18:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MfpiO4YK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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: 716079 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp622551wrp; Tue, 22 Aug 2023 22:18:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFR5IpDbKhZSHWvhbGNlBimTfeWxCsIHuWJ0fu3sYhydI42AD6MLq9JKt61nmENb2xePaIp X-Received: by 2002:a05:622a:108:b0:40f:efce:dcf with SMTP id u8-20020a05622a010800b0040fefce0dcfmr10554160qtw.16.1692767932708; Tue, 22 Aug 2023 22:18:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692767932; cv=none; d=google.com; s=arc-20160816; b=PNjqBsla2T5Jv9B0G0iU8mpDoyNj7rIxbgy5k1w6DdCbhm6Qfg0JiOdoGoAlePcxPS A7GTBRrj/7LFQ1XT5UXjfDynEt191xfVQKbBESmFL1m41bAHEZvp6+SwhboHNrDE79mB lnW5xvo7r21BU7uEUlu6nq5fPZASm3+71u77wsiP7deq7An4lESSp57Q0Nx5Vbyl+mPN faOlo944VfQfeZAjCZSD8cx8mhzQFGR9V43AFCUAuMCwO8ZuVFV/7t8ctxePNo1X42IR s56nZUlg/JO+iOSxIbsYwNwKmEKejIa/IytxOV+wpnPvBAA2sTisrMFLSbwEhhfxcz3A nvHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=M9nEQb22Vi1UF1dUb8GzU/CvfTl2MHdw8gP+pRmxf80=; fh=uta8CuNdWwEUIsmWLQQIuZWY0GOyjYTd4DbN32nR8cE=; b=FwB2Gl1YwM4pA4c03hGzh1ACwkh+f4GDMwr/Dx/7lzkgwCdhbjtenbEfdEYrfqMGnJ uuEkM2mgqP9/z0h44/oI3xQkGL9PIWtC/9R7pJwynyqTdHpShqGIdhUepUWCy4XFUKAR 9kWXt5AJyxVEfzjmEA07XCzxxMPfPwygD3CQb5P6t70ADqzfXUznxEexF7XCpMjL5L/V BgmQX89FSodHq4+rWaG5j3k+xrc9HcSTXCGXVaYZm9LERpUvp67RmHT/hy2z15kDAPBo JTEs3isht9XHK7RW5WVYt9rcg9O/re0aJyrDnOKAWLFpkvX1WGYWYr8MyjRcMv2NakXF YoGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=We7Zcoyp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u8-20020a05622a14c800b0040631ab7350si2234895qtx.475.2023.08.22.22.18.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 22:18:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=We7Zcoyp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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: 716073 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp622203wrp; Tue, 22 Aug 2023 22:17:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFA0Fze55UxKrzzyiy+fkmbkgieuw1cEbBN51Izz5DsOwYw3qsY6YiWwThWVg6O/ApdLvZB X-Received: by 2002:a05:6214:5d93:b0:63f:7b8e:7b4a with SMTP id mf19-20020a0562145d9300b0063f7b8e7b4amr11819224qvb.5.1692767849724; Tue, 22 Aug 2023 22:17:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692767849; cv=none; d=google.com; s=arc-20160816; b=zaN1RuQYtAV0lbVSgprzS5mI50AC/6EytGlfhjx4pLu5Ysa/Nr2Hs+4nZiEgsKPqCX jM4O5gRH3mMdJiwEQz3eGAx8v23vpBTmhzt3H8XbRevZneM7t2/GCRUZRK/kxeMb3Q1i wk+aCdkDH2+4E89NLR2pHIZxUv+ZdB6R0tFbFdN4ohi7HMh1aaxoidNTZuaSMxQNFr2Y n3C9hMuTsqo2q3vFUVkSoaJGnmoIcCUu2z0U4/E9o8tr4q28SvzPZI3U4va0Ik0LEJB1 k8QGJfhSNWsGPTeAqBBEeF5yFgUZjZjG/inwwUNZ8U8tSlTo3FM0gPVsnPfFDTTZoiaf F2Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Rd/JAW+sPFhTSaNKV0zPbZhlNEehxWna67gnUamPROE=; fh=uta8CuNdWwEUIsmWLQQIuZWY0GOyjYTd4DbN32nR8cE=; b=HVMS+enoYxpU5sMJ41d/MxjcbRVf/w2qoMPydRXafb0TKqS/bbtrTCNQLBU0fJ42Ed Lwn3dctBImgPrpYfr2GHv4kHSQt7PFsrUJ7UUxnDJJFnRWIYEwqdrJKgZW3/M3Q8Bgb9 IHaPIpEGrW1ZnqeBlJduIH87UWM/ybpIszjPlJvrvePa0ZlpTH1socoTY5bh1GGxaYHW vabi9V81xw4t3SKvOiucIuoFC7NT8g0SUWaiwRkfNB+47zpKyWdl1pIxWkaYkprTAYC3 qV503nf4S+710IqpYxxRAduLP3n81zEtshCON2saPdM5DPmF46A1eqiKiACC6orV8Xx2 MsmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sAzrnDjA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j8-20020a05620a288800b0076ccb18cad2si6927364qkp.646.2023.08.22.22.17.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 22:17:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sAzrnDjA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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: 716071 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp622198wrp; Tue, 22 Aug 2023 22:17:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+nVFAJrLaXPCvJ/Q/gyAwu2vQPDNEk+EXjuv5TqdBoOlSLokYFxOo7X9Vc1MJJ06VmEBQ X-Received: by 2002:a05:620a:120b:b0:76e:e6cb:81b4 with SMTP id u11-20020a05620a120b00b0076ee6cb81b4mr44004qkj.73.1692767849418; Tue, 22 Aug 2023 22:17:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692767849; cv=none; d=google.com; s=arc-20160816; b=YEFtu3FGlB++aA/gqzxSDqZws+DGMXMKE1RQFO1JVu3qr/DcpobUifuWwDIoIoCaWg mkJimHyPziW78KGmNneoa0tQFlMrlQ9bs0qbJNzuWHfKIP7Fe/Kxe9Z46vi0AcBYkoi+ 4P43SQdt9l1JyVAXKvUiBd6FgbCNbEsh1m5o/zT7uvGuKwfxkLMz0grtyFJJrwgnJR4w /btbpkRhlAkx1kSrpf5y7gjx2fO7l3MBpjlrt4ksWrAIhm1CQF3Ghjglo8aDgNYlcO0j MvV/OeK6dAblBfYHqVn3IhSrDkrVuP6mjIhPugjaOfSnUJaIXelcauPKAQcFdxb6HQg3 IsLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ONpVouFAHtBaoT5On3cpK1SzlinIIZiyWi2CcqB3oSk=; fh=uta8CuNdWwEUIsmWLQQIuZWY0GOyjYTd4DbN32nR8cE=; b=n0Vfo+mtuJMdeKq6cnngKIrMGouw6VpaVbxaii6QT6pP3HnBTtJPlP9GHyYjzIw8MS /TikzyQYLE50I7Ogbfefceuy8KTmrxbeBUpB+RyxDmAzIgdTaOvMDgUYfihlhzF2t79N SyEX0V5XUqbCzkHv4hlkkLGX5kjeHJMJ0Td+B5h5pBtN7fG3Tx5Q0Dx7gIhgutOawnZh JBvgz3D/qJBZw8JDZ4uaToEOI1tABOCpt1ADbw0ca/V/T2U83dSjmBafW44V0CWolD2L DtKH+gzEupxNKZDxumWsqQJyZryJufv6j4j4aAo5Wsg/s4mGPRTDsYTwuW5LlPKRq5BO hB4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ss8u766f; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i25-20020a0cab59000000b0064bd48d399esi6353818qvb.325.2023.08.22.22.17.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 22:17:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ss8u766f; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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); } }