Skip to contentSkip to conversation

Virtual memory size detection for 64 bit MIPS CPUs

PATCH Superseded Guenter Roeck 2 participants 2 messages Feb 2, 2010 MIPS

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 Virtual memory size detection for 64 bit MIPS CPUs

Linux kernel 2.6.32 and later allocates memory from the top of virtual memory space.

This patch implements virtual memory size detection for 64 bit MIPS CPUs to avoid resulting crashes.

---
 arch/mips/include/asm/cpu-features.h |    3 +++
 arch/mips/include/asm/cpu-info.h     |    1 +
 arch/mips/include/asm/pgtable-64.h   |    4 +++-
 arch/mips/kernel/cpu-probe.c         |   12 ++++++++++++
 4 files changed, 19 insertions(+), 1 deletions(-)
arch/mips/include/asm/cpu-features.h +3 -0
index 1f4df64..284eb55 100644
@@ -209,6 +209,9 @@
 # ifndef cpu_has_64bit_addresses
 # define cpu_has_64bit_addresses	1
 # endif
+# ifndef cpu_vmbits
+# define cpu_vmbits cpu_data[0].vmbits
+# endif
 #endif
 
 #if defined(CONFIG_CPU_MIPSR2_IRQ_VI) && !defined(cpu_has_vint)
arch/mips/include/asm/cpu-info.h +1 -0
index 1260443..3c694bc 100644
@@ -58,6 +58,7 @@ struct cpuinfo_mips {
 	struct cache_desc	tcache;	/* Tertiary/split secondary cache */
 	int			srsets;	/* Shadow register sets */
 	int			core;	/* physical core number */
+	int			vmbits;	/* Virtual memory size in bits */
 #if defined(CONFIG_MIPS_MT_SMP) || defined(CONFIG_MIPS_MT_SMTC)
 	/*
 	 * In the MIPS MT "SMTC" model, each TC is considered
arch/mips/include/asm/pgtable-64.h +3 -1
index 9cd5089..259ec58 100644
@@ -110,7 +110,9 @@
 #define VMALLOC_START		MAP_BASE
 #define VMALLOC_END	\
 	(VMALLOC_START + \
-	 PTRS_PER_PGD * PTRS_PER_PMD * PTRS_PER_PTE * PAGE_SIZE - (1UL << 32))
+	 min(PTRS_PER_PGD * PTRS_PER_PMD * PTRS_PER_PTE * PAGE_SIZE, \
+	     (1UL<<cpu_vmbits)) - (1UL << 32))
+
 #if defined(CONFIG_MODULES) && defined(KBUILD_64BIT_SYM32) && \
 	VMALLOC_START != CKSSEG
 /* Load modules into 32bit-compatible segment. */
arch/mips/kernel/cpu-probe.c +12 -0
index 7a51866..ac9aca1 100644
@@ -282,6 +282,16 @@ static inline int __cpu_has_fpu(void)
 	return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
 }
 
+static inline void cpu_set_vmbits(struct cpuinfo_mips *c)
+{
+	if (cpu_has_64bits) {
+		write_c0_entryhi(0xfffffffffffff000ULL);
+		back_to_back_c0_hazard();
+		c->vmbits = fls64(read_c0_entryhi() & 0x3ffffffffffff000ULL);
+	} else
+		c->vmbits = 32;
+}
+
 #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
 		| MIPS_CPU_COUNTER)
 
@@ -967,6 +977,8 @@ __cpuinit void cpu_probe(void)
 		c->srsets = ((read_c0_srsctl() >> 26) & 0x0f) + 1;
 	else
 		c->srsets = 1;
+
+	cpu_set_vmbits(c);
 }
 
 __cpuinit void cpu_report(void)
Signature · 1 line
1.6.0.4
#1 lore raw

Hello.

Quoted 8 lines · Guenter Roeck

Linux kernel 2.6.32 and later allocates memory from the top of virtual memory space.

This patch implements virtual memory size detection for 64 bit MIPS CPUs to avoid resulting crashes.

[...]

arch/mips/include/asm/pgtable-64.h line 115

Quoted 12 lines
arch/mips/include/asm/pgtable-64.h +2 -1
index 9cd5089..259ec58 100644
@@ -110,7 +110,9 @@
 #define VMALLOC_START		MAP_BASE
 #define VMALLOC_END	\
 	(VMALLOC_START + \
-	 PTRS_PER_PGD * PTRS_PER_PMD * PTRS_PER_PTE * PAGE_SIZE - (1UL << 32))
+	 min(PTRS_PER_PGD * PTRS_PER_PMD * PTRS_PER_PTE * PAGE_SIZE, \
+	     (1UL<<cpu_vmbits)) - (1UL << 32))
 

Why you've added spaces around the second << but not around the
first? Should be more consistent.

Quoted 9 lines
arch/mips/include/asm/pgtable-64.h +1 -0
+
 #if defined(CONFIG_MODULES) && defined(KBUILD_64BIT_SYM32) && \
 	VMALLOC_START != CKSSEG

/* Load modules into 32bit-compatible segment. */

arch/mips/kernel/cpu-probe.c +0 -0
index 7a51866..ac9aca1 100644

arch/mips/kernel/cpu-probe.c static inline int __cpu_has_fpu(void) · line 291

Quoted 10 lines
arch/mips/kernel/cpu-probe.c +6 -0
@@ -282,6 +282,16 @@ static inline int __cpu_has_fpu(void)
 	return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
 }
 
+static inline void cpu_set_vmbits(struct cpuinfo_mips *c)
+{
+	if (cpu_has_64bits) {
+		write_c0_entryhi(0xfffffffffffff000ULL);
+		back_to_back_c0_hazard();
+		c->vmbits = fls64(read_c0_entryhi() & 0x3ffffffffffff000ULL);
 

I don't quite understand why set bits 62-63 only to mask them off
later...

WBR, Sergei