Skip to contentSkip to conversation

mm/memblock: export max_pfn for kernel modules

PATCH In review Miles Chen 3 participants 5 messages Jun 3, 2020 – Jun 4, 2020

Subsystems (3)
lore
Share & tools
lore

Miles Chen

author
#0 lore raw

PATCH 1/1 mm/memblock: export max_pfn for kernel modules

max_pfn is uesd to get the highest pfn in the system. Drivers like drivers/iommu/mtk_iommu.c checks max_pfn to see if it should enable its "4GB mode".

This patch exports the max_pfn symbol, so we can build the driver as a kernel module.

---
 mm/memblock.c | 1 +
 1 file changed, 1 insertion(+)
mm/memblock.c +1 -0
index c79ba6f9920c..3b2b21ecebb6 100644
@@ -99,6 +99,7 @@ EXPORT_SYMBOL(contig_page_data);
 unsigned long max_low_pfn;
 unsigned long min_low_pfn;
 unsigned long max_pfn;
+EXPORT_SYMBOL(max_pfn);
 unsigned long long max_possible_pfn;
 
 static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
Signature · 1 line
2.18.0
#1 lore raw
Quoted 6 lines · Miles Chen

max_pfn is uesd to get the highest pfn in the system. Drivers like drivers/iommu/mtk_iommu.c checks max_pfn to see if it should enable its "4GB mode".

This patch exports the max_pfn symbol, so we can build the driver as a kernel module.

Please add that change to the respective user patch (and cc MM-people for that patch), so we have the actual user right along the change and can figure out if this is the right thing to do.

Quoted 19 lines
---
 mm/memblock.c | 1 +
 1 file changed, 1 insertion(+)
mm/memblock.c +1 -0
index c79ba6f9920c..3b2b21ecebb6 100644
@@ -99,6 +99,7 @@ EXPORT_SYMBOL(contig_page_data);
 unsigned long max_low_pfn;
 unsigned long min_low_pfn;
 unsigned long max_pfn;
+EXPORT_SYMBOL(max_pfn);
 unsigned long long max_possible_pfn;
 
 static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
Signature · 3 lines
Thanks,

David / dhildenb
author
#2 lore raw
Quoted 5 lines · David Hildenbrand
Quoted 4 lines · Miles Chen

max_pfn is uesd to get the highest pfn in the system. Drivers like drivers/iommu/mtk_iommu.c checks max_pfn to see if it should enable its "4GB mode".

Quoted 7 lines
Quoted 2 lines

This patch exports the max_pfn symbol, so we can build the driver as a kernel module.

Please add that change to the respective user patch (and cc MM-people for that patch), so we have the actual user right along the change and can figure out if this is the right thing to do.

Thanks for the comment.

Mike points out another alternative way to do this by totalram_pages(). I will use that approach so we don't have to export max_pfn here.

https://lkml.org/lkml/2020/6/3/771

Miles

Quoted 21 lines
Quoted 19 lines
---
 mm/memblock.c | 1 +
 1 file changed, 1 insertion(+)
mm/memblock.c +1 -0
index c79ba6f9920c..3b2b21ecebb6 100644
@@ -99,6 +99,7 @@ EXPORT_SYMBOL(contig_page_data);
 unsigned long max_low_pfn;
 unsigned long min_low_pfn;
 unsigned long max_pfn;
+EXPORT_SYMBOL(max_pfn);
 unsigned long long max_possible_pfn;
 
 static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
#3 lore raw
In reply to Miles Chen
Quoted 6 lines · Miles Chen

max_pfn is uesd to get the highest pfn in the system. Drivers like drivers/iommu/mtk_iommu.c checks max_pfn to see if it should enable its "4GB mode".

This patch exports the max_pfn symbol, so we can build the driver as a kernel module.

You can use totalram_pages(), like e.g.
drivers/media/platform/mtk-vpu/mtk_vpu.c:

$ git grep -np totalram_pages drivers/media/
drivers/media/platform/mtk-vpu/mtk_vpu.c=779=static int mtk_vpu_probe(struct platform_device *pdev)
drivers/media/platform/mtk-vpu/mtk_vpu.c:861:   vpu->enable_4GB = !!(totalram_pages() > (SZ_2G >> PAGE_SHIFT));
Quoted 19 lines
---
 mm/memblock.c | 1 +
 1 file changed, 1 insertion(+)
mm/memblock.c +1 -0
index c79ba6f9920c..3b2b21ecebb6 100644
@@ -99,6 +99,7 @@ EXPORT_SYMBOL(contig_page_data);
 unsigned long max_low_pfn;
 unsigned long min_low_pfn;
 unsigned long max_pfn;
+EXPORT_SYMBOL(max_pfn);
 unsigned long long max_possible_pfn;
 
 static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
Signature · 1 line
2.18.0
Signature · 2 lines
Sincerely yours,
Mike.
author
#4 lore raw
Quoted 8 lines · Mike Rapoport
Quoted 6 lines · Miles Chen

max_pfn is uesd to get the highest pfn in the system. Drivers like drivers/iommu/mtk_iommu.c checks max_pfn to see if it should enable its "4GB mode".

This patch exports the max_pfn symbol, so we can build the driver as a kernel module.

Quoted 7 lines

You can use totalram_pages(), like e.g.
drivers/media/platform/mtk-vpu/mtk_vpu.c:

$ git grep -np totalram_pages drivers/medhttps://lkml.org/lkml/2020/5/30/123ia/
drivers/media/platform/mtk-vpu/mtk_vpu.c=779=static int mtk_vpu_probe(struct platform_device *pdev)
drivers/media/platform/mtk-vpu/mtk_vpu.c:861:   vpu->enable_4GB = !!(totalram_pages() > (SZ_2G >> PAGE_SHIFT));

Thanks for the suggestion.
totalram_pages() works and I can follow this example.

Miles

Quoted 21 lines
Quoted 20 lines
---
 mm/memblock.c | 1 +
 1 file changed, 1 insertion(+)
mm/memblock.c +1 -0
index c79ba6f9920c..3b2b21ecebb6 100644
@@ -99,6 +99,7 @@ EXPORT_SYMBOL(contig_page_data);
 unsigned long max_low_pfn;
 unsigned long min_low_pfn;
 unsigned long max_pfn;
+EXPORT_SYMBOL(max_pfn);
 unsigned long long max_possible_pfn;
 
 static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
Signature · 1 line
2.18.0