Skip to contentSkip to conversation

arm[64]/memremap: fix arch_memremap_can_ram_remap()

PATCH Superseded Ross Stutterheim 6 participants 11 messages Apr 14, 2025 – Apr 19, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm[64]/memremap: fix arch_memremap_can_ram_remap()

commit 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map") added the definition of arch_memremap_can_ram_remap() for arm[64] specific filtering of what pages can be used from the linear mapping. memblock_is_map_memory() was called with the pfn of the address given to arch_memremap_can_ram_remap(); however, memblock_is_map_memory() expects to be given an address, not a pfn.

This results in calls to memremap() returning a newly mapped area when it should return an address in the existing linear mapping.

Fix this by removing the address to pfn translation and pass the address directly.

Fixes 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map")
---
 arch/arm/mm/ioremap.c   | 4 +---
 arch/arm64/mm/ioremap.c | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)
arch/arm/mm/ioremap.c +1 -3
index 748698e91a4b..27e64f782cb3 100644
@@ -515,7 +515,5 @@ void __init early_ioremap_init(void)
 bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size,
 				 unsigned long flags)
 {
-	unsigned long pfn = PHYS_PFN(offset);
-
-	return memblock_is_map_memory(pfn);
+	return memblock_is_map_memory(offset);
 }
arch/arm64/mm/ioremap.c +1 -3
index 10e246f11271..48c38c986b95 100644
@@ -51,7 +51,5 @@ void __init early_ioremap_init(void)
 bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size,
 				 unsigned long flags)
 {
-	unsigned long pfn = PHYS_PFN(offset);
-
-	return pfn_is_map_memory(pfn);
+	return pfn_is_map_memory(offset);
 }
Signature · 1 line
2.49.0
maintainer
#1 lore raw

Please cc the maintainers and the original contributor of the commit you are fixing, otherwise the patch may not be noticed.

Quoted 26 lines · Ross Stutterheim

commit 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map") added the definition of arch_memremap_can_ram_remap() for arm[64] specific filtering of what pages can be used from the linear mapping. memblock_is_map_memory() was called with the pfn of the address given to arch_memremap_can_ram_remap(); however, memblock_is_map_memory() expects to be given an address, not a pfn.

This results in calls to memremap() returning a newly mapped area when it should return an address in the existing linear mapping.

Fix this by removing the address to pfn translation and pass the address directly.

Fixes 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map")
---
 arch/arm/mm/ioremap.c   | 4 +---
 arch/arm64/mm/ioremap.c | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)
arch/arm/mm/ioremap.c +0 -0
index 748698e91a4b..27e64f782cb3 100644

arch/arm/mm/ioremap.c void __init early_ioremap_init(void) · line 519

Quoted 8 lines
arch/arm/mm/ioremap.c +1 -3
@@ -515,7 +515,5 @@ void __init early_ioremap_init(void)
 bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size,
 				 unsigned long flags)
 {
-	unsigned long pfn = PHYS_PFN(offset);
-
-	return memblock_is_map_memory(pfn);
+	return memblock_is_map_memory(offset);
 }

This indeed needs fixing.

arch/arm64/mm/ioremap.c void __init early_ioremap_init(void) · line 54

Quoted 12 lines
arch/arm64/mm/ioremap.c +1 -3
index 10e246f11271..48c38c986b95 100644
@@ -51,7 +51,5 @@ void __init early_ioremap_init(void)
 bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size,
 				 unsigned long flags)
 {
-	unsigned long pfn = PHYS_PFN(offset);
-
-	return pfn_is_map_memory(pfn);
+	return pfn_is_map_memory(offset);

This is already correct.

Signature · 1 line
Catalin
#2 lore raw
Quoted 2 lines · Catalin Marinas

Please cc the maintainers and the original contributor of the commit you are fixing, otherwise the patch may not be noticed.

Thanks for adding them on your reply. I will add to V2.

Quoted 6 lines
Quoted 6 lines
arch/arm64/mm/ioremap.c +0 -0
index 10e246f11271..48c38c986b95 100644
@@ -51,7 +51,5 @@ void __init early_ioremap_init(void)
  bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size,
Quoted 8 lines

arch/arm64/mm/ioremap.c void __init early_ioremap_init(void) · line 54

Quoted 6 lines
arch/arm64/mm/ioremap.c +1 -3
  				 unsigned long flags)
  {
-	unsigned long pfn = PHYS_PFN(offset);
-
-	return pfn_is_map_memory(pfn);
+	return pfn_is_map_memory(offset);

This is already correct.

Will remove on V2.

--
Ross

#3 lore raw

PATCH v2 1/1 arm/memremap: fix arch_memremap_can_ram_remap()

In reply to Ross Stutterheim

commit 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map") added the definition of arch_memremap_can_ram_remap() for arm[64] specific filtering of what pages can be used from the linear mapping. memblock_is_map_memory() was called with the pfn of the address given to arch_memremap_can_ram_remap(); however, memblock_is_map_memory() expects to be given an address for arm, not a pfn.

This results in calls to memremap() returning a newly mapped area when it should return an address in the existing linear mapping.

Fix this by removing the address to pfn translation and pass the address directly.

Fixes 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map")
---
 arch/arm/mm/ioremap.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm/mm/ioremap.c +1 -3
index 748698e91a4b..27e64f782cb3 100644
@@ -515,7 +515,5 @@ void __init early_ioremap_init(void)
 bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size,
 				 unsigned long flags)
 {
-	unsigned long pfn = PHYS_PFN(offset);
-
-	return memblock_is_map_memory(pfn);
+	return memblock_is_map_memory(offset);
 }
