From patchwork Thu Jun 13 00:34:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13695707 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 55E86C27C53 for ; Thu, 13 Jun 2024 00:35:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFD4F6B009B; Wed, 12 Jun 2024 20:35:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C5F666B009D; Wed, 12 Jun 2024 20:35:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B00126B009E; Wed, 12 Jun 2024 20:35:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9293A6B009B for ; Wed, 12 Jun 2024 20:35:01 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 376D6C046B for ; Thu, 13 Jun 2024 00:35:01 +0000 (UTC) X-FDA: 82223995602.19.9F888CB Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf27.hostedemail.com (Postfix) with ESMTP id 03A5640011 for ; Thu, 13 Jun 2024 00:34:58 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.hostedemail.com: domain of "SRS0=ySKb=NP=goodmis.org=rostedt@kernel.org" designates 145.40.73.55 as permitted sender) smtp.mailfrom="SRS0=ySKb=NP=goodmis.org=rostedt@kernel.org" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718238898; a=rsa-sha256; cv=none; b=yZtArjUNSeZ+9HWY7qNpCrsq6B18wL+A0uW+aRjEwtAbThiIl2hJ2FiyXUBEE0QAvkZ/cY 1rWEoyN1jdF2JLVFbOrLbKJ3iEx8bq8PKgGBvUBPTjKerhQDh1eI0ubmuKAZp2cOXdUKvV vkJ2ur9NRsAOzBQJqcCU6KCS4wTllJs= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.hostedemail.com: domain of "SRS0=ySKb=NP=goodmis.org=rostedt@kernel.org" designates 145.40.73.55 as permitted sender) smtp.mailfrom="SRS0=ySKb=NP=goodmis.org=rostedt@kernel.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718238898; 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-type:content-transfer-encoding:in-reply-to: references:references; bh=QzN3YGRkVyxpLqEbfzy/POyX0V7EbVZAm324ZBlI6DY=; b=GE2M+EtKsKKHgkUVIcvGcdvd+tbQIYZL9rhujocAtMHX3A4+9oP32dyjZpo3jjudWPL+QA J7stff+vZpelItU9V5dV52Flu+QCYPcZK8jmypadADKOevNfn/GpfqH0tP4vGNLmovuf1F Aok0M8CPlT8RtvEogevAKLdMT4WvQXQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id EA36CCE2408; Thu, 13 Jun 2024 00:34:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95BCCC32786; Thu, 13 Jun 2024 00:34:52 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sHYQm-00000001eN3-3lZi; Wed, 12 Jun 2024 20:35:08 -0400 Message-ID: <20240613003508.752963299@goodmis.org> User-Agent: quilt/0.68 Date: Wed, 12 Jun 2024 20:34:36 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , linux-mm@kvack.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Kees Cook , Tony Luck , "Guilherme G. Piccoli" , linux-hardening@vger.kernel.org, Guenter Roeck , Ross Zwisler , wklin@google.com, Vineeth Remanan Pillai , Joel Fernandes , Suleiman Souhlal , Linus Torvalds , Catalin Marinas , Will Deacon , Ard Biesheuvel , Mike Rapoport Subject: [PATCH v5 1/2] mm/memblock: Add "reserve_mem" to reserved named memory at boot up References: <20240613003435.401549779@goodmis.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 03A5640011 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ksub1eijexba9n4skqomsgkd54rnah6p X-HE-Tag: 1718238898-628184 X-HE-Meta: U2FsdGVkX19j0HosC2Z45M7BSh5d8B6gw6r99D+4GqvFs9WMoPU3jSObFb+t3j7x9I2X9Ujk9nAXIGcbpYe9JREb1c0nt8x8fjzqKgj1QGna23Hd5F4B2jK1VvZGI9MnCjqh4uSHCzG4TWNDLUF/WvTCA778agiuyJEUFOdSoYcS/FWeHO/QkavfTrjtLdH7ncsuavOERT9veS2IBNhTQmhuzFEsPXOF38neTTejGOv+TLq5Zh/Sp8lfc1CwT6bq/8aYHkpfporvXFXxrJyQ5vW+s6HurJbrQAZlf2ZZhNKpTsQBKu8ticab1LW75+fBIUd6Uiz2Asnskn0nmVUxPWmbGqfIRabgCqEKv6FObQV8pa+f3GxkaLOfGgtKaR4ZvivPDG4Eh1cujU35/AOTadR02RLXlliOPt1fT3wwJzJyNgq+skO9ZxIfsfCINOxpkC5cFEVoZt9l3IX2hi18+g7CAwlPPY5uFzsib6YeZDKXRrdXfJ9N8ERo4sAmzPtX3/qDsnTUlYS4b4vSQ8+u+CLQe57pSFxyLCBTUwJnsJw8UZy5rr29lJdwKcgM6ilio/lMqDm0ieDHzNzm865atdWMd6qMSSFVqfXPXLut0HSoavaQ5w6ae1TVe/FseAAx76EgAApAAYvEIUc3DTVoPa4flrCR2NGqPYpqQVEI69dRygeLVUUp6tmPl5H+1DhSIqKamfxsmLlylQPXXBd5FZriX+P0FIufQsZpf3dtsBB0O9dkTAopOcOkGY8YP1evhGVfmY79eFKtPuYJX/NX1ItXlQOY55+E9bMcr9Z9rxpgBy1OO+ZC8vQlQTnGnUxlPHPt4jlVL1QG5TgPbEuN4jM5ldnK3QUb1XFVkZ3XpK7CfAm1dPFVlBCNcqfgOm5kyKSt1lg8J4Vul0HuAyh240sk4zX14dksnQ3IeCPtdC5dqIJLkl8gtRZmfLugIDRCOLhJGte4yUt/tcA4Dq7 M/97rfJN vwvtSBNzb+zmDK6CEJ8w6ebhegW2GYQdP3gKbA9/xuxJKCa5QUogPsg72jfGQXy7RPfeXzBe+watvZwm5jWj0HkwOXPObJBeK3Lvy3goC/EYgqC+SrNQqcVvRKCIbJm0jxJfN8Lu6lXBydNLVyduOZM2UBx8V66GdOtdtQMXOVU11hLKTBVL2pB788NiW121XnY7AOz+vwwGAVWewwIR27uFh86+VbSrtxrU/CQaCEafYSaQ3vnnX5ktB0qzB7vv59WyHh8J0WeBgPyx9/vBf4ehEYfOUpOMALoraKsgHV+9OWg52/FpgyjrwHAiA6x96profTjd5ZkfoSDpf6UUQf3rDvXsor8g3pugpWfae8zZEO+cdYhF0D5XzGTWv5UW5hddk4UY9apjRjv9cJnZu45KlcQ77p3A8eQPQWGSl78itWbicNq+FJS/C9zJiUIjgWe48sSU3dqPfQVemFN0TjZ4ApfylwRZP08CXUnRPdhDFgk+7z9wqN3Jth5UyxWVGjjS5P2kEST+gUJ0= 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: From: "Steven Rostedt (Google)" In order to allow for requesting a memory region that can be used for things like pstore on multiple machines where the memory layout is not the same, add a new option to the kernel command line called "reserve_mem". The format is: reserve_mem=nn:align:name Where it will find nn amount of memory at the given alignment of align. The name field is to allow another subsystem to retrieve where the memory was found. For example: reserve_mem=12M:4096:oops ramoops.mem_name=oops Where ramoops.mem_name will tell ramoops that memory was reserved for it via the reserve_mem option and it can find it by calling: if (reserve_mem_find_by_name("oops", &start, &size)) { // start holds the start address and size holds the size given This is typically used for systems that do not wipe the RAM, and this command line will try to reserve the same physical memory on soft reboots. Note, it is not guaranteed to be the same location. For example, if KASLR places the kernel at the location of where the RAM reservation was from a previous boot, the new reservation will be at a different location. Any subsystem using this feature must add a way to verify that the contents of the physical memory is from a previous boot, as there may be cases where the memory will not be located at the same location. Not all systems may work either. There could be bit flips if the reboot goes through the BIOS. Using kexec to reboot the machine is likely to have better results in such cases. Link: https://lore.kernel.org/all/ZjJVnZUX3NZiGW6q@kernel.org/ Suggested-by: Mike Rapoport Tested-by: Guilherme G. Piccoli Signed-off-by: Steven Rostedt (Google) --- Changes since v4: https://lore.kernel.org/linux-trace-kernel/20240611215801.443593152@goodmis.org - Add all checks about reserve_mem before allocation. This means reserved_mem_add() is now a void function. - Check for name duplications. - Fix compare of align to SMP_CACHE_BYTES ("<" instead of "<=") .../admin-guide/kernel-parameters.txt | 20 +++ include/linux/mm.h | 2 + mm/memblock.c | 117 ++++++++++++++++++ 3 files changed, 139 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index b600df82669d..ce7de8136f2f 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -5710,6 +5710,26 @@ them. If is less than 0x10000, the region is assumed to be I/O ports; otherwise it is memory. + reserve_mem= [RAM] + Format: nn[KNG]::