Skip to contentSkip to conversation

arm64: account for sparsemem section alignment when choosing vmemmap offset

PATCH New Ard Biesheuvel 5 participants 8 messages Mar 8, 2016 – Mar 9, 2016 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: account for sparsemem section alignment when choosing vmemmap offset

Commit dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region") fixed an issue where the struct page array would overflow into the adjacent virtual memory region if system RAM was placed so high up in physical memory that its addresses were not representable in the build time configured virtual address size.

However, the fix failed to take into account that the vmemmap region needs to be relatively aligned with respect to the sparsemem section size, so that a sequence of page structs corresponding with a sparsemem section in the linear region appears naturally aligned in the vmemmap region.

So round up vmemmap to sparsemem section size. Since this essentially moves the projection of the linear region up in memory, also revert the reduction of the size of the vmemmap region.

Fixes dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region")
---
 arch/arm64/include/asm/pgtable.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/include/asm/pgtable.h +3 -2
index f50608674580..819aff5d593f 100644
@@ -40,7 +40,7 @@
  * VMALLOC_END: extends to the available space below vmmemmap, PCI I/O space,
  *	fixed mappings and modules
  */
-#define VMEMMAP_SIZE		ALIGN((1UL << (VA_BITS - PAGE_SHIFT - 1)) * sizeof(struct page), PUD_SIZE)
+#define VMEMMAP_SIZE		ALIGN((1UL << (VA_BITS - PAGE_SHIFT)) * sizeof(struct page), PUD_SIZE)
 
 #ifndef CONFIG_KASAN
 #define VMALLOC_START		(VA_START)
@@ -52,7 +52,8 @@
 #define VMALLOC_END		(PAGE_OFFSET - PUD_SIZE - VMEMMAP_SIZE - SZ_64K)
 
 #define VMEMMAP_START		(VMALLOC_END + SZ_64K)
-#define vmemmap			((struct page *)VMEMMAP_START - (memstart_addr >> PAGE_SHIFT))
+#define vmemmap			((struct page *)VMEMMAP_START - \
+				 SECTION_ALIGN_DOWN(memstart_addr >> PAGE_SHIFT))
 
 #define FIRST_USER_ADDRESS	0UL
 
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 arm64: account for sparsemem section alignment when choosing vmemmap offset

Quoted 15 lines · Ard Biesheuvel

Commit dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region") fixed an issue where the struct page array would overflow into the adjacent virtual memory region if system RAM was placed so high up in physical memory that its addresses were not representable in the build time configured virtual address size.

However, the fix failed to take into account that the vmemmap region needs to be relatively aligned with respect to the sparsemem section size, so that a sequence of page structs corresponding with a sparsemem section in the linear region appears naturally aligned in the vmemmap region.

So round up vmemmap to sparsemem section size. Since this essentially moves the projection of the linear region up in memory, also revert the reduction of the size of the vmemmap region.

Quoted 6 lines
Fixes dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region")
---
 arch/arm64/include/asm/pgtable.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Why no "Cc: stable" in the signed-off-by area?

#2 lore raw

PATCH 1/1 arm64: account for sparsemem section alignment when choosing vmemmap offset

Quoted 16 lines · Greg KH
Quoted 15 lines · Ard Biesheuvel

Commit dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region") fixed an issue where the struct page array would overflow into the adjacent virtual memory region if system RAM was placed so high up in physical memory that its addresses were not representable in the build time configured virtual address size.

However, the fix failed to take into account that the vmemmap region needs to be relatively aligned with respect to the sparsemem section size, so that a sequence of page structs corresponding with a sparsemem section in the linear region appears naturally aligned in the vmemmap region.

So round up vmemmap to sparsemem section size. Since this essentially moves the projection of the linear region up in memory, also revert the reduction of the size of the vmemmap region.

Quoted 9 lines
Quoted 6 lines
Fixes dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region")
---
 arch/arm64/include/asm/pgtable.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Why no "Cc: stable" in the signed-off-by area?

Because Will nor Catalin have responded yet to the proposed fix, nor to the bug report itself. They may prefer another approach to fixing the original problem rather than putting this on top, so I don't feel it is up to me to add a cc stable at this time.

Signature · 1 line
Ard.
maintainer
#3 lore raw

PATCH 1/1 arm64: account for sparsemem section alignment when choosing vmemmap offset

In reply to Ard Biesheuvel
Quoted 27 lines · Ard Biesheuvel

Commit dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region") fixed an issue where the struct page array would overflow into the adjacent virtual memory region if system RAM was placed so high up in physical memory that its addresses were not representable in the build time configured virtual address size.

However, the fix failed to take into account that the vmemmap region needs to be relatively aligned with respect to the sparsemem section size, so that a sequence of page structs corresponding with a sparsemem section in the linear region appears naturally aligned in the vmemmap region.

So round up vmemmap to sparsemem section size. Since this essentially moves the projection of the linear region up in memory, also revert the reduction of the size of the vmemmap region.

Fixes dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region")
---
 arch/arm64/include/asm/pgtable.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/include/asm/pgtable.h +0 -0
