diff mbox series

[v8,2/4] mm: Introduce memblock_isolate_memory

Message ID 20230316131711.1284451-3-alexghiti@rivosinc.com (mailing list archive)
State Superseded
Headers show
Series riscv: Use PUD/P4D/PGD pages for the linear mapping | expand

Checks

Context Check Description
conchuod/cover_letter success Series has a cover letter
conchuod/tree_selection success Guessed tree name to be for-next
conchuod/fixes_present success Fixes tag not required for -next series
conchuod/maintainers_pattern success MAINTAINERS pattern errors before the patch: 1 and now 1
conchuod/verify_signedoff success Signed-off-by tag matches author and committer
conchuod/kdoc success Errors and warnings before: 0 this patch: 0
conchuod/build_rv64_clang_allmodconfig success Errors and warnings before: 39 this patch: 39
conchuod/module_param success Was 0 now: 0
conchuod/build_rv64_gcc_allmodconfig success Errors and warnings before: 127 this patch: 127
conchuod/build_rv32_defconfig success Build OK
conchuod/dtb_warn_rv64 success Errors and warnings before: 3 this patch: 3
conchuod/header_inline success No static functions without inline keyword in header files
conchuod/checkpatch success total: 0 errors, 0 warnings, 0 checks, 33 lines checked
conchuod/source_inline success Was 0 now: 0
conchuod/build_rv64_nommu_k210_defconfig success Build OK
conchuod/verify_fixes success No Fixes tag
conchuod/build_rv64_nommu_virt_defconfig success Build OK

Commit Message

Alexandre Ghiti March 16, 2023, 1:17 p.m. UTC
This function allows to split a region in memblock.memory and will be
useful when setting up the linear mapping with STRICT_KERNEL_RWX: it
allows to isolate the kernel text/rodata and then avoid to map those
regions with a PUD/P4D/PGD.

Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Tested-by: Anup Patel <anup@brainfault.org>
---
 include/linux/memblock.h |  1 +
 mm/memblock.c            | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)

Comments

Mike Rapoport March 16, 2023, 8:12 p.m. UTC | #1
Hi Alexandre,

On Thu, Mar 16, 2023 at 02:17:09PM +0100, Alexandre Ghiti wrote:
> This function allows to split a region in memblock.memory and will be
> useful when setting up the linear mapping with STRICT_KERNEL_RWX: it
> allows to isolate the kernel text/rodata and then avoid to map those
> regions with a PUD/P4D/PGD.
 
Sorry I've missed it last time. The changelog is fine in the context of
this series, but if you look at it as a part of memblock changelog it
doesn't provide enough background on why memblock_isolate_memory() is
useful.

Can you please add more context so it would be self explanatory?

> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> Reviewed-by: Anup Patel <anup@brainfault.org>
> Tested-by: Anup Patel <anup@brainfault.org>
> ---
>  include/linux/memblock.h |  1 +
>  mm/memblock.c            | 20 ++++++++++++++++++++
>  2 files changed, 21 insertions(+)
> 
> diff --git a/include/linux/memblock.h b/include/linux/memblock.h
> index 50ad19662a32..2f7ef97c0da7 100644
> --- a/include/linux/memblock.h
> +++ b/include/linux/memblock.h
> @@ -125,6 +125,7 @@ int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size);
>  int memblock_mark_mirror(phys_addr_t base, phys_addr_t size);
>  int memblock_mark_nomap(phys_addr_t base, phys_addr_t size);
>  int memblock_clear_nomap(phys_addr_t base, phys_addr_t size);
> +int memblock_isolate_memory(phys_addr_t base, phys_addr_t size);
>  
>  void memblock_free_all(void);
>  void memblock_free(void *ptr, size_t size);
> diff --git a/mm/memblock.c b/mm/memblock.c
> index 25fd0626a9e7..e8c651a37012 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -805,6 +805,26 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
>  	return 0;
>  }
>  
> +/**
> + * memblock_isolate_memory - isolate given range in memblock.memory
> + * @base: base of range to isolate
> + * @size: size of range to isolate
> + *
> + * Isolates the given range in memblock.memory so that it does not share any
> + * region with other ranges.
> + *
> + * Return:
> + * 0 on success, -errno on failure.
> + */
> +
> +int __init_memblock memblock_isolate_memory(phys_addr_t base, phys_addr_t size)
> +{
> +	int start_rgn, end_rgn;
> +
> +	return memblock_isolate_range(&memblock.memory, base, size,
> +				      &start_rgn, &end_rgn);
> +}
> +
>  static int __init_memblock memblock_remove_range(struct memblock_type *type,
>  					  phys_addr_t base, phys_addr_t size)
>  {
> -- 
> 2.37.2
>
Alexandre Ghiti March 20, 2023, 10:54 a.m. UTC | #2
Hi Mike,

On 3/16/23 21:12, Mike Rapoport wrote:
> Hi Alexandre,
>
> On Thu, Mar 16, 2023 at 02:17:09PM +0100, Alexandre Ghiti wrote:
>> This function allows to split a region in memblock.memory and will be
>> useful when setting up the linear mapping with STRICT_KERNEL_RWX: it
>> allows to isolate the kernel text/rodata and then avoid to map those
>> regions with a PUD/P4D/PGD.
>   
> Sorry I've missed it last time. The changelog is fine in the context of


No worries :)


