From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FB8FC33CB1 for ; Wed, 15 Jan 2020 15:34:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 46F622467C for ; Wed, 15 Jan 2020 15:34:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HbG0R0Rz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728963AbgAOPeo (ORCPT ); Wed, 15 Jan 2020 10:34:44 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:58479 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728901AbgAOPen (ORCPT ); Wed, 15 Jan 2020 10:34:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579102482; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UF/PkcANm57Eh1tDw6DcKK7aTyoekC9tB6sajNqHYk8=; b=HbG0R0RzOxEwtl4NbuLs8ET6vOMweOVHxeXNFLh6lJHOmmPMT327vI6NtOPqSfO0LohNsK q3OaUdfMfqvSG39nb9jWdPMFK6aNUBlpBRREIE4eDr8WUlLX95TvZ4CDn9bKjFFJ+8gZb2 evEAiDE/tB08X4u/F1myVYW5U39OoLk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-325-nISm7mClPH-KfBkE5P-Y9A-1; Wed, 15 Jan 2020 10:34:35 -0500 X-MC-Unique: nISm7mClPH-KfBkE5P-Y9A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 110D6109AAFC; Wed, 15 Jan 2020 15:34:34 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.36.118.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id D59618886D; Wed, 15 Jan 2020 15:34:31 +0000 (UTC) From: David Hildenbrand To: stable@vger.kernel.org Cc: linux-mm@kvack.org, Oscar Salvador , Michal Hocko , "Aneesh Kumar K . V" , Greg Kroah-Hartman , Dan Williams , Andrew Morton , Laurent Vivier , Baoquan He , David Hildenbrand Subject: [PATCH for 4.19-stable 18/25] mm/memory_hotplug: remove memory block devices before arch_remove_memory() Date: Wed, 15 Jan 2020 16:33:32 +0100 Message-Id: <20200115153339.36409-19-david@redhat.com> In-Reply-To: <20200115153339.36409-1-david@redhat.com> References: <20200115153339.36409-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Content-Transfer-Encoding: quoted-printable Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org commit 4c4b7f9ba9486c565aead99a198ceeef73ae81f6 upstream. Let's factor out removing of memory block devices, which is only necessary for memory added via add_memory() and friends that created memory block devices. Remove the devices before calling arch_remove_memory(). This finishes factoring out memory block device handling from arch_add_memory() and arch_remove_memory(). Link: http://lkml.kernel.org/r/20190527111152.16324-10-david@redhat.com Signed-off-by: David Hildenbrand Reviewed-by: Dan Williams Acked-by: Michal Hocko Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Cc: David Hildenbrand Cc: "mike.travis@hpe.com" Cc: Andrew Banman Cc: Ingo Molnar Cc: Alex Deucher Cc: "David S. Miller" Cc: Mark Brown Cc: Chris Wilson Cc: Oscar Salvador Cc: Jonathan Cameron Cc: Arun KS Cc: Mathieu Malaterre Cc: Andy Lutomirski Cc: Anshuman Khandual Cc: Ard Biesheuvel Cc: Baoquan He Cc: Benjamin Herrenschmidt Cc: Borislav Petkov Cc: Catalin Marinas Cc: Chintan Pandya Cc: Christophe Leroy Cc: Dave Hansen Cc: Fenghua Yu Cc: Heiko Carstens Cc: "H. Peter Anvin" Cc: Joonsoo Kim Cc: Jun Yao Cc: "Kirill A. Shutemov" Cc: Logan Gunthorpe Cc: Mark Rutland Cc: Masahiro Yamada Cc: Michael Ellerman Cc: Mike Rapoport Cc: Nicholas Piggin Cc: Oscar Salvador Cc: Paul Mackerras Cc: Pavel Tatashin Cc: Peter Zijlstra Cc: Qian Cai Cc: Rich Felker Cc: Rob Herring Cc: Robin Murphy Cc: Thomas Gleixner Cc: Tony Luck Cc: Vasily Gorbik Cc: Wei Yang Cc: Will Deacon Cc: Yoshinori Sato Cc: Yu Zhao Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: David Hildenbrand --- drivers/base/memory.c | 37 ++++++++++++++++++------------------- drivers/base/node.c | 11 ++++++----- include/linux/memory.h | 2 +- include/linux/node.h | 6 ++---- mm/memory_hotplug.c | 5 +++-- 5 files changed, 30 insertions(+), 31 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index b89b9c3efa59..fdda7a6d712e 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -768,32 +768,31 @@ int create_memory_block_devices(unsigned long start= , unsigned long size) return ret; } =20 -void unregister_memory_section(struct mem_section *section) +/* + * Remove memory block devices for the given memory area. Start and size + * have to be aligned to memory block granularity. Memory block devices + * have to be offline. + */ +void remove_memory_block_devices(unsigned long start, unsigned long size= ) { + const int start_block_id =3D pfn_to_block_id(PFN_DOWN(start)); + const int end_block_id =3D pfn_to_block_id(PFN_DOWN(start + size)); struct memory_block *mem; + int block_id; =20 - if (WARN_ON_ONCE(!present_section(section))) + if (WARN_ON_ONCE(!IS_ALIGNED(start, memory_block_size_bytes()) || + !IS_ALIGNED(size, memory_block_size_bytes()))) return; =20 mutex_lock(&mem_sysfs_mutex); - - /* - * Some users of the memory hotplug do not want/need memblock to - * track all sections. Skip over those. - */ - mem =3D find_memory_block(section); - if (!mem) - goto out_unlock; - - unregister_mem_sect_under_nodes(mem, __section_nr(section)); - - mem->section_count--; - if (mem->section_count =3D=3D 0) + for (block_id =3D start_block_id; block_id !=3D end_block_id; block_id+= +) { + mem =3D find_memory_block_by_id(block_id, NULL); + if (WARN_ON_ONCE(!mem)) + continue; + mem->section_count =3D 0; + unregister_memory_block_under_nodes(mem); unregister_memory(mem); - else - put_device(&mem->dev); - -out_unlock: + } mutex_unlock(&mem_sysfs_mutex); } =20 diff --git a/drivers/base/node.c b/drivers/base/node.c index c3968e2d0a98..1211794d658c 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -453,9 +453,10 @@ int register_mem_sect_under_node(struct memory_block= *mem_blk, void *arg) return 0; } =20 -/* unregister memory section under all nodes that it spans */ -int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, - unsigned long phys_index) +/* + * Unregister memory block device under all nodes that it spans. + */ +int unregister_memory_block_under_nodes(struct memory_block *mem_blk) { NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL); unsigned long pfn, sect_start_pfn, sect_end_pfn; @@ -468,8 +469,8 @@ int unregister_mem_sect_under_nodes(struct memory_blo= ck *mem_blk, return -ENOMEM; nodes_clear(*unlinked_nodes); =20 - sect_start_pfn =3D section_nr_to_pfn(phys_index); - sect_end_pfn =3D sect_start_pfn + PAGES_PER_SECTION - 1; + sect_start_pfn =3D section_nr_to_pfn(mem_blk->start_section_nr); + sect_end_pfn =3D section_nr_to_pfn(mem_blk->end_section_nr); for (pfn =3D sect_start_pfn; pfn <=3D sect_end_pfn; pfn++) { int nid; =20 diff --git a/include/linux/memory.h b/include/linux/memory.h index db3e8567f900..f26a5417ec5d 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -112,7 +112,7 @@ extern void unregister_memory_notifier(struct notifie= r_block *nb); extern int register_memory_isolate_notifier(struct notifier_block *nb); extern void unregister_memory_isolate_notifier(struct notifier_block *nb= ); int create_memory_block_devices(unsigned long start, unsigned long size)= ; -extern void unregister_memory_section(struct mem_section *); +void remove_memory_block_devices(unsigned long start, unsigned long size= ); extern int memory_dev_init(void); extern int memory_notify(unsigned long val, void *v); extern int memory_isolate_notify(unsigned long val, void *v); diff --git a/include/linux/node.h b/include/linux/node.h index 257bb3d6d014..9a6db437f2d1 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -72,8 +72,7 @@ extern int register_cpu_under_node(unsigned int cpu, un= signed int nid); extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)= ; extern int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg); -extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, - unsigned long phys_index); +extern int unregister_memory_block_under_nodes(struct memory_block *mem_= blk); =20 #ifdef CONFIG_HUGETLBFS extern void register_hugetlbfs_with_node(node_registration_func_t doregi= ster, @@ -105,8 +104,7 @@ static inline int register_mem_sect_under_node(struct= memory_block *mem_blk, { return 0; } -static inline int unregister_mem_sect_under_nodes(struct memory_block *m= em_blk, - unsigned long phys_index) +static inline int unregister_memory_block_under_nodes(struct memory_bloc= k *mem_blk) { return 0; } diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 414771114685..7a1c9fbf9f41 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -481,8 +481,6 @@ static void __remove_section(struct zone *zone, struc= t mem_section *ms, if (WARN_ON_ONCE(!valid_section(ms))) return; =20 - unregister_memory_section(ms); - scn_nr =3D __section_nr(ms); start_pfn =3D section_nr_to_pfn((unsigned long)scn_nr); __remove_zone(zone, start_pfn); @@ -1914,6 +1912,9 @@ void __ref __remove_memory(int nid, u64 start, u64 = size) memblock_free(start, size); memblock_remove(start, size); =20 + /* remove memory block devices before removing memory */ + remove_memory_block_devices(start, size); + arch_remove_memory(nid, start, size, NULL); __release_memory_resource(start, size); =20 --=20 2.24.1