mbox series

[V3,0/3] mm/memory_hotplug: Pre-validate the address range with platform

Message ID 1610975582-12646-1-git-send-email-anshuman.khandual@arm.com (mailing list archive)
Headers show
Series mm/memory_hotplug: Pre-validate the address range with platform | expand

Message

Anshuman Khandual Jan. 18, 2021, 1:12 p.m. UTC
This series adds a mechanism allowing platforms to weigh in and prevalidate
incoming address range before proceeding further with the memory hotplug.
This helps prevent potential platform errors for the given address range,
down the hotplug call chain, which inevitably fails the hotplug itself.

This mechanism was suggested by David Hildenbrand during another discussion
with respect to a memory hotplug fix on arm64 platform.

https://lore.kernel.org/linux-arm-kernel/1600332402-30123-1-git-send-email-anshuman.khandual@arm.com/

This mechanism focuses on the addressibility aspect and not [sub] section
alignment aspect. Hence check_hotplug_memory_range() and check_pfn_span()
have been left unchanged. Wondering if all these can still be unified in
an expanded memhp_range_allowed() check, that can be called from multiple
memory hot add and remove paths.

This series applies on v5.11-rc4 and has been tested on arm64. But only
build tested on s390.

Changes in V3

- Updated the commit message in [PATCH 1/3]
- Replaced 1 with 'true' and 0 with 'false' in memhp_range_allowed()
- Updated memhp_range.end as VMEM_MAX_PHYS - 1 and updated vmem_add_mapping() on s390
- Changed memhp_range_allowed() behaviour in __add_pages()
- Updated __add_pages() to return E2BIG when memhp_range_allowed() fails for non-linear mapping based requests

Changes in V2:

https://lore.kernel.org/linux-mm/1608218912-28932-1-git-send-email-anshuman.khandual@arm.com/

- Changed s390 version per Heiko and updated the commit message
- Called memhp_range_allowed() only for arch_add_memory() in pagemap_range()
- Exported the symbol memhp_get_pluggable_range() 

Changes in V1:

https://lore.kernel.org/linux-mm/1607400978-31595-1-git-send-email-anshuman.khandual@arm.com/

- Fixed build problems with (MEMORY_HOTPLUG & !MEMORY_HOTREMOVE)
- Added missing prototype for arch_get_mappable_range()
- Added VM_BUG_ON() check for memhp_range_allowed() in arch_add_memory() per David

Changes in RFC V2:

https://lore.kernel.org/linux-mm/1606706992-26656-1-git-send-email-anshuman.khandual@arm.com/

Incorporated all review feedbacks from David.

- Added additional range check in __segment_load() on s390 which was lost
- Changed is_private init in pagemap_range()
- Moved the framework into mm/memory_hotplug.c
- Made arch_get_addressable_range() a __weak function
- Renamed arch_get_addressable_range() as arch_get_mappable_range()
- Callback arch_get_mappable_range() only handles range requiring linear mapping
- Merged multiple memhp_range_allowed() checks in register_memory_resource()
- Replaced WARN() with pr_warn() in memhp_range_allowed()
- Replaced error return code ERANGE with E2BIG

Changes in RFC V1:

https://lore.kernel.org/linux-mm/1606098529-7907-1-git-send-email-anshuman.khandual@arm.com/

Cc: Oscar Salvador <osalvador@suse.de>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-s390@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org

Anshuman Khandual (3):
  mm/memory_hotplug: Prevalidate the address range being added with platform
  arm64/mm: Define arch_get_mappable_range()
  s390/mm: Define arch_get_mappable_range()

David Hildenbrand (1):
  virtio-mem: check against memhp_get_pluggable_range() which memory we can hotplug

 arch/arm64/mm/mmu.c            | 15 +++----
 arch/s390/mm/init.c            |  1 +
 arch/s390/mm/vmem.c            | 15 ++++++-
 drivers/virtio/virtio_mem.c    | 40 +++++++++++------
 include/linux/memory_hotplug.h | 10 +++++
 mm/memory_hotplug.c            | 79 ++++++++++++++++++++++++++--------
 mm/memremap.c                  |  6 +++
 7 files changed, 125 insertions(+), 41 deletions(-)