> this series, but if you look at it as a part of memblock changelog it
> doesn't provide enough background on why memblock_isolate_memory() is
> useful.
>
> Can you please add more context so it would be self explanatory?


What about: "memblock.memory contains the list of memory regions and a 
memory region can cover memory that will be mapped with different 
permissions. So to ease the mapping process, allow to isolate those 
regions by introducing a new function called memblock_isolate_memory. 
This will be used in arch specific code to isolate the kernel 
text/rodata regions when STRICT_KERNEL_RWX is enabled so that we avoid 
mapping them with PUD/P4D/PGD mappings."

Thanks,

Alex


>
>> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
>> Reviewed-by: Anup Patel <anup@brainfault.org>
>> Tested-by: Anup Patel <anup@brainfault.org>
>> ---
>>   include/linux/memblock.h |  1 +
>>   mm/memblock.c            | 20 ++++++++++++++++++++
>>   2 files changed, 21 insertions(+)
>>
>> diff --git a/include/linux/memblock.h b/include/linux/memblock.h
>> index 50ad19662a32..2f7ef97c0da7 100644
>> --- a/include/linux/memblock.h
>> +++ b/include/linux/memblock.h
>> @@ -125,6 +125,7 @@ int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size);
>>   int memblock_mark_mirror(phys_addr_t base, phys_addr_t size);
>>   int memblock_mark_nomap(phys_addr_t base, phys_addr_t size);
>>   int memblock_clear_nomap(phys_addr_t base, phys_addr_t size);
>> +int memblock_isolate_memory(phys_addr_t base, phys_addr_t size);
>>   
>>   void memblock_free_all(void);
>>   void memblock_free(void *ptr, size_t size);
>> diff --git a/mm/memblock.c b/mm/memblock.c
>> index 25fd0626a9e7..e8c651a37012 100644
>> --- a/mm/memblock.c
>> +++ b/mm/memblock.c
>> @@ -805,6 +805,26 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
>>   	return 0;
>>   }
>>   
>> +/**
>> + * memblock_isolate_memory - isolate given range in memblock.memory
>> + * @base: base of range to isolate
>> + * @size: size of range to isolate
>> + *
>> + * Isolates the given range in memblock.memory so that it does not share any
>> + * region with other ranges.
>> + *
>> + * Return:
>> + * 0 on success, -errno on failure.
>> + */
>> +
>> +int __init_memblock memblock_isolate_memory(phys_addr_t base, phys_addr_t size)
>> +{
>> +	int start_rgn, end_rgn;
>> +
>> +	return memblock_isolate_range(&memblock.memory, base, size,
>> +				      &start_rgn, &end_rgn);
>> +}
>> +
>>   static int __init_memblock memblock_remove_range(struct memblock_type *type,
>>   					  phys_addr_t base, phys_addr_t size)
>>   {
>> -- 
>> 2.37.2
>>
Mike Rapoport March 20, 2023, 5:44 p.m. UTC | #3
On Mon, Mar 20, 2023 at 11:54:14AM +0100, Alexandre Ghiti wrote:
> Hi Mike,
> 
> On 3/16/23 21:12, Mike Rapoport wrote:
> > Hi Alexandre,
> > 
> > On Thu, Mar 16, 2023 at 02:17:09PM +0100, Alexandre Ghiti wrote:
> > > This function allows to split a region in memblock.memory and will be
> > > useful when setting up the linear mapping with STRICT_KERNEL_RWX: it
> > > allows to isolate the kernel text/rodata and then avoid to map those
> > > regions with a PUD/P4D/PGD.
> > Sorry I've missed it last time. The changelog is fine in the context of
> 
> 
> No worries :)
> 
> 
> > this series, but if you look at it as a part of memblock changelog it
> > doesn't provide enough background on why memblock_isolate_memory() is
> > useful.
> > 
> > Can you please add more context so it would be self explanatory?
> 
> 
> What about: "memblock.memory contains the list of memory regions and a
> memory region can cover memory that will be mapped with different
> permissions. So to ease the mapping process, allow to isolate those regions
> by introducing a new function called memblock_isolate_memory. This will be
> used in arch specific code to isolate the kernel text/rodata regions when
> STRICT_KERNEL_RWX is enabled so that we avoid mapping them with PUD/P4D/PGD
> mappings."

