Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp83350lqp; Tue, 11 Jun 2024 15:47:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWmH5CKsvrO7uBXC6IlYdujEH8KTP4SoZ0IO0sm2N+zbgI4dPcLYPYilDpLStLMBiD8m+w8CniinYvRsSpWbOR7l25w8KZKligOxLbARw== X-Google-Smtp-Source: AGHT+IEPPWLSqiayRqqqh129K7XtbIPPLl1HO4f7hM2aPKbxW/KmyI9zdkUvgxjcVinsMSk6K/Sz X-Received: by 2002:a05:6a20:a122:b0:1b6:a7c5:4fac with SMTP id adf61e73a8af0-1b8a9c6bb7bmr369303637.38.1718146030888; Tue, 11 Jun 2024 15:47:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718146030; cv=pass; d=google.com; s=arc-20160816; b=YYYpT6iidjfnLhVZlUqo50AG8ZNwdhVZP7ImR/3l7AHuBqYp44FwUsCmgvmjAyAsv9 zfhsWp11OfnWLm/+cDpTE+FTXN0MGxnHlp1kInPMGTVZiArdfzpBB7KV7TKwVnxCnVnT dfmjanb3kXjmPLwYDqPTE9j8b/jL24K3gIZYeVbXpSD5jP3drgwSP1WEd3p7iTtp1T6x P07WdOxnSqFklNppFvePg/z3zsjjz+b8SZHmbdLEG7Ouj+dZ+10x1WmMwUUMilJAZub/ 2+yJ0JPxtEguMG9P5ufvdKprMO2u8ISruXQde+TH1Jkz4hCw4QlDavFlhmIufYP3jol9 wa6Q== 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=XuR9Jv6N8rFckFCZYDxz8ldE5lfU6ItJ8o6UFf0VQuc=; fh=kPTvN3w9H0NqN7Y6AcSaj8+yy/Rle0aH14Nn+S5exuc=; b=CQTIiOErmuHInY6kS3UEIcq5O9fkUQJhWbWTwsFzUl4/HyiojVDGkO21Nh+ruphiEW 02PIxDiRkMciYTBZFA1y/uJ2nl8tmCKgjuFTjexaZcMk8xmcy1dm2/xy6J///pENvbcx 09Gld8gBfzKisFnJmtRCgDoMLcFvXjKuIJtfbLNue4QWM3d77gTOO7NVz65oeCwx8xrL IhlydBiBek+LTPevgBve/DuBVzFFVbuHnrRVZok14GjjScQKujcRHPEeZ9D5EQWPRYyR wfPbmeuuRppHIx7HhL6VIM164IanMSgcaIet7x+0vvbjy6HJxJaps5He2bb8bQP4sxVt s2Rw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-210668-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210668-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c4a765d532si181315a91.157.2024.06.11.15.47.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 15:47:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210668-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-210668-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210668-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 96BC0B20EA1 for ; Tue, 11 Jun 2024 22:36:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0E411553B5; Tue, 11 Jun 2024 22:36:30 +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 6587B15278E; Tue, 11 Jun 2024 22:36:30 +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=1718145390; cv=none; b=QvqWY8o4LD+R9K536C8FBySfbkMh+CZQI0x+9VLb+ox32XZFH1IHMDaz+F0cjF5mMezFupaR5Tb0lk032RHn0ys05r36CiyB7Z0A9EiEkv9OqPyUue2zXgv3SLKqEBb7YYdXKnndSceHqwX11AdGqgWoHmpwdzdkZy6RBYKP0lA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718145390; c=relaxed/simple; bh=oz2WDd+8rgQTA6tAKBoiy2olZlmCeF6niFRohD0MmbA=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E0XhJKvPyJw5iLnbc45REMKpieL6CYNwqEWOp5vdcR8v+GdAtZrrTFcSsTciu35UW7OegBeTMW985PTGoC9QsZh5HOopMfWfFjvydDZM1dXYTR3Ubf8rgFVi6oVPoe9rqtU6/TeFxQ0dVKZFBs7ga1LwjDHO32Nc5A3PHj9HTDI= 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 E625CC2BD10; Tue, 11 Jun 2024 22:36:26 +0000 (UTC) Date: Tue, 11 Jun 2024 18:36:43 -0400 From: Steven Rostedt To: Guenter Roeck 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, Ross Zwisler , wklin@google.com, Vineeth Remanan Pillai , Joel Fernandes , Suleiman Souhlal , Linus Torvalds , Catalin Marinas , Will Deacon , Ard Biesheuvel , Mike Rapoport Subject: Re: [PATCH v4 1/2] mm/memblock: Add "reserve_mem" to reserved named memory at boot up Message-ID: <20240611183643.0327ef5b@gandalf.local.home> In-Reply-To: References: <20240611215610.548854415@goodmis.org> <20240611215801.443593152@goodmis.org> X-Mailer: Claws Mail 3.20.0git84 (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 Tue, 11 Jun 2024 15:26:05 -0700 Guenter Roeck wrote: > > diff --git a/mm/memblock.c b/mm/memblock.c > > index d09136e040d3..044ddce8f085 100644 > > --- a/mm/memblock.c > > +++ b/mm/memblock.c > > @@ -2244,6 +2244,121 @@ void __init memblock_free_all(void) > > totalram_pages_add(pages); > > } > > > > +/* Keep a table to reserve named memory */ > > +#define RESERVE_MEM_MAX_ENTRIES 8 > > +#define RESERVE_MEM_NAME_SIZE 16 > > +struct reserve_mem_table { > > + char name[RESERVE_MEM_NAME_SIZE]; > > + phys_addr_t start; > > + phys_addr_t size; > > +}; > > +static struct reserve_mem_table reserved_mem_table[RESERVE_MEM_MAX_ENTRIES]; > > +static int reserved_mem_count; > > + > > +/* Add wildcard region with a lookup name */ > > +static int __init reserved_mem_add(phys_addr_t start, phys_addr_t size, > > + const char *name) > > +{ > > + struct reserve_mem_table *map; > > + > > + if (!name || !name[0] || strlen(name) >= RESERVE_MEM_NAME_SIZE) > > + return -EINVAL; > > + > > I know I am picky, but name is never NULL, and strlen(name) is guaranteed to be > 0. > Personally I'd suggest to check for strlen(name) >= RESERVE_MEM_NAME_SIZE together > with !strlen(name) and drop the duplicate checks here (and, as side effect, avoid > the pointless memory allocation if the name is invalid). Yeah, it's now checked before hand. I'll remove it for v5. > > > + if (reserved_mem_count >= RESERVE_MEM_MAX_ENTRIES) > > + return -1; > > + > > + map = &reserved_mem_table[reserved_mem_count++]; > > + map->start = start; > > + map->size = size; > > + strscpy(map->name, name); > > + return 0; > > +} > > + > > +/* > > + * Parse reserve_mem=nn:align:name > > + */ > > +static int __init reserve_mem(char *p) > > +{ > > + phys_addr_t start, size, align; > > + char *name; > > + char *oldp; > > + int err; > > + > > + if (!p) > > + return -EINVAL; > > + > > + 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) > > Any reason for using <= instead of < ? Nope. Not sure why I did that. :-/ I'll fix that too. Thanks, -- Steve > > Guenter > > > + align = SMP_CACHE_BYTES; > > + > > + name = p + 1; > > + if (!strlen(name)) > > + return -EINVAL; > > + > > + /* Make sure that name has text */ > > + for (p = name; *p; p++) { > > + if (!isspace(*p)) > > + break; > > + } > > + if (!*p) > > + return -EINVAL; > > + > > + start = memblock_phys_alloc(size, align); > > + if (!start) > > + return -ENOMEM; > > + > > + err = reserved_mem_add(start, size, name); > > + if (err) { > > + memblock_phys_free(start, size); > > + return err; > > + } > > + > > + 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",