Re: [PATCH v2] memblock: make memblock_find_in_range method private

2021-08-08 Thread Nick Kossifidis

Στις 2021-08-02 09:37, Mike Rapoport έγραψε:

From: Mike Rapoport 

There are a lot of uses of memblock_find_in_range() along with
memblock_reserve() from the times memblock allocation APIs did not 
exist.


memblock_find_in_range() is the very core of memblock allocations, so 
any
future changes to its internal behaviour would mandate updates of all 
the

users outside memblock.

Replace the calls to memblock_find_in_range() with an equivalent calls 
to

memblock_phys_alloc() and memblock_phys_alloc_range() and make
memblock_find_in_range() private method of memblock.

This simplifies the callers, ensures that (unlikely) errors in
memblock_reserve() are handled and improves maintainability of
memblock_find_in_range().

Signed-off-by: Mike Rapoport 
---
v2: don't change error message in arm::reserve_crashkernel(), per 
Russell

v1: https://lore.kernel.org/lkml/20210730104039.7047-1-r...@kernel.org

 arch/arm/kernel/setup.c   | 18 +
 arch/arm64/kvm/hyp/reserved_mem.c |  9 +++
 arch/arm64/mm/init.c  | 36 -
 arch/mips/kernel/setup.c  | 14 +-
 arch/riscv/mm/init.c  | 44 ++-
 arch/s390/kernel/setup.c  | 10 ---
 arch/x86/kernel/aperture_64.c |  5 ++--
 arch/x86/mm/init.c| 21 +--
 arch/x86/mm/numa.c|  5 ++--
 arch/x86/mm/numa_emulation.c  |  5 ++--
 arch/x86/realmode/init.c  |  2 +-
 drivers/acpi/tables.c |  5 ++--
 drivers/base/arch_numa.c  |  5 +---
 drivers/of/of_reserved_mem.c  | 12 ++---
 include/linux/memblock.h  |  2 --
 mm/memblock.c |  2 +-
 16 files changed, 78 insertions(+), 117 deletions(-)

diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index f97eb2371672..67f5421b2af7 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -1012,31 +1012,25 @@ static void __init reserve_crashkernel(void)
unsigned long long lowmem_max = __pa(high_memory - 1) + 1;
if (crash_max > lowmem_max)
crash_max = lowmem_max;
-   crash_base = memblock_find_in_range(CRASH_ALIGN, crash_max,
-   crash_size, CRASH_ALIGN);
+
+   crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN,
+  CRASH_ALIGN, crash_max);
if (!crash_base) {
 			pr_err("crashkernel reservation failed - No suitable area 
found.\n");

return;
}
} else {
+   unsigned long long crash_max = crash_base + crash_size;
unsigned long long start;

-   start = memblock_find_in_range(crash_base,
-  crash_base + crash_size,
-  crash_size, SECTION_SIZE);
+   start = memblock_phys_alloc_range(crash_size, SECTION_SIZE,
+ crash_base, crash_max);
if (start != crash_base) {
pr_err("crashkernel reservation failed - memory is in 
use.\n");
return;
}
}

-   ret = memblock_reserve(crash_base, crash_size);
-   if (ret < 0) {
-		pr_warn("crashkernel reservation failed - memory is in use 
(0x%lx)\n",

-   (unsigned long)crash_base);
-   return;
-   }
-
pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System
RAM: %ldMB)\n",
(unsigned long)(crash_size >> 20),
(unsigned long)(crash_base >> 20),
diff --git a/arch/arm64/kvm/hyp/reserved_mem.c
b/arch/arm64/kvm/hyp/reserved_mem.c
index d654921dd09b..578670e3f608 100644
--- a/arch/arm64/kvm/hyp/reserved_mem.c
+++ b/arch/arm64/kvm/hyp/reserved_mem.c
@@ -92,12 +92,10 @@ void __init kvm_hyp_reserve(void)
 * this is unmapped from the host stage-2, and fallback to PAGE_SIZE.
 */