With this change

... STRICT_KERNEL_RWX is enabled so that they can be mapped with base pages.

Acked-by: Mike Rapoport (IBM) <rppt@kernel.org>

> Thanks,
> 
> Alex
> 
> 
> > 
> > > Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> > > Reviewed-by: Anup Patel <anup@brainfault.org>
> > > Tested-by: Anup Patel <anup@brainfault.org>
> > > ---
> > >   include/linux/memblock.h |  1 +
> > >   mm/memblock.c            | 20 ++++++++++++++++++++
> > >   2 files changed, 21 insertions(+)
> > > 
> > > diff --git a/include/linux/memblock.h b/include/linux/memblock.h
> > > index 50ad19662a32..2f7ef97c0da7 100644
> > > --- a/include/linux/memblock.h
> > > +++ b/include/linux/memblock.h
> > > @@ -125,6 +125,7 @@ int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size);
> > >   int memblock_mark_mirror(phys_addr_t base, phys_addr_t size);
> > >   int memblock_mark_nomap(phys_addr_t base, phys_addr_t size);
> > >   int memblock_clear_nomap(phys_addr_t base, phys_addr_t size);
> > > +int memblock_isolate_memory(phys_addr_t base, phys_addr_t size);
> > >   void memblock_free_all(void);
> > >   void memblock_free(void *ptr, size_t size);
> > > diff --git a/mm/memblock.c b/mm/memblock.c
> > > index 25fd0626a9e7..e8c651a37012 100644
> > > --- a/mm/memblock.c
> > > +++ b/mm/memblock.c
> > > @@ -805,6 +805,26 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
> > >   	return 0;
> > >   }
> > > +/**
> > > + * memblock_isolate_memory - isolate given range in memblock.memory
> > > + * @base: base of range to isolate
> > > + * @size: size of range to isolate
> > > + *
> > > + * Isolates the given range in memblock.memory so that it does not share any
> > > + * region with other ranges.
> > > + *
> > > + * Return:
> > > + * 0 on success, -errno on failure.
> > > + */
> > > +
> > > +int __init_memblock memblock_isolate_memory(phys_addr_t base, phys_addr_t size)
> > > +{
> > > +	int start_rgn, end_rgn;
> > > +
> > > +	return memblock_isolate_range(&memblock.memory, base, size,
> > > +				      &start_rgn, &end_rgn);
> > > +}
> > > +
> > >   static int __init_memblock memblock_remove_range(struct memblock_type *type,
> > >   					  phys_addr_t base, phys_addr_t size)
> > >   {
> > > -- 
> > > 2.37.2
> > > 
>
Alexandre Ghiti March 23, 2023, 11:52 a.m. UTC | #4
On 3/20/23 18:44, Mike Rapoport wrote:
> On Mon, Mar 20, 2023 at 11:54:14AM +0100, Alexandre Ghiti wrote:
>> Hi Mike,
>>
>> On 3/16/23 21:12, Mike Rapoport wrote:
>>> Hi Alexandre,
>>>
>>> On Thu, Mar 16, 2023 at 02:17:09PM +0100, Alexandre Ghiti wrote:
>>>> This function allows to split a region in memblock.memory and will be
>>>> useful when setting up the linear mapping with STRICT_KERNEL_RWX: it
>>>> allows to isolate the kernel text/rodata and then avoid to map those
>>>> regions with a PUD/P4D/PGD.
>>> Sorry I've missed it last time. The changelog is fine in the context of
>>
>> No worries :)
>>
>>
>>> this series, but if you look at it as a part of memblock changelog it
>>> doesn't provide enough background on why memblock_isolate_memory() is
>>> useful.
>>>
>>> Can you please add more context so it would be self explanatory?
>>
>> What about: "memblock.memory contains the list of memory regions and a
>> memory region can cover memory that will be mapped with different
>> permissions. So to ease the mapping process, allow to isolate those regions
>> by introducing a new function called memblock_isolate_memory. This will be
>> used in arch specific code to isolate the kernel text/rodata regions when
>> STRICT_KERNEL_RWX is enabled so that we avoid mapping them with PUD/P4D/PGD
>> mappings."
> With this change
>
> ... STRICT_KERNEL_RWX is enabled so that they can be mapped with base pages.


