From patchwork Fri Oct 11 07:23:12 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: 13832171 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 BD588CFC5FB for ; Fri, 11 Oct 2024 07:23:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4259C6B009F; Fri, 11 Oct 2024 03:23:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AE4B6B00A0; Fri, 11 Oct 2024 03:23:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 228196B00A1; Fri, 11 Oct 2024 03:23:52 -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 F36456B009F for ; Fri, 11 Oct 2024 03:23:51 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2A91180E60 for ; Fri, 11 Oct 2024 07:23:48 +0000 (UTC) X-FDA: 82660481862.28.A59EF28 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf30.hostedemail.com (Postfix) with ESMTP id 2535C80007 for ; Fri, 11 Oct 2024 07:23:45 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IU0Lhsrr; spf=pass (imf30.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728631385; 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=43KeZkjM4JRDWlxAgOLwxp7bBo4Ct6yjaya1Z8Z5TnE=; b=4YYeFGmXibjUGvkP41q01/mhRSDf1mXK94Lx0pbI7bcpgDOe5E6//s6tddloueurDqOndV 0xt81AV7AmzJB3Ck7uNh8g/7PRdqDi9BdjqybWBu9fNA6Tr2BNjFypNxhJ8lFO2ab9LMyH jjnQIGdGq7F1d/mHW3zDNzkF/7y8aao= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IU0Lhsrr; spf=pass (imf30.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728631385; a=rsa-sha256; cv=none; b=x1zSqo5JLObb/FtZAg+ro7+sCNs2UZW36/aF4S/Q+XVEzJIIf0dKj7W0+gLfvuXdfaJkjn kjw0hWUqPeDeimU/ayIZH8Tm8APrH8CkEpGakIegzrrqRUg3SjYPIaqVve94l2bS2uYHco UZJ62rmoNuFNMhwpfMRhfRKE5rPUGpo= Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-20b9b35c7c7so11569705ad.1 for ; Fri, 11 Oct 2024 00:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728631429; x=1729236229; 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=43KeZkjM4JRDWlxAgOLwxp7bBo4Ct6yjaya1Z8Z5TnE=; b=IU0LhsrrbncJlRyIDcAITWYg0A6gknnHfg3REkEIKZIXX4vkjEXeYCr/WV4nJ7vEFl 60knVd3NIet0vjvCXABFVzfgRDXt7wyjYuVEpxBmPKW76KBSJD6V2sfF3ZyyIO7A7b+Z V7bRtVi0NnSGq/Jffa5bpHA/S2Mg0BJQ7kHCl2JMNUw+S3ZzOb6GK0WgJey0lHJNYeOO GyqRBUeS7qmfztwL/ZjiDkMkffw3E+nvN5C6WLwSwUj4G0PoHI/cbThIMXG3szNsu6F1 Buf688kv5Hk/4CSaYw5ADvWoMXMTjs16bCjnJb9b5DKjV7dPNqzLJiOiHU90MdSAQIMa 7gxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728631429; x=1729236229; 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=43KeZkjM4JRDWlxAgOLwxp7bBo4Ct6yjaya1Z8Z5TnE=; b=Gv295gLmr1GLnVrAKKNYOZ1qzwdlP4tpz7GhG1KaPRl58rIAGtx2d4d7frotEnDxx+ VRQseCvjokEtpZl/Q4HstE6pFiCnaOIVibeBYl3is1z1Yq8dcwdxdrEt1p3BrJm7dHCY DCU3ziJvnYqjKeKxMSja9sdmp0rm7KqcbhQ2j5JbAK7pAmVrbkC5E18CEOqcxIe8f1Rr SrBP68UvyVbuN1myHvuUs06vlV6z4x7Uzkz6JYoeaA6FBLbnibnMgKTCZR96Qt02QPoB za/fjNaF+aWD/9ZCwVkmNuM6Mi7XCSKb0ABgBbIieZXe+ca/sDiHACfWU+UTEUlklWOu L7Fw== X-Gm-Message-State: AOJu0YzUNjLJAsR+ShcvZjQOovCIYr4vnOcN81MdXwWTWjfZxFDQD5LE OlBG5b3B7N9hHGhWoqsihCwJt6CEehCU5qv7e1wnjMK7zc7RoQJ8 X-Google-Smtp-Source: AGHT+IHvKjtMrFH1g3CLZPdSwjhTqkQHVaREuW1zEqrR1VLtKD+N3w5sn140uSYgK0zgLCGlE26s+w== X-Received: by 2002:a17:903:228b:b0:20b:fa34:7325 with SMTP id d9443c01a7336-20ca16c5acfmr22757985ad.43.1728631428668; Fri, 11 Oct 2024 00:23:48 -0700 (PDT) Received: from dw-tp.ibmuc.com ([49.205.218.89]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c8bad335dsm18825155ad.50.2024.10.11.00.23.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 00:23:48 -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 v2 4/4] fadump: Move fadump_cma_init to setup_arch() after initmem_init() Date: Fri, 11 Oct 2024 12:53:12 +0530 Message-ID: <819b34cc6dd63e21f142c1adbc1a88bc57f3db54.1728585512.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: hxkac47fdjw3bicdnwm3oeniwxg4i356 X-Rspamd-Queue-Id: 2535C80007 X-Rspamd-Server: rspam11 X-HE-Tag: 1728631425-997189 X-HE-Meta: U2FsdGVkX1/FLfraOJzIAP+/DjCnleFatI8fZ7R+UWMScMEnXYTnidl9BtNfqnzQ0HhgEEjnQbQAA/tlhtP6oOYm5OBkwpNiVIdtQoDnXArgUJ4wRyPUvtjfkBVIwystGmo0mSw8a3ZRjz1Qe1A/QIN3vxYMAFNE+tZKaD20bv3U76o/dnwPAS1eVSGqY2bA3Sn/xV2vt/+pTzO2+wYLaXRfnKX6PU0FeGGR6l0SeSzZ8wpD0NsS3yDK3QodAzdEkwsaiSADku7Nd8e/HN/ByNYLC5EnG1r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bSkgwp5E5wLtnpH7V9v5sAZhfw6xcntM9N7MMLQZ97M42NXx5+ksjIPUB/s909MOL+biCVEgYHfkeNObSsIYBnUGSUw7VUdqrqN9kXeNzFjOGjkfrFBFm52bmgEp9NyEkaVfRJeIjt02EK86fzCd9iST3qNCZUYZy7uBBIu8gviScmm432ja65HCHbDndloYt1cwJzO3cJUCgcorknLgqtUK+E 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 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(-) -- 2.46.0 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 943430077375..b6b01502e504 100644 --- a/arch/powerpc/kernel/setup-common.c +++ b/arch/powerpc/kernel/setup-common.c @@ -997,9 +997,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();