Skip to contentSkip to conversation

x86/mm: Don't free P4D table when it is folded at runtime

PATCH Superseded Andrey Ryabinin 2 participants 7 messages Jul 2, 2018 1 message not in the archive Stable branch

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 x86/mm: Don't free P4D table when it is folded at runtime

From: "[email protected]" <[email protected]>

commit 0e311d237d7f3022b7dafb639b42541bfb42fe94 upstream.

When the P4D page table layer is folded at runtime, the p4d_free() should do nothing, the same as in <asm-generic/pgtable-nop4d.h>.

It seems this bug should cause double-free in efi_call_phys_epilog(), but I don't know how to trigger that code path, so I can't confirm that by testing.

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes 98219dda2ab5 ("x86/mm: Fold p4d page table layer at runtime")
---
 arch/x86/include/asm/pgalloc.h | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/include/asm/pgalloc.h +3 -0
index 263c142a6a6c..f65e9e1cea4c 100644
@@ -184,6 +184,9 @@ static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr)
 
 static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
 {
+	if (!pgtable_l5_enabled)
+		return;
+
 	BUG_ON((unsigned long)p4d & (PAGE_SIZE-1));
 	free_page((unsigned long)p4d);
 }
Signature · 1 line
2.16.4
maintainer
#2 lore raw
Quoted 1 line · Andrey Ryabinin

From: "[email protected]" <[email protected]>

Huh? I didn't write this patch.

Quoted 29 lines

commit 0e311d237d7f3022b7dafb639b42541bfb42fe94 upstream.

When the P4D page table layer is folded at runtime, the p4d_free() should do nothing, the same as in <asm-generic/pgtable-nop4d.h>.

It seems this bug should cause double-free in efi_call_phys_epilog(), but I don't know how to trigger that code path, so I can't confirm that by testing.

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes 98219dda2ab5 ("x86/mm: Fold p4d page table layer at runtime")
---
 arch/x86/include/asm/pgalloc.h | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/include/asm/pgalloc.h +0 -0
index 263c142a6a6c..f65e9e1cea4c 100644

arch/x86/include/asm/pgalloc.h static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr) · line 189

Quoted 6 lines
arch/x86/include/asm/pgalloc.h +3 -0
@@ -184,6 +184,9 @@ static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr)
 
 static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
 {
+	if (!pgtable_l5_enabled)
+		return;
+

Did you test build this patch?

Please do so, and be careful about author attribution, again, I did not write this patch.

greg k-h

#3 lore raw
Quoted 4 lines · Greg KH
Quoted 1 line · Andrey Ryabinin

From: "[email protected]" <[email protected]>

Huh? I didn't write this patch.

Right, I've noticed this and sent v2 with this fixed.
It's because I did 'git am' on your email with backported patch, but missed that git changed the autorship.

Quoted 31 lines
Quoted 31 lines

commit 0e311d237d7f3022b7dafb639b42541bfb42fe94 upstream.

When the P4D page table layer is folded at runtime, the p4d_free() should do nothing, the same as in <asm-generic/pgtable-nop4d.h>.

It seems this bug should cause double-free in efi_call_phys_epilog(), but I don't know how to trigger that code path, so I can't confirm that by testing.

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes 98219dda2ab5 ("x86/mm: Fold p4d page table layer at runtime")
---
 arch/x86/include/asm/pgalloc.h | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/include/asm/pgalloc.h +0 -0
index 263c142a6a6c..f65e9e1cea4c 100644
@@ -184,6 +184,9 @@ static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr)
 
Quoted 8 lines

arch/x86/include/asm/pgalloc.h static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr) · line 189

Quoted 5 lines
arch/x86/include/asm/pgalloc.h +3 -0
 static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
 {
+	if (!pgtable_l5_enabled)
+		return;
+

Did you test build this patch?

Sure, successfully built on top of 4.17.3

Quoted 5 lines

Please do so, and be careful about author attribution, again, I did not write this patch.

greg k-h

#4 lore raw

PATCH v2 1/1 x86/mm: Don't free P4D table when it is folded at runtime

In reply to a message not in the archive

commit 0e311d237d7f3022b7dafb639b42541bfb42fe94 upstream.

When the P4D page table layer is folded at runtime, the p4d_free() should do nothing, the same as in <asm-generic/pgtable-nop4d.h>.

It seems this bug should cause double-free in efi_call_phys_epilog(), but I don't know how to trigger that code path, so I can't confirm that by testing.

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes 98219dda2ab5 ("x86/mm: Fold p4d page table layer at runtime")

---

Changes since v1:
- Fix wrong "From:" field

 arch/x86/include/asm/pgalloc.h | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/include/asm/pgalloc.h +3 -0
index 263c142a6a6c..f65e9e1cea4c 100644
@@ -184,6 +184,9 @@ static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr)
 
 static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
 {
+	if (!pgtable_l5_enabled)
+		return;
+
 	BUG_ON((unsigned long)p4d & (PAGE_SIZE-1));
 	free_page((unsigned long)p4d);
 }