Comments

David Hildenbrand Jan. 19, 2021, 1:33 p.m. UTC | #1
On 18.01.21 14:12, Anshuman Khandual wrote:
> This series adds a mechanism allowing platforms to weigh in and prevalidate
> incoming address range before proceeding further with the memory hotplug.
> This helps prevent potential platform errors for the given address range,
> down the hotplug call chain, which inevitably fails the hotplug itself.
> 
> This mechanism was suggested by David Hildenbrand during another discussion
> with respect to a memory hotplug fix on arm64 platform.
> 
> https://lore.kernel.org/linux-arm-kernel/1600332402-30123-1-git-send-email-anshuman.khandual@arm.com/
> 
> This mechanism focuses on the addressibility aspect and not [sub] section
> alignment aspect. Hence check_hotplug_memory_range() and check_pfn_span()
> have been left unchanged. Wondering if all these can still be unified in
> an expanded memhp_range_allowed() check, that can be called from multiple
> memory hot add and remove paths.
> 
> This series applies on v5.11-rc4 and has been tested on arm64. But only
> build tested on s390.
> 
> Changes in V3
> 
> - Updated the commit message in [PATCH 1/3]
> - Replaced 1 with 'true' and 0 with 'false' in memhp_range_allowed()
> - Updated memhp_range.end as VMEM_MAX_PHYS - 1 and updated vmem_add_mapping() on s390
> - Changed memhp_range_allowed() behaviour in __add_pages()
> - Updated __add_pages() to return E2BIG when memhp_range_allowed() fails for non-linear mapping based requests

Minor thing, we should make up our mind if we want to call stuff
internally "memhp_" or "mhp". I prefer the latter, because it is shorter.
Oscar Salvador Jan. 19, 2021, 1:40 p.m. UTC | #2
On Tue, Jan 19, 2021 at 02:33:03PM +0100, David Hildenbrand wrote:
> Minor thing, we should make up our mind if we want to call stuff
> internally "memhp_" or "mhp". I prefer the latter, because it is shorter.

I would rather use the latter as well. I used that in [1].
MEMHP_MERGE_RESOURCE should be renamed if we agree on that.

[1] https://patchwork.kernel.org/project/linux-mm/cover/20201217130758.11565-1-osalvador@suse.de/
Anshuman Khandual Jan. 20, 2021, 8:37 a.m. UTC | #3
On 1/19/21 7:10 PM, Oscar Salvador wrote:
> On Tue, Jan 19, 2021 at 02:33:03PM +0100, David Hildenbrand wrote:
>> Minor thing, we should make up our mind if we want to call stuff
>> internally "memhp_" or "mhp". I prefer the latter, because it is shorter.
> 
> I would rather use the latter as well. I used that in [1].

Okay, will change all that is 'memhp' as 'mhp' instead.

> MEMHP_MERGE_RESOURCE should be renamed if we agree on that.
> 
> [1] https://patchwork.kernel.org/project/linux-mm/cover/20201217130758.11565-1-osalvador@suse.de/
> 
>
Anshuman Khandual Jan. 22, 2021, 6:04 a.m. UTC | #4
On 1/20/21 2:07 PM, Anshuman Khandual wrote:
> 
> 
> On 1/19/21 7:10 PM, Oscar Salvador wrote:
>> On Tue, Jan 19, 2021 at 02:33:03PM +0100, David Hildenbrand wrote:
>>> Minor thing, we should make up our mind if we want to call stuff
>>> internally "memhp_" or "mhp". I prefer the latter, because it is shorter.
>>
>> I would rather use the latter as well. I used that in [1].
> 
> Okay, will change all that is 'memhp' as 'mhp' instead.
> 
>> MEMHP_MERGE_RESOURCE should be renamed if we agree on that.
>>
>> [1] https://patchwork.kernel.org/project/linux-mm/cover/20201217130758.11565-1-osalvador@suse.de/
>>

While replacing 'memhp' as 'mhp' in this series, noticed there are
some more 'memhp' scattered around the code from earlier. A mix of
both 'memhp' and 'mhp' might not be a good idea. Hence should we
just change these remaining 'memhp' as 'mhp' as well and possibly
also MEMHP_MERGE_RESOURCE as suggested earlier, in a subsequent
clean up patch ? Would there be a problem with memhp_default_state
being a command line parameter ?

From a tree wide search -

Documentation/admin-guide/kernel-parameters.txt:        memhp_default_state=online/offline
drivers/base/memory.c:int memhp_online_type_from_str(const char *str)
drivers/base/memory.c:  const int online_type = memhp_online_type_from_str(buf);
drivers/base/memory.c:                    online_type_to_str[memhp_default_online_type]);
drivers/base/memory.c:  const int online_type = memhp_online_type_from_str(buf);
drivers/base/memory.c:  memhp_default_online_type = online_type;
include/linux/memory_hotplug.h:extern int memhp_online_type_from_str(const char *str);
include/linux/memory_hotplug.h:extern int memhp_default_online_type;
mm/memory_hotplug.c:int memhp_default_online_type = MMOP_OFFLINE;
mm/memory_hotplug.c:int memhp_default_online_type = MMOP_ONLINE;
mm/memory_hotplug.c:static int __init setup_memhp_default_state(char *str)
mm/memory_hotplug.c:    const int online_type = memhp_online_type_from_str(str);
mm/memory_hotplug.c:            memhp_default_online_type = online_type;
mm/memory_hotplug.c:__setup("memhp_default_state=", setup_memhp_default_state);
mm/memory_hotplug.c:    mem->online_type = memhp_default_online_type;
mm/memory_hotplug.c:    if (memhp_default_online_type != MMOP_OFFLINE)
David Hildenbrand Jan. 22, 2021, 8:34 a.m. UTC | #5
On 22.01.21 07:04, Anshuman Khandual wrote:
> 
> On 1/20/21 2:07 PM, Anshuman Khandual wrote:
>>
>>
>> On 1/19/21 7:10 PM, Oscar Salvador wrote:
>>> On Tue, Jan 19, 2021 at 02:33:03PM +0100, David Hildenbrand wrote:
>>>> Minor thing, we should make up our mind if we want to call stuff
>>>> internally "memhp_" or "mhp". I prefer the latter, because it is shorter.
>>>
>>> I would rather use the latter as well. I used that in [1].
>>
>> Okay, will change all that is 'memhp' as 'mhp' instead.
>>
>>> MEMHP_MERGE_RESOURCE should be renamed if we agree on that.
>>>
>>> [1] https://patchwork.kernel.org/project/linux-mm/cover/20201217130758.11565-1-osalvador@suse.de/
>>>
> 
> While replacing 'memhp' as 'mhp' in this series, noticed there are
> some more 'memhp' scattered around the code from earlier. A mix of
> both 'memhp' and 'mhp' might not be a good idea. Hence should we
> just change these remaining 'memhp' as 'mhp' as well and possibly
> also MEMHP_MERGE_RESOURCE as suggested earlier, in a subsequent

As mentioned in another thread to Oscar, I already have a cleanup patch
for that one lying around, part of a bigger series. Might just send that
one out separately earlier.

> clean up patch ? Would there be a problem with memhp_default_state
> being a command line parameter ?

Yes, that one we should not change, to not break existing cmdlines
without good reason. We could change the
memhp_default_online_type/memhp_online_type_from_str/... thingies, though.

Feel free to send a patch, thanks!