Actually they will get mapped with PMD mappings :) I'll just append: "or 
PMD mapping" to your sentence above if that's ok with you.


>
> Acked-by: Mike Rapoport (IBM) <rppt@kernel.org>


Thanks for your review,

Alex


>
>> Thanks,
>>
>> Alex
>>
>>
>>>> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
>>>> Reviewed-by: Anup Patel <anup@brainfault.org>
>>>> Tested-by: Anup Patel <anup@brainfault.org>
>>>> ---
>>>>    include/linux/memblock.h |  1 +
>>>>    mm/memblock.c            | 20 ++++++++++++++++++++
>>>>    2 files changed, 21 insertions(+)
>>>>
>>>> diff --git a/include/linux/memblock.h b/include/linux/memblock.h
>>>> index 50ad19662a32..2f7ef97c0da7 100644
>>>> --- a/include/linux/memblock.h
>>>> +++ b/include/linux/memblock.h
>>>> @@ -125,6 +125,7 @@ int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size);
>>>>    int memblock_mark_mirror(phys_addr_t base, phys_addr_t size);
>>>>    int memblock_mark_nomap(phys_addr_t base, phys_addr_t size);
>>>>    int memblock_clear_nomap(phys_addr_t base, phys_addr_t size);
>>>> +int memblock_isolate_memory(phys_addr_t base, phys_addr_t size);
>>>>    void memblock_free_all(void);
>>>>    void memblock_free(void *ptr, size_t size);
>>>> diff --git a/mm/memblock.c b/mm/memblock.c
>>>> index 25fd0626a9e7..e8c651a37012 100644
>>>> --- a/mm/memblock.c
>>>> +++ b/mm/memblock.c
>>>> @@ -805,6 +805,26 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
>>>>    	return 0;
>>>>    }
>>>> +/**
>>>> + * memblock_isolate_memory - isolate given range in memblock.memory
>>>> + * @base: base of range to isolate
>>>> + * @size: size of range to isolate
>>>> + *
>>>> + * Isolates the given range in memblock.memory so that it does not share any
>>>> + * region with other ranges.
>>>> + *
>>>> + * Return:
>>>> + * 0 on success, -errno on failure.
>>>> + */
>>>> +
>>>> +int __init_memblock memblock_isolate_memory(phys_addr_t base, phys_addr_t size)
>>>> +{
>>>> +	int start_rgn, end_rgn;
>>>> +
>>>> +	return memblock_isolate_range(&memblock.memory, base, size,
>>>> +				      &start_rgn, &end_rgn);
>>>> +}
>>>> +
>>>>    static int __init_memblock memblock_remove_range(struct memblock_type *type,
>>>>    					  phys_addr_t base, phys_addr_t size)
>>>>    {
>>>> -- 
>>>> 2.37.2
>>>>
Mike Rapoport March 23, 2023, 12:16 p.m. UTC | #5
On Thu, Mar 23, 2023 at 12:52:36PM +0100, Alexandre Ghiti wrote:
> 
> On 3/20/23 18:44, Mike Rapoport wrote:
> > On Mon, Mar 20, 2023 at 11:54:14AM +0100, Alexandre Ghiti wrote:
> > > Hi Mike,
> > > 
> > > On 3/16/23 21:12, Mike Rapoport wrote:
> > > > Hi Alexandre,
> > > > 
> > > > On Thu, Mar 16, 2023 at 02:17:09PM +0100, Alexandre Ghiti wrote:
> > > > > This function allows to split a region in memblock.memory and will be
> > > > > useful when setting up the linear mapping with STRICT_KERNEL_RWX: it
> > > > > allows to isolate the kernel text/rodata and then avoid to map those
> > > > > regions with a PUD/P4D/PGD.
> > > > Sorry I've missed it last time. The changelog is fine in the context of
> > > 
> > > No worries :)
> > > 
> > > 
> > > > this series, but if you look at it as a part of memblock changelog it
> > > > doesn't provide enough background on why memblock_isolate_memory() is
> > > > useful.
> > > > 
> > > > Can you please add more context so it would be self explanatory?
> > > 
> > > What about: "memblock.memory contains the list of memory regions and a
> > > memory region can cover memory that will be mapped with different
> > > permissions. So to ease the mapping process, allow to isolate those regions
> > > by introducing a new function called memblock_isolate_memory. This will be
> > > used in arch specific code to isolate the kernel text/rodata regions when
> > > STRICT_KERNEL_RWX is enabled so that we avoid mapping them with PUD/P4D/PGD
> > > mappings."
> > With this change
> > 
> > ... STRICT_KERNEL_RWX is enabled so that they can be mapped with base pages.
> 
> 
> Actually they will get mapped with PMD mappings :) I'll just append: "or PMD
> mapping" to your sentence above if that's ok with you.

