Skip to contentSkip to conversation

Fix possible race with 4level-fixup.h

PATCH In review Benjamin Herrenschmidt 2 participants 4 messages Feb 17, 2005 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix possible race with 4level-fixup.h

Hi !

When using 4level-fixup.h, a PMD page may end up beeing freed before the matching PGD entry is cleared due to the way the compatibility macros work. This can cause nasty races on some architectures.

This patch fixes it by defining pud_clear() to be pgd_clear(). That means we'll actually write 0 twice, a small price to pay here, especially seeing how easy it is to convert to the new headers anyway (hint hint, ppc & ppc64 patches as soon as 2.6.11 is out).

include/asm-generic/4level-fixup.h +1 -1
Index: linux-work/include/asm-generic/4level-fixup.h
===================================================================
@@ -24,7 +24,7 @@
 #define pud_bad(pud)			0
 #define pud_present(pud)		1
 #define pud_ERROR(pud)			do { } while (0)
-#define pud_clear(pud)			do { } while (0)
+#define pud_clear(pud)			pgd_clear((pgd_t *)(pud))
 
 #undef pud_free_tlb
 #define pud_free_tlb(tlb, x)            do { } while (0)
#1 lore raw
Quoted 18 lines · Benjamin Herrenschmidt

Hi !

When using 4level-fixup.h, a PMD page may end up beeing freed before the matching PGD entry is cleared due to the way the compatibility macros work. This can cause nasty races on some architectures.

This patch fixes it by defining pud_clear() to be pgd_clear(). That means we'll actually write 0 twice, a small price to pay here, especially seeing how easy it is to convert to the new headers anyway (hint hint, ppc & ppc64 patches as soon as 2.6.11 is out).

Index: linux-work/include/asm-generic/4level-fixup.h
===================================================================

include/asm-generic/4level-fixup.h line 28

Quoted 6 lines
include/asm-generic/4level-fixup.h +1 -1
@@ -24,7 +24,7 @@
 #define pud_bad(pud)			0
 #define pud_present(pud)		1
 #define pud_ERROR(pud)			do { } while (0)
-#define pud_clear(pud)			do { } while (0)
+#define pud_clear(pud)			pgd_clear((pgd_t *)(pud))
 

Just a small nit - no cast needed here.

#2 lore raw
Quoted 14 lines · Nick Piggin
Quoted 13 lines · Benjamin Herrenschmidt

Hi !

When using 4level-fixup.h, a PMD page may end up beeing freed before the matching PGD entry is cleared due to the way the compatibility macros work. This can cause nasty races on some architectures.

This patch fixes it by defining pud_clear() to be pgd_clear(). That means we'll actually write 0 twice, a small price to pay here, especially seeing how easy it is to convert to the new headers anyway (hint hint, ppc & ppc64 patches as soon as 2.6.11 is out).

Quoted 13 lines

include/asm-generic/4level-fixup.h line 28

Quoted 11 lines

Index: linux-work/include/asm-generic/4level-fixup.h
===================================================================

include/asm-generic/4level-fixup.h +1 -1
@@ -24,7 +24,7 @@
 #define pud_bad(pud)			0
 #define pud_present(pud)		1
 #define pud_ERROR(pud)			do { } while (0)
-#define pud_clear(pud)			do { } while (0)
+#define pud_clear(pud)			pgd_clear((pgd_t *)(pud))
 

Just a small nit - no cast needed here.

Well, do you know ? pud is a pud_t* and the arch is free to implement pgd_clear as an inline with strong typing no ?

Ben.

#3 lore raw
Quoted 15 lines · Benjamin Herrenschmidt
Quoted 5 lines
Quoted 5 lines

Index: linux-work/include/asm-generic/4level-fixup.h
===================================================================

include/asm-generic/4level-fixup.h +0 -0
@@ -24,7 +24,7 @@
Quoted 8 lines

include/asm-generic/4level-fixup.h line 28

Quoted 6 lines
include/asm-generic/4level-fixup.h +1 -1
 #define pud_bad(pud)			0
 #define pud_present(pud)		1
 #define pud_ERROR(pud)			do { } while (0)
-#define pud_clear(pud)			do { } while (0)
+#define pud_clear(pud)			pgd_clear((pgd_t *)(pud))
 

Just a small nit - no cast needed here.

Quoted 3 lines

Well, do you know ? pud is a pud_t* and the arch is free to implement pgd_clear as an inline with strong typing no ?

Yeah but if you're using the 4level-fixup.h header, then you get
#define pud_t pgd_t

Not that I really mind, but in this header we've just avoided doing casts for that reason.

Nick