Received: by 2002:ab2:6f44:0:b0:1fd:c486:4f03 with SMTP id l4csp187055lqq; Wed, 12 Jun 2024 23:02:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUjWmiun8GUuhyvEy0ISnXk6RR58zg1rQoEmyzPXi1bzv4Amg+Gk9co6NWHp+HX7oUwVADVekPgWZoBYIkNhn2BeNIcrROV7SJaJUWTCA== X-Google-Smtp-Source: AGHT+IFZXj0SsxtFgCSfU/X94hsdz8iFRGbWTMjhM6NHuehhTni076PRP9B2lLfVbSIHNFM0kIwT X-Received: by 2002:a05:6214:2f0f:b0:6b0:6ad9:1fd3 with SMTP id 6a1803df08f44-6b1912ae2fcmr36489656d6.2.1718258575072; Wed, 12 Jun 2024 23:02:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718258575; cv=pass; d=google.com; s=arc-20160816; b=0cfOxyoq/rOlphGocZtVf2zYQWtz57+FitkUMNOxiiPfStlCXCTTEinqvKZ7d5dNMz Gk3b1IMdWJzKsMm5SnugOQ72fxrbGot06g6sX/FbYWCLUjH2bAZZ6Zn7u2+xWtPnLHNA cf2h7QtP/kDHVNP7K7Tzy5G7e8VeXpYG5njtz6oFmfCeChpYnhLheptEcV83Wwf/+U6o 8SSdEo2C/FCGO6DV/i8BTlAVNPslU+3Xv7OPemFHq/rFPXPf7mkUFW9MSd7fP/x6v5i+ SW1mAut0i01Tx5g/UOHyCfytgNVo1LFYmb94RaOpHwLmWX2N/v8yFXnLuHnbpO+/45rX Z80A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=6yzD8t0eqNOt46QpvjWtzpbDfX0Xq6INDXI4mb7RDJc=; fh=H7m+OjBqGJUxVXEImLdJypVdoyoP8N0ycPhTumbFWw0=; b=fW6ngcDyKWkWt111M4HDGOdFnxRw5Atmv3A8tY3iAHTEQ+nOIRzFw/CAHbT2x6Fd71 9XTPSCv0W7V6suYLCZn98YhMNSZthW7+to4fiWv1s1rxy1sNV0Lb6TB3dlkzyJzRDNsk ORkOlSjri5cA5fKO8x8yfE0ZzQYVrQ2a/Z8uUvePSNOeABLQNOui/sZnS8/rAoDM0cLL ETIG5Ft50WcmzLDMpcE4VNaS4s1wKJZpKHUgUkm215QfY///S2/ZP6reaB6c17jtJZ7s uQ/gf/RxwzqgXlocKqFqP7KYkboawxPlbWF8WXOYKjLf5irvb47w51gxYP/gvRi7I7zw A9Rw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bvkO8eyv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-212588-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212588-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6b2a5b38914si7376626d6.416.2024.06.12.23.02.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 23:02:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212588-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bvkO8eyv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-212588-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212588-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id AD9C51C219FA for ; Thu, 13 Jun 2024 06:02:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BAEB31369A7; Thu, 13 Jun 2024 06:02:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bvkO8eyv" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0E1837C; Thu, 13 Jun 2024 06:02:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718258567; cv=none; b=OR7yxlnDFhChAm13ywu4sNOpr17SI1eRaYX9Sc1vDwTzGUnr6BVBoV4KgYokU/oHxrmq+XfJESOegvFekpz1zyARRDjNyEZYJdp5F3Ym9JnYlKFIq4UDin56F53zcAa3MPa25YABO++p57DCWPcJsHJe/9XIKyIwrzD4Cu57mp0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718258567; c=relaxed/simple; bh=3sL49NFvnClvD1y18UTPpLyD+rkcg9Qkf8lGulrYlEI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=efMhuAsbtUlZ0wobXcipPZ6QYVYz/MY5S73mU7nb90LjcvvumjcgYsqkcwlQojP7n+w9QGMg+V9iAIpEH1dDsoIQinGDCdgtfNDAXKmQUZS/G9rZmeGItm8AMSnTOCw8xjFsC0I9sCj0iIsnQPRsLSrQMtjTy7XUj1yhXUeTVZ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bvkO8eyv; arc=none smtp.client-ip=10.30.226.201 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240613003508.752963299@goodmis.org> 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.