mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master] ARM: mmu: align size of remapped region to page size
Date: Tue,  5 Dec 2023 09:12:47 +0100	[thread overview]
Message-ID: <20231205081247.4148947-1-a.fatoum@pengutronix.de> (raw)

Currently, barebox ARM arch_remap_range() will hang in an infinite loop,
when called with a size that's not aligned to a page boundary.
Its Linux equivalent, ioremap(), will just rounds up to page size and
work correctly. Adopt the Linux behavior to make porting code easier,
e.g. when calling devm_ioremap().

The only other arch_remap_range() in barebox, is PowerPC's. That one
wouldn't loop indefinitely if the size isn't page aligned, so nothing to
do there.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/cpu/mmu_32.c | 3 +++
 arch/arm/cpu/mmu_64.c | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/arch/arm/cpu/mmu_32.c b/arch/arm/cpu/mmu_32.c
index d0ada5866f05..c6eecf9c9d2d 100644
--- a/arch/arm/cpu/mmu_32.c
+++ b/arch/arm/cpu/mmu_32.c
@@ -18,6 +18,7 @@
 #include <memory.h>
 #include <asm/system_info.h>
 #include <asm/sections.h>
+#include <linux/pagemap.h>
 
 #include "mmu_32.h"
 
@@ -253,6 +254,8 @@ static void __arch_remap_range(void *_virt_addr, phys_addr_t phys_addr, size_t s
 	pte_flags = get_pte_flags(map_type);
 	pmd_flags = pte_flags_to_pmd(pte_flags);
 
+	size = PAGE_ALIGN(size);
+
 	while (size) {
 		const bool pgdir_size_aligned = IS_ALIGNED(virt_addr, PGDIR_SIZE);
 		u32 *pgd = (u32 *)&ttb[pgd_index(virt_addr)];
diff --git a/arch/arm/cpu/mmu_64.c b/arch/arm/cpu/mmu_64.c
index 12c4dc90b392..c6ea63e655ad 100644
--- a/arch/arm/cpu/mmu_64.c
+++ b/arch/arm/cpu/mmu_64.c
@@ -19,6 +19,7 @@
 #include <asm/cache.h>
 #include <memory.h>
 #include <asm/system_info.h>
+#include <linux/pagemap.h>
 
 #include "mmu_64.h"
 
@@ -132,6 +133,8 @@ static void create_sections(uint64_t virt, uint64_t phys, uint64_t size,
 
 	attr &= ~PTE_TYPE_MASK;
 
+	size = PAGE_ALIGN(size);
+
 	while (size) {
 		table = ttb;
 		for (level = 0; level < 4; level++) {
-- 
2.39.2




             reply	other threads:[~2023-12-05  8:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-05  8:12 Ahmad Fatoum [this message]
2023-12-05  8:24 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231205081247.4148947-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox