public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/setup: Use a more concise memblock API
@ 2023-11-14  3:14 Yuntao Wang
  2023-11-14  4:11 ` Baoquan He
  0 siblings, 1 reply; 4+ messages in thread
From: Yuntao Wang @ 2023-11-14  3:14 UTC (permalink / raw)
  To: x86, linux-kernel
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin, Peter Zijlstra (Intel), Juergen Gross, Baoquan He,
	Alexander Shishkin, Saurabh Sengar, Yuntao Wang

When executing relocate_initrd(), the memblock.current_limit field has
already been set to `max_pfn_mapped << PAGE_SHIFT`, so we can replace
memblock_phys_alloc_range() with memblock_phys_alloc(), which has the same
functionality but is more concise.

Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
---
 arch/x86/kernel/setup.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index ec2c21a1844e..422497c17eec 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -259,8 +259,7 @@ static void __init relocate_initrd(void)
 	u64 area_size     = PAGE_ALIGN(ramdisk_size);
 
 	/* We need to move the initrd down into directly mapped mem */
-	u64 relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0,
-						      PFN_PHYS(max_pfn_mapped));
+	u64 relocated_ramdisk = memblock_phys_alloc(area_size, PAGE_SIZE);
 	if (!relocated_ramdisk)
 		panic("Cannot find place for new RAMDISK of size %lld\n",
 		      ramdisk_size);
-- 
2.42.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/setup: Use a more concise memblock API
  2023-11-14  3:14 [PATCH] x86/setup: Use a more concise memblock API Yuntao Wang
@ 2023-11-14  4:11 ` Baoquan He
  2023-11-14  7:37   ` [PATCH v2] " Yuntao Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Baoquan He @ 2023-11-14  4:11 UTC (permalink / raw)
  To: Yuntao Wang
  Cc: x86, linux-kernel, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, H. Peter Anvin, Peter Zijlstra (Intel),
	Juergen Gross, Alexander Shishkin, Saurabh Sengar

On 11/14/23 at 11:14am, Yuntao Wang wrote:
> When executing relocate_initrd(), the memblock.current_limit field has
> already been set to `max_pfn_mapped << PAGE_SHIFT`, so we can replace
> memblock_phys_alloc_range() with memblock_phys_alloc(), which has the same
> functionality but is more concise.

Fine to me, do we need consider other places in:

numa_alloc_distance()
numa_emulation()

> 
> Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
> ---
>  arch/x86/kernel/setup.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> index ec2c21a1844e..422497c17eec 100644
> --- a/arch/x86/kernel/setup.c
> +++ b/arch/x86/kernel/setup.c
> @@ -259,8 +259,7 @@ static void __init relocate_initrd(void)
>  	u64 area_size     = PAGE_ALIGN(ramdisk_size);
>  
>  	/* We need to move the initrd down into directly mapped mem */
> -	u64 relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0,
> -						      PFN_PHYS(max_pfn_mapped));
> +	u64 relocated_ramdisk = memblock_phys_alloc(area_size, PAGE_SIZE);
>  	if (!relocated_ramdisk)
>  		panic("Cannot find place for new RAMDISK of size %lld\n",
>  		      ramdisk_size);
> -- 
> 2.42.1
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] x86/setup: Use a more concise memblock API
  2023-11-14  4:11 ` Baoquan He
@ 2023-11-14  7:37   ` Yuntao Wang
  2023-11-14  8:36     ` Baoquan He
  0 siblings, 1 reply; 4+ messages in thread
From: Yuntao Wang @ 2023-11-14  7:37 UTC (permalink / raw)
  To: bhe
  Cc: alexander.shishkin, bp, dave.hansen, hpa, jgross, linux-kernel,
	mingo, peterz, ssengar, tglx, x86, ytcoode, Andy Lutomirski,
	Arnd Bergmann

When executing relocate_initrd()/numa_emulation()/numa_alloc_distance(),
the memblock.current_limit field has already been set to
`max_pfn_mapped << PAGE_SHIFT`, therefore we can replace
memblock_phys_alloc_range() with memblock_phys_alloc(), which has the same
functionality but is more concise.

Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
---
v1 -> v2:

Also replace memblock_phys_alloc_range() in numa_emulation() and
numa_alloc_distance() with memblock_phys_alloc()

 arch/x86/kernel/setup.c      | 3 +--
 arch/x86/mm/numa.c           | 3 +--
 arch/x86/mm/numa_emulation.c | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index ec2c21a1844e..422497c17eec 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -259,8 +259,7 @@ static void __init relocate_initrd(void)
 	u64 area_size     = PAGE_ALIGN(ramdisk_size);

 	/* We need to move the initrd down into directly mapped mem */
-	u64 relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0,
-						      PFN_PHYS(max_pfn_mapped));
+	u64 relocated_ramdisk = memblock_phys_alloc(area_size, PAGE_SIZE);
 	if (!relocated_ramdisk)
 		panic("Cannot find place for new RAMDISK of size %lld\n",
 		      ramdisk_size);
diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index b29ceb19e46e..29cd8fc8ede1 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -378,8 +378,7 @@ static int __init numa_alloc_distance(void)
 	cnt++;
 	size = cnt * cnt * sizeof(numa_distance[0]);

