From nobody Wed Nov 27 17:29:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697672034; cv=none; d=zohomail.com; s=zohoarc; b=erMitLcJJuOGpz7uKyJ1bHsJRptQwvaOgdvoodP+eLJNEVSLAPM7Y7JZCUuybfcqcCMUzFMZc69GSWg/YegJCL2w80NDk2vJd2PUde4/h3A2T/age2Gck+CqtQaqXjNA6IpcGNIKA7V5qT1BlUhiK03gKa6KzTCoOwPXzPNfPqE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697672034; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=D2oYojizKTJe59+z2rFn3jhqwAzCHsM3phmz2spMImU=; b=Dmn0bmBNxFP2kndEYpTkncFc1gHgmJC0vEConSoUhbmUowTkiq3S4CLMlEV/TQdE2gWzG2s6JV0KB96rrgKiHIk8eJTB81au+l0l9Fuxj6zqlBRZmq2NWQOsBT1kFwQE/K/c+nB6ppoLdZjAapP9Wr0rb4A8tKXToOzvw0JXQaQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697672034301645.8506952153143; Wed, 18 Oct 2023 16:33:54 -0700 (PDT) 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) 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) 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) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697672036511100003 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=C3=A9 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_binpr= m *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; =20 + /* 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 =3D TARGET_PAGE_ALIGN(start_bss); end_bss =3D TARGET_PAGE_ALIGN(end_bss); =20 if (start_bss < align_bss) { int flags =3D page_get_flags(start_bss); =20 - 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 -=3D 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); } } =20 - return align_bss >=3D end_bss || - target_mmap(align_bss, end_bss - align_bss, prot, - MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) !=3D -1; + if (align_bss < end_bss && + target_mmap(align_bss, end_bss - align_bss, prot, + MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) =3D=3D -1) { + error_setg_errno(errp, errno, "Error mapping bss"); + return false; + } + return true; } =20 #if defined(TARGET_ARM) @@ -3410,8 +3437,8 @@ static void load_elf_image(const char *image_name, in= t image_fd, =20 /* 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; } =20 /* Find the full program boundaries. */ --=20 2.34.1 From nobody Wed Nov 27 17:29:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697672028; cv=none; d=zohomail.com; s=zohoarc; b=FrdEABiSnAGruZu5LpOJm6jEWxIdJCrmpIyD+3B0FHT5UgBX0lMjIV02cOYgCWs6VjREVJvQtds07CSyUpDCWS2CVKza86J1u8syoDyqZJpUc5PLocvAGtnPpqO2X4PSX2go/kvwwzBKubVwxDxBdm73QxWODN9GEVltUUQW+8I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697672028; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1I5j+CVAtN1UYbE5YS09fVUfZ8qAm7sA0ML6lgTI9YE=; b=ZxJkjFnuE2vL6AUjio1BxsINpfHoD9AtSjeTiIe6eE8FVn/xwjGJ0MEoQphy9mq6QwUO2HIjVtvKFWfuFVBOAujV8kvRt/GhU7bcq1rqFFPZQWGgWCwMBIcdE1mNQxFXI1dY+YFl4qT+3ghZ06lqjAvdVPDDvB9y67K6zafej5o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697672028347367.2208190390103; Wed, 18 Oct 2023 16:33:48 -0700 (PDT) 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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697672030535100007 Content-Type: text/plain; charset="utf-8" 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. */ --=20 2.34.1 From nobody Wed Nov 27 17:29:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697671989; cv=none; d=zohomail.com; s=zohoarc; b=Bs6gS0/WRiFMRIaXT/acrxGffgGh9dcXH3gO1sWY97mbN1v2LOrJVqCvRHy/xHJC3aI8KHPqB8Gj2u384d10kPGNVpO5uyKxachH2VRk/yH9Tdt/Kpd7Y4j+6kctjUcKrJjIDp6z9+kpY6POoP5LuktQshnz6TWn5VxGSWr5iEo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697671989; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2k8XNRKudZqb8EBVa8P0hTDCeDuuDeqPExqYOmBXPTU=; b=esOop0zXd3f7rm2MnCA9Qd1TB2cexjG3Zr7XI21HW52TAN54DcAksEXCVXpsaAqJ/c16T9qeiG/plvPUAQcTRKwvAITZol7t/cFOWau0blsUrmF240QHSQXmhjNwukK06f2xlmsMH5BrQCHOJ0Hm8afxr6A77t0ddwqGa916pDE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697671989900478.23465839994344; Wed, 18 Oct 2023 16:33:09 -0700 (PDT) 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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697671990345100002 Content-Type: text/plain; charset="utf-8" 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 >=3D -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) =20 /* Reset the SP to the saved version in R1. */ regs->gregs[15] =3D regs->gregs[1]; + } else if (regs->gregs[15] >=3D -128u && regs->pc =3D=3D regs->gregs[0= ]) { + /* If we are on the last instruction of a gUSA region, we must res= et + the SP, otherwise we would be pushing the signal context to + invalid memory. */ + regs->gregs[15] =3D regs->gregs[1]; + } else if (regs->flags & TB_FLAG_DELAY_SLOT) { + /* If we are in a delay slot, push the previous instruction. */ + regs->pc -=3D 2; } } =20 --=20 2.34.1 From nobody Wed Nov 27 17:29:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697672064; cv=none; d=zohomail.com; s=zohoarc; b=lGu9AFq2nzBnuIgQlPaHdWKm+dkCDbpMAZGePef/gFkwmCC+kdMQU4eP5DU4/yrCC7pgJYNH9JAC2okP+4VTDABoIt9p4wbEpt8HHoV3AzkSxpuT5m3ZmTzewGm5rtRGueyw6MLieBOG0OIgNUTn9/1MGl0mEhcF5JcqWaeJxRE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697672064; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KeKGrdrxTYoWvojPluBjviNWq1U0AbGSCGNtTdLurtI=; b=GTNPShasF87i+GtIMxZwmBtJ7QoWOnSTuuMWQVn7SGz5V1kUuNd7DLIltfVB0Oef1yfxsZcOkCfUjF1ZsGrekZGosv2Fl2KPRVGJ1PTXd+5lI7xggraX4fGdOZVCz5bkjaB6vDK/QC1ifjJOGPhaVb7FgeoZM+bWFjm6JnirTI8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697672064213147.5087535130691; Wed, 18 Oct 2023 16:34:24 -0700 (PDT) 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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697672064718100005 Content-Type: text/plain; charset="utf-8" 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 |=3D HWCAP_LOONGARCH_LAM; } =20 + if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) { + hwcaps |=3D HWCAP_LOONGARCH_LSX; + } + + if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LASX)) { + hwcaps |=3D HWCAP_LOONGARCH_LASX; + } + return hwcaps; } =20 --=20 2.34.1 From nobody Wed Nov 27 17:29:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697672018; cv=none; d=zohomail.com; s=zohoarc; b=Vkwxj+euMHf42asu0o/+sGXkRoCfoWXhAuqjA/CDGxpz8KlMx2bcMKfoothDjmEbs+fxr/yFVFKRdpOSnPZ3smRhzwEfCHHyAa4MvQKqvEnqj9OS/teSnHeSvZqb9ImNvxihnazJCzc5Nz9Kg22Gan0bYLqRNtsx9CyTcUF5IwM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697672018; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MZQXmTezubKvZiknkUGl30NcUMWQlr0tOKsu9AI7N20=; b=kRU/QKs0kZKRPNAv8KPF5t1Dcl6CaTzonrs76mqBPHLsVFW2bbN1WKSk/W+32n5n+LgIfVT/1ZeGYflU0dfRbFd/gxR3MTnYlXDJfz6QUTqpwKVsOv5uf7WhtVfeg1fz0jR5Yz1u5tmYb4qRTfU79gXn04/usaePDz/qoXKDZIc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169767201850837.406748078738815; Wed, 18 Oct 2023 16:33:38 -0700 (PDT) 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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697672020427100003 Content-Type: text/plain; charset="utf-8" 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; } =20 -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 |=3D page_get_flags(a + 1); } if (prot !=3D 0) { - return; + return 0; } } else { for (prot =3D 0, a =3D real_start; a < start; a +=3D TARGET_PAGE_S= IZE) { @@ -825,7 +825,7 @@ static void mmap_reserve_or_unmap(abi_ulong start, abi_= ulong len) } =20 if (real_last < real_start) { - return; + return 0; } } =20 @@ -836,32 +836,36 @@ static void mmap_reserve_or_unmap(abi_ulong start, ab= i_ulong len) void *ptr =3D mmap(host_start, real_len, PROT_NONE, MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, -1, 0); - assert(ptr =3D=3D host_start); - } else { - int ret =3D munmap(host_start, real_len); - assert(ret =3D=3D 0); + return ptr =3D=3D host_start ? 0 : -1; } + return munmap(host_start, real_len); } =20 int target_munmap(abi_ulong start, abi_ulong len) { + int ret; + trace_target_munmap(start, len); =20 if (start & ~TARGET_PAGE_MASK) { - return -TARGET_EINVAL; + errno =3D EINVAL; + return -1; } len =3D TARGET_PAGE_ALIGN(len); if (len =3D=3D 0 || !guest_range_valid_untagged(start, len)) { - return -TARGET_EINVAL; + errno =3D EINVAL; + return -1; } =20 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 =3D mmap_reserve_or_unmap(start, len); + if (likely(ret =3D=3D 0)) { + page_set_flags(start, start + len - 1, 0); + shm_region_rm_complete(start, start + len - 1); + } mmap_unlock(); =20 - return 0; + return ret; } =20 abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, --=20 2.34.1 From nobody Wed Nov 27 17:29:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697672062; cv=none; d=zohomail.com; s=zohoarc; b=VSLhDL7W1Fy2JoAnSfrsKa2/+3+6NHJMpXA7fJhbFQxfjf+2QlmjF3t7GCQ1XkREjKYdis/KjOfy1IZJ8lyLLDaWkWc0z7vpdq0YUeCZtXkZQUNhuIIW7lrElj4/idHnZaO5R4gnODaCmlhOMGiohcEnxrpkxmE6kdmJCt2w6qk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697672062; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HR6OhNjXMnjPeW+GKwBhvGRBpRXClWtOK/vmyhs99O8=; b=C5s9I94kKkdALp0SF5XZ092cTjcHpRVGhvofToWrPGGMgxTdPFbi6XCSuH9RsumCN2OkZlWB2G4z12R6q4jWovz+eb4RmbVbbhUmPu8ewROMTMjRbl69fHjZ6Rxo7aDgUVO6//3go0Hn37rfvyITbdnMlzsvvUfEp/6HTDj+OXY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697672062349501.1365656223576; Wed, 18 Oct 2023 16:34:22 -0700 (PDT) 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) 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) 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) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , =?UTF-8?q?Philippe=20Mathieu-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697672062591100001 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=C3=A9 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, } =20 /* abort execution with signal */ +static G_NORETURN +void die_with_signal(int host_sig) +{ + struct sigaction act =3D { + .sa_handler =3D SIG_DFL, + }; + + /* + * The proper exit code for dying from an uncaught signal is -. + * The kernel doesn't allow exit() or _exit() to pass a negative value. + * To get the proper exit code we need to actually die from an uncaught + * signal. Here the default signal handler is installed, we send + * the signal and we wait for it to arrive. + */ + sigfillset(&act.sa_mask); + sigaction(host_sig, &act, NULL); + + kill(getpid(), host_sig); + + /* Make sure the signal isn't masked (reusing the mask inside of act).= */ + sigdelset(&act.sa_mask, host_sig); + sigsuspend(&act.sa_mask); + + /* unreachable */ + abort(); +} + static G_NORETURN void dump_core_and_abort(CPUArchState *env, int target_sig) { CPUState *cpu =3D env_cpu(env); TaskState *ts =3D (TaskState *)cpu->opaque; int host_sig, core_dumped =3D 0; - struct sigaction act; =20 host_sig =3D target_to_host_signal(target_sig); trace_user_dump_core_and_abort(env, target_sig, host_sig); @@ -719,29 +745,7 @@ void dump_core_and_abort(CPUArchState *env, int target= _sig) } =20 preexit_cleanup(env, 128 + target_sig); - - /* The proper exit code for dying from an uncaught signal is - * -. The kernel doesn't allow exit() or _exit() to pass - * a negative value. To get the proper exit code we need to - * actually die from an uncaught signal. Here the default signal - * handler is installed, we send ourself a signal and we wait for - * it to arrive. */ - sigfillset(&act.sa_mask); - act.sa_handler =3D SIG_DFL; - act.sa_flags =3D 0; - sigaction(host_sig, &act, NULL); - - /* For some reason raise(host_sig) doesn't send the signal when - * statically linked on x86-64. */ - kill(getpid(), host_sig); - - /* Make sure the signal isn't masked (just reuse the mask inside - of act) */ - sigdelset(&act.sa_mask, host_sig); - sigsuspend(&act.sa_mask); - - /* unreachable */ - abort(); + die_with_signal(host_sig); } =20 /* queue a signal so that it will be send to the virtual CPU as soon --=20 2.34.1 From nobody Wed Nov 27 17:29:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697672010; cv=none; d=zohomail.com; s=zohoarc; b=Q0chMpNhr+plDd2PhhPQ51Wm3jBlPWs+Haf0j94f2EkYsG9igP4u2sybc98ufBMUboYHwZ/QmYUgAmquUx/MK2qo+VTymLv2AafZuEoPbkuOZD3AxFKvmMzWJG/NzpolIguKOUJU1UzCGfVv0hmivTFhtdS5QJOuD1DKGNRkav4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697672010; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XDEeeYBNH4kaMPDKd2bpL06m4MGoDecFzYDq6oXSWUM=; b=ZtKMYZ3+Gf6va0RY4rpZE18YmLc1mlPKh/SCs1v7/tEnRTpab4I3re9Ofip2IpPT8J+y3J/O4g+5GOfzov1nkiwkgQIdhR/Wm+145CEbq4KLPvcz3C0KcRmIzTqO+nfl8Z5VlYoNUHMuZP+wrL03mQhSEZ32o7U1f4eDENySdNQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169767201025168.66986909145623; Wed, 18 Oct 2023 16:33:30 -0700 (PDT) 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) 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) 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) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , =?UTF-8?q?Philippe=20Mathieu-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697672012367100007 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=C3=A9 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); =20 /* unreachable */ - abort(); + _exit(EXIT_FAILURE); } =20 static G_NORETURN --=20 2.34.1 From nobody Wed Nov 27 17:29:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697671989; cv=none; d=zohomail.com; s=zohoarc; b=FlirsrMRhljy06fxNL+9oh2zizw5rOqmhMXuQZwD4U/B6oVaNIdMgNH5MRXqPVCA2RODQWrG24rBoZpDzSFyPq7omeGwAPlHL/PtNnvox02LvyxAyi8o93t2ulCitgV2BAwNa0ESKrxnOxhFi9fP75CLJAFFjIIvl7XbbAxcJ+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697671989; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OQP2+HZbJmIj9sXXPBVMTwI7vC2S6c38AoM7akl90XU=; b=LTfmWuLaJPQgjoG5lt/p3rd+qxP2fzQh6+Jk+vJc+U5RRYNNmQRNsJbbgiN5ORfh/zRb84fbuhxFYoOH4JSGKOCxI+zP1PnsPZBDSJNxakIVwQ4hNc7e3oewh/HLxUy9JbbebeptEPiS1oMLpBT26VGIf/wBv8gjNIIF7FDd61I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697671989948557.065242480758; Wed, 18 Oct 2023 16:33:09 -0700 (PDT) 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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697671990358100003 Content-Type: text/plain; charset="utf-8" From: Helge Deller If there is an internal program error in the qemu source code which raises SIGSEGV or SIGBUS, we currently assume the signal belongs to the guest. With an artificial error introduced, we will now print QEMU internal SIGSEGV {code=3DMAPERR, addr=3D(nil)} Signed-off-by: Helge Deller Message-Id: <20230812164314.352131-1-deller@gmx.de> [rth: Use in_code_gen_buffer and die_with_signal; drop backtrace] Signed-off-by: Richard Henderson --- linux-user/signal.c | 69 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 84a56b76cc..9fadc51347 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -32,6 +32,7 @@ #include "signal-common.h" #include "host-signal.h" #include "user/safe-syscall.h" +#include "tcg/tcg.h" =20 static struct target_sigaction sigact_table[TARGET_NSIG]; =20 @@ -779,6 +780,50 @@ static inline void rewind_if_in_safe_syscall(void *puc) } } =20 +static G_NORETURN +void die_from_signal(siginfo_t *info) +{ + char sigbuf[4], codebuf[12]; + const char *sig, *code =3D NULL; + + switch (info->si_signo) { + case SIGSEGV: + sig =3D "SEGV"; + switch (info->si_code) { + case SEGV_MAPERR: + code =3D "MAPERR"; + break; + case SEGV_ACCERR: + code =3D "ACCERR"; + break; + } + break; + case SIGBUS: + sig =3D "BUS"; + switch (info->si_code) { + case BUS_ADRALN: + code =3D "ADRALN"; + break; + case BUS_ADRERR: + code =3D "ADRERR"; + break; + } + break; + default: + snprintf(sigbuf, sizeof(sigbuf), "%d", info->si_signo); + sig =3D sigbuf; + break; + } + if (code =3D=3D NULL) { + snprintf(codebuf, sizeof(sigbuf), "%d", info->si_code); + code =3D codebuf; + } + + error_report("QEMU internal SIG%s {code=3D%s, addr=3D%p}", + sig, code, info->si_addr); + die_with_signal(info->si_signo); +} + static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) { CPUState *cpu =3D thread_cpu; @@ -814,16 +859,28 @@ static void host_signal_handler(int host_sig, siginfo= _t *info, void *puc) is_write =3D host_signal_write(info, uc); access_type =3D adjust_signal_pc(&pc, is_write); =20 + /* If this was a write to a TB protected page, restart. */ + if (is_write + && host_sig =3D=3D SIGSEGV + && info->si_code =3D=3D SEGV_ACCERR + && h2g_valid(host_addr) + && handle_sigsegv_accerr_write(cpu, sigmask, pc, guest_addr)) { + return; + } + + /* + * If the access was not on behalf of the guest, within the execut= able + * mapping of the generated code buffer, then it is a host bug. + */ + if (access_type !=3D MMU_INST_FETCH + && !in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { + die_from_signal(info); + } + if (host_sig =3D=3D SIGSEGV) { bool maperr =3D true; =20 if (info->si_code =3D=3D SEGV_ACCERR && h2g_valid(host_addr)) { - /* If this was a write to a TB protected page, restart. */ - if (is_write && - handle_sigsegv_accerr_write(cpu, sigmask, pc, guest_ad= dr)) { - return; - } - /* * With reserved_va, the whole address space is PROT_NONE, * which means that we may get ACCERR when we want MAPERR. --=20 2.34.1 From nobody Wed Nov 27 17:29:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697672027; cv=none; d=zohomail.com; s=zohoarc; b=XRBF0MewTnkfdo4Y29KghEQ/UXKI5kXTPAtx6gBtU0BlaxLs0D3ecATrkCxM0xYaxWvuv3uPx8LrtYo+JuBD+etJ/dAR+ETLKiu8JNR8FkWEihg9L1diS+d+FwS6+GyVbV5Ev8IltOkvugXTBrCSDEp4hLSGEYs0w9wF5xWw9oE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697672027; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=N8YP8FFBP63+6pJ6d97ew/Y5ZJwzVjBAkzrh/+j6myU=; b=Nvm8+1j72IW/GaJDFVCQIDw/yZGBUUmiIoy5JhbfRmZmbQRbHKxpcDqm1EnTpq5aF4rImR4gYQbshmCDU1LsVsPfspw5BmDpHI29r1j7whVrJD8oLKcrUeTm3IU4zfqjZMGcpN1YoX4tljuu5Wyc0fpm4D3upRvJGkIMMB+wwkw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697672027105337.54505062008946; Wed, 18 Oct 2023 16:33:47 -0700 (PDT) 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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697672028445100003 Content-Type: text/plain; charset="utf-8" The set of fatal signals is really immaterial. If one arrives, and is unhandled, then the qemu process dies and the parent gets the correct signal. It is only for those signals which we would like to perform a guest core dump instead of a host core dump that we need to catch. 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 tar= get_siginfo_t *tinfo) info->si_value.sival_ptr =3D (void *)(long)sival_ptr; } =20 -static int fatal_signal (int sig) -{ - switch (sig) { - case TARGET_SIGCHLD: - case TARGET_SIGURG: - case TARGET_SIGWINCH: - /* Ignored by default. */ - return 0; - case TARGET_SIGCONT: - case TARGET_SIGSTOP: - case TARGET_SIGTSTP: - case TARGET_SIGTTIN: - case TARGET_SIGTTOU: - /* Job control signals. */ - return 0; - default: - return 1; - } -} - /* returns 1 if given signal should dump core if not handled */ static int core_dump_signal(int sig) { @@ -602,8 +582,9 @@ void signal_init(void) SIGSEGV and SIGBUS, to detect exceptions. We can not just trap all signals because it affects syscall interrupt behavior. But do trap all default-fatal signals. */ - if (fatal_signal (i)) + if (core_dump_signal(i)) { sigaction(host_sig, &act, NULL); + } } } =20 @@ -997,7 +978,6 @@ int do_sigaction(int sig, const struct target_sigaction= *act, struct target_sigaction *oact, abi_ulong ka_restorer) { struct target_sigaction *k; - struct sigaction act1; int host_sig; int ret =3D 0; =20 @@ -1057,22 +1037,27 @@ int do_sigaction(int sig, const struct target_sigac= tion *act, return 0; } if (host_sig !=3D SIGSEGV && host_sig !=3D SIGBUS) { + struct sigaction act1; + sigfillset(&act1.sa_mask); act1.sa_flags =3D SA_SIGINFO; - if (k->sa_flags & TARGET_SA_RESTART) - act1.sa_flags |=3D SA_RESTART; - /* NOTE: it is important to update the host kernel signal - ignore state to avoid getting unexpected interrupted - syscalls */ if (k->_sa_handler =3D=3D TARGET_SIG_IGN) { + /* + * It is important to update the host kernel signal ignore + * state to avoid getting unexpected interrupted syscalls. + */ act1.sa_sigaction =3D (void *)SIG_IGN; } else if (k->_sa_handler =3D=3D TARGET_SIG_DFL) { - if (fatal_signal (sig)) + if (core_dump_signal(sig)) { act1.sa_sigaction =3D host_signal_handler; - else + } else { act1.sa_sigaction =3D (void *)SIG_DFL; + } } else { act1.sa_sigaction =3D host_signal_handler; + if (k->sa_flags & TARGET_SA_RESTART) { + act1.sa_flags |=3D SA_RESTART; + } } ret =3D sigaction(host_sig, &act1, NULL); } --=20 2.34.1 From nobody Wed Nov 27 17:29:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697672012; cv=none; d=zohomail.com; s=zohoarc; b=Cmvt3Dmfz3iFU/B3ptVEn3Yj4FMxsfT/xylTYiNMtsemwjYjNZ4hrvRO8E5tjY5F+4jTGDkHzKqgBSvuABUWXpTHDPXN7JckC42i4KjbRAj3yMBdzsNXAacCthGBOB/0JWzuxhYh1R6JuM2VFGzxxxja9sICVy4UVehnr8je2Uo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697672012; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UKWfNxY8ZBT24vryvV7tNUff057UO3MB5fEykagaJko=; b=dCZFWh3rJ0gcdFAZIxqULO8hIcpYRhdgKndc9pSHdbtmI6ZqRl7w0kJS7uBBKN2wPQrd6Gcyv8RBt9y/oOJTwB6IRvQtinGK7HG0oteQjDKWlXcrwHbpy/WDcl9UX7bu1/4VOyFURrfA+8zo4u+jw9xBfveovDjWD5xGJLNmlWs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697672012687172.2078835506943; Wed, 18 Oct 2023 16:33:32 -0700 (PDT) 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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697672014429100014 Content-Type: text/plain; charset="utf-8" Do not return a valid signal number in one domain when given an invalid signal number in the other domain. 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; =20 /* - * System includes define _NSIG as SIGRTMAX + 1, - * but qemu (like the kernel) defines TARGET_NSIG as TARGET_SIGRTMAX - * and the first signal is SIGHUP defined as 1 + * System includes define _NSIG as SIGRTMAX + 1, but qemu (like the kernel) + * defines TARGET_NSIG as TARGET_SIGRTMAX and the first signal is 1. * Signal number 0 is reserved for use as kill(pid, 0), to test whether * a process exists without sending it a signal. */ @@ -57,7 +56,6 @@ static uint8_t host_to_target_signal_table[_NSIG] =3D { #define MAKE_SIG_ENTRY(sig) [sig] =3D TARGET_##sig, MAKE_SIGNAL_LIST #undef MAKE_SIG_ENTRY - /* next signals stay the same */ }; =20 static uint8_t target_to_host_signal_table[TARGET_NSIG + 1]; @@ -65,18 +63,24 @@ static uint8_t target_to_host_signal_table[TARGET_NSIG = + 1]; /* valid sig is between 1 and _NSIG - 1 */ int host_to_target_signal(int sig) { - if (sig < 1 || sig >=3D _NSIG) { + if (sig < 1) { return sig; } + if (sig >=3D _NSIG) { + return TARGET_NSIG + 1; + } return host_to_target_signal_table[sig]; } =20 /* valid sig is between 1 and TARGET_NSIG */ int target_to_host_signal(int sig) { - if (sig < 1 || sig > TARGET_NSIG) { + if (sig < 1) { return sig; } + if (sig > TARGET_NSIG) { + return _NSIG; + } return target_to_host_signal_table[sig]; } =20 @@ -507,48 +511,48 @@ static int core_dump_signal(int sig) =20 static void signal_table_init(void) { - int host_sig, target_sig, count; + int hsig, tsig, count; =20 /* * Signals are supported starting from TARGET_SIGRTMIN and going up - * until we run out of host realtime signals. - * glibc at least uses only the lower 2 rt signals and probably - * nobody's using the upper ones. - * it's why SIGRTMIN (34) is generally greater than __SIGRTMIN (32) - * To fix this properly we need to do manual signal delivery multiplex= ed - * over a single host signal. + * until we run out of host realtime signals. Glibc uses the lower 2 + * RT signals and (hopefully) nobody uses the upper ones. + * This is why SIGRTMIN (34) is generally greater than __SIGRTMIN (32). + * To fix this properly we would need to do manual signal delivery + * multiplexed over a single host signal. * Attempts for configure "missing" signals via sigaction will be * silently ignored. */ - for (host_sig =3D SIGRTMIN; host_sig <=3D SIGRTMAX; host_sig++) { - target_sig =3D host_sig - SIGRTMIN + TARGET_SIGRTMIN; - if (target_sig <=3D TARGET_NSIG) { - host_to_target_signal_table[host_sig] =3D target_sig; + for (hsig =3D SIGRTMIN; hsig <=3D SIGRTMAX; hsig++) { + tsig =3D hsig - SIGRTMIN + TARGET_SIGRTMIN; + if (tsig <=3D TARGET_NSIG) { + host_to_target_signal_table[hsig] =3D tsig; } } =20 - /* generate signal conversion tables */ - for (target_sig =3D 1; target_sig <=3D TARGET_NSIG; target_sig++) { - target_to_host_signal_table[target_sig] =3D _NSIG; /* poison */ - } - for (host_sig =3D 1; host_sig < _NSIG; host_sig++) { - if (host_to_target_signal_table[host_sig] =3D=3D 0) { - host_to_target_signal_table[host_sig] =3D host_sig; - } - target_sig =3D host_to_target_signal_table[host_sig]; - if (target_sig <=3D TARGET_NSIG) { - target_to_host_signal_table[target_sig] =3D host_sig; + /* Invert the mapping that has already been assigned. */ + for (hsig =3D 1; hsig < _NSIG; hsig++) { + tsig =3D host_to_target_signal_table[hsig]; + if (tsig) { + assert(target_to_host_signal_table[tsig] =3D=3D 0); + target_to_host_signal_table[tsig] =3D hsig; } } =20 - if (trace_event_get_state_backends(TRACE_SIGNAL_TABLE_INIT)) { - for (target_sig =3D 1, count =3D 0; target_sig <=3D TARGET_NSIG; t= arget_sig++) { - if (target_to_host_signal_table[target_sig] =3D=3D _NSIG) { - count++; - } + /* Map everything else out-of-bounds. */ + for (hsig =3D 1; hsig < _NSIG; hsig++) { + if (host_to_target_signal_table[hsig] =3D=3D 0) { + host_to_target_signal_table[hsig] =3D TARGET_NSIG + 1; } - trace_signal_table_init(count); } + for (count =3D 0, tsig =3D 1; tsig <=3D TARGET_NSIG; tsig++) { + if (target_to_host_signal_table[tsig] =3D=3D 0) { + target_to_host_signal_table[tsig] =3D _NSIG; + count++; + } + } + + trace_signal_table_init(count); } =20 void signal_init(void) --=20 2.34.1 From nobody Wed Nov 27 17:29:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697672008; cv=none; d=zohomail.com; s=zohoarc; b=FeNw/MbyajT8yamT3kB5uEp0v+fkvfv/5xfHEY3W+shiH/UU/gDuzTEwmPdvaNeeEZP/uZsixUgmiaezlvhfjMGzbnZhcHpqunnUcqT+gtIELKzwzsEenwic5oCqGewsqOGkr4VEvh66LYPkKnflTK333JtEuWlqsIVc/MR7pCo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697672008; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ypG+ldHB73o41Fm0bO8P6h70i3rbf+HtP65cG8LvxlI=; b=kBJn8zPxYtAFM9gbSsdm4ouxk1+lkBE+uvjnfF9YqPW8YIIbhpQdN/4KWMuG4IUIMFkm/kwViZbt4vKPeaghiZKXXXXUi99a25fTc6joFoaxwScik+De6HIYHpttfJWtUd4cX3IcAVpPhOkag9wJZWRsN4riAkrwyZHAyWHvp1Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697672008887918.7587493780879; Wed, 18 Oct 2023 16:33:28 -0700 (PDT) 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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697672010505100003 Content-Type: text/plain; charset="utf-8" Install the host signal handler at the same time we are probing the target signals for SIG_IGN/SIG_DFL. Ignore unmapped target signals. 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 =3D (TaskState *)thread_cpu->opaque; - struct sigaction act; - struct sigaction oact; - int i; - int host_sig; + struct sigaction act, oact; =20 /* initialize signal conversion tables */ signal_table_init(); @@ -572,23 +569,28 @@ void signal_init(void) sigfillset(&act.sa_mask); act.sa_flags =3D SA_SIGINFO; act.sa_sigaction =3D host_signal_handler; - for(i =3D 1; i <=3D TARGET_NSIG; i++) { - host_sig =3D target_to_host_signal(i); - sigaction(host_sig, NULL, &oact); - if (oact.sa_sigaction =3D=3D (void *)SIG_IGN) { - sigact_table[i - 1]._sa_handler =3D TARGET_SIG_IGN; - } else if (oact.sa_sigaction =3D=3D (void *)SIG_DFL) { - sigact_table[i - 1]._sa_handler =3D TARGET_SIG_DFL; - } - /* If there's already a handler installed then something has - gone horribly wrong, so don't even try to handle that case. */ - /* Install some handlers for our own use. We need at least - SIGSEGV and SIGBUS, to detect exceptions. We can not just - trap all signals because it affects syscall interrupt - behavior. But do trap all default-fatal signals. */ - if (core_dump_signal(i)) { - sigaction(host_sig, &act, NULL); + + /* + * A parent process may configure ignored signals, but all other + * signals are default. For any target signals that have no host + * mapping, set to ignore. For all core_dump_signal, install our + * host signal handler so that we may invoke dump_core_and_abort. + * This includes SIGSEGV and SIGBUS, which are also need our signal + * handler for paging and exceptions. + */ + for (int tsig =3D 1; tsig <=3D TARGET_NSIG; tsig++) { + int hsig =3D target_to_host_signal(tsig); + abi_ptr thand =3D TARGET_SIG_IGN; + + if (hsig < _NSIG) { + struct sigaction *iact =3D core_dump_signal(tsig) ? &act : NUL= L; + + sigaction(hsig, iact, &oact); + if (oact.sa_sigaction !=3D (void *)SIG_IGN) { + thand =3D TARGET_SIG_DFL; + } } + sigact_table[tsig - 1]._sa_handler =3D thand; } } =20 --=20 2.34.1 From nobody Wed Nov 27 17:29:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697671989; cv=none; d=zohomail.com; s=zohoarc; b=KVEGTwBmiofNnlmD3vqdysOiPyMgvTzi7s+fnmapPXm24UCQqpkq0gawXV031wR+44H6aENV8hnkqRDBCrc5b1bZ6UY4HJYmWMe9MgaPgrtGplWodX2C2uSONaGiS3A056SdjT/BOHEZZySwHsJdkVQ58ORSni0/lgzBDwHN80g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697671989; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4PntMv8xOvYf8PdCQHI22CCEWflquoH9lu0dCFWPneE=; b=jAPyfWAZCPuIBxCBDVYruh9Z8IR0/8NfDoOc32NnDjY6eC3bdQhE/SiKrZmWtLKsMEkY95u3cTFWm3wmpCWkHzK4OJiA1/Eo6ypKrSFA4WjaX++iPsQJGaFj/sD3Gjd7ph8vlEMh80Tcppb0JxNzHjLWdCduXxDtU5GH+fdYTEo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697671989961298.11090153635064; Wed, 18 Oct 2023 16:33:09 -0700 (PDT) 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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697671990376100004 Content-Type: text/plain; charset="utf-8" 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); } =20 +static void host_sigsegv_handler(CPUState *cpu, siginfo_t *info, + host_sigcontext *uc) +{ + uintptr_t host_addr =3D (uintptr_t)info->si_addr; + /* + * Convert forcefully to guest address space: addresses outside + * reserved_va are still valid to report via SEGV_MAPERR. + */ + bool is_valid =3D h2g_valid(host_addr); + abi_ptr guest_addr =3D h2g_nocheck(host_addr); + uintptr_t pc =3D host_signal_pc(uc); + bool is_write =3D host_signal_write(info, uc); + MMUAccessType access_type =3D adjust_signal_pc(&pc, is_write); + bool maperr; + + /* If this was a write to a TB protected page, restart. */ + if (is_write + && is_valid + && info->si_code =3D=3D SEGV_ACCERR + && handle_sigsegv_accerr_write(cpu, host_signal_mask(uc), + pc, guest_addr)) { + return; + } + + /* + * If the access was not on behalf of the guest, within the executable + * mapping of the generated code buffer, then it is a host bug. + */ + if (access_type !=3D MMU_INST_FETCH + && !in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { + die_from_signal(info); + } + + maperr =3D true; + if (is_valid && info->si_code =3D=3D SEGV_ACCERR) { + /* + * With reserved_va, the whole address space is PROT_NONE, + * which means that we may get ACCERR when we want MAPERR. + */ + if (page_get_flags(guest_addr) & PAGE_VALID) { + maperr =3D false; + } else { + info->si_code =3D SEGV_MAPERR; + } + } + + sigprocmask(SIG_SETMASK, host_signal_mask(uc), NULL); + cpu_loop_exit_sigsegv(cpu, guest_addr, access_type, maperr, pc); +} + +static void host_sigbus_handler(CPUState *cpu, siginfo_t *info, + host_sigcontext *uc) +{ + uintptr_t pc =3D host_signal_pc(uc); + bool is_write =3D host_signal_write(info, uc); + MMUAccessType access_type =3D adjust_signal_pc(&pc, is_write); + + /* + * If the access was not on behalf of the guest, within the executable + * mapping of the generated code buffer, then it is a host bug. + */ + if (!in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { + die_from_signal(info); + } + + if (info->si_code =3D=3D BUS_ADRALN) { + uintptr_t host_addr =3D (uintptr_t)info->si_addr; + abi_ptr guest_addr =3D h2g_nocheck(host_addr); + + sigprocmask(SIG_SETMASK, host_signal_mask(uc), NULL); + cpu_loop_exit_sigbus(cpu, guest_addr, access_type, pc); + } +} + static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) { CPUState *cpu =3D thread_cpu; @@ -822,73 +896,23 @@ static void host_signal_handler(int host_sig, siginfo= _t *info, void *puc) int guest_sig; uintptr_t pc =3D 0; bool sync_sig =3D false; - void *sigmask =3D host_signal_mask(uc); + void *sigmask; =20 /* * Non-spoofed SIGSEGV and SIGBUS are synchronous, and need special * handling wrt signal blocking and unwinding. */ - if ((host_sig =3D=3D SIGSEGV || host_sig =3D=3D SIGBUS) && info->si_co= de > 0) { - MMUAccessType access_type; - uintptr_t host_addr; - abi_ptr guest_addr; - bool is_write; - - host_addr =3D (uintptr_t)info->si_addr; - - /* - * Convert forcefully to guest address space: addresses outside - * reserved_va are still valid to report via SEGV_MAPERR. - */ - guest_addr =3D h2g_nocheck(host_addr); - - pc =3D host_signal_pc(uc); - is_write =3D host_signal_write(info, uc); - access_type =3D adjust_signal_pc(&pc, is_write); - - /* If this was a write to a TB protected page, restart. */ - if (is_write - && host_sig =3D=3D SIGSEGV - && info->si_code =3D=3D SEGV_ACCERR - && h2g_valid(host_addr) - && handle_sigsegv_accerr_write(cpu, sigmask, pc, guest_addr)) { + if (info->si_code > 0) { + switch (host_sig) { + case SIGSEGV: + /* Only returns on handle_sigsegv_accerr_write success. */ + host_sigsegv_handler(cpu, info, uc); return; + case SIGBUS: + host_sigbus_handler(cpu, info, uc); + sync_sig =3D true; + break; } - - /* - * If the access was not on behalf of the guest, within the execut= able - * mapping of the generated code buffer, then it is a host bug. - */ - if (access_type !=3D MMU_INST_FETCH - && !in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { - die_from_signal(info); - } - - if (host_sig =3D=3D SIGSEGV) { - bool maperr =3D true; - - if (info->si_code =3D=3D SEGV_ACCERR && h2g_valid(host_addr)) { - /* - * With reserved_va, the whole address space is PROT_NONE, - * which means that we may get ACCERR when we want MAPERR. - */ - if (page_get_flags(guest_addr) & PAGE_VALID) { - maperr =3D false; - } else { - info->si_code =3D SEGV_MAPERR; - } - } - - sigprocmask(SIG_SETMASK, sigmask, NULL); - cpu_loop_exit_sigsegv(cpu, guest_addr, access_type, maperr, pc= ); - } else { - sigprocmask(SIG_SETMASK, sigmask, NULL); - if (info->si_code =3D=3D BUS_ADRALN) { - cpu_loop_exit_sigbus(cpu, guest_addr, access_type, pc); - } - } - - sync_sig =3D true; } =20 /* get target signal number */ @@ -929,6 +953,7 @@ static void host_signal_handler(int host_sig, siginfo_t= *info, void *puc) * would write 0xff bytes off the end of the structure and trash * data on the struct. */ + sigmask =3D host_signal_mask(uc); memset(sigmask, 0xff, SIGSET_T_SIZE); sigdelset(sigmask, SIGSEGV); sigdelset(sigmask, SIGBUS); --=20 2.34.1 From nobody Wed Nov 27 17:29:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697671989; cv=none; d=zohomail.com; s=zohoarc; b=SsIuvHwCgblaz2wBm+iUs3Ht1cw07JuiwJPTziT5JAwttt2J774GRL8QCKuDI1TPkym1RYA2oFumZFUo7FVIXM7sF23LVMIN0b2LvHaKLOgdflPAITeYV8cfnfePhgTkhTOqb+3fND4394B5EuNpmAOSxF5PewT4ozBhLSXCmyU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697671989; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cPRrHvcXgvktiUIzW9SQzWI6+9vUxSTnLoJeJQFy4uw=; b=VnVzmCYnP3+dc/fmZlGaTQ06ifA8/zm3SexXW0tSy6lWjEBPXxL+OtXOVbspe4m7AfaPPf9tT93Gx1sKOtX3AOdtTWAX2cu6PrANu0JomgQl8gRDBlM0YZbC/ZBNbDUUX3+lnzrOjqjGAGN4Te1vEWC0eSW3IISZOyGmQYKlpHE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697671989637755.8156025985646; Wed, 18 Oct 2023 16:33:09 -0700 (PDT) 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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697671990340100001 Content-Type: text/plain; charset="utf-8" These signals, when not spoofed via kill(), are always bugs. Use die_from_signal to report this sensibly. 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 =3D "ILL"; + switch (info->si_code) { + case ILL_ILLOPC: + code =3D "ILLOPC"; + break; + case ILL_ILLOPN: + code =3D "ILLOPN"; + break; + case ILL_ILLADR: + code =3D "ILLADR"; + break; + case ILL_PRVOPC: + code =3D "PRVOPC"; + break; + case ILL_PRVREG: + code =3D "PRVREG"; + break; + case ILL_COPROC: + code =3D "COPROC"; + break; + } + break; + case SIGFPE: + sig =3D "FPE"; + switch (info->si_code) { + case FPE_INTDIV: + code =3D "INTDIV"; + break; + case FPE_INTOVF: + code =3D "INTOVF"; + break; + } + break; + case SIGTRAP: + sig =3D "TRAP"; + break; default: snprintf(sigbuf, sizeof(sigbuf), "%d", info->si_signo); sig =3D sigbuf; @@ -900,7 +937,8 @@ static void host_signal_handler(int host_sig, siginfo_t= *info, void *puc) =20 /* * Non-spoofed SIGSEGV and SIGBUS are synchronous, and need special - * handling wrt signal blocking and unwinding. + * handling wrt signal blocking and unwinding. Non-spoofed SIGILL, + * SIGFPE, SIGTRAP are always host bugs. */ if (info->si_code > 0) { switch (host_sig) { @@ -912,6 +950,10 @@ static void host_signal_handler(int host_sig, siginfo_= t *info, void *puc) host_sigbus_handler(cpu, info, uc); sync_sig =3D true; break; + case SIGILL: + case SIGFPE: + case SIGTRAP: + die_from_signal(info); } } =20 --=20 2.34.1 From nobody Wed Nov 27 17:29:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697671990; cv=none; d=zohomail.com; s=zohoarc; b=I/zT/aXhCUoRgoaViSMQQLFUc3xzgSK+BE7W/vdKsaj6mcimXoeH9zIW/QJXg+6kmHj5/VwGAA+vo2SddogWceq/JF8K1EPYNO8aFrV/5D1K/11bvhi3ySXBf9rfOcxktuBTSsOx3QnkA6vJVZ3sSlpXfLJ0dUQpJhNkL1V2Ia0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697671990; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bnu9T106+3Frnuh9qTylVBrRrlFzWm5MBIT4IbQZiD0=; b=EPQ8QC7Y415v1dDxFWuh2gN1uT+2kQZpNhkod1qVfrQdr6bzDqj/f9G2H4sC+/F2t6T/6KTfOP+vVOeRKUS110UCLjztkm209igFi3O5zjSsXs+l3mcLtObg7FVcc0922AS0KdDEb+FZOPPz1AoO1ssYEnI4rpFa6A/A3cS+6HM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697671990487736.1104449152657; Wed, 18 Oct 2023 16:33:10 -0700 (PDT) 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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697671992374100019 Content-Type: text/plain; charset="utf-8" Distinguish host SIGABRT from guest SIGABRT by mapping the guest signal onto one of the host RT signals. This prevents a cycle by which a host assertion failure is caught and handled by host_signal_handler, queued for the guest, and then we attempt to continue past the host abort. What happens next depends on the host libc, but is neither good nor helpful. 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 =3D SIGRTMIN; hsig <=3D SIGRTMAX; hsig++) { + + hsig =3D SIGRTMIN; + host_to_target_signal_table[SIGABRT] =3D 0; + host_to_target_signal_table[hsig++] =3D TARGET_SIGABRT; + + for (; hsig <=3D SIGRTMAX; hsig++) { tsig =3D hsig - SIGRTMIN + TARGET_SIGRTMIN; if (tsig <=3D TARGET_NSIG) { host_to_target_signal_table[hsig] =3D tsig; @@ -539,6 +552,8 @@ static void signal_table_init(void) } } =20 + host_to_target_signal_table[SIGABRT] =3D TARGET_SIGABRT; + /* Map everything else out-of-bounds. */ for (hsig =3D 1; hsig < _NSIG; hsig++) { if (host_to_target_signal_table[hsig] =3D=3D 0) { @@ -582,13 +597,21 @@ void signal_init(void) int hsig =3D target_to_host_signal(tsig); abi_ptr thand =3D TARGET_SIG_IGN; =20 - if (hsig < _NSIG) { - struct sigaction *iact =3D core_dump_signal(tsig) ? &act : NUL= L; + if (hsig >=3D _NSIG) { + continue; + } =20 + /* As we force remap SIGABRT, cannot probe and install in one step= . */ + if (tsig =3D=3D TARGET_SIGABRT) { + sigaction(SIGABRT, NULL, &oact); + sigaction(hsig, &act, NULL); + } else { + struct sigaction *iact =3D core_dump_signal(tsig) ? &act : NUL= L; sigaction(hsig, iact, &oact); - if (oact.sa_sigaction !=3D (void *)SIG_IGN) { - thand =3D TARGET_SIG_DFL; - } + } + + if (oact.sa_sigaction !=3D (void *)SIG_IGN) { + thand =3D TARGET_SIG_DFL; } sigact_table[tsig - 1]._sa_handler =3D thand; } @@ -711,7 +734,12 @@ void dump_core_and_abort(CPUArchState *env, int target= _sig) TaskState *ts =3D (TaskState *)cpu->opaque; int host_sig, core_dumped =3D 0; =20 - host_sig =3D target_to_host_signal(target_sig); + /* On exit, undo the remapping of SIGABRT. */ + if (target_sig =3D=3D TARGET_SIGABRT) { + host_sig =3D SIGABRT; + } else { + host_sig =3D target_to_host_signal(target_sig); + } trace_user_dump_core_and_abort(env, target_sig, host_sig); gdb_signalled(env, target_sig); =20 --=20 2.34.1