index f50608674580..819aff5d593f 100644

arch/arm64/include/asm/pgtable.h line 43

Quoted 5 lines
arch/arm64/include/asm/pgtable.h +1 -1
@@ -40,7 +40,7 @@
  * VMALLOC_END: extends to the available space below vmmemmap, PCI I/O space,
  *	fixed mappings and modules
  */
-#define VMEMMAP_SIZE		ALIGN((1UL << (VA_BITS - PAGE_SHIFT - 1)) * sizeof(struct page), PUD_SIZE)
+#define VMEMMAP_SIZE		ALIGN((1UL << (VA_BITS - PAGE_SHIFT)) * sizeof(struct page), PUD_SIZE)

I think we could have extended the existing halved VMEMMAP_SIZE by PAGES_PER_SECTION * sizeof(struct page) to cope with the alignment but I don't think it's worth.

arch/arm64/include/asm/pgtable.h line 56

Quoted 10 lines
arch/arm64/include/asm/pgtable.h +2 -1
 #ifndef CONFIG_KASAN
 #define VMALLOC_START		(VA_START)
@@ -52,7 +52,8 @@
 #define VMALLOC_END		(PAGE_OFFSET - PUD_SIZE - VMEMMAP_SIZE - SZ_64K)
 
 #define VMEMMAP_START		(VMALLOC_END + SZ_64K)
-#define vmemmap			((struct page *)VMEMMAP_START - (memstart_addr >> PAGE_SHIFT))
+#define vmemmap			((struct page *)VMEMMAP_START - \
+				 SECTION_ALIGN_DOWN(memstart_addr >> PAGE_SHIFT))

It looks fine to me:

Will would probably pick it up tomorrow (and add a cc stable as well).

Signature · 1 line
Catalin
#4 lore raw

PATCH 1/1 arm64: account for sparsemem section alignment when choosing vmemmap offset

Quoted 23 lines · Catalin Marinas
Quoted 22 lines · Ard Biesheuvel

Commit dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region") fixed an issue where the struct page array would overflow into the adjacent virtual memory region if system RAM was placed so high up in physical memory that its addresses were not representable in the build time configured virtual address size.

However, the fix failed to take into account that the vmemmap region needs to be relatively aligned with respect to the sparsemem section size, so that a sequence of page structs corresponding with a sparsemem section in the linear region appears naturally aligned in the vmemmap region.

So round up vmemmap to sparsemem section size. Since this essentially moves the projection of the linear region up in memory, also revert the reduction of the size of the vmemmap region.

Fixes dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region")
---
 arch/arm64/include/asm/pgtable.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 15 lines

arch/arm64/include/asm/pgtable.h line 43

Quoted 10 lines
arch/arm64/include/asm/pgtable.h +1 -1
index f50608674580..819aff5d593f 100644
@@ -40,7 +40,7 @@
  * VMALLOC_END: extends to the available space below vmmemmap, PCI I/O space,
  *   fixed mappings and modules
  */
-#define VMEMMAP_SIZE         ALIGN((1UL << (VA_BITS - PAGE_SHIFT - 1)) * sizeof(struct page), PUD_SIZE)
+#define VMEMMAP_SIZE         ALIGN((1UL << (VA_BITS - PAGE_SHIFT)) * sizeof(struct page), PUD_SIZE)

I think we could have extended the existing halved VMEMMAP_SIZE by PAGES_PER_SECTION * sizeof(struct page) to cope with the alignment but I don't think it's worth.

Indeed. But it is only temporary anyway, since the problem this patch solves does not exist anymore in for-next/core, considering that memstart_addr itself should be sufficiently aligned by construction. So I intend to propose a revert of this change, after -rc1 perhaps?

Quoted 13 lines

arch/arm64/include/asm/pgtable.h line 56

Quoted 10 lines
arch/arm64/include/asm/pgtable.h +2 -1
 #ifndef CONFIG_KASAN
 #define VMALLOC_START                (VA_START)
@@ -52,7 +52,8 @@
 #define VMALLOC_END          (PAGE_OFFSET - PUD_SIZE - VMEMMAP_SIZE - SZ_64K)
 
 #define VMEMMAP_START                (VMALLOC_END + SZ_64K)
-#define vmemmap                      ((struct page *)VMEMMAP_START - (memstart_addr >> PAGE_SHIFT))
+#define vmemmap                      ((struct page *)VMEMMAP_START - \
+                              SECTION_ALIGN_DOWN(memstart_addr >> PAGE_SHIFT))

It looks fine to me:

Quoted 4 lines

Will would probably pick it up tomorrow (and add a cc stable as well).

Thanks

maintainer
#5 lore raw

PATCH 1/1 arm64: account for sparsemem section alignment when choosing vmemmap offset

Quoted 39 lines · Ard Biesheuvel
Quoted 23 lines · Catalin Marinas
Quoted 22 lines · Ard Biesheuvel

Commit dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region") fixed an issue where the struct page array would overflow into the adjacent virtual memory region if system RAM was placed so high up in physical memory that its addresses were not representable in the build time configured virtual address size.

