From nobody Mon Feb 9 21:01:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1677031316; cv=none; d=zohomail.com; s=zohoarc; b=RKVQvlnOWv/+uxYmBIibqe9kn5R1OwWsjrNYO8yaQCC84g6icSLRxyAPqKPb+rUpWoKuLa10HzY6/4qAJ+JjRehb9CihKBHWB17HjipgxgQQDTmplud7EwrHOwrHe3sTYw7/Hv9M4zkuzdhinlkuAU/kmA/ncSN15w9aI2BYUzI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677031316; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gmPWamcS039ttvGx+0lkOqlpPNASpmKk9ydxcZXcCPQ=; b=O8IQvtKvr1ZhPFJjENI3gC1+NDNNgRCu3n13/woHwhMrXbTS/RBxt2ZYvURCS1uB7jis6VPG7zXD9QCV38WtRrjL33mqXmBqgQDT7nQpKU/yhqMNHXVVUldOCKUYHtuYkdnshLGk7ReG0Mm3WZPltyfyPMW6t3POi89ih68xWEk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1677031316141245.06027152725017; Tue, 21 Feb 2023 18:01:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUeQs-00032m-Rh; Tue, 21 Feb 2023 21:00:34 -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 1pUeQp-00032D-J0 for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:31 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUeQn-00013C-Vy for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:31 -0500 Received: by mail-pl1-x629.google.com with SMTP id ko13so7785068plb.13 for ; Tue, 21 Feb 2023 18:00:29 -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 2-20020a170902c10200b00189743ed3b6sm91468pli.64.2023.02.21.18.00.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 18:00:27 -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=aEBfDQSyrYtobx8mlTuoJz7N2Sq/XYrHSVsHFCtoeIDUxKtH2fEtfso7pxE1H+/hN/ JX4YsKQrD/fQJ9lfSYAmK2OwX1r1BlvpQFxNAlMWZH/DO9gAqQDZ4FJjBJFWaTfQkyG3 AdGofU4T+bn1S1TRpAmhjfU5zgrc2OnB3nRkTJ+RGer832RbVJbIgi52m3NaeIBZsYJo 3LW4ac2ileLOxW3PXfYKBIRmN7JDOiFxxgjoAcFNgeanv7GajJZoJUa5OCfPUmDiVNTP yQkD4gFVoPb6w2ppojz4UN5UqX/GjSGPzUQL8E6crDUFj02VvuWZ3eybtC4PewPiPfOm NYlA== 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=YuZPeFAN934/8CA2ajMCqtsEa3DpOZtuMCxgxtbIkSlorZYzscfp2UzMvOwU4KfcZI LIVKMGGaDizdpt3DCBArTXpS5H9+uhdS6m8APlDZuAjNZGqcEP9ttdhZeJGOUFo/vrOU 2cXifxVeUB4hfVNDOf7U/aWR29+NvJYq+MpgMGAR3EzcXkSrx717aah0LLJttglr9H3S 65+yhHtRBXUOjlpyaf2K+uMoq8s7EhLkb9ZotZzSUfQfwbLVndcixoK+/Cj+7DPSE3kJ EiI01U/Nfs8/870src8sTQdo+BJwnpTdZhKYWIGzJfc9TjTPHwrTzRE/X8G5BqCYSymN 82Hg== X-Gm-Message-State: AO0yUKVPyySWYuEvVKn/P/amgnf/F2NFcDkZOr7xVkwZTxaIe8AvipXD 2xca82WtlFEEG6wd/cb8zbcT1fR/nC43amZgEHU= X-Google-Smtp-Source: AK7set+Cua7WM8ALMfAuvioAo+neKcK/+eaRxkHjiQ6eBaU4hGPq3kRzYLsXLfZ+SqnOEM8g/+WvQw== X-Received: by 2002:a17:903:284d:b0:19a:9943:17fe with SMTP id kq13-20020a170903284d00b0019a994317femr5976457plb.50.1677031227989; Tue, 21 Feb 2023 18:00:27 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Sid Manning , =?UTF-8?q?J=C3=B8rgen=20Hansen?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL v2 1/8] accel/tcg: Allow the second page of an instruction to be MMIO Date: Tue, 21 Feb 2023 16:00:16 -1000 Message-Id: <20230222020023.904232-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222020023.904232-1-richard.henderson@linaro.org> References: <20230222020023.904232-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1677031317017100001 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=C3=B8rgen Hansen Reviewed-by: Philippe Mathieu-Daud=C3=A9 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, Disa= sContextBase *db, if (host =3D=3D NULL) { tb_page_addr_t phys_page =3D get_page_addr_code_hostp(env, base, &db->host_addr[1]); - /* We cannot handle MMIO as second page. */ - assert(phys_page !=3D -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 =3D=3D -1)) { + tb_set_page_addr0(tb, -1); + return NULL; + } + tb_set_page_addr1(tb, phys_page); #ifdef CONFIG_USER_ONLY page_protect(end); --=20 2.34.1 From nobody Mon Feb 9 21:01:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1677031326; cv=none; d=zohomail.com; s=zohoarc; b=NefWN7wBlLQq/SnSNKLZof5bCTVqws9AI2uMo6Yh5JCvdRXXyhdqJ1/I7CN0HbWTDeT6CqfSVZ1UzI58FpCRxBXZmWApMxj832IyK2XFSnxCgnIu5eiAOLXTGgapnj4XNyTmroyDODokTea+QxYg87ZZJAsOX0PqZ6v0i32dkqI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677031326; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4zhGePcD91yQ6ch+7pxzLZ4Aayz4MXPEoGj6QOyVgUM=; b=UAT4daX9rPCDsFMgP2QANuFUN/t3Y7GvVQ0y/XhxDW6NOhdjieV9bDEUJdupfThrTbd+cKmc2Dc0QsgDfiUjBT9WehmzJimThtDsnToCryzqztjgaxTWW8kyNgdsTJ+uVnwYABtQZ1wIEr0y9R1CM6meJyCMs/fHqPe9aPc+VFs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1677031326350784.1652730434588; Tue, 21 Feb 2023 18:02:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUeQv-00033M-5z; Tue, 21 Feb 2023 21:00:37 -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 1pUeQq-00032Q-PH for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:32 -0500 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUeQo-00013V-VC for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:32 -0500 Received: by mail-pj1-x1030.google.com with SMTP id nw10-20020a17090b254a00b00233d7314c1cso7138786pjb.5 for ; Tue, 21 Feb 2023 18:00:30 -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 2-20020a170902c10200b00189743ed3b6sm91468pli.64.2023.02.21.18.00.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 18:00:28 -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=H8Gn3iyK0gYpvOUozYDdkZmGBTmTtz3CBrfDh/43lu45TUwm6couNT62H5vOUvwDy0 BZj1eID1p+lOv1kx4VqCV7CKtaVMc13RdpMDYsrNo6MliXTqhO+tJWMAbriH+yKRtwIZ LFzZGdUm+In1T/PL3WbSHr+GBc81n3AhOHkzPGbWbtnKJUIKVo6r2LKXBOcMNsc9+55e VgQhquRoJ9eA/zCGimNoHbZ3WUsYbXZVST3oJoyYLXteVAPE+v4gTklxKo20loKzf25i IuNMhDD1mA4OusJ2ysZ5fMVwc2gH/4I7AZGralxV4zW0t2eiLq2Bd7eupD5qqjCgWZbU EGJw== 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=2Sp8jtsmLU2rY/mSEq4rYMn2ko7sNZtRXUlESbnRjgp31cIK8KW2jh0MzABvLuXfn2 P/LWlVVnvDg7DkQDa4Kcorl1e/Q4Ff/1xukywsqf3o+F9YuLcmCJdO/wsK3u7HvTup8P xYw0L3s3oTHKTPPauVBkRGzcpG2e0g34C5S2eI2q8aJK7laJjs0SGEN9Ysua/sv/wYN/ klnKVu80YlGpmSd6mOVmUizamoq8kbi/ejJVB03lE1doYHF4TsJyhuk6lHk4r/+Xkz99 E6HMHdxsFWzTx3Xger3tWZanH5DrQZVAfB4+s2RTN6xBdi5k/74tjJ3oJj9MHS1nXleB qx6A== X-Gm-Message-State: AO0yUKWwsIdhfq0WXsuFjzZmvHdacZ7Q8wW75MhQ8OAaB/d/fEuRV3f2 KG3BomUKXFpx5/J7ZFNqccUVvhSjhL2NuPChM9w= X-Google-Smtp-Source: AK7set85d49DCbMlSoAyneE3XdN+qwBRne67f1AjVovYpvBT5WC8aLeHdObgRazawEi7Jk7pU8EH9g== X-Received: by 2002:a05:6a20:a10e:b0:be:ed2a:b2dd with SMTP id q14-20020a056a20a10e00b000beed2ab2ddmr6936600pzk.6.1677031229404; Tue, 21 Feb 2023 18:00:29 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Ilya Leoshkevich Subject: [PULL v2 2/8] linux-user/sparc: Raise SIGILL for all unhandled software traps Date: Tue, 21 Feb 2023 16:00:17 -1000 Message-Id: <20230222020023.904232-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222020023.904232-1-richard.henderson@linaro.org> References: <20230222020023.904232-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1677031326962100001 Content-Type: text/plain; charset="utf-8" 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 >=3D TT_TRAP && trapnr <=3D 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); --=20 2.34.1 From nobody Mon Feb 9 21:01:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1677031282; cv=none; d=zohomail.com; s=zohoarc; b=AmpILCiEc9GefwpLJTpLxm32gS9NphIrtdO5QYT4kzNZGxae3t9SKaizl52fvYnahR8jm/3uh+c55ZdUjAY6yUzRF04+pw2WyLNlM+bkuOgU9kOhyJ5zoi0g4nls0cG58mII6XwZ4m8qU9VVQc3HJDAI4uq21Hm3ADPe2Cx0Ea8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677031282; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nN1Nd19UG7Ob6HhOyu1ZExnb36Rzel7CeIAQhipYNRY=; b=HHccLbDRhmJTSXtK1MVgsr6sZDtIJOgxuDTySwV8K01WUT78TAFoWxOz4D2Uwa6A707FzaedjquctcnZq1dtGRk4u9Rs1SFng5cgYEMNm6Rlv0Fby2HH8Vt7RjWbtF06csNF+CvGIiJtN0aFcN+MRebgSucaXM3wF5YpdGX6nxY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1677031282493948.3724817418937; Tue, 21 Feb 2023 18:01:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUeQw-00034j-Dn; Tue, 21 Feb 2023 21:00:38 -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 1pUeQs-00032n-SR for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:34 -0500 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUeQq-00013t-Qc for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:34 -0500 Received: by mail-pj1-x102b.google.com with SMTP id nt5-20020a17090b248500b00237161e33f4so4834792pjb.4 for ; Tue, 21 Feb 2023 18:00:32 -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 2-20020a170902c10200b00189743ed3b6sm91468pli.64.2023.02.21.18.00.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 18:00:31 -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=j9n06ynxaS0F5kR+CHFeJ7ySRkcjI3DdScemCh4CqaPv4cror1TVmjW85Fe3fwnFNH yLXQK3Fj8MBeLQQlSZllrc31ZvC3Ax7xkcU9t8Kc4T+5RIOwBc5KlzJ6ksGi5PdQiVhh 9h6W/+BAJi5rLYw/oDScVo1/HIzp+Uk3b2lsczQ4WqyNfKy+SYLP/k2y9Ut+f25N2K63 1QH3dciqBbgc4OiZArWFLOEB9xGrYOayggFgfAefolEk+0g7zDBOBbHx5paWAWSWcVLU yzgeCMG/2MoGW2qDLHpM/wRQm7tyqEEBQKgmF+OgvKzVhtFHwK5UOUUHzT10KWkrAFKH rneA== 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=7LACxOH60cdGikvFVXg0ts5NFQ5QfSDABz3MCG0niEy4QlyYKeMsc8AipMtBqeYsBF isXJQytPvfQFSZL9XIskPIWT1agDfGWW92AdcS2MvmmUNtNGykb8cWuUN7aqnCczszOC UufIrVOYFPgPOvIUt/0wJOE8IGaTbhSBI1yni3L010WQy5rqm55XDriKZeyAIj+JGean cXdfI6MRSqnDsBjJIC9EBJJXIpoOQ+VnxEz2/UviRS1nB2zTFT2vX11hpGVeB3kofZw6 L1iD2AMyyjdMLydElvzmUfPuRJ/2f7wja+zx/Tb1uYXInXUrHbxDZl8TFbmkt6ZZI4Kd bpiQ== X-Gm-Message-State: AO0yUKVtywinz5zUkhBjafk1e1xCBtdAE72oUYzcqTp4RevavkpqDgAZ +ogt68cJyRDVEefrPrgSN6incJI4qOvpHQifoJE= X-Google-Smtp-Source: AK7set+PvmvUFyl0Wy0Eysf2WHuSEMGPg3hvGoN6tRoUqhUx7VcEwLjCzEfcjp/iCaGXSbqXN6m54w== X-Received: by 2002:a17:902:c94f:b0:196:88b8:8616 with SMTP id i15-20020a170902c94f00b0019688b88616mr8337734pla.5.1677031231455; Tue, 21 Feb 2023 18:00:31 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Ilya Leoshkevich , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL v2 3/8] linux-user: Always exit from exclusive state in fork_end() Date: Tue, 21 Feb 2023 16:00:18 -1000 Message-Id: <20230222020023.904232-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222020023.904232-1-richard.henderson@linaro.org> References: <20230222020023.904232-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1677031283126100001 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=C3=A9e 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() f= or + * both child and parent. + */ + end_exclusive(); } =20 __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 fl= ags, abi_ulong newsp, cpu_clone_regs_parent(env, flags); fork_end(0); } + g_assert(!cpu_in_exclusive_context(cpu)); } return ret; } --=20 2.34.1 From nobody Mon Feb 9 21:01:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1677031349; cv=none; d=zohomail.com; s=zohoarc; b=V9OmKH3qOddZUTEj7sHO3rgFHocrEdWEXfrpw/c7Og6lazdF/fXegRn+V0QWKAlsfGcXxul666iMoxUEALbf+p99Nbcre60GulXDSHgeQR9CUKLkZgYjJP7LqVEtxOrmpxTKB73SSzsVJa7F9+b/OCARTrbO/leIQrKouK989qg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677031349; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zxPSc8yJkvzSaYSSEPoT7SrrtEyyDZGvKalhQ2ISznU=; b=G8oyGYWJXPNBb7LTajH/hn6QGzAb6s0sTqYxgDcXc4k+WpvkA8kjNNtqWE3c9fr6iDcCGDhKI3ua8uppGOd8YUY5LUa+y+5fOTcmuNoP1o0qwL/Q4ibpSml3tyt+bpn3AqXIT0nQUtGyVK4EaLfF8lkR6K3/bYbHoiECv5AId64= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1677031349566786.2596960932099; Tue, 21 Feb 2023 18:02:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUeQx-00036A-5o; Tue, 21 Feb 2023 21:00:39 -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 1pUeQu-00032z-7i for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:36 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUeQs-00014S-L4 for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:35 -0500 Received: by mail-pl1-x630.google.com with SMTP id q11so7478272plx.5 for ; Tue, 21 Feb 2023 18:00:33 -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 2-20020a170902c10200b00189743ed3b6sm91468pli.64.2023.02.21.18.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 18:00:32 -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=vWAf7VNJ8cFB73zb5ZKFtVK3NU5Ie3Ya1NJtuBimgfYWPUPGfoqBPYInxDOOjxi0U7 lgn9rMDNrH1dCh8tRJVPSQqZdFAgzu2z4YVEGM6iXjtU8iLpJ9YRmqwibGHu0hzHQo5h NcEQUjegHb+2YTyivB5UUEmREzswegrIfXA3nDUfvdQh8poKhLCxtQVFn8L3oJyAfRgM SeZxahAzoHQTxgOiMROQeberGnUqVN8lwFqMT/hvbsOhUg52C7NLOskDqIywb26aO5Cm egHksOAc6xWyArzKm2NAzvIi+w0sobxo9yuTPwmgOS17F5ypCE64pRAWcrFGhLXRzwyq rGFg== 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=rmTiwqBiNToQ8IrzM4KZ8WI2sM8j4jIy/Q9vDwcKZn+5lDnIx18KGHLay5PC48rWds FUpW0r4+gV66R1Czm9fmLr/V6W57L3ky4yjtH4C008DnrmSCit2KJfTLWdRsOOOiDLuL NXATin/ZBIGwUzQIxPoSoTAeopFTk28fdkAbD6kfLBkWPqhVLHN6G1bbvkZsfWjhylSJ 9jUPzmn58xR2N4GkO4+rBAAnzgOkEZHKjDNp+rnq3zVcA0Cyw01/dKPHjzP/djbMQtgb DiPpga+8y5FZXKWztIafngTg4XqECg1Oy3fBnonFyGKogQsr8zTRDmEr3LYsyz6di+xk QY9A== X-Gm-Message-State: AO0yUKWcPBzJT+KsJxaYhSDU838w0QASeQsgfUKsGweBFT8QaWpjURd9 fWJZXW0CDdCkjfwl8hfIuRADie6A9OOh7T0c5Uw= X-Google-Smtp-Source: AK7set/n4OoMe+N/fG92W1He8obIQN+trikO9GDki+o38mAyc0oYFNAx4VKUMtkP2sgzIiacjpI2Xg== X-Received: by 2002:a17:902:e884:b0:198:dd3f:2847 with SMTP id w4-20020a170902e88400b00198dd3f2847mr10095406plg.21.1677031232896; Tue, 21 Feb 2023 18:00:32 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Ilya Leoshkevich , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL v2 4/8] cpus: Make {start,end}_exclusive() recursive Date: Tue, 21 Feb 2023 16:00:19 -1000 Message-Id: <20230222020023.904232-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222020023.904232-1-richard.henderson@linaro.org> References: <20230222020023.904232-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1677031351128100004 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=C3=A9e 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_fu= nc 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; } =20 /** 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; =20 + if (current_cpu->exclusive_context_count) { + current_cpu->exclusive_context_count++; + return; + } + qemu_mutex_lock(&qemu_cpu_list_lock); exclusive_idle(); =20 @@ -219,13 +224,16 @@ void start_exclusive(void) */ qemu_mutex_unlock(&qemu_cpu_list_lock); =20 - current_cpu->in_exclusive_context =3D true; + current_cpu->exclusive_context_count =3D 1; } =20 /* Finish an exclusive operation. */ void end_exclusive(void) { - current_cpu->in_exclusive_context =3D false; + current_cpu->exclusive_context_count--; + if (current_cpu->exclusive_context_count) { + return; + } =20 qemu_mutex_lock(&qemu_cpu_list_lock); qatomic_set(&pending_cpus, 0); --=20 2.34.1 From nobody Mon Feb 9 21:01:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1677031349; cv=none; d=zohomail.com; s=zohoarc; b=G+NAt0j5j9Rxkv7ygbHg29n4a1FaJwY6LXOJMQZ8/NoMvwElAgey21EVCdtE67FvaLnM62tawPdjZiVWf0gw7PWRziDenI+EcCwbJAgTpyqjrq3XjPI6bmuhtQgWRtuXalo9uiPPIKgsgUxJXUKmnCBvW0YkjGtb5lzZmfVWE1M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677031349; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JKMBaWZBGONH22d4GZ6aoQ5NI2bVoqwHKZG9lz4sA9s=; b=c3JXYsxJSrB1dW8iD6loBUANJ0Uhnq2fg+v8LRZcLJMBCrDI/RhQWUeVei+SMZSwATkoz2tUGQLDpQOpmxS6BjaioXKG0CqRlf/h0oCbW09ACXgcYJPIp9B3Cr6xViTmIO+Mi6jt89Onpo5zIwKDErc3V4DNEc+IC/FaUDu9Q7E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1677031349669757.2411096751362; Tue, 21 Feb 2023 18:02:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUeQx-00036B-8U; Tue, 21 Feb 2023 21:00:39 -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 1pUeQv-00034W-QH for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:37 -0500 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUeQt-00014h-T0 for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:37 -0500 Received: by mail-pj1-x102d.google.com with SMTP id m3-20020a17090ade0300b00229eec90a7fso687071pjv.0 for ; Tue, 21 Feb 2023 18:00:35 -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 2-20020a170902c10200b00189743ed3b6sm91468pli.64.2023.02.21.18.00.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 18:00:33 -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=r+sIy3KcSW8Yd6RILWmAHzlhOA/Kj2ahEyRX1w4+Tq1mLxfiRJuhoJB6zyjnSFLINr AzBAVZa+KorRc4HYL6948qwpZet5LGeS34YRU/wdbzvmD6/0IpY5THNXaV55Xrjq8JsN 7rzRIl/KJBSco9Oun3HVwl1IAUQbBNZ2lsQbPz9FqsmSnoVY1PU8ysjQWJ8nxNgZVrb9 Wu78/Xt4WqD4+XI+z8HAGkO4AiiWlby7UHlHWRnc4XhlMfUSbgcUlry0t9biiJzE2PvU 0QLOU0n4wtt5KewdTZPScwz30SEu7ObYUZ+cK+o8gCpDKOAlxPBNh4Vc5ly4mnzn1RvE A7uQ== 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=tF6+UK2YMBBFxC8doQ7Ia8KqTbHrbKvInDXHMQPU3m6gw8Sy1joFwD4/WQUxwnYAPX gIx1MoMFczDfeTGixEMkoRbx8RFglcSL1hq5Fn0X6+ajTBqfLudpJOBTsJHhUD/0JmuE gv87tdrJNgZTQ2pqIIK1T6QYJIo5njyyB6yc9OT59L89YOstrFmwz9TK8ND8mgYgTJQk NSy7uRSgtYYDTurvp8soe5tuSlOhZdbmFGQYo3PnHfP0zftYhWjDaWdn9M8AaPhchpxm aNmCGFyTPixS5peRz64YiXt1zByNGw8uSSf8Dj2pBQrRTJv7yN30t+JZdS8LtWyP4au0 CMtA== X-Gm-Message-State: AO0yUKW7/Ngh4ZZ29ADug8aS9KgfbZ+mHMyORnxorsTbdc3DcQnk6ds/ g7YVkqYZwTBCeERGMjr07QrxGR4BXAZmCYKR+5E= X-Google-Smtp-Source: AK7set/0tF4vWKX3PSf6vkMv7R2S95Nj5EZ2khLbvVZEf6eeL/U62lPK13QvVxjKF8jPrXZdlTZdbw== X-Received: by 2002:a17:902:7292:b0:196:56ae:ed1d with SMTP id d18-20020a170902729200b0019656aeed1dmr5162060pll.69.1677031234385; Tue, 21 Feb 2023 18:00:34 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Ilya Leoshkevich Subject: [PULL v2 5/8] linux-user/microblaze: Handle privileged exception Date: Tue, 21 Feb 2023 16:00:20 -1000 Message-Id: <20230222020023.904232-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222020023.904232-1-richard.henderson@linaro.org> References: <20230222020023.904232-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1677031351100100003 Content-Type: text/plain; charset="utf-8" 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_l= oop.c index 5ccf9e942e..212e62d0a6 100644 --- a/linux-user/microblaze/cpu_loop.c +++ b/linux-user/microblaze/cpu_loop.c @@ -25,8 +25,8 @@ =20 void cpu_loop(CPUMBState *env) { + int trapnr, ret, si_code, sig; CPUState *cs =3D env_cpu(env); - int trapnr, ret, si_code; =20 while (1) { cpu_exec_start(cs); @@ -76,6 +76,7 @@ void cpu_loop(CPUMBState *env) env->iflags &=3D ~(IMM_FLAG | D_FLAG); switch (env->esr & 31) { case ESR_EC_DIVZERO: + sig =3D TARGET_SIGFPE; si_code =3D 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 =3D TARGET_SIGFPE; si_code =3D env->fsr; if (si_code & FSR_IO) { si_code =3D TARGET_FPE_FLTINV; @@ -97,13 +99,17 @@ void cpu_loop(CPUMBState *env) si_code =3D TARGET_FPE_FLTRES; } break; + case ESR_EC_PRIVINSN: + sig =3D SIGILL; + si_code =3D 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; =20 case EXCP_DEBUG: --=20 2.34.1 From nobody Mon Feb 9 21:01:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1677031283; cv=none; d=zohomail.com; s=zohoarc; b=SvOD+JqVkz2RnSgRJiosAg52MMzGnYHTn0nCBEkodcUh7WRq7wOTW4WoHTm0EyHhsQhiLfh5hkaNpQqme4nemRtEN24GcaqdF7KCSF+T5dTV8MGk/17cNtV2zVHuTcj5UeCrvP2vToKhEhUlokO84OEirOJJwtU/t1ZmRD1J51U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677031283; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ngk3dzZxI8QiHG0YRp0EJu4+0G0CZqPrFok24rpK6qg=; b=g2POagEKaN5MiT75JyCxTeDItoBEQD1oCgIGZEfsL1GAVTeX5eEuqnVbqoY/oOJdSGDBduq/XRsyyNL4Dp2UkBYhWzb5S7UkbKxNAe/qATTeggyj7CZsJz0mEhoBiGBwHAarqkegd+kMNOIHs4EzDvoMnnrx+38ydoBnC80FTmA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167703128338695.7371653383725; Tue, 21 Feb 2023 18:01:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUeR6-0003By-11; Tue, 21 Feb 2023 21:00:48 -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 1pUeQx-00036S-Lo for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:41 -0500 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUeQv-000153-Af for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:39 -0500 Received: by mail-pj1-x102e.google.com with SMTP id u10so7192469pjc.5 for ; Tue, 21 Feb 2023 18:00:36 -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 2-20020a170902c10200b00189743ed3b6sm91468pli.64.2023.02.21.18.00.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 18:00:35 -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=ngk3dzZxI8QiHG0YRp0EJu4+0G0CZqPrFok24rpK6qg=; b=un9FJDjQXbxJcab+v4ce67rvM2PSWIcPfLQ5kEYqyP8w5OWldqn95U7PINPGXxnuG0 xp8KmyTpRLcCHZXLXFid4Ktk4hFQzot35Ou+cfyQXp+lVpeq1EVb0YeKK3KUVOjxofLc 8/FbmRaw7/EBWpj1BFMSVvbT3/0gO22fpj9/N9ApIqSzjSmgkXhmtipXrxQ+9xdstcjC DypaSGps+CpOPEslQ4NZn/gUkn8zHCJorwElLv0Yp8VggE3tmFzTvAY8fu8tPMVtRf7m Vz8d79V4mlEXk3rtLVFh+qVOUQQ3e0L1IEF8O/k4zep/FX9iwD+qPn29AArdoy4NVbBQ GA+w== 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=ngk3dzZxI8QiHG0YRp0EJu4+0G0CZqPrFok24rpK6qg=; b=MnSWwoY1RdVBEKC4vjYa3JVPRiunSGl2j37tAA4ILlcsB4UtKH7yaHl8HtV15pAGi/ 63HYUSL6za9y8mwgfids1n+XQ6v2xG40yxm7PMJg2JJ9cBftW18aoh16DYh+RBfykLL/ x8ENAeCbds6ztMX5FjhHQqWo5A4g46pJeUPVS6hvNMNJ1R4Ox/yjlxmIn8cxdWMzT3vz DZxyFBOPiWIhCcIrfWYkXsxHC9eLnAzf1jFwxUMo4ldOwVdkws+ycGcYhNb0KSbCzw0O C4n+/tzq86WlcgXa71hrpX2X4xdV98QlTfLWSdV9eMMuo+SNWmqX+Pc8GVwjH0UY7Wuj nzdg== X-Gm-Message-State: AO0yUKUUTeOv8dTr/72Di7QLbdC/OQmPWGtkbxZwL00ttApNCuYc+l+M MYjchWxLsjzegAOgbzvzSBOB3F5g1SrHuRFcT6c= X-Google-Smtp-Source: AK7set/deFovlaNYgO8E5VrAF9+pwvizl/HfltksDBgo6pyyRMy5cPapNKc418MOETcTmcBmWF2/zw== X-Received: by 2002:a17:902:ec85:b0:199:49fc:6104 with SMTP id x5-20020a170902ec8500b0019949fc6104mr7529100plg.51.1677031235871; Tue, 21 Feb 2023 18:00:35 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, "Edgar E . Iglesias" Subject: [PULL v2 6/8] target/microblaze: Add gdbstub xml Date: Tue, 21 Feb 2023 16:00:21 -1000 Message-Id: <20230222020023.904232-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222020023.904232-1-richard.henderson@linaro.org> References: <20230222020023.904232-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1677031284859100009 Content-Type: text/plain; charset="utf-8" Mirroring the upstream gdb xml files, the two stack boundary registers are separated out. Reviewed-by: Edgar E. Iglesias Signed-off-by: Richard Henderson --- target/microblaze/cpu.h | 2 + target/microblaze/cpu.c | 7 ++- target/microblaze/gdbstub.c | 51 +++++++++++----- 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 + 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/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 re= g); =20 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" =20 static const struct { @@ -294,6 +295,9 @@ static void mb_cpu_initfn(Object *obj) CPUMBState *env =3D &cpu->env; =20 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); =20 set_float_rounding_mode(float_round_nearest_even, &env->fp_status); =20 @@ -422,7 +426,8 @@ static void mb_cpu_class_init(ObjectClass *oc, void *da= ta) cc->sysemu_ops =3D &mb_sysemu_ops; #endif device_class_set_props(dc, mb_properties); - cc->gdb_num_core_regs =3D 32 + 27; + cc->gdb_num_core_regs =3D 32 + 25; + cc->gdb_core_xml_file =3D "microblaze-core.xml"; =20 cc->disas_set_info =3D mb_disas_set_info; cc->tcg_ops =3D &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 =3D 32 + 6, GDB_PVR11 =3D 32 + 17, GDB_EDR =3D 32 + 18, - GDB_SLR =3D 32 + 25, - GDB_SHR =3D 32 + 26, +}; + +enum { + GDB_SP_SHL, + GDB_SP_SHR, }; =20 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 *m= em_buf, int n) case GDB_EDR: val =3D env->edr; break; - case GDB_SLR: - val =3D env->slr; - break; - case GDB_SHR: - val =3D env->shr; - break; default: /* Other SRegs aren't modeled, so report a value of 0 */ val =3D 0; @@ -97,6 +94,23 @@ int mb_cpu_gdb_read_register(CPUState *cs, GByteArray *m= em_buf, int n) return gdb_get_reg32(mem_buf, val); } =20 +int mb_cpu_gdb_read_stack_protect(CPUMBState *env, GByteArray *mem_buf, in= t n) +{ + uint32_t val; + + switch (n) { + case GDB_SP_SHL: + val =3D env->slr; + break; + case GDB_SP_SHR: + val =3D 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 =3D 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 =3D tmp; break; - case GDB_SLR: - env->slr =3D tmp; - break; - case GDB_SHR: - env->shr =3D 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 =3D ldl_p(mem_buf); + break; + case GDB_SP_SHR: + env->shr =3D ldl_p(mem_buf); + break; + default: + return 0; } return 4; } diff --git a/configs/targets/microblaze-linux-user.mak b/configs/targets/mi= croblaze-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=3Dcommon TARGET_SYSTBL=3Dsyscall.tbl TARGET_BIG_ENDIAN=3Dy TARGET_HAS_BFLT=3Dy +TARGET_XML_FILES=3Dgdb-xml/microblaze-core.xml gdb-xml/microblaze-stack-pr= otect.xml diff --git a/configs/targets/microblaze-softmmu.mak b/configs/targets/micro= blaze-softmmu.mak index 8385e2d333..e84c0cc728 100644 --- a/configs/targets/microblaze-softmmu.mak +++ b/configs/targets/microblaze-softmmu.mak @@ -2,3 +2,4 @@ TARGET_ARCH=3Dmicroblaze TARGET_BIG_ENDIAN=3Dy TARGET_SUPPORTS_MTTCG=3Dy TARGET_NEED_FDT=3Dy +TARGET_XML_FILES=3Dgdb-xml/microblaze-core.xml gdb-xml/microblaze-stack-pr= otect.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=3Dmicroblaze TARGET_SYSTBL_ABI=3Dcommon TARGET_SYSTBL=3Dsyscall.tbl TARGET_HAS_BFLT=3Dy +TARGET_XML_FILES=3Dgdb-xml/microblaze-core.xml gdb-xml/microblaze-stack-pr= otect.xml diff --git a/configs/targets/microblazeel-softmmu.mak b/configs/targets/mic= roblazeel-softmmu.mak index af40391f2f..9b688036bd 100644 --- a/configs/targets/microblazeel-softmmu.mak +++ b/configs/targets/microblazeel-softmmu.mak @@ -1,3 +1,4 @@ TARGET_ARCH=3Dmicroblaze TARGET_SUPPORTS_MTTCG=3Dy TARGET_NEED_FDT=3Dy +TARGET_XML_FILES=3Dgdb-xml/microblaze-core.xml gdb-xml/microblaze-stack-pr= otect.xml 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-stac= k-protect.xml new file mode 100644 index 0000000000..997301e8a2 --- /dev/null +++ b/gdb-xml/microblaze-stack-protect.xml @@ -0,0 +1,12 @@ + + + + + + + + --=20 2.34.1 From nobody Mon Feb 9 21:01:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1677031293; cv=none; d=zohomail.com; s=zohoarc; b=C4do42vEPPuPlvPK2U6MprUqLl+73MRs+q0vkKsQgU1kiS727XC3M8qwTy5rhijDhCWMjWQyiT/kXr7gpa2P3nE+fXh+XVk6wF3xJWAQ1vXaU+K5yFWD2yjUfjZkKKcPosRYvjLE9vyo0fMz88MfxbdAVPLlKKj22m0AqllefmA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677031293; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5QZ5Dbtl92tzklOChDMe8O5bqURzi4Z13sfncMd8SRE=; b=d3Jk8IAP/x9KvmqChrs6OjwvL4ZuNU1V+KxTC1Gw/hdBq08v6MaTCYdMOfBgLkNG9XeqvUBnQ6eh6k1I5FeTfvxEM2XxThbA0+nPJ+hPZqMDzuxOqkmhI1zyGn2viWcIYevfXHWp8YKCklLrAuvnaiBgX1sLy/SzZlAnhpfLfzA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1677031293606924.9722609314697; Tue, 21 Feb 2023 18:01:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUeRA-0003Ck-9r; Tue, 21 Feb 2023 21:00: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 1pUeQy-00036V-HO for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:41 -0500 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUeQw-00015H-Tj for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:40 -0500 Received: by mail-pj1-x102c.google.com with SMTP id z20-20020a17090a8b9400b002372d7f823eso3070855pjn.4 for ; Tue, 21 Feb 2023 18:00:38 -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 2-20020a170902c10200b00189743ed3b6sm91468pli.64.2023.02.21.18.00.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 18:00:36 -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=5QZ5Dbtl92tzklOChDMe8O5bqURzi4Z13sfncMd8SRE=; b=Z1+55IcG/uq/6iFXCHXoiP/xCutgmWb/8q4BiZ9mATE+IP42/ImueqxVQgNM1B8nfT twGCODE8Q9l631mbd6xILrHWSUi8/1pRlQMP+5YHLYrntNVDxIxMkUvcwJmJO/sSIcoJ cwyOb5M521KS3CoARN+CWXXtZuJwbi86cqHlugt5w/k981hkonZ9oJ7SxeGaJE8SOE1C 5t47H051GFSRrcZRINPsKqqTVMYGC1/NvKn3+z5EHWwBGfuXeqbi1GqSpmCjWawQ1JeN ZMBz3L7HY0iI+giVf2Eq9p2yvLlTHAiR7AdtQwK27hEktECe9kiU2kVDqDWQFWOb5ME6 02qg== 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=5QZ5Dbtl92tzklOChDMe8O5bqURzi4Z13sfncMd8SRE=; b=Sl6El3xuUYk9xSjQfOvrtBcUwh2yhSD0D0UjoujvHo15WktDYC/qQi+kUhOHh/OYcM RKedmq4FbP4uB0wnNBczSRztIVFIts6S/dxENmp7IXcLdY5Ymve6PeyZVP3zVCDF/h18 C5ryfLhMQwCAiISw9GcujufEuugN1CaHc3/FC4jxd9fqXwlXtNgg/esILnajJGg26CIH oVrpGYMB11lxZwEvvO09YQSdden3zsedp59PTqKy0/v5rnkowHCJFvYFjLB0umULv96m 491Iu4MDL9tK+WAiVPunbKRrHE9zQ0atstlIACiYuJB7QweR4nd/he02XKY+w1Hr9k2A gqug== X-Gm-Message-State: AO0yUKVv0Ar3N0WGt0MJ5Eu7lK4EyRDesxZ4xTaJ511dXBZijcs4067w PuO+CGBw7d7uC7kMWg/N/Hpgsgqv2GiabadcgBs= X-Google-Smtp-Source: AK7set/Z6K/j2j5LqwDWVz8KZgGS33bC+80x0UnHxVR90g6juZdlPehuaLRwsAqdZ7QCB4KX78rt9g== X-Received: by 2002:a17:903:22c8:b0:192:4f85:b91d with SMTP id y8-20020a17090322c800b001924f85b91dmr7843024plg.46.1677031237330; Tue, 21 Feb 2023 18:00:37 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Pierrick Bouvier Subject: [PULL v2 7/8] util/cacheflush: fix cache on windows-arm64 Date: Tue, 21 Feb 2023 16:00:22 -1000 Message-Id: <20230222020023.904232-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222020023.904232-1-richard.henderson@linaro.org> References: <20230222020023.904232-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1677031294864100001 Content-Type: text/plain; charset="utf-8" From: Pierrick Bouvier ctr_el0 access is privileged on this platform and fails as an illegal instruction. Windows does not offer a way to flush data cache from userspace, and only FlushInstructionCache is available in Windows API. The generic implementation of flush_idcache_range uses, __builtin___clear_cache, which already use the FlushInstructionCache function. So we rely on that. Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson Message-Id: <20230221153006.20300-2-pierrick.bouvier@linaro.org> Signed-off-by: Richard Henderson --- util/cacheflush.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/util/cacheflush.c b/util/cacheflush.c index 2c2c73e085..06c2333a60 100644 --- a/util/cacheflush.c +++ b/util/cacheflush.c @@ -121,8 +121,12 @@ static void sys_cache_info(int *isize, int *dsize) static bool have_coherent_icache; #endif =20 -#if defined(__aarch64__) && !defined(CONFIG_DARWIN) -/* Apple does not expose CTR_EL0, so we must use system interfaces. */ +#if defined(__aarch64__) && !defined(CONFIG_DARWIN) && !defined(CONFIG_WIN= 32) +/* + * Apple does not expose CTR_EL0, so we must use system interfaces. + * Windows neither, but we use a generic implementation of flush_idcache_r= ange + * in this case. + */ static uint64_t save_ctr_el0; static void arch_cache_info(int *isize, int *dsize) { @@ -225,7 +229,11 @@ static void __attribute__((constructor)) init_cache_in= fo(void) =20 /* Caches are coherent and do not require flushing; symbol inline. */ =20 -#elif defined(__aarch64__) +#elif defined(__aarch64__) && !defined(CONFIG_WIN32) +/* + * For Windows, we use generic implementation of flush_idcache_range, that + * performs a call to FlushInstructionCache, through __builtin___clear_cac= he. + */ =20 #ifdef CONFIG_DARWIN /* Apple does not expose CTR_EL0, so we must use system interfaces. */ --=20 2.34.1 From nobody Mon Feb 9 21:01:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1677031325; cv=none; d=zohomail.com; s=zohoarc; b=KOKAmflqttSzXeCubZnII9RuPSfIcJRU1cBjq9bfVnmxB/HFhQpwrItvcrROim+knFUiOsKmCN8E0bMTtueMTsRMEHx4EymuWeqzVoxdEMJEuAJUjEOidfBCYJmDGhnl14GnlbAUcQ23w+CBi3FT98naEhMawfZvKGEvrevyJvc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677031325; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=65HRmCDkLuuur1UpqMIRZDfCJCF1ZUxrkWbM7vUK1aI=; b=VCMBoMS8XujiaOea2d2UI/WEzCH+RFy1funPUT1idBvPrT04jjyLyJx0xQpH64KsbpZHdvyppBZ09Lln/SQvyycvAmd5L25OOAL5Gf0EQC+2WpicKQdjL8c3VN/29HXJ+4F4BZmaS3T/KSV11uofqm//IiASefSRPb+7a7sZqXk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167703132569970.98168793412913; Tue, 21 Feb 2023 18:02:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUeRA-0003Cl-NC; Tue, 21 Feb 2023 21:00: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 1pUeR0-00037J-7X for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:43 -0500 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUeQy-00015S-EX for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:41 -0500 Received: by mail-pj1-x102b.google.com with SMTP id c23so2310361pjo.4 for ; Tue, 21 Feb 2023 18:00:40 -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 2-20020a170902c10200b00189743ed3b6sm91468pli.64.2023.02.21.18.00.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 18:00:38 -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=65HRmCDkLuuur1UpqMIRZDfCJCF1ZUxrkWbM7vUK1aI=; b=pjrQaHseri1q4CL5gVJIWmZ1kBqPVGiL5DWP18cRyHRB8oviGCOGoXwgypU2JP4BgH sB9SgVwaC2N3hfT+CPykUjJOeTX8kxSk2IJ5q+LrKoXXB1x41iG1c3uHJwMI35VCxxKn A+pHGZjSfnewj22J8YXmhDL7ANbiffzV7Fw7xSagWl5mr0Eo94qNG71v+SrO/of0RBdh Wcx7H3+PV8zBCdPoaMWnwz0r1soKm1RJIJCKbXVPwYKXVVQevd9Mmo+BEze+JUcc2xD8 E3J++vHO0oLhbMHkELcdOb8rKTZRa3dJJzgjBLfdge4C2zOmB0T4DhSoHhwwci1RgrBV gjjQ== 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=65HRmCDkLuuur1UpqMIRZDfCJCF1ZUxrkWbM7vUK1aI=; b=2zdlP8qmbVc16oi5V7gfF91ZW86/eF7FfSkG0O7t27exhn8elOL5TWpdkxmQhTlNu7 UoWrnjSc9PZa/HTs04OVYnC3B1kbw7Xs4la/mMhvFgdNBELGhNXEvHa8z6wxadAbpzmp ZnsTj5G6Ta7h8Vok8dO72WA0Fg/LiYXtIx8n6tGI6lMylBRWZf/I7rY4QKG+YJBOTPn2 OHnNst+g0LfQo6u3aqPih5eqKuc46B4ff9z89uS5sVNnlDMmOQkpgMTAxJOzC4R59wrN DJPNa84weYR2eUk/WFRyY2mK/oX6FYmbJpFEoRXvwHPvHLfSbG3peUbWV4EHgRrDT9ko NRfA== X-Gm-Message-State: AO0yUKUeQD+r9RmNNgP0UIzLVYdVkE/NNmXmVMy4es0cztQRnvCoDYNw x5O15ZQQfFAmxoisQqnYaoSwDf6TQ3MT8C+gsys= X-Google-Smtp-Source: AK7set+P65eQDVR10CbQYxxLvZfrmpF8OJ1rr89ONw0m/OB4R3Vz3dOIbwXcdRKUUaxwAPyi7NbPJg== X-Received: by 2002:a17:902:76c9:b0:19c:a6d6:7d25 with SMTP id j9-20020a17090276c900b0019ca6d67d25mr1031515plt.37.1677031239018; Tue, 21 Feb 2023 18:00:39 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Pierrick Bouvier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL v2 8/8] sysemu/os-win32: fix setjmp/longjmp on windows-arm64 Date: Tue, 21 Feb 2023 16:00:23 -1000 Message-Id: <20230222020023.904232-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222020023.904232-1-richard.henderson@linaro.org> References: <20230222020023.904232-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1677031326970100002 From: Pierrick Bouvier Windows implementation of setjmp/longjmp is done in C:/WINDOWS/system32/ucrtbase.dll. Alas, on arm64, it seems to *always* perform stack unwinding, which crashes from generated code. By using alternative implementation built in mingw, we avoid doing stack unwinding and this fixes crash when calling longjmp. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Pierrick Bouvier Acked-by: Richard Henderson Message-Id: <20230221153006.20300-3-pierrick.bouvier@linaro.org> Signed-off-by: Richard Henderson --- include/sysemu/os-win32.h | 28 ++++++++++++++++++++++++---- meson.build | 21 +++++++++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h index 5b38c7bd04..97d0243aee 100644 --- a/include/sysemu/os-win32.h +++ b/include/sysemu/os-win32.h @@ -51,14 +51,34 @@ typedef struct sockaddr_un { extern "C" { #endif =20 -#if defined(_WIN64) -/* On w64, setjmp is implemented by _setjmp which needs a second parameter. +#if defined(__aarch64__) +/* + * On windows-arm64, setjmp is available in only one variant, and longjmp = always + * does stack unwinding. This crash with generated code. + * Thus, we use another implementation of setjmp (not windows one), coming= from + * mingw, which never performs stack unwinding. + */ +#undef setjmp +#undef longjmp +/* + * These functions are not declared in setjmp.h because __aarch64__ defines + * setjmp to _setjmpex instead. However, they are still defined in libming= wex.a, + * which gets linked automatically. + */ +extern int __mingw_setjmp(jmp_buf); +extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int); +#define setjmp(env) __mingw_setjmp(env) +#define longjmp(env, val) __mingw_longjmp(env, val) +#elif defined(_WIN64) +/* + * On windows-x64, setjmp is implemented by _setjmp which needs a second p= arameter. * If this parameter is NULL, longjump does no stack unwinding. * That is what we need for QEMU. Passing the value of register rsp (defau= lt) - * lets longjmp try a stack unwinding which will crash with generated code= . */ + * lets longjmp try a stack unwinding which will crash with generated code. + */ # undef setjmp # define setjmp(env) _setjmp(env, NULL) -#endif +#endif /* __aarch64__ */ /* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify * "longjmp and don't touch the signal masks". Since we know that the * savemask parameter will always be zero we can safely define these diff --git a/meson.build b/meson.build index bc7e5b1d15..6a139e7085 100644 --- a/meson.build +++ b/meson.build @@ -2466,6 +2466,27 @@ if targetos =3D=3D 'windows' }''', name: '_lock_file and _unlock_file')) endif =20 +if targetos =3D=3D 'windows' + mingw_has_setjmp_longjmp =3D cc.links(''' + #include + int main(void) { + /* + * These functions are not available in setjmp header, but may be + * available at link time, from libmingwex.a. + */ + extern int __mingw_setjmp(jmp_buf); + extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int); + jmp_buf env; + __mingw_setjmp(env); + __mingw_longjmp(env, 0); + } + ''', name: 'mingw setjmp and longjmp') + + if cpu =3D=3D 'aarch64' and not mingw_has_setjmp_longjmp + error('mingw must provide setjmp/longjmp for windows-arm64') + endif +endif + ######################## # Target configuration # ######################## --=20 2.34.1