Signature · 1 line
2.49.0
maintainer Reviewed-by on v2 1/1
#4 lore raw

Re: [PATCH v2] arm/memremap: fix arch_memremap_can_ram_remap()

Quoted 8 lines · Ross Stutterheim

commit 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map") added the definition of arch_memremap_can_ram_remap() for arm[64] specific filtering of what pages can be used from the linear mapping. memblock_is_map_memory() was called with the pfn of the address given to arch_memremap_can_ram_remap(); however, memblock_is_map_memory() expects to be given an address for arm, not a pfn.

Quoted 8 lines

This results in calls to memremap() returning a newly mapped area when it should return an address in the existing linear mapping.

Fix this by removing the address to pfn translation and pass the address directly.

Fixes 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map")

I think you could also add:

Quoted 9 lines
---
 arch/arm/mm/ioremap.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm/mm/ioremap.c +0 -0
index 748698e91a4b..27e64f782cb3 100644

arch/arm/mm/ioremap.c void __init early_ioremap_init(void) · line 519

Quoted 8 lines
arch/arm/mm/ioremap.c +1 -3
@@ -515,7 +515,5 @@ void __init early_ioremap_init(void)
 bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size,
 				 unsigned long flags)
 {
-	unsigned long pfn = PHYS_PFN(offset);
-
-	return memblock_is_map_memory(pfn);
+	return memblock_is_map_memory(offset);
 }