Didn't read the rest of the patches :)

.. STRICT_KERNEL_RWX is enabled so that they can be mapped with differently
than the rest of the memory.

Does it cover the usescases?

> > 
> > Acked-by: Mike Rapoport (IBM) <rppt@kernel.org>
> 
> 
> Thanks for your review,
> 
> Alex
> 
> 
> > 
> > > Thanks,
> > > 
> > > Alex
> > > 
> > > 
> > > > > Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> > > > > Reviewed-by: Anup Patel <anup@brainfault.org>
> > > > > Tested-by: Anup Patel <anup@brainfault.org>
> > > > > ---
> > > > >    include/linux/memblock.h |  1 +
> > > > >    mm/memblock.c            | 20 ++++++++++++++++++++
> > > > >    2 files changed, 21 insertions(+)
> > > > > 
> > > > > diff --git a/include/linux/memblock.h b/include/linux/memblock.h
> > > > > index 50ad19662a32..2f7ef97c0da7 100644
> > > > > --- a/include/linux/memblock.h
> > > > > +++ b/include/linux/memblock.h
> > > > > @@ -125,6 +125,7 @@ int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size);
> > > > >    int memblock_mark_mirror(phys_addr_t base, phys_addr_t size);
> > > > >    int memblock_mark_nomap(phys_addr_t base, phys_addr_t size);
> > > > >    int memblock_clear_nomap(phys_addr_t base, phys_addr_t size);
> > > > > +int memblock_isolate_memory(phys_addr_t base, phys_addr_t size);
> > > > >    void memblock_free_all(void);
> > > > >    void memblock_free(void *ptr, size_t size);
> > > > > diff --git a/mm/memblock.c b/mm/memblock.c
> > > > > index 25fd0626a9e7..e8c651a37012 100644
> > > > > --- a/mm/memblock.c
> > > > > +++ b/mm/memblock.c
> > > > > @@ -805,6 +805,26 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
> > > > >    	return 0;
> > > > >    }
> > > > > +/**
> > > > > + * memblock_isolate_memory - isolate given range in memblock.memory
> > > > > + * @base: base of range to isolate
> > > > > + * @size: size of range to isolate
> > > > > + *
> > > > > + * Isolates the given range in memblock.memory so that it does not share any
> > > > > + * region with other ranges.
> > > > > + *
> > > > > + * Return:
> > > > > + * 0 on success, -errno on failure.
> > > > > + */
> > > > > +
> > > > > +int __init_memblock memblock_isolate_memory(phys_addr_t base, phys_addr_t size)
> > > > > +{
> > > > > +	int start_rgn, end_rgn;
> > > > > +
> > > > > +	return memblock_isolate_range(&memblock.memory, base, size,
> > > > > +				      &start_rgn, &end_rgn);
> > > > > +}
> > > > > +
> > > > >    static int __init_memblock memblock_remove_range(struct memblock_type *type,
> > > > >    					  phys_addr_t base, phys_addr_t size)
> > > > >    {
> > > > > -- 
> > > > > 2.37.2
> > > > >
Alexandre Ghiti March 23, 2023, 12:30 p.m. UTC | #6
On 3/23/23 13:16, Mike Rapoport wrote:
> On Thu, Mar 23, 2023 at 12:52:36PM +0100, Alexandre Ghiti wrote:
>> On 3/20/23 18:44, Mike Rapoport wrote:
>>> On Mon, Mar 20, 2023 at 11:54:14AM +0100, Alexandre Ghiti wrote:
>>>> Hi Mike,
>>>>
>>>> On 3/16/23 21:12, Mike Rapoport wrote:
>>>>> Hi Alexandre,
>>>>>
>>>>> On Thu, Mar 16, 2023 at 02:17:09PM +0100, Alexandre Ghiti wrote:
>>>>>> This function allows to split a region in memblock.memory and will be
>>>>>> useful when setting up the linear mapping with STRICT_KERNEL_RWX: it
>>>>>> allows to isolate the kernel text/rodata and then avoid to map those
>>>>>> regions with a PUD/P4D/PGD.
>>>>> Sorry I've missed it last time. The changelog is fine in the context of
>>>> No worries :)
>>>>
>>>>
>>>>> this series, but if you look at it as a part of memblock changelog it
>>>>> doesn't provide enough background on why memblock_isolate_memory() is
>>>>> useful.
>>>>>
>>>>> Can you please add more context so it would be self explanatory?
>>>> What about: "memblock.memory contains the list of memory regions and a
>>>> memory region can cover memory that will be mapped with different
>>>> permissions. So to ease the mapping process, allow to isolate those regions
>>>> by introducing a new function called memblock_isolate_memory. This will be
>>>> used in arch specific code to isolate the kernel text/rodata regions when
>>>> STRICT_KERNEL_RWX is enabled so that we avoid mapping them with PUD/P4D/PGD
>>>> mappings."
>>> With this change
>>>
>>> ... STRICT_KERNEL_RWX is enabled so that they can be mapped with base pages.
>>
>> Actually they will get mapped with PMD mappings :) I'll just append: "or PMD
>> mapping" to your sentence above if that's ok with you.
> Didn't read the rest of the patches :)
>
> .. STRICT_KERNEL_RWX is enabled so that they can be mapped with differently
> than the rest of the memory.
>
> Does it cover the usescases?


