Skip to contentSkip to conversation

arm: skip nomap memblocks while finding the lowmem/highmem boundary

PATCH In review Chester Lin 3 participants 5 messages Aug 22, 2019 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: skip nomap memblocks while finding the lowmem/highmem boundary

adjust_lowmem_bounds() checks every memblocks in order to find the boundary between lowmem and highmem. However some memblocks could be marked as NOMAP so they are not used by kernel, which should be skipped while calculating the boundary.

---
 arch/arm/mm/mmu.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mm/mmu.c +3 -0
index 426d9085396b..b86dba44d828 100644
@@ -1181,6 +1181,9 @@ void __init adjust_lowmem_bounds(void)
 		phys_addr_t block_start = reg->base;
 		phys_addr_t block_end = reg->base + reg->size;
 
+		if (memblock_is_nomap(reg))
+			continue;
+
 		if (reg->base < vmalloc_limit) {
 			if (block_end > lowmem_limit)
 				/*
Signature · 1 line
2.22.0
#1 lore raw
Quoted 27 lines · Chester Lin

adjust_lowmem_bounds() checks every memblocks in order to find the boundary between lowmem and highmem. However some memblocks could be marked as NOMAP so they are not used by kernel, which should be skipped while calculating the boundary.

---
 arch/arm/mm/mmu.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mm/mmu.c +3 -0
index 426d9085396b..b86dba44d828 100644
@@ -1181,6 +1181,9 @@ void __init adjust_lowmem_bounds(void)
 		phys_addr_t block_start = reg->base;
 		phys_addr_t block_end = reg->base + reg->size;
 
+		if (memblock_is_nomap(reg))
+			continue;
+
 		if (reg->base < vmalloc_limit) {
 			if (block_end > lowmem_limit)
 				/*
Signature · 1 line
2.22.0

Hi Russell, Mike and Ard,

Per the discussion in the thread "[PATH] efi/arm: fix allocation failure ...",
(https://lkml.org/lkml/2019/8/21/163), I presume that the change to disregard NOMAP memblocks in adjust_lowmem_bounds() should be separated as a single patch.

Please let me know if any suggestion, thank you.

#2 lore raw
Quoted 31 lines · Chester Lin
Quoted 27 lines · Chester Lin

adjust_lowmem_bounds() checks every memblocks in order to find the boundary between lowmem and highmem. However some memblocks could be marked as NOMAP so they are not used by kernel, which should be skipped while calculating the boundary.

---
 arch/arm/mm/mmu.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mm/mmu.c +3 -0
index 426d9085396b..b86dba44d828 100644
@@ -1181,6 +1181,9 @@ void __init adjust_lowmem_bounds(void)
 		phys_addr_t block_start = reg->base;
 		phys_addr_t block_end = reg->base + reg->size;
 
+		if (memblock_is_nomap(reg))
+			continue;
+
 		if (reg->base < vmalloc_limit) {
 			if (block_end > lowmem_limit)
 				/*
Signature · 1 line
2.22.0

Hi Russell, Mike and Ard,

Quoted 5 lines

Per the discussion in the thread "[PATH] efi/arm: fix allocation failure ...",
(https://lkml.org/lkml/2019/8/21/163), I presume that the change to disregard NOMAP memblocks in adjust_lowmem_bounds() should be separated as a single patch.

Please let me know if any suggestion, thank you.

Let's add this one to the series:

From 06a986e79d60c310c804b3e550bd50316597aec5 Mon Sep 17 00:00:00 2001
From: Mike Rapoport <[email protected]>
Date: Thu, 22 Aug 2019 09:27:40 +0300
Subject: [PATCH] arm: ensure that usable memory in bank 0 starts from a
PMD-aligned address

The calculation of memblock_limit in adjust_lowmem_bounds() assumes that bank 0 starts from a PMD-aligned address. However, the beginning of the first bank may be NOMAP memory and the start of usable memory will be not aligned to PMD boundary. In such case the memblock_limit will be set to the end of the NOMAP region, which will prevent any memblock allocations.

Mark the region between the end of the NOMAP area and the next PMD-aligned address as NOMAP as well, so that the usable memory will start at PMD-aligned address.

---
 arch/arm/mm/mmu.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm/mm/mmu.c +16 -0
index 4495a26..25da9b2 100644
@@ -1177,6 +1177,22 @@ void __init adjust_lowmem_bounds(void)
 	 */
 	vmalloc_limit = (u64)(uintptr_t)vmalloc_min - PAGE_OFFSET + PHYS_OFFSET;
 
+	/*
+	 * The first usable region must be PMD aligned. Mark its start
+	 * as MEMBLOCK_NOMAP if it isn't
+	 */
+	for_each_memblock(memory, reg) {
+		if (!memblock_is_nomap(reg)) {
+			if (!IS_ALIGNED(reg->base, PMD_SIZE)) {
+				phys_addr_t len;
+
+				len = round_up(reg->base, PMD_SIZE) - reg->base;
+				memblock_mark_nomap(reg->base, len);
+			}
+			break;
+		}
+	}
+
 	for_each_memblock(memory, reg) {
 		phys_addr_t block_start = reg->base;
 		phys_addr_t block_end = reg->base + reg->size;
Signature · 6 lines
2.7.4


-- 
Sincerely yours,
Mike.
#3 lore raw
Quoted 54 lines · Mike Rapoport
Quoted 31 lines · Chester Lin
Quoted 25 lines · Chester Lin

adjust_lowmem_bounds() checks every memblocks in order to find the boundary between lowmem and highmem. However some memblocks could be marked as NOMAP so they are not used by kernel, which should be skipped while calculating the boundary.

---
 arch/arm/mm/mmu.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mm/mmu.c +3 -1
index 426d9085396b..b86dba44d828 100644
@@ -1181,6 +1181,9 @@ void __init adjust_lowmem_bounds(void)
            phys_addr_t block_start = reg->base;
            phys_addr_t block_end = reg->base + reg->size;
 
+           if (memblock_is_nomap(reg))
+                   continue;
+
            if (reg->base < vmalloc_limit) {
                    if (block_end > lowmem_limit)
                            /*
--
Quoted 2 lines

2.22.0

Hi Russell, Mike and Ard,

Quoted 5 lines

Per the discussion in the thread "[PATH] efi/arm: fix allocation failure ...",
(https://lkml.org/lkml/2019/8/21/163), I presume that the change to disregard NOMAP memblocks in adjust_lowmem_bounds() should be separated as a single patch.

Please let me know if any suggestion, thank you.

Let's add this one to the series:

From 06a986e79d60c310c804b3e550bd50316597aec5 Mon Sep 17 00:00:00 2001
From: Mike Rapoport <[email protected]>
Date: Thu, 22 Aug 2019 09:27:40 +0300
Subject: [PATCH] arm: ensure that usable memory in bank 0 starts from a
PMD-aligned address

The calculation of memblock_limit in adjust_lowmem_bounds() assumes that bank 0 starts from a PMD-aligned address. However, the beginning of the first bank may be NOMAP memory and the start of usable memory will be not aligned to PMD boundary. In such case the memblock_limit will be set to the end of the NOMAP region, which will prevent any memblock allocations.

Quoted 5 lines

Mark the region between the end of the NOMAP area and the next PMD-aligned address as NOMAP as well, so that the usable memory will start at PMD-aligned address.

Quoted 39 lines
---
 arch/arm/mm/mmu.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm/mm/mmu.c +16 -1
index 4495a26..25da9b2 100644
@@ -1177,6 +1177,22 @@ void __init adjust_lowmem_bounds(void)
         */
        vmalloc_limit = (u64)(uintptr_t)vmalloc_min - PAGE_OFFSET + PHYS_OFFSET;
 
+       /*
+        * The first usable region must be PMD aligned. Mark its start
+        * as MEMBLOCK_NOMAP if it isn't
+        */
+       for_each_memblock(memory, reg) {
+               if (!memblock_is_nomap(reg)) {
+                       if (!IS_ALIGNED(reg->base, PMD_SIZE)) {
+                               phys_addr_t len;
+
+                               len = round_up(reg->base, PMD_SIZE) - reg->base;
+                               memblock_mark_nomap(reg->base, len);
+                       }
+                       break;
+               }
+       }
+
        for_each_memblock(memory, reg) {
                phys_addr_t block_start = reg->base;
                phys_addr_t block_end = reg->base + reg->size;
--

2.7.4

--
Sincerely yours,
Mike.

Reviewed-by on v1 1/1
#4 lore raw
In reply to Chester Lin
Quoted 6 lines · Chester Lin

adjust_lowmem_bounds() checks every memblocks in order to find the boundary between lowmem and highmem. However some memblocks could be marked as NOMAP so they are not used by kernel, which should be skipped while calculating the boundary.

Quoted 21 lines
---
 arch/arm/mm/mmu.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mm/mmu.c +3 -0
index 426d9085396b..b86dba44d828 100644
@@ -1181,6 +1181,9 @@ void __init adjust_lowmem_bounds(void)
 		phys_addr_t block_start = reg->base;
 		phys_addr_t block_end = reg->base + reg->size;
 
+		if (memblock_is_nomap(reg))
+			continue;
+
 		if (reg->base < vmalloc_limit) {
 			if (block_end > lowmem_limit)
 				/*
Signature · 1 line
2.22.0
Signature · 2 lines
Sincerely yours,
Mike.