From patchwork Wed Nov 6 15:58:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13865122 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 10C7CD59F4A for ; Wed, 6 Nov 2024 15:59:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88A786B00AA; Wed, 6 Nov 2024 10:59:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 813396B00AC; Wed, 6 Nov 2024 10:59:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DDDA6B00AD; Wed, 6 Nov 2024 10:59:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 289496B00AA for ; Wed, 6 Nov 2024 10:59:05 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A4D91ADDBA for ; Wed, 6 Nov 2024 15:59:04 +0000 (UTC) X-FDA: 82756126614.17.DE36C20 Received: from mail-vk1-f171.google.com (mail-vk1-f171.google.com [209.85.221.171]) by imf14.hostedemail.com (Postfix) with ESMTP id 66E70100018 for ; Wed, 6 Nov 2024 15:58:24 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=WceVXzF8; spf=pass (imf14.hostedemail.com: domain of gourry@gourry.net designates 209.85.221.171 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=1730908605; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GrV9O4GPEUiGe4j9uKnxvw7X+oP7rfAOpfBnY6P0I08=; b=2EqecmOETPXRwU8xwoqxZGA6n/E+9XphlcUpm5EFSY0CGq6GyUCImAn8R9QFqxW2HCtsmc kMfiZW2blj0YAzFk/YCpDSixxU9oNLkBx/iximG4/AnOBUehPE3Q8hygz9D1vZJ0VeM9x0 VE6LBJfhEe0ctY6YQcQfFoplnNNvOW0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730908605; a=rsa-sha256; cv=none; b=nPxIsZHwUF1Njd4i3Y/83olmS7XZRdPSVpf/WN97kbFiDw7ByPAOFQ+TJgspR1S/AnvvQz EYEUVl4JtlJQtr/WLZmpsOL6wedTVw/FzDzxW1d4wtxSF4dnc9ccYJlwonx7+Jofumu7j+ oDyjggIYjePPym6e+oQKjtVRZdZO/oo= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=WceVXzF8; spf=pass (imf14.hostedemail.com: domain of gourry@gourry.net designates 209.85.221.171 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none Received: by mail-vk1-f171.google.com with SMTP id 71dfb90a1353d-5139cd01814so1733077e0c.0 for ; Wed, 06 Nov 2024 07:59:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1730908742; x=1731513542; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GrV9O4GPEUiGe4j9uKnxvw7X+oP7rfAOpfBnY6P0I08=; b=WceVXzF8T3f9u+RxtWYoNNshY+zqb5Zr9OdzFoBCVVT2PsQ8ShXIrBa/PseXrP5J3T BFLlharFluqSqmaIeZttJ4kwAHwHcVv+Wsv0Tif8ZqaSxk9DhUot1wnigcq5dcWtL0dQ 0DdwIc0bx6b5qCDCch2ZhYL685H1oHqZJVUeYESW9txvi98R8om4NBKVQ48QrfU8q0zw zQqSjHyjJRtLAab2se3yNeR0wFh9pDcE17Srx8qJz7leNoKrVKUEZeJ3Rk8LOzCsMq3m YtEU4/TxFm5JzUW/C8++fbUPQvTVpDYXsGOU3Wpn4XaUlkETI+Ei9mRcqxr9s4V9LhOP 2xLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730908742; x=1731513542; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GrV9O4GPEUiGe4j9uKnxvw7X+oP7rfAOpfBnY6P0I08=; b=w5L1AQ+p/ofoW7fFID5gyGA7zYEmw3SVe6+aO2SfwKWEyNJEvt9a72ZpI8yXcfI+zJ SzQmFBcyLYu5/11kWW8VYBbZiLtva247n/2sqWiG42wzOMZHs2F/Zkrobz4WzDoVd4tK R8WFai6p1p3kTgJAObj+kMQSc4dCxcVMc9c+O18YPaKscPgWCPFu0xOnMBq4f4MhF+sa VtiVpQIfNvisqrlFMezOUY4mMxFc48l5jfXLZnI23xLQZVG3kB0UHkE0GCxh+iuQZp/m pnCFcntc09PC/kqfulj6lIwCp6l6j7dFFbwXAxJlN5bbEwF5dcjhl1YsnhyomvSQB+Ll 51eA== X-Forwarded-Encrypted: i=1; AJvYcCUH6mXlLUn4D+K2Vokp670k1SMT6LWVCNFbmLquwRMWUbC7eNyJ+/FXcwtdVC5UGApnqqbbkQZaww==@kvack.org X-Gm-Message-State: AOJu0YyQbh2A1PixFOdL+MyEgJyOMme8nh7CzaeAcp8qDJzM396Hb/BE oX80BaineTFW5mcnUvEtmVCVWT/BMqf7LzSBmcbgrmBcv2xBuHwD0oSoG4XhMHw= X-Google-Smtp-Source: AGHT+IFsdN7WBxVaMsC4Loys1Mpdq5x23y2sQKFk/taNoch7FUZg+El0slCCEmCVOauncv36ulU/bg== X-Received: by 2002:a05:6122:2a41:b0:4f6:aa3e:aa4c with SMTP id 71dfb90a1353d-51014ff7a70mr36295778e0c.3.1730908741730; Wed, 06 Nov 2024 07:59:01 -0800 (PST) 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 af79cd13be357-7b2f39f7b85sm641377285a.31.2024.11.06.07.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 07:59:01 -0800 (PST) From: Gregory Price To: x86@kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org Cc: linux-cxl@vger.kernel.org, kernel-team@meta.com, Jonathan.Cameron@huawei.com, dan.j.williams@intel.com, rrichter@amd.com, Terry.Bowman@amd.com, dave.jiang@intel.com, ira.weiny@intel.com, alison.schofield@intel.com, gourry@gourry.net, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, rafael@kernel.org, lenb@kernel.org, david@redhat.com, osalvador@suse.de, gregkh@linuxfoundation.org, akpm@linux-foundation.org, rppt@kernel.org Subject: [PATCH v6 1/3] memory: implement memory_block_advise/probe_max_size Date: Wed, 6 Nov 2024 10:58:45 -0500 Message-ID: <20241106155847.7985-2-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241106155847.7985-1-gourry@gourry.net> References: <20241106155847.7985-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 66E70100018 X-Stat-Signature: zhs4icgnfr1expnpb7761yt5wjyem1qt X-HE-Tag: 1730908704-782427 X-HE-Meta: U2FsdGVkX187nEE1pCTPMPPAQjKzTQQNa6wzpGGW0R6qSaG3ZbCAiJA9zns5XmyKx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kSqAayI44UbcW/5M3Mlj+gvRDNUsvmOzX8lpiGZNdGtPAlDdXRCE3M2f0zj/Iq7advZyxLwZRpbPlfJCLOCQfhfGDjV3I91qY22YqY4UBp0hb94LgWM3hi0YUSyn6mdVMRXOWEsQmW2d67NOv5rpYuy/Qc8pniVs6e2mLqaRkFcd1WoEMX5sc0U0of7z5lEhg39LkF9t9WF8DsT92Aon7L6pFJ51LvWBsmw49FAHP80ZwsAZ8iJoFMNlA= 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: Hotplug memory sources may have opinions on what the memblock size should be - usually for alignment purposes. For example, CXL memory extents can be 256MB with a matching alignment. If this size/alignment is smaller than the block size, it can result in stranded capacity. Implement memory_block_advise_max_size for use prior to allocator init, for software to advise the system on the max block size. Implement memory_block_probe_max_size for use by arch init code to calculate the best block size. Use of advice is architecture defined. The probe value can never change after first probe. Calls to advise after probe will return -EBUSY to aid debugging. On systems without hotplug, always return -ENODEV and 0 respectively. Suggested-by: Ira Weiny Signed-off-by: Gregory Price Acked-by: David Hildenbrand Acked-by: Mike Rapoport (Microsoft) --- drivers/base/memory.c | 53 ++++++++++++++++++++++++++++++++++++++++++ include/linux/memory.h | 10 ++++++++ 2 files changed, 63 insertions(+) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 67858eeb92ed..835793150b41 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -110,6 +110,59 @@ static void memory_block_release(struct device *dev) kfree(mem); } + +/* Max block size to be set by memory_block_advise_max_size */ +static unsigned long memory_block_advised_size; +static bool memory_block_advised_size_queried; + +/** + * memory_block_advise_max_size() - advise memory hotplug on the max suggested + * block size, usually for alignment. + * @size: suggestion for maximum block size. must be aligned on power of 2. + * + * Early boot software (pre-allocator init) may advise archs on the max block + * size. This value can only decrease after initialization, as the intent is + * to identify the largest supported alignment for all sources. + * + * Use of this value is arch-defined, as is min/max block size. + * + * Return: 0 on success + * -EINVAL if size is 0 or not pow2 aligned + * -EBUSY if value has already been probed + */ +int __init memory_block_advise_max_size(unsigned long size) +{ + if (!size || !is_power_of_2(size)) + return -EINVAL; + + if (memory_block_advised_size_queried) + return -EBUSY; + + if (memory_block_advised_size) { + memory_block_advised_size = min(memory_block_advised_size, + size); + } else { + memory_block_advised_size = size; + } + + return 0; +} + +/** + * memory_block_advised_max_size() - query advised max hotplug block size. + * + * After the first call, the value can never change. Callers looking for the + * actual block size should use memory_block_size_bytes. This interface is + * intended for use by arch-init when initializing the hotplug block size. + * + * Return: advised size in bytes, or 0 if never set. + */ +unsigned long memory_block_advised_max_size(void) +{ + memory_block_advised_size_queried = true; + return memory_block_advised_size; +} + unsigned long __weak memory_block_size_bytes(void) { return MIN_MEMORY_BLOCK_SIZE; diff --git a/include/linux/memory.h b/include/linux/memory.h index c0afee5d126e..8202d0efbf46 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -149,6 +149,14 @@ static inline int hotplug_memory_notifier(notifier_fn_t fn, int pri) { return 0; } +static inline int memory_block_advise_max_size(unsigned long size) +{ + return -ENODEV; +} +static inline unsigned long memory_block_advised_max_size(void) +{ + return 0; +} #else /* CONFIG_MEMORY_HOTPLUG */ extern int register_memory_notifier(struct notifier_block *nb); extern void unregister_memory_notifier(struct notifier_block *nb); @@ -181,6 +189,8 @@ int walk_dynamic_memory_groups(int nid, walk_memory_groups_func_t func, void memory_block_add_nid(struct memory_block *mem, int nid, enum meminit_context context); #endif /* CONFIG_NUMA */ +int memory_block_advise_max_size(unsigned long size); +unsigned long memory_block_advised_max_size(void); #endif /* CONFIG_MEMORY_HOTPLUG */ /* From patchwork Wed Nov 6 15:58:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13865123 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 13ABAD59F49 for ; Wed, 6 Nov 2024 15:59:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6E326B00AD; Wed, 6 Nov 2024 10:59:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CCFCC6B00AF; Wed, 6 Nov 2024 10:59:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD2E56B00B0; Wed, 6 Nov 2024 10:59:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 851C16B00AD for ; Wed, 6 Nov 2024 10:59:07 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2D2C012036A for ; Wed, 6 Nov 2024 15:59:07 +0000 (UTC) X-FDA: 82756128042.10.1585026 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by imf19.hostedemail.com (Postfix) with ESMTP id 21FD61A0007 for ; Wed, 6 Nov 2024 15:58:21 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=GF3i8cFZ; dmarc=none; spf=pass (imf19.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.177 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730908686; a=rsa-sha256; cv=none; b=DjLUhOnz82QqaD1NleaZcguBYIQwRdT51bNbkQeO/jYCKC5optsvCIE6XUrePzBs/02JyH mS4/FkS+aZU8J5SOdbn52VFK/C8lcL5jqEizSCQbfj2FnsXA4g4y/6zXHznnk5hWgtJYTh aUyknkMH1pC4kwuhW4zO9718rU5zMSE= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=GF3i8cFZ; dmarc=none; spf=pass (imf19.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.177 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730908686; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DhjUN4fArKWWoXRi7BXSpLcpyo3J42V+ZDp+ucOnHvE=; b=SOtfBz5EJ1dAxUAM7YAliiy0b5AHQ6b6YDoeCyMrqwLqm8Dr73ye3jx/tVaa/Jkle3m3FN 90i8FFGHKSRkKZSyRSmYlvPd6KBOt6ViB2zfXTCV4koHE6MtpmQxj9kxdV4JcS+l01svl1 F853eCzgmi9Ba6KxaV3SU2VT3SZJlPA= Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-7b15d330ce1so503504985a.1 for ; Wed, 06 Nov 2024 07:59:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1730908744; x=1731513544; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DhjUN4fArKWWoXRi7BXSpLcpyo3J42V+ZDp+ucOnHvE=; b=GF3i8cFZYbNuuo2Ig7vUF9KoajHr8286e4/MtonU8J+ZzkqxmieayTGQtDhjZ1Oh/+ VIZeHdqUH0pk9+21U9EPhmFKF3diwJAx/Y2BH2jZbZ1rmNiADjxfEgQLdmgmfLNLTXJ1 2CMmNxXWjHOB8ZEmEcne7sLzChVU5CPg5ck9k7ybs9tzXTrVS8pqdAFjgLxZpeIsYKMM gdPVuWctN71NxUs1mD1IkmEb73TmAgYM72ZWiuG5vPhegZPFxzjhwMO8bzS9XAa4pEvh 8MFy9kBlNFnt5xeDHXe2e21lMhlmF6W2CGWtPBqwV/ZpQhBhLnfmTCaoVbYHJh9WTQ9e TzhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730908744; x=1731513544; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DhjUN4fArKWWoXRi7BXSpLcpyo3J42V+ZDp+ucOnHvE=; b=anr24dFqtdFfTZjyaABfNABOUx21YI4AF3gHUrGxxRcJYMsuhXve1TSEVniTfZgVXs ExI/sBWWnQBUati0w6tVyrfyiNpbYT0daPQgjBI/rWJa3lxeNHpqp1+7y+QbzO27vI2G KcKctd2sbr7dSZN8KHJkvvlIActODJ210BVe2SuGjCM+GA7bwCeG2PSI130Ns5WBubFL IUX/QefuzCk9X9S46NvXbwTKKKTf6/f327dacahEDVyXiBi1WkEfFSM3DjIT6FoE5wVe uUzq+gsBpqeVoiEj/hAORO9OjGbLPYEzjUpD6JHbfKFnbbkqcr1rq3qbZXbFCfTeDVfT BGOA== X-Forwarded-Encrypted: i=1; AJvYcCWg+7VevQ6bZJYif4r7CTMUEOZnf4UDJ6Tj+dAMmGWXX9r8tGqmeKXZ1xo8FOYH+KEfXpC1ZVBl7g==@kvack.org X-Gm-Message-State: AOJu0Yy6FbFsejmQ06Y8NsvO1m2jqprksU4bmxSb5s5vY58trbgNFpIv 2ZbPgOZCHQ8/KMtSEI6RxJLFpE2tdkCQi+pAnCoc+ViZOJ0jxhNL+bwGPslG5G4= X-Google-Smtp-Source: AGHT+IGyyNaqJP5GT84XkBpTnZi+GYICvytezSItQpJFP+BO2bYKSnE0l+VTemNGpDBYq2sb9frOVw== X-Received: by 2002:a05:620a:190f:b0:7a9:b456:c5e6 with SMTP id af79cd13be357-7b2f253d534mr3445707985a.42.1730908744203; Wed, 06 Nov 2024 07:59:04 -0800 (PST) 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 af79cd13be357-7b2f39f7b85sm641377285a.31.2024.11.06.07.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 07:59:03 -0800 (PST) From: Gregory Price To: x86@kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org Cc: linux-cxl@vger.kernel.org, kernel-team@meta.com, Jonathan.Cameron@huawei.com, dan.j.williams@intel.com, rrichter@amd.com, Terry.Bowman@amd.com, dave.jiang@intel.com, ira.weiny@intel.com, alison.schofield@intel.com, gourry@gourry.net, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, rafael@kernel.org, lenb@kernel.org, david@redhat.com, osalvador@suse.de, gregkh@linuxfoundation.org, akpm@linux-foundation.org, rppt@kernel.org Subject: [PATCH v6 2/3] x86: probe memory block size advisement value during mm init Date: Wed, 6 Nov 2024 10:58:46 -0500 Message-ID: <20241106155847.7985-3-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241106155847.7985-1-gourry@gourry.net> References: <20241106155847.7985-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 21FD61A0007 X-Rspamd-Server: rspam11 X-Stat-Signature: 3mh4xunoqhc66a347z61w6o1y9wh9fhp X-HE-Tag: 1730908701-705408 X-HE-Meta: U2FsdGVkX18dmlQ+IBPnez1edmKQf02ZpmdizWjmjkc26g3qlNLnDDOFVcDo8S7R5hkTKiqSPG3x7wvSLEH68aagtWXVOqTF2ItNoygfB4rA5XmDtUXCnIgeihFctfzbz6pzKj05HTy+nTSDw+HfTjMuIrZ5CZUDAviCi+13Tiavaj97eRbjFVKbeEVkrs2au9T+25FEwboHXGZ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AVHtMLsRzO0xGxUcM5JVXZC+YSD6MEaKEUad8gtxQvzTHCHBOnNTS7ccDbrIqAhwnMzJbCA== 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: Systems with hotplug may provide an advisement value on what the memblock size should be. Probe this value when the rest of the configuration values are considered. The new heuristic is as follows 1) set_memory_block_size_order value if already set (cmdline param) 2) minimum block size if memory is less than large block limit 3) if no hotplug advice: Max block size if system is bare-metal, otherwise use end of memory alignment. 4) if hotplug advice: lesser of advice and end of memory alignment. Convert to cpu_feature_enabled() while at it.[1] [1] https://lore.kernel.org/all/20241031103401.GBZyNdGQ-ZyXKyzC_z@fat_crate.local/ Suggested-by: Borislav Petkov Suggested-by: David Hildenbrand Signed-off-by: Gregory Price Acked-by: David Hildenbrand Acked-by: Dave Hansen Acked-by: Mike Rapoport (Microsoft) --- arch/x86/mm/init_64.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index ff253648706f..2622dc7c78ba 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1452,16 +1452,21 @@ static unsigned long probe_memory_block_size(void) } /* - * Use max block size to minimize overhead on bare metal, where - * alignment for memory hotplug isn't a concern. + * When hotplug alignment is not a concern, maximize blocksize + * to minimize overhead. Otherwise, align to the lesser of advice + * alignment and end of memory alignment. */ - if (!boot_cpu_has(X86_FEATURE_HYPERVISOR)) { + bz = memory_block_advised_max_size(); + if (!bz) { bz = MAX_BLOCK_SIZE; - goto done; + if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) + goto done; + } else { + bz = max(min(bz, MAX_BLOCK_SIZE), MIN_MEMORY_BLOCK_SIZE); } /* Find the largest allowed block size that aligns to memory end */ - for (bz = MAX_BLOCK_SIZE; bz > MIN_MEMORY_BLOCK_SIZE; bz >>= 1) { + for (; bz > MIN_MEMORY_BLOCK_SIZE; bz >>= 1) { if (IS_ALIGNED(boot_mem_end, bz)) break; } From patchwork Wed Nov 6 15:58:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13865124 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 EC347D59F48 for ; Wed, 6 Nov 2024 15:59:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC10A6B00AF; Wed, 6 Nov 2024 10:59:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AAB416B00B0; Wed, 6 Nov 2024 10:59:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 924FA6B00B1; Wed, 6 Nov 2024 10:59:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6E62E6B00AF for ; Wed, 6 Nov 2024 10:59:09 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2B68C16191E for ; Wed, 6 Nov 2024 15:59:09 +0000 (UTC) X-FDA: 82756128546.04.D1F8E48 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by imf03.hostedemail.com (Postfix) with ESMTP id 658AA20016 for ; Wed, 6 Nov 2024 15:58:51 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=sScpLB0n; spf=pass (imf03.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.171 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=1730908523; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dE7GBdO27UpsSNU1CxN3p2/3T9xO+pcffcnhhBLFfkk=; b=CgHlGL3v4wm3lb46nTxDKKoquT9jMynQf84xc65tmK/wmCXdm5BXWmdjwpsm/VrOjlniIC HG0VAlcpm7LOSj7nbKn/BUmyD8Nzbg77w7O+UXBiBKnrN10nynYD0sd1Od2krmk/0AFJQq 6RpD/55Fv5IZ513XvzxiZySOKZ2UYGA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=sScpLB0n; spf=pass (imf03.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.171 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730908523; a=rsa-sha256; cv=none; b=YfQPwNJ+nNqQ0OkXhKlabb2d8Tu5Sz1/TPenBU/BLHmOwo8hRPGyC+S14Amaq6ql7a/vkY 6EEE4FynBKN/m0aHTx/RvT430B/LRTCXdAN1/3e6CrAcj/LjyCLPzUxdmHPm6n/1lgsgi4 jpFGXeU55dGn+GzB2kQJn2/bFgYEN/c= Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-7b1507c42faso82704785a.0 for ; Wed, 06 Nov 2024 07:59:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1730908746; x=1731513546; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dE7GBdO27UpsSNU1CxN3p2/3T9xO+pcffcnhhBLFfkk=; b=sScpLB0n6rrf8jQA0ORtPUZ+kEPTcmRPNpLWm6kIobPjGoxq1NeNeY31TWMlW4X1XU tdauV4MWaBG9RWCUgJJav7zrtsWVRwAhp4DJrb1RIOaquyv2ysZj7XlYt5lAvJ4MfqWJ OZOHDnPJMmvUjdCrOv51serWjsnhcO6xIrBIxZ8LGtq2rLrsTSmX1XlcvavcDqf5cHch 3d/ieVTQBNy1xXyRD5OgxBFEse3SmvFzk1ImVW7h7vJrqSs8M3X53ffkSfX4BXMT96kr sKniwu8Dx+l6EXfOXb0DRWW7alTAyU35uW6Qb9QO2gBU3hWSxbidRbRs2SSkT3+PigfX Y5Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730908746; x=1731513546; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dE7GBdO27UpsSNU1CxN3p2/3T9xO+pcffcnhhBLFfkk=; b=JfTxc1dLNSi3Vby2KKjpheFRUSMmK7V6P8grPWK7hl5uqpb8yt4nS4QmWSavvHXGdO irJc9sPaJxzCrIuvG2pUdYTKvMQqHtZiIjvpKEYVm7FIyuTn36kd+CsWxV2i536C5QyG 7FKcqv9LY4IYJfzjD7UBma7NX/gLJsbDNe+4Wxhm50tGFJjreZi30LNtB0Hfbxp9rZ7D WaOoTNC4M03G5KrXIQ+XZUMXpSW4gbLHV5XLgtLKAA6/yk0LYGaqGmBM1ZL3y/kbkMFT TKvKA71DgncM8BBLnCCXxSh4uyOhNdxHvI+kocK6p9aVIz09YHwfZ7nZLWJ4bGgJYr8j ydkQ== X-Forwarded-Encrypted: i=1; AJvYcCXNbmbDvdpkqqBYo0r80tzlN27w6Nd8MfnzLo+BlKyKrvCDer9kMBSM8jcf6qFZxgAR7J3GJeVaKw==@kvack.org X-Gm-Message-State: AOJu0Ywk+I4MjC3pjegP6vhOSO1Gvy7FkpD82XLJwgGJNFebzlX/lAN6 e6T5uXidSekW9QIHNg9wyzBdJbhD32cvBKhCDYb/ZeUH/gavOwZUkoQIijMmvsM= X-Google-Smtp-Source: AGHT+IEUkctiVyqefq/YK8UzVAb3G1JlrVxWuRVPIwvQYFeNj0t51VLwtemS/L2Zn+W2U6AWN8z3Tg== X-Received: by 2002:a05:620a:bc4:b0:7b1:3c19:a665 with SMTP id af79cd13be357-7b3217fd138mr445393985a.19.1730908746378; Wed, 06 Nov 2024 07:59:06 -0800 (PST) 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 af79cd13be357-7b2f39f7b85sm641377285a.31.2024.11.06.07.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 07:59:06 -0800 (PST) From: Gregory Price To: x86@kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org Cc: linux-cxl@vger.kernel.org, kernel-team@meta.com, Jonathan.Cameron@huawei.com, dan.j.williams@intel.com, rrichter@amd.com, Terry.Bowman@amd.com, dave.jiang@intel.com, ira.weiny@intel.com, alison.schofield@intel.com, gourry@gourry.net, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, rafael@kernel.org, lenb@kernel.org, david@redhat.com, osalvador@suse.de, gregkh@linuxfoundation.org, akpm@linux-foundation.org, rppt@kernel.org Subject: [PATCH v6 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Date: Wed, 6 Nov 2024 10:58:47 -0500 Message-ID: <20241106155847.7985-4-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241106155847.7985-1-gourry@gourry.net> References: <20241106155847.7985-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 658AA20016 X-Stat-Signature: gi67ns8789aoodaz6kyim9gr1pfizrzn X-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yKJHFNxvLl0Ea8xYtDZLZ7pJh4TSeFYk0nVjmDh/Z/+stkNNGrZOrf3Dvip7UQt2gA32mFS7bwA2nc7FHvHwPhKnAcLu7MhVSPJcvquRp3Gw4FD6uhy4TCZf0UIviZ968HUi2QYIqke9TFmb57F1NpUqGvr6GtV+GIH5JF2aIltODPQzjreh/MahIP0plrwaK5o4JHXbyLbBKoqg8e/EN9YoVRhxB7ErJm0Tpancp99ZQ0jCAllxl80ph7oJmfTTuYZn+J2XEczZKX5aCqMS5aoqzbzjJrswOQA01ngSWo6/wCI8KzUC1NsxbqP4swSLuOiV7qQw== 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: Capacity is stranded when CFMWS regions are not aligned to block size. On x86, block size increases with capacity (2G blocks @ 64G capacity). Use CFMWS base/size to report memory block size alignment advice. Suggested-by: Dan Williams Signed-off-by: Gregory Price Acked-by: Mike Rapoport (Microsoft) Acked-by: David Hildenbrand --- drivers/acpi/numa/srat.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c index 44f91f2c6c5d..34b6993e7d6c 100644 --- a/drivers/acpi/numa/srat.c +++ b/drivers/acpi/numa/srat.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -338,13 +339,22 @@ static int __init acpi_parse_cfmws(union acpi_subtable_headers *header, { struct acpi_cedt_cfmws *cfmws; int *fake_pxm = arg; - u64 start, end; + u64 start, end, align; int node; cfmws = (struct acpi_cedt_cfmws *)header; start = cfmws->base_hpa; end = cfmws->base_hpa + cfmws->window_size; + /* Align memblock size to CFMW regions if possible */ + align = 1UL << __ffs(start | end); + if (align >= SZ_256M) { + if (memory_block_advise_max_size(align) < 0) + pr_warn("CFMWS: memblock size advise failed\n"); + } else { + pr_err("CFMWS: [BIOS BUG] base/size alignment violates spec\n"); + } + /* * The SRAT may have already described NUMA details for all, * or a portion of, this CFMWS HPA range. Extend the memblks