Yes, fine with me!

Thanks again


>
>>> Acked-by: Mike Rapoport (IBM) <rppt@kernel.org>
>>
>> Thanks for your review,
>>
>> Alex
>>
>>
>>>> Thanks,
>>>>
>>>> Alex
>>>>
>>>>
>>>>>> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
>>>>>> Reviewed-by: Anup Patel <anup@brainfault.org>
>>>>>> Tested-by: Anup Patel <anup@brainfault.org>
>>>>>> ---
>>>>>>     include/linux/memblock.h |  1 +
>>>>>>     mm/memblock.c            | 20 ++++++++++++++++++++
>>>>>>     2 files changed, 21 insertions(+)
>>>>>>
>>>>>> diff --git a/include/linux/memblock.h b/include/linux/memblock.h
>>>>>> index 50ad19662a32..2f7ef97c0da7 100644
>>>>>> --- a/include/linux/memblock.h
>>>>>> +++ b/include/linux/memblock.h
>>>>>> @@ -125,6 +125,7 @@ int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size);
>>>>>>     int memblock_mark_mirror(phys_addr_t base, phys_addr_t size);
>>>>>>     int memblock_mark_nomap(phys_addr_t base, phys_addr_t size);
>>>>>>     int memblock_clear_nomap(phys_addr_t base, phys_addr_t size);
>>>>>> +int memblock_isolate_memory(phys_addr_t base, phys_addr_t size);
>>>>>>     void memblock_free_all(void);
>>>>>>     void memblock_free(void *ptr, size_t size);
>>>>>> diff --git a/mm/memblock.c b/mm/memblock.c
>>>>>> index 25fd0626a9e7..e8c651a37012 100644
>>>>>> --- a/mm/memblock.c
>>>>>> +++ b/mm/memblock.c
>>>>>> @@ -805,6 +805,26 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
>>>>>>     	return 0;
>>>>>>     }
>>>>>> +/**
>>>>>> + * memblock_isolate_memory - isolate given range in memblock.memory
>>>>>> + * @base: base of range to isolate
>>>>>> + * @size: size of range to isolate
>>>>>> + *
>>>>>> + * Isolates the given range in memblock.memory so that it does not share any
>>>>>> + * region with other ranges.
>>>>>> + *
>>>>>> + * Return:
>>>>>> + * 0 on success, -errno on failure.
>>>>>> + */
>>>>>> +
>>>>>> +int __init_memblock memblock_isolate_memory(phys_addr_t base, phys_addr_t size)
>>>>>> +{
>>>>>> +	int start_rgn, end_rgn;
>>>>>> +
>>>>>> +	return memblock_isolate_range(&memblock.memory, base, size,
>>>>>> +				      &start_rgn, &end_rgn);
>>>>>> +}
>>>>>> +
>>>>>>     static int __init_memblock memblock_remove_range(struct memblock_type *type,
>>>>>>     					  phys_addr_t base, phys_addr_t size)
>>>>>>     {
>>>>>> -- 
>>>>>> 2.37.2
>>>>>>
diff mbox series

Patch

diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 50ad19662a32..2f7ef97c0da7 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -125,6 +125,7 @@  int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size);
 int memblock_mark_mirror(phys_addr_t base, phys_addr_t size);
 int memblock_mark_nomap(phys_addr_t base, phys_addr_t size);
 int memblock_clear_nomap(phys_addr_t base, phys_addr_t size);
+int memblock_isolate_memory(phys_addr_t base, phys_addr_t size);
 
 void memblock_free_all(void);
 void memblock_free(void *ptr, size_t size);
diff --git a/mm/memblock.c b/mm/memblock.c
index 25fd0626a9e7..e8c651a37012 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -805,6 +805,26 @@  static int __init_memblock memblock_isolate_range(struct memblock_type *type,
 	return 0;
 }
 
+/**
+ * memblock_isolate_memory - isolate given range in memblock.memory
+ * @base: base of range to isolate
+ * @size: size of range to isolate
+ *
+ * Isolates the given range in memblock.memory so that it does not share any
+ * region with other ranges.
+ *
+ * Return:
+ * 0 on success, -errno on failure.
+ */
+
+int __init_memblock memblock_isolate_memory(phys_addr_t base, phys_addr_t size)
+{
+	int start_rgn, end_rgn;
+
+	return memblock_isolate_range(&memblock.memory, base, size,
+				      &start_rgn, &end_rgn);
+}
+
 static int __init_memblock memblock_remove_range(struct memblock_type *type,
 					  phys_addr_t base, phys_addr_t size)
 {