hyp_mem_size = hyp_mem_pages << PAGE_SHIFT;
-   hyp_mem_base = memblock_find_in_range(0, memblock_end_of_DRAM(),
- ALIGN(hyp_mem_size, PMD_SIZE),
- PMD_SIZE);
+   hyp_mem_base = memblock_phys_alloc(ALIGN(hyp_mem_size, PMD_SIZE),
+  PMD_SIZE);
if (!hyp_mem_base)
-   hyp_mem_base = memblock_find_in_range(0, memblock_end_of_DRAM(),
- hyp_mem_size, PAGE_SIZE);
+   hyp_mem_base = memblock_phys_alloc(hyp_mem_size, PAGE_SIZE);
else
hyp_mem_size = ALIGN(hyp_mem_size, PMD_SIZE);

@@ -105,7 +103,6 @@ void __init kvm_hyp_reserve(void)
kvm_err("Failed to reserve hyp memory\n");
return;
}
-   

Re: [PATCH v2] memblock: make memblock_find_in_range method private

2021-08-06 Thread Russell King (Oracle)
On Mon, Aug 02, 2021 at 09:37:37AM +0300, Mike Rapoport wrote:
> From: Mike Rapoport 
> 
> There are a lot of uses of memblock_find_in_range() along with
> memblock_reserve() from the times memblock allocation APIs did not exist.
> 
> memblock_find_in_range() is the very core of memblock allocations, so any
> future changes to its internal behaviour would mandate updates of all the
> users outside memblock.
> 
> Replace the calls to memblock_find_in_range() with an equivalent calls to
> memblock_phys_alloc() and memblock_phys_alloc_range() and make
> memblock_find_in_range() private method of memblock.
> 
> This simplifies the callers, ensures that (unlikely) errors in
> memblock_reserve() are handled and improves maintainability of
> memblock_find_in_range().
> 
> Signed-off-by: Mike Rapoport 
Acked-by: Russell King (Oracle) 

Thanks.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
___
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm


Re: [PATCH v2] memblock: make memblock_find_in_range method private

2021-08-06 Thread Rafael J. Wysocki
On Mon, Aug 2, 2021 at 8:37 AM Mike Rapoport  wrote:
>
> From: Mike Rapoport 
>
> There are a lot of uses of memblock_find_in_range() along with
> memblock_reserve() from the times memblock allocation APIs did not exist.
>
> memblock_find_in_range() is the very core of memblock allocations, so any
> future changes to its internal behaviour would mandate updates of all the
> users outside memblock.
>
> Replace the calls to memblock_find_in_range() with an equivalent calls to
> memblock_phys_alloc() and memblock_phys_alloc_range() and make
> memblock_find_in_range() private method of memblock.
>
> This simplifies the callers, ensures that (unlikely) errors in
> memblock_reserve() are handled and improves maintainability of
> memblock_find_in_range().
>
> Signed-off-by: Mike Rapoport 

For the ACPI part:

Acked-by: Rafael J. Wysocki 

> ---
> v2: don't change error message in arm::reserve_crashkernel(), per Russell
> v1: https://lore.kernel.org/lkml/20210730104039.7047-1-r...@kernel.org
>
>  arch/arm/kernel/setup.c   | 18 +
>  arch/arm64/kvm/hyp/reserved_mem.c |  9 +++
>  arch/arm64/mm/init.c  | 36 -
>  arch/mips/kernel/setup.c  | 14 +-
>  arch/riscv/mm/init.c  | 44 ++-
>  arch/s390/kernel/setup.c  | 10 ---
>  arch/x86/kernel/aperture_64.c |  5 ++--
>  arch/x86/mm/init.c| 21 +--
>  arch/x86/mm/numa.c|  5 ++--
>  arch/x86/mm/numa_emulation.c  |  5 ++--
>  arch/x86/realmode/init.c  |  2 +-
>  drivers/acpi/tables.c |  5 ++--
>  drivers/base/arch_numa.c  |  5 +---
>  drivers/of/of_reserved_mem.c  | 12 ++---
>  include/linux/memblock.h  |  2 --
>  mm/memblock.c |  2 +-
>  16 files changed, 78 insertions(+), 117 deletions(-)
>
> diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
> index f97eb2371672..67f5421b2af7 100644
> --- a/arch/arm/kernel/setup.c
> +++ b/arch/arm/kernel/setup.c
> @@ -1012,31 +1012,25 @@ static void __init reserve_crashkernel(void)
> unsigned long long lowmem_max = __pa(high_memory - 1) + 1;
> if (crash_max > lowmem_max)
> crash_max = lowmem_max;
> -   crash_base = memblock_find_in_range(CRASH_ALIGN, crash_max,
> -   crash_size, CRASH_ALIGN);
> +
> +   crash_base = memblock_phys_alloc_range(crash_size, 
> CRASH_ALIGN,
> +  CRASH_ALIGN, 
> crash_max);
> if (!crash_base) {
> pr_err("crashkernel reservation failed - No suitable 
> area found.\n");
> return;
> }
> } else {
> +   unsigned long long crash_max = crash_base + crash_size;
> unsigned long long start;
>
> -   start = memblock_find_in_range(crash_base,
> -  crash_base + crash_size,
> -  crash_size, SECTION_SIZE);
> +   start = memblock_phys_alloc_range(crash_size, SECTION_SIZE,
> + crash_base, crash_max);
> if (start != crash_base) {
> pr_err("crashkernel reservation failed - memory is in 
> use.\n");
> return;
> }
> }
>
> -   ret = memblock_reserve(crash_base, crash_size);
> -   if (ret < 0) {
> -   pr_warn("crashkernel reservation failed - memory is in use 
> (0x%lx)\n",
> -   (unsigned long)crash_base);
> -   return;
> -   }
> -
> pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System 
> RAM: %ldMB)\n",
> (unsigned long)(crash_size >> 20),
> (unsigned long)(crash_base >> 20),
> diff --git a/arch/arm64/kvm/hyp/reserved_mem.c 
> b/arch/arm64/kvm/hyp/reserved_mem.c
> index d654921dd09b..578670e3f608 100644
> --- a/arch/arm64/kvm/hyp/reserved_mem.c
> +++ b/arch/arm64/kvm/hyp/reserved_mem.c
> @@ -92,12 +92,10 @@ void __init kvm_hyp_reserve(void)
>  * this is unmapped from the host stage-2, and fallback to PAGE_SIZE.
>  */
> hyp_mem_size = hyp_mem_pages << PAGE_SHIFT;
> -   hyp_mem_base = memblock_find_in_range(0, memblock_end_of_DRAM(),
> - ALIGN(hyp_mem_size, PMD_SIZE),
> - PMD_SIZE);
> +   hyp_mem_base = memblock_phys_alloc(ALIGN(hyp_mem_size, PMD_SIZE),
> +  PMD_SIZE);
> if (!hyp_mem_base)
> -   hyp_mem_base = memblock_find_in_range(0, 
> memblock_end_of_DRAM(),
> - hyp_mem_size, 
> PAGE_SIZE);
> +   

Re: [PATCH v2] memblock: make memblock_find_in_range method private

2021-08-02 Thread Mike Rapoport
Hi Rob,