-	phys = memblock_phys_alloc_range(size, PAGE_SIZE, 0,
-					 PFN_PHYS(max_pfn_mapped));
+	phys = memblock_phys_alloc(size, PAGE_SIZE);
 	if (!phys) {
 		pr_warn("Warning: can't allocate distance table!\n");
 		/* don't retry until explicitly reset */
diff --git a/arch/x86/mm/numa_emulation.c b/arch/x86/mm/numa_emulation.c
index 9a9305367fdd..8acb8d0f7d0f 100644
--- a/arch/x86/mm/numa_emulation.c
+++ b/arch/x86/mm/numa_emulation.c
@@ -447,8 +447,7 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
 	if (numa_dist_cnt) {
 		u64 phys;

-		phys = memblock_phys_alloc_range(phys_size, PAGE_SIZE, 0,
-						 PFN_PHYS(max_pfn_mapped));
+		phys = memblock_phys_alloc(phys_size, PAGE_SIZE);
 		if (!phys) {
 			pr_warn("NUMA: Warning: can't allocate copy of distance table, disabling emulation\n");
 			goto no_emu;
--
2.42.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] x86/setup: Use a more concise memblock API
  2023-11-14  7:37   ` [PATCH v2] " Yuntao Wang
@ 2023-11-14  8:36     ` Baoquan He
  0 siblings, 0 replies; 4+ messages in thread
From: Baoquan He @ 2023-11-14  8:36 UTC (permalink / raw)
  To: Yuntao Wang
  Cc: alexander.shishkin, bp, dave.hansen, hpa, jgross, linux-kernel,
	mingo, peterz, ssengar, tglx, x86, Andy Lutomirski, Arnd Bergmann

On 11/14/23 at 03:37pm, Yuntao Wang wrote:
> When executing relocate_initrd()/numa_emulation()/numa_alloc_distance(),
> the memblock.current_limit field has already been set to
> `max_pfn_mapped << PAGE_SHIFT`, therefore we can replace
> memblock_phys_alloc_range() with memblock_phys_alloc(), which has the same
> functionality but is more concise.
> 
> Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
> ---
> v1 -> v2:
> 
> Also replace memblock_phys_alloc_range() in numa_emulation() and
> numa_alloc_distance() with memblock_phys_alloc()

LGTM,

Reviewed-by: Baoquan He <bhe@redhat.com>

> 
>  arch/x86/kernel/setup.c      | 3 +--
>  arch/x86/mm/numa.c           | 3 +--
>  arch/x86/mm/numa_emulation.c | 3 +--
>  3 files changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> index ec2c21a1844e..422497c17eec 100644
> --- a/arch/x86/kernel/setup.c
> +++ b/arch/x86/kernel/setup.c
> @@ -259,8 +259,7 @@ static void __init relocate_initrd(void)
>  	u64 area_size     = PAGE_ALIGN(ramdisk_size);
> 
>  	/* We need to move the initrd down into directly mapped mem */
> -	u64 relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0,
> -						      PFN_PHYS(max_pfn_mapped));
> +	u64 relocated_ramdisk = memblock_phys_alloc(area_size, PAGE_SIZE);
>  	if (!relocated_ramdisk)
>  		panic("Cannot find place for new RAMDISK of size %lld\n",
>  		      ramdisk_size);
> diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
> index b29ceb19e46e..29cd8fc8ede1 100644
> --- a/arch/x86/mm/numa.c
> +++ b/arch/x86/mm/numa.c
> @@ -378,8 +378,7 @@ static int __init numa_alloc_distance(void)
>  	cnt++;
>  	size = cnt * cnt * sizeof(numa_distance[0]);
> 
> -	phys = memblock_phys_alloc_range(size, PAGE_SIZE, 0,
> -					 PFN_PHYS(max_pfn_mapped));
> +	phys = memblock_phys_alloc(size, PAGE_SIZE);
>  	if (!phys) {
>  		pr_warn("Warning: can't allocate distance table!\n");
>  		/* don't retry until explicitly reset */
> diff --git a/arch/x86/mm/numa_emulation.c b/arch/x86/mm/numa_emulation.c
> index 9a9305367fdd..8acb8d0f7d0f 100644
> --- a/arch/x86/mm/numa_emulation.c
> +++ b/arch/x86/mm/numa_emulation.c
> @@ -447,8 +447,7 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
>  	if (numa_dist_cnt) {
>  		u64 phys;
> 
> -		phys = memblock_phys_alloc_range(phys_size, PAGE_SIZE, 0,
> -						 PFN_PHYS(max_pfn_mapped));
> +		phys = memblock_phys_alloc(phys_size, PAGE_SIZE);
>  		if (!phys) {
>  			pr_warn("NUMA: Warning: can't allocate copy of distance table, disabling emulation\n");
>  			goto no_emu;
> --
> 2.42.1
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-14  8:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-14  3:14 [PATCH] x86/setup: Use a more concise memblock API Yuntao Wang
2023-11-14  4:11 ` Baoquan He
2023-11-14  7:37   ` [PATCH v2] " Yuntao Wang
2023-11-14  8:36     ` Baoquan He

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox