From patchwork Fri Jun 23 08:19:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1798783 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=kNxJBLTa; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QnVZ91gn9z20XS for ; Fri, 23 Jun 2023 18:21:21 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCc1w-0000ff-GH; Fri, 23 Jun 2023 04:20:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qCc1s-0000dT-9l; Fri, 23 Jun 2023 04:20:29 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qCc1n-0002hP-Ct; Fri, 23 Jun 2023 04:20:27 -0400 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-517ab9a4a13so372896a12.1; Fri, 23 Jun 2023 01:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687508418; x=1690100418; 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=2+mfnEVCvr63N6fHKwMF6YaPrDB5JFpRkwNfrijFFDY=; b=kNxJBLTaC1mVHt/qlkHAi1KxnTtINMSL7aWQwqerSTnvkIAy7GC0IMOC7L2tZ2gHmF 1FeCNnaW3JxuUdc77/EDPcup9VnUJ5mTO68mE8HOfEKbWwi+uf6/M868mUJ+T9mdE4EA WvdayHSWMrxFpTjqiMoSck61jkfg7ntHeIx5GwwRQNlyrkpjiDTDLiR3bls/2jn1mrjL Trf1mDaKOm0lx/tyMg7LdFu0pdRphjjV/qlScUgqah9QmH4XrrVTlTSSx8QOs3FgljIW uyCEOmUJd0uHgEyDfPno5/W60g7VTQoDgwhz5KD91WNm3FgrLWdHbc7yE3j+moEER7Qn fWVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687508418; x=1690100418; 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=2+mfnEVCvr63N6fHKwMF6YaPrDB5JFpRkwNfrijFFDY=; b=fee/+pxUZu6LV4hJx4A9vP8w+dmK/Ez5hBdEd4GwBJCHYrcFH5NGwMiD1T8oQzX21z mEc9KcRGihP/t/ucI70MTaQi7OzryNq8FYVsjXWfNNH04vy2DztW5Ld/tea0ztX7cBnE H6xvZoUBG2NVCoScHPkBObB5XerMvQXaMb/Hwlv4C6QIBezO0PZbNAG+mTT1U4xhwQaT fwS7blXIWO/uutmqoJ0cfH3JwVn0qlaZYWWhDWEkvc8fiz0DxNSULenPSD7s63zLonah ATvGcvAxGqlIox6CVcqZ5B2F9hKKHd08hw+X3+SNHMBv5ZqEfSJqF8nhfpi17ybznarK GT0w== X-Gm-Message-State: AC+VfDz4bhMK3vF4cnuP3EmSouG4wag/9O/Selj3On+mBx9oDc672CfV N7jTL2cGa8CvlkpYXUUzA7mkM+z52ok= X-Google-Smtp-Source: ACHHUZ6COH0Wqx5noo2vtg4wCmpmxjHNgg5e1PBHQdz6p2tpG4cF6q2dW0uk7ZgAGKvA1z1W+MxojQ== X-Received: by 2002:a05:6a20:4328:b0:125:377c:831d with SMTP id h40-20020a056a20432800b00125377c831dmr4134452pzk.3.1687508417723; Fri, 23 Jun 2023 01:20:17 -0700 (PDT) Received: from wheely.local0.net ([1.146.27.231]) by smtp.gmail.com with ESMTPSA id s15-20020a62e70f000000b0066884d4efdbsm5780604pfh.12.2023.06.23.01.20.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 01:20:17 -0700 (PDT) From: Nicholas Piggin To: qemu-ppc@nongnu.org Cc: Nicholas Piggin , qemu-devel@nongnu.org, Christophe Leroy , BALATON Zoltan , Harsh Prateek Bora , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz Subject: [PATCH 1/4] target/ppc: Machine check on invalid real address access Date: Fri, 23 Jun 2023 18:19:50 +1000 Message-Id: <20230623081953.290875-2-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623081953.290875-1-npiggin@gmail.com> References: <20230623081953.290875-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=npiggin@gmail.com; helo=mail-pg1-x532.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org ppc currently silently accepts invalid real address access. Catch these and turn them into machine checks. POWER9/10 machine check codes for invalid real address access are implemented. Signed-off-by: Nicholas Piggin --- target/ppc/cpu_init.c | 1 + target/ppc/excp_helper.c | 35 +++++++++++++++++++++++++++++++++++ target/ppc/internal.h | 5 +++++ 3 files changed, 41 insertions(+) diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index 7bce421a7c..3b23f2d5b6 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -7267,6 +7267,7 @@ static const struct TCGCPUOps ppc_tcg_ops = { .cpu_exec_enter = ppc_cpu_exec_enter, .cpu_exec_exit = ppc_cpu_exec_exit, .do_unaligned_access = ppc_cpu_do_unaligned_access, + .do_transaction_failed = ppc_cpu_do_transaction_failed, #endif /* !CONFIG_USER_ONLY */ }; #endif /* CONFIG_TCG */ diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index 12d8a7257b..c9bfa3a827 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -1402,7 +1402,9 @@ static void powerpc_excp_books(PowerPCCPU *cpu, int excp) /* machine check exceptions don't have ME set */ new_msr &= ~((target_ulong)1 << MSR_ME); + msr |= env->error_code; break; + case POWERPC_EXCP_DSI: /* Data storage exception */ trace_ppc_excp_dsi(env->spr[SPR_DSISR], env->spr[SPR_DAR]); break; @@ -3123,5 +3125,38 @@ void ppc_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr, env->error_code = insn & 0x03FF0000; cpu_loop_exit(cs); } + +void ppc_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, + vaddr vaddr, unsigned size, + MMUAccessType access_type, + int mmu_idx, MemTxAttrs attrs, + MemTxResult response, uintptr_t retaddr) +{ + CPUPPCState *env = cs->env_ptr; + + switch (env->excp_model) { +#if defined(TARGET_PPC64) + case POWERPC_EXCP_970: + case POWERPC_EXCP_POWER7: + case POWERPC_EXCP_POWER8: + case POWERPC_EXCP_POWER9: + case POWERPC_EXCP_POWER10: + /* + * TODO: This does not give the correct machine check code but + * it will report a NIP and DAR. + */ + if (access_type == MMU_DATA_LOAD || access_type == MMU_DATA_STORE) { + env->spr[SPR_DAR] = vaddr; + } + break; +#endif + default: + /* TODO: Check behaviour for other CPUs, for now do nothing. */ + return; + } + + cs->exception_index = POWERPC_EXCP_MCHECK; + cpu_loop_exit_restore(cs, retaddr); +} #endif /* CONFIG_TCG */ #endif /* !CONFIG_USER_ONLY */ diff --git a/target/ppc/internal.h b/target/ppc/internal.h index 901bae6d39..57acb3212c 100644 --- a/target/ppc/internal.h +++ b/target/ppc/internal.h @@ -296,6 +296,11 @@ bool ppc_cpu_tlb_fill(CPUState *cs, vaddr address, int size, G_NORETURN void ppc_cpu_do_unaligned_access(CPUState *cs, vaddr addr, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr); +void ppc_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, + vaddr addr, unsigned size, + MMUAccessType access_type, + int mmu_idx, MemTxAttrs attrs, + MemTxResult response, uintptr_t retaddr); #endif FIELD(GER_MSK, XMSK, 0, 4) From patchwork Fri Jun 23 08:19:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1798782 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=b2rgyYMa; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QnVZ91nfHz20Xk for ; Fri, 23 Jun 2023 18:21:21 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCc1w-0000fr-QB; Fri, 23 Jun 2023 04:20:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qCc1t-0000dX-6P; Fri, 23 Jun 2023 04:20:29 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qCc1p-0002lz-Pv; Fri, 23 Jun 2023 04:20:28 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-666ecf9a0ceso152720b3a.2; Fri, 23 Jun 2023 01:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687508423; x=1690100423; 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=Y2MH4VazMgtpKVZkWlVs9pGXSlLjfIVFBDMD0/bLia4=; b=b2rgyYMaoOAfnVeURC9CIRhYOm4VUUoIabJpCpkmhMapJCeSeGQlCZvKlDAgaNd4TG MRISqcDSwkCf5I/1fkAZH4cmtDWsyJhTHbfaNZPT2o/8bplA0GBjmGWrPhDqbmd6cf2u 78tUFNDO48H3rc56onj9Ou99mXQmi/qJ7l/5x2M/MjR4SKRciClAs2clCNJA5enpWRdm I1VhpNvuZdj1q5+2EdIh7GifAZtFDFYL7DF1PB5O8kUvnU/LLgnIvjolROdXS85KwzPs d6o77EF55oDvlXWahikbsE0Oj+dlp/SjL6O8rAblGTigyMqmjav2oLkVNvVhYyXFgYSq vM+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687508423; x=1690100423; 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=Y2MH4VazMgtpKVZkWlVs9pGXSlLjfIVFBDMD0/bLia4=; b=S7g14pkkp7+4Ctycn8QoxGBSBKDC/n1Oukb7yoPa/Wqus4VCdqPzzxJM1RzYfnltqe N52ag8Qi44qTewBVKaSC47RHh4NDKZYbyOmIzzSCd5CxWOTdxpdX/EJDlL3Ey38L14t4 5Dn4CQb0AG/4jbhRIGqlXLq3AYEOuo+NuZKpFL+iANVT6oPBasaCTtoap3xyEz+afrhZ bpva/UK2sQbkqp0hpqZ37gQNbbCh9aqkW8sHdjVzyHhkpmNQKT8bOcKyqNDKp0ubTY+w S2zrD96SWpLt/+QoVURoczmZGBmwxDMk+xRCdhtLffaOSf5ZkN1feXYhSKoS1VNSkGTD EXsA== X-Gm-Message-State: AC+VfDx5rzy1Jzigfm9V2ukq7TZ1C7G2Eu5OImyHENT+xiTqQnxyv/lI RDX9xTSROBmknZmvQ+3DUFWdtTnEK4Y= X-Google-Smtp-Source: ACHHUZ7/gHnVryNP1x34z6x/SB74LU9UG3BUbT2gky/wdgbBZfgT0Cyc1xpCm1oL4GDbO8on6gXvBA== X-Received: by 2002:a05:6a20:7f93:b0:10b:8bc7:e112 with SMTP id d19-20020a056a207f9300b0010b8bc7e112mr22140741pzj.10.1687508423195; Fri, 23 Jun 2023 01:20:23 -0700 (PDT) Received: from wheely.local0.net ([1.146.27.231]) by smtp.gmail.com with ESMTPSA id s15-20020a62e70f000000b0066884d4efdbsm5780604pfh.12.2023.06.23.01.20.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 01:20:22 -0700 (PDT) From: Nicholas Piggin To: qemu-ppc@nongnu.org Cc: Nicholas Piggin , qemu-devel@nongnu.org, Christophe Leroy , BALATON Zoltan , Harsh Prateek Bora , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz Subject: [PATCH 2/4] target/ppc: Add POWER9/10 invalid-real machine check codes Date: Fri, 23 Jun 2023 18:19:51 +1000 Message-Id: <20230623081953.290875-3-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623081953.290875-1-npiggin@gmail.com> References: <20230623081953.290875-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=npiggin@gmail.com; helo=mail-pf1-x42e.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Implement the correct register settings for the invalid-real access machine check for POWER9/10 processors. Signed-off-by: Nicholas Piggin --- target/ppc/excp_helper.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index c9bfa3a827..1c26828d8b 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -3139,8 +3139,6 @@ void ppc_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, case POWERPC_EXCP_970: case POWERPC_EXCP_POWER7: case POWERPC_EXCP_POWER8: - case POWERPC_EXCP_POWER9: - case POWERPC_EXCP_POWER10: /* * TODO: This does not give the correct machine check code but * it will report a NIP and DAR. @@ -3149,6 +3147,30 @@ void ppc_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, env->spr[SPR_DAR] = vaddr; } break; + case POWERPC_EXCP_POWER9: + case POWERPC_EXCP_POWER10: + /* + * Machine check codes can be found in User Manual or Linux or + * skiboot source. + */ + if (access_type == MMU_DATA_LOAD) { + env->spr[SPR_DAR] = vaddr; + env->spr[SPR_DSISR] = PPC_BIT(57); + env->error_code = PPC_BIT(42); + + } else if (access_type == MMU_DATA_STORE) { + /* + * MCE for stores in POWER is asynchronous so hardware does + * not set DAR, but QEMU can do better. + */ + env->spr[SPR_DAR] = vaddr; + env->error_code = PPC_BIT(36) | PPC_BIT(43) | PPC_BIT(45); + env->error_code |= PPC_BIT(42); + } else { /* Fetch */ + + env->error_code = PPC_BIT(36) | PPC_BIT(44) | PPC_BIT(45); + } + break; #endif default: /* TODO: Check behaviour for other CPUs, for now do nothing. */ From patchwork Fri Jun 23 08:19:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1798787 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=FTt9tmP5; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QnVZh1RV5z20XS for ; Fri, 23 Jun 2023 18:21:48 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCc20-0000iT-D1; Fri, 23 Jun 2023 04:20:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qCc1y-0000h6-Ei; Fri, 23 Jun 2023 04:20:34 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qCc1u-0002pV-LN; Fri, 23 Jun 2023 04:20:34 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-66615629689so201689b3a.2; Fri, 23 Jun 2023 01:20:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687508428; x=1690100428; 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=mSMu7K59gsJkKuMnSScWtyJ//9NCTa8sk+fznKryss4=; b=FTt9tmP5hmjg3e9iH7J5Wj5cABIWNdGjDXbPDftm7VrXLC6xoYYuCaLuEZ/fKvO4NO iqIfkzPIhhJUD31Yg0THYTzMEUs4kSSzf1SyJhW1r0HfeIAo0REbmUD72YohcNM+kiDp DewVynTDqW/Zy/WVHpS8kePOdlfCCP3GEi7Ug82RyxAmq0cbaImsTW87D3+o2M0SOOUZ +KSXaMoNCQ8yR03gDDE/fO+q3b4YsihzRMiEhysI9IwEmf/90hQYJI4ZYTfFmfdWS7qR xKGW3zAjcOOp1vV9x3QDJiVJiBngqtC0QoiG3z3DndULF9vhRyM4E5z0yDImFBVNZZC0 2wKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687508428; x=1690100428; 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=mSMu7K59gsJkKuMnSScWtyJ//9NCTa8sk+fznKryss4=; b=UclMArc7TJSJvJlgnjcXcs7tP25fhosVChyZ3x4F+gT5um6lS10qLxaErFd2YkHVkY 63XAA5gc6bbyLlHoJavnOlotEuM0blMfH2JUHGGrpsgyaR6rYN4gEKMHcBYbtGniycPE e4EV9xnM3Be0JSz6Iw9jCAbDbFALG/7UA9zfsMGxn50f7aaE56OVpsO01vbXQ7MCHrMO mhY2UFA3D48X6c1Z0tp/KZNmpYCr+rM4Vfk9n/1iQ6stKQaOQrQr5MvjKsAvuMl5eoWV MK5AYUrD+91xQbMv4MybF6tRu+BlcnJ8xStqq3BeWjTdNU7OT4Wpr+ZPCewwzYF3famc 7PKQ== X-Gm-Message-State: AC+VfDzkdDT1NEW+UWlIC08+Chyz5pdcPuhagL4jJ5uqsScL0gpC+NT3 41cOBaKazT/fXjZwR8Gu/yhUSCpFWZ4= X-Google-Smtp-Source: ACHHUZ4WzmdABzN3af1zOLsg4YkJItSBELlYbfRbp1mEhy0Tkwfu0wnp8QHpoxryjvdT+QpgYGhpXQ== X-Received: by 2002:a05:6a00:17a6:b0:666:e954:8ab5 with SMTP id s38-20020a056a0017a600b00666e9548ab5mr25767770pfg.5.1687508428240; Fri, 23 Jun 2023 01:20:28 -0700 (PDT) Received: from wheely.local0.net ([1.146.27.231]) by smtp.gmail.com with ESMTPSA id s15-20020a62e70f000000b0066884d4efdbsm5780604pfh.12.2023.06.23.01.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 01:20:28 -0700 (PDT) From: Nicholas Piggin To: qemu-ppc@nongnu.org Cc: Nicholas Piggin , qemu-devel@nongnu.org, Christophe Leroy , BALATON Zoltan , Harsh Prateek Bora , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz Subject: [PATCH 3/4] target/ppc: Move common check in machne check handlers to a function Date: Fri, 23 Jun 2023 18:19:52 +1000 Message-Id: <20230623081953.290875-4-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623081953.290875-1-npiggin@gmail.com> References: <20230623081953.290875-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=npiggin@gmail.com; helo=mail-pf1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: BALATON Zoltan All powerpc exception handlers share some code when handling machine check exceptions. Move this to a common function. Reviewed-by: Nicholas Piggin Signed-off-by: BALATON Zoltan [np: tweak subject, rename function to powerpc_mcheck_test_and_checkstop] Signed-off-by-by: Nicholas Piggin --- target/ppc/excp_helper.c | 114 +++++++++------------------------------ 1 file changed, 25 insertions(+), 89 deletions(-) diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index 1c26828d8b..4bfcfc3c3d 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -404,6 +404,25 @@ static void powerpc_set_excp_state(PowerPCCPU *cpu, target_ulong vector, env->reserve_addr = -1; } +static void powerpc_mcheck_test_and_checkstop(CPUPPCState *env) +{ + CPUState *cs = env_cpu(env); + + if (FIELD_EX64(env->msr, MSR, ME)) { + return; + } + + /* Machine check exception is not enabled. Enter checkstop state. */ + fprintf(stderr, "Machine check while not allowed. " + "Entering checkstop state\n"); + if (qemu_log_separate()) { + qemu_log("Machine check while not allowed. " + "Entering checkstop state\n"); + } + cs->halted = 1; + cpu_interrupt_exittb(cs); +} + static void powerpc_excp_40x(PowerPCCPU *cpu, int excp) { CPUState *cs = CPU(cpu); @@ -446,21 +465,7 @@ static void powerpc_excp_40x(PowerPCCPU *cpu, int excp) srr1 = SPR_40x_SRR3; break; case POWERPC_EXCP_MCHECK: /* Machine check exception */ - if (!FIELD_EX64(env->msr, MSR, ME)) { - /* - * Machine check exception is not enabled. Enter - * checkstop state. - */ - fprintf(stderr, "Machine check while not allowed. " - "Entering checkstop state\n"); - if (qemu_log_separate()) { - qemu_log("Machine check while not allowed. " - "Entering checkstop state\n"); - } - cs->halted = 1; - cpu_interrupt_exittb(cs); - } - + powerpc_mcheck_test_and_checkstop(env); /* machine check exceptions don't have ME set */ new_msr &= ~((target_ulong)1 << MSR_ME); @@ -577,21 +582,7 @@ static void powerpc_excp_6xx(PowerPCCPU *cpu, int excp) case POWERPC_EXCP_CRITICAL: /* Critical input */ break; case POWERPC_EXCP_MCHECK: /* Machine check exception */ - if (!FIELD_EX64(env->msr, MSR, ME)) { - /* - * Machine check exception is not enabled. Enter - * checkstop state. - */ - fprintf(stderr, "Machine check while not allowed. " - "Entering checkstop state\n"); - if (qemu_log_separate()) { - qemu_log("Machine check while not allowed. " - "Entering checkstop state\n"); - } - cs->halted = 1; - cpu_interrupt_exittb(cs); - } - + powerpc_mcheck_test_and_checkstop(env); /* machine check exceptions don't have ME set */ new_msr &= ~((target_ulong)1 << MSR_ME); @@ -750,21 +741,7 @@ static void powerpc_excp_7xx(PowerPCCPU *cpu, int excp) switch (excp) { case POWERPC_EXCP_MCHECK: /* Machine check exception */ - if (!FIELD_EX64(env->msr, MSR, ME)) { - /* - * Machine check exception is not enabled. Enter - * checkstop state. - */ - fprintf(stderr, "Machine check while not allowed. " - "Entering checkstop state\n"); - if (qemu_log_separate()) { - qemu_log("Machine check while not allowed. " - "Entering checkstop state\n"); - } - cs->halted = 1; - cpu_interrupt_exittb(cs); - } - + powerpc_mcheck_test_and_checkstop(env); /* machine check exceptions don't have ME set */ new_msr &= ~((target_ulong)1 << MSR_ME); @@ -935,21 +912,7 @@ static void powerpc_excp_74xx(PowerPCCPU *cpu, int excp) switch (excp) { case POWERPC_EXCP_MCHECK: /* Machine check exception */ - if (!FIELD_EX64(env->msr, MSR, ME)) { - /* - * Machine check exception is not enabled. Enter - * checkstop state. - */ - fprintf(stderr, "Machine check while not allowed. " - "Entering checkstop state\n"); - if (qemu_log_separate()) { - qemu_log("Machine check while not allowed. " - "Entering checkstop state\n"); - } - cs->halted = 1; - cpu_interrupt_exittb(cs); - } - + powerpc_mcheck_test_and_checkstop(env); /* machine check exceptions don't have ME set */ new_msr &= ~((target_ulong)1 << MSR_ME); @@ -1130,21 +1093,7 @@ static void powerpc_excp_booke(PowerPCCPU *cpu, int excp) srr1 = SPR_BOOKE_CSRR1; break; case POWERPC_EXCP_MCHECK: /* Machine check exception */ - if (!FIELD_EX64(env->msr, MSR, ME)) { - /* - * Machine check exception is not enabled. Enter - * checkstop state. - */ - fprintf(stderr, "Machine check while not allowed. " - "Entering checkstop state\n"); - if (qemu_log_separate()) { - qemu_log("Machine check while not allowed. " - "Entering checkstop state\n"); - } - cs->halted = 1; - cpu_interrupt_exittb(cs); - } - + powerpc_mcheck_test_and_checkstop(env); /* machine check exceptions don't have ME set */ new_msr &= ~((target_ulong)1 << MSR_ME); @@ -1377,20 +1326,7 @@ static void powerpc_excp_books(PowerPCCPU *cpu, int excp) switch (excp) { case POWERPC_EXCP_MCHECK: /* Machine check exception */ - if (!FIELD_EX64(env->msr, MSR, ME)) { - /* - * Machine check exception is not enabled. Enter - * checkstop state. - */ - fprintf(stderr, "Machine check while not allowed. " - "Entering checkstop state\n"); - if (qemu_log_separate()) { - qemu_log("Machine check while not allowed. " - "Entering checkstop state\n"); - } - cs->halted = 1; - cpu_interrupt_exittb(cs); - } + powerpc_mcheck_test_and_checkstop(env); if (env->msr_mask & MSR_HVB) { /* * ISA specifies HV, but can be delivered to guest with HV From patchwork Fri Jun 23 08:19:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1798781 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=EA2orlZt; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QnVZ64L82z20XS for ; Fri, 23 Jun 2023 18:21:18 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCc22-0000jD-Is; Fri, 23 Jun 2023 04:20:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qCc21-0000ie-0q; Fri, 23 Jun 2023 04:20:37 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qCc1z-0002tB-8F; Fri, 23 Jun 2023 04:20:36 -0400 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-543ae6ce8d1so369719a12.2; Fri, 23 Jun 2023 01:20:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687508433; x=1690100433; 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=TAeWCYAlTb2aqEPCBDmE25oHqVckLOxsVAOrw8DbLjI=; b=EA2orlZtwtDlQ+8Kb/5mJCg6CpoiSYLkaymCe5o8ef9x3VmBHoWtV8WLv3tbxk2S+r im5yxB0CC/5Qtawj9ZusIfkh9ANpOlYRec+9AtODwhn0YUyOFcgbXlEyU+XonwlrHhOc 1P6Ek56nbytxiygPvqwDLjvUyoQQzMRtrzRBUpNIPqiEclSgUiVLBnwVF4QcAFd7T1aY Vif1k2WlcRzlzEWLOdZcE6sJ2uCWPjI/cB+T7HCExvLgQRIIshkOsT3veTVqgG8Z9n2X 9+csGe6TJ+kY0Wf+AC3IqfFnWc+/DHtmtoVRxufUVuIJA2AjDmcYKym9PbVt9qW7Dy38 eePQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687508433; x=1690100433; 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=TAeWCYAlTb2aqEPCBDmE25oHqVckLOxsVAOrw8DbLjI=; b=lApB2WLIB/j48001tLuF2jYag6+BUpvFYqob6w5pqaMiX//CrlYX+YQW/JTFk8tNK7 Y4ArlabuVObksbVack9bbeOnPwkilLEXTHfwxb/SuuTq43zpKwxFvx0KMjAUb2z8asLI jYpItYAago8W+IpNC4IDycL+SxecEkygroC911zGOuok8hpeS1rdAWC0pgKbhBdKmwbu qL9diIZNr7LJw89To2n80VHHxHnNPZ/2QjhPbLHur5xny2Ine4sTrCjZA+rdbL/r1rxW PzuDiP21/biITjY4XRuzZhNris8wgjODrce79SNgmRieMksSUtxWnL12BzM/wj5P1t+V xeww== X-Gm-Message-State: AC+VfDzK2CDgIALnnqBpl3SBmQd216NfV9JjE8+bXPR0DZ4KFDdhv/SO 61/RuxwM1v3zQyAjlsvibCl+881yqeI= X-Google-Smtp-Source: ACHHUZ7gPaKrOKsPUH/tAHf55qI+KQ3p8W8g+fo8VuOQda4lbUHC7Ndv1cJFdRzC0q6RkYyVZmo7HQ== X-Received: by 2002:a05:6a21:78a9:b0:10a:cb95:5aa3 with SMTP id bf41-20020a056a2178a900b0010acb955aa3mr25901059pzc.7.1687508433357; Fri, 23 Jun 2023 01:20:33 -0700 (PDT) Received: from wheely.local0.net ([1.146.27.231]) by smtp.gmail.com with ESMTPSA id s15-20020a62e70f000000b0066884d4efdbsm5780604pfh.12.2023.06.23.01.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 01:20:33 -0700 (PDT) From: Nicholas Piggin To: qemu-ppc@nongnu.org Cc: Nicholas Piggin , qemu-devel@nongnu.org, Christophe Leroy , BALATON Zoltan , Harsh Prateek Bora , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz Subject: [PATCH 4/4] target/ppc: Make checkstop stop the system Date: Fri, 23 Jun 2023 18:19:53 +1000 Message-Id: <20230623081953.290875-5-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230623081953.290875-1-npiggin@gmail.com> References: <20230623081953.290875-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=npiggin@gmail.com; helo=mail-pg1-x52e.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org checkstop state does not halt the system, interrupts continue to be serviced, and other CPUs run. Stop the machine with vm_stop(), and print a register dump too. Signed-off-by: Nicholas Piggin --- target/ppc/excp_helper.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index 4bfcfc3c3d..51e83d7f07 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qemu/main-loop.h" #include "qemu/log.h" +#include "sysemu/runstate.h" #include "cpu.h" #include "exec/exec-all.h" #include "internal.h" @@ -165,6 +166,24 @@ static void ppc_excp_debug_sw_tlb(CPUPPCState *env, int excp) env->error_code); } +static void powerpc_checkstop(PowerPCCPU *cpu, const char *reason) +{ + CPUState *cs = CPU(cpu); + + vm_stop(RUN_STATE_GUEST_PANICKED); + + fprintf(stderr, "Entering checkstop state: %s\n", reason); + cpu_dump_state(cs, stderr, CPU_DUMP_FPU | CPU_DUMP_CCOP); + if (qemu_log_separate()) { + FILE *logfile = qemu_log_trylock(); + if (logfile) { + fprintf(logfile, "Entering checkstop state: %s\n", reason); + cpu_dump_state(cs, logfile, CPU_DUMP_FPU | CPU_DUMP_CCOP); + qemu_log_unlock(logfile); + } + } +} + #if defined(TARGET_PPC64) static int powerpc_reset_wakeup(CPUState *cs, CPUPPCState *env, int excp, target_ulong *msr) @@ -406,21 +425,9 @@ static void powerpc_set_excp_state(PowerPCCPU *cpu, target_ulong vector, static void powerpc_mcheck_test_and_checkstop(CPUPPCState *env) { - CPUState *cs = env_cpu(env); - - if (FIELD_EX64(env->msr, MSR, ME)) { - return; - } - - /* Machine check exception is not enabled. Enter checkstop state. */ - fprintf(stderr, "Machine check while not allowed. " - "Entering checkstop state\n"); - if (qemu_log_separate()) { - qemu_log("Machine check while not allowed. " - "Entering checkstop state\n"); + if (!FIELD_EX64(env->msr, MSR, ME)) { + powerpc_checkstop(env_archcpu(env), "machine check with MSR[ME]=0"); } - cs->halted = 1; - cpu_interrupt_exittb(cs); } static void powerpc_excp_40x(PowerPCCPU *cpu, int excp)