From: Harsh Prateek Bora <harshpb@linux.ibm.com>
To: qemu-devel@nongnu.org
Cc: Minhang Zhang <zhangminhang@kylinos.cn>,
Chinmay Rath <rathc@linux.ibm.com>
Subject: [PULL 2/7] target/ppc: Validate HTABMASK and reserved bits in SDR1 for 32-bit mode
Date: Sun, 23 Aug 2026 13:05:28 +0530 [thread overview]
Message-ID: <20260823073536.40282-3-harshpb@linux.ibm.com> (raw)
In-Reply-To: <20260823073536.40282-1-harshpb@linux.ibm.com>
From: Minhang Zhang <zhangminhang@kylinos.cn>
ppc_store_sdr1() had validation for 64-bit SDR1 values but lacked
corresponding checks for the 32-bit case. According to the Power ISA,
in 32-bit mode SDR1 bits 16-22 are reserved (must be zero) and
HTABMASK (bits 23-31) must consist of a consecutive string of
1-bits starting from the LSB, i.e., be of the form 2^n-1.
Add checks to reject invalid HTABMASK values and log a guest error
for non-zero reserved bits, following the same pattern used by the
existing 64-bit validation.
Reviewed-by: Chinmay Rath <rathc@linux.ibm.com>
Signed-off-by: Minhang Zhang <zhangminhang@kylinos.cn>
Link: https://lore.kernel.org/qemu-devel/tencent_8388D4B38DC5172F5EEE70436D3AD6D02006@qq.com
Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
---
target/ppc/mmu_common.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/target/ppc/mmu_common.c b/target/ppc/mmu_common.c
index 2499e619f8..2a36817181 100644
--- a/target/ppc/mmu_common.c
+++ b/target/ppc/mmu_common.c
@@ -42,24 +42,39 @@ void ppc_store_sdr1(CPUPPCState *env, target_ulong value)
PowerPCCPU *cpu = env_archcpu(env);
qemu_log_mask(CPU_LOG_MMU, "%s: " TARGET_FMT_lx "\n", __func__, value);
assert(!cpu->env.has_hv_mode || !cpu->vhyp);
-#if defined(TARGET_PPC64)
if (mmu_is_64bit(env->mmu_model)) {
+#if defined(TARGET_PPC64)
target_ulong sdr_mask = SDR_64_HTABORG | SDR_64_HTABSIZE;
target_ulong htabsize = value & SDR_64_HTABSIZE;
if (value & ~sdr_mask) {
qemu_log_mask(LOG_GUEST_ERROR, "Invalid bits 0x"TARGET_FMT_lx
- " set in SDR1", value & ~sdr_mask);
+ " set in SDR1\n", value & ~sdr_mask);
value &= sdr_mask;
}
if (htabsize > 28) {
qemu_log_mask(LOG_GUEST_ERROR, "Invalid HTABSIZE 0x" TARGET_FMT_lx
- " stored in SDR1", htabsize);
+ " stored in SDR1\n", htabsize);
return;
}
- }
#endif /* defined(TARGET_PPC64) */
- /* FIXME: Should check for valid HTABMASK values in 32-bit case */
+ } else {
+ target_ulong sdr_mask = SDR_32_HTABORG | SDR_32_HTABMASK;
+ target_ulong htabmask = value & SDR_32_HTABMASK;
+
+ if (value & ~sdr_mask) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "Invalid bits 0x" TARGET_FMT_lx
+ " set in SDR1\n", value & ~sdr_mask);
+ value &= sdr_mask;
+ }
+ if ((htabmask & (htabmask + 1)) != 0) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "Invalid HTABMASK 0x" TARGET_FMT_lx
+ " in SDR1 (must be of form 2^n-1)\n", htabmask);
+ return;
+ }
+ }
env->spr[SPR_SDR1] = value;
}
--
2.52.0
next prev parent reply other threads:[~2026-08-23 7:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-23 7:35 [PULL 0/7] ppc-for-11.2 queue Harsh Prateek Bora
2026-08-23 7:35 ` [PULL 1/7] target/ppc/cpu_init: make cpu listing deterministic Harsh Prateek Bora
2026-08-23 7:35 ` Harsh Prateek Bora [this message]
2026-08-23 7:35 ` [PULL 3/7] MAINTAINERS: Add myself as a reviewer for PPC KVM and sPAPR Harsh Prateek Bora
2026-08-23 7:35 ` [PULL 4/7] hw/watchdog: Add lower bound check for watchdogNumber Harsh Prateek Bora
2026-08-23 7:35 ` [PULL 5/7] powernv: boot OpenBSD on POWER9 Harsh Prateek Bora
2026-08-23 7:35 ` [PULL 6/7] MAINTAINERS: add dedicated PowerPC RAS section Harsh Prateek Bora
2026-08-23 7:35 ` [PULL 7/7] MAINTAINERS: add self as reviewer for PowerPC RAS Harsh Prateek Bora
2026-08-24 6:03 ` [PULL 0/7] ppc-for-11.2 queue Richard Henderson
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=20260823073536.40282-3-harshpb@linux.ibm.com \
--to=harshpb@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=rathc@linux.ibm.com \
--cc=zhangminhang@kylinos.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.