From patchwork Tue Oct 8 13:27:18 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: 13826481 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 0C23ACEF173 for ; Tue, 8 Oct 2024 13:27:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9022A6B0083; Tue, 8 Oct 2024 09:27:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B1FB6B0085; Tue, 8 Oct 2024 09:27:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 779CE6B0088; Tue, 8 Oct 2024 09:27:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5A7F56B0083 for ; Tue, 8 Oct 2024 09:27:42 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id ED94414123B for ; Tue, 8 Oct 2024 13:27:40 +0000 (UTC) X-FDA: 82650512322.12.86A27F7 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by imf04.hostedemail.com (Postfix) with ESMTP id 117214000F for ; Tue, 8 Oct 2024 13:27:39 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JM7qbQqF; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.215.171 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728394017; a=rsa-sha256; cv=none; b=8Xn69ifPRu+aPx+Un7iJscgYl4JnbyT7wM9IoaYsy08fdDCfTKBo3PuXvNqUhp6mJUXMa3 LZYZK8t5gdxRBuoVTRISfJsYYslN6E7fkzH1aS6m0/sPstnexwGL5lDIjeM+nlbFh53+m5 SqfHFZQVVvzVigR+L8JDEpqJ+Ag8U6E= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JM7qbQqF; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.215.171 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=1728394017; 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:references:dkim-signature; bh=GNRTK4GY4M/5SnKSdR40yf4xxmnZc4ktxUmJ5/TaZVA=; b=i3fj+HPL8PM6hXVVPRkobZpyzdNX84msH5PBTCfcP++T87Ph5y6+RLzjf1M+wwLD2oQGkw opGEZW0fMPGTVO5GFZl2nsP8UJYOHrkfff0mLo7m+ceAwVtqYiXFVonSy0+qxG5WcapQ9h bwAMQPTRWuPtUzb/cCB/dzg2MptZgwQ= Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-7c3e1081804so2651507a12.3 for ; Tue, 08 Oct 2024 06:27:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728394059; x=1728998859; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=GNRTK4GY4M/5SnKSdR40yf4xxmnZc4ktxUmJ5/TaZVA=; b=JM7qbQqFmu6CBA6J8Ilg5b0NYukMW/p2JBKmMjY/5abr4Y5/u5oJoMjrgql5Klt9H0 c5PZeWMEpOWYNxbOA+9Lh9bPWL/tnc5KnVqVOk9qspwZoe3FQWyEPMmQA1kSgUfEZTj9 bz6Lg7SEp3tkYmeezlhB8fMUHOFugvJ58fZ+YHJ26ksOX8tr10olBW5jrnUprXUdjcuy drVKvuexoVaBPczEsFnJ57CAOu6vMze7hK78tGgm0oLez2mMyhioX8TOOc4W6fPO4bYn Jk8pOcLd9bWaCBL6LSdyr/1nEDO2AhmAEpwWclOx5NugBCssbjmTX0xKLidQ1EHZqLiF W62A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728394059; x=1728998859; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GNRTK4GY4M/5SnKSdR40yf4xxmnZc4ktxUmJ5/TaZVA=; b=X0uz2P5scE1bALN1kI1axiq+MyuQPqaChP3hWVhj0yjVV810qu3gitFql+EJ+lhAnG N1WA9xG1N+l881YYvDEahmM4SVhw2DmKWneWt/OHydNHHjTAW40RFXxrWYNzixlDqMkM pjf7qmJ6L//c39eDlMULSnopp5wngfShxenRoMaQGhDSuqfwSNMs7QkuT4ayxrijbiwt JMWaRihlBAamHuNeaBQ6SV6lwardhPirxkcdHhU2FuiXjgng8d8Rit3rJ+iDM8FHkCJS XYUYACJvnh942zhrS4ByKM8Vh3glYOcKxXCbc23X1SYJbZqgZKjy7rX3AFn/dt7ePSVi 45NQ== X-Gm-Message-State: AOJu0YwIXTaY7p8IhaGhOdGbEkx57pyxGpQLbirfOOx1WRvOrzshjESr ob8ssbQD/e0T2GkPs2SnZyt7rNnT6eJoPAmf6yEUi0+v5ccWW9D2 X-Google-Smtp-Source: AGHT+IEPBSY9n6qD6ZyvnmB52+tWd6fPMTLLVgOtWzgpTHXZv6NjkRb9kArISqSlxpL+qPUzVtYrRA== X-Received: by 2002:a05:6a20:c886:b0:1cc:da34:585e with SMTP id adf61e73a8af0-1d6dfaee214mr21301979637.46.1728394058567; Tue, 08 Oct 2024 06:27:38 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.87.188]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e20af4655dsm7628992a91.27.2024.10.08.06.27.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 06:27:37 -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 , "Ritesh Harjani (IBM)" , Sachin P Bappalige Subject: [RFC 1/2] cma: Fix CMA_MIN_ALIGNMENT_BYTES during early_init Date: Tue, 8 Oct 2024 18:57:18 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 117214000F X-Rspamd-Server: rspam01 X-Stat-Signature: pbhnae3qgqdr5h7j8x6r99krgiywgtgc X-HE-Tag: 1728394059-329132 X-HE-Meta: U2FsdGVkX1881/zcvFdOda2NR19ACGLt5tumQxYnimiyYMPn03WgamREGe6lUT+N31sq/oPowbGo5GGjhdMmDASelEvUDgLjeb30teC6365b692/VULJqGPr2kn2AgVTaKCFe0WYRiDZaDOau6mhg/Sghiok2UmOvvmR5tko5Ius8LotIpwmHHr6x3cyBfSKFSLGgyBYjDF6axHhxhScADxFz0fhN5szdnC5H0+GSJmUpDf5FXg4+ftCMYJs2AaAdpbNDW2xSRwbbNI7AEVEt+Antg5NPJeIXKdoxS0c+2rOD4ccEfak/H4FY8hKgPH3FlqNIdClk5aAJ9dCISzGCzraOb/mJQSxVJK2JlFgnyQ/qND80FSgi655/JQKN/ncwHaWflCOMKJoCqbe7fqz4WMXUtGM2NhYBvoyy3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XWTpi/12cwIc+diDuaN4feiQWzs1w/F4l0RQsvOY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000031, 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 paging_init() e.g. paging_init() -> free_area_init() -> set_pageblock_order(). One such use case is - early_setup() -> early_init_devtree() -> fadump_reserve_mem() 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. Instead of fixing it locally for fadump case on PowerPC, I believe this should be fixed for CMA_MIN_ALIGNMENT_BYTES. ============== 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 Reported-by: Sachin P Bappalige Signed-off-by: Ritesh Harjani (IBM) --- include/linux/cma.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.46.0 diff --git a/include/linux/cma.h b/include/linux/cma.h index 9db877506ea8..20abc6561bcd 100644 --- a/include/linux/cma.h +++ b/include/linux/cma.h @@ -5,6 +5,7 @@ #include #include #include +#include #ifdef CONFIG_CMA_AREAS #define MAX_CMA_AREAS CONFIG_CMA_AREAS @@ -17,7 +18,8 @@ * -- can deal with only some pageblocks of a higher-order page being * MIGRATE_CMA, we can use pageblock_nr_pages. */ -#define CMA_MIN_ALIGNMENT_PAGES pageblock_nr_pages +#define CMA_MIN_ALIGNMENT_PAGES \ + (1ULL << min_not_zero(MAX_PAGE_ORDER, pageblock_order)) #define CMA_MIN_ALIGNMENT_BYTES (PAGE_SIZE * CMA_MIN_ALIGNMENT_PAGES) struct cma;