However, the fix failed to take into account that the vmemmap region needs to be relatively aligned with respect to the sparsemem section size, so that a sequence of page structs corresponding with a sparsemem section in the linear region appears naturally aligned in the vmemmap region.

So round up vmemmap to sparsemem section size. Since this essentially moves the projection of the linear region up in memory, also revert the reduction of the size of the vmemmap region.

Fixes dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region")
---
 arch/arm64/include/asm/pgtable.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 14 lines

arch/arm64/include/asm/pgtable.h line 43

Quoted 10 lines
arch/arm64/include/asm/pgtable.h +1 -1
index f50608674580..819aff5d593f 100644
@@ -40,7 +40,7 @@
  * VMALLOC_END: extends to the available space below vmmemmap, PCI I/O space,
  *   fixed mappings and modules
  */
-#define VMEMMAP_SIZE         ALIGN((1UL << (VA_BITS - PAGE_SHIFT - 1)) * sizeof(struct page), PUD_SIZE)
+#define VMEMMAP_SIZE         ALIGN((1UL << (VA_BITS - PAGE_SHIFT)) * sizeof(struct page), PUD_SIZE)

I think we could have extended the existing halved VMEMMAP_SIZE by PAGES_PER_SECTION * sizeof(struct page) to cope with the alignment but I don't think it's worth.

Quoted 4 lines

Indeed. But it is only temporary anyway, since the problem this patch solves does not exist anymore in for-next/core, considering that memstart_addr itself should be sufficiently aligned by construction. So I intend to propose a revert of this change, after -rc1 perhaps?

Sounds fine.

Signature · 1 line
Catalin
#6 lore raw

PATCH 1/1 arm64: account for sparsemem section alignment when choosing vmemmap offset

In reply to Ard Biesheuvel
Quoted 11 lines · Ard Biesheuvel

Commit dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region") fixed an issue where the struct page array would overflow into the adjacent virtual memory region if system RAM was placed so high up in physical memory that its addresses were not representable in the build time configured virtual address size.

However, the fix failed to take into account that the vmemmap region needs to be relatively aligned with respect to the sparsemem section size, so that a sequence of page structs corresponding with a sparsemem section in the linear region appears naturally aligned in the vmemmap region.

Quoted 6 lines

So round up vmemmap to sparsemem section size. Since this essentially moves the projection of the linear region up in memory, also revert the reduction of the size of the vmemmap region.

Fixes dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region")

For me, this fixes the failures caused by dfd55ad85e4a

Quoted 29 lines
---
  arch/arm64/include/asm/pgtable.h | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/include/asm/pgtable.h +3 -2
index f50608674580..819aff5d593f 100644
@@ -40,7 +40,7 @@
   * VMALLOC_END: extends to the available space below vmmemmap, PCI I/O space,
   *	fixed mappings and modules
   */
-#define VMEMMAP_SIZE		ALIGN((1UL << (VA_BITS - PAGE_SHIFT - 1)) * sizeof(struct page), PUD_SIZE)
+#define VMEMMAP_SIZE		ALIGN((1UL << (VA_BITS - PAGE_SHIFT)) * sizeof(struct page), PUD_SIZE)
 
  #ifndef CONFIG_KASAN
  #define VMALLOC_START		(VA_START)
@@ -52,7 +52,8 @@
  #define VMALLOC_END		(PAGE_OFFSET - PUD_SIZE - VMEMMAP_SIZE - SZ_64K)
 
  #define VMEMMAP_START		(VMALLOC_END + SZ_64K)
-#define vmemmap			((struct page *)VMEMMAP_START - (memstart_addr >> PAGE_SHIFT))
+#define vmemmap			((struct page *)VMEMMAP_START - \
+				 SECTION_ALIGN_DOWN(memstart_addr >> PAGE_SHIFT))
 
  #define FIRST_USER_ADDRESS	0UL
 
#7 lore raw

PATCH 1/1 arm64: account for sparsemem section alignment when choosing vmemmap offset

In reply to Ard Biesheuvel
Quoted 15 lines · Ard Biesheuvel

Commit dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region") fixed an issue where the struct page array would overflow into the adjacent virtual memory region if system RAM was placed so high up in physical memory that its addresses were not representable in the build time configured virtual address size.

However, the fix failed to take into account that the vmemmap region needs to be relatively aligned with respect to the sparsemem section size, so that a sequence of page structs corresponding with a sparsemem section in the linear region appears naturally aligned in the vmemmap region.

So round up vmemmap to sparsemem section size. Since this essentially moves the projection of the linear region up in memory, also revert the reduction of the size of the vmemmap region.

Quoted 6 lines
Fixes dfd55ad85e4a ("arm64: vmemmap: use virtual projection of linear region")
---
 arch/arm64/include/asm/pgtable.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Sorry for the slight delay, I was flying back from the US and didn't read mail for a couple of days. Anyway, I'll send this for 4.5 along with a CC stable and the various tested-bys. Hopefully it won't be too late for final.

Will