sys/powerpc64: encode PTCR PATS correctly

Kirill A. Korinsky <[email protected]>
Newsgroups gmane.os.openbsd.tech
Message-ID <[email protected]>
Mark, George,

Shivang Upadhyay in qemu-devel
https://marc.info/?l=qemu-devel&m=178332702820587&w=2 pointed that we may
have a typo kind of bug in powerpc64's pmap.

The PTCR PATS field stores log2(partition table size) - 12.  Since
PATMEMSZ is a power of two, ffs(PATMEMSZ) is log2(PATMEMSZ) + 1; the
old expression wrote 5 for the 64 KiB table, describing 128 KiB to
Book3S v3 hardware.

Use fls(PATMEMSZ) - 1 - 12 to express the intended log2 calculation
and encode the 64 KiB partition table as PATS == 4.

Ok?

Index: sys/arch/powerpc64/powerpc64/pmap.c
===================================================================
RCS file: /home/cvs/src/sys/arch/powerpc64/powerpc64/pmap.c,v
diff -u -p -r1.66 pmap.c
--- sys/arch/powerpc64/powerpc64/pmap.c	21 Aug 2025 00:10:21 -0000	1.66
+++ sys/arch/powerpc64/powerpc64/pmap.c	7 Jul 2026 20:20:55 -0000
@@ -124,7 +124,7 @@ uint64_t pmap_ptab_mask;
 struct pate *pmap_pat;
 
 #define PATMEMSZ	(64 * 1024)
-#define PATSIZE		(ffs(PATMEMSZ) - 12)
+#define PATSIZE		(fls(PATMEMSZ) - 1 - 12)
 
 struct pte_desc {
 	/* Linked list of phys -> virt entries */


-- 
wbr, Kirill
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.