diff mbox series

arm[64]/memremap: fix arch_memremap_can_ram_remap()

Message ID 20250414133219.107455-1-ross.stutterheim@garmin.com (mailing list archive)
State New
Headers show
Series arm[64]/memremap: fix arch_memremap_can_ram_remap() | expand

Commit Message

Ross Stutterheim April 14, 2025, 1:32 p.m. UTC
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")
Signed-off-by: Ross Stutterheim <ross.stutterheim@garmin.com>
---
 arch/arm/mm/ioremap.c   | 4 +---
 arch/arm64/mm/ioremap.c | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

Comments

Catalin Marinas April 14, 2025, 1:49 p.m. UTC | #1
Please cc the maintainers and the original contributor of the commit you
are fixing, otherwise the patch may not be noticed.

On Mon, Apr 14, 2025 at 08:32:19AM -0500, Ross Stutterheim wrote:
> 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")
> Signed-off-by: Ross Stutterheim <ross.stutterheim@garmin.com>
> ---
>  arch/arm/mm/ioremap.c   | 4 +---
>  arch/arm64/mm/ioremap.c | 4 +---
>  2 files changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
> index 748698e91a4b..27e64f782cb3 100644
> --- a/arch/arm/mm/ioremap.c
> +++ b/arch/arm/mm/ioremap.c
> @@ -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.

> diff --git a/arch/arm64/mm/ioremap.c b/arch/arm64/mm/ioremap.c
> index 10e246f11271..48c38c986b95 100644
> --- a/arch/arm64/mm/ioremap.c
> +++ b/arch/arm64/mm/ioremap.c
> @@ -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.
Ross Stutterheim April 14, 2025, 2:18 p.m. UTC | #2
On 4/14/25 08:49, Catalin Marinas wrote:
> 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.

>> diff --git a/arch/arm64/mm/ioremap.c b/arch/arm64/mm/ioremap.c
>> index 10e246f11271..48c38c986b95 100644
>> --- a/arch/arm64/mm/ioremap.c
>> +++ b/arch/arm64/mm/ioremap.c
>> @@ -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.
Will remove on V2.

--
Ross
diff mbox series

Patch

diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
index 748698e91a4b..27e64f782cb3 100644
--- a/arch/arm/mm/ioremap.c
+++ b/arch/arm/mm/ioremap.c
@@ -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);
 }
diff --git a/arch/arm64/mm/ioremap.c b/arch/arm64/mm/ioremap.c
index 10e246f11271..48c38c986b95 100644
--- a/arch/arm64/mm/ioremap.c
+++ b/arch/arm64/mm/ioremap.c
@@ -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);
 }