From patchwork Fri Oct 11 15:00:05 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: 13832629 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 B3BE9D0D7AB for ; Fri, 11 Oct 2024 15:00:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D2A86B00A3; Fri, 11 Oct 2024 11:00:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 182666B00A5; Fri, 11 Oct 2024 11:00:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 049AC6B00A7; Fri, 11 Oct 2024 11:00:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DC82C6B00A3 for ; Fri, 11 Oct 2024 11:00:24 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6F1DC8124F for ; Fri, 11 Oct 2024 15:00:20 +0000 (UTC) X-FDA: 82661632326.03.C0D5043 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf16.hostedemail.com (Postfix) with ESMTP id 010BB180016 for ; Fri, 11 Oct 2024 15:00:19 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bnsVdkPv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728658709; a=rsa-sha256; cv=none; b=Y86RgdmsqkhTE0tqP8P4teUJapXVAuqYdp578STG4+aFKgt9A7kgdNF735Hl6KPmlGs0q/ 0Qy90ULYGNExzdWOiqPt3fvniT5Qkoe8XTcypyQAviodzM1fa8CY93N0cqt1y24E3BAVU/ UbiGnGHgtQHstOXxv6xutDLJD16TyvA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bnsVdkPv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.182 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=1728658709; 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=FOuvgWQlE/foa4I7724xWSn7l3vcksejBT7rSNJjxxM=; b=D0MZrq/gk7zTfesgIkQXSP3UDuP6CYGYVd4SlbMrtai/j9xJM+9ydMwL2o1t6Irki+SUP9 Bbwifi3pgJaWzxOohR62zRVAg/6i7oAHrhcWl4DFU5qKzl5P1kxP/Ct8LvCfgz34QwLtAt 2X56Hw7piLrKweeJfFRTsYg6jDyrUYk= Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-71dec1cf48fso1839009b3a.0 for ; Fri, 11 Oct 2024 08:00:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728658821; x=1729263621; 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=FOuvgWQlE/foa4I7724xWSn7l3vcksejBT7rSNJjxxM=; b=bnsVdkPvckRXc1AxjGPKaAradQ5W9InN726OoAiXAQIbeG27BbWbjs8Dd7kzS8O9fM AQukcUKbLjqAo4pbOczS4vCFwc984aj0pjGQPPvnwC4hrODrzWNS0JyPttlCKTcj5B1x uKNeWa1YgSpWpGFykhZZBzMt5IDD87T6eXY1NoF/9ZTaD/Unqqb0Rjav4UK7APHMmEKV xtIow7yMLi+eII1lFwesx/nIl0K0mYjWEVXivhHdRrXvNRcLchwugHDOu1BAwVASiB2d 4/IL0+jzEYkrE7/LJgNUbOmK1hj/zbOsbcawoQDPz97yPy8S7LkUri4qFx1+xEBgxBZU wyiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728658821; x=1729263621; 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=FOuvgWQlE/foa4I7724xWSn7l3vcksejBT7rSNJjxxM=; b=s8BW+VH6X4NowV0b+KdXpqfDcTVKHYWzG8Ug2BEJtfcPz34FzdLBVvRR+0XOfgyYtS HVksg7ZwnyHZ2aSVSOi4FAWiAmxfihyk8Bz+D4mI/9RS4YPbaBldqYhWnpzlS7AVCYxM XgTyiPyE8vueJt42goeFlm0S1ziJwrbDXPSnMkap+4sk6QWQUWhBSejxsvUCUFGphnb8 GTUF54V0BR0giqkW9Yn1hYaZoEARfBGQ9HFkYM6ISM6phNEDwZgUcMcozgnVSDblfd9h XmQbEE1a2B4+dbbiYu7KARIjMVuidP2hNFpGfH+wUf4/h1oRBUvr999Ubx9HAEI2u+nF hvVw== X-Gm-Message-State: AOJu0Yyz+eNhWrGgosAuH3rfHCA5vdoLlZAFODRQPPZEb4t2qGqWbuqD 7gvD8lXxOh/zxlo3vfGxMh1bP8ILRJQRuErRqBwAj4wXy16pD5RE X-Google-Smtp-Source: AGHT+IG28SN7o4rqiQUvFnUoGcWs4GuDv3GMOcb/mAbo3sv1g27mwrxdu/TPHQf2tYzBTJhSQ+rF+g== X-Received: by 2002:a05:6a00:4fd6:b0:71d:fb10:7d1c with SMTP id d2e1a72fcca58-71e380beb6bmr3997069b3a.26.1728658820768; Fri, 11 Oct 2024 08:00:20 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 08:00:20 -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 2/3] fadump: Reserve page-aligned boot_memory_size during fadump_reserve_mem Date: Fri, 11 Oct 2024 20:30:05 +0530 Message-ID: <32496f6daeb4ed04c772ae484895241ab2ae1da1.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-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 010BB180016 X-Stat-Signature: zbsdj4px1e6ubwjrzhgyiyho4kib43u8 X-Rspam-User: X-HE-Tag: 1728658819-531910 X-HE-Meta: U2FsdGVkX18MZDwe8Z/25DvPZ+DW5TnzjzAkki1MR39yjxHzAe85T5+XA8TGqwOQT2fEJK+hwcnknDXnEKE8tQ7Feh2T6xiWNxQL473B6bPOZzNorGgRrzj6yxxvV8iqyfhPSrvf8Xa1JK1iF/1BN6H5CSbIh8TJYInXktztycNW9FJ1mk81p7MNXtRaTKxBAYuoyLpvLNMEGWLayqlTw1oBGi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tESQSqadEF6di40GbIbssub+g7aSJbp9Bn6EgLvMpM/HMKNM969USW5Z3+NUg67m+qoLUgqiNRDjBv9A0nz1tRyvQffVomd0FDWOGh/44Mwj8RUGDgU3bb8a4ThPKzhj8fQRdi5WVqgRk3DO4VAUPwz1zdcjZ+OTjYxWzuUeD2+XZSxp9p4eTW+owztVr9O1hQOB8l70d2ZsxECidl3etxLvh5Oh1IkpS4cIE75cfvjxD8sBYZAUvBY2Y= 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: This patch refactors all CMA related initialization and alignment code to within fadump_cma_init() which gets called in the end. This also means that we keep [reserve_dump_area_start, boot_memory_size] page aligned during fadump_reserve_mem(). Then later in fadump_cma_init() we extract the aligned chunk and provide it to CMA. This inherently also fixes an issue in the current code where the reserve_dump_area_start is not aligned when the physical memory can have holes and the suitable chunk starts at an unaligned boundary. After this we should be able to call fadump_cma_init() independently later in setup_arch() where pageblock_order is non-zero. Suggested-by: Sourabh Jain Acked-by: Hari Bathini Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/kernel/fadump.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c index 162327d66982..ffaec625b7a8 100644 --- a/arch/powerpc/kernel/fadump.c +++ b/arch/powerpc/kernel/fadump.c @@ -80,7 +80,7 @@ static struct cma *fadump_cma; */ static void __init fadump_cma_init(void) { - unsigned long long base, size; + unsigned long long base, size, end; int rc; if (!fw_dump.fadump_supported || !fw_dump.fadump_enabled || @@ -92,8 +92,24 @@ static void __init fadump_cma_init(void) if (fw_dump.nocma || !fw_dump.boot_memory_size) return; + /* + * [base, end) should be reserved during early init in + * fadump_reserve_mem(). No need to check this here as + * cma_init_reserved_mem() already checks for overlap. + * Here we give the aligned chunk of this reserved memory to CMA. + */ base = fw_dump.reserve_dump_area_start; size = fw_dump.boot_memory_size; + end = base + size; + + base = ALIGN(base, CMA_MIN_ALIGNMENT_BYTES); + end = ALIGN_DOWN(end, CMA_MIN_ALIGNMENT_BYTES); + size = end - base; + + if (end <= base) { + pr_warn("%s: Too less memory to give to CMA\n", __func__); + return; + } rc = cma_init_reserved_mem(base, size, 0, "fadump_cma", &fadump_cma); if (rc) { @@ -116,11 +132,12 @@ static void __init fadump_cma_init(void) /* * So we now have successfully initialized cma area for fadump. */ - pr_info("Initialized 0x%lx bytes cma area at %ldMB from 0x%lx " + pr_info("Initialized [0x%llx, %luMB] cma area from [0x%lx, %luMB] " "bytes of memory reserved for firmware-assisted dump\n", - cma_get_size(fadump_cma), - (unsigned long)cma_get_base(fadump_cma) >> 20, - fw_dump.reserve_dump_area_size); + cma_get_base(fadump_cma), cma_get_size(fadump_cma) >> 20, + fw_dump.reserve_dump_area_start, + fw_dump.boot_memory_size >> 20); + return; } #else static void __init fadump_cma_init(void) { } @@ -553,13 +570,6 @@ int __init fadump_reserve_mem(void) if (!fw_dump.dump_active) { fw_dump.boot_memory_size = PAGE_ALIGN(fadump_calculate_reserve_size()); -#ifdef CONFIG_CMA - if (!fw_dump.nocma) { - fw_dump.boot_memory_size = - ALIGN(fw_dump.boot_memory_size, - CMA_MIN_ALIGNMENT_BYTES); - } -#endif bootmem_min = fw_dump.ops->fadump_get_bootmem_min(); if (fw_dump.boot_memory_size < bootmem_min) {