From patchwork Wed Oct 18 23:31:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1851368 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=X/LzXjG7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S9nH71p88z1ypX for ; Thu, 19 Oct 2023 10:33:55 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG0s-0003e8-BI; Wed, 18 Oct 2023 19:31:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG0r-0003Xg-CZ for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:41 -0400 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0o-0000EJ-5h for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:41 -0400 Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-35754465cb3so27427085ab.0 for ; Wed, 18 Oct 2023 16:31:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671896; x=1698276696; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D2oYojizKTJe59+z2rFn3jhqwAzCHsM3phmz2spMImU=; b=X/LzXjG76Ye5xqLNpsqI8HAAVck+vO2Vw35rKs8HRQ7HXUXWNiNhPTuyzYgHuTHBSh ffBa4wnvJr6/MQpF2RtIXxrHDss3qgrou5RFUTp5ucmcQO3vrbgs9vwe2DAZzKc71MIA KWxyYvuNGF8lVaSpMdSu6X87MeMu+fmmCYPrm5+BSGzNLHx/7hjP0L3pVS9ouDg0onn7 ofPJktkEaW4jmvTpIsnLvo3wfK6bMk1ui9+9ovC0Jl7MVbLul5qjDL+puw/1ri/5oMnX +s1fmvm2qAP/p7jyilyp28lUfAIfBKbBgBFR9+thSIxV/z8iA/mNoVHMO+F1KvszjiSM zkgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671896; x=1698276696; 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=D2oYojizKTJe59+z2rFn3jhqwAzCHsM3phmz2spMImU=; b=Qh+bBm6uWVjpZjN56Yo9ILVaFk/mflEl48WLbHA8R2Lim5nmQUMjMjlVNmRSRUEFmG wC1gGkUVEGrEsHffA0YFguyA3NwbQqXDx9G2N5IuihfGNTVTSyUdDvFVyOb8+3z1v4XT jHXmVddGJaTvU34fxJF7LCbwJCvnrHqYnFXojX09A9DgXt4ylLl3vacJHvF0SPwxk1mZ 4T4k4Ppb1oAbLkdXcL08bNlD8y4nqKVya7ISlu2n7v5s0A3/VIw8KT2B99TUM4WcnaTK K3MqLuRBsLX/n2c0WCm647pqkUinTZ0WHjhWRbwS4ghsjGyMjDzGUjR6Q3muAHsNDxh6 hgtA== X-Gm-Message-State: AOJu0YxBPS7EwHLI/9RtvtnkfYcplrmFGfx7xCURStiBPMmmjAxmeweQ hzfyfoGrj2pb0CvgWuVuErPDqJEUv1iEMO3/YIA= X-Google-Smtp-Source: AGHT+IHmz5DFH3zqalCZpjOJdeBVlQotWSVovSL2yng/PdcPHn63ZIcbj2ssXlVulJFWGDMMiXfAEQ== X-Received: by 2002:a92:d650:0:b0:350:f956:91c4 with SMTP id x16-20020a92d650000000b00350f95691c4mr728194ilp.4.1697671896348; Wed, 18 Oct 2023 16:31:36 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 01/14] linux-user: Fixes for zero_bss Date: Wed, 18 Oct 2023 16:31:21 -0700 Message-Id: <20231018233134.1594292-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::134; envelope-from=richard.henderson@linaro.org; helo=mail-il1-x134.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The previous change, 2d385be6152, assumed !PAGE_VALID meant that the page would be unmapped by the elf image. However, since we reserved the entire image space via mmap, PAGE_VALID will always be set. Instead, assume PROT_NONE for the same condition. Furthermore, assume bss is only ever present for writable segments, and that there is no page overlap between PT_LOAD segments. Instead of an assert, return false to indicate failure. Cc: qemu-stable@nongnu.org Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1854 Fixes: 2d385be6152 ("linux-user: Do not adjust zero_bss for host page size") Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/elfload.c | 53 +++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index f21e2e0c3d..213fd3e584 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2362,31 +2362,58 @@ static abi_ulong setup_arg_pages(struct linux_binprm *bprm, * Map and zero the bss. We need to explicitly zero any fractional pages * after the data section (i.e. bss). Return false on mapping failure. */ -static bool zero_bss(abi_ulong start_bss, abi_ulong end_bss, int prot) +static bool zero_bss(abi_ulong start_bss, abi_ulong end_bss, + int prot, Error **errp) { abi_ulong align_bss; + /* We only expect writable bss; the code segment shouldn't need this. */ + if (!(prot & PROT_WRITE)) { + error_setg(errp, "PT_LOAD with non-writable bss"); + return false; + } + align_bss = TARGET_PAGE_ALIGN(start_bss); end_bss = TARGET_PAGE_ALIGN(end_bss); if (start_bss < align_bss) { int flags = page_get_flags(start_bss); - if (!(flags & PAGE_VALID)) { - /* Map the start of the bss. */ + if (!(flags & PAGE_BITS)) { + /* + * The whole address space of the executable was reserved + * at the start, therefore all pages will be VALID. + * But assuming there are no PROT_NONE PT_LOAD segments, + * a PROT_NONE page means no data all bss, and we can + * simply extend the new anon mapping back to the start + * of the page of bss. + */ align_bss -= TARGET_PAGE_SIZE; - } else if (flags & PAGE_WRITE) { - /* The page is already mapped writable. */ - memset(g2h_untagged(start_bss), 0, align_bss - start_bss); } else { - /* Read-only zeros? */ - g_assert_not_reached(); + /* + * The start of the bss shares a page with something. + * The only thing that we expect is the data section, + * which would already be marked writable. + * Overlapping the RX code segment seems malformed. + */ + if (!(flags & PAGE_WRITE)) { + error_setg(errp, "PT_LOAD with bss overlapping " + "non-writable page"); + return false; + } + + /* The page is already mapped and writable. */ + memset(g2h_untagged(start_bss), 0, align_bss - start_bss); } } - return align_bss >= end_bss || - target_mmap(align_bss, end_bss - align_bss, prot, - MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) != -1; + if (align_bss < end_bss && + target_mmap(align_bss, end_bss - align_bss, prot, + MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) == -1) { + error_setg_errno(errp, errno, "Error mapping bss"); + return false; + } + return true; } #if defined(TARGET_ARM) @@ -3410,8 +3437,8 @@ static void load_elf_image(const char *image_name, int image_fd, /* If the load segment requests extra zeros (e.g. bss), map it. */ if (vaddr_ef < vaddr_em && - !zero_bss(vaddr_ef, vaddr_em, elf_prot)) { - goto exit_mmap; + !zero_bss(vaddr_ef, vaddr_em, elf_prot, &err)) { + goto exit_errmsg; } /* Find the full program boundaries. */ From patchwork Wed Oct 18 23:31:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1851367 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=w3uxCWr+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S9nH123B0z23jP for ; Thu, 19 Oct 2023 10:33:49 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG0s-0003g8-FP; Wed, 18 Oct 2023 19:31:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG0r-0003W1-55 for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:41 -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 1qtG0o-0000Fl-Ks for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:40 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6bb4abb8100so3867458b3a.2 for ; Wed, 18 Oct 2023 16:31:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671897; x=1698276697; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1I5j+CVAtN1UYbE5YS09fVUfZ8qAm7sA0ML6lgTI9YE=; b=w3uxCWr+FAeDbgM3yAWT+aejaZA8XRR7mCNEedAyu1+8LFLVrfDXwhSLoHVOAMiwO6 KNnWcKl4rNgSSazKdctDoar/OQ9WI+YFT+DQ2Tu2rh7TQcucrt/B5pt/FmBq86br+eOe MFYzhhMwLei2KGlOMnKlaz0bBqvB44RZLpt6A6fLpfsQAJ6d/FRPbbJLJLTR9IZNl86H jcsw9RhuiDrApjaYCqRU9pHa/D6crvoP2a3IYabRGAWTSykjj3REzVaU3eNxwX4L75Z2 5dwhW3sQZekELF2V3FolReYDJM0SbfNixBMjXWaasrXh/MsMdCnQO+oKw9558vpjdqDe wXWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671897; x=1698276697; 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=1I5j+CVAtN1UYbE5YS09fVUfZ8qAm7sA0ML6lgTI9YE=; b=HljuvF88Qy8CaSVAchtdZm4JDWmGTVWZHvbYt0Z4NoVnS9kvY85AUJOP75L8Hqt05s arQRq+IUEW0vRJY8g6NfZGvDog3OThG2Rdu2f3cNOLSJNxGa2V41gsN0WjCwFQyKsrru 0ezZ1Zw9yE7eDYTUEXqrggvi+YTe++r4UpD1SocZQ0n8It5nE1kbzThVJUITjwljY7LZ JsANNKno18TzhMdgMilSiKHxEVZgbdHlYVP+5z3+PSi7e9qIY2OgMSKQ/UlbK/m32d/F BviBOzB60jNwp+Gbe+ZI5xfvsMImuYzo2WBmNQ15/LVB3FnWP944fd4OVhLl3YnbZRFl 1xTg== X-Gm-Message-State: AOJu0YxR5QRX9Zp3V0iBhf4iQI1z5TqjzZ3O1QEQba+Hh7E9aDqiDS/A G480kjHLfYY+UYuZlURT4frq7GDG9FWwn7V87bk= X-Google-Smtp-Source: AGHT+IHXiLjylmN8G6bxSVj06uKRlBovtK8IuWHWxvv5A6Zj3AUmyvtjIa8Zsxgv12YL16XFO2t1qg== X-Received: by 2002:a05:6a00:1354:b0:692:6d3f:485b with SMTP id k20-20020a056a00135400b006926d3f485bmr641843pfu.3.1697671897116; Wed, 18 Oct 2023 16:31:37 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Mikulas Patocka , qemu-stable@nongnu.org Subject: [PULL 02/14] linux-user/mips: fix abort on integer overflow Date: Wed, 18 Oct 2023 16:31:22 -0700 Message-Id: <20231018233134.1594292-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Mikulas Patocka QEMU mips userspace emulation crashes with "qemu: unhandled CPU exception 0x15 - aborting" when one of the integer arithmetic instructions detects an overflow. This patch fixes it so that it delivers SIGFPE with FPE_INTOVF instead. Cc: qemu-stable@nongnu.org Signed-off-by: Mikulas Patocka Message-Id: <3ef979a8-3ee1-eb2d-71f7-d788ff88dd11@redhat.com> Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- linux-user/mips/cpu_loop.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c index 8735e58bad..990b03e727 100644 --- a/linux-user/mips/cpu_loop.c +++ b/linux-user/mips/cpu_loop.c @@ -180,7 +180,9 @@ done_syscall: } force_sig_fault(TARGET_SIGFPE, si_code, env->active_tc.PC); break; - + case EXCP_OVERFLOW: + force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTOVF, env->active_tc.PC); + break; /* The code below was inspired by the MIPS Linux kernel trap * handling code in arch/mips/kernel/traps.c. */ From patchwork Wed Oct 18 23:31:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1851356 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=T1HjE9s/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S9nGG5CjTz23kJ for ; Thu, 19 Oct 2023 10:33:10 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG0t-0003sI-Fm; Wed, 18 Oct 2023 19:31:43 -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 1qtG0r-0003bl-Tg for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:41 -0400 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0p-0000He-Am for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:41 -0400 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-581d4f9a2c5so1295454eaf.0 for ; Wed, 18 Oct 2023 16:31:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671898; x=1698276698; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2k8XNRKudZqb8EBVa8P0hTDCeDuuDeqPExqYOmBXPTU=; b=T1HjE9s/vAwmlJdg3j4bvMnWFNEUhgxCi83qF0fciFrq4iMeXPdQnGgBWsnkUqzIUt jxzXImOc3/JpaXpX8ZAGv0QW8Ac6bjHPGpEFT5mqT3OqJM7z1vfHRZxEQywvdwTe0g9d dujdI0CtwAVUFd5vXX6HzyhwB1ba28Uxgj/UHKnYUQDE0MUy9NZHTQy/mSY6nSDcHNVj 0AgZtUL3OhC8i0U/Q81acJEpFtT9MJtzxVbAuVWXP942R8Z0vdC3dIK6E2JOn09ebdYB HbuPS7gIaOIbO532FJgyIjgLhwVp3O7q0MjQ5g21tSQxwuFqMcuqg7LZ1Feh8HsaiTpf f0Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671898; x=1698276698; 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=2k8XNRKudZqb8EBVa8P0hTDCeDuuDeqPExqYOmBXPTU=; b=ILyzx6GKlD1WKv+mb02rNAt2xUJv9AsZmmkeeY2tUii4tTaTaOHbEn7JE0tGTY1oG1 WLo9sagVBWrolgRsYQiih77ekYdgL5+SJ4alxLITkPSXCtIvDXxhgVjzYc29WSeh55Sd QDz95IGkrwZQ0Q6DrNc8phq6HwlpiFzjV0STpRCBEPkE+t2aWQP6KZowyT4OWQqKetLF freXX8v2+4BXNapuf/izlQlWHqRpW/tz3moDGgwSYReSdBoTtXTe/+z77C9OeTSLjnT8 S/zjL/ovEgWAXFTXShMdnU1Ns0ZjK4/gJcOYE5wGPiyUJhGyMq/Muwmh7XOGkg2WLexN 9a+g== X-Gm-Message-State: AOJu0YxtocmN/BK8fUcyUnb0nZ4cLucBJKwr205Bt2yaklzAPhWCUDS5 t9kky90tL303aAZpedhnvJPBb8OABAVVZVdJkZo= X-Google-Smtp-Source: AGHT+IGLxyNfa7bjHam+oXF8Ve3NLM22VXgqmCzlIsW3AZQLw7HVdDcZs/xPYByQa6UKsKBrMSBBKQ== X-Received: by 2002:a05:6358:fd02:b0:143:70a1:afcd with SMTP id ui2-20020a056358fd0200b0014370a1afcdmr453415rwb.1.1697671897987; Wed, 18 Oct 2023 16:31:37 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Mikulas Patocka , qemu-stable@nongnu.org, Yoshinori Sato Subject: [PULL 03/14] linux-user/sh4: Fix crashes on signal delivery Date: Wed, 18 Oct 2023 16:31:23 -0700 Message-Id: <20231018233134.1594292-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c2b; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc2b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Mikulas Patocka sh4 uses gUSA (general UserSpace Atomicity) to provide atomicity on CPUs that don't have atomic instructions. A gUSA region that adds 1 to an atomic variable stored in @R2 looks like this: 4004b6: 03 c7 mova 4004c4 ,r0 4004b8: f3 61 mov r15,r1 4004ba: 09 00 nop 4004bc: fa ef mov #-6,r15 4004be: 22 63 mov.l @r2,r3 4004c0: 01 73 add #1,r3 4004c2: 32 22 mov.l r3,@r2 4004c4: 13 6f mov r1,r15 R0 contains a pointer to the end of the gUSA region R1 contains the saved stack pointer R15 contains negative length of the gUSA region When this region is interrupted by a signal, the kernel detects if R15 >= -128U. If yes, the kernel rolls back PC to the beginning of the region and restores SP by copying R1 to R15. The problem happens if we are interrupted by a signal at address 4004c4. R15 still holds the value -6, but the atomic value was already written by an instruction at address 4004c2. In this situation we can't undo the gUSA. The function unwind_gusa does nothing, the signal handler attempts to push a signal frame to the address -6 and crashes. This patch fixes it, so that if we are interrupted at the last instruction in a gUSA region, we copy R1 to R15 to restore the correct stack pointer and avoid crashing. There's another bug: if we are interrupted in a delay slot, we save the address of the instruction in the delay slot. We must save the address of the previous instruction. Cc: qemu-stable@nongnu.org Signed-off-by: Mikulas Patocka Reviewed-by: Yoshinori Sato Message-Id: Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- linux-user/sh4/signal.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/linux-user/sh4/signal.c b/linux-user/sh4/signal.c index c4ba962708..c16c2c2d57 100644 --- a/linux-user/sh4/signal.c +++ b/linux-user/sh4/signal.c @@ -104,6 +104,14 @@ static void unwind_gusa(CPUSH4State *regs) /* Reset the SP to the saved version in R1. */ regs->gregs[15] = regs->gregs[1]; + } else if (regs->gregs[15] >= -128u && regs->pc == regs->gregs[0]) { + /* If we are on the last instruction of a gUSA region, we must reset + the SP, otherwise we would be pushing the signal context to + invalid memory. */ + regs->gregs[15] = regs->gregs[1]; + } else if (regs->flags & TB_FLAG_DELAY_SLOT) { + /* If we are in a delay slot, push the previous instruction. */ + regs->pc -= 2; } } From patchwork Wed Oct 18 23:31:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1851370 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=RjcgIrZ4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S9nHj1TpZz1ypX for ; Thu, 19 Oct 2023 10:34:25 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG0u-0003wH-CU; Wed, 18 Oct 2023 19:31:44 -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 1qtG0s-0003fx-Df for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:42 -0400 Received: from mail-il1-x12c.google.com ([2607:f8b0:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0p-0000I4-TU for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:42 -0400 Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-3575287211bso27379195ab.1 for ; Wed, 18 Oct 2023 16:31:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671899; x=1698276699; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KeKGrdrxTYoWvojPluBjviNWq1U0AbGSCGNtTdLurtI=; b=RjcgIrZ4kB5mPpL2skFbOjOpDzAVP4HGYyuYWAQTyacyOLElsoIBi6XQ9cjbvV8MEy cOCHFbNhvG3HPlW+7Gdw4HRds5iYEAF3pI+n7LAVrLN9xTmVbp8Qmtc2DTKY23xxGrn7 ACXcaZxKhKuGq6wJORMme9JVCPltiqr3OtB0a7Y2MLAN4XF4xGHSa9B5vz3r8+lb5q2M /LQnOqp1ByiHre1Ov5qYl2j9/XrLOtvCFDZSFdpHuycrdFFogTb/rrzgnva7L1j8vjeF Wd0FrvMSSt19jC0+4pCBVyxs2mcefA0x1gAlHEUAz7Ew0KWdp6K0b3twhFRfETwsBKU9 ckrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671899; x=1698276699; 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=KeKGrdrxTYoWvojPluBjviNWq1U0AbGSCGNtTdLurtI=; b=xOKSAOc2HvHgByr7s0wMX07wfBaanj8Vf5f5YNJFv+Un/bzo1ZkPWJBAxEMRLoxmzF LHC0c/V6odnCw3elcz/Z7+esQDwFiGSqZ6BGt0yjsnkE+d+aObL88AHVgAIjq9FwZWTJ ujac3VdweoaG7UkS3RTObvALIShEfalPKQTeKzsmRhC1gyG/0ZDAl3vSpf/R+f2lGJGG lF8c/+SxRISBuz3W5Z+1g5vdYwjPK8QUNIGfKp6JYZJZsWokGSVR5ghMoU5/yPBchHBB W11/w6AqX8DMWvZqCAVLI3yrcpA8OkOHa5JvoZnJfY+3TXQp9eLVqz2N01OoEB/dKA5+ 4emg== X-Gm-Message-State: AOJu0YzPXdSpgQ7FrMh9chLmYlHV8T/8FS2yEEMnBCtPp/kwZlrVGQp0 tv2fnw1i6CXnlMLsxdE9G0f4vmNRR3KsXnnq1tQ= X-Google-Smtp-Source: AGHT+IEHA6tQBbDHug2NbTbfjbuTtNCzZaI3DlsHU6EhtA6APOcIzUY1OeXNwC43dnDUFhUQvge5ig== X-Received: by 2002:a92:c262:0:b0:34f:a4c5:8eca with SMTP id h2-20020a92c262000000b0034fa4c58ecamr999999ild.27.1697671898776; Wed, 18 Oct 2023 16:31:38 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Jiajie Chen Subject: [PULL 04/14] linux-user/elfload: Enable LSX/LASX in HWCAP for LoongArch Date: Wed, 18 Oct 2023 16:31:24 -0700 Message-Id: <20231018233134.1594292-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::12c; envelope-from=richard.henderson@linaro.org; helo=mail-il1-x12c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jiajie Chen Since support for LSX and LASX is landed in QEMU recently, we can update HWCAPS accordingly. Signed-off-by: Jiajie Chen Reviewed-by: Richard Henderson Message-Id: <20231001085315.1692667-1-c@jia.je> Signed-off-by: Richard Henderson --- linux-user/elfload.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 213fd3e584..2e3809f03c 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1237,6 +1237,14 @@ static uint32_t get_elf_hwcap(void) hwcaps |= HWCAP_LOONGARCH_LAM; } + if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) { + hwcaps |= HWCAP_LOONGARCH_LSX; + } + + if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LASX)) { + hwcaps |= HWCAP_LOONGARCH_LASX; + } + return hwcaps; } From patchwork Wed Oct 18 23:31:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1851365 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=UhBV2fP1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S9nGq3t9nz1ypX for ; Thu, 19 Oct 2023 10:33:39 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG11-00046l-Rx; Wed, 18 Oct 2023 19:31:51 -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 1qtG0s-0003lt-RW for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:42 -0400 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0q-0000Ia-Ti for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:42 -0400 Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-7a67ebc2cb3so25267739f.2 for ; Wed, 18 Oct 2023 16:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671899; x=1698276699; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MZQXmTezubKvZiknkUGl30NcUMWQlr0tOKsu9AI7N20=; b=UhBV2fP1i+sf410LUy7MV1QCAkxH0dUu5tc5OXyfssKTcB/JDs7KAcuECptazKt9sc SoxUyKh6R2buAjA8gdpQkqswEf2T8kHbmzD7/y5KOZxfouy245m/w6StsALM6O8T9lUb VU0Db382NgXvi6kRFLyPzKqZZUejah0d63qOWrB8+JpW1CvRjmiyQsJCoAKisB38BRZ1 Qw9RhQ1+1RKSDuZh9XpbEAahPJSnCFTnps56s6SKwrJBRnicsGIBWv6iqggL2JYZVNZo n3BmQRVvvrjJfSb9u6QWR/rt6gmQTy7xMijmFj94ke/DxhgETUUvPdrWOfitcvowMTsE r3bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671899; x=1698276699; 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=MZQXmTezubKvZiknkUGl30NcUMWQlr0tOKsu9AI7N20=; b=oa/maBS1fNyVPdNUQGlbHvl9zUguwASecHEzBplv0O15fgt60dy6CRb+Kt1GZ5Q+5r N5Mk+Tcc0wrwdYxIU+SPEqUtwvMdBM5eFTyBZkFrAy1spuqKGlttX2mCc1PDGAnlVDZV ItSOsOwx+lfOqMElm2y8av1P5wNsDg/ACoHYaa2gCHfCm0EfiRC8NbmioBHBR6x2qDrg gyu4vhlNfuSnjmShPAhQX1UFS9p1caNfsFCGWA9T3e50IHfCm5lKL0ecJ+wRX+sRPwQJ lFyQTAUT4FSHBArumUkwfTQ19A8GAFEUFMqPsMIjt1T8pVY4pVIzaXl/S7W1hxOfaTKu Zqug== X-Gm-Message-State: AOJu0YzRTAqaQS71dzjKMSHdk2Yzs93qXkYQ1I5S2kxqJehSsC2wWb5B eMBfhxDfQDRvOmq6tMf1WMB6EyQ8g/f6zsVLzz0= X-Google-Smtp-Source: AGHT+IG0cvDfSc31AsKD9KH3tqSINpuriv8QFpiwDjClajVqOPjn59WWu7C7ypCmw58YTZAxyyvmeg== X-Received: by 2002:a05:6e02:2168:b0:357:7b04:721 with SMTP id s8-20020a056e02216800b003577b040721mr948604ilv.32.1697671899501; Wed, 18 Oct 2023 16:31:39 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Andreas Schwab Subject: [PULL 05/14] linux-user: Propagate failure in mmap_reserve_or_unmap back to target_munmap Date: Wed, 18 Oct 2023 16:31:25 -0700 Message-Id: <20231018233134.1594292-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::d2e; envelope-from=richard.henderson@linaro.org; helo=mail-io1-xd2e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Do not assert success, but return any failure received. Additionally, fix the method of earlier error return in target_munmap. Reported-by: Andreas Schwab Signed-off-by: Richard Henderson --- linux-user/mmap.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 8ccaab7859..7b44b9ff49 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -778,7 +778,7 @@ fail: return -1; } -static void mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) +static int mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) { abi_ulong real_start; abi_ulong real_last; @@ -807,7 +807,7 @@ static void mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) prot |= page_get_flags(a + 1); } if (prot != 0) { - return; + return 0; } } else { for (prot = 0, a = real_start; a < start; a += TARGET_PAGE_SIZE) { @@ -825,7 +825,7 @@ static void mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) } if (real_last < real_start) { - return; + return 0; } } @@ -836,32 +836,36 @@ static void mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) void *ptr = mmap(host_start, real_len, PROT_NONE, MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, -1, 0); - assert(ptr == host_start); - } else { - int ret = munmap(host_start, real_len); - assert(ret == 0); + return ptr == host_start ? 0 : -1; } + return munmap(host_start, real_len); } int target_munmap(abi_ulong start, abi_ulong len) { + int ret; + trace_target_munmap(start, len); if (start & ~TARGET_PAGE_MASK) { - return -TARGET_EINVAL; + errno = EINVAL; + return -1; } len = TARGET_PAGE_ALIGN(len); if (len == 0 || !guest_range_valid_untagged(start, len)) { - return -TARGET_EINVAL; + errno = EINVAL; + return -1; } mmap_lock(); - mmap_reserve_or_unmap(start, len); - page_set_flags(start, start + len - 1, 0); - shm_region_rm_complete(start, start + len - 1); + ret = mmap_reserve_or_unmap(start, len); + if (likely(ret == 0)) { + page_set_flags(start, start + len - 1, 0); + shm_region_rm_complete(start, start + len - 1); + } mmap_unlock(); - return 0; + return ret; } abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, From patchwork Wed Oct 18 23:31:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1851369 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Q2h+rqhZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S9nHg2Pfwz1ypX for ; Thu, 19 Oct 2023 10:34:23 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG15-000483-BR; Wed, 18 Oct 2023 19:31:55 -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 1qtG0t-0003rB-AS for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:43 -0400 Received: from mail-il1-x12c.google.com ([2607:f8b0:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0r-0000JX-Jf for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:43 -0400 Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-35757bfb3f7so28872835ab.2 for ; Wed, 18 Oct 2023 16:31:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671900; x=1698276700; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HR6OhNjXMnjPeW+GKwBhvGRBpRXClWtOK/vmyhs99O8=; b=Q2h+rqhZP/VuOhuhJBPUC+pYz1Ni0cd+/mXSDmr6rBfHRuAjzeT8Hq4ACQo/VwcjOK bNsmiLaWnMavwKjZRjfdA4SFwYvXS+MgQCQo9IcaJc5ZPwvuhWdlVJMqE+rVNlY9T/n9 0MR8IJdGmJgh6Ujz49P8PYzo7Z5ULMGromwIzREJBGL3xnRUb5QBp71GJYDWPmOZjW+O Q5LQ0m1FmPZcmm+8klaTPELYzT9nd8fJGY/WovEyuh55CaiAJ71qy1gli6Bp4G4AnDLe O630yfdG5WyDGVUr+jV32p4M4/r8ahFHZSh3AIW0sC6gzMoAUUblKOAFZ7G5eUGKjGAe DFCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671900; x=1698276700; 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=HR6OhNjXMnjPeW+GKwBhvGRBpRXClWtOK/vmyhs99O8=; b=XWP3j2rC+GO+CqlA+DcgJN81THZF02YuV8qJHJYQFlcFVJHw6vVICse30F7BvrWLdx 6+xU8it0q+GIMTwdKRd7ee3PL91v2PvKinbr3GFwS/iVVpuC9WQEA1HJOlbjCrr5X7l7 /ZPOEYk7ZMv83sy1s8Az1R4wMP0uY30m0vxrauoZhscOmkQky3GDTIzg7j1wVhmeWKvn XhYfOUYIWtldcnEm/r/yNlB1dC8OgmxbH1yRtRpgqJ8hmp4kzabdQm68sEiUVlLMWwYl jJ97oMEK/KqarFAb4KhRSOIvYAzRcVkUo8b8F/pgsBqTNgZ6UaTr8C7uMM+au6EoHDC2 6dRA== X-Gm-Message-State: AOJu0YxlA/cUCafIsRRcnyNpAIqOoO4WRTk5VUCtjdNSZEjzrNsTXLXM M2E1fL0CGtZaSeM3gi1UmGrzKamNX/ZpyVSSf/A= X-Google-Smtp-Source: AGHT+IE1VFj4HJaZkhv20LfcraCD09eH6yPZXMQCghbmIYGz99xBpR4xzK4BR0sR99N+7Pus/dntCw== X-Received: by 2002:a05:6e02:219b:b0:357:72e5:4adf with SMTP id j27-20020a056e02219b00b0035772e54adfmr1090888ila.26.1697671900599; Wed, 18 Oct 2023 16:31:40 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 06/14] linux-user: Split out die_with_signal Date: Wed, 18 Oct 2023 16:31:26 -0700 Message-Id: <20231018233134.1594292-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::12c; envelope-from=richard.henderson@linaro.org; helo=mail-il1-x12c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Because we trap so many signals for use by the guest, we have to take extra steps to exit properly. Acked-by: Helge Deller Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/signal.c | 52 ++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index a67ab47d30..b7a2c47837 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -689,13 +689,39 @@ void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr, } /* abort execution with signal */ +static G_NORETURN +void die_with_signal(int host_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(host_sig, &act, NULL); + + kill(getpid(), host_sig); + + /* Make sure the signal isn't masked (reusing the mask inside of act). */ + sigdelset(&act.sa_mask, host_sig); + sigsuspend(&act.sa_mask); + + /* unreachable */ + abort(); +} + static G_NORETURN void dump_core_and_abort(CPUArchState *env, int target_sig) { CPUState *cpu = env_cpu(env); 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); @@ -719,29 +745,7 @@ void dump_core_and_abort(CPUArchState *env, int target_sig) } preexit_cleanup(env, 128 + target_sig); - - /* The proper exit code for dying from an uncaught signal is - * -. The kernel doesn't allow exit() or _exit() to pass - * a negative value. To get the proper exit code we need to - * actually die from an uncaught signal. Here the default signal - * handler is installed, we send ourself a signal and we wait for - * it to arrive. */ - sigfillset(&act.sa_mask); - act.sa_handler = 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 Oct 18 23:31:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1851362 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=E5bVMljh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S9nGf6MRSz1ypX for ; Thu, 19 Oct 2023 10:33:30 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG0v-0003yg-SW; Wed, 18 Oct 2023 19:31:45 -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 1qtG0u-0003vt-3a for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:44 -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 1qtG0s-0000KC-Ig for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:43 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6b1e46ca282so5808204b3a.2 for ; Wed, 18 Oct 2023 16:31:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671901; x=1698276701; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XDEeeYBNH4kaMPDKd2bpL06m4MGoDecFzYDq6oXSWUM=; b=E5bVMljhVaac6oapoai8D5VZEBpg26aWN1S68fE3yZUQ0RD+n1Bf9iMc1dvGu7qV8l gu1u39Wv2w/DtUPYs+LqpvvNq57ITlRX3zHU9P54F3TcYm02C5wNURCYc/RN89MlKsIk cg/CBqfwl1V9bqG8qM0u4+DNpYc+0m3Bnd29FZuRIG5St8FXkDjD51lYCYPYezSvXFJ4 UqiRbN6tpI8tNnmGhp+enM84QnW1PY8uC0B/S8xGW1hniJQ8nbMtwa7PdbtLK+Ka07l3 4gZdqhsbsjgNXy+KD8pyKtvwls/Cq87fTuicF4X7NycNE8Y60FzFF7bzveWH6UBKleiF 66gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671901; x=1698276701; 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=XDEeeYBNH4kaMPDKd2bpL06m4MGoDecFzYDq6oXSWUM=; b=I902sHxOSE6o3rIU/vgEutM/lZ7Wvhy3ZyJQFNfJcn1j0pUJrxfPW1eTrMd7qgTlq6 2boNkShJRgltEO/LDTqUwBSioW0nrwn2kW0uLONiIiEXuW8+LAcFibArr0U234u/niBC bVmlj7kMHEe8hMe00g22kP6MjlgQKV2dx1bTVosMTWT3l1N2pdh9ZTjZ6j4Xcmv17MpQ Kwx1l2KXktdmCqisX3O2XBMBC/xmkvhVyGuV4uGoNEYQ+riINfm4TpQdAyBteQPC8oWK bB7r17M2lQzr9nkIjhQ0pfCGKar84KLkyhr29GphRzoW3VP8OzdGc+6evC0hjthaH/qr lkLQ== X-Gm-Message-State: AOJu0YxGncnMAdGveoWyhbxdwVZsJUVmcVbQZWyRcRSqeSCspJNE3twX Eg3ojonoGfBkBrGzLmKSKKRnpjSymcovKwxiH3w= X-Google-Smtp-Source: AGHT+IED1UtoC8RdGH8IuHBQr76tuTFXTZA2lO2yyYcZvJ0cWlBAUTu2hxAsDWTceSDptxyRuvZTBQ== X-Received: by 2002:a05:6a00:189f:b0:68f:c7c5:a73a with SMTP id x31-20020a056a00189f00b0068fc7c5a73amr655931pfh.16.1697671901235; Wed, 18 Oct 2023 16:31:41 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 07/14] linux-user: Exit not abort in die_with_backtrace Date: Wed, 18 Oct 2023 16:31:27 -0700 Message-Id: <20231018233134.1594292-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. Acked-by: Helge Deller Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index b7a2c47837..84a56b76cc 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -713,7 +713,7 @@ void die_with_signal(int host_sig) sigsuspend(&act.sa_mask); /* unreachable */ - abort(); + _exit(EXIT_FAILURE); } static G_NORETURN From patchwork Wed Oct 18 23:31:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1851358 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=IBuuzY6E; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S9nGG5G2Cz23kQ for ; Thu, 19 Oct 2023 10:33:10 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG0w-00040F-4Z; Wed, 18 Oct 2023 19:31:46 -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 1qtG0v-0003xQ-2C for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:45 -0400 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0t-0000KW-7w for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:44 -0400 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6c646b5028dso4867856a34.3 for ; Wed, 18 Oct 2023 16:31:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671902; x=1698276702; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OQP2+HZbJmIj9sXXPBVMTwI7vC2S6c38AoM7akl90XU=; b=IBuuzY6E+oFSysj0ymtpPsytGO+XLWJHp9Omipe5GFCQ7d8fo1maMom5k7tYXDDRWi 6RZV9X86jzzpz7N9P/tyNnntz451y5iOQa3yC0rPU/vp7+v/guOFnvLz6lCOtja5I4XV rYrkudo7lKT9mqWdDja7EZeL31scldfO/GJP7pAv0PARYh8R+GSiwAznEV7rl8hxZ//k B6LSDDQ+rk5oJVFfmArKYFqSxLs1ObSJsD5qaOaNBeBDUKy3E4z8Hkqu4+Z3+26V7pev ZoUC5LycWJGvdOISPjYFmgMRWX5enpTflDPvySiz3fGHefJbKJrcKSP75M8rakThoJFo wwaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671902; x=1698276702; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OQP2+HZbJmIj9sXXPBVMTwI7vC2S6c38AoM7akl90XU=; b=qJocHFZHalqChORdaHxDJDg3aXuPETGc+G4thmpKtJ5Ajk31b3XuBb8M4yvXKT8UaD aRmOVM9sNEzBQoir1MVVeBD/B83mzLRMMCoNI39d09mQ1AhicYpQuW7otWxMCl4h8wGp G4xRK8uHu24XdkAb9gKvAUj7UzJFi/GSlYSslYSQC52EYlCvpQHgTSTpymllah42JmVN 6xoWmrw4TercJOEb9FNJMiFYsHRucvQaMfMYab7qQZvQ/F+YfgX7kSe97T6OHtjjYFHN 3js6JoM5qv1GEmh4w4o66UR28e1FLIPm66TAT8HjhUqX/xHMNCRZbDU9EZzzotO6GR+D 7QQA== X-Gm-Message-State: AOJu0YwzeuGvNE1hvRQsmJJu64802Vmfi0nnJPzQGmD2W1yXAJ5abNUl YPYSIpYfBJZwP3t0s6ha+8H+UuGqJYcgFu5/MXs= X-Google-Smtp-Source: AGHT+IG9w7aQvEiov3fhjzsyLoZuCqQv31fh2lf4djm2MMCbVsWOXBnZKoFGpptx9KR6dj7Tn5rAMg== X-Received: by 2002:a9d:4d07:0:b0:6bc:fb5f:7b06 with SMTP id n7-20020a9d4d07000000b006bcfb5f7b06mr731046otf.17.1697671901979; Wed, 18 Oct 2023 16:31:41 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 08/14] linux-user: Detect and report host crashes Date: Wed, 18 Oct 2023 16:31:28 -0700 Message-Id: <20231018233134.1594292-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::330; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x330.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Helge Deller If there is an internal program error in the qemu source code which raises SIGSEGV or SIGBUS, we currently assume the signal belongs to the guest. With an artificial error introduced, we will now print QEMU internal SIGSEGV {code=MAPERR, addr=(nil)} Signed-off-by: Helge Deller Message-Id: <20230812164314.352131-1-deller@gmx.de> [rth: Use in_code_gen_buffer and die_with_signal; drop backtrace] Signed-off-by: Richard Henderson --- linux-user/signal.c | 69 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 84a56b76cc..9fadc51347 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -32,6 +32,7 @@ #include "signal-common.h" #include "host-signal.h" #include "user/safe-syscall.h" +#include "tcg/tcg.h" static struct target_sigaction sigact_table[TARGET_NSIG]; @@ -779,6 +780,50 @@ static inline void rewind_if_in_safe_syscall(void *puc) } } +static G_NORETURN +void die_from_signal(siginfo_t *info) +{ + char sigbuf[4], codebuf[12]; + const char *sig, *code = NULL; + + switch (info->si_signo) { + case SIGSEGV: + sig = "SEGV"; + switch (info->si_code) { + case SEGV_MAPERR: + code = "MAPERR"; + break; + case SEGV_ACCERR: + code = "ACCERR"; + break; + } + break; + case SIGBUS: + sig = "BUS"; + switch (info->si_code) { + case BUS_ADRALN: + code = "ADRALN"; + break; + case BUS_ADRERR: + code = "ADRERR"; + break; + } + break; + default: + snprintf(sigbuf, sizeof(sigbuf), "%d", info->si_signo); + sig = sigbuf; + break; + } + if (code == NULL) { + snprintf(codebuf, sizeof(sigbuf), "%d", info->si_code); + code = codebuf; + } + + error_report("QEMU internal SIG%s {code=%s, addr=%p}", + sig, code, info->si_addr); + die_with_signal(info->si_signo); +} + static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) { CPUState *cpu = thread_cpu; @@ -814,16 +859,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_from_signal(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 Oct 18 23:31:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1851366 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ldUBiC9t; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S9nH00gwnz1ypX for ; Thu, 19 Oct 2023 10:33:48 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG0y-00045x-2Q; Wed, 18 Oct 2023 19:31:48 -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 1qtG0v-0003yy-S3 for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:45 -0400 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0u-0000LX-4m for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:45 -0400 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-581f78a0206so621684eaf.2 for ; Wed, 18 Oct 2023 16:31:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671903; x=1698276703; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=N8YP8FFBP63+6pJ6d97ew/Y5ZJwzVjBAkzrh/+j6myU=; b=ldUBiC9t4xg2eP9SVkGMYPf+O6B8F/z/eEQjjbaWv19rHu5cT9OQHIsnAGKS+zhv9E R/xGG9tFXDsPC1ECVceT7aWN5fZ7DtdElfZiWeWFmH/R7aA4Cz5adZbMcOIY9ud5efye ON+G5Ts0IkU0UE8rrCGBkdVWdBsL2zIESGPKUabW4WxjpElL/djugugqhGY0q8ygr+Rp wFQrI0RP8nExb5ogRG0pvWfq60u0r/eveUrJTMyERRgO+RRCUWjz9bSRMhsS/j+73b/T YlWyDKK18vcYu8Chkt74j4e7DT1jgOShmMLuk5x7nTVFcWOzDcSNR1ssyx+c/kAeCYJg P5kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671903; x=1698276703; 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=N8YP8FFBP63+6pJ6d97ew/Y5ZJwzVjBAkzrh/+j6myU=; b=Pjy8j5NJQ64Ad0dUsGKtKUwNaY6+U1Q3xveL4n5DiIqint0sGH4elM33ShNaIrOpIh ee2w0WY5v6YUP0UeMzxb9lMetA9b5+qRYLHGRb0D2kxpirQL5mk+Dmb5tTGkPt7jUiwX hTqJyqMyI4UKWEbDx8eEixcBzkJJqGrPmWRJGNbT1CvDq/qWETjyYCUs3AWUz17099IJ XEeeUxnzejsx8UXXqFeosD8z2MGHo5Ueu28f02DEt5W0Nk7UV8WiOhqrM10b6hl4KR5B p631fOJvKbwkY4zkZsEFW81K9jbtL9DI28qO90NCsX8v8bp01PurB1qrMSpCopISNJmG awaw== X-Gm-Message-State: AOJu0YwTbpe0gzLDIoxYgVbRNlkfszk4PnZQF29t8Lz4h4O1FqzVdyic MuX0dUvBtfMne9eVWNnUrfUWyhIB3W9zRvRW818= X-Google-Smtp-Source: AGHT+IEUsWEnHKPFEP8Pq2bG3ixCk50BGeyeMtKwvwXDaBPHvVBLHuqUELfNw5B0CBtcbQrzXyznjw== X-Received: by 2002:a05:6358:9f85:b0:139:9fc3:eade with SMTP id fy5-20020a0563589f8500b001399fc3eademr429405rwb.29.1697671902800; Wed, 18 Oct 2023 16:31:42 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 09/14] linux-user: Only register handlers for core_dump_signal by default Date: Wed, 18 Oct 2023 16:31:29 -0700 Message-Id: <20231018233134.1594292-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c2b; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc2b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The set of fatal signals is really immaterial. If one arrives, and is unhandled, then the qemu process dies and the parent gets the correct signal. It is only for those signals which we would like to perform a guest core dump instead of a host core dump that we need to catch. Acked-by: Helge Deller 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 9fadc51347..aab05f8eec 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -488,26 +488,6 @@ void target_to_host_siginfo(siginfo_t *info, const 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) { @@ -602,8 +582,9 @@ void signal_init(void) SIGSEGV and SIGBUS, to detect exceptions. We can not just trap all signals because it affects syscall interrupt behavior. But do trap all default-fatal signals. */ - if (fatal_signal (i)) + if (core_dump_signal(i)) { sigaction(host_sig, &act, NULL); + } } } @@ -997,7 +978,6 @@ int do_sigaction(int sig, const struct target_sigaction *act, struct target_sigaction *oact, abi_ulong ka_restorer) { struct target_sigaction *k; - struct sigaction act1; int host_sig; int ret = 0; @@ -1057,22 +1037,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 Oct 18 23:31:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1851364 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=UbN7ggD/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S9nGj4p4gz23jP for ; Thu, 19 Oct 2023 10:33:33 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG11-00046m-RU; Wed, 18 Oct 2023 19:31:51 -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 1qtG0x-00044s-2n for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:47 -0400 Received: from mail-oo1-xc31.google.com ([2607:f8b0:4864:20::c31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0v-0000Lp-2x for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:46 -0400 Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-57b5ef5b947so4745129eaf.0 for ; Wed, 18 Oct 2023 16:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671904; x=1698276704; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UKWfNxY8ZBT24vryvV7tNUff057UO3MB5fEykagaJko=; b=UbN7ggD/knFsrh6J2kylQfTclqqk2mpjtFLBZmj3WV70we/mhb/JZ4rT12cHyXVJx/ SYnV79oHZBXNNsFoYgdIO0px2IEPDXKTnfeTRDyCEvX0xbthXWCtHMG5y9HRZ/yLJPEe Q2Y/vLzWhKUbm8GX5G7HG2fKROzHn91wuGZ+MddUFXb33a0EMMfqm2tpGeuG1ccGA8Aa xll5YEU6kyQRJlP1VUAcvzylV2NydDC2EWLd68lMXfJq5RW2p7oORo47ErrrW+OaVrMm vUY4gpFZJkr7aHdQf0zOEhiQQbFC56wZcPflbuEo4NOvlwyxw+5HJtx5UgFwJO4V/F8D xMwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671904; x=1698276704; 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=UKWfNxY8ZBT24vryvV7tNUff057UO3MB5fEykagaJko=; b=eNbZKn4H2WwiWwqqZfUGZW3CkGtjfBPl/f5S8066fk3KHZrSHoA4TX4RtoE1G8eTnQ QXEFAfgcRQCSjQGD2U/wHfYtXWsSas+DQfrhoIxQqTlCVqI/YcC0L6Za1Obyx7F+5prg xpfMcppQb6JjiTVc9UGWjjmS2e6MO9ihCDTUsFeeh9Hueh1yKyA81qqSwz0QGNF96n9a cKdW8Nf0hqp0ebRK8/a4W+SGM0JfCbWgAzARdysvZ3yDJbTxgDvESSIgd2dSE89WZLwP o75QcEvO3FWiSQK6wDQD3FbSftMjHyqzHbdiiH22y+0NZuVh3mh7Zs1c66y46HjgTOU5 Brsw== X-Gm-Message-State: AOJu0YxABLazEsGwKuOpeWx7uakuLLgAQMg2pcqqG9V5kViS54SQycxZ Lhnn+Jvb2gUvb3oaYmFwEHKANHwZBs+knW2MR6o= X-Google-Smtp-Source: AGHT+IHcIJkYa6B91qw/GdY/qa/2bUqeSZ9CRv/rHVqCXsOpRmSTmdSfjdTkrrscL2C6/VN6wRLdRw== X-Received: by 2002:a05:6358:3a0e:b0:168:9f53:9d67 with SMTP id g14-20020a0563583a0e00b001689f539d67mr493003rwe.20.1697671903722; Wed, 18 Oct 2023 16:31:43 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 10/14] linux-user: Map unsupported signals to an out-of-bounds value Date: Wed, 18 Oct 2023 16:31:30 -0700 Message-Id: <20231018233134.1594292-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c31; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc31.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Do not return a valid signal number in one domain when given an invalid signal number in the other domain. Acked-by: Helge Deller 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 aab05f8eec..653fd2f9fd 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -44,9 +44,8 @@ abi_ulong default_sigreturn; abi_ulong default_rt_sigreturn; /* - * System includes define _NSIG as SIGRTMAX + 1, - * but qemu (like the kernel) defines TARGET_NSIG as TARGET_SIGRTMAX - * and the first signal is SIGHUP defined as 1 + * System includes define _NSIG as SIGRTMAX + 1, but qemu (like the kernel) + * defines TARGET_NSIG as TARGET_SIGRTMAX and the first signal is 1. * Signal number 0 is reserved for use as kill(pid, 0), to test whether * a process exists without sending it a signal. */ @@ -57,7 +56,6 @@ static uint8_t host_to_target_signal_table[_NSIG] = { #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]; @@ -65,18 +63,24 @@ static uint8_t target_to_host_signal_table[TARGET_NSIG + 1]; /* valid sig is between 1 and _NSIG - 1 */ int host_to_target_signal(int sig) { - if (sig < 1 || sig >= _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]; } @@ -507,48 +511,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 Oct 18 23:31:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1851361 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=pzG5zr46; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S9nGd4mlzz1ypX for ; Thu, 19 Oct 2023 10:33:29 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG11-00046k-NV; Wed, 18 Oct 2023 19:31:51 -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 1qtG0x-00045t-Hs for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:47 -0400 Received: from mail-oo1-xc2e.google.com ([2607:f8b0:4864:20::c2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0v-0000M3-T7 for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:47 -0400 Received: by mail-oo1-xc2e.google.com with SMTP id 006d021491bc7-57b5f0d658dso4313547eaf.0 for ; Wed, 18 Oct 2023 16:31:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671904; x=1698276704; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ypG+ldHB73o41Fm0bO8P6h70i3rbf+HtP65cG8LvxlI=; b=pzG5zr46atE5QdTXGfnCBd4stxYeKsXYGtFMl7A8ZcxYviExjTX8HwCKlrFZHyy1AM An25RFjTnbph3IrIkomaYHFjIFBLDrFrRDnCJmQb+rhOaRfAG2yGiUnFTLwHx9NVDx9s EoB7PfHaWcjHHnK9s4CZlMKy4pG/PuzFKf7jvvQ6GRW9RURkJrRea7r/z8YLj/zDrHfs b9tOuklMN80IlPKTM20/138fG0qWP+hPBJmwIxbFGIrUHdhp9WkqK77vxhi+aDYVWoye iGKhNCGA3J31YZ11rRDVnuig1pTIVw4g9fatPC+yz0KYtuDr4EWfj4+neApcpjPIf+ny /KiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671904; x=1698276704; 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=ypG+ldHB73o41Fm0bO8P6h70i3rbf+HtP65cG8LvxlI=; b=huRgmOl8U2DpvKbr2rksGBYlDU7rfvZZbMf8k0d0BKkwlQy0bF3rqK2yWNQMhYWjBR Xz4F5+ZmCc7LOmJR55ChtWw6i1XArRt6lIh5TzpFHaIoK53BcpJ02g6ob6KchThOgyzG eetAHwmZitSi1CwVWOo3lqSOG8WHo84O3D6Fn8w6O/jRWkup0Ro1CMBgGDnMqKw/ZMVE 5fXYO8F7jDqA+dUsNsnX4SgDexsiolpAD2JoxaAYd4snpXb/jUhkp4+3fsh7lpA5kT6d ctCUAZsllQKXwCg2wWbeIr26KPTQGep8UVUBU/+bX2Ef1REQpVVUVU+3xOKPfnWCEKxp D6EQ== X-Gm-Message-State: AOJu0YybdRJc/AhjxsuCsq257HTv9kIrtt0ypECm9QTlynrqQmKihRUw CHZfLgABzLE9RsOZPZLSaYTd+2xIhgbZg724qPI= X-Google-Smtp-Source: AGHT+IEl7mPttHERM78ISqrmIPoyBEJmmolLhmHzT1Ds/3Lfh5w/nRCnvrcIltrcev3e/AAjp+c0Zw== X-Received: by 2002:a05:6358:ca6:b0:143:8084:e625 with SMTP id o38-20020a0563580ca600b001438084e625mr514122rwj.11.1697671904636; Wed, 18 Oct 2023 16:31:44 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 11/14] linux-user: Simplify signal_init Date: Wed, 18 Oct 2023 16:31:31 -0700 Message-Id: <20231018233134.1594292-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c2e; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc2e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Install the host signal handler at the same time we are probing the target signals for SIG_IGN/SIG_DFL. Ignore unmapped target signals. Acked-by: Helge Deller Signed-off-by: Richard Henderson --- linux-user/signal.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 653fd2f9fd..09840b0eb0 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -558,10 +558,7 @@ static void signal_table_init(void) void signal_init(void) { TaskState *ts = (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(); @@ -572,23 +569,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++) { - 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 Oct 18 23:31:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1851359 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=EHpkRAMr; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S9nGG50n3z1ypX for ; Thu, 19 Oct 2023 10:33:10 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG1F-0004Cv-96; Wed, 18 Oct 2023 19:32:05 -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 1qtG0y-00046T-OS for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:48 -0400 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0w-0000MI-Sq for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:48 -0400 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3b2e330033fso1196305b6e.3 for ; Wed, 18 Oct 2023 16:31:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671905; x=1698276705; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4PntMv8xOvYf8PdCQHI22CCEWflquoH9lu0dCFWPneE=; b=EHpkRAMrXIwDT5FLR4LG8rtZMw0c8YHdDexUuwLo76lPyWswUW4RI+D9q2+INMSuzv XbYob9mc7unLq6AlKkOlECeGD0+QRfEWNGHig840fgsQ3AHGDAHAVQBJmuRjpo8TFV0p KpA+rs3YVPjG16NMk4pKGtwnDsLdjncbwh2+tDc+o3nzOMhm23Q5aExRlAohGFW+7dnx Bd0MbUg0cv0PqiQbyaLkaPkf7qNEHhVUDidKA1M8Zgs117mTC0P7jnd7oED/rWCemwlv TctX60RENhua3jtdFKhd8BAIRLxLVlWKeg1MPSt0U0REO3rRpT781w+L2MfS6l+Kh5xQ cI0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671905; x=1698276705; 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=4PntMv8xOvYf8PdCQHI22CCEWflquoH9lu0dCFWPneE=; b=TiGlJgHdcBQHzX5UiwHSiY1ossiz9VaA9/GhEg0PrTc5kLj5BiCLvXv5i9UDuBX0ek /+NGVHol1UDtKD9D5AqNPyrD5jZQ913ypMq4OoxG/CtHCwXUaxNjMcbCBGg2bktk77Cr fHUsWpX0WotrTuFihnzfp7u6mn9fGYPRlCv9IOU3xBMZ2RwfupWIR2SOMBaM7X+OodKz +VIOpj/R177YZUlquUX3sGmSQgT4jNFPXsj/C9BKvyttt4hDC9YcIkYgoBdgdGVQ53bY rhGo7qKdKmuVMfCcl05MKGSXmQMZcAspGXdzbzDDyqqcA+JgH/pZ/i7OXg0uabqU5Evd iQSQ== X-Gm-Message-State: AOJu0YzWtGhlLkBRJdJMpn868WHjWpC4VB746AIJVvee+pwqFechyYIJ USxka0ohZJNBLNG4vBdPXqz1DbBVXg6KYzvygI8= X-Google-Smtp-Source: AGHT+IFxrarK4OtUFGadviKiRXWTnY3PnJ3SKFHrzOPoSPtrMFHFggJkRec5ynHtCRtWwZLObNcXFg== X-Received: by 2002:a05:6359:6317:b0:168:9100:d114 with SMTP id sf23-20020a056359631700b001689100d114mr377961rwb.21.1697671905327; Wed, 18 Oct 2023 16:31:45 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 12/14] linux-user: Split out host_sig{segv,bus}_handler Date: Wed, 18 Oct 2023 16:31:32 -0700 Message-Id: <20231018233134.1594292-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::234; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x234.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Make host_signal_handler slightly easier to read. Acked-by: Helge Deller 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 09840b0eb0..706b8ac7a7 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -811,6 +811,80 @@ void die_from_signal(siginfo_t *info) die_with_signal(info->si_signo); } +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_from_signal(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_from_signal(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) { CPUState *cpu = thread_cpu; @@ -822,73 +896,23 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) int guest_sig; uintptr_t pc = 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_from_signal(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 */ @@ -929,6 +953,7 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) * would write 0xff bytes off the end of the structure and trash * data on the struct. */ + sigmask = host_signal_mask(uc); memset(sigmask, 0xff, SIGSET_T_SIZE); sigdelset(sigmask, SIGSEGV); sigdelset(sigmask, SIGBUS); From patchwork Wed Oct 18 23:31:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1851357 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Q4ftAnus; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S9nGG56gbz23jP for ; Thu, 19 Oct 2023 10:33:10 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG1E-0004Co-Ua; Wed, 18 Oct 2023 19:32:04 -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 1qtG0y-00046X-Ua for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:48 -0400 Received: from mail-oo1-xc2f.google.com ([2607:f8b0:4864:20::c2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0x-0000MQ-Ai for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:48 -0400 Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-5832ea25c7eso345589eaf.3 for ; Wed, 18 Oct 2023 16:31:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671906; x=1698276706; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cPRrHvcXgvktiUIzW9SQzWI6+9vUxSTnLoJeJQFy4uw=; b=Q4ftAnus3bAgnokg7B1JoaQSGGyy4MUj3ftVpw+YvnQ1Xh3v174V4bNxFYwyfLh4i5 N8xrR4CFTxjaC63y8PEuPxUOKl/bUygLWpjJSW4yNwaH234+yaNUvSOWiIatELQ4SKu3 HLUfrNuVamfY6eqZ3WglmQ+3SNYYSCRFE1WRxeLdTkQpuP4p17a7uxENbCNNwmrEdc4S 0EobzHA8O7EhGKCDZxd78y5RyxYy4LODTlQYnitThE39WrBENT8D/8Z9BJ/zE20YTACn ptINnIIFVgpd/qx5nbtDBr5hmWrUGfJ6DGimne7hVGNxgxZRYMDmFc9/7eu+yyW93doF sTPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671906; x=1698276706; 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=cPRrHvcXgvktiUIzW9SQzWI6+9vUxSTnLoJeJQFy4uw=; b=FGuRr+C3ioQe3XREZBLPnBvYtHobGNWuf1NSPgObyWDMR50XlnVMATIWNK6y8i5kse KwMO5EW1wVad3wdBdcXU1UUs3EQxIXwQMkTlX/QvgxX2ON0DyaV7tsBvt93ULoKHROlM NCsktZUotqwrUZV5noWbVVSRI/noQNDkm6AjWdM16AE9qNhY1hVNY5JRSkld35iDiAhc Jf4MzyhDioAE50TmJOC1bCJX1d4pRzL2dwgIIq1WTskxdniuTFOTgfwJcAHNdHG6Apdv 7Ub3ZPVlNoi13owzGJzDF11xw9+405Gp/1/JUmw6/EYxxkXywFP1ISXuP+X62Y47mNYP 1W+w== X-Gm-Message-State: AOJu0YwrGN1yO0UihF2DWoNdIQC8tniQJIQ1rwGZ6/AucE38eK9rZvtW SPLGGs7hYOo0BDiqg1vp5fahc+KVA3IAi1+HgkM= X-Google-Smtp-Source: AGHT+IGYNBMmBtJusrVDe2Dmtnn+/ugkCpQpRaZREWiChk3JgoNXhtioxbHn+/SjQnohNEzPmnpJbQ== X-Received: by 2002:a05:6359:3110:b0:134:d806:69df with SMTP id rh16-20020a056359311000b00134d80669dfmr364662rwb.18.1697671906034; Wed, 18 Oct 2023 16:31:46 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 13/14] linux-user: Detect and report host SIGILL, SIGFPE, SIGTRAP Date: Wed, 18 Oct 2023 16:31:33 -0700 Message-Id: <20231018233134.1594292-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c2f; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc2f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org These signals, when not spoofed via kill(), are always bugs. Use die_from_signal to report this sensibly. Acked-by: Helge Deller Signed-off-by: Richard Henderson --- linux-user/signal.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 706b8ac7a7..b67077f320 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -796,6 +796,43 @@ void die_from_signal(siginfo_t *info) break; } break; + case SIGILL: + sig = "ILL"; + switch (info->si_code) { + case ILL_ILLOPC: + code = "ILLOPC"; + break; + case ILL_ILLOPN: + code = "ILLOPN"; + break; + case ILL_ILLADR: + code = "ILLADR"; + break; + case ILL_PRVOPC: + code = "PRVOPC"; + break; + case ILL_PRVREG: + code = "PRVREG"; + break; + case ILL_COPROC: + code = "COPROC"; + break; + } + break; + case SIGFPE: + sig = "FPE"; + switch (info->si_code) { + case FPE_INTDIV: + code = "INTDIV"; + break; + case FPE_INTOVF: + code = "INTOVF"; + break; + } + break; + case SIGTRAP: + sig = "TRAP"; + break; default: snprintf(sigbuf, sizeof(sigbuf), "%d", info->si_signo); sig = sigbuf; @@ -900,7 +937,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) { @@ -912,6 +950,10 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) host_sigbus_handler(cpu, info, uc); sync_sig = true; break; + case SIGILL: + case SIGFPE: + case SIGTRAP: + die_from_signal(info); } } From patchwork Wed Oct 18 23:31:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1851360 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=bGdIuMhR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S9nGH4ZYgz26jQ for ; Thu, 19 Oct 2023 10:33:11 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG1J-0004Ho-54; Wed, 18 Oct 2023 19:32:09 -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 1qtG10-00046n-7s for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:51 -0400 Received: from mail-oo1-xc33.google.com ([2607:f8b0:4864:20::c33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0y-0000Md-2O for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:49 -0400 Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-57be3d8e738so4161992eaf.1 for ; Wed, 18 Oct 2023 16:31:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671907; x=1698276707; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bnu9T106+3Frnuh9qTylVBrRrlFzWm5MBIT4IbQZiD0=; b=bGdIuMhRHz4aRB7J3gowVA8JKknhwObHJvk3PnhzNtSGbGG7KzLc24hvke0P4pAf2k 3cLfROlbtFfXJiFZ2LG7FRYnrUlWOsknkN7CMnJMsaSfBj04gWiafeC/PqrQK/dLLdX/ LmeI6EEyt5KAi4IoeeFcDK9LXt7cs0d3L6p15IIO2QTrB5qT/sjT0xNsH7RiaY8jdtLv FkxDlY3r10F5EqU9Z8rf5GN7NVblkswi8bWySeI5PICer5wcy14UDW7nD4cB95JwnlCb P7MxmQf4+t5tqoSoOPgApiOXIbJqOJqHFdAqmx3QFeWRITPQX/BkDQztzudH4M/tBEUS 95tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671907; x=1698276707; 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=bnu9T106+3Frnuh9qTylVBrRrlFzWm5MBIT4IbQZiD0=; b=D+AE1z0xAHzpjnIl5F8eJJEpbTQiA/spqhqbZu3xyumHJ/xy4kUycJTCYysc46D6U1 tylO24+G8NL8E8dqSbverXBxyKVa3VccGxWtacaZukJyUMxIEt3bemPO5Y479ESif3X8 m2f58vpzMEzRjdP6z305JPFXTegmmP5xVlUe+OwwqSbLw3lk6leRd/fkooS+F0ATXQmJ jouhEkftdqNFMfSL3dp/1+Oe8ESegWK9yaEOxakKQ19Jb/eUPCRkf/cKBTOtBne3BGJK 2gvD3OSap6J/iAm1/bB/tDDv2ur/ScbmN0wduNEcbbipadowSKslVuH8BQCc2l1yCLzM Sgow== X-Gm-Message-State: AOJu0Yw6NuexBVOV8U6EDNVyRqaE3HaDKTded6aHLmJZyso5YVXSlcjR cJVXrxLDwnCVCsHtzZSUM90WnVf/3MbCNCCGBZY= X-Google-Smtp-Source: AGHT+IGHGeg/Thp/MvOBWr47nlNt2wd1PoccI1xeNEuUJCZpfAB/CqMIrIui43oupOxyxJ2uSoktGg== X-Received: by 2002:a05:6359:5e18:b0:164:8d78:258a with SMTP id pw24-20020a0563595e1800b001648d78258amr419570rwb.20.1697671906794; Wed, 18 Oct 2023 16:31:46 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 14/14] linux-user: Remap guest SIGABRT Date: Wed, 18 Oct 2023 16:31:34 -0700 Message-Id: <20231018233134.1594292-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c33; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc33.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Distinguish host SIGABRT from guest SIGABRT by mapping the guest signal onto one of the host RT signals. This prevents a cycle by which a host assertion failure is caught and handled by host_signal_handler, queued for the guest, and then we attempt to continue past the host abort. What happens next depends on the host libc, but is neither good nor helpful. Acked-by: Helge Deller Signed-off-by: Richard Henderson --- linux-user/signal.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index b67077f320..3b8efec89f 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -522,8 +522,21 @@ static void signal_table_init(void) * multiplexed over a single host signal. * Attempts for configure "missing" signals via sigaction will be * silently ignored. + * + * Remap the target SIGABRT, so that we can distinguish host abort + * from guest abort. When the guest registers a signal handler or + * calls raise(SIGABRT), the host will raise SIG_RTn. If the guest + * arrives at dump_core_and_abort(), we will map back to host SIGABRT + * so that the parent (native or emulated) sees the correct signal. + * Finally, also map host to guest SIGABRT so that the emulated + * parent sees the correct mapping from wait status. */ - for (hsig = SIGRTMIN; hsig <= SIGRTMAX; hsig++) { + + hsig = SIGRTMIN; + host_to_target_signal_table[SIGABRT] = 0; + host_to_target_signal_table[hsig++] = TARGET_SIGABRT; + + for (; hsig <= SIGRTMAX; hsig++) { tsig = hsig - SIGRTMIN + TARGET_SIGRTMIN; if (tsig <= TARGET_NSIG) { host_to_target_signal_table[hsig] = tsig; @@ -539,6 +552,8 @@ static void signal_table_init(void) } } + host_to_target_signal_table[SIGABRT] = TARGET_SIGABRT; + /* Map everything else out-of-bounds. */ for (hsig = 1; hsig < _NSIG; hsig++) { if (host_to_target_signal_table[hsig] == 0) { @@ -582,13 +597,21 @@ void signal_init(void) 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; + if (hsig >= _NSIG) { + continue; + } + /* As we force remap SIGABRT, cannot probe and install in one step. */ + if (tsig == TARGET_SIGABRT) { + sigaction(SIGABRT, NULL, &oact); + sigaction(hsig, &act, NULL); + } else { + struct sigaction *iact = core_dump_signal(tsig) ? &act : NULL; sigaction(hsig, iact, &oact); - if (oact.sa_sigaction != (void *)SIG_IGN) { - thand = TARGET_SIG_DFL; - } + } + + if (oact.sa_sigaction != (void *)SIG_IGN) { + thand = TARGET_SIG_DFL; } sigact_table[tsig - 1]._sa_handler = thand; } @@ -711,7 +734,12 @@ void dump_core_and_abort(CPUArchState *env, int target_sig) TaskState *ts = (TaskState *)cpu->opaque; int host_sig, core_dumped = 0; - host_sig = target_to_host_signal(target_sig); + /* On exit, undo the remapping of SIGABRT. */ + if (target_sig == TARGET_SIGABRT) { + host_sig = SIGABRT; + } else { + host_sig = target_to_host_signal(target_sig); + } trace_user_dump_core_and_abort(env, target_sig, host_sig); gdb_signalled(env, target_sig);