From patchwork Fri Oct 11 15:00:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 13832630 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF4D0D0D7B3 for ; Fri, 11 Oct 2024 15:00:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 506946B00A7; Fri, 11 Oct 2024 11:00:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B6396B00A9; Fri, 11 Oct 2024 11:00:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A5AA6B00AA; Fri, 11 Oct 2024 11:00:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1AF796B00A7 for ; Fri, 11 Oct 2024 11:00:29 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DC0691A0E12 for ; Fri, 11 Oct 2024 15:00:20 +0000 (UTC) X-FDA: 82661632494.11.3D6E0D7 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf21.hostedemail.com (Postfix) with ESMTP id D5B431C0029 for ; Fri, 11 Oct 2024 15:00:21 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UUm5Xu37; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728658782; a=rsa-sha256; cv=none; b=G3v5aF/wJahYbhAsiuvMRnnjn/3zCD5MuOg9G98jRAGleJoYv3BaISHzuw/2QMyJC9ztbX XEBR008QtzqeI9LjhvYwkQea4c6ThTfoJarSthA9BG+xO1w35zOT+Ers6L3k05sh0J3ZXN OPGOOIwJNfV/QsS8s3EZ4JCuqhyYm+0= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UUm5Xu37; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728658782; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SU6Z8cvJobq05V76diaI6hL+YRyehnIANBYxgVSeFp8=; b=046MBlXDgLx6qAM6oyvkDLehtkOe60xOfy5xLXF6mmZli0j28aZOjk1HfwkpCSVR/aXcwG ehN3IfFLPEp+WpTYa4rTEf0jH6wmcat8UXUY8o4w3ym0YPLHU9hxmVYFsb/lzFn0AwI7qP WK59L6Znj88it91ZHNuEwAlGAoHy85c= Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-71e03be0d92so1789449b3a.3 for ; Fri, 11 Oct 2024 08:00:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728658825; x=1729263625; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SU6Z8cvJobq05V76diaI6hL+YRyehnIANBYxgVSeFp8=; b=UUm5Xu37QtVJkz05F8UKvwM8U14Orf7dhfrZp9lCgsEqUzXv0miijWF3SCEAWRsxKw 6FXWhB1eXxFTVnkNQBdAdriiGu2M019aMUnXVnaLYl96Zyy1DCNztnKx+LGkdwW6eape QztLwGAnZpDPteWExBa+Qrkt4kSpLx4/4ftVZ0yTr+G8Na+e5OtYDbuBJA3QCPIV893K hPQTQ8HkIK9rbpa0q004emsIJSZwYiDTdu3lBi8KgrGTgIRXyuse5vfZVTYSKkCFjObZ s5HERBcdmnb9I6C7BlwfPfYOUIcPRDVah4dQ4LAkgSQZc8cY+mgglSzbsp6qzKFI7IXV MVmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728658825; x=1729263625; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SU6Z8cvJobq05V76diaI6hL+YRyehnIANBYxgVSeFp8=; b=HAwpmitDDqt7gWePDw94tBQEp2I3LARL2lsTtEksnZsVTjF8O+BPr2wZVthGIXzBPi LDm/KmKuY1cSHVNzPd2SvhtnD+6AiiafNIUcT7NyvUVYqassoe5Fq3tb8vXBfZjTxm/K 9qhTNZKdr8EEUbPZwFFBE/IWDtGQX8tR9ph5rH/OGTsAW15nvWyVi3U/VxbeU23KLlyq ycqSjXxQ7Lyjflry4pbbOPWPWSRacSi3/97jlWFixNoETmq/rZ6+wATc9c/TMXSrPTtc kvWqMRDNzDuhIjuLKWKHEt0fjF92AQ7R0gesJjUhhF7wEvT1eaDnXxTTEKGS/O8Q4mJr 7xGw== X-Gm-Message-State: AOJu0YyAT4Q7LzkS9tLIVMq9+oGJlk6XeAv5MghExpqTclUu9tS9Iwa2 5tRFNj3oZgbiMcwsfvD7ONdHSF7F7UYHNe6pm35k4o1b0CXvn1TJ X-Google-Smtp-Source: AGHT+IHIUtDDWU1ylOOcQb4+U5VINFQKXV7ELQ0WwbOcryePVBd3VxH1zwAA7jKr8WsXcEzg2aapfg== X-Received: by 2002:a05:6a00:1941:b0:710:5848:8ae1 with SMTP id d2e1a72fcca58-71e37e28ad2mr5574776b3a.4.1728658825459; Fri, 11 Oct 2024 08:00:25 -0700 (PDT) Received: from dw-tp.. ([171.76.85.106]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e4a2c9767sm146561b3a.85.2024.10.11.08.00.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 08:00:24 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: linux-mm@kvack.org, Sourabh Jain , Hari Bathini , Zi Yan , David Hildenbrand , "Kirill A . Shutemov" , Mahesh J Salgaonkar , Michael Ellerman , Madhavan Srinivasan , "Aneesh Kumar K . V" , Donet Tom , LKML , Sachin P Bappalige , "Ritesh Harjani (IBM)" Subject: [RFC v3 3/3] fadump: Move fadump_cma_init to setup_arch() after initmem_init() Date: Fri, 11 Oct 2024 20:30:06 +0530 Message-ID: <759d0fc37d9fedca6cfe78ea7061447ecbf1bc77.1728658614.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <030b6d46fddac126a6cf7e119bea48055338f0ed.1728658614.git.ritesh.list@gmail.com> References: <030b6d46fddac126a6cf7e119bea48055338f0ed.1728658614.git.ritesh.list@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: D5B431C0029 X-Rspamd-Server: rspam01 X-Stat-Signature: t1m3e87rjhc5osty3aijphxpqn8riz33 X-HE-Tag: 1728658821-412195 X-HE-Meta: U2FsdGVkX1+bTfF6PWJynNPDdiyMFkTxX8mPl2J+GhhfxD370vtnAPEkMWyCtb3J0V1+9xd/RwzFNuT8zmL//P+tkdntIjnaRIMhRX0TK30Gbg8sIJa0O58k71wU2twVY+FtEUNSQocG7LErGeXXeHobYtoQm+aEXpiJ4N8Dq905+rAOJhCXDNRkHAir4CDW/B1A37Px+XtyfzgI6o2RhKCM4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0+abH0odbdELx9crbysF6+m3t4Mf6bCcmETF5NDD+oa5tPBFbDnLm5bGzN5NnQ4Vpr47Pqw5gm5Og/2WT+IZ0rOL5l9iR4qM20tLN8unhT1M6EqxZndNjMGDCGJqkcs+dVq9WZH/FjbC8sExrIBoavB3zdlV3HvIJp3aAnPciTF04WRQYKZPFo196WFiBZGcZ6HuhZpeu51UszujfNdEjSca8pfD5d0FPERgrzz8QumOD14NY8n5EHdPJ6NkY2x4vT+pgMYDxUnuNHjp9j 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: List-Subscribe: List-Unsubscribe: During early init CMA_MIN_ALIGNMENT_BYTES can be PAGE_SIZE, since pageblock_order is still zero and it gets initialized later during initmem_init() e.g. setup_arch() -> initmem_init() -> sparse_init() -> set_pageblock_order() One such use case where this causes issues is - early_setup() -> early_init_devtree() -> fadump_reserve_mem() -> fadump_cma_init() This causes CMA memory alignment check to be bypassed in cma_init_reserved_mem(). Then later cma_activate_area() can hit a VM_BUG_ON_PAGE(pfn & ((1 << order) - 1)) if the reserved memory area was not pageblock_order aligned. Fix it by moving the fadump_cma_init() after initmem_init(), where other such cma reservations also gets called. ============== page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10010 flags: 0x13ffff800000000(node=1|zone=0|lastcpupid=0x7ffff) CMA raw: 013ffff800000000 5deadbeef0000100 5deadbeef0000122 0000000000000000 raw: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: VM_BUG_ON_PAGE(pfn & ((1 << order) - 1)) ------------[ cut here ]------------ kernel BUG at mm/page_alloc.c:778! Call Trace: __free_one_page+0x57c/0x7b0 (unreliable) free_pcppages_bulk+0x1a8/0x2c8 free_unref_page_commit+0x3d4/0x4e4 free_unref_page+0x458/0x6d0 init_cma_reserved_pageblock+0x114/0x198 cma_init_reserved_areas+0x270/0x3e0 do_one_initcall+0x80/0x2f8 kernel_init_freeable+0x33c/0x530 kernel_init+0x34/0x26c ret_from_kernel_user_thread+0x14/0x1c Fixes: 11ac3e87ce09 ("mm: cma: use pageblock_order as the single alignment") Suggested-by: David Hildenbrand Reported-by: Sachin P Bappalige Acked-by: Hari Bathini Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/include/asm/fadump.h | 7 +++++++ arch/powerpc/kernel/fadump.c | 6 +----- arch/powerpc/kernel/setup-common.c | 6 ++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/include/asm/fadump.h b/arch/powerpc/include/asm/fadump.h index ef40c9b6972a..3638f04447f5 100644 --- a/arch/powerpc/include/asm/fadump.h +++ b/arch/powerpc/include/asm/fadump.h @@ -34,4 +34,11 @@ extern int early_init_dt_scan_fw_dump(unsigned long node, const char *uname, int depth, void *data); extern int fadump_reserve_mem(void); #endif + +#if defined(CONFIG_FA_DUMP) && defined(CONFIG_CMA) +void fadump_cma_init(void); +#else +static inline void fadump_cma_init(void) { } +#endif + #endif /* _ASM_POWERPC_FADUMP_H */ diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c index ffaec625b7a8..c42f89862893 100644 --- a/arch/powerpc/kernel/fadump.c +++ b/arch/powerpc/kernel/fadump.c @@ -78,7 +78,7 @@ static struct cma *fadump_cma; * But for some reason even if it fails we still have the memory reservation * with us and we can still continue doing fadump. */ -static void __init fadump_cma_init(void) +void __init fadump_cma_init(void) { unsigned long long base, size, end; int rc; @@ -139,8 +139,6 @@ static void __init fadump_cma_init(void) fw_dump.boot_memory_size >> 20); return; } -#else -static void __init fadump_cma_init(void) { } #endif /* CONFIG_CMA */ /* @@ -642,8 +640,6 @@ int __init fadump_reserve_mem(void) pr_info("Reserved %lldMB of memory at %#016llx (System RAM: %lldMB)\n", (size >> 20), base, (memblock_phys_mem_size() >> 20)); - - fadump_cma_init(); } return ret; diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c index 4bd2f87616ba..9f1e6f2e299e 100644 --- a/arch/powerpc/kernel/setup-common.c +++ b/arch/powerpc/kernel/setup-common.c @@ -996,9 +996,11 @@ void __init setup_arch(char **cmdline_p) initmem_init(); /* - * Reserve large chunks of memory for use by CMA for KVM and hugetlb. These must - * be called after initmem_init(), so that pageblock_order is initialised. + * Reserve large chunks of memory for use by CMA for fadump, KVM and + * hugetlb. These must be called after initmem_init(), so that + * pageblock_order is initialised. */ + fadump_cma_init(); kvm_cma_reserve(); gigantic_hugetlb_cma_reserve();