From patchwork Wed Oct 18 23:31:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 735179 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1258687wro; Wed, 18 Oct 2023 16:33:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZEEFgoQzZ4zUSwf/GHf0W79vng5okEpvg2zGfJcQnFfjkAHjCPs0MkSP2txmUOejI/wgJ X-Received: by 2002:ac8:5742:0:b0:418:1d4f:995c with SMTP id 2-20020ac85742000000b004181d4f995cmr908825qtx.55.1697672034020; Wed, 18 Oct 2023 16:33:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697672034; cv=none; d=google.com; s=arc-20160816; b=xMNKOj3SKUHWnWaXMI/kFEASlhIn8rl5uF7PaDsuFx+4Z6M3th+0iHrW9S2IXcHn0i GwWBlU8uhLK2bokGeuPeC4BVtsFa87jDUce6ye/PB/6qNhTrgOA3YT7QaXhED7CDHtEc GRbo0uggjphDDuoz96dz4MMmQiykzhHNgGO4crw8OToeUW1X2kXu7E+yUL+0IoKVgMQL e3CqMmELgSaTQcDrMHXj1yWD11OjvghQdXd1CJkNpdFH231v/G4iIt6IGh0WWq+BdjEo 63VhiCxUd4Vj34cfJSmGRDRzZslRaA7mOES8rHvE6MLA/cTO1d8PVN6x72AICB4JLyMu YkSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=D2oYojizKTJe59+z2rFn3jhqwAzCHsM3phmz2spMImU=; fh=aYwv1qvAWDHKcZLZyhvLuIoAkBRd6ysYy/Itgr1WhFg=; b=Rffrf+NFS1t0xLPxSQyB8MTX7If+ZBIFbDAQcB3xSXV9iRuShI/fbSVtHy7HkAsqBG 3NFNi5HWoo2t4AlDPzu92ou5xEyImqXFaFwYS9dbTu/WkL7jtY7lKoW3RVA2nU9IKiIX NjMxTkdWjDtqazPs6iyXDtk0wu3AOvmc2sm0vso4auOPkTI4Cs1/QQmVbflStDNX592O q3lt3LYVqBHxOXrSJDtgUz+5MqcHpJk7PIm0d2P8tlprkDCUFTOMqJhv24V2wzlmGnQe 4jp26f0lCcNWERwf7SZ+uLw5mZnoAV1jLQxu/fbvOkphaHBwBnhLjhU8VFxg31QvgSVl eAYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="X/LzXjG7"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b8-20020ac87fc8000000b0041893ae942asi737314qtk.730.2023.10.18.16.33.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2023 16:33:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="X/LzXjG7"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG0s-0003e8-BI; Wed, 18 Oct 2023 19:31:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG0r-0003Xg-CZ for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:41 -0400 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0o-0000EJ-5h for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:41 -0400 Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-35754465cb3so27427085ab.0 for ; Wed, 18 Oct 2023 16:31:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671896; x=1698276696; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D2oYojizKTJe59+z2rFn3jhqwAzCHsM3phmz2spMImU=; b=X/LzXjG76Ye5xqLNpsqI8HAAVck+vO2Vw35rKs8HRQ7HXUXWNiNhPTuyzYgHuTHBSh ffBa4wnvJr6/MQpF2RtIXxrHDss3qgrou5RFUTp5ucmcQO3vrbgs9vwe2DAZzKc71MIA KWxyYvuNGF8lVaSpMdSu6X87MeMu+fmmCYPrm5+BSGzNLHx/7hjP0L3pVS9ouDg0onn7 ofPJktkEaW4jmvTpIsnLvo3wfK6bMk1ui9+9ovC0Jl7MVbLul5qjDL+puw/1ri/5oMnX +s1fmvm2qAP/p7jyilyp28lUfAIfBKbBgBFR9+thSIxV/z8iA/mNoVHMO+F1KvszjiSM zkgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671896; x=1698276696; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D2oYojizKTJe59+z2rFn3jhqwAzCHsM3phmz2spMImU=; b=Qh+bBm6uWVjpZjN56Yo9ILVaFk/mflEl48WLbHA8R2Lim5nmQUMjMjlVNmRSRUEFmG wC1gGkUVEGrEsHffA0YFguyA3NwbQqXDx9G2N5IuihfGNTVTSyUdDvFVyOb8+3z1v4XT jHXmVddGJaTvU34fxJF7LCbwJCvnrHqYnFXojX09A9DgXt4ylLl3vacJHvF0SPwxk1mZ 4T4k4Ppb1oAbLkdXcL08bNlD8y4nqKVya7ISlu2n7v5s0A3/VIw8KT2B99TUM4WcnaTK K3MqLuRBsLX/n2c0WCm647pqkUinTZ0WHjhWRbwS4ghsjGyMjDzGUjR6Q3muAHsNDxh6 hgtA== X-Gm-Message-State: AOJu0YxBPS7EwHLI/9RtvtnkfYcplrmFGfx7xCURStiBPMmmjAxmeweQ hzfyfoGrj2pb0CvgWuVuErPDqJEUv1iEMO3/YIA= X-Received: by 2002:a92:d650:0:b0:350:f956:91c4 with SMTP id x16-20020a92d650000000b00350f95691c4mr728194ilp.4.1697671896348; Wed, 18 Oct 2023 16:31:36 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 01/14] linux-user: Fixes for zero_bss Date: Wed, 18 Oct 2023 16:31:21 -0700 Message-Id: <20231018233134.1594292-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::134; envelope-from=richard.henderson@linaro.org; helo=mail-il1-x134.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The previous change, 2d385be6152, assumed !PAGE_VALID meant that the page would be unmapped by the elf image. However, since we reserved the entire image space via mmap, PAGE_VALID will always be set. Instead, assume PROT_NONE for the same condition. Furthermore, assume bss is only ever present for writable segments, and that there is no page overlap between PT_LOAD segments. Instead of an assert, return false to indicate failure. Cc: qemu-stable@nongnu.org Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1854 Fixes: 2d385be6152 ("linux-user: Do not adjust zero_bss for host page size") Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/elfload.c | 53 +++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index f21e2e0c3d..213fd3e584 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2362,31 +2362,58 @@ static abi_ulong setup_arg_pages(struct linux_binprm *bprm, * Map and zero the bss. We need to explicitly zero any fractional pages * after the data section (i.e. bss). Return false on mapping failure. */ -static bool zero_bss(abi_ulong start_bss, abi_ulong end_bss, int prot) +static bool zero_bss(abi_ulong start_bss, abi_ulong end_bss, + int prot, Error **errp) { abi_ulong align_bss; + /* We only expect writable bss; the code segment shouldn't need this. */ + if (!(prot & PROT_WRITE)) { + error_setg(errp, "PT_LOAD with non-writable bss"); + return false; + } + align_bss = TARGET_PAGE_ALIGN(start_bss); end_bss = TARGET_PAGE_ALIGN(end_bss); if (start_bss < align_bss) { int flags = page_get_flags(start_bss); - if (!(flags & PAGE_VALID)) { - /* Map the start of the bss. */ + if (!(flags & PAGE_BITS)) { + /* + * The whole address space of the executable was reserved + * at the start, therefore all pages will be VALID. + * But assuming there are no PROT_NONE PT_LOAD segments, + * a PROT_NONE page means no data all bss, and we can + * simply extend the new anon mapping back to the start + * of the page of bss. + */ align_bss -= TARGET_PAGE_SIZE; - } else if (flags & PAGE_WRITE) { - /* The page is already mapped writable. */ - memset(g2h_untagged(start_bss), 0, align_bss - start_bss); } else { - /* Read-only zeros? */ - g_assert_not_reached(); + /* + * The start of the bss shares a page with something. + * The only thing that we expect is the data section, + * which would already be marked writable. + * Overlapping the RX code segment seems malformed. + */ + if (!(flags & PAGE_WRITE)) { + error_setg(errp, "PT_LOAD with bss overlapping " + "non-writable page"); + return false; + } + + /* The page is already mapped and writable. */ + memset(g2h_untagged(start_bss), 0, align_bss - start_bss); } } - return align_bss >= end_bss || - target_mmap(align_bss, end_bss - align_bss, prot, - MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) != -1; + if (align_bss < end_bss && + target_mmap(align_bss, end_bss - align_bss, prot, + MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) == -1) { + error_setg_errno(errp, errno, "Error mapping bss"); + return false; + } + return true; } #if defined(TARGET_ARM) @@ -3410,8 +3437,8 @@ static void load_elf_image(const char *image_name, int image_fd, /* If the load segment requests extra zeros (e.g. bss), map it. */ if (vaddr_ef < vaddr_em && - !zero_bss(vaddr_ef, vaddr_em, elf_prot)) { - goto exit_mmap; + !zero_bss(vaddr_ef, vaddr_em, elf_prot, &err)) { + goto exit_errmsg; } /* Find the full program boundaries. */ From patchwork Wed Oct 18 23:31:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 735178 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1258652wro; Wed, 18 Oct 2023 16:33:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUngXV20N2fMBIRRJL+4HjR8KQb+SbZrhHGgoC865LCplAiz0UrcDgOtrozVQLC5gVP9Dw X-Received: by 2002:ad4:5aa1:0:b0:66d:1d4d:5a2 with SMTP id u1-20020ad45aa1000000b0066d1d4d05a2mr831142qvg.38.1697672027982; Wed, 18 Oct 2023 16:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697672027; cv=none; d=google.com; s=arc-20160816; b=NOakfCLjj6aII548q10d0gYEdDgQagQk4BkKFlqHkK9xxCtAGFAgR109Dd0pOZ/lwN EgL3ISFFrvWulCaQOuwQ6l8Ukl3rWpsJVly1J7IlZ3wtBF8CBH9DbFZMMVMelQ2wDnmM tQIIK/nn/UISqdaKbyZZgGM4A52PLxcDsTu6b7cCcpSD5PrGu0Xt81KaqLXTXEinq5rH Z2g9Kh+59GOoe2PLL752ZQ1TXMXD/fG9bMgYZHVipRuhPRoUTSUcXvfxhDYEo2z1kpAM 65o7Ccl0yAR7bTWxf+cdU7akyGR3F7usgvLm+VPezuqZGVzAxI7Y2GmM5dBwOP4drFTt V9/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1I5j+CVAtN1UYbE5YS09fVUfZ8qAm7sA0ML6lgTI9YE=; fh=yONVzBeAMMMg44rnXEsrewzqFJrmRgAIVzzVI2CmwNk=; b=JMmZKO4O0AGxoD7wzZomKG5wOB19uJPtAwliYA94cuE8dxUlBwReygHxUjKlQhoMe3 MxNH8vQrlOAPYq39YNtx+3z+t3RQuIQwNyT4VywZ3ggNqHzA+5Y7CAYkLrV8gUAVyOyt 6nZwr74IFHiJZCUZsiJI/z/K6pLW7gKU876Vpzjm68RBfL+d+iWNs8Vi+sI0V7DUSMcM XjwK5N+Xz3CfvRWfltUbVqT+uZVgs+V/tqK4tzOAcloXlp8BwCrEucpcosxHZhEfRH87 T1qjt/1kD3NVSFHBFkc3FGlgyYHDmGF8tILvqVcXPwEJE/N3iJ/6NH6h8PzLaeQOCBsx TSyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=w3uxCWr+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k16-20020a05620a415000b0076d8bb2e9f9si819887qko.680.2023.10.18.16.33.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2023 16:33:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=w3uxCWr+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG0s-0003g8-FP; Wed, 18 Oct 2023 19:31:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG0r-0003W1-55 for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:41 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0o-0000Fl-Ks for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:40 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6bb4abb8100so3867458b3a.2 for ; Wed, 18 Oct 2023 16:31:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671897; x=1698276697; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1I5j+CVAtN1UYbE5YS09fVUfZ8qAm7sA0ML6lgTI9YE=; b=w3uxCWr+FAeDbgM3yAWT+aejaZA8XRR7mCNEedAyu1+8LFLVrfDXwhSLoHVOAMiwO6 KNnWcKl4rNgSSazKdctDoar/OQ9WI+YFT+DQ2Tu2rh7TQcucrt/B5pt/FmBq86br+eOe MFYzhhMwLei2KGlOMnKlaz0bBqvB44RZLpt6A6fLpfsQAJ6d/FRPbbJLJLTR9IZNl86H jcsw9RhuiDrApjaYCqRU9pHa/D6crvoP2a3IYabRGAWTSykjj3REzVaU3eNxwX4L75Z2 5dwhW3sQZekELF2V3FolReYDJM0SbfNixBMjXWaasrXh/MsMdCnQO+oKw9558vpjdqDe wXWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671897; x=1698276697; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1I5j+CVAtN1UYbE5YS09fVUfZ8qAm7sA0ML6lgTI9YE=; b=HljuvF88Qy8CaSVAchtdZm4JDWmGTVWZHvbYt0Z4NoVnS9kvY85AUJOP75L8Hqt05s arQRq+IUEW0vRJY8g6NfZGvDog3OThG2Rdu2f3cNOLSJNxGa2V41gsN0WjCwFQyKsrru 0ezZ1Zw9yE7eDYTUEXqrggvi+YTe++r4UpD1SocZQ0n8It5nE1kbzThVJUITjwljY7LZ JsANNKno18TzhMdgMilSiKHxEVZgbdHlYVP+5z3+PSi7e9qIY2OgMSKQ/UlbK/m32d/F BviBOzB60jNwp+Gbe+ZI5xfvsMImuYzo2WBmNQ15/LVB3FnWP944fd4OVhLl3YnbZRFl 1xTg== X-Gm-Message-State: AOJu0YxR5QRX9Zp3V0iBhf4iQI1z5TqjzZ3O1QEQba+Hh7E9aDqiDS/A G480kjHLfYY+UYuZlURT4frq7GDG9FWwn7V87bk= X-Received: by 2002:a05:6a00:1354:b0:692:6d3f:485b with SMTP id k20-20020a056a00135400b006926d3f485bmr641843pfu.3.1697671897116; Wed, 18 Oct 2023 16:31:37 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Mikulas Patocka , qemu-stable@nongnu.org Subject: [PULL 02/14] linux-user/mips: fix abort on integer overflow Date: Wed, 18 Oct 2023 16:31:22 -0700 Message-Id: <20231018233134.1594292-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Mikulas Patocka QEMU mips userspace emulation crashes with "qemu: unhandled CPU exception 0x15 - aborting" when one of the integer arithmetic instructions detects an overflow. This patch fixes it so that it delivers SIGFPE with FPE_INTOVF instead. Cc: qemu-stable@nongnu.org Signed-off-by: Mikulas Patocka Message-Id: <3ef979a8-3ee1-eb2d-71f7-d788ff88dd11@redhat.com> Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- linux-user/mips/cpu_loop.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c index 8735e58bad..990b03e727 100644 --- a/linux-user/mips/cpu_loop.c +++ b/linux-user/mips/cpu_loop.c @@ -180,7 +180,9 @@ done_syscall: } force_sig_fault(TARGET_SIGFPE, si_code, env->active_tc.PC); break; - + case EXCP_OVERFLOW: + force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTOVF, env->active_tc.PC); + break; /* The code below was inspired by the MIPS Linux kernel trap * handling code in arch/mips/kernel/traps.c. */ From patchwork Wed Oct 18 23:31:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 735170 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1258431wro; Wed, 18 Oct 2023 16:33:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeBfXaWnuAPhD5dgQvaDLoOw3SRgNtapE6DAIeo+/Q79xGMZcu42f0zzBwgHL5zXPNzV9/ X-Received: by 2002:a05:620a:570:b0:775:d7d7:d049 with SMTP id p16-20020a05620a057000b00775d7d7d049mr532274qkp.67.1697671989776; Wed, 18 Oct 2023 16:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697671989; cv=none; d=google.com; s=arc-20160816; b=HJX6S3OOIimX1ft8EoNB8YNzwetI2YYc304B5JQOZ41930DjHbNEZlr3+RJsqrisJX Czu7H2NhjjJVkRfN69uk/GtrpGHIJOtudPCSZL9BXsXf2WEnKaUuZlyXb1fY/8ddPXJl aOoTRM48mLNj8FV4wwlFGhEMLX2xSSvbAfgQc7R+eKSqjQnNSfhebEJL0u15ql5yIlKW 2OJBSOcqJK1ZTJfX2mappzvJW9RyeWSTQcdV74n4nbk8CMoK04kAkqpiDEIEa5s32iOW L8ihXpGHz9KxcqPIqvCsTHB2XsrZuj1IPKkplV+oD4zzhsAk3tHjGFyhf591D7CQk0JS Qb7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2k8XNRKudZqb8EBVa8P0hTDCeDuuDeqPExqYOmBXPTU=; fh=vMw6S/E7sjhp9Rx21XLcbWs2y0eiwbKGEuZzTdn3vz0=; b=Q7MmhhZ29INGSdhf1AjxqPUQJxwX/bPhtr14Sjqj3HFS0TT0BCcVdbsly04n1fZuRW D7JW6Oow9Up2Rjc3/pAmJxbaDgm+21vkZWYsKEHgoK7CQf8Ht4rP7+MoZak5DvDjDTWh VhKmAxgOyTf5wkT0q6Es78VhRSgLXxKfE3X6Wr+8eeooeOTSPryEpSeGPiQo+f6o5xau M6FJ6VptaOmK2XwBluwpfHANPw4ckZPe5iNqnQCTh9h/QuouHG8OdFoB0NFtBLrI7wIS hLkW7laU817LeKOdQLRz+VNWbeanKUYmKZ0SHtuaHZYZ/cAVMLamOkArW35vPfXsje4f kdHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="T1HjE9s/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z3-20020ae9f443000000b0077587ebfdecsi713829qkl.176.2023.10.18.16.33.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2023 16:33:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="T1HjE9s/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG0t-0003sI-Fm; Wed, 18 Oct 2023 19:31:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG0r-0003bl-Tg for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:41 -0400 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0p-0000He-Am for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:41 -0400 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-581d4f9a2c5so1295454eaf.0 for ; Wed, 18 Oct 2023 16:31:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671898; x=1698276698; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2k8XNRKudZqb8EBVa8P0hTDCeDuuDeqPExqYOmBXPTU=; b=T1HjE9s/vAwmlJdg3j4bvMnWFNEUhgxCi83qF0fciFrq4iMeXPdQnGgBWsnkUqzIUt jxzXImOc3/JpaXpX8ZAGv0QW8Ac6bjHPGpEFT5mqT3OqJM7z1vfHRZxEQywvdwTe0g9d dujdI0CtwAVUFd5vXX6HzyhwB1ba28Uxgj/UHKnYUQDE0MUy9NZHTQy/mSY6nSDcHNVj 0AgZtUL3OhC8i0U/Q81acJEpFtT9MJtzxVbAuVWXP942R8Z0vdC3dIK6E2JOn09ebdYB HbuPS7gIaOIbO532FJgyIjgLhwVp3O7q0MjQ5g21tSQxwuFqMcuqg7LZ1Feh8HsaiTpf f0Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671898; x=1698276698; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2k8XNRKudZqb8EBVa8P0hTDCeDuuDeqPExqYOmBXPTU=; b=ILyzx6GKlD1WKv+mb02rNAt2xUJv9AsZmmkeeY2tUii4tTaTaOHbEn7JE0tGTY1oG1 WLo9sagVBWrolgRsYQiih77ekYdgL5+SJ4alxLITkPSXCtIvDXxhgVjzYc29WSeh55Sd QDz95IGkrwZQ0Q6DrNc8phq6HwlpiFzjV0STpRCBEPkE+t2aWQP6KZowyT4OWQqKetLF freXX8v2+4BXNapuf/izlQlWHqRpW/tz3moDGgwSYReSdBoTtXTe/+z77C9OeTSLjnT8 S/zjL/ovEgWAXFTXShMdnU1Ns0ZjK4/gJcOYE5wGPiyUJhGyMq/Muwmh7XOGkg2WLexN 9a+g== X-Gm-Message-State: AOJu0YxtocmN/BK8fUcyUnb0nZ4cLucBJKwr205Bt2yaklzAPhWCUDS5 t9kky90tL303aAZpedhnvJPBb8OABAVVZVdJkZo= X-Received: by 2002:a05:6358:fd02:b0:143:70a1:afcd with SMTP id ui2-20020a056358fd0200b0014370a1afcdmr453415rwb.1.1697671897987; Wed, 18 Oct 2023 16:31:37 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Mikulas Patocka , qemu-stable@nongnu.org, Yoshinori Sato Subject: [PULL 03/14] linux-user/sh4: Fix crashes on signal delivery Date: Wed, 18 Oct 2023 16:31:23 -0700 Message-Id: <20231018233134.1594292-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c2b; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc2b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Mikulas Patocka sh4 uses gUSA (general UserSpace Atomicity) to provide atomicity on CPUs that don't have atomic instructions. A gUSA region that adds 1 to an atomic variable stored in @R2 looks like this: 4004b6: 03 c7 mova 4004c4 ,r0 4004b8: f3 61 mov r15,r1 4004ba: 09 00 nop 4004bc: fa ef mov #-6,r15 4004be: 22 63 mov.l @r2,r3 4004c0: 01 73 add #1,r3 4004c2: 32 22 mov.l r3,@r2 4004c4: 13 6f mov r1,r15 R0 contains a pointer to the end of the gUSA region R1 contains the saved stack pointer R15 contains negative length of the gUSA region When this region is interrupted by a signal, the kernel detects if R15 >= -128U. If yes, the kernel rolls back PC to the beginning of the region and restores SP by copying R1 to R15. The problem happens if we are interrupted by a signal at address 4004c4. R15 still holds the value -6, but the atomic value was already written by an instruction at address 4004c2. In this situation we can't undo the gUSA. The function unwind_gusa does nothing, the signal handler attempts to push a signal frame to the address -6 and crashes. This patch fixes it, so that if we are interrupted at the last instruction in a gUSA region, we copy R1 to R15 to restore the correct stack pointer and avoid crashing. There's another bug: if we are interrupted in a delay slot, we save the address of the instruction in the delay slot. We must save the address of the previous instruction. Cc: qemu-stable@nongnu.org Signed-off-by: Mikulas Patocka Reviewed-by: Yoshinori Sato Message-Id: Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- linux-user/sh4/signal.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/linux-user/sh4/signal.c b/linux-user/sh4/signal.c index c4ba962708..c16c2c2d57 100644 --- a/linux-user/sh4/signal.c +++ b/linux-user/sh4/signal.c @@ -104,6 +104,14 @@ static void unwind_gusa(CPUSH4State *regs) /* Reset the SP to the saved version in R1. */ regs->gregs[15] = regs->gregs[1]; + } else if (regs->gregs[15] >= -128u && regs->pc == regs->gregs[0]) { + /* If we are on the last instruction of a gUSA region, we must reset + the SP, otherwise we would be pushing the signal context to + invalid memory. */ + regs->gregs[15] = regs->gregs[1]; + } else if (regs->flags & TB_FLAG_DELAY_SLOT) { + /* If we are in a delay slot, push the previous instruction. */ + regs->pc -= 2; } } From patchwork Wed Oct 18 23:31:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 735181 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1258844wro; Wed, 18 Oct 2023 16:34:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHF4jyVCchDsOFqbGndPkXbuGTEnmEKO5HD56ML+JODHDmf1ANY1Q+nRa1xE9EgS/7TKv3i X-Received: by 2002:ad4:5d6e:0:b0:66c:e3b2:13f4 with SMTP id fn14-20020ad45d6e000000b0066ce3b213f4mr651339qvb.65.1697672063881; Wed, 18 Oct 2023 16:34:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697672063; cv=none; d=google.com; s=arc-20160816; b=lAaj2EVH0ddcAuhiKLMs+AA9VWOWRd7u2pPeKMJ7KWWvCFthqRWw3DoHbbiroFtGHM 3BPlhcXreRs1FgJ+h7hWzkKumAc9dSAd8Uq1cGJtDWipa2S3vhVLmcEYxg+HjvafiXjG nxwElHY3xzVg+rRoTf6yWPPlDb2i77uiRCUmpjzUt4lRehzp2X4mr8NlSI0JUrRg/18g PhXjrFslDqSuw7d4M62EFHPe4h1tpOOo6KRZpbsfVIDTejXW60OR96Vebs1FpPq+YZ81 Q+hICBguyxeK7bkUNK3J06piA/8XX9lat1RKpnb8AN8Y3HPrP4hGGymF9mZhqj2n70+O 9oUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KeKGrdrxTYoWvojPluBjviNWq1U0AbGSCGNtTdLurtI=; fh=XdZcuDF0lIDVBff2CYkB4/gQzRNs362lYRoE1KF8IAU=; b=O3gig6YrH7uE8L1miHYR/CuUNslQTPZ53GGBTpCgW4ufXxcgFSsWAQfK+7XjIWlnpX iA8KysUyXiRhVNgTXRZufVL7Q+ATuWlh2nWqKUcRl7tpuEBzaY9vzJuGFwXRjCL0sYN4 i51GLOGOiPiDMOB7VB3bQxw/3zsThFnLuqo9Bd6iRa+4Gg20fNBjknY3K8G2L9vjYynh nzUmWi34PGkgPcgaT/CYXzCdkM2W5ONR0Ei6Sp0o2F8GYPXkNFlJwv0S8BIyxmq47/hH IHo3aXDG2TDK+6riklSr22dWU1kdJ+DUlMzYC+KZ2uXnHECEQYeIA5QNIyhoM0yN3Ns2 ZMwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RjcgIrZ4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ev19-20020a0562140a9300b0063d456fcd44si713799qvb.515.2023.10.18.16.34.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2023 16:34:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RjcgIrZ4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG0u-0003wH-CU; Wed, 18 Oct 2023 19:31:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG0s-0003fx-Df for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:42 -0400 Received: from mail-il1-x12c.google.com ([2607:f8b0:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0p-0000I4-TU for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:42 -0400 Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-3575287211bso27379195ab.1 for ; Wed, 18 Oct 2023 16:31:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671899; x=1698276699; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KeKGrdrxTYoWvojPluBjviNWq1U0AbGSCGNtTdLurtI=; b=RjcgIrZ4kB5mPpL2skFbOjOpDzAVP4HGYyuYWAQTyacyOLElsoIBi6XQ9cjbvV8MEy cOCHFbNhvG3HPlW+7Gdw4HRds5iYEAF3pI+n7LAVrLN9xTmVbp8Qmtc2DTKY23xxGrn7 ACXcaZxKhKuGq6wJORMme9JVCPltiqr3OtB0a7Y2MLAN4XF4xGHSa9B5vz3r8+lb5q2M /LQnOqp1ByiHre1Ov5qYl2j9/XrLOtvCFDZSFdpHuycrdFFogTb/rrzgnva7L1j8vjeF Wd0FrvMSSt19jC0+4pCBVyxs2mcefA0x1gAlHEUAz7Ew0KWdp6K0b3twhFRfETwsBKU9 ckrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671899; x=1698276699; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KeKGrdrxTYoWvojPluBjviNWq1U0AbGSCGNtTdLurtI=; b=xOKSAOc2HvHgByr7s0wMX07wfBaanj8Vf5f5YNJFv+Un/bzo1ZkPWJBAxEMRLoxmzF LHC0c/V6odnCw3elcz/Z7+esQDwFiGSqZ6BGt0yjsnkE+d+aObL88AHVgAIjq9FwZWTJ ujac3VdweoaG7UkS3RTObvALIShEfalPKQTeKzsmRhC1gyG/0ZDAl3vSpf/R+f2lGJGG lF8c/+SxRISBuz3W5Z+1g5vdYwjPK8QUNIGfKp6JYZJZsWokGSVR5ghMoU5/yPBchHBB W11/w6AqX8DMWvZqCAVLI3yrcpA8OkOHa5JvoZnJfY+3TXQp9eLVqz2N01OoEB/dKA5+ 4emg== X-Gm-Message-State: AOJu0YzPXdSpgQ7FrMh9chLmYlHV8T/8FS2yEEMnBCtPp/kwZlrVGQp0 tv2fnw1i6CXnlMLsxdE9G0f4vmNRR3KsXnnq1tQ= X-Received: by 2002:a92:c262:0:b0:34f:a4c5:8eca with SMTP id h2-20020a92c262000000b0034fa4c58ecamr999999ild.27.1697671898776; Wed, 18 Oct 2023 16:31:38 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Jiajie Chen Subject: [PULL 04/14] linux-user/elfload: Enable LSX/LASX in HWCAP for LoongArch Date: Wed, 18 Oct 2023 16:31:24 -0700 Message-Id: <20231018233134.1594292-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::12c; envelope-from=richard.henderson@linaro.org; helo=mail-il1-x12c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jiajie Chen Since support for LSX and LASX is landed in QEMU recently, we can update HWCAPS accordingly. Signed-off-by: Jiajie Chen Reviewed-by: Richard Henderson Message-Id: <20231001085315.1692667-1-c@jia.je> Signed-off-by: Richard Henderson --- linux-user/elfload.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 213fd3e584..2e3809f03c 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1237,6 +1237,14 @@ static uint32_t get_elf_hwcap(void) hwcaps |= HWCAP_LOONGARCH_LAM; } + if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) { + hwcaps |= HWCAP_LOONGARCH_LSX; + } + + if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LASX)) { + hwcaps |= HWCAP_LOONGARCH_LASX; + } + return hwcaps; } From patchwork Wed Oct 18 23:31:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 735176 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1258597wro; Wed, 18 Oct 2023 16:33:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjsnkzOt5QMX4BOzYye72pxTTTc6p7JH1qCURsTICnBmktR1C85iVvCPbVKh5RUX76q3dL X-Received: by 2002:ac8:7d41:0:b0:419:b54d:9e91 with SMTP id h1-20020ac87d41000000b00419b54d9e91mr917383qtb.48.1697672018174; Wed, 18 Oct 2023 16:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697672018; cv=none; d=google.com; s=arc-20160816; b=eA/ZKWPK7EOrfZ151zM0u8NDa3diak7xdofgRr9XhmXCLzGWsPe8meiAJkYcrqS06u j44RJe6j4SJDMI/sZZfSexlrIW/CN2E7QX0bUPMKte9b6qVk2m0KlLD40iOJVvYpquDq wNs0TFhYC2PK5WnmgRUYaWUTWeI7xadlViwihSySnZwT77/JG7B/pUiZjdZDl576UCYW 4PepCieL/wcNll05VnCY3Ch7Z5eu1jXX3bhJMl9FFNld6gymLL8KzaSvs6Ht0lSVOr8v 6a0x1AUi57ILXeI2fWzo8UBvEf3tos/gRd0N2EIQMKkc3HvCOtpkhNDpMaLfogVFUZ/6 Qvdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MZQXmTezubKvZiknkUGl30NcUMWQlr0tOKsu9AI7N20=; fh=8c0w1Y/Hj4Gl/Vt6wBvf654EGKW0UtRIa5T9ySUitCI=; b=dW58UhmHE13VZ7WFMXWM5lM5CotDACCS2RNP955X5x1v327appz5LifoDL2AlOsIaq x/eDJe3bJO1jxjB2k32pATIEPN/kGgNuPC7V1RdOS8JvNmTwnRGVMXU5CGv4rBbXLKEK G1Lwo7sLt9XV50xENsbwtklw/FuttM4uh/Vvy+x1SMcshXXnZWM0QfxwOhTmTHVt47z5 996Jn2fAqlI9SeqmJgB7pVvnsUYZ1NCIiVcw3B1nWGLUPvYhp/VuuE+FtJVxE2XoacWV wR0OSjuyGOruYFXOfBbXrzwSWDh5MbMSgVIkWj+wiwFAsrVGlw7JFdT+4yAZYsznvqqY bu6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UhBV2fP1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z16-20020a05622a029000b00419842fb21csi728660qtw.488.2023.10.18.16.33.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2023 16:33:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UhBV2fP1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG11-00046l-Rx; Wed, 18 Oct 2023 19:31:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG0s-0003lt-RW for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:42 -0400 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0q-0000Ia-Ti for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:42 -0400 Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-7a67ebc2cb3so25267739f.2 for ; Wed, 18 Oct 2023 16:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671899; x=1698276699; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MZQXmTezubKvZiknkUGl30NcUMWQlr0tOKsu9AI7N20=; b=UhBV2fP1i+sf410LUy7MV1QCAkxH0dUu5tc5OXyfssKTcB/JDs7KAcuECptazKt9sc SoxUyKh6R2buAjA8gdpQkqswEf2T8kHbmzD7/y5KOZxfouy245m/w6StsALM6O8T9lUb VU0Db382NgXvi6kRFLyPzKqZZUejah0d63qOWrB8+JpW1CvRjmiyQsJCoAKisB38BRZ1 Qw9RhQ1+1RKSDuZh9XpbEAahPJSnCFTnps56s6SKwrJBRnicsGIBWv6iqggL2JYZVNZo n3BmQRVvvrjJfSb9u6QWR/rt6gmQTy7xMijmFj94ke/DxhgETUUvPdrWOfitcvowMTsE r3bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671899; x=1698276699; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MZQXmTezubKvZiknkUGl30NcUMWQlr0tOKsu9AI7N20=; b=oa/maBS1fNyVPdNUQGlbHvl9zUguwASecHEzBplv0O15fgt60dy6CRb+Kt1GZ5Q+5r N5Mk+Tcc0wrwdYxIU+SPEqUtwvMdBM5eFTyBZkFrAy1spuqKGlttX2mCc1PDGAnlVDZV ItSOsOwx+lfOqMElm2y8av1P5wNsDg/ACoHYaa2gCHfCm0EfiRC8NbmioBHBR6x2qDrg gyu4vhlNfuSnjmShPAhQX1UFS9p1caNfsFCGWA9T3e50IHfCm5lKL0ecJ+wRX+sRPwQJ lFyQTAUT4FSHBArumUkwfTQ19A8GAFEUFMqPsMIjt1T8pVY4pVIzaXl/S7W1hxOfaTKu Zqug== X-Gm-Message-State: AOJu0YzRTAqaQS71dzjKMSHdk2Yzs93qXkYQ1I5S2kxqJehSsC2wWb5B eMBfhxDfQDRvOmq6tMf1WMB6EyQ8g/f6zsVLzz0= X-Received: by 2002:a05:6e02:2168:b0:357:7b04:721 with SMTP id s8-20020a056e02216800b003577b040721mr948604ilv.32.1697671899501; Wed, 18 Oct 2023 16:31:39 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Andreas Schwab Subject: [PULL 05/14] linux-user: Propagate failure in mmap_reserve_or_unmap back to target_munmap Date: Wed, 18 Oct 2023 16:31:25 -0700 Message-Id: <20231018233134.1594292-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::d2e; envelope-from=richard.henderson@linaro.org; helo=mail-io1-xd2e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Do not assert success, but return any failure received. Additionally, fix the method of earlier error return in target_munmap. Reported-by: Andreas Schwab Signed-off-by: Richard Henderson --- linux-user/mmap.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 8ccaab7859..7b44b9ff49 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -778,7 +778,7 @@ fail: return -1; } -static void mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) +static int mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) { abi_ulong real_start; abi_ulong real_last; @@ -807,7 +807,7 @@ static void mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) prot |= page_get_flags(a + 1); } if (prot != 0) { - return; + return 0; } } else { for (prot = 0, a = real_start; a < start; a += TARGET_PAGE_SIZE) { @@ -825,7 +825,7 @@ static void mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) } if (real_last < real_start) { - return; + return 0; } } @@ -836,32 +836,36 @@ static void mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) void *ptr = mmap(host_start, real_len, PROT_NONE, MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, -1, 0); - assert(ptr == host_start); - } else { - int ret = munmap(host_start, real_len); - assert(ret == 0); + return ptr == host_start ? 0 : -1; } + return munmap(host_start, real_len); } int target_munmap(abi_ulong start, abi_ulong len) { + int ret; + trace_target_munmap(start, len); if (start & ~TARGET_PAGE_MASK) { - return -TARGET_EINVAL; + errno = EINVAL; + return -1; } len = TARGET_PAGE_ALIGN(len); if (len == 0 || !guest_range_valid_untagged(start, len)) { - return -TARGET_EINVAL; + errno = EINVAL; + return -1; } mmap_lock(); - mmap_reserve_or_unmap(start, len); - page_set_flags(start, start + len - 1, 0); - shm_region_rm_complete(start, start + len - 1); + ret = mmap_reserve_or_unmap(start, len); + if (likely(ret == 0)) { + page_set_flags(start, start + len - 1, 0); + shm_region_rm_complete(start, start + len - 1); + } mmap_unlock(); - return 0; + return ret; } abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, From patchwork Wed Oct 18 23:31:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 735180 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1258833wro; Wed, 18 Oct 2023 16:34:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZfGur/GCmkdCY17O3XqqYBxtLOZHKJeh6+jri9pMyIHJOJNdRAdRlT7UaTVQt/qaNZ6v3 X-Received: by 2002:a1f:7f04:0:b0:49d:8fc1:3fce with SMTP id o4-20020a1f7f04000000b0049d8fc13fcemr604707vki.0.1697672062007; Wed, 18 Oct 2023 16:34:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697672061; cv=none; d=google.com; s=arc-20160816; b=Iwuvst8fVbO4edTgnr77ZDoGlQwY+x2n4AHpyGeKLEAX1N9P3LDhpQBrBRSNmgqx9o XlZb+c0UOP9KHhB7N9Pj4whUSBwbZCpzmfnw5YH9ppphVZSTONYiMajgUboh7WWIIlfO lGJujGh9bKaU0dFBnrlI9/9fxgPqhcLehTc8CUEUkkNUtuMFGxOzK5BabMIgpwyKoi7P CdeWyXmcfBiwsj16mF6GpVgj+2soSh857WZyxry2Y5ZdQo84pK8czaAIRxAL0K9e21GL v448gclYWcREaF4smx8s9vtMqoGSynsN7nW39Rxo72I0W6EJN+d6tUTTOQ5fKZtgBA+t mxcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HR6OhNjXMnjPeW+GKwBhvGRBpRXClWtOK/vmyhs99O8=; fh=3//KcqJEsa04kIBt5Nb/DJuP+2GuH1NwDRxnSl44zdw=; b=UANyh4x2Pm4p4N43u1pTDahH/5Aw2s9NrbMUbyB4B5jER9EuWyFpYCkOQAHfiY//DZ tWDaLTK5jT+FG82lEA9Zg4q76L1Qz0Lsf8724/h/BOmg9c6Z2jcv/FSCQ5r609O9DvD2 fMeck05Fy9iTcFlDx+Hm9zIXfI0XBIB1VpRZiuLCtxecsp6txo0rEvZ+z9dtJT6PNRcN B1Sb6HacnAU2kpw+fIeSotV+VwwFWVx9elZRagDdxIAy+E/X9tqz1W638F64DWORa1Bi OG+0ziZq83V3t5p3ABjNjsvoVHNHxY+n0o77M1CwSYCL12LvdH+WVoHMzjtTeBw69R1M 20hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q2h+rqhZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v9-20020ac85789000000b0041996c8044dsi747586qta.307.2023.10.18.16.34.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2023 16:34:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q2h+rqhZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG15-000483-BR; Wed, 18 Oct 2023 19:31:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG0t-0003rB-AS for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:43 -0400 Received: from mail-il1-x12c.google.com ([2607:f8b0:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0r-0000JX-Jf for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:43 -0400 Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-35757bfb3f7so28872835ab.2 for ; Wed, 18 Oct 2023 16:31:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671900; x=1698276700; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HR6OhNjXMnjPeW+GKwBhvGRBpRXClWtOK/vmyhs99O8=; b=Q2h+rqhZP/VuOhuhJBPUC+pYz1Ni0cd+/mXSDmr6rBfHRuAjzeT8Hq4ACQo/VwcjOK bNsmiLaWnMavwKjZRjfdA4SFwYvXS+MgQCQo9IcaJc5ZPwvuhWdlVJMqE+rVNlY9T/n9 0MR8IJdGmJgh6Ujz49P8PYzo7Z5ULMGromwIzREJBGL3xnRUb5QBp71GJYDWPmOZjW+O Q5LQ0m1FmPZcmm+8klaTPELYzT9nd8fJGY/WovEyuh55CaiAJ71qy1gli6Bp4G4AnDLe O630yfdG5WyDGVUr+jV32p4M4/r8ahFHZSh3AIW0sC6gzMoAUUblKOAFZ7G5eUGKjGAe DFCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671900; x=1698276700; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HR6OhNjXMnjPeW+GKwBhvGRBpRXClWtOK/vmyhs99O8=; b=XWP3j2rC+GO+CqlA+DcgJN81THZF02YuV8qJHJYQFlcFVJHw6vVICse30F7BvrWLdx 6+xU8it0q+GIMTwdKRd7ee3PL91v2PvKinbr3GFwS/iVVpuC9WQEA1HJOlbjCrr5X7l7 /ZPOEYk7ZMv83sy1s8Az1R4wMP0uY30m0vxrauoZhscOmkQky3GDTIzg7j1wVhmeWKvn XhYfOUYIWtldcnEm/r/yNlB1dC8OgmxbH1yRtRpgqJ8hmp4kzabdQm68sEiUVlLMWwYl jJ97oMEK/KqarFAb4KhRSOIvYAzRcVkUo8b8F/pgsBqTNgZ6UaTr8C7uMM+au6EoHDC2 6dRA== X-Gm-Message-State: AOJu0YxlA/cUCafIsRRcnyNpAIqOoO4WRTk5VUCtjdNSZEjzrNsTXLXM M2E1fL0CGtZaSeM3gi1UmGrzKamNX/ZpyVSSf/A= X-Received: by 2002:a05:6e02:219b:b0:357:72e5:4adf with SMTP id j27-20020a056e02219b00b0035772e54adfmr1090888ila.26.1697671900599; Wed, 18 Oct 2023 16:31:40 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 06/14] linux-user: Split out die_with_signal Date: Wed, 18 Oct 2023 16:31:26 -0700 Message-Id: <20231018233134.1594292-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::12c; envelope-from=richard.henderson@linaro.org; helo=mail-il1-x12c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Because we trap so many signals for use by the guest, we have to take extra steps to exit properly. Acked-by: Helge Deller Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/signal.c | 52 ++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index a67ab47d30..b7a2c47837 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -689,13 +689,39 @@ void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr, } /* abort execution with signal */ +static G_NORETURN +void die_with_signal(int host_sig) +{ + struct sigaction act = { + .sa_handler = SIG_DFL, + }; + + /* + * The proper exit code for dying from an uncaught signal is -. + * The kernel doesn't allow exit() or _exit() to pass a negative value. + * To get the proper exit code we need to actually die from an uncaught + * signal. Here the default signal handler is installed, we send + * the signal and we wait for it to arrive. + */ + sigfillset(&act.sa_mask); + sigaction(host_sig, &act, NULL); + + kill(getpid(), host_sig); + + /* Make sure the signal isn't masked (reusing the mask inside of act). */ + sigdelset(&act.sa_mask, host_sig); + sigsuspend(&act.sa_mask); + + /* unreachable */ + abort(); +} + static G_NORETURN void dump_core_and_abort(CPUArchState *env, int target_sig) { CPUState *cpu = env_cpu(env); TaskState *ts = (TaskState *)cpu->opaque; int host_sig, core_dumped = 0; - struct sigaction act; host_sig = target_to_host_signal(target_sig); trace_user_dump_core_and_abort(env, target_sig, host_sig); @@ -719,29 +745,7 @@ void dump_core_and_abort(CPUArchState *env, int target_sig) } preexit_cleanup(env, 128 + target_sig); - - /* The proper exit code for dying from an uncaught signal is - * -. The kernel doesn't allow exit() or _exit() to pass - * a negative value. To get the proper exit code we need to - * actually die from an uncaught signal. Here the default signal - * handler is installed, we send ourself a signal and we wait for - * it to arrive. */ - sigfillset(&act.sa_mask); - act.sa_handler = SIG_DFL; - act.sa_flags = 0; - sigaction(host_sig, &act, NULL); - - /* For some reason raise(host_sig) doesn't send the signal when - * statically linked on x86-64. */ - kill(getpid(), host_sig); - - /* Make sure the signal isn't masked (just reuse the mask inside - of act) */ - sigdelset(&act.sa_mask, host_sig); - sigsuspend(&act.sa_mask); - - /* unreachable */ - abort(); + die_with_signal(host_sig); } /* queue a signal so that it will be send to the virtual CPU as soon From patchwork Wed Oct 18 23:31:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 735173 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1258549wro; Wed, 18 Oct 2023 16:33:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH9cI/UF6wD8ZzK3Ka9L6QQTmXk+hQvZrHlUWvWn95q5aw2JCRI1qqCvwJ6qQEglswfIstK X-Received: by 2002:a05:6214:e8c:b0:65a:f332:10f6 with SMTP id hf12-20020a0562140e8c00b0065af33210f6mr959256qvb.35.1697672010220; Wed, 18 Oct 2023 16:33:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697672010; cv=none; d=google.com; s=arc-20160816; b=bN2W6ksVtt4a4DHLU76K21He8rYcn8FZX+ZiLJr4trk5br2126pF2FqjSywGz9C/WP umtSrlgBD8+9FkzYIkXoWIs1Nz/Xa4Ip2C742hZ8sYJM+he4zXmM8C5fvPZBM8BYaGzy RUtt7Rb8yHyKCRyTBia783ByUrzyMNOFus14HYRT9RMLMuWye/DVUusTdRlFU2MdL0U7 qDhFRVx/00fg9Y4bFC5OR492QWDp+KCCjqDbdeawbho67kXPJlrNfRKa+R9n22kb14SU mQXYrGy4rSwBPLPRQv1G789SqW+VhwSvewfgUfNYv6KIxqrRlhvPD9zM3hbfOGPtMbFe LGlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XDEeeYBNH4kaMPDKd2bpL06m4MGoDecFzYDq6oXSWUM=; fh=3//KcqJEsa04kIBt5Nb/DJuP+2GuH1NwDRxnSl44zdw=; b=j6frtWp5A5W8cNpRl1DP1KRIWWM7p8Zu3pWgsd46b42eCP8/fX1/54cFjP+5tN0ecf 4/BAXV2jc836KUD5OhBNMe+uqp5U18k+6iyvDLSjl45MwtBsaPPZiPHPrTVfWkK8At+o c3+hX/l41IqbYNjS1NNDVTCRjxdviee2l2kpahIHOOUgUP4GV/RO83a1F2eZ8hwkz/TL Xze8365oC7zf9tcIRcbCMKIxJ2le0sppnLatQcl3kmf+EbHKkfI4EBXk33ccjjBTeKqs jdAQOmdk8qMYhA8WbuqEZRI/go1XYJUxPIn/YSITL9s9FY2G4lSYcw1N+6LYlBu1MeRs ZoZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E5bVMljh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v2-20020a0ccd82000000b0065b2cca41a2si737390qvm.110.2023.10.18.16.33.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2023 16:33:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E5bVMljh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG0v-0003yg-SW; Wed, 18 Oct 2023 19:31:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG0u-0003vt-3a for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:44 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0s-0000KC-Ig for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:43 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6b1e46ca282so5808204b3a.2 for ; Wed, 18 Oct 2023 16:31:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671901; x=1698276701; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XDEeeYBNH4kaMPDKd2bpL06m4MGoDecFzYDq6oXSWUM=; b=E5bVMljhVaac6oapoai8D5VZEBpg26aWN1S68fE3yZUQ0RD+n1Bf9iMc1dvGu7qV8l gu1u39Wv2w/DtUPYs+LqpvvNq57ITlRX3zHU9P54F3TcYm02C5wNURCYc/RN89MlKsIk cg/CBqfwl1V9bqG8qM0u4+DNpYc+0m3Bnd29FZuRIG5St8FXkDjD51lYCYPYezSvXFJ4 UqiRbN6tpI8tNnmGhp+enM84QnW1PY8uC0B/S8xGW1hniJQ8nbMtwa7PdbtLK+Ka07l3 4gZdqhsbsjgNXy+KD8pyKtvwls/Cq87fTuicF4X7NycNE8Y60FzFF7bzveWH6UBKleiF 66gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671901; x=1698276701; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XDEeeYBNH4kaMPDKd2bpL06m4MGoDecFzYDq6oXSWUM=; b=I902sHxOSE6o3rIU/vgEutM/lZ7Wvhy3ZyJQFNfJcn1j0pUJrxfPW1eTrMd7qgTlq6 2boNkShJRgltEO/LDTqUwBSioW0nrwn2kW0uLONiIiEXuW8+LAcFibArr0U234u/niBC bVmlj7kMHEe8hMe00g22kP6MjlgQKV2dx1bTVosMTWT3l1N2pdh9ZTjZ6j4Xcmv17MpQ Kwx1l2KXktdmCqisX3O2XBMBC/xmkvhVyGuV4uGoNEYQ+riINfm4TpQdAyBteQPC8oWK bB7r17M2lQzr9nkIjhQ0pfCGKar84KLkyhr29GphRzoW3VP8OzdGc+6evC0hjthaH/qr lkLQ== X-Gm-Message-State: AOJu0YxGncnMAdGveoWyhbxdwVZsJUVmcVbQZWyRcRSqeSCspJNE3twX Eg3ojonoGfBkBrGzLmKSKKRnpjSymcovKwxiH3w= X-Received: by 2002:a05:6a00:189f:b0:68f:c7c5:a73a with SMTP id x31-20020a056a00189f00b0068fc7c5a73amr655931pfh.16.1697671901235; Wed, 18 Oct 2023 16:31:41 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 07/14] linux-user: Exit not abort in die_with_backtrace Date: Wed, 18 Oct 2023 16:31:27 -0700 Message-Id: <20231018233134.1594292-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This line is supposed to be unreachable, but if we're going to have it at all, SIGABRT via abort() is subject to the same signal peril that created this function in the first place. We can _exit immediately without peril. Acked-by: Helge Deller Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index b7a2c47837..84a56b76cc 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -713,7 +713,7 @@ void die_with_signal(int host_sig) sigsuspend(&act.sa_mask); /* unreachable */ - abort(); + _exit(EXIT_FAILURE); } static G_NORETURN From patchwork Wed Oct 18 23:31:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 735169 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1258432wro; Wed, 18 Oct 2023 16:33:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFt0jM9oB74Hohxg69yTct+QnHB4HON6ncl/x+TqJZnISrZ/r/4m21DVf9S3Felfl3DZOhA X-Received: by 2002:a05:620a:8dc5:b0:775:ed1e:2741 with SMTP id rd5-20020a05620a8dc500b00775ed1e2741mr492770qkn.7.1697671989815; Wed, 18 Oct 2023 16:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697671989; cv=none; d=google.com; s=arc-20160816; b=VhuovUEdyuKmM0oEm6SD1Iwc9PmBbDEiz49WzMMX68SA6cF5l1IZFLHjkFEL13WDCl ud9CZlb8o3hs8oGD18Oyy4+i+wj/rG8YoAAMg7NzTCDF9gbpR+Ytnx+gts0usBBBpWri PBYcmcydOHUql589zI3GRbWvJYj3NkdtA6SwaNmbN5bYog+q9uY3Q2diR4r3SCu1gHfk jrWFkIXFJfqu+Th2EwZkpadBxpghfM+HMytb54qHuc0Kt53UY3I9TnpI7DmWz3KQy/7a 79V7wc672ZtwkIIodFw0IWmfbD+rs06OPtlpQtiNn6VXzYfL6JUcM0AOgobAm5AcTwUl gArQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OQP2+HZbJmIj9sXXPBVMTwI7vC2S6c38AoM7akl90XU=; fh=wDljmxUHXfz9MGj2//jPHYRc53BMWF157v8rVKELrf4=; b=KMz9Wk6BRVVV9WQSCcs76ZIHYUVEzAJd4vn0VIQXZD+uduw9lonPH/jhulQeGwarsI XARBh3+0DVhHVOzMdSO6hX671IWHMVVxH1mZpNFU1FQDExQ/EjBlZ5sjpUcEwPyCwwCL aaBO0oyDxcPeZttg520kt2Y5WhkJXshmQul9taFxNxISwYql3aumaWt8YclLc8QsdoBl HDbzXRxFSX6r2Jiz3d8i69vXxWbOXjmRmeUf0rkxLOAUNum6CpvvMvZ1qB5N13STbpQv rHjLsYjnVS/H6Zag2D72E3zuOUXa7/PLZuHkBA9FXTvy4v1G3K/7Yzld4gn1BSvuK8CJ Ib+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IBuuzY6E; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b23-20020a05620a0cd700b0077263dd03f3si735219qkj.33.2023.10.18.16.33.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2023 16:33:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IBuuzY6E; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG0w-00040F-4Z; Wed, 18 Oct 2023 19:31:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG0v-0003xQ-2C for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:45 -0400 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0t-0000KW-7w for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:44 -0400 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6c646b5028dso4867856a34.3 for ; Wed, 18 Oct 2023 16:31:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671902; x=1698276702; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OQP2+HZbJmIj9sXXPBVMTwI7vC2S6c38AoM7akl90XU=; b=IBuuzY6E+oFSysj0ymtpPsytGO+XLWJHp9Omipe5GFCQ7d8fo1maMom5k7tYXDDRWi 6RZV9X86jzzpz7N9P/tyNnntz451y5iOQa3yC0rPU/vp7+v/guOFnvLz6lCOtja5I4XV rYrkudo7lKT9mqWdDja7EZeL31scldfO/GJP7pAv0PARYh8R+GSiwAznEV7rl8hxZ//k B6LSDDQ+rk5oJVFfmArKYFqSxLs1ObSJsD5qaOaNBeBDUKy3E4z8Hkqu4+Z3+26V7pev ZoUC5LycWJGvdOISPjYFmgMRWX5enpTflDPvySiz3fGHefJbKJrcKSP75M8rakThoJFo wwaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671902; x=1698276702; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OQP2+HZbJmIj9sXXPBVMTwI7vC2S6c38AoM7akl90XU=; b=qJocHFZHalqChORdaHxDJDg3aXuPETGc+G4thmpKtJ5Ajk31b3XuBb8M4yvXKT8UaD aRmOVM9sNEzBQoir1MVVeBD/B83mzLRMMCoNI39d09mQ1AhicYpQuW7otWxMCl4h8wGp G4xRK8uHu24XdkAb9gKvAUj7UzJFi/GSlYSslYSQC52EYlCvpQHgTSTpymllah42JmVN 6xoWmrw4TercJOEb9FNJMiFYsHRucvQaMfMYab7qQZvQ/F+YfgX7kSe97T6OHtjjYFHN 3js6JoM5qv1GEmh4w4o66UR28e1FLIPm66TAT8HjhUqX/xHMNCRZbDU9EZzzotO6GR+D 7QQA== X-Gm-Message-State: AOJu0YwzeuGvNE1hvRQsmJJu64802Vmfi0nnJPzQGmD2W1yXAJ5abNUl YPYSIpYfBJZwP3t0s6ha+8H+UuGqJYcgFu5/MXs= X-Received: by 2002:a9d:4d07:0:b0:6bc:fb5f:7b06 with SMTP id n7-20020a9d4d07000000b006bcfb5f7b06mr731046otf.17.1697671901979; Wed, 18 Oct 2023 16:31:41 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 08/14] linux-user: Detect and report host crashes Date: Wed, 18 Oct 2023 16:31:28 -0700 Message-Id: <20231018233134.1594292-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::330; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x330.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Helge Deller If there is an internal program error in the qemu source code which raises SIGSEGV or SIGBUS, we currently assume the signal belongs to the guest. With an artificial error introduced, we will now print QEMU internal SIGSEGV {code=MAPERR, addr=(nil)} Signed-off-by: Helge Deller Message-Id: <20230812164314.352131-1-deller@gmx.de> [rth: Use in_code_gen_buffer and die_with_signal; drop backtrace] Signed-off-by: Richard Henderson --- linux-user/signal.c | 69 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 84a56b76cc..9fadc51347 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -32,6 +32,7 @@ #include "signal-common.h" #include "host-signal.h" #include "user/safe-syscall.h" +#include "tcg/tcg.h" static struct target_sigaction sigact_table[TARGET_NSIG]; @@ -779,6 +780,50 @@ static inline void rewind_if_in_safe_syscall(void *puc) } } +static G_NORETURN +void die_from_signal(siginfo_t *info) +{ + char sigbuf[4], codebuf[12]; + const char *sig, *code = NULL; + + switch (info->si_signo) { + case SIGSEGV: + sig = "SEGV"; + switch (info->si_code) { + case SEGV_MAPERR: + code = "MAPERR"; + break; + case SEGV_ACCERR: + code = "ACCERR"; + break; + } + break; + case SIGBUS: + sig = "BUS"; + switch (info->si_code) { + case BUS_ADRALN: + code = "ADRALN"; + break; + case BUS_ADRERR: + code = "ADRERR"; + break; + } + break; + default: + snprintf(sigbuf, sizeof(sigbuf), "%d", info->si_signo); + sig = sigbuf; + break; + } + if (code == NULL) { + snprintf(codebuf, sizeof(sigbuf), "%d", info->si_code); + code = codebuf; + } + + error_report("QEMU internal SIG%s {code=%s, addr=%p}", + sig, code, info->si_addr); + die_with_signal(info->si_signo); +} + static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) { CPUState *cpu = thread_cpu; @@ -814,16 +859,28 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) is_write = host_signal_write(info, uc); access_type = adjust_signal_pc(&pc, is_write); + /* If this was a write to a TB protected page, restart. */ + if (is_write + && host_sig == SIGSEGV + && info->si_code == SEGV_ACCERR + && h2g_valid(host_addr) + && handle_sigsegv_accerr_write(cpu, sigmask, pc, guest_addr)) { + return; + } + + /* + * If the access was not on behalf of the guest, within the executable + * mapping of the generated code buffer, then it is a host bug. + */ + if (access_type != MMU_INST_FETCH + && !in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { + die_from_signal(info); + } + if (host_sig == SIGSEGV) { bool maperr = true; if (info->si_code == SEGV_ACCERR && h2g_valid(host_addr)) { - /* If this was a write to a TB protected page, restart. */ - if (is_write && - handle_sigsegv_accerr_write(cpu, sigmask, pc, guest_addr)) { - return; - } - /* * With reserved_va, the whole address space is PROT_NONE, * which means that we may get ACCERR when we want MAPERR. From patchwork Wed Oct 18 23:31:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 735177 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1258645wro; Wed, 18 Oct 2023 16:33:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKbv+4YfcrQQ56Yq3Ec6MGQh8Z2NH9MH2XCQ8tJ0G8xL8K2waI07aJQze/MbpvGE5k3Hez X-Received: by 2002:a67:e115:0:b0:457:c547:c3b with SMTP id d21-20020a67e115000000b00457c5470c3bmr413036vsl.4.1697672026889; Wed, 18 Oct 2023 16:33:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697672026; cv=none; d=google.com; s=arc-20160816; b=ZN4H6k3ZlIS3rJuCsUvzkxsWT/Je5U4kReTjP0QAklfnLoTsZ+1dtZ++iP9SKWS1Se 53g68TmirSpFtgYxdmqzDXU/VaWnAR7C/+oj72/WMPJRXzOwzxmDmwI6Ja96ltTmkVrK DRB9ZiG9FfyUmNhMcX0ex4KiAkl9DuaLRiLuFm7M/uO6OXorZZTXDLmmo2O2+GwKHRa4 jabAWLCvROZCapsBgY7uKmcRy1wKXSWk2QQ6se5TpFVr9NwHNXtS53vRrpufM16tbm8m 18AmiHOkwnOcphBpLrMOQRj0Wf0+xoeWkQsIp0RBYGfpTp+e2bDBet0yXUOy1w5Wlx7u 6soQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=N8YP8FFBP63+6pJ6d97ew/Y5ZJwzVjBAkzrh/+j6myU=; fh=wDljmxUHXfz9MGj2//jPHYRc53BMWF157v8rVKELrf4=; b=w6ezICwP2MYmS0VFnjdiqug7p5a+nSOz6QA0+bN/kHFHIF+C+iQ46gWt+BUsV1mJgX 6WPzib3DfMufOcvk9aZ4J5kHrP0s895GVdslvP+bs1NgtYw28/zJZvrqQzUBXfmRPeOS aa872vHnU+PR4WTK7QAH+yOz0QNcK8ZM+mKRpVZNDLUXAraGhu2KZcJq2zF/y8spk08H 8dmAY14PvbPXzw+GFtnzJ7/CKORXA68qPhOpHy5vt6RMCY59lUQyqFqiNwpDJBIfy526 C4exrbsvpRi4ZpuN/jxoG0bDC6A3Ys2dpsP8GSST+EiXLfdK0cuP6XhE9ji756wP+PLJ TJ+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ldUBiC9t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i15-20020ac85e4f000000b00419608e885csi733810qtx.692.2023.10.18.16.33.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2023 16:33:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ldUBiC9t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG0y-00045x-2Q; Wed, 18 Oct 2023 19:31:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG0v-0003yy-S3 for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:45 -0400 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0u-0000LX-4m for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:45 -0400 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-581f78a0206so621684eaf.2 for ; Wed, 18 Oct 2023 16:31:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671903; x=1698276703; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=N8YP8FFBP63+6pJ6d97ew/Y5ZJwzVjBAkzrh/+j6myU=; b=ldUBiC9t4xg2eP9SVkGMYPf+O6B8F/z/eEQjjbaWv19rHu5cT9OQHIsnAGKS+zhv9E R/xGG9tFXDsPC1ECVceT7aWN5fZ7DtdElfZiWeWFmH/R7aA4Cz5adZbMcOIY9ud5efye ON+G5Ts0IkU0UE8rrCGBkdVWdBsL2zIESGPKUabW4WxjpElL/djugugqhGY0q8ygr+Rp wFQrI0RP8nExb5ogRG0pvWfq60u0r/eveUrJTMyERRgO+RRCUWjz9bSRMhsS/j+73b/T YlWyDKK18vcYu8Chkt74j4e7DT1jgOShmMLuk5x7nTVFcWOzDcSNR1ssyx+c/kAeCYJg P5kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671903; x=1698276703; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N8YP8FFBP63+6pJ6d97ew/Y5ZJwzVjBAkzrh/+j6myU=; b=Pjy8j5NJQ64Ad0dUsGKtKUwNaY6+U1Q3xveL4n5DiIqint0sGH4elM33ShNaIrOpIh ee2w0WY5v6YUP0UeMzxb9lMetA9b5+qRYLHGRb0D2kxpirQL5mk+Dmb5tTGkPt7jUiwX hTqJyqMyI4UKWEbDx8eEixcBzkJJqGrPmWRJGNbT1CvDq/qWETjyYCUs3AWUz17099IJ XEeeUxnzejsx8UXXqFeosD8z2MGHo5Ueu28f02DEt5W0Nk7UV8WiOhqrM10b6hl4KR5B p631fOJvKbwkY4zkZsEFW81K9jbtL9DI28qO90NCsX8v8bp01PurB1qrMSpCopISNJmG awaw== X-Gm-Message-State: AOJu0YwTbpe0gzLDIoxYgVbRNlkfszk4PnZQF29t8Lz4h4O1FqzVdyic MuX0dUvBtfMne9eVWNnUrfUWyhIB3W9zRvRW818= X-Received: by 2002:a05:6358:9f85:b0:139:9fc3:eade with SMTP id fy5-20020a0563589f8500b001399fc3eademr429405rwb.29.1697671902800; Wed, 18 Oct 2023 16:31:42 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 09/14] linux-user: Only register handlers for core_dump_signal by default Date: Wed, 18 Oct 2023 16:31:29 -0700 Message-Id: <20231018233134.1594292-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c2b; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc2b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The set of fatal signals is really immaterial. If one arrives, and is unhandled, then the qemu process dies and the parent gets the correct signal. It is only for those signals which we would like to perform a guest core dump instead of a host core dump that we need to catch. Acked-by: Helge Deller Signed-off-by: Richard Henderson --- linux-user/signal.c | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 9fadc51347..aab05f8eec 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -488,26 +488,6 @@ void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo) info->si_value.sival_ptr = (void *)(long)sival_ptr; } -static int fatal_signal (int sig) -{ - switch (sig) { - case TARGET_SIGCHLD: - case TARGET_SIGURG: - case TARGET_SIGWINCH: - /* Ignored by default. */ - return 0; - case TARGET_SIGCONT: - case TARGET_SIGSTOP: - case TARGET_SIGTSTP: - case TARGET_SIGTTIN: - case TARGET_SIGTTOU: - /* Job control signals. */ - return 0; - default: - return 1; - } -} - /* returns 1 if given signal should dump core if not handled */ static int core_dump_signal(int sig) { @@ -602,8 +582,9 @@ void signal_init(void) SIGSEGV and SIGBUS, to detect exceptions. We can not just trap all signals because it affects syscall interrupt behavior. But do trap all default-fatal signals. */ - if (fatal_signal (i)) + if (core_dump_signal(i)) { sigaction(host_sig, &act, NULL); + } } } @@ -997,7 +978,6 @@ int do_sigaction(int sig, const struct target_sigaction *act, struct target_sigaction *oact, abi_ulong ka_restorer) { struct target_sigaction *k; - struct sigaction act1; int host_sig; int ret = 0; @@ -1057,22 +1037,27 @@ int do_sigaction(int sig, const struct target_sigaction *act, return 0; } if (host_sig != SIGSEGV && host_sig != SIGBUS) { + struct sigaction act1; + sigfillset(&act1.sa_mask); act1.sa_flags = SA_SIGINFO; - if (k->sa_flags & TARGET_SA_RESTART) - act1.sa_flags |= SA_RESTART; - /* NOTE: it is important to update the host kernel signal - ignore state to avoid getting unexpected interrupted - syscalls */ if (k->_sa_handler == TARGET_SIG_IGN) { + /* + * It is important to update the host kernel signal ignore + * state to avoid getting unexpected interrupted syscalls. + */ act1.sa_sigaction = (void *)SIG_IGN; } else if (k->_sa_handler == TARGET_SIG_DFL) { - if (fatal_signal (sig)) + if (core_dump_signal(sig)) { act1.sa_sigaction = host_signal_handler; - else + } else { act1.sa_sigaction = (void *)SIG_DFL; + } } else { act1.sa_sigaction = host_signal_handler; + if (k->sa_flags & TARGET_SA_RESTART) { + act1.sa_flags |= SA_RESTART; + } } ret = sigaction(host_sig, &act1, NULL); } From patchwork Wed Oct 18 23:31:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 735175 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1258561wro; Wed, 18 Oct 2023 16:33:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH0xPG1n2T1ZBdKgPnvs0UIiJh2KAEcu9tWmI9V6vUhaPSPoSoC7ImLeIUZf665KnGsnbtI X-Received: by 2002:ad4:5de1:0:b0:66d:627e:24c0 with SMTP id jn1-20020ad45de1000000b0066d627e24c0mr748070qvb.38.1697672012489; Wed, 18 Oct 2023 16:33:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697672012; cv=none; d=google.com; s=arc-20160816; b=S39PuPCEFaeJhxe7yCDNC66+YL+LABtsJsMXRMGG1sRw6NgYQrccxLEWzQFbNQD+H3 hwdOOz9nfuVVJgzfi/nPqVjU6hHmDpYac+G/lx/R3AFnRWbNYyl6fptmTMxbqAT8Yfx3 Ic1ftR6PB/5hJtBBVKXs1Pv69EcBpVG9pA2ISMnh1xqTsBw1msJLHAT9yJ0EExDnhTI8 dLulAbL1tFxL0YanCaY4pQ26pk2g396wvVs5sFHUMkfsF3cF4gghfoCKpEFMUQ0Hx2wI io23zkubmyjkaL0Dr9I/zv4suX8p8kgZvQ/DUJnefQetueoOz9ybDbc4yJ5ffDubpz3E rFug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UKWfNxY8ZBT24vryvV7tNUff057UO3MB5fEykagaJko=; fh=wDljmxUHXfz9MGj2//jPHYRc53BMWF157v8rVKELrf4=; b=B8ulaYaAVIwxADpoTEYsZRzSYHHXd3T4PWcdjSQWmvQOoqXvFyX+mALGOOd04Idtp3 XmPibsOvPUT+6k8P9wV2K/XYkFSumaR6+kQWOtGIvmhUvSVJO9d5/wMfYj5LuZ/kOodp mp+lquo6sj6c/paY0LZTw1fu7fAnhUi7p57BPHJcB+rNFwMp9+qcWy1WXoKNzhul/3bZ bWJyDte98qmmg5ww7NhN12Xaa2S+v4lWv0BhauQIkeNjfSBSyeE9oLjh2ZPz3SCWgGK6 WdEmMpdvBpB6tavF/CVzaoY2ubSAkTQ410/HXwvYdguS/oV8qChd2U5MekH9tmeJ0iuc 7ATw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UbN7ggD/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id im11-20020a056214246b00b0066d15c73fb1si830237qvb.285.2023.10.18.16.33.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2023 16:33:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UbN7ggD/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG11-00046m-RU; Wed, 18 Oct 2023 19:31:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG0x-00044s-2n for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:47 -0400 Received: from mail-oo1-xc31.google.com ([2607:f8b0:4864:20::c31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0v-0000Lp-2x for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:46 -0400 Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-57b5ef5b947so4745129eaf.0 for ; Wed, 18 Oct 2023 16:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671904; x=1698276704; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UKWfNxY8ZBT24vryvV7tNUff057UO3MB5fEykagaJko=; b=UbN7ggD/knFsrh6J2kylQfTclqqk2mpjtFLBZmj3WV70we/mhb/JZ4rT12cHyXVJx/ SYnV79oHZBXNNsFoYgdIO0px2IEPDXKTnfeTRDyCEvX0xbthXWCtHMG5y9HRZ/yLJPEe Q2Y/vLzWhKUbm8GX5G7HG2fKROzHn91wuGZ+MddUFXb33a0EMMfqm2tpGeuG1ccGA8Aa xll5YEU6kyQRJlP1VUAcvzylV2NydDC2EWLd68lMXfJq5RW2p7oORo47ErrrW+OaVrMm vUY4gpFZJkr7aHdQf0zOEhiQQbFC56wZcPflbuEo4NOvlwyxw+5HJtx5UgFwJO4V/F8D xMwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671904; x=1698276704; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UKWfNxY8ZBT24vryvV7tNUff057UO3MB5fEykagaJko=; b=eNbZKn4H2WwiWwqqZfUGZW3CkGtjfBPl/f5S8066fk3KHZrSHoA4TX4RtoE1G8eTnQ QXEFAfgcRQCSjQGD2U/wHfYtXWsSas+DQfrhoIxQqTlCVqI/YcC0L6Za1Obyx7F+5prg xpfMcppQb6JjiTVc9UGWjjmS2e6MO9ihCDTUsFeeh9Hueh1yKyA81qqSwz0QGNF96n9a cKdW8Nf0hqp0ebRK8/a4W+SGM0JfCbWgAzARdysvZ3yDJbTxgDvESSIgd2dSE89WZLwP o75QcEvO3FWiSQK6wDQD3FbSftMjHyqzHbdiiH22y+0NZuVh3mh7Zs1c66y46HjgTOU5 Brsw== X-Gm-Message-State: AOJu0YxABLazEsGwKuOpeWx7uakuLLgAQMg2pcqqG9V5kViS54SQycxZ Lhnn+Jvb2gUvb3oaYmFwEHKANHwZBs+knW2MR6o= X-Received: by 2002:a05:6358:3a0e:b0:168:9f53:9d67 with SMTP id g14-20020a0563583a0e00b001689f539d67mr493003rwe.20.1697671903722; Wed, 18 Oct 2023 16:31:43 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 10/14] linux-user: Map unsupported signals to an out-of-bounds value Date: Wed, 18 Oct 2023 16:31:30 -0700 Message-Id: <20231018233134.1594292-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c31; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc31.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Do not return a valid signal number in one domain when given an invalid signal number in the other domain. Acked-by: Helge Deller Signed-off-by: Richard Henderson --- linux-user/signal.c | 72 ++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index aab05f8eec..653fd2f9fd 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -44,9 +44,8 @@ abi_ulong default_sigreturn; abi_ulong default_rt_sigreturn; /* - * System includes define _NSIG as SIGRTMAX + 1, - * but qemu (like the kernel) defines TARGET_NSIG as TARGET_SIGRTMAX - * and the first signal is SIGHUP defined as 1 + * System includes define _NSIG as SIGRTMAX + 1, but qemu (like the kernel) + * defines TARGET_NSIG as TARGET_SIGRTMAX and the first signal is 1. * Signal number 0 is reserved for use as kill(pid, 0), to test whether * a process exists without sending it a signal. */ @@ -57,7 +56,6 @@ static uint8_t host_to_target_signal_table[_NSIG] = { #define MAKE_SIG_ENTRY(sig) [sig] = TARGET_##sig, MAKE_SIGNAL_LIST #undef MAKE_SIG_ENTRY - /* next signals stay the same */ }; static uint8_t target_to_host_signal_table[TARGET_NSIG + 1]; @@ -65,18 +63,24 @@ static uint8_t target_to_host_signal_table[TARGET_NSIG + 1]; /* valid sig is between 1 and _NSIG - 1 */ int host_to_target_signal(int sig) { - if (sig < 1 || sig >= _NSIG) { + if (sig < 1) { return sig; } + if (sig >= _NSIG) { + return TARGET_NSIG + 1; + } return host_to_target_signal_table[sig]; } /* valid sig is between 1 and TARGET_NSIG */ int target_to_host_signal(int sig) { - if (sig < 1 || sig > TARGET_NSIG) { + if (sig < 1) { return sig; } + if (sig > TARGET_NSIG) { + return _NSIG; + } return target_to_host_signal_table[sig]; } @@ -507,48 +511,48 @@ static int core_dump_signal(int sig) static void signal_table_init(void) { - int host_sig, target_sig, count; + int hsig, tsig, count; /* * Signals are supported starting from TARGET_SIGRTMIN and going up - * until we run out of host realtime signals. - * glibc at least uses only the lower 2 rt signals and probably - * nobody's using the upper ones. - * it's why SIGRTMIN (34) is generally greater than __SIGRTMIN (32) - * To fix this properly we need to do manual signal delivery multiplexed - * over a single host signal. + * until we run out of host realtime signals. Glibc uses the lower 2 + * RT signals and (hopefully) nobody uses the upper ones. + * This is why SIGRTMIN (34) is generally greater than __SIGRTMIN (32). + * To fix this properly we would need to do manual signal delivery + * multiplexed over a single host signal. * Attempts for configure "missing" signals via sigaction will be * silently ignored. */ - for (host_sig = SIGRTMIN; host_sig <= SIGRTMAX; host_sig++) { - target_sig = host_sig - SIGRTMIN + TARGET_SIGRTMIN; - if (target_sig <= TARGET_NSIG) { - host_to_target_signal_table[host_sig] = target_sig; + for (hsig = SIGRTMIN; hsig <= SIGRTMAX; hsig++) { + tsig = hsig - SIGRTMIN + TARGET_SIGRTMIN; + if (tsig <= TARGET_NSIG) { + host_to_target_signal_table[hsig] = tsig; } } - /* generate signal conversion tables */ - for (target_sig = 1; target_sig <= TARGET_NSIG; target_sig++) { - target_to_host_signal_table[target_sig] = _NSIG; /* poison */ - } - for (host_sig = 1; host_sig < _NSIG; host_sig++) { - if (host_to_target_signal_table[host_sig] == 0) { - host_to_target_signal_table[host_sig] = host_sig; - } - target_sig = host_to_target_signal_table[host_sig]; - if (target_sig <= TARGET_NSIG) { - target_to_host_signal_table[target_sig] = host_sig; + /* Invert the mapping that has already been assigned. */ + for (hsig = 1; hsig < _NSIG; hsig++) { + tsig = host_to_target_signal_table[hsig]; + if (tsig) { + assert(target_to_host_signal_table[tsig] == 0); + target_to_host_signal_table[tsig] = hsig; } } - if (trace_event_get_state_backends(TRACE_SIGNAL_TABLE_INIT)) { - for (target_sig = 1, count = 0; target_sig <= TARGET_NSIG; target_sig++) { - if (target_to_host_signal_table[target_sig] == _NSIG) { - count++; - } + /* Map everything else out-of-bounds. */ + for (hsig = 1; hsig < _NSIG; hsig++) { + if (host_to_target_signal_table[hsig] == 0) { + host_to_target_signal_table[hsig] = TARGET_NSIG + 1; } - trace_signal_table_init(count); } + for (count = 0, tsig = 1; tsig <= TARGET_NSIG; tsig++) { + if (target_to_host_signal_table[tsig] == 0) { + target_to_host_signal_table[tsig] = _NSIG; + count++; + } + } + + trace_signal_table_init(count); } void signal_init(void) From patchwork Wed Oct 18 23:31:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 735172 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1258544wro; Wed, 18 Oct 2023 16:33:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQKxet1s3J9NzZNg8pa/5P/nzsvp2krwgabCNeF/5fkBuZdfk1XvEyksRrU4AP9OlJ6PTk X-Received: by 2002:a05:6122:3d0d:b0:49e:1be5:de9b with SMTP id ga13-20020a0561223d0d00b0049e1be5de9bmr595154vkb.5.1697672008477; Wed, 18 Oct 2023 16:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697672008; cv=none; d=google.com; s=arc-20160816; b=SClUnK0KuwjlF1wWpPPwWozt/vsb1/aG08cRrBMrgP34vjP6Seqa8hV5ZqHWkNgu40 W9yICntsib23nQpO/37yamE7yD6sOCXETQwt4pAKawYlwkXJXFiKHCUzpkzQjKHeQnwg LbvA/X4DorHY8KJC4FnMoufY5ex66yeraP0e+8umotUh8GOeBTUDtd+0Fd/w353eoo59 c3TVwdpO3yMj/1eTllkH+7b0gyFEZYgjjUBS0O2nJIWOW/X1HV/mAuRbHHPidUugWiPr cXK93Lv1c5weZh5k6Cq1FxDfoNdsU/If99fDyYJpXGmFXd1AKti2dl9USluAAoJcADW0 Ib4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ypG+ldHB73o41Fm0bO8P6h70i3rbf+HtP65cG8LvxlI=; fh=wDljmxUHXfz9MGj2//jPHYRc53BMWF157v8rVKELrf4=; b=VLCdzknaimfpo8JFY6IGP2+Dc7QVGZhP4RgP311emvytMjmB0j2kn/Le+Ys+t7fCBl DBxRgPGkT4oYocEPZKDbb8rHEYKWRhqX/p8lKVZXtwqWhcmyxvuRy1Vj6q+uNoN2JFve Pgw36MJ9b6iRmiia/9wCbqa34CmGjFwunhqERC81bPJqWAkWqleVCv8XNICQ2z3/S9hs O8T+E3k/qe+mEFBT0DPdr97wN8g+BKdJQwdQTFv+EXbkamKL8zpI9CWbwwnvWJovYqjP /cODsFO95W6ZO9hmDPw0DIjVJJdSk5AiFwDBleA6fVs+AZuymOwOLzSE2rBfwjW8r2HY zRLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pzG5zr46; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m22-20020a05622a119600b0041b83bbd0eesi800757qtk.43.2023.10.18.16.33.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2023 16:33:28 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pzG5zr46; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG11-00046k-NV; Wed, 18 Oct 2023 19:31:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG0x-00045t-Hs for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:47 -0400 Received: from mail-oo1-xc2e.google.com ([2607:f8b0:4864:20::c2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0v-0000M3-T7 for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:47 -0400 Received: by mail-oo1-xc2e.google.com with SMTP id 006d021491bc7-57b5f0d658dso4313547eaf.0 for ; Wed, 18 Oct 2023 16:31:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671904; x=1698276704; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ypG+ldHB73o41Fm0bO8P6h70i3rbf+HtP65cG8LvxlI=; b=pzG5zr46atE5QdTXGfnCBd4stxYeKsXYGtFMl7A8ZcxYviExjTX8HwCKlrFZHyy1AM An25RFjTnbph3IrIkomaYHFjIFBLDrFrRDnCJmQb+rhOaRfAG2yGiUnFTLwHx9NVDx9s EoB7PfHaWcjHHnK9s4CZlMKy4pG/PuzFKf7jvvQ6GRW9RURkJrRea7r/z8YLj/zDrHfs b9tOuklMN80IlPKTM20/138fG0qWP+hPBJmwIxbFGIrUHdhp9WkqK77vxhi+aDYVWoye iGKhNCGA3J31YZ11rRDVnuig1pTIVw4g9fatPC+yz0KYtuDr4EWfj4+neApcpjPIf+ny /KiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671904; x=1698276704; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ypG+ldHB73o41Fm0bO8P6h70i3rbf+HtP65cG8LvxlI=; b=huRgmOl8U2DpvKbr2rksGBYlDU7rfvZZbMf8k0d0BKkwlQy0bF3rqK2yWNQMhYWjBR Xz4F5+ZmCc7LOmJR55ChtWw6i1XArRt6lIh5TzpFHaIoK53BcpJ02g6ob6KchThOgyzG eetAHwmZitSi1CwVWOo3lqSOG8WHo84O3D6Fn8w6O/jRWkup0Ro1CMBgGDnMqKw/ZMVE 5fXYO8F7jDqA+dUsNsnX4SgDexsiolpAD2JoxaAYd4snpXb/jUhkp4+3fsh7lpA5kT6d ctCUAZsllQKXwCg2wWbeIr26KPTQGep8UVUBU/+bX2Ef1REQpVVUVU+3xOKPfnWCEKxp D6EQ== X-Gm-Message-State: AOJu0YybdRJc/AhjxsuCsq257HTv9kIrtt0ypECm9QTlynrqQmKihRUw CHZfLgABzLE9RsOZPZLSaYTd+2xIhgbZg724qPI= X-Received: by 2002:a05:6358:ca6:b0:143:8084:e625 with SMTP id o38-20020a0563580ca600b001438084e625mr514122rwj.11.1697671904636; Wed, 18 Oct 2023 16:31:44 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 11/14] linux-user: Simplify signal_init Date: Wed, 18 Oct 2023 16:31:31 -0700 Message-Id: <20231018233134.1594292-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c2e; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc2e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Install the host signal handler at the same time we are probing the target signals for SIG_IGN/SIG_DFL. Ignore unmapped target signals. Acked-by: Helge Deller Signed-off-by: Richard Henderson --- linux-user/signal.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 653fd2f9fd..09840b0eb0 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -558,10 +558,7 @@ static void signal_table_init(void) void signal_init(void) { TaskState *ts = (TaskState *)thread_cpu->opaque; - struct sigaction act; - struct sigaction oact; - int i; - int host_sig; + struct sigaction act, oact; /* initialize signal conversion tables */ signal_table_init(); @@ -572,23 +569,28 @@ void signal_init(void) sigfillset(&act.sa_mask); act.sa_flags = SA_SIGINFO; act.sa_sigaction = host_signal_handler; - for(i = 1; i <= TARGET_NSIG; i++) { - host_sig = target_to_host_signal(i); - sigaction(host_sig, NULL, &oact); - if (oact.sa_sigaction == (void *)SIG_IGN) { - sigact_table[i - 1]._sa_handler = TARGET_SIG_IGN; - } else if (oact.sa_sigaction == (void *)SIG_DFL) { - sigact_table[i - 1]._sa_handler = TARGET_SIG_DFL; - } - /* If there's already a handler installed then something has - gone horribly wrong, so don't even try to handle that case. */ - /* Install some handlers for our own use. We need at least - SIGSEGV and SIGBUS, to detect exceptions. We can not just - trap all signals because it affects syscall interrupt - behavior. But do trap all default-fatal signals. */ - if (core_dump_signal(i)) { - sigaction(host_sig, &act, NULL); + + /* + * A parent process may configure ignored signals, but all other + * signals are default. For any target signals that have no host + * mapping, set to ignore. For all core_dump_signal, install our + * host signal handler so that we may invoke dump_core_and_abort. + * This includes SIGSEGV and SIGBUS, which are also need our signal + * handler for paging and exceptions. + */ + for (int tsig = 1; tsig <= TARGET_NSIG; tsig++) { + int hsig = target_to_host_signal(tsig); + abi_ptr thand = TARGET_SIG_IGN; + + if (hsig < _NSIG) { + struct sigaction *iact = core_dump_signal(tsig) ? &act : NULL; + + sigaction(hsig, iact, &oact); + if (oact.sa_sigaction != (void *)SIG_IGN) { + thand = TARGET_SIG_DFL; + } } + sigact_table[tsig - 1]._sa_handler = thand; } } From patchwork Wed Oct 18 23:31:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 735167 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1258425wro; Wed, 18 Oct 2023 16:33:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvSUPkNbftKrGDpxWNOi1xA1i7nD5+93lm3VdbWmkTyYMxeTMOJqkmJ9kFKDw44nElUEhp X-Received: by 2002:ac8:5795:0:b0:418:eee:15ed with SMTP id v21-20020ac85795000000b004180eee15edmr892154qta.64.1697671989414; Wed, 18 Oct 2023 16:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697671989; cv=none; d=google.com; s=arc-20160816; b=Slo9EqNSYMdVYCaXb3+zMyYeoSB+yYDfc4NCjSdMp+3+FNQHQinRqxLJDQfFhmRORN GOOcNEExAPkv0k6333eTCe5Oh1tuh+cfP+Uxdm+vrYYd51sL6uh3yhwu3qu6qiDZoNCi ZcnzgjD8t8gn8ZAo0zLLU3/NeJeRUGcIxF2U+CkTyAQUXiP1sdOd3r19drqGFLBSz1GV MBhsYkYfbBk253VmbiJmvM31V9tKgXJIq+kYV7ErnhGz+ncfiPaRMgHQLjJa7i5COHWq ID3yi5y7/RYlTHdfWpvnSp3TwJLhUYfVtRnFLUi3lbXkFUJF6M71ZY8N+4reJ5PoVSma BR5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4PntMv8xOvYf8PdCQHI22CCEWflquoH9lu0dCFWPneE=; fh=wDljmxUHXfz9MGj2//jPHYRc53BMWF157v8rVKELrf4=; b=R2voyGfysXVg0Uyh+DLdFS21ugCrlpZtbdc4Fb+xprh4FnCP0cMRojlAhufH1zU0Q7 lQs1TLe72v1IDTHoou2/JzCZGN44G8mq0pyXLmJ4Kvxr6dI4T7ilBKV/U7dNA5phL6Dc 1YLtpTOl/XfU1NfsdYuX6eFElNFlmNhO+fHtMX5qkL+n1/wBMXBGmLZC0wpKqPklpi0A PYJhhDlKKff9JcXNvIKI+pecGK9rf+EO4Ke7JFkV7iPd+lEos8yGKiH2lwkVntwOC2/B BHUISVd8m2Wpz4K+SxIujfi/AOXwmPehMJRDiAHU6FAKcm2y0hSI0Sz6K2bdOjQmHmiq c/+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EHpkRAMr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a9-20020a05622a064900b004008532ea2asi710359qtb.500.2023.10.18.16.33.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2023 16:33:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EHpkRAMr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG1F-0004Cv-96; Wed, 18 Oct 2023 19:32:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG0y-00046T-OS for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:48 -0400 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0w-0000MI-Sq for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:48 -0400 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3b2e330033fso1196305b6e.3 for ; Wed, 18 Oct 2023 16:31:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671905; x=1698276705; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4PntMv8xOvYf8PdCQHI22CCEWflquoH9lu0dCFWPneE=; b=EHpkRAMrXIwDT5FLR4LG8rtZMw0c8YHdDexUuwLo76lPyWswUW4RI+D9q2+INMSuzv XbYob9mc7unLq6AlKkOlECeGD0+QRfEWNGHig840fgsQ3AHGDAHAVQBJmuRjpo8TFV0p KpA+rs3YVPjG16NMk4pKGtwnDsLdjncbwh2+tDc+o3nzOMhm23Q5aExRlAohGFW+7dnx Bd0MbUg0cv0PqiQbyaLkaPkf7qNEHhVUDidKA1M8Zgs117mTC0P7jnd7oED/rWCemwlv TctX60RENhua3jtdFKhd8BAIRLxLVlWKeg1MPSt0U0REO3rRpT781w+L2MfS6l+Kh5xQ cI0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671905; x=1698276705; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4PntMv8xOvYf8PdCQHI22CCEWflquoH9lu0dCFWPneE=; b=TiGlJgHdcBQHzX5UiwHSiY1ossiz9VaA9/GhEg0PrTc5kLj5BiCLvXv5i9UDuBX0ek /+NGVHol1UDtKD9D5AqNPyrD5jZQ913ypMq4OoxG/CtHCwXUaxNjMcbCBGg2bktk77Cr fHUsWpX0WotrTuFihnzfp7u6mn9fGYPRlCv9IOU3xBMZ2RwfupWIR2SOMBaM7X+OodKz +VIOpj/R177YZUlquUX3sGmSQgT4jNFPXsj/C9BKvyttt4hDC9YcIkYgoBdgdGVQ53bY rhGo7qKdKmuVMfCcl05MKGSXmQMZcAspGXdzbzDDyqqcA+JgH/pZ/i7OXg0uabqU5Evd iQSQ== X-Gm-Message-State: AOJu0YzWtGhlLkBRJdJMpn868WHjWpC4VB746AIJVvee+pwqFechyYIJ USxka0ohZJNBLNG4vBdPXqz1DbBVXg6KYzvygI8= X-Received: by 2002:a05:6359:6317:b0:168:9100:d114 with SMTP id sf23-20020a056359631700b001689100d114mr377961rwb.21.1697671905327; Wed, 18 Oct 2023 16:31:45 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 12/14] linux-user: Split out host_sig{segv,bus}_handler Date: Wed, 18 Oct 2023 16:31:32 -0700 Message-Id: <20231018233134.1594292-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::234; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x234.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Make host_signal_handler slightly easier to read. Acked-by: Helge Deller Signed-off-by: Richard Henderson --- linux-user/signal.c | 145 ++++++++++++++++++++++++++------------------ 1 file changed, 85 insertions(+), 60 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 09840b0eb0..706b8ac7a7 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -811,6 +811,80 @@ void die_from_signal(siginfo_t *info) die_with_signal(info->si_signo); } +static void host_sigsegv_handler(CPUState *cpu, siginfo_t *info, + host_sigcontext *uc) +{ + uintptr_t host_addr = (uintptr_t)info->si_addr; + /* + * Convert forcefully to guest address space: addresses outside + * reserved_va are still valid to report via SEGV_MAPERR. + */ + bool is_valid = h2g_valid(host_addr); + abi_ptr guest_addr = h2g_nocheck(host_addr); + uintptr_t pc = host_signal_pc(uc); + bool is_write = host_signal_write(info, uc); + MMUAccessType access_type = adjust_signal_pc(&pc, is_write); + bool maperr; + + /* If this was a write to a TB protected page, restart. */ + if (is_write + && is_valid + && info->si_code == SEGV_ACCERR + && handle_sigsegv_accerr_write(cpu, host_signal_mask(uc), + pc, guest_addr)) { + return; + } + + /* + * If the access was not on behalf of the guest, within the executable + * mapping of the generated code buffer, then it is a host bug. + */ + if (access_type != MMU_INST_FETCH + && !in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { + die_from_signal(info); + } + + maperr = true; + if (is_valid && info->si_code == SEGV_ACCERR) { + /* + * With reserved_va, the whole address space is PROT_NONE, + * which means that we may get ACCERR when we want MAPERR. + */ + if (page_get_flags(guest_addr) & PAGE_VALID) { + maperr = false; + } else { + info->si_code = SEGV_MAPERR; + } + } + + sigprocmask(SIG_SETMASK, host_signal_mask(uc), NULL); + cpu_loop_exit_sigsegv(cpu, guest_addr, access_type, maperr, pc); +} + +static void host_sigbus_handler(CPUState *cpu, siginfo_t *info, + host_sigcontext *uc) +{ + uintptr_t pc = host_signal_pc(uc); + bool is_write = host_signal_write(info, uc); + MMUAccessType access_type = adjust_signal_pc(&pc, is_write); + + /* + * If the access was not on behalf of the guest, within the executable + * mapping of the generated code buffer, then it is a host bug. + */ + if (!in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { + die_from_signal(info); + } + + if (info->si_code == BUS_ADRALN) { + uintptr_t host_addr = (uintptr_t)info->si_addr; + abi_ptr guest_addr = h2g_nocheck(host_addr); + + sigprocmask(SIG_SETMASK, host_signal_mask(uc), NULL); + cpu_loop_exit_sigbus(cpu, guest_addr, access_type, pc); + } +} + static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) { CPUState *cpu = thread_cpu; @@ -822,73 +896,23 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) int guest_sig; uintptr_t pc = 0; bool sync_sig = false; - void *sigmask = host_signal_mask(uc); + void *sigmask; /* * Non-spoofed SIGSEGV and SIGBUS are synchronous, and need special * handling wrt signal blocking and unwinding. */ - if ((host_sig == SIGSEGV || host_sig == SIGBUS) && info->si_code > 0) { - MMUAccessType access_type; - uintptr_t host_addr; - abi_ptr guest_addr; - bool is_write; - - host_addr = (uintptr_t)info->si_addr; - - /* - * Convert forcefully to guest address space: addresses outside - * reserved_va are still valid to report via SEGV_MAPERR. - */ - guest_addr = h2g_nocheck(host_addr); - - pc = host_signal_pc(uc); - is_write = host_signal_write(info, uc); - access_type = adjust_signal_pc(&pc, is_write); - - /* If this was a write to a TB protected page, restart. */ - if (is_write - && host_sig == SIGSEGV - && info->si_code == SEGV_ACCERR - && h2g_valid(host_addr) - && handle_sigsegv_accerr_write(cpu, sigmask, pc, guest_addr)) { + if (info->si_code > 0) { + switch (host_sig) { + case SIGSEGV: + /* Only returns on handle_sigsegv_accerr_write success. */ + host_sigsegv_handler(cpu, info, uc); return; + case SIGBUS: + host_sigbus_handler(cpu, info, uc); + sync_sig = true; + break; } - - /* - * If the access was not on behalf of the guest, within the executable - * mapping of the generated code buffer, then it is a host bug. - */ - if (access_type != MMU_INST_FETCH - && !in_code_gen_buffer((void *)(pc - tcg_splitwx_diff))) { - die_from_signal(info); - } - - if (host_sig == SIGSEGV) { - bool maperr = true; - - if (info->si_code == SEGV_ACCERR && h2g_valid(host_addr)) { - /* - * With reserved_va, the whole address space is PROT_NONE, - * which means that we may get ACCERR when we want MAPERR. - */ - if (page_get_flags(guest_addr) & PAGE_VALID) { - maperr = false; - } else { - info->si_code = SEGV_MAPERR; - } - } - - sigprocmask(SIG_SETMASK, sigmask, NULL); - cpu_loop_exit_sigsegv(cpu, guest_addr, access_type, maperr, pc); - } else { - sigprocmask(SIG_SETMASK, sigmask, NULL); - if (info->si_code == BUS_ADRALN) { - cpu_loop_exit_sigbus(cpu, guest_addr, access_type, pc); - } - } - - sync_sig = true; } /* get target signal number */ @@ -929,6 +953,7 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) * would write 0xff bytes off the end of the structure and trash * data on the struct. */ + sigmask = host_signal_mask(uc); memset(sigmask, 0xff, SIGSET_T_SIZE); sigdelset(sigmask, SIGSEGV); sigdelset(sigmask, SIGBUS); From patchwork Wed Oct 18 23:31:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 735168 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1258429wro; Wed, 18 Oct 2023 16:33:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTMVYRURlmm9LMmz0WAi72WSf6B+n5pe8sCIJE5dOvuFRwb0FuwMkji8X2K27ePYTC/bv3 X-Received: by 2002:a05:690c:fc3:b0:599:da80:e1e6 with SMTP id dg3-20020a05690c0fc300b00599da80e1e6mr873855ywb.34.1697671989564; Wed, 18 Oct 2023 16:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697671989; cv=none; d=google.com; s=arc-20160816; b=kfAomXjEVEXC1iNt2YS9ZCKMrnWXS2zKdg3m5gFUEyOOlmmCvu7oEESL9MmyObSGJN s2WMiaPPJeLQgJnGD1O7rtwaxuxcIcEJ84DoP7iYZ9zNhnDSAfI3xNVSj0LbXnjP997Z eDAUZlVtij1OCw+uhNfx4AHuu4a9T/0GBjJ6l7dAQ45WNs1QsCOir7PTo/5xu9ZnpHV3 UdInsJSiBDfrLdjmR4BEFBc78X/VvdeS+Supd2KZ4C+53yJcdB6F9ItS9PC0wWLJF6ex iQn1WPhCjqI5bNeFzeg4wTZ+a95PYYzE7XrKcaIp8fQkHg1yfisAl6f22F4vchhq2YBt tExg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cPRrHvcXgvktiUIzW9SQzWI6+9vUxSTnLoJeJQFy4uw=; fh=wDljmxUHXfz9MGj2//jPHYRc53BMWF157v8rVKELrf4=; b=RKuD7VTFkGGcx3tbX68HiDdhbj80eTz3lpLh5oQ4xSMI86ivoyAc0EsN/mlLrW900N wKRXlNx8/7IjEjpxrCuDwF5lIQdjBn8tUpYTNb2jcnMJNdAmLGcyrlNrRcOTeB2uorDq Fd3CyO0Zcv4bJDsZOqNd0tueJtBvwhfKDsSdYSoY268B4Rmm4ZuxIKj5kMu9YusyVq+g Dmi0/njhuVNzabdSWcNkmx1VrCH577dTQDUws8zAR1V8M5Dc+/6OOX4ibpQrmHaCCH5j 6JdjcArRjJHNEKat1EzDs878U0SJbb+LZLPgwQcCrtpbytwthZsEHlcgeFEY+Hx3mBzy z05g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q4ftAnus; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w13-20020a05620a424d00b00767f226bc82si742622qko.315.2023.10.18.16.33.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2023 16:33:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q4ftAnus; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG1E-0004Co-Ua; Wed, 18 Oct 2023 19:32:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG0y-00046X-Ua for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:48 -0400 Received: from mail-oo1-xc2f.google.com ([2607:f8b0:4864:20::c2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0x-0000MQ-Ai for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:48 -0400 Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-5832ea25c7eso345589eaf.3 for ; Wed, 18 Oct 2023 16:31:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671906; x=1698276706; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cPRrHvcXgvktiUIzW9SQzWI6+9vUxSTnLoJeJQFy4uw=; b=Q4ftAnus3bAgnokg7B1JoaQSGGyy4MUj3ftVpw+YvnQ1Xh3v174V4bNxFYwyfLh4i5 N8xrR4CFTxjaC63y8PEuPxUOKl/bUygLWpjJSW4yNwaH234+yaNUvSOWiIatELQ4SKu3 HLUfrNuVamfY6eqZ3WglmQ+3SNYYSCRFE1WRxeLdTkQpuP4p17a7uxENbCNNwmrEdc4S 0EobzHA8O7EhGKCDZxd78y5RyxYy4LODTlQYnitThE39WrBENT8D/8Z9BJ/zE20YTACn ptINnIIFVgpd/qx5nbtDBr5hmWrUGfJ6DGimne7hVGNxgxZRYMDmFc9/7eu+yyW93doF sTPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671906; x=1698276706; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cPRrHvcXgvktiUIzW9SQzWI6+9vUxSTnLoJeJQFy4uw=; b=FGuRr+C3ioQe3XREZBLPnBvYtHobGNWuf1NSPgObyWDMR50XlnVMATIWNK6y8i5kse KwMO5EW1wVad3wdBdcXU1UUs3EQxIXwQMkTlX/QvgxX2ON0DyaV7tsBvt93ULoKHROlM NCsktZUotqwrUZV5noWbVVSRI/noQNDkm6AjWdM16AE9qNhY1hVNY5JRSkld35iDiAhc Jf4MzyhDioAE50TmJOC1bCJX1d4pRzL2dwgIIq1WTskxdniuTFOTgfwJcAHNdHG6Apdv 7Ub3ZPVlNoi13owzGJzDF11xw9+405Gp/1/JUmw6/EYxxkXywFP1ISXuP+X62Y47mNYP 1W+w== X-Gm-Message-State: AOJu0YwrGN1yO0UihF2DWoNdIQC8tniQJIQ1rwGZ6/AucE38eK9rZvtW SPLGGs7hYOo0BDiqg1vp5fahc+KVA3IAi1+HgkM= X-Received: by 2002:a05:6359:3110:b0:134:d806:69df with SMTP id rh16-20020a056359311000b00134d80669dfmr364662rwb.18.1697671906034; Wed, 18 Oct 2023 16:31:46 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 13/14] linux-user: Detect and report host SIGILL, SIGFPE, SIGTRAP Date: Wed, 18 Oct 2023 16:31:33 -0700 Message-Id: <20231018233134.1594292-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c2f; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc2f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org These signals, when not spoofed via kill(), are always bugs. Use die_from_signal to report this sensibly. Acked-by: Helge Deller Signed-off-by: Richard Henderson --- linux-user/signal.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 706b8ac7a7..b67077f320 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -796,6 +796,43 @@ void die_from_signal(siginfo_t *info) break; } break; + case SIGILL: + sig = "ILL"; + switch (info->si_code) { + case ILL_ILLOPC: + code = "ILLOPC"; + break; + case ILL_ILLOPN: + code = "ILLOPN"; + break; + case ILL_ILLADR: + code = "ILLADR"; + break; + case ILL_PRVOPC: + code = "PRVOPC"; + break; + case ILL_PRVREG: + code = "PRVREG"; + break; + case ILL_COPROC: + code = "COPROC"; + break; + } + break; + case SIGFPE: + sig = "FPE"; + switch (info->si_code) { + case FPE_INTDIV: + code = "INTDIV"; + break; + case FPE_INTOVF: + code = "INTOVF"; + break; + } + break; + case SIGTRAP: + sig = "TRAP"; + break; default: snprintf(sigbuf, sizeof(sigbuf), "%d", info->si_signo); sig = sigbuf; @@ -900,7 +937,8 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) /* * Non-spoofed SIGSEGV and SIGBUS are synchronous, and need special - * handling wrt signal blocking and unwinding. + * handling wrt signal blocking and unwinding. Non-spoofed SIGILL, + * SIGFPE, SIGTRAP are always host bugs. */ if (info->si_code > 0) { switch (host_sig) { @@ -912,6 +950,10 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) host_sigbus_handler(cpu, info, uc); sync_sig = true; break; + case SIGILL: + case SIGFPE: + case SIGTRAP: + die_from_signal(info); } } From patchwork Wed Oct 18 23:31:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 735171 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1258435wro; Wed, 18 Oct 2023 16:33:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFM6YJm5iFxuvF/hEZMo+MM3nidyJ0R/fxMoIqeZgjj2l/1HvL5BkNBuVrEjzT1/lYARdWW X-Received: by 2002:a67:b001:0:b0:452:db93:1ee3 with SMTP id z1-20020a67b001000000b00452db931ee3mr491940vse.30.1697671990196; Wed, 18 Oct 2023 16:33:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697671990; cv=none; d=google.com; s=arc-20160816; b=n99yaDN93XtmXml9zNwhkKjiSPiMS8aw5vNKyMVodk77dgy3hkfLEz3/rG3PJ5gQzi 2MQBoL3z6tm6poY/8ZSK638KAqQ4x7rxioHlR00li8s2TSxG3ech9qImsnXoFKW2wJaJ phNOzbDziohjOJp+KLda1dk1lCDk6m9hKKfiCtg8qX5K0VGX8M28QHYuUe1UOeaeaEOx 3yt+KaNYFTw/76n84nKqbxCifUkmbZiM8wrqKEYUa+s6eSjVTnZbk9cU+WrX2s6cXtAP oS76D47trV9rbB/yK++fOTjV420CHhZubhg0B+GoHKAp7cQt7eWnKLN6S5KVLssFelhU NEhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bnu9T106+3Frnuh9qTylVBrRrlFzWm5MBIT4IbQZiD0=; fh=wDljmxUHXfz9MGj2//jPHYRc53BMWF157v8rVKELrf4=; b=wLzc4eKXGOe9C4rZOThHBdofyDbCd8r/Vbg1SAccVH4LBl3icaGrormyKRexgs9akw OxRHcTl19TXDRtx6aV4Ctue7Eo6QQK+wr6iQu2ipxbSlQ+gPCDUm3ONZoDX29m2SRZ7+ iLlfbnN94n33lPsWoUi5+2i/iubmWZohWZoSCnzps3o7N7GrWKz1I129+9FLRdykysML 43D9O1ogO/XN/FHF0jJ1x79I8tSwCEpYHGODei5cutsObhqFnG7eAiw6aLQaSv7nXgsi dBkIvoz4f3JrXrWTVSaUgazOBdTjPsVZNsHVzZgKFprl07JJ56DL+sD4ACUPG33Lf6NI eFwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bGdIuMhR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id iw3-20020a0562140f2300b0066d10e104cdsi834712qvb.363.2023.10.18.16.33.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Oct 2023 16:33:10 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bGdIuMhR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtG1J-0004Ho-54; Wed, 18 Oct 2023 19:32:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtG10-00046n-7s for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:51 -0400 Received: from mail-oo1-xc33.google.com ([2607:f8b0:4864:20::c33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtG0y-0000Md-2O for qemu-devel@nongnu.org; Wed, 18 Oct 2023 19:31:49 -0400 Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-57be3d8e738so4161992eaf.1 for ; Wed, 18 Oct 2023 16:31:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697671907; x=1698276707; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bnu9T106+3Frnuh9qTylVBrRrlFzWm5MBIT4IbQZiD0=; b=bGdIuMhRHz4aRB7J3gowVA8JKknhwObHJvk3PnhzNtSGbGG7KzLc24hvke0P4pAf2k 3cLfROlbtFfXJiFZ2LG7FRYnrUlWOsknkN7CMnJMsaSfBj04gWiafeC/PqrQK/dLLdX/ LmeI6EEyt5KAi4IoeeFcDK9LXt7cs0d3L6p15IIO2QTrB5qT/sjT0xNsH7RiaY8jdtLv FkxDlY3r10F5EqU9Z8rf5GN7NVblkswi8bWySeI5PICer5wcy14UDW7nD4cB95JwnlCb P7MxmQf4+t5tqoSoOPgApiOXIbJqOJqHFdAqmx3QFeWRITPQX/BkDQztzudH4M/tBEUS 95tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671907; x=1698276707; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bnu9T106+3Frnuh9qTylVBrRrlFzWm5MBIT4IbQZiD0=; b=D+AE1z0xAHzpjnIl5F8eJJEpbTQiA/spqhqbZu3xyumHJ/xy4kUycJTCYysc46D6U1 tylO24+G8NL8E8dqSbverXBxyKVa3VccGxWtacaZukJyUMxIEt3bemPO5Y479ESif3X8 m2f58vpzMEzRjdP6z305JPFXTegmmP5xVlUe+OwwqSbLw3lk6leRd/fkooS+F0ATXQmJ jouhEkftdqNFMfSL3dp/1+Oe8ESegWK9yaEOxakKQ19Jb/eUPCRkf/cKBTOtBne3BGJK 2gvD3OSap6J/iAm1/bB/tDDv2ur/ScbmN0wduNEcbbipadowSKslVuH8BQCc2l1yCLzM Sgow== X-Gm-Message-State: AOJu0Yw6NuexBVOV8U6EDNVyRqaE3HaDKTded6aHLmJZyso5YVXSlcjR cJVXrxLDwnCVCsHtzZSUM90WnVf/3MbCNCCGBZY= X-Received: by 2002:a05:6359:5e18:b0:164:8d78:258a with SMTP id pw24-20020a0563595e1800b001648d78258amr419570rwb.20.1697671906794; Wed, 18 Oct 2023 16:31:46 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g9-20020aa796a9000000b006be5af77f06sm3881690pfk.2.2023.10.18.16.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:31:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 14/14] linux-user: Remap guest SIGABRT Date: Wed, 18 Oct 2023 16:31:34 -0700 Message-Id: <20231018233134.1594292-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018233134.1594292-1-richard.henderson@linaro.org> References: <20231018233134.1594292-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c33; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc33.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Distinguish host SIGABRT from guest SIGABRT by mapping the guest signal onto one of the host RT signals. This prevents a cycle by which a host assertion failure is caught and handled by host_signal_handler, queued for the guest, and then we attempt to continue past the host abort. What happens next depends on the host libc, but is neither good nor helpful. Acked-by: Helge Deller Signed-off-by: Richard Henderson --- linux-user/signal.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index b67077f320..3b8efec89f 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -522,8 +522,21 @@ static void signal_table_init(void) * multiplexed over a single host signal. * Attempts for configure "missing" signals via sigaction will be * silently ignored. + * + * Remap the target SIGABRT, so that we can distinguish host abort + * from guest abort. When the guest registers a signal handler or + * calls raise(SIGABRT), the host will raise SIG_RTn. If the guest + * arrives at dump_core_and_abort(), we will map back to host SIGABRT + * so that the parent (native or emulated) sees the correct signal. + * Finally, also map host to guest SIGABRT so that the emulated + * parent sees the correct mapping from wait status. */ - for (hsig = SIGRTMIN; hsig <= SIGRTMAX; hsig++) { + + hsig = SIGRTMIN; + host_to_target_signal_table[SIGABRT] = 0; + host_to_target_signal_table[hsig++] = TARGET_SIGABRT; + + for (; hsig <= SIGRTMAX; hsig++) { tsig = hsig - SIGRTMIN + TARGET_SIGRTMIN; if (tsig <= TARGET_NSIG) { host_to_target_signal_table[hsig] = tsig; @@ -539,6 +552,8 @@ static void signal_table_init(void) } } + host_to_target_signal_table[SIGABRT] = TARGET_SIGABRT; + /* Map everything else out-of-bounds. */ for (hsig = 1; hsig < _NSIG; hsig++) { if (host_to_target_signal_table[hsig] == 0) { @@ -582,13 +597,21 @@ void signal_init(void) int hsig = target_to_host_signal(tsig); abi_ptr thand = TARGET_SIG_IGN; - if (hsig < _NSIG) { - struct sigaction *iact = core_dump_signal(tsig) ? &act : NULL; + if (hsig >= _NSIG) { + continue; + } + /* As we force remap SIGABRT, cannot probe and install in one step. */ + if (tsig == TARGET_SIGABRT) { + sigaction(SIGABRT, NULL, &oact); + sigaction(hsig, &act, NULL); + } else { + struct sigaction *iact = core_dump_signal(tsig) ? &act : NULL; sigaction(hsig, iact, &oact); - if (oact.sa_sigaction != (void *)SIG_IGN) { - thand = TARGET_SIG_DFL; - } + } + + if (oact.sa_sigaction != (void *)SIG_IGN) { + thand = TARGET_SIG_DFL; } sigact_table[tsig - 1]._sa_handler = thand; } @@ -711,7 +734,12 @@ void dump_core_and_abort(CPUArchState *env, int target_sig) TaskState *ts = (TaskState *)cpu->opaque; int host_sig, core_dumped = 0; - host_sig = target_to_host_signal(target_sig); + /* On exit, undo the remapping of SIGABRT. */ + if (target_sig == TARGET_SIGABRT) { + host_sig = SIGABRT; + } else { + host_sig = target_to_host_signal(target_sig); + } trace_user_dump_core_and_abort(env, target_sig, host_sig); gdb_signalled(env, target_sig);