From mboxrd@z Thu Jan 1 00:00:00 1970 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 C1C2CC27C4F for ; Thu, 13 Jun 2024 06:02:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B40D6B007B; Thu, 13 Jun 2024 02:02:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 163276B0085; Thu, 13 Jun 2024 02:02:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02AF96B0093; Thu, 13 Jun 2024 02:02:50 -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 D86EE6B007B for ; Thu, 13 Jun 2024 02:02:50 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 86B6A1C2C64 for ; Thu, 13 Jun 2024 06:02:50 +0000 (UTC) X-FDA: 82224821700.02.F88BFCF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id C621914001E for ; Thu, 13 Jun 2024 06:02:48 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bvkO8eyv; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718258568; 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:in-reply-to:references:references:dkim-signature; bh=6yzD8t0eqNOt46QpvjWtzpbDfX0Xq6INDXI4mb7RDJc=; b=BQHtj/ilrC8Y8YcnBDJPORmI6FrZdY8YRh/eN4K4uWbuOSeWwpi7ZfcXTWiqBQBLp6UGHj a2sUWR7dpOA59h3zelLncpyfplnXFlkomIkOkQZ4gwH6MckohLfiFcLWvkPNdcPXrOEqi7 fsM4esiCjXZ3ei3XNLDH1Ha/m2okDOQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718258568; a=rsa-sha256; cv=none; b=LCH3vvSXwGJJeT7ONTtIoff59lF0Vs2AwSj1C5DkGdXKFLWwTNFu5Cn3I9tHXZMvj1NL+U 2ptXtSrxseeEywIfLdCQc4CARj6GtWuYosdeub8DTyFMD2BOwArfIn7sAvE0z/mxYU74U9 ZT1DXPnx1TXqZ2HQq8SA2yPYL2UktQs= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bvkO8eyv; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9B282617CA; Thu, 13 Jun 2024 06:02:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 637B4C2BBFC; Thu, 13 Jun 2024 06:02:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718258567; bh=3sL49NFvnClvD1y18UTPpLyD+rkcg9Qkf8lGulrYlEI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bvkO8eyvvIQKPJoZWLyWMTfK6O5N03AQA4XC6mijqToSBsMszcXr9Ps7YULdd+mwQ CMIxPSG6EFndRhrbMBaKeL08MauHHAIYDLjAKQjgKU9NWCkcTVyFrvmFQ8r91xLE5G KwzQ4EytMRXAmkLSDbDYk3Jw+MQeBKW52A481j5Gd4DtQ4Vuoxq/v80A/v3kTyKhUZ ykIEmOFhBgNH6uX8WEQThF4xIbon1RXDG+QAmVAq9AD4LNVqnG0TVN+3QEi1q60q0h oN9NkQffZog6Xl9BoKMpr+ebDOPGgNSA3sS4mGDmYKBzRXD9g7BgXpjse/6BO5DZDa qaftLWaQdNBdA== Date: Thu, 13 Jun 2024 09:00:31 +0300 From: Mike Rapoport To: Steven Rostedt Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, 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 Subject: Re: [PATCH v5 1/2] mm/memblock: Add "reserve_mem" to reserved named memory at boot up Message-ID: References: <20240613003435.401549779@goodmis.org> <20240613003508.752963299@goodmis.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240613003508.752963299@goodmis.org> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C621914001E X-Stat-Signature: 6gi9po4ec4oeif9cpw16btwd3j7j5ob5 X-Rspam-User: X-HE-Tag: 1718258568-133941 X-HE-Meta: U2FsdGVkX1/8XNoXHBppZR862JXm8MHExJgdj8im9V7VPg7zZuc206+xY73wjmCII2d7sNjli5RGT8KuW87L8EmFzzTPIJkLh6RdAC4YBlALVr22c1m5U0Ggfuwd7QM+0b7d06NeP0UqjEKs+MIOmX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u1cq0x0Yr3HVFSodVxDFtDkvPD5Ej65YlD7Ach/8sr2xCxg84i5p8pkuIIwSzWQzjQmGcS1BknFH0G2GUI8QCU2sWu0Zgn1bvhnNSQRENJ/gnheQM17j37eYDpBOilYQxL9OMC9aNGWoc02URna+DMq0zKSngSUlw/G+I4GnbIds9f/YymJyti7z8yikqKVxPPorOAu0O/+TBSp8LpRk2chAPEjt+V4= 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: On Wed, Jun 12, 2024 at 08:34:36PM -0400, Steven Rostedt wrote: > 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/mm/memblock.c b/mm/memblock.c > index d09136e040d3..739d106a9165 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c ... > +/* > + * Parse reserve_mem=nn:align:name > + */ > +static int __init reserve_mem(char *p) > +{ > + phys_addr_t start, size, align; > + char *name; > + char *oldp; > + int len; > + > + if (!p) > + return -EINVAL; > + > + /* Check if there's room for more reserved memory */ > + if (reserved_mem_count >= RESERVE_MEM_MAX_ENTRIES) > + return -EBUSY; > + > + oldp = p; > + size = memparse(p, &p); > + if (!size || p == oldp) > + return -EINVAL; > + > + if (*p != ':') > + return -EINVAL; > + > + align = memparse(p+1, &p); > + if (*p != ':') > + return -EINVAL; > + > + /* > + * memblock_phys_alloc() doesn't like a zero size align, > + * but it is OK for this command to have it. > + */ > + if (align < SMP_CACHE_BYTES) > + align = SMP_CACHE_BYTES; > + > + name = p + 1; > + len = strlen(name); > + > + /* name needs to have length but not too big */ > + if (!len || len >= RESERVE_MEM_NAME_SIZE) > + return -EINVAL; > + > + /* Make sure that name has text */ > + for (p = name; *p; p++) { > + if (!isspace(*p)) > + break; > + } > + if (!*p) > + return -EINVAL; > + > + /* Make sure the name is not already used (size is only updated if found) */ > + if (reserve_mem_find_by_name(name, &start, &size)) > + return -EBUSY; I'd prefer another variable here rather than size. Will be more robust IMO. > + > + start = memblock_phys_alloc(size, align); > + if (!start) > + return -ENOMEM; > + > + reserved_mem_add(start, size, name); > + > + return 0; > +} > +__setup("reserve_mem=", reserve_mem); > + > #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_ARCH_KEEP_MEMBLOCK) > static const char * const flagname[] = { > [ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG", > -- > 2.43.0 > > -- Sincerely yours, Mike.