From: sesame_h@qq.com
To: qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, npiggin@gmail.com, adityag@linux.ibm.com,
milesg@linux.ibm.com, harshpb@linux.ibm.com, rathc@linux.ibm.com,
Minhang Zhang <zhangminhang@kylinos.cn>
Subject: [PATCH] target/ppc: Validate HTABMASK and reserved bits in SDR1 for 32-bit mode
Date: Fri, 7 Aug 2026 17:17:35 +0800 [thread overview]
Message-ID: <tencent_8A3172131A5ED2AD86D441389EB32CF67809@qq.com> (raw)
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.
Signed-off-by: Minhang Zhang <zhangminhang@kylinos.cn>
---
target/ppc/mmu_common.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/target/ppc/mmu_common.c b/target/ppc/mmu_common.c
index 2499e61..59e8324 100644
--- a/target/ppc/mmu_common.c
+++ b/target/ppc/mmu_common.c
@@ -57,9 +57,23 @@ void ppc_store_sdr1(CPUPPCState *env, target_ulong value)
" stored in SDR1", htabsize);
return;
}
- }
+ } else
#endif /* defined(TARGET_PPC64) */
- /* FIXME: Should check for valid HTABMASK values in 32-bit case */
+ {
+ target_ulong htabmask = value & SDR_32_HTABMASK;
+ if (value & 0x007F0000UL) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "Invalid SDR1: reserved bits 0x" TARGET_FMT_lx
+ " set\n", value & 0x007F0000UL);
+ value &= ~0x007F0000UL;
+ }
+ 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.43.0
next reply other threads:[~2026-08-07 12:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 9:17 sesame_h [this message]
2026-08-11 13:17 ` [PATCH] target/ppc: Validate HTABMASK and reserved bits in SDR1 for 32-bit mode Chinmay Rath
2026-08-11 13:21 ` Chinmay Rath
2026-08-14 3:06 ` sesame_h
2026-08-14 8:29 ` Chinmay Rath
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=tencent_8A3172131A5ED2AD86D441389EB32CF67809@qq.com \
--to=sesame_h@qq.com \
--cc=adityag@linux.ibm.com \
--cc=harshpb@linux.ibm.com \
--cc=milesg@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@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.