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=-3.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS autolearn=no 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 8C075C2D0DB for ; Tue, 28 Jan 2020 13:50:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 359A02468D for ; Tue, 28 Jan 2020 13:50:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="WtQeoPY/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 359A02468D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2437C6B0279; Tue, 28 Jan 2020 08:50:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 107C96B027A; Tue, 28 Jan 2020 08:50:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F39E46B027B; Tue, 28 Jan 2020 08:50:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0113.hostedemail.com [216.40.44.113]) by kanga.kvack.org (Postfix) with ESMTP id D11476B0279 for ; Tue, 28 Jan 2020 08:50:16 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 8D338181AEF10 for ; Tue, 28 Jan 2020 13:50:16 +0000 (UTC) X-FDA: 76427177232.28.alarm65_3c88b803aae5f X-HE-Tag: alarm65_3c88b803aae5f X-Filterd-Recvd-Size: 13980 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Tue, 28 Jan 2020 13:50:15 +0000 (UTC) Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B6F7F2468F; Tue, 28 Jan 2020 13:50:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580219415; bh=dUiLzibvM6Bh7L8Z+57cjsVccaym+btExbIBVfCSpMg=; h=Subject:To:Cc:From:Date:In-Reply-To:From; b=WtQeoPY/yYqHTQvif3Drp7DADyJh19kJQxU3Fh8ZGaKCisz0EvRt1PQ/ScCfmuq3S 8kiCmG4scglCnHgvH22qV3eU/4X8viBN+xBnn8ONZUrUJob38imZwCjADGDFctF8zp nhv4qH7TE9NtulG7iK3wKmDnSeRYBcN6ok7dpP10= Subject: Patch "mm/memory_hotplug: remove memory block devices before arch_remove_memory()" has been added to the 4.19-stable tree To: 20190527111152.16324-10-david@redhat.com, Jonathan.Cameron@huawei.com, akpm@linux-foundation.org, alexander.deucher@amd.com, andrew.banman@hpe.com, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, ard.biesheuvel@linaro.org, arunks@codeaurora.org, benh@kernel.crashing.org, bhe@redhat.com, bp@alien8.de, broonie@kernel.org, cai@lca.pw, catalin.marinas@arm.com, chris@chris-wilson.co.uk, christophe.leroy@c-s.fr, cpandya@codeaurora.org, dalias@libc.org, dan.j.williams@intel.com, dave.hansen@linux.intel.com, davem@davemloft.net, david@redhat.com, fenghua.yu@intel.com, gor@linux.ibm.com, gregkh@linuxfoundation.org, heiko.carstens@de.ibm.com, hpa@zytor.com, iamjoonsoo.kim@lge.com, kirill.shutemov@linux.intel.com, linux-mm@kvack.org, logang@deltatee.com, luto@kernel.org, malat@debian.org, mark.rutland@arm.com, mhocko@suse.com, mike.travis@hpe.com, mingo@kernel.org, mpe@ellerman.id.au, npiggin@gmail.com, osalvador@suse.com, osalvador@suse.de, pasha.tatashin@soleen.com, paulus@samba.org, peterz@infradead.org, rafael@kernel.org, ri@kvack.org, chard.weiyang@gmail.com, robh@kernel.org, robin.murphy@arm.com, rppt@linux.vnet.ibm.com, tglx@linutronix.de, tony.luck@intel.com, torvalds@linux-foundation.org, will.deacon@arm.com, yamada.masahiro@socionext.com, yaojun8558363@gmail.com, ysato@users.sourceforge.jp, yuzhao@google.com Cc: From: Date: Tue, 28 Jan 2020 14:49:45 +0100 In-Reply-To: <20200128095021.8076-18-david@redhat.com> Message-ID: <15802193854228@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 X-stable: commit X-Patchwork-Hint: ignore Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This is a note to let you know that I've just added the patch titled mm/memory_hotplug: remove memory block devices before arch_remove_mem= ory() to the 4.19-stable tree which can be found at: http://www.kernel.org/git/?p=3Dlinux/kernel/git/stable/stable-queue.g= it;a=3Dsummary The filename of the patch is: mm-memory_hotplug-remove-memory-block-devices-before-arch_remove_mem= ory.patch and it can be found in the queue-4.19 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. >From foo@baz Tue 28 Jan 2020 02:32:10 PM CET From: David Hildenbrand Date: Tue, 28 Jan 2020 10:50:14 +0100 Subject: mm/memory_hotplug: remove memory block devices before arch_remov= e_memory() To: stable@vger.kernel.org Cc: linux-mm@kvack.org, Michal Hocko , Greg Kroah-Hartma= n , Andrew Morton = , "Aneesh Kumar K . V" , Baoquan He , Dan Williams , Oscar Salvador , Wei Yang , David Hildenbrand Message-ID: <20200128095021.8076-18-david@redhat.com> From: David Hildenbrand 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 Signed-off-by: Greg Kroah-Hartman --- 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(-) --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -768,32 +768,31 @@ int create_memory_block_devices(unsigned 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 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -453,9 +453,10 @@ int register_mem_sect_under_node(struct 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(stru 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 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -112,7 +112,7 @@ extern void unregister_memory_notifier(s 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); --- a/include/linux/node.h +++ b/include/linux/node.h @@ -72,8 +72,7 @@ extern int register_cpu_under_node(unsig 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_unde { 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; } --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -481,8 +481,6 @@ static void __remove_section(struct zone 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 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 Patches currently in stable-queue which might be from david@redhat.com ar= e queue-4.19/mm-memory_hotplug-remove-memory-block-devices-before-arch_remo= ve_memory.patch queue-4.19/mm-hotplug-kill-is_dev_zone-usage-in-__remove_pages.patch queue-4.19/mm-memory_hotplug-create-memory-block-devices-after-arch_add_m= emory.patch queue-4.19/drivers-base-memory-pass-a-block_id-to-init_memory_block.patch queue-4.19/drivers-base-memory.c-clean-up-relics-in-function-parameters.p= atch queue-4.19/mm-memory_hotplug-update-a-comment-in-unregister_memory.patch queue-4.19/mm-memory_hotplug-shrink-zones-when-offlining-memory.patch queue-4.19/mm-memory_hotplug-make-unregister_memory_block_under_nodes-nev= er-fail.patch queue-4.19/mm-memunmap-don-t-access-uninitialized-memmap-in-memunmap_page= s.patch queue-4.19/mm-memory_hotplug-make-__remove_section-never-fail.patch queue-4.19/mm-sparse-drop-pgdat_resize_lock-in-sparse_add-remove_one_sect= ion.patch queue-4.19/mm-memory_hotplug-make-unregister_memory_section-never-fail.pa= tch queue-4.19/mm-memory_hotplug-release-memory-resource-after-arch_remove_me= mory.patch queue-4.19/mm-memory_hotplug-add-nid-parameter-to-arch_remove_memory.patc= h queue-4.19/powerpc-mm-fix-section-mismatch-warning.patch queue-4.19/mm-memory_hotplug-allow-arch_remove_memory-without-config_memo= ry_hotremove.patch queue-4.19/mm-memory_hotplug-make-remove_memory-take-the-device_hotplug_l= ock.patch queue-4.19/mm-memory_hotplug-make-__remove_pages-and-arch_remove_memory-n= ever-fail.patch queue-4.19/mm-memory_hotplug-fix-try_offline_node.patch queue-4.19/mm-memory_hotplug-remove-zone-parameter-from-sparse_remove_one= _section.patch queue-4.19/drivers-base-memory.c-remove-an-unnecessary-check-on-nr_mem_se= ctions.patch queue-4.19/drivers-base-node.c-simplify-unregister_memory_block_under_nod= es.patch queue-4.19/s390x-mm-implement-arch_remove_memory.patch queue-4.19/mm-sparse-pass-nid-instead-of-pgdat-to-sparse_add_one_section.= patch