From patchwork Sat Jun 5 03:01:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12301151 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=-14.2 required=3.0 tests=BAYES_00,DATE_IN_PAST_03_06, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 A8DA3C47082 for ; Sat, 5 Jun 2021 06:06:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 405F06024A for ; Sat, 5 Jun 2021 06:06:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 405F06024A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DA20E6B0078; Sat, 5 Jun 2021 02:06:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D78F06B007B; Sat, 5 Jun 2021 02:06:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1A016B007D; Sat, 5 Jun 2021 02:06:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0156.hostedemail.com [216.40.44.156]) by kanga.kvack.org (Postfix) with ESMTP id 904926B0078 for ; Sat, 5 Jun 2021 02:06:48 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 27E721DE7 for ; Sat, 5 Jun 2021 06:06:48 +0000 (UTC) X-FDA: 78218636496.01.E2794D9 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf28.hostedemail.com (Postfix) with ESMTP id 6883D200291B for ; Sat, 5 Jun 2021 06:06:35 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id BDF4761403; Sat, 5 Jun 2021 03:01:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1622862085; bh=e0AWlECXHw26Zo1vEyB7QPq7XtcTfEtmAsD1HG1t80E=; h=Date:From:To:Subject:In-Reply-To:From; b=wKmIADuyBc1mdAR1Voelu6gRnamuYucF1RCwUeZ33tnKJVnR8y4IuG7dkdRGPUc8y JKKFGOP+LHVRVlVH0/K1oNPMsuv6uyGuVXNtak+o0QKFy20InUTgY3sTl4f2QspY/6 AsjbzT5ASPp5g+2METTC3qjMM9A3bdk3AtYQGdkw= Date: Fri, 04 Jun 2021 20:01:24 -0700 From: Andrew Morton To: akpm@linux-foundation.org, anshuman.khandual@arm.com, david@redhat.com, linux-mm@kvack.org, mhocko@suse.com, mm-commits@vger.kernel.org, osalvador@suse.de, quic_qiancai@quicinc.com, rppt@kernel.org, torvalds@linux-foundation.org Subject: [patch 06/13] drivers/base/memory: fix trying offlining memory blocks with memory holes on aarch64 Message-ID: <20210605030124.YGvVrHxno%akpm@linux-foundation.org> In-Reply-To: <20210604200040.d8d0406caf195525620c0f3d@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6883D200291B Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=wKmIADuy; dmarc=none; spf=pass (imf28.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Stat-Signature: a8pfxnrzb3cogud8847acgcj7xyans5i X-HE-Tag: 1622873195-262679 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: From: David Hildenbrand Subject: drivers/base/memory: fix trying offlining memory blocks with memory holes on aarch64 offline_pages() properly checks for memory holes and bails out. However, we do a page_zone(pfn_to_page(start_pfn)) before calling offline_pages() when offlining a memory block. We should not unconditionally call page_zone(pfn_to_page(start_pfn)) on aarch64 in offlining code, otherwise we can trigger a BUG when hitting a memory hole: [ 162.327720][ T1694] kernel BUG at include/linux/mm.h:1383! [ 162.333695][ T1694] Internal error: Oops - BUG: 0 [#1] SMP [ 162.339181][ T1694] Modules linked in: loop processor efivarfs ip_tables x_tables ext4 mbcache jbd2 dm_mod igb nvme i2c_algo_bit mlx5_core i2c_core nvme_core firmware_class [ 162.354604][ T1694] CPU: 13 PID: 1694 Comm: ranbug Not tainted 5.12.0-next-20210524+ #4 [ 162.362601][ T1694] Hardware name: MiTAC RAPTOR EV-883832-X3-0001/RAPTOR, BIOS 1.6 06/28/2020 [ 162.371116][ T1694] pstate: 60000005 (nZCv daif -PAN -UAO -TCO BTYPE=--) [ 162.377811][ T1694] pc : memory_subsys_offline+0x1f8/0x250 [ 162.383295][ T1694] lr : memory_subsys_offline+0x1f8/0x250 [ 162.388773][ T1694] sp : ffff80002458f8e0 [ 162.392773][ T1694] x29: ffff80002458f8e0 x28: ffff800010914d30 x27: 0000000000000000 [ 162.400602][ T1694] x26: 0000000000002000 x25: 1fffe00002550401 x24: ffff000012a82008 [ 162.408431][ T1694] x23: fffffc0000000000 x22: 0000000000008000 x21: 0000000000000001 [ 162.416259][ T1694] x20: ffffffffffffffff x19: ffff000012a82018 x18: ffff0008527b6a70 [ 162.424086][ T1694] x17: 0000000000000000 x16: 0000000000000007 x15: 00000000000000c8 [ 162.431914][ T1694] x14: 0000000000000000 x13: ffff800011c6eea4 x12: ffff60136ceb8574 [ 162.439742][ T1694] x11: 1fffe0136ceb8573 x10: ffff60136ceb8573 x9 : dfff800000000000 [ 162.447570][ T1694] x8 : ffff009b675c2b9b x7 : 0000000000000001 x6 : ffff009b675c2b98 [ 162.455398][ T1694] x5 : 00009fec93147a8d x4 : ffff009b675c2b98 x3 : 1fffe0010a4f6c09 [ 162.463226][ T1694] x2 : 0000000000000000 x1 : 0000000000000000 x0 : 0000000000000034 [ 162.471054][ T1694] Call trace: [ 162.474186][ T1694] memory_subsys_offline+0x1f8/0x250 [ 162.479318][ T1694] device_offline+0x154/0x1d8 [ 162.483844][ T1694] online_store+0xa4/0x118 [ 162.488107][ T1694] dev_attr_store+0x44/0x78 [ 162.492457][ T1694] sysfs_kf_write+0xe8/0x138 [ 162.496896][ T1694] kernfs_fop_write_iter+0x26c/0x3d0 [ 162.502028][ T1694] new_sync_write+0x2bc/0x4f8 [ 162.506552][ T1694] vfs_write+0x718/0xc88 [ 162.510643][ T1694] ksys_write+0xf8/0x1e0 [ 162.514732][ T1694] __arm64_sys_write+0x74/0xa8 [ 162.519342][ T1694] invoke_syscall.constprop.0+0x78/0x1e8 [ 162.524824][ T1694] do_el0_svc+0xe4/0x298 [ 162.528914][ T1694] el0_svc+0x20/0x30 [ 162.532658][ T1694] el0_sync_handler+0xb0/0xb8 [ 162.537181][ T1694] el0_sync+0x178/0x180 [ 162.541187][ T1694] Code: f00033e1 91318021 91090021 97e38d8b (d4210000) [ 162.547968][ T1694] ---[ end trace 2a1964462a219f20 ]--- [ 162.553273][ T1694] Kernel panic - not syncing: Oops - BUG: Fatal exception [ 162.560250][ T1694] SMP: stopping secondary CPUs [ 162.564871][ T1694] Kernel Offset: disabled [ 162.569045][ T1694] CPU features: 0x00000251,20000846 [ 162.574089][ T1694] Memory Limit: none [ 162.577849][ T1694] ---[ end Kernel panic - not syncing: Oops - BUG: Fatal exception ]--- If nr_vmemmap_pages is set, we know that we are dealing with hotplugged memory that doesn't have any holes. So call page_zone(pfn_to_page(start_pfn)) only when really necessary -- when nr_vmemmap_pages is set and we actually adjust the present pages. Link: https://lkml.kernel.org/r/20210526075226.5572-1-david@redhat.com Fixes: a08a2ae34613 ("mm,memory_hotplug: allocate memmap from the added memory range") Signed-off-by: David Hildenbrand Reported-by: Qian Cai (QUIC) Reviewed-by: Oscar Salvador Acked-by: Michal Hocko Cc: Anshuman Khandual Cc: Mike Rapoport Signed-off-by: Andrew Morton --- drivers/base/memory.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/base/memory.c~drivers-base-memory-fix-trying-offlining-memory-blocks-with-memory-holes-on-aarch64 +++ a/drivers/base/memory.c @@ -218,14 +218,14 @@ static int memory_block_offline(struct m struct zone *zone; int ret; - zone = page_zone(pfn_to_page(start_pfn)); - /* * Unaccount before offlining, such that unpopulated zone and kthreads * can properly be torn down in offline_pages(). */ - if (nr_vmemmap_pages) + if (nr_vmemmap_pages) { + zone = page_zone(pfn_to_page(start_pfn)); adjust_present_page_count(zone, -nr_vmemmap_pages); + } ret = offline_pages(start_pfn + nr_vmemmap_pages, nr_pages - nr_vmemmap_pages);