Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp905119lqo; Wed, 8 May 2024 21:00:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU8l4OuSKMx9w/KXOYq4CwrmBJEnm4cbHxhKjISeXwaO2tLLRC4/w32opAe2Ew/fZPAOwoGX6duwsxhVU4IbPh5HF0p7h/m+mgUKCw9kA== X-Google-Smtp-Source: AGHT+IGyqY8OtH4bdg1caAFDmnX99bCJoJIxV05kUTMLGZFJA5AAQrkSny9QEuw9EIqA9SZ0lAZ3 X-Received: by 2002:a05:622a:2c9:b0:43a:e984:81b with SMTP id d75a77b69052e-43dbf4ea361mr52420091cf.8.1715227233360; Wed, 08 May 2024 21:00:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715227233; cv=pass; d=google.com; s=arc-20160816; b=0WCCotkCg3pD0VLY/soyxV092cHJW6GFnz0aHWlKDBMl2iEu0J/088kazRrZJFEvOw p9ifNgY++eq3jZbo8OXP/chAW8N/hu/eQpTa1Z/Uq+wu/eCWsOiMzCQPsO3rT7F0HdH0 wiQssOK74bitHe1XzeQ4prJGrLrDftNBsNidwsw1H7uU2Npu7tome3nBESunsKff2i1D ux71AelO2jkrHTOrtXGVm1xFFcdZXHdfZq5mEDGgNRLia842AKJk3GA8oD/VF0yEYQEO 4KNu137odmXPKgYvljnpF30huoMTptFh8ecmTwkXFSvNoACuUFLE2oP6XzkcZPk8z7f6 5tXw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=PRSO0KL2gHmGj8UkTLlN/HzLIKVybqcaVipePe81Vrk=; fh=0Hoz004CVqkSauOcyGo6w+Nffyo2aMpqRBWyE8Xt3B8=; b=BEGQlCzrQmSPoAZVz1/VHZ5iv4Rxdk2aor5+mV14x5Y/BgIjCc9SolrKaRvyUvE1Sw koyUSCCjBD98kKwcj35DWRbJU+xuqM8JNFQLazecPewOgNPLXbtHBrxbGPeDHRP5AucN CO1Y11pi4/HV1Coodc3v9+Zo10d3eycl1uiiDh3Z0nQlQrRkRR4NulBVQf3za859+W2J r8Sr//gCC49Tnbvemwa4dLhZ7BMNqxE6csl0dkCQ2W9ELDRAHJEdZ52+zIdzynN7dM8N 6qpN0uABef5rWkTcO9UkrJIsP59aTjUxyhcfXV23USoUmc4WaAXnE0Gxn4ABeuCBHH8B 5VsQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-174112-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174112-linux.lists.archive=gmail.com@vger.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 d75a77b69052e-43df71d9b83si2164701cf.183.2024.05.08.21.00.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 21:00:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174112-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; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-174112-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174112-linux.lists.archive=gmail.com@vger.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 155771C21AB1 for ; Thu, 9 May 2024 04:00:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A82EB1482F1; Thu, 9 May 2024 04:00:27 +0000 (UTC) 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 2007F13C91A; Thu, 9 May 2024 04:00:26 +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=1715227227; cv=none; b=be2vEPPBr7OdnqEw0yMJ7jULbbqCEJNw1K/5kYtv4Uvruzwta6OmAO7025mDgxZQBFd5tEekOoFdnQXLMD9geJniwvPryaHPnSTsEuyrhlMlWnBznfp6YRnMzgNT4vvC+PVdQlb9QE8U31XJpnUROA2yJm6uRAnm2t/ig1Afk6s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715227227; c=relaxed/simple; bh=/WuVnMddurzRtwEvdj/SXUmfhB8S+diULnomVZxDPDQ=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EloGbTd8levwlF1a25K/9Y4LT/cOghs4fsRoLSOwNdpME4yxzqP0nVCpWtxl9A7+eyl7tL2vxINKBOP8dGkWGq4FdKJx0M/sqMT3dFJRnHdxB2P56IVSySashlIp9O6PvQ755qCPSLTL0uhK6Cch8fxescPk2dU/DdPefu83KfM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86446C116B1; Thu, 9 May 2024 04:00:25 +0000 (UTC) Date: Thu, 9 May 2024 00:00:23 -0400 From: Steven Rostedt To: Mike Rapoport Cc: "Guilherme G. Piccoli" , "Luck, Tony" , Kees Cook , Joel Fernandes , "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 , "linux-hardening@vger.kernel.org" , Guenter Roeck , Ross Zwisler , "wklin@google.com" , Vineeth Remanan Pillai , Suleiman Souhlal , Linus Torvalds , Catalin Marinas , Will Deacon Subject: Re: [POC][RFC][PATCH 0/2] pstore/mm/x86: Add wildcard memmap to map pstore consistently Message-ID: <20240509000023.096d4032@rorschach.local.home> In-Reply-To: References: <20240409210254.660888920@goodmis.org> <20240409172358.34ea19f0@gandalf.local.home> <202404091519.B7B2221@keescook> <3391c693-cf54-526b-79a8-d565e7140947@igalia.com> <20240411154007.5bdf8d95@gandalf.local.home> <20240412132243.053ad096@gandalf.local.home> <20240501105455.42b78a0b@gandalf.local.home> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Wed, 1 May 2024 18:30:40 +0300 Mike Rapoport wrote: > > So this will allocate the same physical location for every boot, if booting > > the same kernel and having the same physical memory layout? > > Up to kaslr that might use that location for the kernel image. > But it's the same as allocating from e820 after kaslr. > > And, TBH, I don't have good ideas how to ensure the same physical location > with randomization of the physical address of the kernel image. > I tried this approach and it unfortunately picks a different physical location every time :-( So it is either adding to e820 tables or we create a new way to allocate memory at early boot up. Below is the patch I used. -- Steve diff --git a/include/linux/mm.h b/include/linux/mm.h index b6bdaa18b9e9..74aaf0bcb363 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -4204,4 +4204,6 @@ static inline bool pfn_is_unaccepted_memory(unsigned long pfn) return range_contains_unaccepted_memory(paddr, paddr + PAGE_SIZE); } +int memmap_named(const char *name, unsigned long *start, unsigned long *size); + #endif /* _LINUX_MM_H */ diff --git a/mm/memblock.c b/mm/memblock.c index d09136e040d3..3c015395d262 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2243,6 +2243,101 @@ void __init memblock_free_all(void) pages = free_low_memory_core_early(); totalram_pages_add(pages); } +/* For wildcard memory requests, have a table to find them later */ +#define MEMMAP_MAX_MAPS 8 +#define MEMMAP_NAME_SIZE 16 +struct memmap_map { + char name[MEMMAP_NAME_SIZE]; + unsigned long start; + unsigned long size; +}; +static struct memmap_map memmap_list[MEMMAP_MAX_MAPS] __initdata; +static int memmap_size __initdata; + +/* Add wildcard region with a lookup name */ +static int __init memmap_add(u64 start, u64 size, const char *name) +{ + struct memmap_map *map; + + if (!name || !name[0] || strlen(name) >= MEMMAP_NAME_SIZE) + return -EINVAL; + + if (memmap_size >= MEMMAP_MAX_MAPS) + return -1; + + map = &memmap_list[memmap_size++]; + map->start = start; + map->size = size; + strcpy(map->name, name); + return 0; +} + +/** + * memmap_named - Find a wildcard region with a given name + * @name: The name that is attached to a wildcard region + * @start: If found, holds the start address + * @size: If found, holds the size of the address. + * + * Returns: 1 if found or 0 if not found. + */ +int __init memmap_named(const char *name, unsigned long *start, unsigned long *size) +{ + struct memmap_map *map; + int i; + + for (i = 0; i < memmap_size; i++) { + map = &memmap_list[i]; + if (!map->size) + continue; + if (strcmp(name, map->name) == 0) { + *start = map->start; + *size = map->size; + return 1; + } + } + return 0; +} + +/* + * Parse early_reserve_mem=nn:align:name + */ +static int __init early_reserve_mem(char *p) +{ + phys_addr_t start, size, align; + char *oldp; + int err; + + if (!p) + return -EINVAL; + + oldp = p; + size = memparse(p, &p); + if (p == oldp) + return -EINVAL; + + if (*p != ':') + return -EINVAL; + + align = memparse(p+1, &p); + if (*p != ':') + return -EINVAL; + + start = memblock_phys_alloc(size, align); + if (!start) + return -ENOMEM; + + p++; + err = memmap_add(start, size, p); + if (err) { + memblock_phys_free(start, size); + return err; + } + + p += strlen(p); + + return *p == '\0' ? 0: -EINVAL; +} +__setup("early_reserve_mem=", early_reserve_mem); #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_ARCH_KEEP_MEMBLOCK) static const char * const flagname[] = {