Skip to contentSkip to conversation

arm64: mm: fix max_mapnr is assigned the wrong value

PATCH In review Muchun Song 2 participants 4 messages Mar 30, 2019 – Apr 1, 2019 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: mm: fix max_mapnr is assigned the wrong value

When we not use flat memory, the mem_map will be NULL and pfn_to_page(max_pfn) is a pointer which is located in kernel space. So max_mapnr is assigned a very large number(e.g., 0xffffxxxx_xxxxxxxx) - fix it.

---
 arch/arm64/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/init.c +1 -1
index bc02818fa48b..e86c21a44c88 100644
@@ -535,7 +535,7 @@ void __init mem_init(void)
 	else
 		swiotlb_force = SWIOTLB_NO_FORCE;
 
-	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
+	set_max_mapnr(max_pfn - PHYS_PFN_OFFSET);
 
 #ifndef CONFIG_SPARSEMEM_VMEMMAP
 	free_unused_memmap();
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 15 lines · Muchun Song

When we not use flat memory, the mem_map will be NULL and pfn_to_page(max_pfn) is a pointer which is located in kernel space. So max_mapnr is assigned a very large number(e.g., 0xffffxxxx_xxxxxxxx) - fix it.

---
 arch/arm64/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/init.c +0 -0
index bc02818fa48b..e86c21a44c88 100644

arch/arm64/mm/init.c void __init mem_init(void) · line 541

Quoted 8 lines
arch/arm64/mm/init.c +1 -1
@@ -535,7 +535,7 @@ void __init mem_init(void)
 	else
 		swiotlb_force = SWIOTLB_NO_FORCE;
 
-	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
+	set_max_mapnr(max_pfn - PHYS_PFN_OFFSET);
 
 #ifndef CONFIG_SPARSEMEM_VMEMMAP
 	free_unused_memmap();

The patch looks fine but did you actually hit any problem? max_mapnr seems to only be used in the generic pfn_valid() which we do not use on arm64 (just wondering if it needs a cc stable; it doesn't look like as it's not a regression).

Signature · 1 line
Catalin
#2 lore raw

Hi Catalin,

Thanks for your reply. In fact, I didn't hit any problem. I just read the code and found the problem. I see max_mapnr is to only be used in the generic pfn_valid().
As you said, we do not use it on arm64. So in a sense, the patch is meaningless.

But I think since it is a problem, why not fix it (Even if max_mapnr is not be used)?
What is your opinion?

Quoted 33 lines · Catalin Marinas <[email protected]> 于2019年4月1日周一 下午6:44写道:
Quoted 15 lines · Muchun Song

When we not use flat memory, the mem_map will be NULL and pfn_to_page(max_pfn) is a pointer which is located in kernel space. So max_mapnr is assigned a very large number(e.g., 0xffffxxxx_xxxxxxxx) - fix it.

---
 arch/arm64/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/init.c +0 -0
index bc02818fa48b..e86c21a44c88 100644

arch/arm64/mm/init.c void __init mem_init(void) · line 541

Quoted 8 lines
arch/arm64/mm/init.c +1 -1
@@ -535,7 +535,7 @@ void __init mem_init(void)
      else
              swiotlb_force = SWIOTLB_NO_FORCE;
 
-     set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
+     set_max_mapnr(max_pfn - PHYS_PFN_OFFSET);
 
 #ifndef CONFIG_SPARSEMEM_VMEMMAP
      free_unused_memmap();

The patch looks fine but did you actually hit any problem? max_mapnr seems to only be used in the generic pfn_valid() which we do not use on arm64 (just wondering if it needs a cc stable; it doesn't look like as it's not a regression).

--
Catalin

maintainer Reviewed-by
#3 lore raw
Quoted 9 lines · Muchun Song

Thanks for your reply. In fact, I didn't hit any problem. I just read the code and found the problem. I see max_mapnr is to only be used in the generic pfn_valid().
As you said, we do not use it on arm64. So in a sense, the patch is meaningless.

But I think since it is a problem, why not fix it (Even if max_mapnr is not be used)?
What is your opinion?

I'm ok with fixing, only that it's not urgent. Will can pick it up for the 5.2 merging window.