Skip to contentSkip to conversation

sparc64: Resolve conflict between sparc v9 and M7 on usage of bit 9 of TTE

PATCH RESEND Superseded Khalid Aziz 2 participants 3 messages Apr 27, 2015 – May 14, 2015 SPARC + UltraSPARC (sparc/sparc64)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 sparc64: Resolve conflict between sparc v9 and M7 on usage of bit 9 of TTE

sparc64: Resolve conflict between sparc v9 and M7 on usage of bit 9 of TTE

Bit 9 of TTE is CV (Cacheable in V-cache) on sparc v9 processor while the same bit 9 is MCDE (Memory Corruption Detection Enable) on M7 processor. This creates a conflicting usage of the same bit. Kernel sets TTE.cv bit on all pages for sun4v architecture which works well for sparc v9 but enables memory corruption detection on M7 processor which is not the intent. This patch adds code to determine if kernel is running on M7 processor and takes steps to not enable memory corruption detection in TTE erroneously.

---

Bits 63:60 of VA hold the version tag when MCD is enabled. Version tag values of 0x0 and 0xf are reserved values and are ignored for detecting MCD error. This makes it ok for kernel to run with TTE.mcde=1 for now and we could possibly avoid making changes to vmemmap_populate(), kern_large_tte() and sun4v_linear_pte_xor_finalize(). On the other hand, if processor designers choose to change this behavior in future, this could cause nasty breakage in the kernel. It is also not right to set a bit in TTE when the actual function of that bit is different from the intent of the code. In any case, I am ok with removing changes to kernel TTE setup functions if these changes cause concern.

 arch/sparc/include/asm/pgtable_64.h | 22 ++++++++-
 arch/sparc/include/asm/trap_block.h |  2 +
 arch/sparc/kernel/entry.h           |  2 +
 arch/sparc/kernel/setup_64.c        | 27 +++++++++++
 arch/sparc/kernel/vmlinux.lds.S     |  5 ++
 arch/sparc/mm/init_64.c             | 93 ++++++++++++++++++++++++++++++-------
 6 files changed, 133 insertions(+), 18 deletions(-)
arch/sparc/include/asm/pgtable_64.h +21 -1
index dc165eb..936aa88 100644
@@ -308,12 +308,26 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t prot)
 	"	sllx		%1, 32, %1\n"
 	"	or		%0, %1, %0\n"
 	"	.previous\n"
+	"	.section	.sun_m7_2insn_patch, \"ax\"\n"
+	"	.word		661b\n"
+	"	sethi		%%uhi(%4), %1\n"
+	"	sethi		%%hi(%4), %0\n"
+	"	.word		662b\n"
+	"	or		%1, %%ulo(%4), %1\n"
+	"	or		%0, %%lo(%4), %0\n"
+	"	.word		663b\n"
+	"	sllx		%1, 32, %1\n"
+	"	or		%0, %1, %0\n"
+	"	.previous\n"
 	: "=r" (mask), "=r" (tmp)
 	: "i" (_PAGE_PADDR_4U | _PAGE_MODIFIED_4U | _PAGE_ACCESSED_4U |
 	       _PAGE_CP_4U | _PAGE_CV_4U | _PAGE_E_4U |
 	       _PAGE_SPECIAL | _PAGE_PMD_HUGE | _PAGE_SZALL_4U),
 	  "i" (_PAGE_PADDR_4V | _PAGE_MODIFIED_4V | _PAGE_ACCESSED_4V |
 	       _PAGE_CP_4V | _PAGE_CV_4V | _PAGE_E_4V |
+	       _PAGE_SPECIAL | _PAGE_PMD_HUGE | _PAGE_SZALL_4V),
+	  "i" (_PAGE_PADDR_4V | _PAGE_MODIFIED_4V | _PAGE_ACCESSED_4V |
+	       _PAGE_CP_4V | _PAGE_E_4V |
 	       _PAGE_SPECIAL | _PAGE_PMD_HUGE | _PAGE_SZALL_4V));
 
 	return __pte((pte_val(pte) & mask) | (pgprot_val(prot) & ~mask));
@@ -342,9 +356,15 @@ static inline pgprot_t pgprot_noncached(pgprot_t prot)
 	"	andn		%0, %4, %0\n"
 	"	or		%0, %5, %0\n"
 	"	.previous\n"
+	"	.section	.sun_m7_2insn_patch, \"ax\"\n"
+	"	.word		661b\n"
+	"	andn		%0, %6, %0\n"
+	"	or		%0, %5, %0\n"
+	"	.previous\n"
 	: "=r" (val)
 	: "0" (val), "i" (_PAGE_CP_4U | _PAGE_CV_4U), "i" (_PAGE_E_4U),
