Skip to contentSkip to conversation

parisc: Prevent ldil() to sign-extend into upper 32 bits

PATCH New Helge Deller 1 participant 4 messages May 17, 2022 PA-RISC architecture

lore
Share & tools
lore

Helge Deller

author maintainer
#0 lore raw

PATCH 1/4 parisc: Prevent ldil() to sign-extend into upper 32 bits

Add some build time checks to prevent that the various usages of

	"ldil L%(TMPALIAS_MAP_START), %reg"

sign-extends into the upper 32 bits when building a 64-bit kernel.

---
 arch/parisc/mm/init.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/parisc/mm/init.c +6 -0
index 1dc2e88e7b04..0a81499dd35e 100644
@@ -555,6 +555,12 @@ void __init mem_init(void)
 	BUILD_BUG_ON(PT_INITIAL > PTRS_PER_PGD);
 #endif
 
+#ifdef CONFIG_64BIT
+	/* avoid ldil_%L() asm statements to sign-extend into upper 32-bits */
+	BUILD_BUG_ON(__PAGE_OFFSET >= 0x80000000);
+	BUILD_BUG_ON(TMPALIAS_MAP_START >= 0x80000000);
+#endif
+
 	high_memory = __va((max_pfn << PAGE_SHIFT));
 	set_max_mapnr(max_low_pfn);
 	memblock_free_all();

--
2.35.3

author maintainer
#1 lore raw

PATCH 2/4 parisc: Fix comment for shr macro - usage of same registers are allowed

The comment that the source and target register can not be the same is wrong. Instead on PA2.0 use of extru can clobber upper 32-bits. This patch fixes the comment.

---
 arch/parisc/include/asm/assembly.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/include/asm/assembly.h +1 -1
index ea0cb318b13d..be784b41048c 100644
@@ -143,7 +143,7 @@
 	depd,z	\r, 63-(\sa), 64-(\sa), \t
 	.endm
 
-	/* Shift Right - note the r and t can NOT be the same! */
+	/* Shift Right for 32-bit. Clobbers upper 32-bit on PA2.0. */
 	.macro shr r, sa, t
 	extru \r, 31-(\sa), 32-(\sa), \t
 	.endm

--
2.35.3

author maintainer
#2 lore raw

PATCH 3/4 parisc: Add a dep_safe() macro to deposit a value in 32- and 64-kernels

In reply to Helge Deller
---
 arch/parisc/include/asm/assembly.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/parisc/include/asm/assembly.h +10 -0
index be784b41048c..0f0d4a496fef 100644
@@ -174,6 +174,16 @@
 #endif
 	.endm
 
+	/* The depw instruction leaves the most significant 32 bits of the
+	 * target register in an undefined state on PA 2.0 systems. */
+	.macro dep_safe i, p, len, t
+#ifdef CONFIG_64BIT
+	depd	\i, 32+(\p), \len, \t
+#else
+	depw	\i, \p, \len, \t
+#endif
+	.endm
+
 	/* load 32-bit 'value' into 'reg' compensating for the ldil
 	 * sign-extension when running in wide mode.
 	 * WARNING!! neither 'value' nor 'reg' can be expressions

--
2.35.3

author maintainer
#3 lore raw

PATCH 4/4 parisc: Optimize tmpalias function calls

In reply to Helge Deller

Instead of converting the physical address of the mapping to the tlb insert format inside all the various tmpalias functions, move this conversion over to the DTLB miss handler. The physical address is already in %r26 (or will be calculated into %r32), so there are no additional steps needed.

Additionally we can now use the dep_safe() and depi_safe() macros to avoid differentiating between 32- and 64-bit builds and as such make the code much more readable.

The check if "ldil L%(TMPALIAS_MAP_START)" would sign extend into the upper 32 bits can be dropped, because we added a compile time check in an earlier patch.

---
 arch/parisc/kernel/entry.S   | 13 ++----
 arch/parisc/kernel/pacache.S | 89 ++++++------------------------------
 2 files changed, 17 insertions(+), 85 deletions(-)
arch/parisc/kernel/entry.S +4 -9
index 2af27c8b4aa6..df8102fb435f 100644
@@ -566,11 +566,6 @@
 	.macro		do_alias	spc,tmp,tmp1,va,pte,prot,fault,patype
 	cmpib,COND(<>),n 0,\spc,\fault
 	ldil		L%(TMPALIAS_MAP_START),\tmp
-#if defined(CONFIG_64BIT) && (TMPALIAS_MAP_START >= 0x80000000)
-	/* on LP64, ldi will sign extend into the upper 32 bits,
-	 * which is behaviour we don't want */
-	depdi		0,31,32,\tmp
-#endif
 	copy		\va,\tmp1
 	depi_safe	0,31,TMPALIAS_SIZE_BITS+1,\tmp1
 	cmpb,COND(<>),n	\tmp,\tmp1,\fault
@@ -605,13 +600,13 @@
 	 * OK, it is in the temp alias region, check whether "from" or "to".
 	 * Check "subtle" note in pacache.S re: r23/r26.
 	 */
-#ifdef CONFIG_64BIT
-	extrd,u,*=	\va,63-TMPALIAS_SIZE_BITS,1,%r0
-#else
 	extrw,u,=	\va,31-TMPALIAS_SIZE_BITS,1,%r0
-#endif
 	or,COND(tr)	%r23,%r0,\pte
 	or		%r26,%r0,\pte
+
+	/* convert phys addr in \pte (from r23 or r26) to tlb insert format */
+	SHRREG		\pte,PAGE_SHIFT+PAGE_ADD_SHIFT-5, \pte
+	depi_safe	_PAGE_SIZE_ENCODING_DEFAULT, 31,5, \pte
 	.endm
 
 
arch/parisc/kernel/pacache.S +13 -76

128 lines not on this page · raw message

--
2.35.3