From: Nicholas Piggin <npiggin@gmail.com>
To: qemu-ppc@nongnu.org
Cc: Nicholas Piggin <npiggin@gmail.com>, 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 [thread overview]
Message-ID: <20250303112315.586478-3-npiggin@gmail.com> (raw)
In-Reply-To: <20250303112315.586478-1-npiggin@gmail.com>
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 <npiggin@gmail.com>
---
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;
/*
--
2.47.1
next prev parent reply other threads:[~2025-03-03 11:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-03 11:23 [PATCH 0/3] target/ppc: Fixes for TCG TLB modeling of some MMU SPRs Nicholas Piggin
2025-03-03 11:23 ` [PATCH 1/3] target/ppc: flush TLB on HRMOR and LPCR SPR updates Nicholas Piggin
2025-03-03 11:23 ` Nicholas Piggin [this message]
2025-03-03 11:23 ` [PATCH 3/3] target/ppc: add missing TLB flushes for memory protection key " Nicholas Piggin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250303112315.586478-3-npiggin@gmail.com \
--to=npiggin@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).