From patchwork Fri Oct 18 16:17:56 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: 13842036 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 EB89CD30019 for ; Fri, 18 Oct 2024 16:18:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7807D6B0083; Fri, 18 Oct 2024 12:18:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 72FE06B0088; Fri, 18 Oct 2024 12:18:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5AAC46B0089; Fri, 18 Oct 2024 12:18:22 -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 3C5B06B0083 for ; Fri, 18 Oct 2024 12:18:22 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E0AD4121C4F for ; Fri, 18 Oct 2024 16:18:10 +0000 (UTC) X-FDA: 82687230108.23.14CA067 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf03.hostedemail.com (Postfix) with ESMTP id A132F20008 for ; Fri, 18 Oct 2024 16:18:14 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LmuEy8By; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729268180; a=rsa-sha256; cv=none; b=NcI/0vn9Q9w1K9h+Rnd1e8jHDjXqiK25x693f287c2BAQiRW52mDtWhzm5BkIaCFbWIxaM 6BIbuBZKKiczkpiQt3/ZUSSz+XWABMKRVuPSxqOQxeoxlGbHofwzniIbuL85Dj8JjSbjeZ HK8xgm2gtfOgdy3Z+LRlBHWb01yj25Y= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LmuEy8By; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.172 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=1729268180; 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=1OVm1aMfcJH+C5h2HeT9933XrsU2qvy2OkpNXm8z7tg=; b=7onBV3T+Zr6auZC0fh7Lwf98EXURDxGai41DJIx2ApDRxGh737uU1FW8vWiYOwSQskRVEX gUE6rdQPf3zce6qQjj8cFGa86UEAYhwrRO14eo0k2B2ZjkLEY6AdLlk4Fj3YPvC69x2jZu W4wtrOuZhvztIerKGxuH2lIRl8/aS6s= Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-71e579abb99so1646520b3a.2 for ; Fri, 18 Oct 2024 09:18:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729268299; x=1729873099; 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=1OVm1aMfcJH+C5h2HeT9933XrsU2qvy2OkpNXm8z7tg=; b=LmuEy8By3BqhCEYxtafmZ+EHUWXSiJybY+fEKIcI/UZXUlkXey52T5KuBFfZwtc76G 62IsYC0YOPvzl5uHMBjkFTtSZVGgysjDTVfe5wVsU1oygFkNJ7RpDABNf775gkdKsrET 4lp73vRD9HLLd/TVTPxgFWR0AK6DaqZldOhswAehalF0cTHgNgg+DZsm8grGfFI8aSpj 70w+SrBy4PJekhUW+IfargPyTHs5AgluB5rI/6RIlKCTu42SOMvr+FCFlTGtyyuvX+hZ MT0GhfoqZ2Mxi8sf9ISnmHWzEAhoR/ekR6Txm2El8S76wsbFHBgP/UyD9cdJdQ/L7rHf w7Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729268299; x=1729873099; 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=1OVm1aMfcJH+C5h2HeT9933XrsU2qvy2OkpNXm8z7tg=; b=bJshj/cbNWpi1a1/WBzPjuu9vU8fcBg8mInY71IjY/pTX4eudDu2butW7YK+crz9Za YC0zkQErCbLmVtbgB9Goi8Qd3ymIIEnpWt2mgSqYyJqu9nZ64ADx/amDEDPqhEn7T7Ps X1JfGVi0WEzuVMfby8BVc8qy+8yzjMYU6ymCSEfECaMYIhkY+xUQx/cT7M4/qml8ga4W xTD16j4R1nvbaCTIoxKX9wQbsMJqvjGBfN4olvxw9UhG6EQ2aabe5lbC+AkVVfmvmycR mOkxHiA7wo0XOy/Hftsi0xMsA2FH1R7UgKOdikeU8+rzFqUmP9B8MFSOby+N4Xu2fbCc iOhw== X-Gm-Message-State: AOJu0Yyeo6BPYBkknObLhg8kJd+fyJbE7baWbtHRM5omuhv5zI6QNLrk iRDJTUt+WevdMwzrb8lPX5MSAUDZjaUnlQRPdzQotHRN+McsVO/w X-Google-Smtp-Source: AGHT+IFYn+jHU87+CuAdiC2bANQdqGrWOhnXYjaGpsSCpU5oDVmDDYqIstLDV3L6h3hQlUt3per1nw== X-Received: by 2002:a05:6a00:c84:b0:71e:58be:3604 with SMTP id d2e1a72fcca58-71ea31923b9mr4310756b3a.4.1729268298529; Fri, 18 Oct 2024 09:18:18 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ea345677asm1692140b3a.147.2024.10.18.09.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 09:18:17 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: linux-mm@kvack.org, Zi Yan , David Hildenbrand , Sourabh Jain , Hari Bathini , Mahesh J Salgaonkar , Michael Ellerman , Madhavan Srinivasan , "Aneesh Kumar K . V" , Donet Tom , LKML , Sachin P Bappalige , "Ritesh Harjani (IBM)" Subject: [PATCH v4 2/3] powerpc/fadump: Reserve page-aligned boot_memory_size during fadump_reserve_mem Date: Fri, 18 Oct 2024 21:47:56 +0530 Message-ID: <805d6b900968fb9402ad8f4e4775597db42085c4.1729146153.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A132F20008 X-Stat-Signature: b9ypi3sgah98uxp4todfidxj3rrokgx5 X-Rspam-User: X-HE-Tag: 1729268294-310738 X-HE-Meta: U2FsdGVkX1/HeRITAih+9tDu+fA1n+fWzXjAJytrGR3SnfAvq3RlBSQoO8lvEZk8U1N7KIDJJmCWyYrI1Yx5TlHItc8v+txCminTGSTmbRhKNnJl7jnsyk3Vedngo4OgPjX+fiB6Zo/V2RjJhG8ri8xEXtW1oKbslZ/vav806cJspcEaxyT0qhqgh51CVscA/RrI34j4cPH7Oqvg7hPXMqkRrAHgdCd2NvIQOyTtLnXgG5WGD9+c80VEDyAzIGkt2+M+0s4imixLKwXrRzc2VrOxsxDYd1O9plTcYdJgBHAZsgZuJ1capoNjeDyDZaLn4FRSlXoxHqZt6YzBA8IWMnXZ0PENtpHMq/Fo2YGVjMESfk5skiGU/6rtSQtfdbRVUwA2jc5T6dH3WeF7UsNxxUEEYsjE/Uk9huXhcPLaPmVcKwbhzG6X34RZ9FRYSmRKvBSPhxWhy2JPjMKyfL1VM17XYXhDSkIJHrVNCkBRu8RB4aS8dSkh8ctbvBy9pc0vHam7zowBMhLRgW7+skqiLN+UNTdCjHlj9JLoGsRoP4x2bTOSmvjBCvcZQjX2bD99bvxSf0GqBuQqJCpReQ4fBEGvAgEVFSOKoM+zCJaL79Hr6Arrz+OrCuWt0YpBvvA5YWgsC/nJqyovyDCoGT2tWfNULOm540v/aGggpoL7LJct11Rs48DCQpq2oNM3xewPqAoZ58afFJPzBOl6qjH1OJMTvJU9LKrbPxOMYtHFqy7nlDa6pzaYUU7TUsP/G857OqyTLYext+OuMW7eSA3Qbkdh+dmJC75wxzI1B/d2+oY1gQwadyXwoywzYu2dau5SQvq4VPrVCiHDySS/W1SZnYj0knMzlaosUFJ5GYsNUXFXJxQTbUa9ngPWSxFYTd4Kft+1DjDUdq0IYI+7DlktOQtf8oH1AO+vmRBGYj8GSYipPMy6yqjbUDhE65RytAJNEut6zJrMA2EV+4KkaFO j7pQRZ9U RDtskJ2Pwk3693JctXMkPnUn6oBndYXi7q6RyOekrI9zfkor4y6cezetFgoyoea/HUkKpQoEXoqghFkep4Af646tDnR8RDCOfVv2NSc1F/dj1vYAAgSc6jxxy1PcEji+uRrENMMd+UyP5Zy27/v3euXRlEqqKoTLKtYgvB1m4ig53ddasqUzMLeCUiohTD5/Qq/OjnKx7dIbjmtVCP19a4gfAiH6kAJrrwdqicx3LfnTk03S7yMbyk8bF/oAySHjMadEsLLEOQcaeDJz4zPL8qoqmLDSw35Q/HwYNfvSMFog/c3FS9uCEYTYwXSn8OgdPmLJkmQj8mH0M0+/ojCH69snR7g== 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 Reviewed-by: Madhavan Srinivasan Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/kernel/fadump.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) -- 2.46.0 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) {