-	             "i" (_PAGE_CP_4V | _PAGE_CV_4V), "i" (_PAGE_E_4V));
+			"i" (_PAGE_CP_4V | _PAGE_CV_4V), "i" (_PAGE_E_4V),
+			"i" (_PAGE_CP_4V));
 
 	return __pgprot(val);
 }
arch/sparc/include/asm/trap_block.h +2 -0
index 6fd4436..ec9c04d 100644
@@ -79,6 +79,8 @@ struct sun4v_2insn_patch_entry {
 };
 extern struct sun4v_2insn_patch_entry __sun4v_2insn_patch,
 	__sun4v_2insn_patch_end;
+extern struct sun4v_2insn_patch_entry __sun_m7_2insn_patch,
+	__sun_m7_2insn_patch_end;
 
 
 #endif /* !(__ASSEMBLY__) */
arch/sparc/kernel/entry.h +2 -0
index 07cc49e..0f67942 100644
@@ -69,6 +69,8 @@ void sun4v_patch_1insn_range(struct sun4v_1insn_patch_entry *,
 			     struct sun4v_1insn_patch_entry *);
 void sun4v_patch_2insn_range(struct sun4v_2insn_patch_entry *,
 			     struct sun4v_2insn_patch_entry *);
+void sun_m7_patch_2insn_range(struct sun4v_2insn_patch_entry *,
+			     struct sun4v_2insn_patch_entry *);
 extern unsigned int dcache_parity_tl1_occurred;
 extern unsigned int icache_parity_tl1_occurred;
 
arch/sparc/kernel/setup_64.c +27 -0
index c38d19f..606e3f9 100644
@@ -255,6 +255,30 @@ void sun4v_patch_2insn_range(struct sun4v_2insn_patch_entry *start,
 	}
 }
 
+void sun_m7_patch_2insn_range(struct sun4v_2insn_patch_entry *start,
+			     struct sun4v_2insn_patch_entry *end)
+{
+	while (start < end) {
+		unsigned long addr = start->addr;
+
+		*(unsigned int *) (addr +  0) = start->insns[0];
+		/* We are updating an instruction. Make sure it is
+		 * written out
+		 */
+		wmb();
+		__asm__ __volatile__("flush	%0" : : "r" (addr +  0));
+
+		*(unsigned int *) (addr +  4) = start->insns[1];
+		/* We are updating an instruction. Make sure it is
+		 * written out
+		 */
+		wmb();
+		__asm__ __volatile__("flush	%0" : : "r" (addr +  4));
+
+		start++;
+	}
+}
+
 static void __init sun4v_patch(void)
 {
 	extern void sun4v_hvapi_init(void);
@@ -267,6 +291,9 @@ static void __init sun4v_patch(void)
 
 	sun4v_patch_2insn_range(&__sun4v_2insn_patch,
 				&__sun4v_2insn_patch_end);
+	if (sun4v_chip_type = SUN4V_CHIP_SPARC_M7)
+		sun_m7_patch_2insn_range(&__sun_m7_2insn_patch,
+				&__sun_m7_2insn_patch_end);
 
 	sun4v_hvapi_init();
 }
arch/sparc/kernel/vmlinux.lds.S +5 -0
index 0924305..f1a2f68 100644
@@ -138,6 +138,11 @@ SECTIONS
 		*(.pause_3insn_patch)
 		__pause_3insn_patch_end = .;
 	}
+	.sun_m7_2insn_patch : {
+		__sun_m7_2insn_patch = .;
+		*(.sun_m7_2insn_patch)
+		__sun_m7_2insn_patch_end = .;
+	}
 	PERCPU_SECTION(SMP_CACHE_BYTES)
 
 	. = ALIGN(PAGE_SIZE);
arch/sparc/mm/init_64.c +76 -17

158 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer
#1 lore raw

From: Khalid Aziz <[email protected]>
Date: Mon, 27 Apr 2015 16:19:49 -0600

Quoted 4 lines
arch/sparc/include/asm/pgtable_64.h +0 -0
@@ -342,9 +356,15 @@ static inline pgprot_t pgprot_noncached(pgprot_t prot)
 	"	andn		%0, %4, %0\n"
 	"	or		%0, %5, %0\n"
 	"	.previous\n"

arch/sparc/include/asm/pgtable_64.h static inline pgprot_t pgprot_noncached(pgprot_t prot) · line 367

