Skip to contentSkip to conversation

armv8: mmu: Detect page table overflow in emergency pt creation

PATCH Superseded Alexander Graf 2 participants 2 messages Jul 29, 2016 Arm (32-bit)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 armv8: mmu: Detect page table overflow in emergency pt creation

We create 2 sets of page tables: One for normal operation, one for emergency (used while modifying the former).

Because the page tables grow dynamically, we have code that checks for overflow. Unfortunately we didn't adjust the available space variable while creating the emergency tables, so potentially someone might run into an overflow there (not seen in real world yet though!).

Fix it by properly adjusting the size as well as the base offset in emergency page table creation.

---
 arch/arm/cpu/armv8/cache_v8.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/cpu/armv8/cache_v8.c +4 -0
index ac909a1..8a82bba 100644
@@ -380,6 +380,7 @@ void setup_pgtables(void)
 static void setup_all_pgtables(void)
 {
 	u64 tlb_addr = gd->arch.tlb_addr;
+	u64 tlb_size = gd->arch.tlb_size;
 
 	/* Reset the fill ptr */
 	gd->arch.tlb_fillptr = tlb_addr;
@@ -388,10 +389,13 @@ static void setup_all_pgtables(void)
 	setup_pgtables();
 
 	/* Create emergency page tables */
+	gd->arch.tlb_size -= ((uintptr_t)gd->arch.tlb_fillptr -
+			      (uintptr_t)gd->arch.tlb_addr);
 	gd->arch.tlb_addr = gd->arch.tlb_fillptr;
 	setup_pgtables();
 	gd->arch.tlb_emerg = gd->arch.tlb_addr;
 	gd->arch.tlb_addr = tlb_addr;
+	gd->arch.tlb_size = tlb_size;
 }
 
 /* to activate the MMU we need to set up virtual memory */
Signature · 1 line
1.8.5.6
#1 lore raw

PATCH 1/1 armv8: mmu: Detect page table overflow in emergency pt creation

Quoted 30 lines · Alexander Graf

We create 2 sets of page tables: One for normal operation, one for emergency (used while modifying the former).

Because the page tables grow dynamically, we have code that checks for overflow. Unfortunately we didn't adjust the available space variable while creating the emergency tables, so potentially someone might run into an overflow there (not seen in real world yet though!).

Fix it by properly adjusting the size as well as the base offset in emergency page table creation.

---
 arch/arm/cpu/armv8/cache_v8.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/cpu/armv8/cache_v8.c +1 -0
index ac909a1..8a82bba 100644
@@ -380,6 +380,7 @@ void setup_pgtables(void)
 static void setup_all_pgtables(void)
 {
 	u64 tlb_addr = gd->arch.tlb_addr;
+	u64 tlb_size = gd->arch.tlb_size;
 
 	/* Reset the fill ptr */
 	gd->arch.tlb_fillptr = tlb_addr;

arch/arm/cpu/armv8/cache_v8.c static void setup_all_pgtables(void) · line 393

Quoted 5 lines
arch/arm/cpu/armv8/cache_v8.c +2 -0
@@ -388,10 +389,13 @@ static void setup_all_pgtables(void)
 	setup_pgtables();
 
 	/* Create emergency page tables */
+	gd->arch.tlb_size -= ((uintptr_t)gd->arch.tlb_fillptr -
+			      (uintptr_t)gd->arch.tlb_addr);

nitpik. The parentheses are not necessary.

arch/arm/cpu/armv8/cache_v8.c static void setup_all_pgtables(void) · line 401

Quoted 9 lines
arch/arm/cpu/armv8/cache_v8.c +1 -0
 	gd->arch.tlb_addr = gd->arch.tlb_fillptr;
 	setup_pgtables();
 	gd->arch.tlb_emerg = gd->arch.tlb_addr;
 	gd->arch.tlb_addr = tlb_addr;
+	gd->arch.tlb_size = tlb_size;
 }
 
 /* to activate the MMU we need to set up virtual memory */