Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp59066lqp; Fri, 12 Apr 2024 10:22:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUBkZRxYr8SAOzboaBDznHzTeL1MVX5SV0U1bfCiNQtKv1Cr75wcgjsW5JmN+HOy4pJ1J7YmNsMIJJaWIK7WvHOaqguzt1LLu3ejaNBZA== X-Google-Smtp-Source: AGHT+IFWAEpmeYvEP/H/70nXbO7uOcv0RZB0plSwt5/j4e6f65MNkdsf3ASOLOXy11oOwtSjqe/5 X-Received: by 2002:a17:906:3913:b0:a52:2dce:64a6 with SMTP id f19-20020a170906391300b00a522dce64a6mr2076513eje.17.1712942576366; Fri, 12 Apr 2024 10:22:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712942576; cv=pass; d=google.com; s=arc-20160816; b=jdQ7Ki8we8HxnTjovGeYlo0oHKEAHYbgEuhBNu1w8+bvKM+LC9zhypB+zqdpX8pput 9sSxVxzt8tMklYHz1CP3OfcH5dRqO33peKsjGAuClMpNWIp15MXpjCNdfWHvqup7pT3k 1qGH1+wcjBPwH02cqnHUL9TcGDTw85zigz0dA/+NFvTPvHgbgw3eM+XD+V+IiR1nn9VD BhjpS0eCmpOJGJUgxNrXFj9r5P3V0sMT7Z/a76wSwK0nfIWJU8xuZPHu0E2FSQTA1pwM 75g4WDgOXjZtWGmWQis9Gry4VqBURWha0oFF4VBlZjLBaiACyb6DQbJlsHq9/trGoZJM qEHg== 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=Ok7rurcKIRmarBP+tWe6z4ML7EkOHi7xI8Le42mpXJc=; fh=MoZyV+euipI8XTETvVwSKlfeTtJOYwtulmyqaD27NVw=; b=RLSbMn7+MXxl32TCuwVgiYvnaRDndNtsPzFL5q1Z0o7/vjTP6+gu3D0YyUh081xAdu 6co7cLA0lb42DdNWnLPOJBKNqRBZi1GI2vP5JsgHnuptZjpCHffk1sVM7kSXPuz9h6oU /lc674XbYYAtYsRbvhiVihTk5BNeOkQ9jNEvCzWXdAZ1r7z6Prv+EaOhWupuR/pnhwWB E6cH2Nxgbz3EVZ2jBr7nPsR2hJ5vYPfnTULBHYbCpSySLV01fJDmB6L8sFIm76N/EysH tCPczu5AF/oPjeQp+bHVKKvQ04liACaQCmUtJlSR5gByARJyv9arQ9vUr+N9nxROmvZy l/iw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-143121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143121-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r17-20020a170906c29100b00a522962dfecsi1363702ejz.62.2024.04.12.10.22.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 10:22:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-143121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143121-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 am.mirrors.kernel.org (Postfix) with ESMTPS id DA7AB1F22E28 for ; Fri, 12 Apr 2024 17:22:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01E6214D43D; Fri, 12 Apr 2024 17:22:49 +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 4A83C1E53A; Fri, 12 Apr 2024 17:22: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=1712942568; cv=none; b=dJabSdDKL63Wq4w7UKKkUU1k6RBekcXX45Gx4PJMaMIBeVSpNddoqlMjQK9BQpLiFRyhCmopylLxrRS43DP48/+vv/iPEYqkdWC48dOV7xWGDwieSXwmcJWvXUil3HaFGU5FIERMrkFfkAFJPTImLCfoajc7nF/6T+QYUSxIjaA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712942568; c=relaxed/simple; bh=O92YTgEoikgZ6iz+Dkm9PvGOpbulKCx8UBawRe5N7iM=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QlN1Gzcon8ig3UODl8UBUX2hPZFcbp4672Q2EIUCHfuoe8rrz4/Fs4hseKDER7a1pEK40qP66CcX1T63z+AZlMu9HCUVIuaezzxsaaRrPWwIjjGbC/6DXulblMkECeiawTKWTtHMiOtKDXfgibtx4NGauIscoO7w0j2uAIzPUDs= 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 BF76AC2BD11; Fri, 12 Apr 2024 17:22:44 +0000 (UTC) Date: Fri, 12 Apr 2024 13:22:43 -0400 From: Steven Rostedt To: "Guilherme G. Piccoli" Cc: "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: <20240412132243.053ad096@gandalf.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> X-Mailer: Claws Mail 3.19.1 (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 Fri, 12 Apr 2024 09:17:18 -0300 "Guilherme G. Piccoli" wrote: > Thanks Steve, seems a good idea. With that, I could test on kdumpst (the > tool used on Steam Deck), since it relies on modular pstore/ram. Something like this could work. -- Steve diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index a8831ef30c73..878aee8b2399 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -64,61 +65,6 @@ struct e820_table *e820_table __refdata = &e820_table_init; struct e820_table *e820_table_kexec __refdata = &e820_table_kexec_init; struct e820_table *e820_table_firmware __refdata = &e820_table_firmware_init; -/* For wildcard memory requests, have a table to find them later */ -#define E820_MAX_MAPS 8 -#define E820_MAP_NAME_SIZE 16 -struct e820_mmap_map { - char name[E820_MAP_NAME_SIZE]; - u64 start; - u64 size; -}; -static struct e820_mmap_map e820_mmap_list[E820_MAX_MAPS] __initdata; -static int e820_mmap_size __initdata; - -/* Add wildcard region with a lookup name */ -static int __init e820_add_mmap(u64 start, u64 size, const char *name) -{ - struct e820_mmap_map *map; - - if (!name || !name[0] || strlen(name) >= E820_MAP_NAME_SIZE) - return -EINVAL; - - if (e820_mmap_size >= E820_MAX_MAPS) - return -1; - - map = &e820_mmap_list[e820_mmap_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, u64 *start, u64 *size) -{ - struct e820_mmap_map *map; - int i; - - for (i = 0; i < e820_mmap_size; i++) { - map = &e820_mmap_list[i]; - if (!map->size) - continue; - if (strcmp(name, map->name) == 0) { - *start = map->start; - *size = map->size; - return 1; - } - } - return 0; -} - /* For PCI or other memory-mapped resources */ unsigned long pci_mem_start = 0xaeedbabe; #ifdef CONFIG_PCI @@ -1024,6 +970,8 @@ static int __init parse_memmap_one(char *p) e820__range_add(start_at, mem_size, E820_TYPE_RESERVED); } else if (*p == '*') { u64 align; + int ret; + /* Followed by alignment and ':' then the name */ align = memparse(p+1, &p); start_at = e820__region(mem_size, align); @@ -1032,9 +980,10 @@ static int __init parse_memmap_one(char *p) if (*p != ':') return -EINVAL; p++; - e820_add_mmap(start_at, mem_size, p); + ret = memmap_add(start_at, mem_size, p); p += strlen(p); - e820__range_add(start_at, mem_size, E820_TYPE_RESERVED); + if (!ret) + e820__range_add(start_at, mem_size, E820_TYPE_RESERVED); } else if (*p == '!') { start_at = memparse(p+1, &p); e820__range_add(start_at, mem_size, E820_TYPE_PRAM); diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index c200388399fb..22d2e2731dc2 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -919,7 +919,6 @@ static void __init ramoops_register_dummy(void) { struct ramoops_platform_data pdata; -#ifndef MODULE /* Only allowed when builtin */ if (mem_name) { u64 start; @@ -930,7 +929,6 @@ static void __init ramoops_register_dummy(void) mem_size = size; } } -#endif /* * Prepare a dummy platform data structure to carry the module diff --git a/include/linux/mm.h b/include/linux/mm.h index cf9b34454c6f..6ce1c6929d1f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -4203,5 +4203,6 @@ static inline bool pfn_is_unaccepted_memory(unsigned long pfn) } int memmap_named(const char *name, u64 *start, u64 *size); +int memmap_add(long start, long size, const char *name); #endif /* _LINUX_MM_H */ diff --git a/mm/memory.c b/mm/memory.c index 7a29f17df7c1..fe054e1bb678 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -120,12 +120,6 @@ static bool vmf_orig_pte_uffd_wp(struct vm_fault *vmf) return pte_marker_uffd_wp(vmf->orig_pte); } -int __init __weak memmap_named(const char *name, u64 *start, u64 *size) -{ - pr_info("Kernel command line: memmap=nn*align:name not supported on this kernel"); - /* zero means not found */ - return 0; -} /* * A number of key systems in x86 including ioremap() rely on the assumption diff --git a/mm/mm_init.c b/mm/mm_init.c index 549e76af8f82..e5b729b83fdc 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -154,6 +154,77 @@ static __init int set_mminit_loglevel(char *str) early_param("mminit_loglevel", set_mminit_loglevel); #endif /* CONFIG_DEBUG_MEMORY_INIT */ +/* For wildcard memory requests, have a table to find them later */ +#define MAX_MAPS 8 +#define MAP_NAME_SIZE 16 +struct mmap_map { + char name[MAP_NAME_SIZE]; + long start; + long size; +}; +static struct mmap_map early_mmap_list[MAX_MAPS] __initdata; +static int early_mmap_size __initdata; +static struct mmap_map *mmap_list; + +/* Add wildcard region with a lookup name */ +int memmap_add(long start, long size, const char *name) +{ + struct mmap_map *map; + + if (!name || !name[0] || strlen(name) >= MAP_NAME_SIZE) + return -EINVAL; + + if (early_mmap_size >= MAX_MAPS) + return -1; + + map = &early_mmap_list[early_mmap_size++]; + map->start = start; + map->size = size; + strcpy(map->name, name); + return 0; +} + +static void __init memmap_copy(void) +{ + if (!early_mmap_size) + return; + + mmap_list = kcalloc(early_mmap_size + 1, sizeof(mmap_list), GFP_KERNEL); + if (!mmap_list) + return; + + for (int i = 0; i < early_mmap_size; i++) + mmap_list[i] = early_mmap_list[i]; +} + +/** + * 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 memmap_named(const char *name, u64 *start, u64 *size) +{ + struct mmap_map *map; + + if (!mmap_list) + return 0; + + for (int i = 0; mmap_list[i].name[0]; i++) { + map = &mmap_list[i]; + if (!map->size) + continue; + if (strcmp(name, map->name) == 0) { + *start = map->start; + *size = map->size; + return 1; + } + } + return 0; +} + struct kobject *mm_kobj; #ifdef CONFIG_SMP @@ -2793,4 +2864,5 @@ void __init mm_core_init(void) pti_init(); kmsan_init_runtime(); mm_cache_init(); + memmap_copy(); }