From patchwork Fri Oct 11 07:23:11 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: 13832170 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 C911BCEDDBD for ; Fri, 11 Oct 2024 07:23:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5ABD06B009D; Fri, 11 Oct 2024 03:23:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5349B6B009E; Fri, 11 Oct 2024 03:23:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3AE3A6B009F; Fri, 11 Oct 2024 03:23:46 -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 13EF56B009D for ; Fri, 11 Oct 2024 03:23:46 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2B2021C6896 for ; Fri, 11 Oct 2024 07:23:41 +0000 (UTC) X-FDA: 82660481568.30.D693F13 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf28.hostedemail.com (Postfix) with ESMTP id EA509C0015 for ; Fri, 11 Oct 2024 07:23:41 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TAsmqUf9; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728631322; a=rsa-sha256; cv=none; b=gaDh2i4z8wJlzy3a9yjT4WIXoiwFGpV6XOwta0NkyIDXBaW/eMb25UeMzTtNAJT5dLxQl3 n8edxA/8QD2nu/DVQZqu8sgvBkTwGaQM4klRI2s+csGfzeDfyPlqDkpFhJfUQwsHQddPjO IpuUzE/uEzez1X5LjtjWLUr/5QdoKeA= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TAsmqUf9; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.214.178 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=1728631322; 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=5ubewzzmHjedesx22pwLGzOS0cZPbgARDYakPnaDJMA=; b=afwft46sx9HPrM9fy2qJuQkbYHuGynefpzhcRLco9KXW4Cbp24HGJYINz+P8saezUs9WlS 4rAoEZK67cUJ4qtZXpeuCpZTS6IlN5JF05A7IltkLGeNUDEsPICJERpzvkWcI/qbbOqdzD 7RzVeEEcXg4YnM8zvYp7IlOblzQw28E= Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-20caccadbeeso1156045ad.2 for ; Fri, 11 Oct 2024 00:23:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728631423; x=1729236223; 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=5ubewzzmHjedesx22pwLGzOS0cZPbgARDYakPnaDJMA=; b=TAsmqUf9mP8mvVuH2Bu3B8CSN1BS50+jH2gC7D1IflAC+BBDZfJe/pxvgHh4lx62DQ 0djqK39N3bYIVX2o/dLteoh18q6kefcF/Wud58Hs5IjXbK4hCuArezWmLYG+gxlB4s51 0LxlApYZYqakMECGWiRa/MhaajhsvXM708yLW4oj3h0g2LUxwR/me1kw5m5J5SZWESCi ZdtHpVuniSmHti75GsJmGjSAcK2QxO7dgr66FpXip5vJ/pRUD8SEZOReJOyrk+R9W5P7 Jp1/HQZ7P+RXUoFyplIQSMvVdLPExVN91I4z8MdNfDtcKYa0QlMueifkcQp8PfZ9xHAb u7IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728631423; x=1729236223; 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=5ubewzzmHjedesx22pwLGzOS0cZPbgARDYakPnaDJMA=; b=XRfC2DvvoEo4vJeRnTNdiqvlUfTkS3HQg7y+sobhiKrA7spuIStaLKLR4LoxvX1NXU vvGz8dADGA8/+fzZpa6UUWk75TvaIsfC0tz8h0DrVGwZZYP6xWJ3Om6kU0Ig+fUJJyPN cj8JSSaQNkxFgl1i96p3vaNHPv9tX+/Sj6zzRph5vRcAUMsq183OjzEW7uEeI5ObQRIG bCWlBm4+2tPrLB5opD4oj/x88uUeMxCjzJp5uZzG67lidHbHHUyzwFczPM3EOj3gB1r+ WPbEmnBMxlbJcuU9qEc+dG5mjJVxtVuLFF/66/MfJa+PWtTt7M8gsXpU4p3jhQ1JIez7 1Bwg== X-Gm-Message-State: AOJu0YyhBnxZ1DXDwKOcXzTnR5kpjO+SawYnpf22SwMaXI0E/VLDY1CE i4Y7ZbU/xcaoe5zJMMJwg1k4m00TfZ+WfHyW9obrnGYAqABIWGXcijuALw== X-Google-Smtp-Source: AGHT+IGf9QK0QpSNxbm45T2FEivaCIusibESERuvwR9YsSh8uK+WhxBRvYeFa70z9Xc08Q9BwN2JgQ== X-Received: by 2002:a17:902:fc8f:b0:20b:5231:cd61 with SMTP id d9443c01a7336-20ca14732d9mr21408005ad.24.1728631422585; Fri, 11 Oct 2024 00:23:42 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 00:23:41 -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 3/4] fadump: Reserve page-aligned boot_memory_size during fadump_reserve_mem Date: Fri, 11 Oct 2024 12:53:11 +0530 Message-ID: <4cea3a03fb0a9f52dbd6b62ec21209abf14fb7bf.1728585512.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: EA509C0015 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 9trjsthgfa3zc9tfzx1b8tfx53g9nit1 X-HE-Tag: 1728631421-555881 X-HE-Meta: U2FsdGVkX19W9W/iJlB9kpFRWJWWSVjTjZKNlScLAipKw1HCSKa+gvsymGKqi6q+fYHcFsIC7CWASgRqbE6YpYwOMxEbqp41oG020d+ECUXbEd5Tf7Q0jKaVGYZm1uZfM23nnWlbnmnARKhaPilMImbbcp4w5cnjAnhbn7Zd9Ewz4u4UroJySvPWVaz/rT59jwBl6DuHSiVuiyvF4DOFm8O/hRu0Rw9aQ4DiQqYzRs3z7Qp1wVDLAIE/0eBgaxCOSKwaMy5qReVOnEU0XqbPmbOoKzXVpkZdmUXVxvpq8lJwfvUleFY/06UjnmD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WpbohUbIGkWNafB+vZq/Xc1iCAv3FrE3g3D7FDk2Q2HzpSp7auZZ3XcUt5ynON71MKdzG8g6/Pp9X4TzhQTsaRaoWlxiHW2RC5Mq+hgXE0cKZtI5VmJ9OnhNTb4A6EM2AFFjSYfb1pQQ= 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 Signed-off-by: Ritesh Harjani (IBM) Acked-by: Hari Bathini --- 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) {