From patchwork Mon Feb 20 03:23:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655039 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcd:0:0:0:0:0 with SMTP id e13csp1179931wrc; Sun, 19 Feb 2023 19:25:07 -0800 (PST) X-Google-Smtp-Source: AK7set8+tWn9tfw571lzz7IDjzctIhA9WAmpwtLzzF5VuAAF8zuTSaqhJXc7sPk7Dm7tAERDZ5PH X-Received: by 2002:ac8:7d8d:0:b0:3b9:a641:aa66 with SMTP id c13-20020ac87d8d000000b003b9a641aa66mr11053305qtd.15.1676863507045; Sun, 19 Feb 2023 19:25:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676863507; cv=none; d=google.com; s=arc-20160816; b=Svhk/OKQ2ouE0K+n62gE/JCOF3ZR/vYWQKQB1F5maex3sdnCexgpEYHny/zWGBxLbd OCTLilrLTHVytkqks7xAemvhQNyhjeIi+qD1c3iifMg+v3u02oVcZM8Pe1rKIeTqUwxt iHDKzJztIgz2JVtIMIbmVq/wpwpGnopvmJhqP91A93cH+sC9vpKz5elP4OolB1mJTTlU +YZtOn4mHI3U8ajcIv6D1A5+pdetd6vOX+mxUWydSipKhUx0lZZkwuM3o6t5jkw2P03P Ze5jQpnNxMxvXFKPztPi2RhN5zVQEvEjVEAoW4v0UM1L4sAfsaUMG5m52Gy0PvhIcnLr s/Zg== 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=gmPWamcS039ttvGx+0lkOqlpPNASpmKk9ydxcZXcCPQ=; b=SpWg2EqJtXvToL8XrFc4Kz1Pe81nWEVk3IqDMDATdCxuQz0j3F0nOr81ZFDn7YlVz8 oocGWiztYF868TqkKaSYIGgUTPz73aj/MIQYoPRuWVgMZhM4x6Q1lQIaEKMLNpYC9Q4r 31m09qoh/Y8Qwc+vFIWd/flcZRD0JHgO4PFLSVE/C4NZpWdZgSskoNUGGYoc+LGmEBb5 zqIVm6jVQISjOA1IPswQHxiQgEqoOWxnuqaE4e7HT40Om0VFT+FUs8yuUjX4b74InmoZ 2SFf2vBENGDimpSgtGv9CY1ZIlN5rkiJUz9VmjgEqivQ7z1+aNT+g4soo0B1i6nCNwYX WxYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NqcROCFo; 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 6-20020ac84e86000000b003b82eb6578esi9325616qtp.138.2023.02.19.19.25.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 19 Feb 2023 19:25:07 -0800 (PST) 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=NqcROCFo; 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 1pTwmN-00019i-Bf; Sun, 19 Feb 2023 22:23:51 -0500 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 1pTwmL-00018v-7z for qemu-devel@nongnu.org; Sun, 19 Feb 2023 22:23:49 -0500 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pTwmJ-0005px-O4 for qemu-devel@nongnu.org; Sun, 19 Feb 2023 22:23:48 -0500 Received: by mail-pj1-x102f.google.com with SMTP id e13so1903631pjt.4 for ; Sun, 19 Feb 2023 19:23:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=gmPWamcS039ttvGx+0lkOqlpPNASpmKk9ydxcZXcCPQ=; b=NqcROCFoPy2d/NxUlGPdbaV3r1FHLet8VoX4MJnu0AjqJPDI5ChfBjIkP9/2sFqYEg OH9aNk+6QNLg0IVH38vdfLwjMXoVAhn8l6T725mlINHdXpVZSXFYeY788DCW9OqWwbXT QwvSWLNwEFgTfpDfrXIvcqnt3vwaSNwbeYIF9I9obPApQRrulukmBaeV35uGr8zl+cBB pSQvacDZ2dCLU792gYRYJHAxx7Rz0CxdRc4XokGKne5zva4zZKpIiAt/ka8Rp8eFF5fX 98sGX5RqdEP94mLrSfhQobQFx/r56jx3VtHOZ5kVUe2JS/RZItRoAvDAROZDp3Qnr5zj VpBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=gmPWamcS039ttvGx+0lkOqlpPNASpmKk9ydxcZXcCPQ=; b=fi5Yt/dGcIV5XIrOl0YYJn6GUAZDNVwRgKWfMTlimug/mCETHJP6sxpYSj3d1//5Th /mK38u6yYFUMn1GzWMi5rYGcGOddyd3aWoEE4x8MkyYp49K75PjdMbHkjej11Gac4YlQ ElW9VyNYkCY94e7SEsmThOiAbqVMc/0rM69xY9zFZomkPRfMSrBaUQMuNDz4m5/SdCJ/ GcCeIGzwlJNvYsZzqYj1YKUkKpqeHuGYNf92RiXNcAQO/5Hltn1HwUpPTGfHTUjk5aTF UdZK7ViqcSQdprqgkykzXXJtTqI2b+SNW1ZxyDgRfJCq4MQn/XS7wKooi3N8yFPpumoL izlg== X-Gm-Message-State: AO0yUKUeIjNRm2JbqJJnlXQ6mS68fezwnThANToIwff5YRySy0rQo3Qn IJyaFB5YSWKuZ70jHoH3nJsUbWHqG3LsIbxF7io= X-Received: by 2002:a17:902:d4c3:b0:19c:17d1:28a4 with SMTP id o3-20020a170902d4c300b0019c17d128a4mr412493plg.67.1676863426206; Sun, 19 Feb 2023 19:23:46 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id l11-20020a170902d34b00b00198e1bc9d83sm6621302plk.266.2023.02.19.19.23.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Feb 2023 19:23:45 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Sid Manning , =?utf-8?q?J?= =?utf-8?q?=C3=B8rgen_Hansen?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Subject: [PULL 1/7] accel/tcg: Allow the second page of an instruction to be MMIO Date: Sun, 19 Feb 2023 17:23:32 -1000 Message-Id: <20230220032338.5619-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220032338.5619-1-richard.henderson@linaro.org> References: <20230220032338.5619-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.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 If an instruction straddles a page boundary, and the first page was ram, but the second page was MMIO, we would abort. Handle this as if both pages are MMIO, by setting the ram_addr_t for the first page to -1. Reported-by: Sid Manning Reported-by: Jørgen Hansen Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/translator.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index ef5193c67e..1cf404ced0 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -176,8 +176,16 @@ static void *translator_access(CPUArchState *env, DisasContextBase *db, if (host == NULL) { tb_page_addr_t phys_page = get_page_addr_code_hostp(env, base, &db->host_addr[1]); - /* We cannot handle MMIO as second page. */ - assert(phys_page != -1); + + /* + * If the second page is MMIO, treat as if the first page + * was MMIO as well, so that we do not cache the TB. + */ + if (unlikely(phys_page == -1)) { + tb_set_page_addr0(tb, -1); + return NULL; + } + tb_set_page_addr1(tb, phys_page); #ifdef CONFIG_USER_ONLY page_protect(end); From patchwork Mon Feb 20 03:23: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: 655036 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcd:0:0:0:0:0 with SMTP id e13csp1179747wrc; Sun, 19 Feb 2023 19:24:33 -0800 (PST) X-Google-Smtp-Source: AK7set+mcbRhLfa7tCvm+JflVATmIGuhNh3R+sn0KtL7db+Hnqv2OwmIRnlmxXXUpsz3IwiyQTMh X-Received: by 2002:a05:622a:5:b0:3bd:1647:1601 with SMTP id x5-20020a05622a000500b003bd16471601mr20643234qtw.53.1676863473584; Sun, 19 Feb 2023 19:24:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676863473; cv=none; d=google.com; s=arc-20160816; b=IqPMZ6FMz5iKjx5oczfNX4rOm22TG2r7jtuaXAkPv0fIllyTTsws7tPvXJFKcEMU8+ Z7d2nbNcjm9oNRlM33DI1tpM/ObJYtpyBM+wURsNjddno9jaqeykaDSX0j0kA/v68FhV 9rdYUi7IiTlknNBPWtn+qIBiACByp86r8GOdwmzPx/pz9mi9eJ5gdkm9kIwtZyGHDxhv fmt+TDIR3mnlF0fFvmLJiJ0Aa+cG9lk6GEJJZx/chRoXnBDwUOugArU/53BvgC8Vh4dt 3DFIYTmzDWOkkQd7d/Vq5AFRIhLGOjPWc4gz+Gp+eouokye8fky8chnxhiiyIM5dpj+S Ts9w== 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=4zhGePcD91yQ6ch+7pxzLZ4Aayz4MXPEoGj6QOyVgUM=; b=Dx/wJG6MBPhFd8QUkDw4FdjNbzLOvj66CzLuvvgS0q0tH2ES37j/pGEHFDf8qxphPr Eqj7SzyyN58dVIxVGAr3dyfKsHjbkr7Atr1Ydj9xtkqsbK58KTUdRWL3UT8ohHwPwGZq qmPDH1YtBGL/gIUWu+BiWMPKz1Ikiy8v9gcSZNSWhzsEkB5Ajk9P3DDCzDZAkRWcaBRm s7V8yoXnjVVT+FirPqJyXekPvdCrBviDYZFsqHzIR2P89nvkIQzDXSsEnYwkFH2dNwpc xNTFfLozRZUIclZTcID9w6RmUxpEPSPVFcJmtA3zGNOyvu1waAZMKIUZW5wEXgJqvhwN PQlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k1iPuwWN; 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 s12-20020a05620a254c00b0072ee0cc8e5dsi8835638qko.455.2023.02.19.19.24.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 19 Feb 2023 19:24:33 -0800 (PST) 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=k1iPuwWN; 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 1pTwmO-00019k-Im; Sun, 19 Feb 2023 22:23:52 -0500 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 1pTwmM-00019Y-RY for qemu-devel@nongnu.org; Sun, 19 Feb 2023 22:23:50 -0500 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pTwmL-0005q9-DB for qemu-devel@nongnu.org; Sun, 19 Feb 2023 22:23:50 -0500 Received: by mail-pl1-x636.google.com with SMTP id l15so1047359pls.1 for ; Sun, 19 Feb 2023 19:23:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=4zhGePcD91yQ6ch+7pxzLZ4Aayz4MXPEoGj6QOyVgUM=; b=k1iPuwWN05dCebnyza/8iKydDRbNtnylTmzUoMu/7cBwmY2XaQuwYPx49P7cBGxXk4 kK6d/Zv2KXyFCexiJs5Zi4PW+8Bi3I8vPLlDzNrCaM4d8OgJSUxeBbBRo57qoBScswHw Fm5uhGTD2AKoWSvABq77cLDJYH+PRlnsOg3WsTKMJTqDrGE6sNGmOXRajAwp+p6b5nIx bNJR2CEukN8AIKGuQgEf7euxMZjiHxsVI8d237BLPTZBQCR9HPSKH94fmoGWLJZ8glNv Yby83iy0HqLP7fUFmHU9xqiK/Je1NpnFbeXPWgHtB6R27yYOfHMekEhVsc49ocAjKaTn YL6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=4zhGePcD91yQ6ch+7pxzLZ4Aayz4MXPEoGj6QOyVgUM=; b=P5MsLMomqy49wlgQfznQXc2c8zhkNL009+Cd+UskYzGucanDhD6PXKyimA0tMbv4rS zUFTvhKEhaKQ2GuvpHP+lvrEbX/A8xhSrjGvQJjvitnX6rG/1ZFli8bHe8n43ULs3Wcy 1+1ETq0B/ZF+VuOncDZenjc06XKGHv+OlNMeaV3vMPx2aGTxI1k/PQGXwPxM8GNBqLSL z2AYlTdtHAoSXf/1IdrmvNrUSaUyjMTfwqlLQqbujV8Pk9q1MsZYow8/2ZIxF1RSeNZ2 Lk2RHmnRUDNKO2Djg6gK1SX6sbaXjSOxoLsP61HFQxlRgaPha10jyW4APAUE9rYz1vxQ R+OA== X-Gm-Message-State: AO0yUKUdI8OYB8EdVzEnf9JVeeHHVwOEVJs45aRHaTmaxf8ER089gHK3 tRR/QKrRBJbhhTceanxNc6Wsmt+ipwcM1m3I1gk= X-Received: by 2002:a17:902:d502:b0:194:a531:4b39 with SMTP id b2-20020a170902d50200b00194a5314b39mr1670980plg.67.1676863427727; Sun, 19 Feb 2023 19:23:47 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id l11-20020a170902d34b00b00198e1bc9d83sm6621302plk.266.2023.02.19.19.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Feb 2023 19:23:47 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Ilya Leoshkevich Subject: [PULL 2/7] linux-user/sparc: Raise SIGILL for all unhandled software traps Date: Sun, 19 Feb 2023 17:23:33 -1000 Message-Id: <20230220032338.5619-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220032338.5619-1-richard.henderson@linaro.org> References: <20230220032338.5619-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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 linux kernel's trap tables vector all unassigned trap numbers to BAD_TRAP, which then raises SIGILL. Tested-by: Ilya Leoshkevich Reported-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- linux-user/sparc/cpu_loop.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c index 434c90a55f..c120c42278 100644 --- a/linux-user/sparc/cpu_loop.c +++ b/linux-user/sparc/cpu_loop.c @@ -248,6 +248,14 @@ void cpu_loop (CPUSPARCState *env) cpu_exec_step_atomic(cs); break; default: + /* + * Most software trap numbers vector to BAD_TRAP. + * Handle anything not explicitly matched above. + */ + if (trapnr >= TT_TRAP && trapnr <= TT_TRAP + 0x7f) { + force_sig_fault(TARGET_SIGILL, ILL_ILLTRP, env->pc); + break; + } fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr); cpu_dump_state(cs, stderr, 0); exit(EXIT_FAILURE); From patchwork Mon Feb 20 03:23:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655037 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcd:0:0:0:0:0 with SMTP id e13csp1179820wrc; Sun, 19 Feb 2023 19:24:46 -0800 (PST) X-Google-Smtp-Source: AK7set8ZZSvbGmBcmbJO4XLbewtUWkZLdFlFk1ZbwwG5lGkxRlMEz6JncbRhDXrWs0weDiKV8OsR X-Received: by 2002:a05:622a:14c9:b0:3b9:b6b7:90c5 with SMTP id u9-20020a05622a14c900b003b9b6b790c5mr11648014qtx.49.1676863486048; Sun, 19 Feb 2023 19:24:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676863486; cv=none; d=google.com; s=arc-20160816; b=QywXvEihR955gkwbuu7WN7FozE81iFSS+rVfYlEAdgKHxmyppYsAucU/3QIlA84f12 Op4D4rzg815E8Uzq66utOgFiePaisD8fXm/jbYMM2/ALHUHxbqgfds5crF6kzX9sJuy5 LVQ1x3cgs37hMO/nr2vGAVQ3m+bziOOFYv4TzwGYJtXCqm0RlZX3U5jedz7Upjb7fNlw Fk9gWcCr2urynvq7CzOt0fEQdqf+rA8GWcj9vj9db7+GLz3rwgcH4XYpTSesJmINJcOj XqGsZh4tcXyc2TYqRur32KczEWC446sUvAt+8wmAnkK1bxAWQCNaOftcpgH1iXHfxEzP 4RfA== 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=nN1Nd19UG7Ob6HhOyu1ZExnb36Rzel7CeIAQhipYNRY=; b=eJyrWliC3z39aUzqlfyeHF2KNYQ6AFUdrgSr2NvUoUQEhLRPNZu7ypzaaE6wbmUYTX mJIRHlhnKqH0nVmdYQiUBqcXpU07qUIHr5PxUWHy/OsUxGlF4PKt9MNLJnNgckgkoeMi NWBXtWm6EZZZ1PlxcsWnSOAnQwkKpVXqQ0lhtVsi85p7HuOgaqZsDmt/xY+KkWShEf03 +Sd12O8I4bzj4ZtWRCnWp2PDZyRQRufiSBJaqxvrn+s/j+ctWsppQlHI7jiW3Dw8F9rn gO9zo7H1jDSL0NEY2TFmVyCm+IPi4R9DY+kRHhlJVWmkjqBHLTfcFdiegQWceQzhBI5j 22uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fR9XRr4a; 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 c23-20020a05620a269700b006f9fee8e4acsi9240050qkp.399.2023.02.19.19.24.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 19 Feb 2023 19:24:46 -0800 (PST) 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=fR9XRr4a; 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 1pTwmQ-0001AI-9J; Sun, 19 Feb 2023 22:23:54 -0500 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 1pTwmO-00019l-M7 for qemu-devel@nongnu.org; Sun, 19 Feb 2023 22:23:52 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pTwmN-0005qL-3Y for qemu-devel@nongnu.org; Sun, 19 Feb 2023 22:23:52 -0500 Received: by mail-pl1-x62d.google.com with SMTP id c1so139948plg.4 for ; Sun, 19 Feb 2023 19:23:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=nN1Nd19UG7Ob6HhOyu1ZExnb36Rzel7CeIAQhipYNRY=; b=fR9XRr4aNnBEzUwKGFljBa/TFdtHOOxXFEpFQGezrIiyixPeLrgNFCraGA/ZxJvPT9 7KsrmWnc70go2jxy9Qmy8DxeODDfdtFUP5H5ehl8bhdvg9ei7IOYkS1v2bOk2LBGxSqO TnYL91VOUjWZ9+41VkWpXr/V//7dOBWuCPFGB9n+XEG2QKw+zOSb66WD0DNW4OjKvYp2 oULPe3fKdw/yJ0TsdHXRXdntXypTW5gQ5ydUMUtoBInzrXJVxfArffisrcxvVzMG+aZa tnc5KKeEvv8p/8BQ46dhicvix2RyHZE6mhaIyyEQ3+v7gQnntJ+NcSQ+PNAYlbl7qnu0 85Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=nN1Nd19UG7Ob6HhOyu1ZExnb36Rzel7CeIAQhipYNRY=; b=pWc6UhfwonEVH3x6TKArs2IcrLcmxM5YW1YCTgBni5s9d0m7ypgoroCM+DvTxAKgoQ B7isZ/DP3YMmNq7kLgR09iErAXr6CcP2JCSzbR3POugFjBws1D++73GdRoNk18ndeh/W 7SEpQy6j+BcUFHycBhhGXpafPUcx1gwP0H5IE29cKAgJLd33+qgpFM3kEAGm142hZ48+ AFlbhR01I4FgVJs4AgOFVoXIfrD7RYZNcAYuuVpn5abjwDRW+tBSY1/pWPUw2kr3TcJp AVmw4jdJczBXdEwC846JVbExYV+Playx9HyRyDBV6QFIeXA0oUthE8OfnzeCi2oa+4su x4HQ== X-Gm-Message-State: AO0yUKXNsATHRaFZqL1a7MnsEeZl6jLR7YOxI52AZvGNS9TQJvEpPCoM 4tqMvW2BsspyFkNGKOH0eooJudLb+V1zrAO3R94= X-Received: by 2002:a17:902:cec1:b0:199:2f0a:697 with SMTP id d1-20020a170902cec100b001992f0a0697mr2404580plg.33.1676863429612; Sun, 19 Feb 2023 19:23:49 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id l11-20020a170902d34b00b00198e1bc9d83sm6621302plk.266.2023.02.19.19.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Feb 2023 19:23:49 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Ilya Leoshkevich , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 3/7] linux-user: Always exit from exclusive state in fork_end() Date: Sun, 19 Feb 2023 17:23:34 -1000 Message-Id: <20230220032338.5619-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220032338.5619-1-richard.henderson@linaro.org> References: <20230220032338.5619-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Ilya Leoshkevich fork()ed processes currently start with current_cpu->in_exclusive_context set, which is, strictly speaking, not correct, but does not cause problems (even assertion failures). With one of the next patches, the code begins to rely on this value, so fix it by always calling end_exclusive() in fork_end(). Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée Signed-off-by: Ilya Leoshkevich Message-Id: <20230214140829.45392-2-iii@linux.ibm.com> Signed-off-by: Richard Henderson --- linux-user/main.c | 10 ++++++---- linux-user/syscall.c | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 4290651c3c..4ff30ff980 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -161,13 +161,15 @@ void fork_end(int child) } qemu_init_cpu_list(); gdbserver_fork(thread_cpu); - /* qemu_init_cpu_list() takes care of reinitializing the - * exclusive state, so we don't need to end_exclusive() here. - */ } else { cpu_list_unlock(); - end_exclusive(); } + /* + * qemu_init_cpu_list() reinitialized the child exclusive state, but we + * also need to keep current_cpu consistent, so call end_exclusive() for + * both child and parent. + */ + end_exclusive(); } __thread CPUState *thread_cpu; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 1e868e9b0e..a6c426d73c 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6752,6 +6752,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, cpu_clone_regs_parent(env, flags); fork_end(0); } + g_assert(!cpu_in_exclusive_context(cpu)); } return ret; } From patchwork Mon Feb 20 03:23:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655040 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcd:0:0:0:0:0 with SMTP id e13csp1179941wrc; Sun, 19 Feb 2023 19:25:08 -0800 (PST) X-Google-Smtp-Source: AK7set+n3ybmP/JAKUpO2BDWNh7TMMS+FJU/xEi8MZPxCy3E/KCDifmbjhYQRxwSUkRqC4jl4zQf X-Received: by 2002:a05:6214:e8d:b0:56e:a4c5:9d9d with SMTP id hf13-20020a0562140e8d00b0056ea4c59d9dmr1305116qvb.22.1676863507871; Sun, 19 Feb 2023 19:25:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676863507; cv=none; d=google.com; s=arc-20160816; b=DxWLSbjlnI6Olb5wrD3UjRSKqafvkw/a8eM0ImxMz20pAqTiVKurAMSUouhxRGxZYN DdgTVqvB2kjJQjleG/7kIJZxqivlYBkjmqwQCVG/vqfwzdBMRY4q4eMTG7A2ent2R+UD nhD8a1LNr+/Hihou54Enk3mJTtKTleOJDDo8S0S7FzB6uLUXvC8jlwn+3QV3eqrjTzz4 PSwurhujZDHlao2KZD8w2YHYCRJKQaukmS0Hx+DtjaIF+Fv65JZQWuMJjcXl1O2iUh75 Sn+TFqKDu+I/goAovyqFaQMfnGIUQoilDhYO5ZGTBN2S9bqRYqPP4RjX6jk/Dlquk50V aSlw== 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=zxPSc8yJkvzSaYSSEPoT7SrrtEyyDZGvKalhQ2ISznU=; b=RbySFEyO5u6NT1JRWMpoMGQ2n49TaHI5whvGFHwvqniyb2NXqOxVc1MwmU1gykPcmq kk3tVHJCJj/doZCXsITpKfNc7ufYsuHjF4/KZ4ty/jJbMRWihi9S16Y5pBqAKQogjsGb p8yEjehEjQc7eYHBJ3bAcLjw2eOyGdlYSII7cw8lD7DFz6Riby8F9iBM/Z4SkhkRWQR7 nymgUSwfdjAFrRnL/3zj/90uHGsDZtj/ht6K9DSPCrzii0te5tLtIeTegybfr5uIsTKe 7uQ5CDac/MSRsvGvwQK7q3Ks194AhY0eporLeC8rWZ9s8npQlVNzAq2n3pXO7Lo9YUBk nfjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xQGOdQE5; 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 u20-20020a0cf1d4000000b0056c21051f0fsi1038286qvl.592.2023.02.19.19.25.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 19 Feb 2023 19:25:07 -0800 (PST) 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=xQGOdQE5; 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 1pTwmQ-0001Ae-S0; Sun, 19 Feb 2023 22:23:54 -0500 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 1pTwmQ-0001AH-6c for qemu-devel@nongnu.org; Sun, 19 Feb 2023 22:23:54 -0500 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pTwmO-0005qc-LZ for qemu-devel@nongnu.org; Sun, 19 Feb 2023 22:23:53 -0500 Received: by mail-pj1-x102f.google.com with SMTP id mg17-20020a17090b371100b00229ca6a4636so1934943pjb.0 for ; Sun, 19 Feb 2023 19:23:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=zxPSc8yJkvzSaYSSEPoT7SrrtEyyDZGvKalhQ2ISznU=; b=xQGOdQE5fjPXJrAl15obpcT+Dgg1sPFXqIEvHnJO8MkhAbUaOyIuULsufGFGNzb0We 3bB/wL0B824828RnIJ8jN8ITQ1lMJh/rZJ1MoyUA14UuGGZLCHDJEQ36lOmfLZAQWue5 FhyZW/rK5irkVE8l2VXS67g++Ep+kgy3G3Jx9bVwBbUMDNncV0dVXo2XuoFqvA3Hd54/ dBEyZVpB1xOgAo33AvgwcEmGrk4rTatX+56SQMASmtrGTrdolKlV9tYA6yZCNxmnYc/+ m/nkPzQSQuoMzAxnR33yKPaOOchJyiju+mGO5HyGc47c/O5ZcHh1YjyTVAqQhQ26Xdl4 MjWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=zxPSc8yJkvzSaYSSEPoT7SrrtEyyDZGvKalhQ2ISznU=; b=HAHXqgKDyRcaJJe4WYetchKlH9YVxeFYIg9QG+CTmkSmw9890XE7ODI4WK1ybxIOsb uqqg31en/EJjLWcczk6lHKreWeq1O8I2hPJV+XpeYJ6pLezRfCvIM410ES6RVQkUJxcP 26Sa7ol5wy+nh9LFl4OGJqgZkdFM+zVe/d73ICpueuciQBuCx/quSPgTze1kIw3wJ21P VsONRokk86v/sGCSllYw9UDMxkjqEGRVoAs1ABUsX+JQ8x6pSmYb1HbbpEdLd0Vdgr9G xg4e3SDRNiwchjVveKpLrrJHpd7SC5aLHX34gokhPumiYgYyUZ4KYX2oaFNARpMcK5Kz Sj+A== X-Gm-Message-State: AO0yUKUhgtUvDKK0HfKQZ33iBeQyS+g4R91GwvZPRUMHDqOcxP+/qash YeomEf6EaOad/3AlMyOPCXkLjXHf8oxcF1JkjSM= X-Received: by 2002:a17:902:fa86:b0:19a:66bb:698f with SMTP id lc6-20020a170902fa8600b0019a66bb698fmr1637631plb.58.1676863431253; Sun, 19 Feb 2023 19:23:51 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id l11-20020a170902d34b00b00198e1bc9d83sm6621302plk.266.2023.02.19.19.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Feb 2023 19:23:50 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Ilya Leoshkevich , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 4/7] cpus: Make {start,end}_exclusive() recursive Date: Sun, 19 Feb 2023 17:23:35 -1000 Message-Id: <20230220032338.5619-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220032338.5619-1-richard.henderson@linaro.org> References: <20230220032338.5619-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.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: Ilya Leoshkevich Currently dying to one of the core_dump_signal()s deadlocks, because dump_core_and_abort() calls start_exclusive() two times: first via stop_all_tasks(), and then via preexit_cleanup() -> qemu_plugin_user_exit(). There are a number of ways to solve this: resume after dumping core; check cpu_in_exclusive_context() in qemu_plugin_user_exit(); or make {start,end}_exclusive() recursive. Pick the last option, since it's the most straightforward one. Fixes: da91c1920242 ("linux-user: Clean up when exiting due to a signal") Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée Signed-off-by: Ilya Leoshkevich Message-Id: <20230214140829.45392-3-iii@linux.ibm.com> Signed-off-by: Richard Henderson --- include/hw/core/cpu.h | 4 ++-- cpus-common.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 2417597236..671f041bec 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -349,7 +349,7 @@ struct CPUState { bool unplug; bool crash_occurred; bool exit_request; - bool in_exclusive_context; + int exclusive_context_count; uint32_t cflags_next_tb; /* updates protected by BQL */ uint32_t interrupt_request; @@ -758,7 +758,7 @@ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data */ static inline bool cpu_in_exclusive_context(const CPUState *cpu) { - return cpu->in_exclusive_context; + return cpu->exclusive_context_count; } /** diff --git a/cpus-common.c b/cpus-common.c index 793364dc0e..39f355de98 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -192,6 +192,11 @@ void start_exclusive(void) CPUState *other_cpu; int running_cpus; + if (current_cpu->exclusive_context_count) { + current_cpu->exclusive_context_count++; + return; + } + qemu_mutex_lock(&qemu_cpu_list_lock); exclusive_idle(); @@ -219,13 +224,16 @@ void start_exclusive(void) */ qemu_mutex_unlock(&qemu_cpu_list_lock); - current_cpu->in_exclusive_context = true; + current_cpu->exclusive_context_count = 1; } /* Finish an exclusive operation. */ void end_exclusive(void) { - current_cpu->in_exclusive_context = false; + current_cpu->exclusive_context_count--; + if (current_cpu->exclusive_context_count) { + return; + } qemu_mutex_lock(&qemu_cpu_list_lock); qatomic_set(&pending_cpus, 0); From patchwork Mon Feb 20 03:23:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655038 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcd:0:0:0:0:0 with SMTP id e13csp1179855wrc; Sun, 19 Feb 2023 19:24:52 -0800 (PST) X-Google-Smtp-Source: AK7set/MBMJdeqDZ6c3jxulG4DcWzf0AGltvnm3HNP/BYizWg03A1YSpViZ2yYj5un53QJHFdxmu X-Received: by 2002:a05:622a:1821:b0:3b8:683c:40f with SMTP id t33-20020a05622a182100b003b8683c040fmr12257326qtc.30.1676863492575; Sun, 19 Feb 2023 19:24:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676863492; cv=none; d=google.com; s=arc-20160816; b=fdz2lzr/RdrFJAajbHdJyw6qUa1QQQmmivDuHy+QWJR5gGp2JDfi/JJHZsK5TmKE6B gS/S8h83wBEFkGeou+C/kxRsEst0HMZ76UH7naJeF9F1caChnJ2nb9JSEe7uLCWmFI3Y hiYxGhlaOOcFZ18RpmNDj+usbCvB5H63827bAjOETNuFqBvcbb8CTnAsc7iPvXvFWx8c zXVY3OA4PRWbhtnMuIQW/Nndj9pBg6hgJ8srQbhCfMP0wUwLrGEIix/t6nLN3veTAgpK Ydb3t/O1Dm/WTJsQ9dfrKG7q3zvsRMfl85nTVyVRQ6V3CWPyqLCVFHpd3eociiGDb7eo L8nQ== 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=JKMBaWZBGONH22d4GZ6aoQ5NI2bVoqwHKZG9lz4sA9s=; b=CvqyBAjVU7CbvVDkOFgSTO2Hcy8WiyMOjhIYFaLliYIQo6DPozmYsr46jYyT29CIjh SIh828TqX7P04WrApMcmd9QStFt1h4UKx9GNUz3X7YA4zi2/y13rd4+6FARWml2SHJAe qc28YozO4DdfI5mkyq00jdI+s2MFFOMcHFaZ0SsKw4UXn40SuP1SLy58FBwqmg/M5MAq 9xTMl3A+MtvgU8Lri3AhOuq2xV5taPD+jstWu7+VEMP6I/9BKi0/OGtGjg9oDrC4nmhL XxQrO58hzUYmWVuRtUJMXVd7+8O2fm3CoLD+c7hrzHPDKEnpSHGqQoh42bB3ogKTuBIy 5jHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YzdR1yc1; 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 i123-20020a378681000000b0073b398bbf98si8220680qkd.129.2023.02.19.19.24.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 19 Feb 2023 19:24:52 -0800 (PST) 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=YzdR1yc1; 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 1pTwmT-0001BK-KX; Sun, 19 Feb 2023 22:23:57 -0500 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 1pTwmR-0001Av-SS for qemu-devel@nongnu.org; Sun, 19 Feb 2023 22:23:55 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pTwmQ-0005qm-9T for qemu-devel@nongnu.org; Sun, 19 Feb 2023 22:23:55 -0500 Received: by mail-pl1-x62d.google.com with SMTP id q9so2040325plh.6 for ; Sun, 19 Feb 2023 19:23:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=JKMBaWZBGONH22d4GZ6aoQ5NI2bVoqwHKZG9lz4sA9s=; b=YzdR1yc1S5JYXOoNhpa9IxLl+hTme/WPpNSeOnX7jn5L+WlEW8z0cGhTh2AuSU9Lmx /ZelLEGc27P7c6edAhagPR/pkuTg+BKXPdiE7nTfhHI94SBIIk4m4eeFhI7gP7i8sic4 h+k8Iuvq8AgaSuEUTGNHVZOr9Z30O5Vhp6FaIX3j4WqFvK+Za/PV6Y6pQanEfgS+ZKjX VSx5m4X+h2KdUuDWrqzP66WT/+hhB4Dn3BArk7J/VT7gq3Z5PmSeM8k9BMo8Yv02u3f4 z7Qx/pljY+BH4si1CMbT7RYzXbXeNFzVV+6rE8b/OHFzj3vmrb48zTGoqpumSOosOLZ5 X3+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=JKMBaWZBGONH22d4GZ6aoQ5NI2bVoqwHKZG9lz4sA9s=; b=f6Xp1cfb8LyE8kW67fy5VR3vEJwLqyj3RVss7Pi9ekLiNvNfCGlnAxJdYFF6LdmMx6 2o9RdgSo8FFGE5enj7qE1SIdwIEX53PMj3iWs5PhmF0FodfwGhskvGD6Hd8cO6/TITEo KWvS79+Jt245M/RrXvciduEFI0jugxr+1Bn4PTWPxnd8l1/dbHG+wfWLoWFIig0YJQI2 ZAkPZagMQNLvGM3m5Z35GLIflPmVAuZ24K6n3WDjpmYd07FESgVlfsE/OfFhRYmG5d8y XuCzrVmbFWSLpoLvaYXOX7nFNGa8nvbSfTLygWCKfFJ9jRIkVxdYjFlMHBzp7j6hsmzK d9aQ== X-Gm-Message-State: AO0yUKWQ0VJSjRDuO4kXGMrUIbJogLjlN220OsIdVKZ0B3mqwbMC7uTd jN8zkk07N18bdp4AlXq4RE/57bQtk1N21UY0V28= X-Received: by 2002:a17:903:790:b0:196:f00:c8f9 with SMTP id kn16-20020a170903079000b001960f00c8f9mr2348490plb.10.1676863432905; Sun, 19 Feb 2023 19:23:52 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id l11-20020a170902d34b00b00198e1bc9d83sm6621302plk.266.2023.02.19.19.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Feb 2023 19:23:52 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Ilya Leoshkevich Subject: [PULL 5/7] linux-user/microblaze: Handle privileged exception Date: Sun, 19 Feb 2023 17:23:36 -1000 Message-Id: <20230220032338.5619-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220032338.5619-1-richard.henderson@linaro.org> References: <20230220032338.5619-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Ilya Leoshkevich Follow what kernel's full_exception() is doing. Reviewed-by: Richard Henderson Signed-off-by: Ilya Leoshkevich Message-Id: <20230214140829.45392-4-iii@linux.ibm.com> Signed-off-by: Richard Henderson --- linux-user/microblaze/cpu_loop.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/linux-user/microblaze/cpu_loop.c b/linux-user/microblaze/cpu_loop.c index 5ccf9e942e..212e62d0a6 100644 --- a/linux-user/microblaze/cpu_loop.c +++ b/linux-user/microblaze/cpu_loop.c @@ -25,8 +25,8 @@ void cpu_loop(CPUMBState *env) { + int trapnr, ret, si_code, sig; CPUState *cs = env_cpu(env); - int trapnr, ret, si_code; while (1) { cpu_exec_start(cs); @@ -76,6 +76,7 @@ void cpu_loop(CPUMBState *env) env->iflags &= ~(IMM_FLAG | D_FLAG); switch (env->esr & 31) { case ESR_EC_DIVZERO: + sig = TARGET_SIGFPE; si_code = TARGET_FPE_INTDIV; break; case ESR_EC_FPU: @@ -84,6 +85,7 @@ void cpu_loop(CPUMBState *env) * if there's no recognized bit set. Possibly this * implies that si_code is 0, but follow the structure. */ + sig = TARGET_SIGFPE; si_code = env->fsr; if (si_code & FSR_IO) { si_code = TARGET_FPE_FLTINV; @@ -97,13 +99,17 @@ void cpu_loop(CPUMBState *env) si_code = TARGET_FPE_FLTRES; } break; + case ESR_EC_PRIVINSN: + sig = SIGILL; + si_code = ILL_PRVOPC; + break; default: fprintf(stderr, "Unhandled hw-exception: 0x%x\n", env->esr & ESR_EC_MASK); cpu_dump_state(cs, stderr, 0); exit(EXIT_FAILURE); } - force_sig_fault(TARGET_SIGFPE, si_code, env->pc); + force_sig_fault(sig, si_code, env->pc); break; case EXCP_DEBUG: From patchwork Mon Feb 20 03:23:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655042 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcd:0:0:0:0:0 with SMTP id e13csp1180017wrc; Sun, 19 Feb 2023 19:25:23 -0800 (PST) X-Google-Smtp-Source: AK7set9AnBKJRw0ItzYCrbKFqCPHUovLqs9Iv8eJc6v0D7mXCHF25xp05siSoo7aU+brMDXv1I/i X-Received: by 2002:a05:6214:b6d:b0:570:7026:2a19 with SMTP id ey13-20020a0562140b6d00b0057070262a19mr4846834qvb.36.1676863523201; Sun, 19 Feb 2023 19:25:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676863523; cv=none; d=google.com; s=arc-20160816; b=0GDIIyAQ8F1gkqvVf3mVSENpj0FkT4/gr4P/Q7yerzjA0+IMomc9q9Xbp4R+hgcJjd H4Wt2BaLZzrc3VB0tlyJKczvyXI49bwg5mcsD3NC91IJJR9OLUYo4BlSnwzGUvB+aahx pxpUhGwPHUH/5zHieDkd36JFCDZEnNo7lhhhteah1cNOGpkgJcAcwz8HLW6zK9J6r8+D 7X8zzfldRIJFnU+/UOYvlwhO9ub1AVRPHJmqThtD18zZNeyUpXZrcOD6iaOGEgyX4gYJ K2S4KRrjAsmM8trISavjzm3lzmJOUg8PE/QFJWHc5usbgWhkC5BracVNBvrkZRKi29RY 4hXg== 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=XxLQVkzo6u05XRu/oTQ+Gc3Lg7Bmhol2RuzS9iezzHg=; b=EDd55HZ6o5JRSb/YRjwjgS0WwKJ7wWjjHtLP/5RDYZOwc4eoUS8c9qiZHNEbOgOi2y 8ONZHjeGWEMis8nuXp3z9mLCSZ82iLsKsxWwAxTaLIURShwKERw9e5YCIda8pIaPU58p JFfRE99REdexsVJ1q5A5DtlrIYUyw8nje4oMLkfmhB5p7tZQUtP3jLrsQcfIR0adniWd InTmw3qt3I/qBqEoQvcy8wyP32CxJOgKq+3az6KZgNpMFgGtlqiGV1ZBN4cXUcBpFl1g UTDl7EgvhogIoI+L0vDytn4ik/qcYFDR3puDIsyE1CoUMRLjBBROQ6Z9d+i3eWJB8N4Q yHcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XxN1Mgox; 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 fi14-20020a0562141a4e00b005376fc51789si267262qvb.43.2023.02.19.19.25.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 19 Feb 2023 19:25:23 -0800 (PST) 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=XxN1Mgox; 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 1pTwmV-0001Bb-GN; Sun, 19 Feb 2023 22:23:59 -0500 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 1pTwmT-0001BL-O4 for qemu-devel@nongnu.org; Sun, 19 Feb 2023 22:23:57 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pTwmS-0005r1-3S for qemu-devel@nongnu.org; Sun, 19 Feb 2023 22:23:57 -0500 Received: by mail-pj1-x1029.google.com with SMTP id o17-20020a17090ab89100b002349a303ca5so1791277pjr.4 for ; Sun, 19 Feb 2023 19:23:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=XxLQVkzo6u05XRu/oTQ+Gc3Lg7Bmhol2RuzS9iezzHg=; b=XxN1MgoxJd+U40U4KikY3FrdJHZe589HIYBw2KbcFVTsXOSHr947bsO/hYW81ogxaM 0YPWov4BhN37Ze4ehJsn+9pBNfPZZnayfudgoV5Vqxw4UwnyI0sHOrp7NXs7xD2t0bjF z9AxvXyG1SA+jsR68THjoSEInFg51zg8RNVCian6a02l4lgh+wDNsxqTTTekgt00MpYB Lri8SOiAlZPxbZdwYRU/CIW01+eZ4fM/4aX1ufBOo+OpszIQvyH0P0iTEw7SZRbutJUq jJYZ0VYPfPxtpB3r1YfcTo1m2Gwdkbcx//1rZeufODgZe2gIz4BJjh8JOe4vPFef9uoX L9zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=XxLQVkzo6u05XRu/oTQ+Gc3Lg7Bmhol2RuzS9iezzHg=; b=MofwVnMCuw4hkFbeBZ5yJ969s44fHysU+4GLpO+tlOE0E6KLG9EOa6PUiicGnIFt9E OJpkQbNafnFEjSpI1BGK05xqntQM1gPxettutCsV5j5p2JmQKnbnH1ODrcmiANzPxTkX WH0Cc3EJsi1zX62oiKi9YWNB0RdX4Jlb8Dc/MAr1pXiEUokSNe4GB18JuWXNzRAloNPy GqfJbZH9nZafpDVDfmFAG+vslOBg69kJALu+BRBPs38OMeoq8boI6PxnB43rRhQEjkyN CmtsBDH1wW2YFzye/Of5KdDbjcoRCQGhFyus4FrMS+TBUzmVEZqWgDm53yEFbMsker0k 8rrA== X-Gm-Message-State: AO0yUKWHj89zascypSFmzuG9C1SX9WHKHbEIHSvbaNuUwzexJCay4QuL 43jL9I8g7eBzX+RlJxI4X0S8lZozfRoskJpTpJw= X-Received: by 2002:a17:902:c408:b0:19a:9984:5590 with SMTP id k8-20020a170902c40800b0019a99845590mr1393472plk.5.1676863434603; Sun, 19 Feb 2023 19:23:54 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id l11-20020a170902d34b00b00198e1bc9d83sm6621302plk.266.2023.02.19.19.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Feb 2023 19:23:54 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Ilya Leoshkevich , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 6/7] tests/tcg/linux-test: Add linux-fork-trap test Date: Sun, 19 Feb 2023 17:23:37 -1000 Message-Id: <20230220032338.5619-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220032338.5619-1-richard.henderson@linaro.org> References: <20230220032338.5619-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.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: Ilya Leoshkevich Check that dying due to a signal does not deadlock. Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée Signed-off-by: Ilya Leoshkevich Message-Id: <20230214140829.45392-5-iii@linux.ibm.com> Signed-off-by: Richard Henderson --- tests/tcg/multiarch/linux/linux-fork-trap.c | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/tcg/multiarch/linux/linux-fork-trap.c diff --git a/tests/tcg/multiarch/linux/linux-fork-trap.c b/tests/tcg/multiarch/linux/linux-fork-trap.c new file mode 100644 index 0000000000..2bfef800c3 --- /dev/null +++ b/tests/tcg/multiarch/linux/linux-fork-trap.c @@ -0,0 +1,51 @@ +/* + * Test that a fork()ed process terminates after __builtin_trap(). + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include +#include +#include +#include +#include +#include + +int main(void) +{ + struct rlimit nodump; + pid_t err, pid; + int wstatus; + + pid = fork(); + assert(pid != -1); + if (pid == 0) { + /* We are about to crash on purpose; disable core dumps. */ + if (getrlimit(RLIMIT_CORE, &nodump)) { + return EXIT_FAILURE; + } + nodump.rlim_cur = 0; + if (setrlimit(RLIMIT_CORE, &nodump)) { + return EXIT_FAILURE; + } + /* + * An alternative would be to dereference a NULL pointer, but that + * would be an UB in C. + */ + printf("about to trigger fault...\n"); +#if defined(__MICROBLAZE__) + /* + * gcc emits "bri 0", which is an endless loop. + * Take glibc's ABORT_INSTRUCTION. + */ + asm volatile("brki r0,-1"); +#else + __builtin_trap(); +#endif + } + err = waitpid(pid, &wstatus, 0); + assert(err == pid); + assert(WIFSIGNALED(wstatus)); + printf("faulting thread exited cleanly\n"); + + return EXIT_SUCCESS; +} From patchwork Mon Feb 20 03:23:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655041 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcd:0:0:0:0:0 with SMTP id e13csp1180015wrc; Sun, 19 Feb 2023 19:25:23 -0800 (PST) X-Google-Smtp-Source: AK7set++nb8f8rvetOS4D4TNPwSYbM1MJBXIxB1OhE99bHxEEUGMYTXbTQe/0RFiNhFLb+cd2BKD X-Received: by 2002:a05:622a:138e:b0:3b6:3038:d4df with SMTP id o14-20020a05622a138e00b003b63038d4dfmr14757117qtk.34.1676863522842; Sun, 19 Feb 2023 19:25:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676863522; cv=none; d=google.com; s=arc-20160816; b=0p7W5jkX7XYmbUr5b+CGunU8s51T/1xnCIgsl/d1E6OBaeWJdrWPviPs0DO76c8TVX unU6wL8Ac+SUXRwC8d+jeKZWR8okwoGfaqv/3G6P3Ate2h+AoKxYeZny+UjqvkurkBaM v1jIu8xagabpoX4UTvHYiN6Si5i4WL8i+dMfvtWb8TAINsPl2DpJO3Cot8PXrPNDWGBt ak7LSucgNTUy4D2E12Di6byn3fRYj5oQA7nTeVLYLGcDpNvKKxWHZunXh8Cp9X5YcSLX 7cIZq73bcIqNbO9+dOotfvaDooFv0R7Fxp+bRPFIs2M/pT+M2BJYKHGdxVkfiJx1srFh wyFA== 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=DlJuyAHzYrazSg4WxydLb3Ck/tzkX7PaZRHPA6NtOV4=; b=s1Nbf9elTAubRGXvfFd29ZaBrcZZNpKvywrX/N3DtW/Qv8TJLVDWD+0wxRUhdfCkVv 0/0RVvjLcDL65eGxu6TPlYXfpgLL8EfvNXLE+uP+Xd5rHZi0hFy9fNzIRmTh1oCci/Zp kB71T6m+ZMhslM+7hKVydj7wtHcwTN/j0gSCX51vkB7mxAQTnx1NsTkDmF/xSqfpc6WE io62aF8QEN4XH6z9lM1XlVUqjlw3M5FlWL/dojphkbHiimOvT7f78mqwM0WGJKbqmfBk zoeKAuiEk4/pv+6pAYHlvl6jVSaRFG48R0q/XLB2lv77LJnWNHoqivpi78IdPx0DV/Vk eBoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZWtwqL6w; 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 t27-20020a37ea1b000000b0073b882ce6efsi8591018qkj.298.2023.02.19.19.25.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 19 Feb 2023 19:25:22 -0800 (PST) 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=ZWtwqL6w; 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 1pTwmY-0001Gr-9E; Sun, 19 Feb 2023 22:24:02 -0500 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 1pTwmV-0001Bf-RJ for qemu-devel@nongnu.org; Sun, 19 Feb 2023 22:23:59 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pTwmT-0005sN-KW for qemu-devel@nongnu.org; Sun, 19 Feb 2023 22:23:59 -0500 Received: by mail-pl1-x634.google.com with SMTP id f14so1959159plr.0 for ; Sun, 19 Feb 2023 19:23:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=DlJuyAHzYrazSg4WxydLb3Ck/tzkX7PaZRHPA6NtOV4=; b=ZWtwqL6w1fJ/cAIIg+0BMlNZWQLMsrhC6tAv0Xvy4NzyXEp2WnZAsWMd64ixazZ7cg PPi7ySvhKuEfoumnlrnKdDOHAH135cOXntXn/b+S/xdNajIsUrr1SHZwn6njPfo1tAya 31xwd3KeZSGRmkYxY8CpXyj8+3r+BOvk38VSxPBvmZsvxo2RZVVNwrS2i8ZQbaaS5/1M EA5e0JEI7qpxNaoOuFIOVTZ0myHEL+cwya/GSLgL1UZb1coBrGc6MO9QqX/krp4mOxlh yy6nE3n/vx2wLvw/sfJt9CK5BekNexrJM0ukSnICgrAIT04vSBUxQZHiLEDKHdJ3DYvV 992Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=DlJuyAHzYrazSg4WxydLb3Ck/tzkX7PaZRHPA6NtOV4=; b=FycpptBnRDkETulfH46JplhZEmB6xiPFcUVQFjT1KBtzrqKCqaJWb/pxdujrMakzWT BypoY2VzO2APIQnMwVKn0h3wzIknguBNYT5h2o9j2iKZdAb/pwcHWCQhH8wjwRGTSk8F x4j/rN3bEjrtc0D5GRZVpCtayUhCzKtPMhKQy7GTN+lUGtczrsHeHlVMvscmN39K9MSM onyF95ypLc6XjUcteYctR9bTOHdolDH8YD0PXlB+6RiY0blvnONDQutOZie3VCc/u66s JiaSk/aW1ojPrXnYBck5ox1A9tkOWlqRRLFxuI157tcXXVbxbs6PQH6KiiVmGQCCHpXd VAzw== X-Gm-Message-State: AO0yUKWgTQObkuwBkbedisbeOiLMQT4hEC3FOYiuUB6Wf9ZMeimmG77d i648mmIM6M7cBGg7NNZQtmqY6o7tB6H7IgCSqGY= X-Received: by 2002:a17:903:11d0:b0:19a:b683:e11b with SMTP id q16-20020a17090311d000b0019ab683e11bmr2813388plh.23.1676863436223; Sun, 19 Feb 2023 19:23:56 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id l11-20020a170902d34b00b00198e1bc9d83sm6621302plk.266.2023.02.19.19.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Feb 2023 19:23:55 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, "Edgar E . Iglesias" Subject: [PULL 7/7] target/microblaze: Add gdbstub xml Date: Sun, 19 Feb 2023 17:23:38 -1000 Message-Id: <20230220032338.5619-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220032338.5619-1-richard.henderson@linaro.org> References: <20230220032338.5619-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Mirroring the upstream gdb xml files, the two stack boundary registers are separated out. Reviewed-by: Edgar E. Iglesias Signed-off-by: Richard Henderson --- configs/targets/microblaze-linux-user.mak | 1 + configs/targets/microblaze-softmmu.mak | 1 + configs/targets/microblazeel-linux-user.mak | 1 + configs/targets/microblazeel-softmmu.mak | 1 + target/microblaze/cpu.h | 2 + target/microblaze/cpu.c | 7 ++- target/microblaze/gdbstub.c | 51 +++++++++++----- gdb-xml/microblaze-core.xml | 67 +++++++++++++++++++++ gdb-xml/microblaze-stack-protect.xml | 12 ++++ 9 files changed, 128 insertions(+), 15 deletions(-) create mode 100644 gdb-xml/microblaze-core.xml create mode 100644 gdb-xml/microblaze-stack-protect.xml diff --git a/configs/targets/microblaze-linux-user.mak b/configs/targets/microblaze-linux-user.mak index 4249a37f65..0a2322c249 100644 --- a/configs/targets/microblaze-linux-user.mak +++ b/configs/targets/microblaze-linux-user.mak @@ -3,3 +3,4 @@ TARGET_SYSTBL_ABI=common TARGET_SYSTBL=syscall.tbl TARGET_BIG_ENDIAN=y TARGET_HAS_BFLT=y +TARGET_XML_FILES=gdb-xml/microblaze-core.xml gdb-xml/microblaze-stack-protect.xml diff --git a/configs/targets/microblaze-softmmu.mak b/configs/targets/microblaze-softmmu.mak index 8385e2d333..e84c0cc728 100644 --- a/configs/targets/microblaze-softmmu.mak +++ b/configs/targets/microblaze-softmmu.mak @@ -2,3 +2,4 @@ TARGET_ARCH=microblaze TARGET_BIG_ENDIAN=y TARGET_SUPPORTS_MTTCG=y TARGET_NEED_FDT=y +TARGET_XML_FILES=gdb-xml/microblaze-core.xml gdb-xml/microblaze-stack-protect.xml diff --git a/configs/targets/microblazeel-linux-user.mak b/configs/targets/microblazeel-linux-user.mak index d0e775d840..270743156a 100644 --- a/configs/targets/microblazeel-linux-user.mak +++ b/configs/targets/microblazeel-linux-user.mak @@ -2,3 +2,4 @@ TARGET_ARCH=microblaze TARGET_SYSTBL_ABI=common TARGET_SYSTBL=syscall.tbl TARGET_HAS_BFLT=y +TARGET_XML_FILES=gdb-xml/microblaze-core.xml gdb-xml/microblaze-stack-protect.xml diff --git a/configs/targets/microblazeel-softmmu.mak b/configs/targets/microblazeel-softmmu.mak index af40391f2f..9b688036bd 100644 --- a/configs/targets/microblazeel-softmmu.mak +++ b/configs/targets/microblazeel-softmmu.mak @@ -1,3 +1,4 @@ TARGET_ARCH=microblaze TARGET_SUPPORTS_MTTCG=y TARGET_NEED_FDT=y +TARGET_XML_FILES=gdb-xml/microblaze-core.xml gdb-xml/microblaze-stack-protect.xml diff --git a/target/microblaze/cpu.h b/target/microblaze/cpu.h index 1e84dd8f47..e541fbb0b3 100644 --- a/target/microblaze/cpu.h +++ b/target/microblaze/cpu.h @@ -367,6 +367,8 @@ hwaddr mb_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr, MemTxAttrs *attrs); int mb_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int mb_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int mb_cpu_gdb_read_stack_protect(CPUArchState *cpu, GByteArray *buf, int reg); +int mb_cpu_gdb_write_stack_protect(CPUArchState *cpu, uint8_t *buf, int reg); static inline uint32_t mb_cpu_read_msr(const CPUMBState *env) { diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c index 817681f9b2..a2d2f5c340 100644 --- a/target/microblaze/cpu.c +++ b/target/microblaze/cpu.c @@ -28,6 +28,7 @@ #include "qemu/module.h" #include "hw/qdev-properties.h" #include "exec/exec-all.h" +#include "exec/gdbstub.h" #include "fpu/softfloat-helpers.h" static const struct { @@ -294,6 +295,9 @@ static void mb_cpu_initfn(Object *obj) CPUMBState *env = &cpu->env; cpu_set_cpustate_pointers(cpu); + gdb_register_coprocessor(CPU(cpu), mb_cpu_gdb_read_stack_protect, + mb_cpu_gdb_write_stack_protect, 2, + "microblaze-stack-protect.xml", 0); set_float_rounding_mode(float_round_nearest_even, &env->fp_status); @@ -422,7 +426,8 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) cc->sysemu_ops = &mb_sysemu_ops; #endif device_class_set_props(dc, mb_properties); - cc->gdb_num_core_regs = 32 + 27; + cc->gdb_num_core_regs = 32 + 25; + cc->gdb_core_xml_file = "microblaze-core.xml"; cc->disas_set_info = mb_disas_set_info; cc->tcg_ops = &mb_tcg_ops; diff --git a/target/microblaze/gdbstub.c b/target/microblaze/gdbstub.c index 2e6e070051..8143fcae88 100644 --- a/target/microblaze/gdbstub.c +++ b/target/microblaze/gdbstub.c @@ -39,8 +39,11 @@ enum { GDB_PVR0 = 32 + 6, GDB_PVR11 = 32 + 17, GDB_EDR = 32 + 18, - GDB_SLR = 32 + 25, - GDB_SHR = 32 + 26, +}; + +enum { + GDB_SP_SHL, + GDB_SP_SHR, }; int mb_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) @@ -83,12 +86,6 @@ int mb_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) case GDB_EDR: val = env->edr; break; - case GDB_SLR: - val = env->slr; - break; - case GDB_SHR: - val = env->shr; - break; default: /* Other SRegs aren't modeled, so report a value of 0 */ val = 0; @@ -97,6 +94,23 @@ int mb_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return gdb_get_reg32(mem_buf, val); } +int mb_cpu_gdb_read_stack_protect(CPUMBState *env, GByteArray *mem_buf, int n) +{ + uint32_t val; + + switch (n) { + case GDB_SP_SHL: + val = env->slr; + break; + case GDB_SP_SHR: + val = env->shr; + break; + default: + return 0; + } + return gdb_get_reg32(mem_buf, val); +} + int mb_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) { MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs); @@ -135,12 +149,21 @@ int mb_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) case GDB_EDR: env->edr = tmp; break; - case GDB_SLR: - env->slr = tmp; - break; - case GDB_SHR: - env->shr = tmp; - break; + } + return 4; +} + +int mb_cpu_gdb_write_stack_protect(CPUMBState *env, uint8_t *mem_buf, int n) +{ + switch (n) { + case GDB_SP_SHL: + env->slr = ldl_p(mem_buf); + break; + case GDB_SP_SHR: + env->shr = ldl_p(mem_buf); + break; + default: + return 0; } return 4; } diff --git a/gdb-xml/microblaze-core.xml b/gdb-xml/microblaze-core.xml new file mode 100644 index 0000000000..becf77c89c --- /dev/null +++ b/gdb-xml/microblaze-core.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gdb-xml/microblaze-stack-protect.xml b/gdb-xml/microblaze-stack-protect.xml new file mode 100644 index 0000000000..997301e8a2 --- /dev/null +++ b/gdb-xml/microblaze-stack-protect.xml @@ -0,0 +1,12 @@ + + + + + + + +