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 DDFFCCEFC23 for ; Tue, 8 Oct 2024 15:17:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 53B2E6B0089; Tue, 8 Oct 2024 11:17:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4EAF26B008A; Tue, 8 Oct 2024 11:17:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B2676B008C; Tue, 8 Oct 2024 11:17:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1EE826B008A for ; Tue, 8 Oct 2024 11:17:35 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B470B140431 for ; Tue, 8 Oct 2024 15:17:33 +0000 (UTC) X-FDA: 82650789228.24.90DFD9E Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by imf09.hostedemail.com (Postfix) with ESMTP id D400014001B for ; Tue, 8 Oct 2024 15:17:32 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b="h/r5VDrt"; spf=pass (imf09.hostedemail.com: domain of gourry@gourry.net designates 209.85.160.182 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728400473; 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=H78KOsXxqZBUvG+QHX45xW+vctWF6+s2zoBWOxIrUFc=; b=Sza+VhA2D8bgbpZby5VmgAu2494Rej8UmN4blxabQe9a11YL8PR6I3SVNHKWEz4le4ayiY wdrkatbygVYsdqWmzQrBrN4WOfQu7f/mnMiOVg6n8egxpXys0S2PktvbdbFFQ+Y0Zjoxpi NtvaqIGpLW7MBNBQT9fvPjqhD/BeAPs= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b="h/r5VDrt"; spf=pass (imf09.hostedemail.com: domain of gourry@gourry.net designates 209.85.160.182 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728400473; a=rsa-sha256; cv=none; b=VMvPNnILU69uTvB1UV6vD585KH++ILpO5oBx5KQjgE/ItUREUtvFwzg8aWXyX+4sWCpXtH IXYPaKOUaoquqtIjrtj+EzI1eHWHoOYa+ETIME/v8OZnZOQLmQWcJwnSOOdG+hE3HWohnK 8NJv0sf/IvlmsPoq71f1zBIGJWs8USo= Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-45f059dcc77so4923951cf.1 for ; Tue, 08 Oct 2024 08:17:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1728400652; x=1729005452; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=H78KOsXxqZBUvG+QHX45xW+vctWF6+s2zoBWOxIrUFc=; b=h/r5VDrtvivTTonqAkxeZi9TAy0xtXsCA4fUJ18wvG9khMXWtb/KzwvMH/0s7nGgRJ yWpa49ZWSBPhX1SygtJKxNED/ybP745vrNkl5pW+n86Uo1cVXOzzV3HKvjI3+i6kOY9h XDWaYzu4vR2AN60paWe0ps1bkfHvw9j7dI3UyJkkjfm8Qv7ljTJiNn55+ttPtPe1WM0+ K862dAJ9GfCHurN25dfy2Wli993/0Tc1WjwvViJcWrc9jdze5p7V0DFa1isj+KkCMoN0 lR9+b//q8PB7QyxoqGzkkSdEeBmLK0rCaTFHhRjFrUs+nZMrqB7vUBKK4jygpKEFDtqz HX0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728400652; x=1729005452; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=H78KOsXxqZBUvG+QHX45xW+vctWF6+s2zoBWOxIrUFc=; b=bleiTgnFU63AeV19+ckzDSJ1FdAsFDniaAF5AKsomLOlN7iSZAQg0XWaa+XOBAmjBc BwUKApmx5TpgfGhshdIGGDNUKXi2vs2KNfWx5jWC/yISWt6+xtStH4heAFy9vlpVJ9aK 9dnjFQ+/H/IwbX9DcpJWnOOQmHQ3Cze5rNUwfc+QaugzI7ksGvlP+2XeorSrMVt6+q8j unLgQjR9V2v5mTQK4Zg1NiQl2AN9WjBt+7P9PcjrnCTCZ/kPFbIcYOrAJGVrt+Gqk7bU KrOmAxsIf0WDZdu4lF8ImoVo30l4/GHhcgb5X9el8IJWka7SGHWtIdc44MgWvbjEe7q0 TO7g== X-Forwarded-Encrypted: i=1; AJvYcCUHygDq4f8gU9PpS4I+SqIJm74e+svFP5Wfnw2Hn29II7RoV19+SA5g9P1ppTQHBNfceoOW3Qk7MA==@kvack.org X-Gm-Message-State: AOJu0Yy0EejO7CpyR8pKtNORPEae35t7f7weppRe0KeTMfP6+aUy8wrX kmkFo/AHDDJR6IcTvS64WMe/pSedvgw1Ab2MTsHMr+LGQJfqPOvTuDmLK1/ZZHY= X-Google-Smtp-Source: AGHT+IG7uM3piKF3jfYxHaDkswnZHDMGTup6PjRZnneyV4fyTZle4+CCL0LEcgUKcnOhtQbrxRwlJA== X-Received: by 2002:a05:622a:5798:b0:458:5357:dc19 with SMTP id d75a77b69052e-45d9bafaefbmr235642641cf.49.1728400651702; Tue, 08 Oct 2024 08:17:31 -0700 (PDT) Received: from PC2K9PVX.TheFacebook.com (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45efcedd9dcsm6790911cf.91.2024.10.08.08.17.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 08:17:31 -0700 (PDT) Date: Tue, 8 Oct 2024 11:17:21 -0400 From: Gregory Price To: Ira Weiny Cc: linux-cxl@vger.kernel.org, x86@kernel.org, linux-mm@kvack.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, david@redhat.com, osalvador@suse.de, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, dan.j.williams@intel.com, Jonathan.Cameron@huawei.com, alison.schofield@intel.com, rrichter@amd.com, terry.bowman@amd.com, lenb@kernel.org, dave.jiang@intel.com Subject: Re: [PATCH 3/3] acpi,srat: reduce memory block size if CFMWS has a smaller alignment Message-ID: References: <20241008044355.4325-1-gourry@gourry.net> <20241008044355.4325-4-gourry@gourry.net> <6705489bdc79b_125a729415@iweiny-mobl.notmuch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6705489bdc79b_125a729415@iweiny-mobl.notmuch> X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D400014001B X-Stat-Signature: f77k3ipxo18paps76ewr4eqeq3qm5y4m X-Rspam-User: X-HE-Tag: 1728400652-933961 X-HE-Meta: U2FsdGVkX1+sAvqDPTGz0tlD+LoJC837lpoIGIMF0CKwMGLtORVx1W4aqpxov7cHpS8tRbNn3QNRUP4TO5mE6HJI+LDFqIrY5o+/3NvUdVA/KuqsRYJOp+cwbC+wwA6kTIrnH43GPF80tNWkTb98MJ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z6eEVDKzWIkTtWKgFSjhKH5Gfr0wY5ruKhHDnSK1oWRX+oy9Zq1QZvsafVADptjyMWBAGptYP7hx7ecScx5//51Sert9SyRTvZ13aUibIl+KueqQu9pF5yR41LwaRH/Y7zNdkyhrqYIaxrZNvmEIaG++Q== 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 Tue, Oct 08, 2024 at 09:58:35AM -0500, Ira Weiny wrote: > Gregory Price wrote: > > The CXL Fixed Memory Window allows for memory aligned down to the > > size of 256MB. However, by default on x86, memory blocks increase > > in size as total System RAM capacity increases. On x86, this caps > > out at 2G when 64GB of System RAM is reached. > > > > When the CFMWS regions are not aligned to memory block size, this > > results in lost capacity on either side of the alignment. > > > > Parse all CFMWS to detect the largest common denomenator among all > > regions, and reduce the block size accordingly. > > > > This can only be done when MEMORY_HOTPLUG and SPARSEMEM configs are > > enabled, but the surrounding code may not necessarily require these > > configs, so build accordingly. > > > > Suggested-by: Dan Williams > > Signed-off-by: Gregory Price > > --- > > drivers/acpi/numa/srat.c | 48 ++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 48 insertions(+) > > > > diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c > > index 44f91f2c6c5d..9367d36eba9a 100644 > > --- a/drivers/acpi/numa/srat.c > > +++ b/drivers/acpi/numa/srat.c > > @@ -14,6 +14,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -333,6 +334,37 @@ acpi_parse_memory_affinity(union acpi_subtable_headers *header, > > return 0; > > } > > > > +#if defined(CONFIG_MEMORY_HOTPLUG) > > Generally we avoid config defines in *.c files... See more below. > > > +/* > > + * CXL allows CFMW to be aligned along 256MB boundaries, but large memory > > + * systems default to larger alignments (2GB on x86). Misalignments can > > + * cause some capacity to become unreachable. Calculate the largest supported > > + * alignment for all CFMW to maximize the amount of mappable capacity. > > + */ > > +static int __init acpi_align_cfmws(union acpi_subtable_headers *header, > > + void *arg, const unsigned long table_end) > > +{ > > + struct acpi_cedt_cfmws *cfmws = (struct acpi_cedt_cfmws *)header; > > + u64 start = cfmws->base_hpa; > > + u64 size = cfmws->window_size; > > + unsigned long *fin_bz = arg; > > + unsigned long bz; > > + > > + for (bz = SZ_64T; bz >= SZ_256M; bz >>= 1) { > > + if (IS_ALIGNED(start, bz) && IS_ALIGNED(size, bz)) > > + break; > > + } > > + > > + /* Only adjust downward, we never want to increase block size */ > > + if (bz < *fin_bz && bz >= SZ_256M) > > + *fin_bz = bz; > > + else if (bz < SZ_256M) > > + pr_err("CFMWS: [BIOS BUG] base/size alignment violates spec\n"); > > + > > + return 0; > > +} > > +#endif /* defined(CONFIG_MEMORY_HOTPLUG) */ > > + > > static int __init acpi_parse_cfmws(union acpi_subtable_headers *header, > > void *arg, const unsigned long table_end) > > { > > @@ -501,6 +533,10 @@ acpi_table_parse_srat(enum acpi_srat_type id, > > int __init acpi_numa_init(void) > > { > > int i, fake_pxm, cnt = 0; > > +#if defined(CONFIG_MEMORY_HOTPLUG) > > + unsigned long block_sz = memory_block_size_bytes(); > > To help address David's comment as well; > > Is there a way to scan all the alignments of the windows and pass the > desired alignment to the arch in a new call and have the arch determine if > changing the order is ok? > At least on x86, it's only OK during init, so it would probably look like setting a static bit (like the global value in x86) and just refusing to update once it is locked. I could implement that on the x86 side as an example. FWIW: this was Dan's suggestion (quoting discord, sorry Dan!) ``` I am assuming we would call it here drivers/acpi/numa/srat.c::acpi_parse_cfmws() which should be before page-allocator init ``` It's only safe before page-allocator init (i.e. once blocks start getting populated and used), and this area occurs before that. > Also the call to the arch would be a noop for !CONFIG_MEMORY_HOTPLUG which > cleans up this function WRT CONFIG_MEMORY_HOTPLUG. > > Ira > The ifdefs are a nasty result of the HOTPLUG and SPARSEMEM configs being, from my perview, horrendously inconsistent throughout the system. As an example, MIN_MEMORY_BLOCK_SIZE depends on SECTION_SIZE_BITS which on some architectures is dependent on CONFIG_SPARSEMEM, and on others is defined unconditionally. Compound this with memblock usage appearing to imply CONFIG_MEMORY_HOTPLUG which implies CONFIG_SPARSEMEM (see drivers/base/memory.c) - but mm/memblock.c makes no such assumption. The result of this is that if you extern these functions and build x86 with each combination of HOTPLUG/SPARSMEM on/off, it builds - but loongarch (and others) fail to build because SECTION_SIZE_BITS doesn't get defined in some configurations. It's not clear if removing those ifdefs from those archs is "correct" (for some definition of correct) and I didn't want to increase scope. So it's really not clear how to wire this all up. I spent the better part of a week trying to detangle this mess just to get things building successfully in LKP and decided to just add the ifdefs to get it out and get opinions on the issue :[ > > + unsigned long cfmw_align = block_sz; > > +#endif /* defined(CONFIG_MEMORY_HOTPLUG) */ > > > > if (acpi_disabled) > > return -EINVAL; > > @@ -552,6 +588,18 @@ int __init acpi_numa_init(void) > > } > > last_real_pxm = fake_pxm; > > fake_pxm++; > > + > > +#if defined(CONFIG_MEMORY_HOTPLUG) > > + /* Calculate and set largest supported memory block size alignment */ > > + acpi_table_parse_cedt(ACPI_CEDT_TYPE_CFMWS, acpi_align_cfmws, > > + &cfmw_align); > > + if (cfmw_align < block_sz && cfmw_align >= SZ_256M) { > > + if (set_memory_block_size_order(ffs(cfmw_align)-1)) > > + pr_warn("CFMWS: Unable to adjust memory block size\n"); > > + } > > +#endif /* defined(CONFIG_MEMORY_HOTPLUG) */ > > + > > + /* Then parse and fill the numa nodes with the described memory */ > > acpi_table_parse_cedt(ACPI_CEDT_TYPE_CFMWS, acpi_parse_cfmws, > > &fake_pxm); > > > > -- > > 2.43.0 > > > > > >