On Mon, Aug 02, 2021 at 08:55:57AM -0600, Rob Herring wrote:
> On Mon, Aug 2, 2021 at 12:37 AM Mike Rapoport  wrote:
> >
> > From: Mike Rapoport 
> >
> > There are a lot of uses of memblock_find_in_range() along with
> > memblock_reserve() from the times memblock allocation APIs did not exist.
> >
> > memblock_find_in_range() is the very core of memblock allocations, so any
> > future changes to its internal behaviour would mandate updates of all the
> > users outside memblock.
> >
> > Replace the calls to memblock_find_in_range() with an equivalent calls to
> > memblock_phys_alloc() and memblock_phys_alloc_range() and make
> > memblock_find_in_range() private method of memblock.
> >
> > This simplifies the callers, ensures that (unlikely) errors in
> > memblock_reserve() are handled and improves maintainability of
> > memblock_find_in_range().
> >
> > Signed-off-by: Mike Rapoport 
> > ---
> > v2: don't change error message in arm::reserve_crashkernel(), per Russell
> > v1: https://lore.kernel.org/lkml/20210730104039.7047-1-r...@kernel.org
> >
> >  arch/arm/kernel/setup.c   | 18 +
> >  arch/arm64/kvm/hyp/reserved_mem.c |  9 +++
> >  arch/arm64/mm/init.c  | 36 -
> >  arch/mips/kernel/setup.c  | 14 +-
> >  arch/riscv/mm/init.c  | 44 ++-
> >  arch/s390/kernel/setup.c  | 10 ---
> >  arch/x86/kernel/aperture_64.c |  5 ++--
> >  arch/x86/mm/init.c| 21 +--
> >  arch/x86/mm/numa.c|  5 ++--
> >  arch/x86/mm/numa_emulation.c  |  5 ++--
> >  arch/x86/realmode/init.c  |  2 +-
> >  drivers/acpi/tables.c |  5 ++--
> >  drivers/base/arch_numa.c  |  5 +---
> >  drivers/of/of_reserved_mem.c  | 12 ++---
> >  include/linux/memblock.h  |  2 --
> >  mm/memblock.c |  2 +-
> >  16 files changed, 78 insertions(+), 117 deletions(-)
> >
> > diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
> > index f97eb2371672..67f5421b2af7 100644
> > --- a/arch/arm/kernel/setup.c
> > +++ b/arch/arm/kernel/setup.c
> > @@ -1012,31 +1012,25 @@ static void __init reserve_crashkernel(void)
> > unsigned long long lowmem_max = __pa(high_memory - 1) + 1;
> > if (crash_max > lowmem_max)
> > crash_max = lowmem_max;
> > -   crash_base = memblock_find_in_range(CRASH_ALIGN, crash_max,
> > -   crash_size, 
> > CRASH_ALIGN);
> > +
> > +   crash_base = memblock_phys_alloc_range(crash_size, 
> > CRASH_ALIGN,
> > +  CRASH_ALIGN, 
> > crash_max);
> > if (!crash_base) {
> > pr_err("crashkernel reservation failed - No 
> > suitable area found.\n");
> > return;
> > }
> > } else {
> > +   unsigned long long crash_max = crash_base + crash_size;
> > unsigned long long start;
> >
> > -   start = memblock_find_in_range(crash_base,
> > -  crash_base + crash_size,
> > -  crash_size, SECTION_SIZE);
> > +   start = memblock_phys_alloc_range(crash_size, SECTION_SIZE,
> > + crash_base, crash_max);
> > if (start != crash_base) {
> 
> If this is true and start is non-zero, then you need an
> memblock_free(). However, since the range is equal to the size, then
> that can never happen and just checking !start is sufficient.

Agree. Will update.
 
> > pr_err("crashkernel reservation failed - memory is 
> > in use.\n");
> > return;
> > }
> > }
> >
> > -   ret = memblock_reserve(crash_base, crash_size);
> > -   if (ret < 0) {
> > -   pr_warn("crashkernel reservation failed - memory is in use 
> > (0x%lx)\n",
> > -   (unsigned long)crash_base);
> > -   return;
> > -   }
> > -
> > pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System 
> > RAM: %ldMB)\n",
> > (unsigned long)(crash_size >> 20),
> > (unsigned long)(crash_base >> 20),
> > diff --git a/arch/arm64/kvm/hyp/reserved_mem.c 
> > b/arch/arm64/kvm/hyp/reserved_mem.c
> > index d654921dd09b..578670e3f608 100644
> > --- a/arch/arm64/kvm/hyp/reserved_mem.c
> > +++ b/arch/arm64/kvm/hyp/reserved_mem.c
> > @@ -92,12 +92,10 @@ void __init kvm_hyp_reserve(void)
> >  * this is unmapped from the host stage-2, and fallback to 
> > PAGE_SIZE.
> >  */
> > hyp_mem_size = hyp_mem_pages << PAGE_SHIFT;
> > -   hyp_mem_base = memblock_find_in_range(0, memblock_end_of_DRAM(),
> > - 

Re: [PATCH v2] memblock: make memblock_find_in_range method private

2021-08-02 Thread Rob Herring
On Mon, Aug 2, 2021 at 12:37 AM Mike Rapoport  wrote:
>
> From: Mike Rapoport 
>
> There are a lot of uses of memblock_find_in_range() along with
> memblock_reserve() from the times memblock allocation APIs did not exist.
>
> memblock_find_in_range() is the very core of memblock allocations, so any
> future changes to its internal behaviour would mandate updates of all the
> users outside memblock.
>
> Replace the calls to memblock_find_in_range() with an equivalent calls to
> memblock_phys_alloc() and memblock_phys_alloc_range() and make
> memblock_find_in_range() private method of memblock.
>
> This simplifies the callers, ensures that (unlikely) errors in
> memblock_reserve() are handled and improves maintainability of
> memblock_find_in_range().
>
> Signed-off-by: Mike Rapoport 
> ---
> v2: don't change error message in arm::reserve_crashkernel(), per Russell
> v1: https://lore.kernel.org/lkml/20210730104039.7047-1-r...@kernel.org
>
>  arch/arm/kernel/setup.c   | 18 +
>  arch/arm64/kvm/hyp/reserved_mem.c |  9 +++
>  arch/arm64/mm/init.c  | 36 -
>  arch/mips/kernel/setup.c  | 14 +-
>  arch/riscv/mm/init.c  | 44 ++-
>  arch/s390/kernel/setup.c  | 10 ---
>  arch/x86/kernel/aperture_64.c |  5 ++--
>  arch/x86/mm/init.c| 21 +--
>  arch/x86/mm/numa.c|  5 ++--
>  arch/x86/mm/numa_emulation.c  |  5 ++--
>  arch/x86/realmode/init.c  |  2 +-
>  drivers/acpi/tables.c |  5 ++--
>  drivers/base/arch_numa.c  |  5 +---
>  drivers/of/of_reserved_mem.c  | 12 ++---
>  include/linux/memblock.h  |  2 --
>  mm/memblock.c |  2 +-
>  16 files changed, 78 insertions(+), 117 deletions(-)
>
> diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
> index f97eb2371672..67f5421b2af7 100644
> --- a/arch/arm/kernel/setup.c
> +++ b/arch/arm/kernel/setup.c
> @@ -1012,31 +1012,25 @@ static void __init reserve_crashkernel(void)
> unsigned long long lowmem_max = __pa(high_memory - 1) + 1;
> if (crash_max > lowmem_max)
> crash_max = lowmem_max;
> -   crash_base = memblock_find_in_range(CRASH_ALIGN, crash_max,
> -   crash_size, CRASH_ALIGN);
> +
> +   crash_base = memblock_phys_alloc_range(crash_size, 
> CRASH_ALIGN,
> +  CRASH_ALIGN, 
> crash_max);
> if (!crash_base) {
> pr_err("crashkernel reservation failed - No suitable 
> area found.\n");
> return;
> }
> } else {
> +   unsigned long long crash_max = crash_base + crash_size;
> unsigned long long start;
>
> -   start = memblock_find_in_range(crash_base,
> -  crash_base + crash_size,
> -  crash_size, SECTION_SIZE);
> +   start = memblock_phys_alloc_range(crash_size, SECTION_SIZE,
> + crash_base, crash_max);
> if (start != crash_base) {

If this is true and start is non-zero, then you need an
memblock_free(). However, since the range is equal to the size, then
that can never happen and just checking !start is sufficient.

> pr_err("crashkernel reservation failed - memory is in 
> use.\n");
> return;
> }
> }
>
> -   ret = memblock_reserve(crash_base, crash_size);
> -   if (ret < 0) {
> -   pr_warn("crashkernel reservation failed - memory is in use 
> (0x%lx)\n",
> -   (unsigned long)crash_base);
> -   return;
> -   }
> -
> pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System 
> RAM: %ldMB)\n",
> (unsigned long)(crash_size >> 20),
> (unsigned long)(crash_base >> 20),
> diff --git a/arch/arm64/kvm/hyp/reserved_mem.c 
> b/arch/arm64/kvm/hyp/reserved_mem.c
> index d654921dd09b..578670e3f608 100644
> --- a/arch/arm64/kvm/hyp/reserved_mem.c
> +++ b/arch/arm64/kvm/hyp/reserved_mem.c
> @@ -92,12 +92,10 @@ void __init kvm_hyp_reserve(void)
>  * this is unmapped from the host stage-2, and fallback to PAGE_SIZE.
>  */
> hyp_mem_size = hyp_mem_pages << PAGE_SHIFT;
> -   hyp_mem_base = memblock_find_in_range(0, memblock_end_of_DRAM(),
> - ALIGN(hyp_mem_size, PMD_SIZE),
> - PMD_SIZE);
> +   hyp_mem_base = memblock_phys_alloc(ALIGN(hyp_mem_size, PMD_SIZE),
> +  PMD_SIZE);
> if (!hyp_mem_base)
> -   hyp_mem_base = 

Re: [PATCH v2] memblock: make memblock_find_in_range method private

2021-08-02 Thread Kirill A. Shutemov
On Mon, Aug 02, 2021 at 09:37:37AM +0300, Mike Rapoport wrote:
> From: Mike Rapoport 
> 
> There are a lot of uses of memblock_find_in_range() along with
> memblock_reserve() from the times memblock allocation APIs did not exist.
> 
> memblock_find_in_range() is the very core of memblock allocations, so any
> future changes to its internal behaviour would mandate updates of all the
> users outside memblock.
> 
> Replace the calls to memblock_find_in_range() with an equivalent calls to
> memblock_phys_alloc() and memblock_phys_alloc_range() and make
> memblock_find_in_range() private method of memblock.
> 
> This simplifies the callers, ensures that (unlikely) errors in
> memblock_reserve() are handled and improves maintainability of
> memblock_find_in_range().
> 
> Signed-off-by: Mike Rapoport 

Looks good to me:

Acked-by: Kirill A. Shutemov 

-- 
 Kirill A. Shutemov
___
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm


[PATCH v2] memblock: make memblock_find_in_range method private

2021-08-02 Thread Mike Rapoport
From: Mike Rapoport 

There are a lot of uses of memblock_find_in_range() along with
memblock_reserve() from the times memblock allocation APIs did not exist.

memblock_find_in_range() is the very core of memblock allocations, so any
future changes to its internal behaviour would mandate updates of all the
users outside memblock.

Replace the calls to memblock_find_in_range() with an equivalent calls to
memblock_phys_alloc() and memblock_phys_alloc_range() and make
memblock_find_in_range() private method of memblock.

This simplifies the callers, ensures that (unlikely) errors in
memblock_reserve() are handled and improves maintainability of
memblock_find_in_range().

Signed-off-by: Mike Rapoport 
---
v2: don't change error message in arm::reserve_crashkernel(), per Russell
v1: https://lore.kernel.org/lkml/20210730104039.7047-1-r...@kernel.org

 arch/arm/kernel/setup.c   | 18 +
 arch/arm64/kvm/hyp/reserved_mem.c |  9 +++
 arch/arm64/mm/init.c  | 36 -
 arch/mips/kernel/setup.c  | 14 +-
 arch/riscv/mm/init.c  | 44 ++-
 arch/s390/kernel/setup.c  | 10 ---
 arch/x86/kernel/aperture_64.c |  5 ++--
 arch/x86/mm/init.c| 21 +--
 arch/x86/mm/numa.c|  5 ++--
 arch/x86/mm/numa_emulation.c  |  5 ++--
 arch/x86/realmode/init.c  |  2 +-
 drivers/acpi/tables.c |  5 ++--
 drivers/base/arch_numa.c  |  5 +---
 drivers/of/of_reserved_mem.c  | 12 ++---
 include/linux/memblock.h  |  2 --
 mm/memblock.c |  2 +-
 16 files changed, 78 insertions(+), 117 deletions(-)

diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index f97eb2371672..67f5421b2af7 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -1012,31 +1012,25 @@ static void __init reserve_crashkernel(void)
unsigned long long lowmem_max = __pa(high_memory - 1) + 1;
if (crash_max > lowmem_max)
crash_max = lowmem_max;
-   crash_base = memblock_find_in_range(CRASH_ALIGN, crash_max,
-   crash_size, CRASH_ALIGN);
+
+   crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN,
+  CRASH_ALIGN, crash_max);
if (!crash_base) {
pr_err("crashkernel reservation failed - No suitable 
area found.\n");
return;
}
} else {
+   unsigned long long crash_max = crash_base + crash_size;
unsigned long long start;
 
-   start = memblock_find_in_range(crash_base,
-  crash_base + crash_size,
-  crash_size, SECTION_SIZE);
+   start = memblock_phys_alloc_range(crash_size, SECTION_SIZE,
+ crash_base, crash_max);
if (start != crash_base) {
pr_err("crashkernel reservation failed - memory is in 
use.\n");
return;
}
}
 
-   ret = memblock_reserve(crash_base, crash_size);
-   if (ret < 0) {
-   pr_warn("crashkernel reservation failed - memory is in use 
(0x%lx)\n",
-   (unsigned long)crash_base);
-   return;
-   }
-
pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System 
RAM: %ldMB)\n",
(unsigned long)(crash_size >> 20),
(unsigned long)(crash_base >> 20),
diff --git a/arch/arm64/kvm/hyp/reserved_mem.c 
b/arch/arm64/kvm/hyp/reserved_mem.c
index d654921dd09b..578670e3f608 100644
--- a/arch/arm64/kvm/hyp/reserved_mem.c
+++ b/arch/arm64/kvm/hyp/reserved_mem.c
@@ -92,12 +92,10 @@ void __init kvm_hyp_reserve(void)
 * this is unmapped from the host stage-2, and fallback to PAGE_SIZE.
 */
hyp_mem_size = hyp_mem_pages << PAGE_SHIFT;
-   hyp_mem_base = memblock_find_in_range(0, memblock_end_of_DRAM(),
- ALIGN(hyp_mem_size, PMD_SIZE),
- PMD_SIZE);
+   hyp_mem_base = memblock_phys_alloc(ALIGN(hyp_mem_size, PMD_SIZE),
+  PMD_SIZE);
if (!hyp_mem_base)
-   hyp_mem_base = memblock_find_in_range(0, memblock_end_of_DRAM(),
- hyp_mem_size, PAGE_SIZE);
+   hyp_mem_base = memblock_phys_alloc(hyp_mem_size, PAGE_SIZE);
else
hyp_mem_size = ALIGN(hyp_mem_size, PMD_SIZE);
 
@@ -105,7 +103,6 @@ void __init kvm_hyp_reserve(void)
kvm_err("Failed to reserve hyp memory\n");
return;
}
-