From nobody Wed Nov 27 10:01:12 2024 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8019E209F36 for ; Fri, 11 Oct 2024 07:23:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631412; cv=none; b=IOJmmDxeT7wq/cxG6YshHPvaBzJ/sVe7A1fUJZTgz7/WvpvBCsrf8mznvL4feLO++21o4OLzdnGlzQyo/rp41iQpkOQqaxYo+BAbs2ZLx0pO9LCuclz7Yv00O6mkiJPs/CBp6CmXGWBBsb3ePTNaW4wU/Mp2sMMmjOg5FG4mLrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631412; c=relaxed/simple; bh=Tjq7WHo4wiY9BUcZ7Wk9jSRfZDh6UkNJTT78Q2v49Ts=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DUJ9WuiAqKzir7HlfO2FAGmqrbLMXuwKc7KLNxrFVKZPRUho1xuuXVbiTIwdJoBMNkqTLzGSxmcmAb6VRk13UdYPEd8pDh+q4blR55HkSL1WF1F6sAiavEo61ema7O2Jkra9BAJGrvg8cJejAMm4cRRPkiNJoPDSA4dgYrbNC34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=T6epu6QN; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T6epu6QN" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-20ca7fc4484so1461175ad.3 for ; Fri, 11 Oct 2024 00:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728631411; x=1729236211; darn=vger.kernel.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=cFXU0lQKXMNLX0e10iqDZMzQn21Hy9EUBSVtGclHKC0=; b=T6epu6QNeycaPo3BDZuRGyXyEXGJ1J4PUFplv45JUAXKrlky9k/Pkv8TwuzhZ8CnLD GRUhOFHMM998lyOvAqg8l898Ncdjpr6jgZSo0kSZRJ5rqtTKL+UBF2R38u7rZa30V2On RoTHh2h9YwTUXcX+lmxds0XOVcc06MfURS9L/5tohoSMTMsfLYqzeOw0BJyJ0Bjp9qQR 1MubkTdDeAANST4i+VMugbalzhup7pilVr/DYHpgBPMnw1k51Fhu1osEhzTUHgxwsWf/ 41De4iFHs5E5sJdRU7VERKtwsszbaT96Cj43XZmW/Acq0VdodQjV/5wp81pNG4v5fZ/G Uysw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728631411; x=1729236211; 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=cFXU0lQKXMNLX0e10iqDZMzQn21Hy9EUBSVtGclHKC0=; b=E7eZyureu+I5PqbgJ6qAsVr3m/liz7aEBHChtJZyqjUl6INCqmGbfK4ZCyxWprbwEY cXqwzsWtaWosN/qAN68BlJrhlaUcMzKsjnsHkWQZglq0Fa1wcc1+hySOc6y7SVX8YY2Y y0kDGDnWzmrYoQtoYFcSvsGQOv2jZfuD+sk3nifjIpsQhSifBvom7Z91LVy+AuvAlC/+ mb56O3CfCpd1gxfMUiGhLpeFZVOt7oT+wZfrHZiLyMsxkx9k+W26jONk8v1Dx70jYi3W bW/Cd1OaQWCLzi8yJMk3BxdYRIiVpUIpvSF90u3ENba7FVHmtqmgF2SMDQ/lxusms+wu uMCg== X-Forwarded-Encrypted: i=1; AJvYcCWzVIrkoZSerwTbShyajppmpFrqsqFMDzyeHag3Q9K3HqwnaVGqzA3S04AfzT0SgtV3dQe7rVfc/SOcCQk=@vger.kernel.org X-Gm-Message-State: AOJu0YxVNiDRcShFWBh2xooBqTbanoEfk39F23LJjusuC1mqW3LP22Bs pELGcBgR577qhDdVFy2OtYEa+Y1gCdubBmWZWqoyYP6kF9CTkWTG X-Google-Smtp-Source: AGHT+IGQ8iq1sir1NebxPCSK/DS4CJ2zGOXIXoa+HRwjhD+gjsmYWNAElhY1mGxdYNMN7u4TdJpehw== X-Received: by 2002:a17:902:d2c8:b0:206:96bf:b0cf with SMTP id d9443c01a7336-20ca1315240mr25369385ad.0.1728631410877; Fri, 11 Oct 2024 00:23:30 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 00:23:30 -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 1/4] cma: Enforce non-zero pageblock_order during cma_init_reserved_mem() Date: Fri, 11 Oct 2024 12:53:09 +0530 Message-ID: <8579f887412720bd6f2fbce513c1c9904772ead4.1728585512.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" cma_init_reserved_mem() checks base and size alignment with CMA_MIN_ALIGNMENT_BYTES. However, some users might call this during early boot when pageblock_order is 0. That means if base and size does not have pageblock_order alignment, it can cause functional failures during cma activate area. So let's enforce pageblock_order to be non-zero during cma_init_reserved_mem(). Signed-off-by: Ritesh Harjani (IBM) Acked-by: David Hildenbrand --- mm/cma.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/cma.c b/mm/cma.c index 3e9724716bad..36d753e7a0bf 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -182,6 +182,15 @@ int __init cma_init_reserved_mem(phys_addr_t base, phy= s_addr_t size, if (!size || !memblock_is_region_reserved(base, size)) return -EINVAL; =20 + /* + * CMA uses CMA_MIN_ALIGNMENT_BYTES as alignment requirement which + * needs pageblock_order to be initialized. Let's enforce it. + */ + if (!pageblock_order) { + pr_err("pageblock_order not yet initialized. Called during early boot?\n= "); + return -EINVAL; + } + /* ensure minimal alignment required by mm core */ if (!IS_ALIGNED(base | size, CMA_MIN_ALIGNMENT_BYTES)) return -EINVAL; --=20 2.46.0 From nobody Wed Nov 27 10:01:12 2024 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFD4520A5F1 for ; Fri, 11 Oct 2024 07:23:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631419; cv=none; b=AAzOysT4FDgc+zJZaTETAsK87O+B6Jk3OFJtEnbN0nnR0+CrxdhvYtW4P8n3uruQfY105Gd3H6pbbuRhxJrDWl+O4BAxZaZDKZ/DBetcETt2bdKQeS3NNHEwGs59uzkMqocTEBf9WlDFGe2WJYIyOjVwQJz3IsxCV5v3pVzivuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631419; c=relaxed/simple; bh=pWtMmxnwZ3gTBjNa88ijjlObv61ZuB5OCQXy/tH1fEs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FHKRbor8VPclq+mWmNGRtty3/a82QV5baKMg5Tj/lP1OK7Ep5l986ebQGwbR/PWhdMstR/b7ePCwduM8TdSKbFsFHvjmFEGr0v8fKUZi8+vL3UXANFg/08HXtbJzBkVJLDPP4ugDQl1FhYxC8ZkfAooRM9xArmKLAp2twosMHcc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=d1DSu+86; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d1DSu+86" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-7ae3d7222d4so1478587a12.3 for ; Fri, 11 Oct 2024 00:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728631417; x=1729236217; darn=vger.kernel.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=e0XcJo9JGEctgbuPEWvt7vh5Yz6kEP61gEF6kN7DKNI=; b=d1DSu+868BhblXtkQJKbsQar3r92OBDfG1O3H8wsA7S53Aljg9BsNcccAzLJTFTZT7 BiFIFtWma246Gx1piYjkF/JLg/fuIui4uYXV+uORGh5onl0Ea++1BqhTAhPC8lR9MHOg s8E6GVvXlyqvlpGMm/wEn/h2cQJAyVA9ap33mutY5BZXDOBcOJHTF0a11B5b43L3yYaz ZSLdfHgZzBCIAMNjctE9pRUBOCsvIcDFW7W6J4p4wQySMls6YMFI6N1duz57Ho5XATp4 SCbZFExz4J7UuFxXNFFjLiIzUkVpAE4KDgylAdqX0UaXdo3rHe201VMkYXnaIXlOBwtL eYHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728631417; x=1729236217; 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=e0XcJo9JGEctgbuPEWvt7vh5Yz6kEP61gEF6kN7DKNI=; b=K82t/RpjelkPPTAvC7wT+uSdKH0GfO2jjWm9F0z08SuC9G54On+2bkcPjj+3GPfDVK Pc6IVDbUqSlf36oHt5gvw9pqnM7BUg/97rc+AaqVO8CbRbo4gVnWxvndiAr/GSPqP7co G3pBk9nM5AY6njvr9hDwr3BkGl7otDzBonxqRdGQ65bBzmvjwLZrme6oZJSzrBCWh3A/ HzBFbbxY2tPK4pj9ru1KseHGKHWzu3BRFo+JssEEukLKYnRpYMZ1dMqYtDom4k3tX2qE pvRHxHVchvURjlaC/CPv62orG0dMALkWWTtsr6ufa79WnAG4t3zjQbq3vz9t6UpPBgJ7 v5fg== X-Forwarded-Encrypted: i=1; AJvYcCXfhnmaPllvqUoDtWWIcmwzr89JNiMBVvf8Se4kR1l9RlkAP9QuuqNc5Q4XZPDxypK0JkHxen+Qw0DPE8E=@vger.kernel.org X-Gm-Message-State: AOJu0YxKzA3CA00ChyxoUf9g/bWuPfMNOeWtfujHoDhLCUWm+55z0j/2 qFS+YD+1FdV3+NDemQpGXx2jRR3VzouLLSAzX7NnjY63M/PIJFC1 X-Google-Smtp-Source: AGHT+IFVJLbjrihstm+z1iQykRd1RHjrMq1OggwLcM33etRABky007jtDtqG43IWWvWSUwC4nwqrng== X-Received: by 2002:a05:6a21:6b0a:b0:1d6:de67:91ca with SMTP id adf61e73a8af0-1d8bcefd51bmr2327071637.4.1728631416985; Fri, 11 Oct 2024 00:23:36 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 00:23:36 -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 2/4] fadump: Refactor and prepare fadump_cma_init for late init Date: Fri, 11 Oct 2024 12:53:10 +0530 Message-ID: <079e98d7db3b63bc8a568f4e8c03f2976878ae23.1728585512.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We anyway don't use any return values from fadump_cma_init(). Since fadump_reserve_mem() from where fadump_cma_init() gets called today, already has the required checks. This patch makes this function return type as void. Let's also handle extra cases like return if fadump_supported is false or dump_active, so that in later patches we can call fadump_cma_init() separately from setup_arch(). Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/kernel/fadump.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c index a612e7513a4f..162327d66982 100644 --- a/arch/powerpc/kernel/fadump.c +++ b/arch/powerpc/kernel/fadump.c @@ -78,27 +78,23 @@ static struct cma *fadump_cma; * But for some reason even if it fails we still have the memory reservati= on * with us and we can still continue doing fadump. */ -static int __init fadump_cma_init(void) +static void __init fadump_cma_init(void) { unsigned long long base, size; int rc; =20 - if (!fw_dump.fadump_enabled) - return 0; - + if (!fw_dump.fadump_supported || !fw_dump.fadump_enabled || + fw_dump.dump_active) + return; /* * Do not use CMA if user has provided fadump=3Dnocma kernel parameter. - * Return 1 to continue with fadump old behaviour. */ - if (fw_dump.nocma) - return 1; + if (fw_dump.nocma || !fw_dump.boot_memory_size) + return; =20 base =3D fw_dump.reserve_dump_area_start; size =3D fw_dump.boot_memory_size; =20 - if (!size) - return 0; - rc =3D cma_init_reserved_mem(base, size, 0, "fadump_cma", &fadump_cma); if (rc) { pr_err("Failed to init cma area for firmware-assisted dump,%d\n", rc); @@ -108,7 +104,7 @@ static int __init fadump_cma_init(void) * blocked from production system usage. Hence return 1, * so that we can continue with fadump. */ - return 1; + return; } =20 /* @@ -125,10 +121,9 @@ static int __init fadump_cma_init(void) cma_get_size(fadump_cma), (unsigned long)cma_get_base(fadump_cma) >> 20, fw_dump.reserve_dump_area_size); - return 1; } #else -static int __init fadump_cma_init(void) { return 1; } +static void __init fadump_cma_init(void) { } #endif /* CONFIG_CMA */ =20 /* @@ -638,7 +633,7 @@ 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)); =20 - ret =3D fadump_cma_init(); + fadump_cma_init(); } =20 return ret; --=20 2.46.0 From nobody Wed Nov 27 10:01:12 2024 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AA8E20A5F1 for ; Fri, 11 Oct 2024 07:23:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631424; cv=none; b=sVFKpaeEPnxYm0jqIbyDhalnsZF8XPuALgbMDSTBZPPdQpz3l9ob4lTWjaR7MuOqtzhaY34ezV3LevmGQDh7glCT++mAg3hH4VqOysPozUJRTnChX6iYZ0EGpZX/us8Nnj0BXrADkAwRbOsmFp8jY+3lwsWCvbzXRmv4njCpo34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631424; c=relaxed/simple; bh=nHxXQVCx+AjI+TCgFGMZIsXkjXhyQedDQPiOWfLR9bY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MdfdiW6zyINwtixlvHAUVhu8i+rP4622nJ0KXZLgkxhIIF2woA+ouKn5UnQohOzOLBht7fjJP/mSguxIINqlsZmhNaELn04Je/sclOuMyue/SuZnGyUHL8TaiTiLOmmkYPIt+cqf0dA2CnKtsa1/BYHcEyboC7aDo0t6OIhiBkA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ne07Xr9w; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ne07Xr9w" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-20b90ab6c19so17327405ad.0 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=vger.kernel.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=ne07Xr9wJFMqIwmwHmDwO05fEmJPqEGOm1wcj7TSYfAVORWSQc0ffOQMUd6Lh4hA7q N9kYSsrbkDj6LIIif8sXHEw+cUkL2k1YZXIe3va1ioLp7YkUAcsVFNIsMp2ykklILS1/ sq5buX+xcYCwxBrwsu9mTCRB3dA1sGCDERCMBJ7TCB3k5QinP6DD+jv0/hyXmqrfoYzg eMmK+T9d8eCAaJtPzrrCWk8pJhrJLMw27e/rFeZoNIBMJj7C62edehP55a/+dlNQR7La ffbVFBt5MRRoyzOa7eKlX1nuogwN+Crx2vvygkJmomJlS7evWgNvbD8PRMHJKA1T5Gp8 jtvg== 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=FA2i8k+TmG/2nHwo7tINsL/9oflP44GN2kZ26dO+SDum5F0wZt/J5UelVHq1h027RQ 1JjRFE5UVzH0E0FGK5P+HFQY429oYVOrJitnuEnImoODlfuvyPo0vYtp9l/AWHoT0HNN a+1RuHUow/iQPTj7GbWv2tFq66EA4uUEjH0aaoFjXcPUjwfJK214ufw/lg0Smn3ByXOc SrULf04vuX9cDUMxU0LJOb5GUOAgp0/SfUkg9nMeltu/s8cW0N9k8cHiIlpW0b7a2rVg fh6BOBM//Kp+spYm9MCMxca4CSMG1vM2rAxnSngJWcYQbocjFWCIrlP7CPgpB3wZTozm qpVQ== X-Forwarded-Encrypted: i=1; AJvYcCUiR/WAOyW823sEeKmx7d97o3pFuU1pS6ktZP0OJ+ntlv/wMEQGNm1J7mPESRCYBVtnLwcmnyd9uVXa7/8=@vger.kernel.org X-Gm-Message-State: AOJu0Yx8SwWOIgkkJFS2p3lgdPjOTYp+Rp+m3OqId6qEi2zH42MOTS+U 5+PIg8fwrF9S0QT7AVd8iyS6kPakuTpvcXFpZXkG/mzDqXeWM+b7 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: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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; =20 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; =20 + /* + * [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 =3D fw_dump.reserve_dump_area_start; size =3D fw_dump.boot_memory_size; + end =3D base + size; + + base =3D ALIGN(base, CMA_MIN_ALIGNMENT_BYTES); + end =3D ALIGN_DOWN(end, CMA_MIN_ALIGNMENT_BYTES); + size =3D end - base; + + if (end <=3D base) { + pr_warn("%s: Too less memory to give to CMA\n", __func__); + return; + } =20 rc =3D 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 =3D PAGE_ALIGN(fadump_calculate_reserve_size()); -#ifdef CONFIG_CMA - if (!fw_dump.nocma) { - fw_dump.boot_memory_size =3D - ALIGN(fw_dump.boot_memory_size, - CMA_MIN_ALIGNMENT_BYTES); - } -#endif =20 bootmem_min =3D fw_dump.ops->fadump_get_bootmem_min(); if (fw_dump.boot_memory_size < bootmem_min) { --=20 2.46.0 From nobody Wed Nov 27 10:01:12 2024 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FD5A20ADF4 for ; Fri, 11 Oct 2024 07:23:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631430; cv=none; b=teMfc6vnOTaIJta4H6J2TRI8zwLI1zuce0BHnzdzhCQySuubqyisAuR7f9SoDHtfsV5fomtJAWGA3vVTAo1MbxNCcqbTP7Iym2JwtuRMhhozpq3RUZdcgd0821WU1T64baTYBzBoy3PA9vwMjCeAkw2gmb4h/O3XJ+iP9ULSA0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631430; c=relaxed/simple; bh=IE9QpX5jYmdGcJKm9aBjxfQ0HBiGaeNjeifVxAkzwhw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FNzSEY6tUzhNVDJZ3jfzggp8OsbSNveSe65AmBu3aI74qHaQqlAoKRbxktyzqdzVhutmIMu0zg8z4XxWCKyYZmep3/4nBH87S+IqbvvoR/XsKx3F2BFuIIVbTCN/SyUrYbEdQxFLjnBW2IB97tXWmahZl41rW7XT1lS/eef0mRI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IBkznMmT; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IBkznMmT" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-20bc2970df5so13676285ad.3 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=vger.kernel.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=IBkznMmTNrr3mG6LYNStmAa+Tbwqk8m8gDkf80o1ZsyzQKL+GLBb8RuhOyPWv52fNm uPedHje7bWN68s3zFai+LcEioHBu6ZDPAAKw8jyGZtI47JVOxTJgRueCH9notrKOvVoj ek+wf3G23NiiFjrM6ZAVxenMTiakSzZMziDV1ZYvF+tYh493OLGur+DuTQGxYxugOUb+ 551Avz058sSV64DmAcsuaigDpfNPhJY1vVTPFietlcLiunzh0es2B2gqxMq6Xmpqo1sF eiT2nY59SJDQyEhigM+anuXfF8fFLb7deRgoS88CQtMPLqlonXXA6McSG0E2VuWqVVT5 7Q5A== 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=NYRVoNf0a1bJR6uptVzZums3ekrq75ayU9QK7FJhaFBk6RITo6xrik0d0lLFBzGlMe 6EgIZXPNa1c0lgduiotzuIu1H3wijS9qDOZvXsygQvt136e9iJiHokuDkGKLUQDkyddy ZXvid6pCcF5wPSYnWCPPQTXTqkmLkbFa49/3Z+XKhzzTb2HeOuXX93mNF8igwp0tvPlr 0pQhDgqH6BJhaGVIqhQz69u/TSK5cyE4teLO0GAdbkxQq5hSlhNX2fr+UTJQVZ2R5dK6 r5xyHMgVdl3OX9KJNZHwv5SV7yIXqb049z7msWP3arApFJNTA3N/fRP1BrvVBKLdpHzy eBfg== X-Forwarded-Encrypted: i=1; AJvYcCUWHi9ppT0Gh9r4JLfyj19vMOPpb60IWr3EMK7/l/axYnRIVBRBd5dbRJSZrr24kDUILDDp7duxzEXWC7A=@vger.kernel.org X-Gm-Message-State: AOJu0YwH1vbZ5W3l1aqZSL6MJ4ghU/XWtVGhx8rTHYjkWCs9veLOG2mX l7vT0K/UGsFbt8K+zOZsw8KqRuKnntT/9+XVAzEH0RmvYOeWX3RY 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: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10010 flags: 0x13ffff800000000(node=3D1|zone=3D0|lastcpupid=3D0x7ffff) CMA raw: 013ffff800000000 5deadbeef0000100 5deadbeef0000122 0000000000000000 raw: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: VM_BUG_ON_PAGE(pfn & ((1 << order) - 1)) Reported-by: Sachin P Bappalige Suggested-by: David Hildenbrand ------------[ 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(-) diff --git a/arch/powerpc/include/asm/fadump.h b/arch/powerpc/include/asm/f= adump.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 reservati= on * 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. The= se 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(); -- 2.46.0