Quoted 10 lines
arch/sparc/include/asm/pgtable_64.h +7 -1
+	"	.section	.sun_m7_2insn_patch, \"ax\"\n"
+	"	.word		661b\n"
+	"	andn		%0, %6, %0\n"
+	"	or		%0, %5, %0\n"
+	"	.previous\n"
 	: "=r" (val)
 	: "0" (val), "i" (_PAGE_CP_4U | _PAGE_CV_4U), "i" (_PAGE_E_4U),
-	             "i" (_PAGE_CP_4V | _PAGE_CV_4V), "i" (_PAGE_E_4V));
+			"i" (_PAGE_CP_4V | _PAGE_CV_4V), "i" (_PAGE_E_4V),
+			"i" (_PAGE_CP_4V));

Please don't change the indentation of the "i" arguments.

Quoted 7 lines
arch/sparc/mm/init_64.c +1 -1
@@ -2446,18 +2471,35 @@ static void __init sun4u_pgprot_init(void)
 static void __init sun4v_pgprot_init(void)
 {
 	unsigned long page_none, page_shared, page_copy, page_readonly;
-	unsigned long page_exec_bit;
+	unsigned long page_exec_bit, page_cache4v_flag;
 	int i;

...

arch/sparc/mm/init_64.c static void __init sun4u_pgprot_init(void) · line 2493

Quoted 8 lines
arch/sparc/mm/init_64.c +8 -0
+	switch (sun4v_chip_type) {
+	case SUN4V_CHIP_SPARC_M7:
+		page_cache4v_flag = _PAGE_CP_4V;
+		break;
+	default:
+		page_cache4v_flag = _PAGE_CACHE_4V;
+		break;
+	}

Ok you've computed what cacheability bits to use in page_cache4v_flag.

arch/sparc/mm/init_64.c static void __init sun4v_pgprot_init(void) · line 2519

Quoted 12 lines
arch/sparc/mm/init_64.c +9 -1
-	kern_linear_pte_xor[0] |= (_PAGE_CP_4V | _PAGE_CV_4V |
+	switch (sun4v_chip_type) {
+	case SUN4V_CHIP_SPARC_M7:
+		kern_linear_pte_xor[0] |= (_PAGE_CP_4V | _PAGE_P_4V |
+				   _PAGE_W_4V);
+		break;
+	default:
+		kern_linear_pte_xor[0] |= (_PAGE_CP_4V | _PAGE_CV_4V |
 				   _PAGE_P_4V | _PAGE_W_4V);
+		break;
+	}

Then needlessly compute this all over again, just use the value you have already in page_cache4v_flag.

Quoted 9 lines
arch/sparc/mm/init_64.c +2 -3
@@ -2541,9 +2591,18 @@ static unsigned long kern_large_tte(unsigned long paddr)
 	       _PAGE_CP_4U | _PAGE_CV_4U | _PAGE_P_4U |
 	       _PAGE_EXEC_4U | _PAGE_L_4U | _PAGE_W_4U);
 	if (tlb_type = hypervisor)
-		val = (_PAGE_VALID | _PAGE_SZ4MB_4V |
-		       _PAGE_CP_4V | _PAGE_CV_4V | _PAGE_P_4V |
-		       _PAGE_EXEC_4V | _PAGE_W_4V);
+		switch (sun4v_chip_type) {
+		case SUN4V_CHIP_SPARC_M7:

arch/sparc/mm/init_64.c static unsigned long kern_large_tte(unsigned long paddr) · line 2605

Quoted 10 lines
arch/sparc/mm/init_64.c +10 -0
+			val = (_PAGE_VALID | _PAGE_SZ4MB_4V |
+			       _PAGE_CP_4V | _PAGE_P_4V |
+			       _PAGE_EXEC_4V | _PAGE_W_4V);
+			break;
+		default:
+			val = (_PAGE_VALID | _PAGE_SZ4MB_4V |
+			       _PAGE_CP_4V | _PAGE_CV_4V | _PAGE_P_4V |
+			       _PAGE_EXEC_4V | _PAGE_W_4V);
+			break;
+		}

Although in another function, we seem to compute it here yet again.

Perhaps early on put this into a "static unsigned long page_cache4v_flag" and just use that everywhere.

If you do it early enough in paging_init() you should be fine.

#2 lore raw
Quoted 9 lines · David Miller

Ok you've computed what cacheability bits to use in page_cache4v_flag.
.......
Although in another function, we seem to compute it here yet again.

Perhaps early on put this into a "static unsigned long page_cache4v_flag" and just use that everywhere.

If you do it early enough in paging_init() you should be fine.

Makes perfect sense. Thanks! I will send out a v2 patch.

--
Khalid