Not sure how Russell picks patches up these days (I used to send them to the patch system -
https://www.arm.linux.org.uk/developer/patches/info.php).

It might be simpler with git send-email (that's the alias I had):

  git send-email --add-header="KernelVersion: $(git describe --abbrev=0)" --no-thread --suppress-cc=all --to="[email protected]"
Signature · 1 line
Catalin
#5 lore raw

Re: [PATCH v2] arm/memremap: fix arch_memremap_can_ram_remap()

Quoted 6 lines · Catalin Marinas
Quoted 2 lines
Fixes 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map")

I think you could also add:

Done. I also added some other Cc: entries on V3 along with Reviewed-by: lines . I'm new here, so I'm not sure I've used those 100% properly.

Quoted 8 lines

Not sure how Russell picks patches up these days (I used to send them to the patch system -
https://www.arm.linux.org.uk/developer/patches/info.php).

It might be simpler with git send-email (that's the alias I had):

   git send-email --add-header="KernelVersion: $(git describe --abbrev=0)" --no-thread --suppress-cc=all --to="[email protected]"

Thanks. I created an account there and submitted V3 through the web interface (to avoid my SMTP server appending more stuff on the end).

--
Ross

#6 lore raw

Re: [PATCH v2] arm/memremap: fix arch_memremap_can_ram_remap()

Quoted 14 lines · Ross Stutterheim
Quoted 6 lines · Catalin Marinas
Quoted 2 lines
Fixes 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map")

I think you could also add:

Done. I also added some other Cc: entries on V3 along with Reviewed-by:
lines . I'm new here, so I'm not sure I've used those 100% properly.

Quoted 4 lines

Not sure how Russell picks patches up these days (I used to send them to the patch system -
https://www.arm.linux.org.uk/developer/patches/info.php).

Quoted 6 lines
Quoted 4 lines

It might be simpler with git send-email (that's the alias I had):

   git send-email --add-header="KernelVersion: $(git describe --abbrev=0)" --no-thread --suppress-cc=all --to="[email protected]"

Thanks. I created an account there and submitted V3 through the web interface (to avoid my SMTP server appending more stuff on the end).

Thanks, seems all good, applied and pushed out. I'll send it to Linus tomorrow as it's certainly a serious regression.

I'm surprised Mike hasn't responded...

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
maintainer
#7 lore raw

Re: [PATCH v2] arm/memremap: fix arch_memremap_can_ram_remap()

Quoted 19 lines · Russell King
Quoted 18 lines · Ross Stutterheim
Quoted 6 lines · Catalin Marinas
Quoted 2 lines
Fixes 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map")

I think you could also add:

Done. I also added some other Cc: entries on V3 along with Reviewed-by:
lines . I'm new here, so I'm not sure I've used those 100% properly.

Quoted 8 lines

Not sure how Russell picks patches up these days (I used to send them to the patch system -
https://www.arm.linux.org.uk/developer/patches/info.php).

It might be simpler with git send-email (that's the alias I had):

   git send-email --add-header="KernelVersion: $(git describe --abbrev=0)" --no-thread --suppress-cc=all --to="[email protected]"
Quoted 7 lines
Quoted 2 lines

Thanks. I created an account there and submitted V3 through the web interface (to avoid my SMTP server appending more stuff on the end).

Thanks, seems all good, applied and pushed out. I'll send it to Linus tomorrow as it's certainly a serious regression.

I'm surprised Mike hasn't responded...

Ah, I think he joined Microsoft. Adding his kernel.org address.

Signature · 1 line
Catalin
#8 lore raw

Re: [PATCH v2] arm/memremap: fix arch_memremap_can_ram_remap()

In reply to Russell King (Oracle)
Quoted 19 lines · Russell King (Oracle)
Quoted 18 lines · Ross Stutterheim
Quoted 6 lines · Catalin Marinas
Quoted 2 lines
Fixes 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map")

I think you could also add:

Done. I also added some other Cc: entries on V3 along with Reviewed-by:
lines . I'm new here, so I'm not sure I've used those 100% properly.

Quoted 8 lines

Not sure how Russell picks patches up these days (I used to send them to the patch system -
https://www.arm.linux.org.uk/developer/patches/info.php).

It might be simpler with git send-email (that's the alias I had):

   git send-email --add-header="KernelVersion: $(git describe --abbrev=0)" --no-thread --suppress-cc=all --to="[email protected]"
Quoted 7 lines
Quoted 2 lines

Thanks. I created an account there and submitted V3 through the web interface (to avoid my SMTP server appending more stuff on the end).

Thanks, seems all good, applied and pushed out. I'll send it to Linus tomorrow as it's certainly a serious regression.

I'm surprised Mike hasn't responded...

Passover vacation :)

Quoted 3 lines
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Signature · 2 lines
Sincerely yours,
Mike.
Reviewed-by on v2 1/1
#9 lore raw

Re: [PATCH v2] arm/memremap: fix arch_memremap_can_ram_remap()

In reply to Ross Stutterheim
Quoted 8 lines · Ross Stutterheim

commit 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map") added the definition of arch_memremap_can_ram_remap() for arm[64] specific filtering of what pages can be used from the linear mapping. memblock_is_map_memory() was called with the pfn of the address given to arch_memremap_can_ram_remap(); however, memblock_is_map_memory() expects to be given an address for arm, not a pfn.

Quoted 8 lines

This results in calls to memremap() returning a newly mapped area when it should return an address in the existing linear mapping.

Fix this by removing the address to pfn translation and pass the address directly.

Fixes 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map")

OMG

Also add Cc: [email protected] as pointed out by Catalin.

Yours,
Linus Walleij

#10 lore raw

PATCH v3 1/1 arm/memremap: fix arch_memremap_can_ram_remap()

In reply to Ross Stutterheim

commit 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map") added the definition of arch_memremap_can_ram_remap() for arm[64] specific filtering of what pages can be used from the linear mapping. memblock_is_map_memory() was called with the pfn of the address given to arch_memremap_can_ram_remap(); however, memblock_is_map_memory() expects to be given an address for arm, not a pfn.

This results in calls to memremap() returning a newly mapped area when it should return an address in the existing linear mapping.

Fix this by removing the address to pfn translation and pass the address directly.

Fixes 260364d112bc ("arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map")
Cc Mike Rapoport <[email protected]>
Cc Russell King <[email protected]>
---
 arch/arm/mm/ioremap.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm/mm/ioremap.c +1 -3
index 748698e91a4b..27e64f782cb3 100644
@@ -515,7 +515,5 @@ void __init early_ioremap_init(void)
 bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size,
 				 unsigned long flags)
 {
-	unsigned long pfn = PHYS_PFN(offset);
-
-	return memblock_is_map_memory(pfn);
+	return memblock_is_map_memory(offset);
 }
Signature · 1 line
2.49.0