Signature · 1 line
2.16.4
maintainer
#5 lore raw
Quoted 32 lines · Andrey Ryabinin

commit 0e311d237d7f3022b7dafb639b42541bfb42fe94 upstream.

When the P4D page table layer is folded at runtime, the p4d_free() should do nothing, the same as in <asm-generic/pgtable-nop4d.h>.

It seems this bug should cause double-free in efi_call_phys_epilog(), but I don't know how to trigger that code path, so I can't confirm that by testing.

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes 98219dda2ab5 ("x86/mm: Fold p4d page table layer at runtime")

---

Changes since v1:
- Fix wrong "From:" field

 arch/x86/include/asm/pgalloc.h | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/include/asm/pgalloc.h +0 -0
index 263c142a6a6c..f65e9e1cea4c 100644

arch/x86/include/asm/pgalloc.h static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr) · line 189

Quoted 6 lines
arch/x86/include/asm/pgalloc.h +3 -0
@@ -184,6 +184,9 @@ static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr)
 
 static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
 {
+	if (!pgtable_l5_enabled)
+		return;
+

Again, did you actually test-build this? What changed from the original patch which blew the build up into little tiny pieces?

greg k-h

#6 lore raw
Quoted 34 lines · Greg KH
Quoted 33 lines · Andrey Ryabinin

commit 0e311d237d7f3022b7dafb639b42541bfb42fe94 upstream.

When the P4D page table layer is folded at runtime, the p4d_free() should do nothing, the same as in <asm-generic/pgtable-nop4d.h>.

It seems this bug should cause double-free in efi_call_phys_epilog(), but I don't know how to trigger that code path, so I can't confirm that by testing.

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes 98219dda2ab5 ("x86/mm: Fold p4d page table layer at runtime")

---

Changes since v1:
- Fix wrong "From:" field

 arch/x86/include/asm/pgalloc.h | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/include/asm/pgalloc.h +0 -0
index 263c142a6a6c..f65e9e1cea4c 100644
@@ -184,6 +184,9 @@ static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr)
 
Quoted 7 lines

arch/x86/include/asm/pgalloc.h static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr) · line 189

Quoted 5 lines
arch/x86/include/asm/pgalloc.h +3 -0
 static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
 {
+	if (!pgtable_l5_enabled)
+		return;
+

Again, did you actually test-build this?

Again, yes, I did test-build this.

Quoted 3 lines

What changed from the original
patch which blew the build up into little tiny pieces?

Removed '()'. In 4.17 pgtable_l5_enabled is variable, in 4.18 it's function.

Quoted 2 lines

greg k-h

maintainer
#7 lore raw
Quoted 45 lines · Andrey Ryabinin
Quoted 34 lines · Greg KH
Quoted 33 lines · Andrey Ryabinin

commit 0e311d237d7f3022b7dafb639b42541bfb42fe94 upstream.

When the P4D page table layer is folded at runtime, the p4d_free() should do nothing, the same as in <asm-generic/pgtable-nop4d.h>.

It seems this bug should cause double-free in efi_call_phys_epilog(), but I don't know how to trigger that code path, so I can't confirm that by testing.

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes 98219dda2ab5 ("x86/mm: Fold p4d page table layer at runtime")

---

Changes since v1:
- Fix wrong "From:" field

 arch/x86/include/asm/pgalloc.h | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/include/asm/pgalloc.h +0 -0
index 263c142a6a6c..f65e9e1cea4c 100644
@@ -184,6 +184,9 @@ static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr)
 
Quoted 7 lines

arch/x86/include/asm/pgalloc.h static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr) · line 189

Quoted 5 lines
arch/x86/include/asm/pgalloc.h +3 -0
 static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
 {
+	if (!pgtable_l5_enabled)
+		return;
+

Again, did you actually test-build this?

Quoted 7 lines

Again, yes, I did test-build this.

Quoted 3 lines

What changed from the original
patch which blew the build up into little tiny pieces?

Removed '()'. In 4.17 pgtable_l5_enabled is variable, in 4.18 it's function.

Ah, good, it wasn't obvious that you changed anything. I'll queue this up after these latest kernels are released in a few days.

thanks,

greg k-h