Skip to contentSkip to conversation

arm64: mm: drop redundant remap of FDT first page

PATCH In review Sang-Heon Jeon 2 participants 4 messages May 13 – May 27 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: mm: drop redundant remap of FDT first page

fixmap_remap_fdt() calls create_mapping_noalloc() to map the first page of the FDT to read its magic and totalsize from the header. If the FDT does not fit in a single page, it calls create_mapping_noalloc() again to map the rest.

The second mapping redundantly covers the first page that was just mapped by the first mapping.

Start the second mapping at dt_phys_base + PAGE_SIZE so it only covers the pages that have not been mapped yet. No functional change.

---
QEMU-based test results

$ qemu-system-aarch64 -M virt -singlestep -d nochain,exec ...

Count log lines from fixmap_remap_fdt() entry to return
- entry PC : address of the <fixmap_remap_fdt> symbol
- return PC : next address of each bl ... <fixmap_remap_fdt>

1) AS-IS
- 1st call (KERNEL) : 4935
- 2nd call (KERNEL_RO) : 14151
2) TO-BE
- 1st call : 4888
- 2nd call : 14104

---
Hello,

While looking into boot information, I found a minor cleanup point. If I misunderstood anything, please feel free to let me know.

Thank you for taking valuable time to review this work.

Best Regards,
Sang-Heon Jeon

---
 arch/arm64/mm/fixmap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/fixmap.c +3 -2
index c5c5425791da..f8aea5572f7c 100644
@@ -167,8 +167,9 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
 		return NULL;
 
 	if (offset + *size > PAGE_SIZE) {
-		create_mapping_noalloc(dt_phys_base, dt_virt_base,
-				       offset + *size, prot);
+		create_mapping_noalloc(dt_phys_base + PAGE_SIZE,
+			dt_virt_base + PAGE_SIZE,
+			offset + *size - PAGE_SIZE, prot);
 	}
 
 	return dt_virt;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 48 lines · Sang-Heon Jeon

fixmap_remap_fdt() calls create_mapping_noalloc() to map the first page of the FDT to read its magic and totalsize from the header. If the FDT does not fit in a single page, it calls create_mapping_noalloc() again to map the rest.

The second mapping redundantly covers the first page that was just mapped by the first mapping.

Start the second mapping at dt_phys_base + PAGE_SIZE so it only covers the pages that have not been mapped yet. No functional change.

---
QEMU-based test results

$ qemu-system-aarch64 -M virt -singlestep -d nochain,exec ...

Count log lines from fixmap_remap_fdt() entry to return
- entry PC : address of the <fixmap_remap_fdt> symbol
- return PC : next address of each bl ... <fixmap_remap_fdt>

1) AS-IS
- 1st call (KERNEL) : 4935
- 2nd call (KERNEL_RO) : 14151
2) TO-BE
- 1st call : 4888
- 2nd call : 14104

---
Hello,

While looking into boot information, I found a minor cleanup point. If I misunderstood anything, please feel free to let me know.

Thank you for taking valuable time to review this work.

Best Regards,
Sang-Heon Jeon

---
 arch/arm64/mm/fixmap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/fixmap.c +0 -0
index c5c5425791da..f8aea5572f7c 100644

arch/arm64/mm/fixmap.c void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot) · line 169

Quoted 3 lines
arch/arm64/mm/fixmap.c +0 -0
@@ -167,8 +167,9 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
                return NULL;
 
        if (offset + *size > PAGE_SIZE) {

Based on sashiko review [1], I made another patch [2]. Please check that patch as well. Thank you.

[1] https://sashiko.dev/#/patchset/20260513170101.1858213-1-ekffu200098%40gmail.com
[2] https://lore.kernel.org/all/[email protected]/

Best Regards,
Sang-Heon Jeon

Quoted 11 lines
arch/arm64/mm/fixmap.c +3 -3
-               create_mapping_noalloc(dt_phys_base, dt_virt_base,
-                                      offset + *size, prot);
+               create_mapping_noalloc(dt_phys_base + PAGE_SIZE,
+                       dt_virt_base + PAGE_SIZE,
+                       offset + *size - PAGE_SIZE, prot);
        }
 
        return dt_virt;
--

2.43.0

maintainer
#2 lore raw
In reply to Sang-Heon Jeon
Quoted 12 lines · Sang-Heon Jeon

fixmap_remap_fdt() calls create_mapping_noalloc() to map the first page of the FDT to read its magic and totalsize from the header. If the FDT does not fit in a single page, it calls create_mapping_noalloc() again to map the rest.

The second mapping redundantly covers the first page that was just mapped by the first mapping.

Start the second mapping at dt_phys_base + PAGE_SIZE so it only covers the pages that have not been mapped yet. No functional change.

[...]

Quoted 5 lines
arch/arm64/mm/fixmap.c +0 -0
index c5c5425791da..f8aea5572f7c 100644

arch/arm64/mm/fixmap.c void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot) · line 173

Quoted 9 lines
arch/arm64/mm/fixmap.c +3 -2
@@ -167,8 +167,9 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
 		return NULL;
 
 	if (offset + *size > PAGE_SIZE) {
-		create_mapping_noalloc(dt_phys_base, dt_virt_base,
-				       offset + *size, prot);
+		create_mapping_noalloc(dt_phys_base + PAGE_SIZE,
+			dt_virt_base + PAGE_SIZE,
+			offset + *size - PAGE_SIZE, prot);
 	}

Is it actually worth it? It's not that we allocate memory here or take a noticeable time to reach the first pte. I find the current easier to read.

Signature · 1 line
Catalin
#3 lore raw
Quoted 22 lines · Catalin Marinas
Quoted 12 lines · Sang-Heon Jeon

fixmap_remap_fdt() calls create_mapping_noalloc() to map the first page of the FDT to read its magic and totalsize from the header. If the FDT does not fit in a single page, it calls create_mapping_noalloc() again to map the rest.

The second mapping redundantly covers the first page that was just mapped by the first mapping.

Start the second mapping at dt_phys_base + PAGE_SIZE so it only covers the pages that have not been mapped yet. No functional change.

[...]

Quoted 7 lines
arch/arm64/mm/fixmap.c +0 -0
index c5c5425791da..f8aea5572f7c 100644
@@ -167,8 +167,9 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
              return NULL;
 
Quoted 11 lines

arch/arm64/mm/fixmap.c void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot) · line 173

Quoted 7 lines
arch/arm64/mm/fixmap.c +3 -2
      if (offset + *size > PAGE_SIZE) {
-             create_mapping_noalloc(dt_phys_base, dt_virt_base,
-                                    offset + *size, prot);
+             create_mapping_noalloc(dt_phys_base + PAGE_SIZE,
+                     dt_virt_base + PAGE_SIZE,
+                     offset + *size - PAGE_SIZE, prot);
      }

Is it actually worth it? It's not that we allocate memory here or take a noticeable time to reach the first pte. I find the current easier to read.

Fair point. This is just a minor cleanup on my side. If you feel the original reads better, happy to drop this patch.

Thanks for reviewing, Catalin.

Best Regards
Sang-Heon Jeon

Quoted 2 lines

--
Catalin