From patchwork Mon Mar 3 11:23:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13998612 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 967F6C282C5 for ; Mon, 3 Mar 2025 11:24:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tp3tR-0002qd-Le; Mon, 03 Mar 2025 06:23:29 -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 1tp3tQ-0002oa-FY; Mon, 03 Mar 2025 06:23:28 -0500 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tp3tO-00076J-Mp; Mon, 03 Mar 2025 06:23:28 -0500 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-2234bec7192so57714735ad.2; Mon, 03 Mar 2025 03:23:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741001004; x=1741605804; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9Sd3DVVAXD6tqmCQ5NglFT6kDc4plDf6NJTVkHPAxEw=; b=FOABHUmuM8mAk7oYpEpSE1fytTt5gJvwUhighZbYYaJ2c+s82sXDwBfXZ03wJOAapo FPz/1PZOz5QDN7mvGRIeof344eDxdM+2jWPCWsbr1DIIl3Pi6ITwMNCxYbjtmN/uUxZk lTKuV4SkkprQv5rzUCjwbUqQQyaFozpE5c6NJDdgAvSc/QSB4yEN6vuxdVi/4qvOBLtl SjB9maHT/0LAs0BYH1ucy97pnbH0uhevRS4uvmRyxH32dNQT3m8MM2TdY2hH2u20hAFL 7tHrn7jodMO9tZuox8sFLCzI5RvEpMnZYm8+jLlNbBu8t/4LNpL2+TRF7WRg5kZb+7cM S8BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741001004; x=1741605804; 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=9Sd3DVVAXD6tqmCQ5NglFT6kDc4plDf6NJTVkHPAxEw=; b=iarYa+f9o969To3VJIdgCxR6bfVw0t68xjVtB/Ik0iQ3Ye1Q6MMKg1C1o4FCA8yoCT V/zXA4kZw73jcH7XeKfg14diiLurAEBPnPX+wvzoqcJVfu0B9wtG0IjzIUiMF763KdoT eZ7qOzFo7DIXjkDYIdqJvUVn3nFgU0reepUhnGIopcz0jHwvqIbeuvLxSeQB28n/Jia5 fOUYj0qwfBQgnPGfvdm62EafwLoTPzQoO780FQD9zyN+/2pkHNJUxaa+0MTsjvGK8iW8 6Lhi9oTOixfuKGgm/wvuVLo5vIUgk8OIUXOClHFHCcoAhzr8Xa8bq8ap7YOstNx7LKx6 V/dg== X-Forwarded-Encrypted: i=1; AJvYcCUVgWELbBiBXlB/+PG5b0UQXaIsc2SLtKXAqiY/98CuMhYOE8usUpfClgVyKxuHWw//QfjNxvi+NlWS@nongnu.org X-Gm-Message-State: AOJu0YyjiNauuqkHzSG0rOlcy7LWrIzB2ygI/zA1GXp1VImjDxioSZL9 p0R1tLrC7WW4mL1l5eYygxE25y7cxPPu8eWn+RgT+5D0pPzk9iu7bNsW+w== X-Gm-Gg: ASbGncuZJt/NBMaIV/CjzFhDe71V9C06UN8sP7XrE9Dl2OAcWFX1L6nWUmv15w37Rp3 GuyHQrjciT/RCSV4EGYj0hQzLbxvzVH2Pc4QXiouwT5t+B+OIXWHT/yVJpZSy9CBYNoNUVpMKwI 10kDfCel/KvhPSiblG6Ii8XkbVjy/rQU3bduuYb39Y/cvU10atIUmq68Jw2d4HxUrnNS794mwZA qv9qHFqvup4HaLMHTshXlNv0zqj1B5i4NlqxEEsZlz2lDMY8C0D9twfsYw+MgC0RuFskm8BXL6K BlncqrCodVlAfCUG0FB40Sg/ILRJO+2rAWYpT+4y5KbS+TDcTnk= X-Google-Smtp-Source: AGHT+IH4AFJ2Ae0Ld9F0SzXxZbtEYkhwNpf+03J/yylh5B7tZdZUK2c6IQccTvpQOVPlZ9smAdPjSA== X-Received: by 2002:a17:903:33cc:b0:223:5a6e:b16 with SMTP id d9443c01a7336-22368f60ac5mr180058215ad.5.1741001003763; Mon, 03 Mar 2025 03:23:23 -0800 (PST) Received: from wheely.local0.net ([118.208.151.101]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-223501f9e3bsm75388875ad.82.2025.03.03.03.23.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 03:23:23 -0800 (PST) From: Nicholas Piggin To: qemu-ppc@nongnu.org Cc: Nicholas Piggin , qemu-devel@nongnu.org Subject: [PATCH 1/3] target/ppc: flush TLB on HRMOR and LPCR SPR updates Date: Mon, 3 Mar 2025 21:23:12 +1000 Message-ID: <20250303112315.586478-2-npiggin@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250303112315.586478-1-npiggin@gmail.com> References: <20250303112315.586478-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=npiggin@gmail.com; helo=mail-pl1-x62f.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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The HRMOR and LPCR registers are involved with MMU translations that are not tagged in the TLB (i.e., with mmuidx), so the TLB needs to be flushed when these are changed, e.g., as PIDR, LPIDR already do. target/ppc: add missing TLB flushes for MMU SPR updates Signed-off-by: Nicholas Piggin --- target/ppc/helper.h | 1 + target/ppc/spr_common.h | 1 + target/ppc/cpu.c | 4 ++++ target/ppc/cpu_init.c | 2 +- target/ppc/misc_helper.c | 23 +++++++++++++++++++++++ target/ppc/translate.c | 10 ++++++++++ 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/target/ppc/helper.h b/target/ppc/helper.h index 5a77e761bd3..6178ebe138f 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -723,6 +723,7 @@ DEF_HELPER_FLAGS_1(load_vtb, TCG_CALL_NO_RWG, tl, env) #if defined(TARGET_PPC64) DEF_HELPER_FLAGS_1(load_purr, TCG_CALL_NO_RWG, tl, env) DEF_HELPER_FLAGS_2(store_purr, TCG_CALL_NO_RWG, void, env, tl) +DEF_HELPER_2(store_hrmor, void, env, tl) DEF_HELPER_2(store_ptcr, void, env, tl) DEF_HELPER_FLAGS_1(load_dpdes, TCG_CALL_NO_RWG, tl, env) DEF_HELPER_FLAGS_2(store_dpdes, TCG_CALL_NO_RWG, void, env, tl) diff --git a/target/ppc/spr_common.h b/target/ppc/spr_common.h index 01aff449bcc..8cac82b2dac 100644 --- a/target/ppc/spr_common.h +++ b/target/ppc/spr_common.h @@ -177,6 +177,7 @@ void spr_write_pidr(DisasContext *ctx, int sprn, int gprn); void spr_write_lpidr(DisasContext *ctx, int sprn, int gprn); void spr_read_hior(DisasContext *ctx, int gprn, int sprn); void spr_write_hior(DisasContext *ctx, int sprn, int gprn); +void spr_write_hrmor(DisasContext *ctx, int sprn, int gprn); void spr_write_ptcr(DisasContext *ctx, int sprn, int gprn); void spr_write_pcr(DisasContext *ctx, int sprn, int gprn); void spr_read_dpdes(DisasContext *ctx, int gprn, int sprn); diff --git a/target/ppc/cpu.c b/target/ppc/cpu.c index d148cd76b47..cdd50cb36d6 100644 --- a/target/ppc/cpu.c +++ b/target/ppc/cpu.c @@ -21,6 +21,7 @@ #include "cpu.h" #include "cpu-models.h" #include "cpu-qom.h" +#include "exec/exec-all.h" #include "exec/log.h" #include "fpu/softfloat-helpers.h" #include "mmu-hash64.h" @@ -101,6 +102,9 @@ void ppc_store_lpcr(PowerPCCPU *cpu, target_ulong val) /* The gtse bit affects hflags */ hreg_compute_hflags(env); + /* Various untagged bits affect translation (e.g., TC, HR, etc). */ + tlb_flush(env_cpu(env)); + ppc_maybe_interrupt(env); } diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index 062a6e85fba..92316b55afd 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -5496,7 +5496,7 @@ static void register_book3s_ids_sprs(CPUPPCState *env) spr_register_hv(env, SPR_HRMOR, "HRMOR", SPR_NOACCESS, SPR_NOACCESS, SPR_NOACCESS, SPR_NOACCESS, - &spr_read_generic, &spr_core_write_generic, + &spr_read_generic, &spr_write_hrmor, 0x00000000); } diff --git a/target/ppc/misc_helper.c b/target/ppc/misc_helper.c index f0ca80153b2..179e8b6b4d2 100644 --- a/target/ppc/misc_helper.c +++ b/target/ppc/misc_helper.c @@ -169,6 +169,29 @@ void helper_store_sdr1(CPUPPCState *env, target_ulong val) } #if defined(TARGET_PPC64) +void helper_store_hrmor(CPUPPCState *env, target_ulong val) +{ + if (env->spr[SPR_HRMOR] != val) { + CPUState *cs = env_cpu(env); + + qemu_log_mask(CPU_LOG_MMU, "%s: " TARGET_FMT_lx "\n", __func__, val); + + if (ppc_cpu_lpar_single_threaded(cs)) { + env->spr[SPR_HRMOR] = val; + tlb_flush(cs); + } else { + CPUState *ccs; + + THREAD_SIBLING_FOREACH(cs, ccs) { + PowerPCCPU *ccpu = POWERPC_CPU(ccs); + CPUPPCState *cenv = &ccpu->env; + cenv->spr[SPR_HRMOR] = val; + tlb_flush(ccs); + } + } + } +} + void helper_store_ptcr(CPUPPCState *env, target_ulong val) { if (env->spr[SPR_PTCR] != val) { diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 80638ab5359..ac910151cfa 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -909,6 +909,16 @@ void spr_write_hior(DisasContext *ctx, int sprn, int gprn) tcg_gen_andi_tl(t0, cpu_gpr[gprn], 0x3FFFFF00000ULL); tcg_gen_st_tl(t0, tcg_env, offsetof(CPUPPCState, excp_prefix)); } + +void spr_write_hrmor(DisasContext *ctx, int sprn, int gprn) +{ + if (!gen_serialize_core(ctx)) { + return; + } + + gen_helper_store_hrmor(tcg_env, cpu_gpr[gprn]); +} + void spr_write_ptcr(DisasContext *ctx, int sprn, int gprn) { if (!gen_serialize_core(ctx)) { From patchwork Mon Mar 3 11:23:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13998614 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0BCF7C282CD for ; Mon, 3 Mar 2025 11:24:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tp3tT-0002sr-8D; Mon, 03 Mar 2025 06:23:31 -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 1tp3tR-0002qi-JA; Mon, 03 Mar 2025 06:23:29 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tp3tQ-00076t-4L; Mon, 03 Mar 2025 06:23:29 -0500 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2239aa5da08so18866465ad.3; Mon, 03 Mar 2025 03:23:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741001006; x=1741605806; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Cu9dJddBsSRtdsBzKn6C+oUO9t7UsRoDwTthYYeOMK4=; b=BZQsabt0Z1LDOAThPP8CxjmYm373dpzxbDkWjHWUm86egTn4wk866I2yGF1V9fbZTy nIwBMwIpenasrYkEUMpRVnS0geZ2k4Le+q0XvfeyWz/BvLaPYG6H5jkhpPGxyPWeqHhZ Wyol5K5hcllX0JziIGJKDLgETJeNMnfGkkdJRhc3J6Zhfl/FJ47LVpVrOmIQKpfx5sl7 y+vkb/IsIIENO6EiMgryfbXez4JRlhBPclvlGCcf9xuprwcDCup73QYLCaCKe7le+wha 8Omvau9ulKwdX23f02KF5+snaaXH2yKjYe7jr5McLE5lY1YEfchz3CS/fC6evKP7L2nc 0fzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741001006; x=1741605806; 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=Cu9dJddBsSRtdsBzKn6C+oUO9t7UsRoDwTthYYeOMK4=; b=TV+1jDv5iVLx3nfM2qVXIHvlRttFY/bua9Wer6vcUOgmvXv+aJiOdb27x677CMdpXt jg9UYPAB71Pz8l1G2wMepzNY0zXHmcZw/tNf95Q3r8y4dLL4C1G1MF6FhZjgjXqotePe dfeSbl92NtimDwQW/BeSf7KnMzD/w5nor++hLVJPVIIv7A4uJc76SMC9n8yWYt0WthVy E3LkFdBGe+7sSqCCIfz79ncumkoGfN/dn4wBlL9aKMwCmBSdG3bm74lOF6VaFDfsi0pZ WasULatcJD36RBcCa3yC/FKs1agSWBOtxTqjeYgoHxAOO+4MydH7XbynRRMSuS8k+vNU 2NEw== X-Forwarded-Encrypted: i=1; AJvYcCXAGJ5b2Gf5d5/jD69REUv0bdQxg/Q2SvTmFKkwKXpJ0s+GMuetQt1bwDSk7gClFqlVgsriBuLfS6d8@nongnu.org X-Gm-Message-State: AOJu0YzJTLNdpCpIXY0E3EcGX/NX7UuTBsew8FSZTibPbvT1A7UnpbXI 5HpGqxlk7fLgcUVCv3ov2es8KbTdUv4VtPsnkqSG2ZvE3CdHV5RCSl9dWA== X-Gm-Gg: ASbGncsG+HVjqCJauPf1hqePlEVAhVDpF36CpB3ENIVNSAyUeCf8T4gpAu2+KHQqf1O 1Cg1Z24K9ztXCLz7pXxjbHobDh+klyqasJJeMPtdYEgO/PMSG1xWp9t0QH31LApRxrb21VhFqkZ uTFJAoqr4z7Ydb3N5Gp5ZXJDihJkeoswx2LBd9DBv+ZfNX59CM1kRL3f7Vr9+cO0CB2miL1Vjwg 9qYynbcOnG3RrWQ9m4IAEuJqW88ITggtMrIXvmRV43ssC625xe1gLcUznk7JiTWZxsRpKlTl4xZ 8d1wWMIaPjVitE4Y57bCSfu5maqR8wKQjDRrLtI3y09GMIi/M/E= X-Google-Smtp-Source: AGHT+IE0crRjB9HRFCalYWm1hjJO/xP7QWgt9BkE2vA+IItaNHeWguQc+99MOYmRxi7OZHcKsNQeyQ== X-Received: by 2002:a17:903:18a:b0:216:5448:22a4 with SMTP id d9443c01a7336-22368f6dc74mr226818155ad.10.1741001006109; Mon, 03 Mar 2025 03:23:26 -0800 (PST) Received: from wheely.local0.net ([118.208.151.101]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-223501f9e3bsm75388875ad.82.2025.03.03.03.23.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 03:23:25 -0800 (PST) From: Nicholas Piggin To: qemu-ppc@nongnu.org Cc: Nicholas Piggin , qemu-devel@nongnu.org Subject: [PATCH 2/3] target/ppc: Avoid work if MMU SPRs are written with same value Date: Mon, 3 Mar 2025 21:23:13 +1000 Message-ID: <20250303112315.586478-3-npiggin@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250303112315.586478-1-npiggin@gmail.com> References: <20250303112315.586478-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=npiggin@gmail.com; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Avoid TLB flushing and hflags recomputation if LPCR, LPIDR, or PIDR are written with the same value. This is observed to happen in some cases (e.g., in hypervisor real-mode exit fastpath handlers). Signed-off-by: Nicholas Piggin --- target/ppc/cpu.c | 8 +++++++- target/ppc/misc_helper.c | 14 +++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/target/ppc/cpu.c b/target/ppc/cpu.c index cdd50cb36d6..0fa2ccfcb2f 100644 --- a/target/ppc/cpu.c +++ b/target/ppc/cpu.c @@ -97,8 +97,14 @@ void ppc_store_lpcr(PowerPCCPU *cpu, target_ulong val) { PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); CPUPPCState *env = &cpu->env; + target_ulong old, new; - env->spr[SPR_LPCR] = val & pcc->lpcr_mask; + old = env->spr[SPR_LPCR]; + new = val & pcc->lpcr_mask; + if (old == new) { + return; + } + env->spr[SPR_LPCR] = new; /* The gtse bit affects hflags */ hreg_compute_hflags(env); diff --git a/target/ppc/misc_helper.c b/target/ppc/misc_helper.c index 179e8b6b4d2..ac439e00326 100644 --- a/target/ppc/misc_helper.c +++ b/target/ppc/misc_helper.c @@ -403,12 +403,24 @@ void helper_store_sprd(CPUPPCState *env, target_ulong val) void helper_store_pidr(CPUPPCState *env, target_ulong val) { + if (env->spr[SPR_BOOKS_PID] == (uint32_t)val) { + return; + } + env->spr[SPR_BOOKS_PID] = (uint32_t)val; - tlb_flush(env_cpu(env)); + + if (env->spr[SPR_LPCR] & LPCR_HR) { + /* PID is only relevant to CPU translations when LPCR[HR]=1 */ + tlb_flush(env_cpu(env)); + } } void helper_store_lpidr(CPUPPCState *env, target_ulong val) { + if (env->spr[SPR_LPIDR] == (uint32_t)val) { + return; + } + env->spr[SPR_LPIDR] = (uint32_t)val; /* From patchwork Mon Mar 3 11:23:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13998611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14DC3C282C6 for ; Mon, 3 Mar 2025 11:24:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tp3tY-0002wY-40; Mon, 03 Mar 2025 06:23:36 -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 1tp3tU-0002vX-Qp; Mon, 03 Mar 2025 06:23:32 -0500 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tp3tS-00077K-RS; Mon, 03 Mar 2025 06:23:32 -0500 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-2feb9076a1cso6586048a91.0; Mon, 03 Mar 2025 03:23:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741001008; x=1741605808; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TI7o/qEAGPSuly/owjhhS2EmzO3Fc7cBJEztAx9lX1I=; b=SUc6FVKVk8JsMVp2Dweb0ELJJsXnV7aFvU0qMkN5Fmh+f4Fxt0bbIupjo+KyTbjaFO p0LvlREUEQQ4SdC+mW77yskTdIF/Vs/WwTdnfno44K9tn8oDeE3Qb3XdUqdl+K5s/upq 3TRM1J4f3YEH9TThdyQozIECBW7N+Ms9PqaU+1FIQxc5ZVjC/atK5dlqt+sYUR+OCiAm Yq1Ox26jP7QJkytMClpSwe3mv6DVBTBWgM/hn/zqCQnXP95LLXF9wabM0Mlxc7ZE2QEV VOR8e9VWL/1k+V2nXzpPf+W3p512sKT5UXS1umgjofh0JLjbM4W5yNSfN6Ft62Da9WbI /x7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741001008; x=1741605808; 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=TI7o/qEAGPSuly/owjhhS2EmzO3Fc7cBJEztAx9lX1I=; b=Qr0wO3MMWEpuP4L7gaYC1k1wmsBn4FqEVxGBUaeuFiMRcJwCsOmD3fmw7h4HDqxYKt CezNCLBtTZxPRXks6dLDbxlro4aEZ7TFUbnXObcObtuTouR/eCTkg8a3u/8qxY9ZrrAc 3C7CGTggr40/cfnSOvw2y0jypitc3NvFNEYAtNhIpAVN36kJDxrAeSrMK22nSsOy6I6n RT6GqCn8xwH8OWN/x5SOOqLQbONN/UQ9TGJ2si12ZxhR4V+mp7gikm7KD8KJjgLBL3M/ f3qwtorX6ndClg8p6jLC73HAEse9uk1M3u0NJh+5PSuJKmh6xwN8T6n025etYUm2QXFh ak4g== X-Forwarded-Encrypted: i=1; AJvYcCXdfPW6yo/bDhJivhPdA9LBs8Oqflb6AMrdO9uqraHX8FzOGqyRrVSjUGf+LjfAjiM9MpqOUfZEGMKK@nongnu.org X-Gm-Message-State: AOJu0YyBSPvnEBXVpIcD4CKsdo+0a9Vt2SL15CG0PHpPessZUANbc//Z Q/x0f2JO3Dn3w0ZcXxj2rWwaaMjmDem7VxcKx1Xeo6JXXfBA4Bv6376oqQ== X-Gm-Gg: ASbGnctj+TM0CqkMTweIPf6MPSfuLGGEg3maUyvCfZnvsdANxAktBOASaG+E/ugF64E 79gpa3Lx5uFDCAM5C3rHCRm0l73zWZLEoBiwd1lqpXPyWhQkJ0pl9ulh+J+fDuc/r0JGccOxpYH p3R5OLELgGn6RvPuM+GiCONhVG0xhxRjn80btTIjs/O1eaMZfgPSrFtBgqgyuDiqdQtDSFTS7qA fhIy18DyR6OYU2fwOezQ4ngxQ1d59Mywt9fP5ZtCR12itLZ5GqeYILsCBtBYPTMth9izl+Naj7n rd41OXlb76Ea//Y8cn4YyQArKBQMwYgpUlrkyAXAk9yryTGtGOw= X-Google-Smtp-Source: AGHT+IEKO7rqC9gDjctM1FehSt5U9EYkDcUll1IwzNQTGcDajBJMU1A5VOGM/MDNL0T6yQrpdNF0pA== X-Received: by 2002:a17:90b:4c11:b0:2ee:a4f2:b307 with SMTP id 98e67ed59e1d1-2febab2ebcfmr19902859a91.4.1741001008575; Mon, 03 Mar 2025 03:23:28 -0800 (PST) Received: from wheely.local0.net ([118.208.151.101]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-223501f9e3bsm75388875ad.82.2025.03.03.03.23.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 03:23:28 -0800 (PST) From: Nicholas Piggin To: qemu-ppc@nongnu.org Cc: Nicholas Piggin , qemu-devel@nongnu.org Subject: [PATCH 3/3] target/ppc: add missing TLB flushes for memory protection key SPR updates Date: Mon, 3 Mar 2025 21:23:14 +1000 Message-ID: <20250303112315.586478-4-npiggin@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250303112315.586478-1-npiggin@gmail.com> References: <20250303112315.586478-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=npiggin@gmail.com; helo=mail-pj1-x1033.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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The IAMR and AMR registers are involved with MMU translations that are not tagged in the TLB (i.e., with mmuidx), so the TLB needs to be flushed when these are changed, e.g., as PIDR, LPIDR already do. This moves AMR and IAMR write to helpers rather than use tlb_need_flush because they can be written in problem state where tlb_need_flush is not checked. XXX: As far as I can tell this is needed for correct memory protection key operation, however it seems to be causing slowdowns when booting Linux, enough to cause failures due to timeouts, so I will not merge it at the moment. I have been considering possible ways to speed this up e.g., with mmu indexes, but that's not entirely trivial and needs a bit more work. Signed-off-by: Nicholas Piggin --- target/ppc/helper.h | 2 ++ target/ppc/cpu_init.c | 4 ++-- target/ppc/misc_helper.c | 48 +++++++++++++++++++++++++++++++++++++ target/ppc/translate.c | 52 ++-------------------------------------- 4 files changed, 54 insertions(+), 52 deletions(-) diff --git a/target/ppc/helper.h b/target/ppc/helper.h index 6178ebe138f..e8de4f95581 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -723,6 +723,8 @@ DEF_HELPER_FLAGS_1(load_vtb, TCG_CALL_NO_RWG, tl, env) #if defined(TARGET_PPC64) DEF_HELPER_FLAGS_1(load_purr, TCG_CALL_NO_RWG, tl, env) DEF_HELPER_FLAGS_2(store_purr, TCG_CALL_NO_RWG, void, env, tl) +DEF_HELPER_2(store_amr, void, env, tl) +DEF_HELPER_2(store_iamr, void, env, tl) DEF_HELPER_2(store_hrmor, void, env, tl) DEF_HELPER_2(store_ptcr, void, env, tl) DEF_HELPER_FLAGS_1(load_dpdes, TCG_CALL_NO_RWG, tl, env) diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index 92316b55afd..43af471ae64 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -238,7 +238,7 @@ static void register_amr_sprs(CPUPPCState *env) spr_register_kvm_hv(env, SPR_AMR, "AMR", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_amr, - &spr_read_generic, &spr_write_generic, + &spr_read_generic, &spr_write_amr, KVM_REG_PPC_AMR, 0); spr_register_kvm_hv(env, SPR_UAMOR, "UAMOR", SPR_NOACCESS, SPR_NOACCESS, @@ -259,7 +259,7 @@ static void register_iamr_sprs(CPUPPCState *env) spr_register_kvm_hv(env, SPR_IAMR, "IAMR", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_iamr, - &spr_read_generic, &spr_write_generic, + &spr_read_generic, &spr_write_iamr, KVM_REG_PPC_IAMR, 0); #endif /* !CONFIG_USER_ONLY */ } diff --git a/target/ppc/misc_helper.c b/target/ppc/misc_helper.c index ac439e00326..dfc9d806b30 100644 --- a/target/ppc/misc_helper.c +++ b/target/ppc/misc_helper.c @@ -169,6 +169,54 @@ void helper_store_sdr1(CPUPPCState *env, target_ulong val) } #if defined(TARGET_PPC64) +void helper_store_amr(CPUPPCState *env, target_ulong val) +{ + target_ulong old, new, mask; + + if (FIELD_EX64(env->msr, MSR, PR)) { + mask = env->spr[SPR_UAMOR]; + } else if (FIELD_EX64(env->msr, MSR, HV)) { + mask = (target_ulong)-1; + } else { + mask = env->spr[SPR_AMOR]; + } + + old = env->spr[SPR_AMR]; + /* Replace controllable bits with those in val */ + new = (old & ~mask) | (val & mask); + + if (old != new) { + CPUState *cs = env_cpu(env); + env->spr[SPR_AMR] = new; + /* AMR is involved in MMU translations so must flush TLB */ + tlb_flush(cs); + } +} + +void helper_store_iamr(CPUPPCState *env, target_ulong val) +{ + target_ulong old, new, mask; + + if (FIELD_EX64(env->msr, MSR, PR)) { + g_assert_not_reached(); /* mtIAMR is privileged */ + } else if (FIELD_EX64(env->msr, MSR, HV)) { + mask = (target_ulong)-1; + } else { + mask = env->spr[SPR_AMOR]; + } + + old = env->spr[SPR_IAMR]; + /* Replace controllable bits with those in val */ + new = (old & ~mask) | (val & mask); + + if (old != new) { + CPUState *cs = env_cpu(env); + env->spr[SPR_IAMR] = new; + /* IAMR is involved in MMU translations so must flush TLB */ + tlb_flush(cs); + } +} + void helper_store_hrmor(CPUPPCState *env, target_ulong val) { if (env->spr[SPR_HRMOR] != val) { diff --git a/target/ppc/translate.c b/target/ppc/translate.c index ac910151cfa..c5fe3de64e9 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -1080,33 +1080,7 @@ void spr_write_excp_vector(DisasContext *ctx, int sprn, int gprn) #ifndef CONFIG_USER_ONLY void spr_write_amr(DisasContext *ctx, int sprn, int gprn) { - TCGv t0 = tcg_temp_new(); - TCGv t1 = tcg_temp_new(); - TCGv t2 = tcg_temp_new(); - - /* - * Note, the HV=1 PR=0 case is handled earlier by simply using - * spr_write_generic for HV mode in the SPR table - */ - - /* Build insertion mask into t1 based on context */ - if (ctx->pr) { - gen_load_spr(t1, SPR_UAMOR); - } else { - gen_load_spr(t1, SPR_AMOR); - } - - /* Mask new bits into t2 */ - tcg_gen_and_tl(t2, t1, cpu_gpr[gprn]); - - /* Load AMR and clear new bits in t0 */ - gen_load_spr(t0, SPR_AMR); - tcg_gen_andc_tl(t0, t0, t1); - - /* Or'in new bits and write it out */ - tcg_gen_or_tl(t0, t0, t2); - gen_store_spr(SPR_AMR, t0); - spr_store_dump_spr(SPR_AMR); + gen_helper_store_amr(tcg_env, cpu_gpr[gprn]); } void spr_write_uamor(DisasContext *ctx, int sprn, int gprn) @@ -1138,29 +1112,7 @@ void spr_write_uamor(DisasContext *ctx, int sprn, int gprn) void spr_write_iamr(DisasContext *ctx, int sprn, int gprn) { - TCGv t0 = tcg_temp_new(); - TCGv t1 = tcg_temp_new(); - TCGv t2 = tcg_temp_new(); - - /* - * Note, the HV=1 case is handled earlier by simply using - * spr_write_generic for HV mode in the SPR table - */ - - /* Build insertion mask into t1 based on context */ - gen_load_spr(t1, SPR_AMOR); - - /* Mask new bits into t2 */ - tcg_gen_and_tl(t2, t1, cpu_gpr[gprn]); - - /* Load AMR and clear new bits in t0 */ - gen_load_spr(t0, SPR_IAMR); - tcg_gen_andc_tl(t0, t0, t1); - - /* Or'in new bits and write it out */ - tcg_gen_or_tl(t0, t0, t2); - gen_store_spr(SPR_IAMR, t0); - spr_store_dump_spr(SPR_IAMR); + gen_helper_store_iamr(tcg_env, cpu_gpr[gprn]); } #endif #endif