From patchwork Wed Jul 26 18:22:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1813418 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=qb2TeLzH; 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 4RB3Zf5Kvfz1yY5 for ; Thu, 27 Jul 2023 05:18:02 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOjAM-0003vq-3q; Wed, 26 Jul 2023 14:23:19 -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 1qOj9s-0003qs-Q8; Wed, 26 Jul 2023 14:22:48 -0400 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 1qOj9r-0008RE-68; Wed, 26 Jul 2023 14:22:48 -0400 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-2685bcd046eso89834a91.3; Wed, 26 Jul 2023 11:22:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690395765; x=1691000565; 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=Fu3SNX5pWMfAFlu2iRITWI/ZZuTkozaiKRck9Odx43Y=; b=qb2TeLzHRUXsFSEAwyANagQBOBm788fpl9ZiDfhGFgVeZYZDZ1i8NRo4PtEgF+EhzE yWHT5Tp4+OtdEqUo73L/gGrLliw7AyJlbAnLME2o927lVqFCrpqMJS6kWd5Av/kcQm9l 9Cg1AHcwMuyN/9qadMZutSgZGO4by1RfBY3Z+52IXb4CjFanU0YHtl32ALYSJomnKNNl 63XFVnNuGPkxKQw6Cf8LIaE40BzUZ/vFxyZG/bz/5LcUWXEpGnSojqZiV0nJdmjzMN+W cojXhRkenET41mXl/kfWYAoTEBngnwPY/KCnWJdqIPTy1KZUNA5qcoXLxYLlaGa926rN SuTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690395765; x=1691000565; 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=Fu3SNX5pWMfAFlu2iRITWI/ZZuTkozaiKRck9Odx43Y=; b=ZeT22yra57VN/O77sH3hzQOCgcRpgCQZMyOwJdcfvPmpjm6S+MeBcW4bWYOBYTCLc/ x5EHtsp7gvbCV2LpIkGc+QPdn1gXws+eyFeeT9bZY0jlhHRDaw8127kwVs7jqEb1pNmF M3CUDN3JOvL+DZjR/2xcvJcK8DJDy7PGV2DAxercNIGASkhOmAOK833BlVyFOCDMHnDG YB+NkzzT/mFS32IcBMbapr/qbH1QaAagu8WY73Utz+FgNrJ7H6Ag1HXVwJMwyMsH6dRZ kFHk92/bGg+WoV2sizALyMfHi6gGgW9osE4XMqFopKxuRjkGgu+k5G74rg+0Dz1BZ28F gEmg== X-Gm-Message-State: ABy/qLZDwm5VfwdsZwKuIjpWAHaW3Cc7IuRu6p4f0Xr8YxcOdJ843wSE oAmxw4jOCx0F/KqhfGaziLhd+z2Fnos= X-Google-Smtp-Source: APBJJlFKYA3Pdb9lw3igXuBfpChEYpcfFqq7NEzycQOnoFrp3djeFFGZKshn9+mDXdmw2JeXbalY3A== X-Received: by 2002:a17:90b:2388:b0:25e:d013:c22c with SMTP id mr8-20020a17090b238800b0025ed013c22cmr2242675pjb.47.1690395765310; Wed, 26 Jul 2023 11:22:45 -0700 (PDT) Received: from wheely.local0.net ([118.102.104.45]) by smtp.gmail.com with ESMTPSA id b25-20020a639319000000b0055adced9e13sm360185pge.0.2023.07.26.11.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 11:22:45 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?utf-8?q?C=C3=A9dric_Le_Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 1/6] target/ppc: Implement ASDR register for ISA v3.0 for HPT Date: Thu, 27 Jul 2023 04:22:25 +1000 Message-Id: <20230726182230.433945-2-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230726182230.433945-1-npiggin@gmail.com> References: <20230726182230.433945-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=npiggin@gmail.com; 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, 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 The ASDR register was introduced in ISA v3.0. It has not been implemented for HPT. With HPT, ASDR is the format of the slbmte RS operand (containing VSID), which matches the ppc_slb_t field. Fixes: 3367c62f522b ("target/ppc: Support for POWER9 native hash") Signed-off-by: Nicholas Piggin Reviewed-by: Cédric Le Goater --- target/ppc/mmu-hash64.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c index 900f906990..a0c90df3ce 100644 --- a/target/ppc/mmu-hash64.c +++ b/target/ppc/mmu-hash64.c @@ -770,7 +770,8 @@ static bool ppc_hash64_use_vrma(CPUPPCState *env) } } -static void ppc_hash64_set_isi(CPUState *cs, int mmu_idx, uint64_t error_code) +static void ppc_hash64_set_isi(CPUState *cs, int mmu_idx, uint64_t slb_vsid, + uint64_t error_code) { CPUPPCState *env = &POWERPC_CPU(cs)->env; bool vpm; @@ -782,13 +783,15 @@ static void ppc_hash64_set_isi(CPUState *cs, int mmu_idx, uint64_t error_code) } if (vpm && !mmuidx_hv(mmu_idx)) { cs->exception_index = POWERPC_EXCP_HISI; + env->spr[SPR_ASDR] = slb_vsid; } else { cs->exception_index = POWERPC_EXCP_ISI; } env->error_code = error_code; } -static void ppc_hash64_set_dsi(CPUState *cs, int mmu_idx, uint64_t dar, uint64_t dsisr) +static void ppc_hash64_set_dsi(CPUState *cs, int mmu_idx, uint64_t slb_vsid, + uint64_t dar, uint64_t dsisr) { CPUPPCState *env = &POWERPC_CPU(cs)->env; bool vpm; @@ -802,6 +805,7 @@ static void ppc_hash64_set_dsi(CPUState *cs, int mmu_idx, uint64_t dar, uint64_t cs->exception_index = POWERPC_EXCP_HDSI; env->spr[SPR_HDAR] = dar; env->spr[SPR_HDSISR] = dsisr; + env->spr[SPR_ASDR] = slb_vsid; } else { cs->exception_index = POWERPC_EXCP_DSI; env->spr[SPR_DAR] = dar; @@ -963,13 +967,13 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type, } switch (access_type) { case MMU_INST_FETCH: - ppc_hash64_set_isi(cs, mmu_idx, SRR1_PROTFAULT); + ppc_hash64_set_isi(cs, mmu_idx, 0, SRR1_PROTFAULT); break; case MMU_DATA_LOAD: - ppc_hash64_set_dsi(cs, mmu_idx, eaddr, DSISR_PROTFAULT); + ppc_hash64_set_dsi(cs, mmu_idx, 0, eaddr, DSISR_PROTFAULT); break; case MMU_DATA_STORE: - ppc_hash64_set_dsi(cs, mmu_idx, eaddr, + ppc_hash64_set_dsi(cs, mmu_idx, 0, eaddr, DSISR_PROTFAULT | DSISR_ISSTORE); break; default: @@ -1022,7 +1026,7 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type, /* 3. Check for segment level no-execute violation */ if (access_type == MMU_INST_FETCH && (slb->vsid & SLB_VSID_N)) { if (guest_visible) { - ppc_hash64_set_isi(cs, mmu_idx, SRR1_NOEXEC_GUARD); + ppc_hash64_set_isi(cs, mmu_idx, slb->vsid, SRR1_NOEXEC_GUARD); } return false; } @@ -1035,13 +1039,14 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type, } switch (access_type) { case MMU_INST_FETCH: - ppc_hash64_set_isi(cs, mmu_idx, SRR1_NOPTE); + ppc_hash64_set_isi(cs, mmu_idx, slb->vsid, SRR1_NOPTE); break; case MMU_DATA_LOAD: - ppc_hash64_set_dsi(cs, mmu_idx, eaddr, DSISR_NOPTE); + ppc_hash64_set_dsi(cs, mmu_idx, slb->vsid, eaddr, DSISR_NOPTE); break; case MMU_DATA_STORE: - ppc_hash64_set_dsi(cs, mmu_idx, eaddr, DSISR_NOPTE | DSISR_ISSTORE); + ppc_hash64_set_dsi(cs, mmu_idx, slb->vsid, eaddr, + DSISR_NOPTE | DSISR_ISSTORE); break; default: g_assert_not_reached(); @@ -1075,7 +1080,7 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type, if (PAGE_EXEC & ~amr_prot) { srr1 |= SRR1_IAMR; /* Access violates virt pg class key prot */ } - ppc_hash64_set_isi(cs, mmu_idx, srr1); + ppc_hash64_set_isi(cs, mmu_idx, slb->vsid, srr1); } else { int dsisr = 0; if (need_prot & ~pp_prot) { @@ -1087,7 +1092,7 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type, if (need_prot & ~amr_prot) { dsisr |= DSISR_AMR; } - ppc_hash64_set_dsi(cs, mmu_idx, eaddr, dsisr); + ppc_hash64_set_dsi(cs, mmu_idx, slb->vsid, eaddr, dsisr); } return false; } From patchwork Wed Jul 26 18:22:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1813416 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=bcROapOs; 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 4RB3Yd2pnsz1yY5 for ; Thu, 27 Jul 2023 05:17:09 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOjAM-0003vr-3e; Wed, 26 Jul 2023 14:23:19 -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 1qOj9w-0003rP-R5; Wed, 26 Jul 2023 14:22:54 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qOj9u-0008Rq-TT; Wed, 26 Jul 2023 14:22:52 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-686efb9ee3cso103421b3a.3; Wed, 26 Jul 2023 11:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690395769; x=1691000569; 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=U/FtV0fq+M1oqQhY61vaP0OZ0xzxbuzvQTaIIl0I9dk=; b=bcROapOsw4QK/wccgMPX5/ousDa0Cp0wIuWAFAxnCKfsVO7K3Ka+jRg01yG6EqaC/r YH43+79VmtBMHrBGZlxiH5Uj7Q6VzJFm2LkwCleIHT/lX4kUXr91a/BUJeAufX2nDtKc I5dPBWPjAKaorTp5rDtLAgc+7tjx8NGrXBlaH99c2UCT0lO/9/mtBPRKZLQk9CD+W4JN UcIqftbEfult6demAi9hY8p83+vgYQa52jzKleN0H7Kdl1pxA3brDWEl1h8T+QKYnH1U 5WfHU/dM1L7427WbPfgNkxt+4mtUZx5/D01/c7FzrK2aXcIVLUtfi9ZTzuS1mJjHJHA2 6e8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690395769; x=1691000569; 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=U/FtV0fq+M1oqQhY61vaP0OZ0xzxbuzvQTaIIl0I9dk=; b=XSqU5ip5D/jrKGdcEF+4i+OACSNRxWdpa3DXR3mHB1kDmpP1n3kvAuWR8PRv6D6Ttg CwEtGRK2/+roAfjhcA6bnr5nryT1mHOb2+VxZB81k1iGtLufjiGio5c62U9ouzn3LBoS Cgjjv6NkQzgb7gT99XzByzbsgyT+qAhrn743ZSEXcuYdUGXjxwhLrPnCst69cKVb8iPg QHa99mL2XXb7ZeWtynxRU0LdfBIfvbS9npMtXGn2nhduVSafKfuko+8DgaAbVLHXo5z1 +GY//A6G+jPykUa0Nj1FFc9sUmrNnfJYLiRJDoCnBJVgzpbA+9rjHqvuCX8Ggzf3uPdM ilnA== X-Gm-Message-State: ABy/qLb6X3lxfZTQh/bacDJiZabo4BOPLYNC6mFKuo6vKmxHOP31869g oSnNKySDPAf6b34ZCQnudx8= X-Google-Smtp-Source: APBJJlEO6bqyGRrcTqB1M0HhzpCuq5jdwJ3ImsYBb6Y07JOkFWomg+J2HbwwwVbRaoV8G7BM0DYcEg== X-Received: by 2002:a05:6a21:3381:b0:134:4de4:d5e6 with SMTP id yy1-20020a056a21338100b001344de4d5e6mr3698310pzb.57.1690395769308; Wed, 26 Jul 2023 11:22:49 -0700 (PDT) Received: from wheely.local0.net ([118.102.104.45]) by smtp.gmail.com with ESMTPSA id b25-20020a639319000000b0055adced9e13sm360185pge.0.2023.07.26.11.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 11:22:49 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?utf-8?q?C=C3=A9dric_Le_Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 2/6] target/ppc: Fix VRMA page size for ISA v3.0 Date: Thu, 27 Jul 2023 04:22:26 +1000 Message-Id: <20230726182230.433945-3-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230726182230.433945-1-npiggin@gmail.com> References: <20230726182230.433945-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=npiggin@gmail.com; helo=mail-pf1-x429.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 Until v2.07s, the VRMA page size (L||LP) was encoded in LPCR[VRMASD]. In v3.0 that moved to the partition table PS field. The powernv machine can now run KVM HPT guests on POWER9/10 CPUs with this fix and the patch to add ASDR. Fixes: 3367c62f522b ("target/ppc: Support for POWER9 native hash") Signed-off-by: Nicholas Piggin --- target/ppc/mmu-hash64.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c index a0c90df3ce..7f8bbbbdb0 100644 --- a/target/ppc/mmu-hash64.c +++ b/target/ppc/mmu-hash64.c @@ -874,12 +874,41 @@ static target_ulong rmls_limit(PowerPCCPU *cpu) return rma_sizes[rmls]; } -static int build_vrma_slbe(PowerPCCPU *cpu, ppc_slb_t *slb) +/* Return the LLP in SLB_VSID format */ +static uint64_t get_vrma_llp(PowerPCCPU *cpu) { CPUPPCState *env = &cpu->env; - target_ulong lpcr = env->spr[SPR_LPCR]; - uint32_t vrmasd = (lpcr & LPCR_VRMASD) >> LPCR_VRMASD_SHIFT; - target_ulong vsid = SLB_VSID_VRMA | ((vrmasd << 4) & SLB_VSID_LLP_MASK); + uint64_t llp; + + if (env->mmu_model == POWERPC_MMU_3_00) { + ppc_v3_pate_t pate; + uint64_t ps; + + /* + * ISA v3.0 removes the LPCR[VRMASD] field and puts the VRMA base + * page size (L||LP equivalent) in the PS field in the HPT partition + * table entry. + */ + if (!ppc64_v3_get_pate(cpu, cpu->env.spr[SPR_LPIDR], &pate)) { + error_report("Bad VRMA with no partition table entry"); + return 0; + } + ps = pate.dw0 >> (63 - 58); + llp = ((ps & 0x4) << (63 - 55 - 2)) | ((ps & 0x3) << (63 - 59)); + + } else { + uint64_t lpcr = env->spr[SPR_LPCR]; + target_ulong vrmasd = (lpcr & LPCR_VRMASD) >> LPCR_VRMASD_SHIFT; + + llp = (vrmasd << 4) & SLB_VSID_LLP_MASK; + } + + return llp; +} + +static int build_vrma_slbe(PowerPCCPU *cpu, ppc_slb_t *slb) +{ + target_ulong vsid = SLB_VSID_VRMA | get_vrma_llp(cpu); int i; for (i = 0; i < PPC_PAGE_SIZES_MAX_SZ; i++) { @@ -897,8 +926,8 @@ static int build_vrma_slbe(PowerPCCPU *cpu, ppc_slb_t *slb) } } - error_report("Bad page size encoding in LPCR[VRMASD]; LPCR=0x" - TARGET_FMT_lx, lpcr); + error_report("Bad VRMA page size encoding 0x" TARGET_FMT_lx, + get_vrma_llp(cpu)); return -1; } From patchwork Wed Jul 26 18:22:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1813431 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=CqCUScvB; 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 4RB3lG3MJQz1ydm for ; Thu, 27 Jul 2023 05:25:30 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOjAf-000426-3j; Wed, 26 Jul 2023 14:23:37 -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 1qOjA0-0003rg-Mr; Wed, 26 Jul 2023 14:22:58 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qOj9z-0008SK-5F; Wed, 26 Jul 2023 14:22:56 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-686efb9ee3cso103480b3a.3; Wed, 26 Jul 2023 11:22:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690395773; x=1691000573; 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=GPFNgLtuXEMW3RIJM7zOTpIuZJEYRDjteVhC8Ic/foo=; b=CqCUScvBw8ms0iPDMtX3W6zZ9ayNbbtAelie522QN2l/TCxVZhmkjCQW20aN4nuhSe Zo7SfwhUxnwhXijTTlPt6mJmqZx+EyuWV6dx4hz268zmq8zdJpH4RlLUxVlMY7R5q5/a L56zs2GPpf37JQEct2bZGyYN8KzB5DzbYgaXDbRJeUSar+7jPayWJWiFcEj9n+L6OkKM +spW3LVYSy0gnLBG5/0JHoUrUWlCrxaBJfhwMVGo4hbKm6FGw/V5sBG8H7BFsIhvaYX5 qyvA8b4EpfuQoXjRTVZV9WVd27drzMVML/jgImYX1oYRuLp+mIlZ7sAWmQdQ5gXSiOc0 MQzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690395773; x=1691000573; 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=GPFNgLtuXEMW3RIJM7zOTpIuZJEYRDjteVhC8Ic/foo=; b=TonMhVYKPqp8jtLUA/3I+eIre++n052Fs1x5LQFN0sq/xz7XmNf0Hwljama3BwyvWp ry9CpP/fjYxfS6tdJDkvou91L2QK5wDU1eTIxa47sjItEocYdo2MXzn4rq9meTGzkNHB HR7+lBjnglROCm+qaMTkwnrY/4JJxcOt79rINZQZcr+B90U20/lkmAB+VKV8kf1fjF+D EDf1TzM6dGlo1tbUsPv1S3fOlxWskLhNDiZVwGuj7iEcjc7x0crO7ISUHMwkv6327OcZ cJeaUem28V2aZ7o7Dx9+KHShZdT1n0hLoARMNkcEFTt5Cuid6KmjhzdM0AUniRkPIegb 2QFw== X-Gm-Message-State: ABy/qLaBX5fpzVO95pBMt8kBuhzicy/Vw+0yltzOO+vgdzXuwAZiFSs+ 6UIyvUzwZzooDKQrEUvZ5I4= X-Google-Smtp-Source: APBJJlETfK/BxWqSAOAw7hcVCZE0qVnwtHYTa82wFMXuAMlruP8ofvtuipHseQa8iI8sp9SNEBuVew== X-Received: by 2002:a05:6a00:2d8e:b0:682:616a:f910 with SMTP id fb14-20020a056a002d8e00b00682616af910mr3459302pfb.20.1690395773200; Wed, 26 Jul 2023 11:22:53 -0700 (PDT) Received: from wheely.local0.net ([118.102.104.45]) by smtp.gmail.com with ESMTPSA id b25-20020a639319000000b0055adced9e13sm360185pge.0.2023.07.26.11.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 11:22:53 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?utf-8?q?C=C3=A9dric_Le_Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 3/6] target/ppc: Fix pending HDEC when entering PM state Date: Thu, 27 Jul 2023 04:22:27 +1000 Message-Id: <20230726182230.433945-4-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230726182230.433945-1-npiggin@gmail.com> References: <20230726182230.433945-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=npiggin@gmail.com; helo=mail-pf1-x42b.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 HDEC is defined to not wake from PM state. There is a check in the HDEC timer to avoid setting the interrupt if we are in a PM state, but no check on PM entry to lower HDEC if it already fired. This can cause a HDECR wake up and QEMU abort with unsupported exception in Power Save mode. Fixes: 4b236b621bf ("ppc: Initial HDEC support") Signed-off-by: Nicholas Piggin Reviewed-by: Cédric Le Goater --- target/ppc/excp_helper.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index 003805b202..9aa8e46566 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -2685,6 +2685,12 @@ void helper_pminsn(CPUPPCState *env, uint32_t insn) env->resume_as_sreset = (insn != PPC_PM_STOP) || (env->spr[SPR_PSSCR] & PSSCR_EC); + /* HDECR is not to wake from PM state, it may have already fired */ + if (env->resume_as_sreset) { + PowerPCCPU *cpu = env_archcpu(env); + ppc_set_irq(cpu, PPC_INTERRUPT_HDECR, 0); + } + ppc_maybe_interrupt(env); } #endif /* defined(TARGET_PPC64) */ From patchwork Wed Jul 26 18:22:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1813415 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=B3wGmMWF; 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 4RB3YH2dKbz1yY5 for ; Thu, 27 Jul 2023 05:16:48 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOjAW-0003yx-Bg; Wed, 26 Jul 2023 14:23:29 -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 1qOjA5-0003sT-Su; Wed, 26 Jul 2023 14:23:07 -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 1qOjA4-0008Sv-7s; Wed, 26 Jul 2023 14:23:01 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-686efdeabaeso84731b3a.3; Wed, 26 Jul 2023 11:22:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690395777; x=1691000577; 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=H0qoXrPvoquYQTQlBD4shTNqfDEEX1RsqpNF9V5SWPc=; b=B3wGmMWFO3XJMuyGEoyug48XJIh15PYfIFa2oSM1BTpOwu2j4HQb5IIhqeDL6B70F0 vrTyarTn2u9v6PBYio/VS69KZREc7U8UerY8ELnQPKlPtj+epjKEawrkVFHZg77fguDa C11x8IRFyBD8jJLs8Wlfz7NYnEiI+u3PmhetlaleNNe0SgtR7tTpuAJh8e5Wf9yfptL1 XJMB3PECpZt5mgqCFbSfz597aYil8+jHmPmkzn2+hFyb/v0DMiVTkvsAx8tubeLcAfUP zYbSrooHK70PO94WwmsV3BCWx1MEBJAkTldGs4ytdnK98cH45TTGvTTj0VGakcUUn6KG rFTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690395777; x=1691000577; 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=H0qoXrPvoquYQTQlBD4shTNqfDEEX1RsqpNF9V5SWPc=; b=CAs7YL1XWXJORhQj5yQDU2gfFIoPEGMwiNtGQ99UrxftRUOZgjN7bjHpiKXftIm7k+ IjymyIjgqGP0VoHCZMAVUvliO3jrU3oubYrWa7VCUSXqpsNRFmhjbDYB3go6Q1T+VC9Y gPBiDmBh+JamCjkRnK+ua29S4GCoebSRDk4rUP+Nmo2FcmFRalQudmQEERsGGYElpkWw B4DZF1EDsUqV8hOhLxGrJn2agiz2+r4MvaF3LHpzhdGEG8MWMPIh+mcDd1Mcg/AeX/nP 0NIZmGETJuK9nfjhP2tnEoRZUMyKq13t5mzsEhABCxOER3usMiqMeptdxmaaIAkg+9Zg 05EQ== X-Gm-Message-State: ABy/qLZD/nXjQx5MV1Vo1Zp8riLUsasOiys8NBTza2H6W7BSZ9KBE8se mkrqhGBoaKun34x6/oIgZh8= X-Google-Smtp-Source: APBJJlF9DQuaUtkL1fP91w0hYg+EcarJH6svrfzjFHZNdPrtLJ5ODu45Lu5irTijvk990ifXRlyMPg== X-Received: by 2002:a05:6a20:7f84:b0:126:43f7:e271 with SMTP id d4-20020a056a207f8400b0012643f7e271mr2655208pzj.39.1690395777122; Wed, 26 Jul 2023 11:22:57 -0700 (PDT) Received: from wheely.local0.net ([118.102.104.45]) by smtp.gmail.com with ESMTPSA id b25-20020a639319000000b0055adced9e13sm360185pge.0.2023.07.26.11.22.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 11:22:56 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?utf-8?q?C=C3=A9dric_Le_Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 4/6] hw/ppc: Avoid decrementer rounding errors Date: Thu, 27 Jul 2023 04:22:28 +1000 Message-Id: <20230726182230.433945-5-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230726182230.433945-1-npiggin@gmail.com> References: <20230726182230.433945-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 The decrementer register contains a relative time in timebase units. When writing to DECR this is converted and stored as an absolute value in nanosecond units, reading DECR converts back to relative timebase. The tb<->ns conversion of the relative part can cause rounding such that a value writen to the decrementer can read back a different, with time held constant. This is a particular problem for a deterministic icount and record-replay trace. Fix this by storing the absolute value in timebase units rather than nanoseconds. The math before: store: decr_next = now_ns + decr * ns_per_sec / tb_per_sec load: decr = (decr_next - now_ns) * tb_per_sec / ns_per_sec load(store): decr = decr * ns_per_sec / tb_per_sec * tb_per_sec / ns_per_sec After: store: decr_next = now_ns * tb_per_sec / ns_per_sec + decr load: decr = decr_next - now_ns * tb_per_sec / ns_per_sec load(store): decr = decr Fixes: 9fddaa0c0cab ("PowerPC merge: real time TB and decrementer - faster and simpler exception handling (Jocelyn Mayer)") Signed-off-by: Nicholas Piggin --- hw/ppc/ppc.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index 0e0a3d93c3..fa60f76dd4 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -686,16 +686,17 @@ bool ppc_decr_clear_on_delivery(CPUPPCState *env) static inline int64_t _cpu_ppc_load_decr(CPUPPCState *env, uint64_t next) { ppc_tb_t *tb_env = env->tb_env; - int64_t decr, diff; + uint64_t now, n; + int64_t decr; - diff = next - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - if (diff >= 0) { - decr = muldiv64(diff, tb_env->decr_freq, NANOSECONDS_PER_SECOND); - } else if (tb_env->flags & PPC_TIMER_BOOKE) { + now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + n = muldiv64(now, tb_env->decr_freq, NANOSECONDS_PER_SECOND); + if (next > n && tb_env->flags & PPC_TIMER_BOOKE) { decr = 0; - } else { - decr = -muldiv64(-diff, tb_env->decr_freq, NANOSECONDS_PER_SECOND); + } else { + decr = next - n; } + trace_ppc_decr_load(decr); return decr; @@ -834,11 +835,11 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint64_t *nextp, /* Calculate the next timer event */ now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - next = now + muldiv64(value, NANOSECONDS_PER_SECOND, tb_env->decr_freq); - *nextp = next; + next = muldiv64(now, tb_env->decr_freq, NANOSECONDS_PER_SECOND) + value; + *nextp = next; /* nextp is in timebase units */ /* Adjust timer */ - timer_mod(timer, next); + timer_mod(timer, muldiv64(next, NANOSECONDS_PER_SECOND, tb_env->decr_freq)); } static inline void _cpu_ppc_store_decr(PowerPCCPU *cpu, target_ulong decr, @@ -1153,14 +1154,20 @@ static void start_stop_pit (CPUPPCState *env, ppc_tb_t *tb_env, int is_excp) } else { trace_ppc4xx_pit_start(ppc40x_timer->pit_reload); now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - next = now + muldiv64(ppc40x_timer->pit_reload, - NANOSECONDS_PER_SECOND, tb_env->decr_freq); - if (is_excp) - next += tb_env->decr_next - now; - if (next == now) - next++; + + if (is_excp) { + tb_env->decr_next += ppc40x_timer->pit_reload; + } else { + tb_env->decr_next = muldiv64(now, tb_env->decr_freq, + NANOSECONDS_PER_SECOND) + + ppc40x_timer->pit_reload; + } + next = muldiv64(tb_env->decr_next, NANOSECONDS_PER_SECOND, + tb_env->decr_freq); + if (next <= now) { + next = now + 1; + } timer_mod(tb_env->decr_timer, next); - tb_env->decr_next = next; } } From patchwork Wed Jul 26 18:22:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1813410 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=FJv+P7Cj; 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 4RB3RP6l5Sz1ydm for ; Thu, 27 Jul 2023 05:11:45 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOjAg-00043N-33; Wed, 26 Jul 2023 14:23: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 1qOjA8-0003sX-9W; Wed, 26 Jul 2023 14:23:07 -0400 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qOjA6-0008UO-MB; Wed, 26 Jul 2023 14:23:04 -0400 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6b9b52724ccso62229a34.1; Wed, 26 Jul 2023 11:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690395781; x=1691000581; 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=GZQTChBYLoqHBg/YGc0TeJy3uEDe22OcFDiFrIsmZvA=; b=FJv+P7Cj3SdeNBq230/tt5yiRrRgiRu45XvmZSfhDlK8MUyxKUVen80z/XkPZkt2zC VtBDExK2pI0GoJ+BEXC/mJP3CaEfa4yhUaxjAiP8lmUrbIKsT0kfYmBSf3R8DyNSvkNT f0foY/nap43eOoZn+qwGlzXWdUFKIilLw03JSHVMDaGgFOz/bhBkZn+AX58MQra8HiNC Vt+QZHo+I4JoJ7WxprBQzvfG25OHlMBptc0tLMEJwDOKbQhGGUZaurJ/KEuiJ3pVD/76 ll7j9oINfXDHEJrkdRZhpNT/jFUTl5Z8AIPDd8oGJtIYQ9KbZKfBlT+fJG+pJl8dHi2Q HT7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690395781; x=1691000581; 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=GZQTChBYLoqHBg/YGc0TeJy3uEDe22OcFDiFrIsmZvA=; b=ZgsWYl3KlcVDsojnGLY5scdQQsE2ErGcJZaobbVcAv3JBoA8DmeHXUrhXKG0pPHwLD BcgvwhW1B2G588OJHU44+O+QKf8ZU65nvYvJxcQXQMJpo61jXYO2+RISUSJDjvX8f4X1 cNauqC5WfOdMedjNCy8xb0ZDwrBnU81atCSRibWhYyWpk2duXy1ldxVmynCzPXKsmdhz 07c1KNn6GD6awKv6naPXHIdoSrUw9U7ATldfaGPrx1Nwk5KVro+2sYtsaXXo9jikHO5N pJcoX5aijCbsrbjZbtc5qBoxzPwEpYYeAc3t3AWF/S0OHrQ7eTlXwolBp0YoKc6CoI7I Dnyw== X-Gm-Message-State: ABy/qLaC/58eOI7Aboc6Q0gmMTIIIMWdlrj6FNJQDQ+CWu/x0AsoO1nd Q5EzpZN/12h8RBoMyqtlgk8= X-Google-Smtp-Source: APBJJlHje8nUVDReIA09Qwl2vMWRuzqyeNeAFmmIDlwgm5VOF8QsyI6bBTs0gg7JToIvVD9Biz6U/Q== X-Received: by 2002:a05:6358:41a3:b0:134:de8b:17f0 with SMTP id w35-20020a05635841a300b00134de8b17f0mr2606054rwc.19.1690395781046; Wed, 26 Jul 2023 11:23:01 -0700 (PDT) Received: from wheely.local0.net ([118.102.104.45]) by smtp.gmail.com with ESMTPSA id b25-20020a639319000000b0055adced9e13sm360185pge.0.2023.07.26.11.22.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 11:23:00 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?utf-8?q?C=C3=A9dric_Le_Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 5/6] hw/ppc: Always store the decrementer value Date: Thu, 27 Jul 2023 04:22:29 +1000 Message-Id: <20230726182230.433945-6-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230726182230.433945-1-npiggin@gmail.com> References: <20230726182230.433945-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::331; envelope-from=npiggin@gmail.com; helo=mail-ot1-x331.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 When writing a value to the decrementer that raises an exception, the irq is raised, but the value is not stored so the store doesn't appear to have changed the register when it is read again. Always store the write value to the register. Fixes: e81a982aa53 ("PPC: Clean up DECR implementation") Signed-off-by: Nicholas Piggin --- hw/ppc/ppc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index fa60f76dd4..cd1993e9c1 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -812,6 +812,11 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint64_t *nextp, return; } + /* Calculate the next timer event */ + now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + next = muldiv64(now, tb_env->decr_freq, NANOSECONDS_PER_SECOND) + value; + *nextp = next; /* nextp is in timebase units */ + /* * Going from 1 -> 0 or 0 -> -1 is the event to generate a DEC interrupt. * @@ -833,11 +838,6 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint64_t *nextp, (*lower_excp)(cpu); } - /* Calculate the next timer event */ - now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - next = muldiv64(now, tb_env->decr_freq, NANOSECONDS_PER_SECOND) + value; - *nextp = next; /* nextp is in timebase units */ - /* Adjust timer */ timer_mod(timer, muldiv64(next, NANOSECONDS_PER_SECOND, tb_env->decr_freq)); } From patchwork Wed Jul 26 18:22:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1813432 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=CWspJNPr; 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 4RB3lX5rWgz1ydm for ; Thu, 27 Jul 2023 05:25:44 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOjAf-00042d-Am; Wed, 26 Jul 2023 14:23:37 -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 1qOjAD-0003tm-I8; Wed, 26 Jul 2023 14:23:15 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qOjAB-00005O-EH; Wed, 26 Jul 2023 14:23:08 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-666e6ecb52dso123914b3a.2; Wed, 26 Jul 2023 11:23:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690395785; x=1691000585; 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=jnOO8sOKFvquVVGd7wwV21JSwUZNyJsumnSJEzq/sZM=; b=CWspJNPrG6ocNIp/srTsNnlAMFKQ+A5VA9XS0sQLHFdQQMIL0jqQZ7UIssRxDpufZq iEV+67KXDx/k/dQyGOhydgUK2eNdRQ7RolThD0BKvQDXHuu3NDU1UVhHk9mXwagfuaHb nHEJTOrllz+4G22gx46StbCLYF3sx3WuD38VzA6DIXjbOEcUC51Xh0wQQSwFeacK4Dkk NHnmT9MhTLmLnsRnSvB/Uc1NgC5qMN2Yf673mlybG1me+z/E9AppK/EbYXunRVtKpiFt eqN1dwSaX7fjPHPiL+KA78xwlZfu2XPnwEDkDX2IgKnrmvWh17YAgRAFbT9LRJXyTg3F /ZOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690395785; x=1691000585; 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=jnOO8sOKFvquVVGd7wwV21JSwUZNyJsumnSJEzq/sZM=; b=dAQIRX+gHRejqrLEjl1/ucpjrsQ3XZL2UfGXcg5k3li35/f8rLEdUAEC9RZxc+1VkU 7pwxCdnfO8Rxy9aOiEb/fEGG8HCLaF48IGC4mRX1xNG1wExaknWBEj3zNPPEOkwpPKjm YPzIkYjw75DDKzGSDvTZj5gNsG8JTfH7tcmk7zoZ2e9iHoqUuI3diOxRo7bcrvcASdrL DVU8s7NqodyuYlFtvzBTb4DvTrJHqbllsBf549TcvCvhV8tej0gzukvU3zSt/bSffg/E Gz4VxIHriK+guQeKMzZN/DTUSd7DkVbVyvD80z5DchrUp/75v36TuyVEuW8PGTxzI4Z4 60ZA== X-Gm-Message-State: ABy/qLbNahy2qA2xY2aFFD+21VR8HeX3bc7EEWFhAWNxdBzPQm2K4rOZ Kf3fUD/czXYGotqW+Ml9ohA= X-Google-Smtp-Source: APBJJlHLSJ3FArhuPFsitrcG00MLlnEXnCEqzCgVVgjpHhNTkjFaUq7g4vzeIBOmxxS3HMy9aiB00Q== X-Received: by 2002:a05:6a00:849:b0:686:6d87:1cd with SMTP id q9-20020a056a00084900b006866d8701cdmr2898903pfk.5.1690395784987; Wed, 26 Jul 2023 11:23:04 -0700 (PDT) Received: from wheely.local0.net ([118.102.104.45]) by smtp.gmail.com with ESMTPSA id b25-20020a639319000000b0055adced9e13sm360185pge.0.2023.07.26.11.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 11:23:04 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?utf-8?q?C=C3=A9dric_Le_Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 6/6] target/ppc: Migrate DECR SPR Date: Thu, 27 Jul 2023 04:22:30 +1000 Message-Id: <20230726182230.433945-7-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230726182230.433945-1-npiggin@gmail.com> References: <20230726182230.433945-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=npiggin@gmail.com; helo=mail-pf1-x42d.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 TCG does not maintain the DEC reigster in the SPR array, so it does get migrated. TCG also needs to re-start the decrementer timer on the destination machine. Load and store the decrementer into the SPR when migrating. This works for the level-triggered (book3s) decrementer, and should be compatible with existing KVM machines that do keep the DEC value there. This fixes lost decrementer interrupt on migration that can cause hangs, as well as other problems including record-replay bugs. Signed-off-by: Nicholas Piggin --- target/ppc/machine.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/target/ppc/machine.c b/target/ppc/machine.c index 134b16c625..ebb37e07d0 100644 --- a/target/ppc/machine.c +++ b/target/ppc/machine.c @@ -209,6 +209,14 @@ static int cpu_pre_save(void *opaque) /* Used to retain migration compatibility for pre 6.0 for 601 machines. */ env->hflags_compat_nmsr = 0; + if (tcg_enabled()) { + /* + * TCG does not maintain the DECR spr (unlike KVM) so have to save + * it here. + */ + env->spr[SPR_DECR] = cpu_ppc_load_decr(env); + } + return 0; } @@ -314,6 +322,12 @@ static int cpu_post_load(void *opaque, int version_id) post_load_update_msr(env); if (tcg_enabled()) { + /* + * TCG needs to re-start the decrementer timer and/or raise the + * interrupt. This works for level-triggered decrementer. Edge + * triggered types (including HDEC) would need to carry more state. + */ + cpu_ppc_store_decr(env, env->spr[SPR_DECR]); pmu_mmcr01_updated(env); }