From patchwork Wed Oct 16 19:24:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13838789 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 570CED2A543 for ; Wed, 16 Oct 2024 19:25:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC6FA6B0092; Wed, 16 Oct 2024 15:25:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D509B6B0093; Wed, 16 Oct 2024 15:25:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCA3B6B0095; Wed, 16 Oct 2024 15:25:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A230B6B0092 for ; Wed, 16 Oct 2024 15:25:17 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2EEB31A0B05 for ; Wed, 16 Oct 2024 19:24:59 +0000 (UTC) X-FDA: 82680443580.25.CEAB5E6 Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) by imf30.hostedemail.com (Postfix) with ESMTP id B5AB680008 for ; Wed, 16 Oct 2024 19:24:58 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b="EI/OsrOJ"; spf=pass (imf30.hostedemail.com: domain of gourry@gourry.net designates 209.85.210.47 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=1729106572; 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=dBo6zWcPK+3VP3Pj2DhU6SEkNl/D37D0T08p/JVF3UI=; b=Z/Z1ITTDNKz+rhN4VIUl+lnES5BqCzfOIGoBDg1Ur/sbN6Wm9OzrZjU1ZPqfenDbMgQOmC dnR2Ukd4cjtoD1tqv1vzeVdDFRFft/lzD/PaIJHvIy9eYI00RJx7l/efs6q9Ds2w79HBWi Cx6GCqrlmlI8iH5eWKBFf+dMqww3xH8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729106572; a=rsa-sha256; cv=none; b=NASbPWHvBC7rpQQO3/Vs8ANI9LiCt/p5MNbldmWWU/t3ZMJ+XuixUX7IPRQot1t/tcDPyi 3uQ7nlT4OihNPL6Kx/WSrrZ9ukP3HxCjKrCawFEmVzoOTmc57OeLK67dqk9XbOt6LkoTjJ fve8r4yxxc2Z0V9732hXlNSFy/s9c/0= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b="EI/OsrOJ"; spf=pass (imf30.hostedemail.com: domain of gourry@gourry.net designates 209.85.210.47 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-717d4b88ac9so104483a34.2 for ; Wed, 16 Oct 2024 12:25:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1729106714; x=1729711514; 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=dBo6zWcPK+3VP3Pj2DhU6SEkNl/D37D0T08p/JVF3UI=; b=EI/OsrOJl16xj6PWQR/DWLB7RG1Z62MKCZ86tmfGw6ILnSmBG0GcTJZcpbAQ1LV0DD qfxH30r6MDobnWnG6KUhZcx/bE+yvMCSwpp2bs1Ty07Wk2pW33DfTh+EuYpi6vXP+9MF K2yKEPzye8QPhUEyEx7zOyaYWFcco+7hH5wcNjB31nb8oQ/nT4apmuS2qrJmwRxfITb7 DpR4UL9ZEocDWQN9Yz4XrYWOHgxK+BzeXj8gUTDPdE7Fj1BzlCGan1/nsQlJPWV1MeGU PnsI6EZzVGbHZK85CcTr7w5wlQvTMTnaYdhCy7c83s5QgNH4rvF6xWxMOMsPB9Yqa6lE EmSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729106714; x=1729711514; 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=dBo6zWcPK+3VP3Pj2DhU6SEkNl/D37D0T08p/JVF3UI=; b=gGIdfaYmkPUt2J6itrelaClyAwtdre7sQqCjFxr4N9LkaL7L2BX2Z4vw4gVxM4nr0C 3dg0r++6m0tFTNpcncJN3Xc3kK678crz4CNnxJZfjGmqAlrA+6PAnSYujtErNVLmtgBa Y9e0/zzrlWdXwvtZMRvzXezzGol2kzdm7juYj5+QSvgOCQIGIIYQUcL+8Bn+f1d3TJA7 T6miQjXff2os79zirYDTT1UPDOXlkzB0K/tljsghDPX/EDpUG/KmSvcGi5qkP8qIre1F ACJOQ2jaLC0dYSlmWrYrK58iDupgiZR4yxbrxvUcz5xYSdHJri/9JwxGFh6sfOYmncUn MU4Q== X-Forwarded-Encrypted: i=1; AJvYcCWIBZda+FxBSWd0/PeqA4NJgjxfWDJJwNxU1xMgwRa2mrSXdIz03eYtrjjGEKG3ao5jsdC34IQ/ww==@kvack.org X-Gm-Message-State: AOJu0YzBOfyEzUydOyEG+5xdCoJn3bKu1IzsT1HSajBVXnX3ROtclLkl gOioXBm42Yh/A0u8Bfb9sBWFD77VekXEv4nlSzr3RnvRCYaP99Q+rt1H4F8zaio= X-Google-Smtp-Source: AGHT+IHgEaZY8iMsb9K6bD0HeyumMxOtRYAvr41KKGuerxwMHdKgbYwRirurzLA7V5zk8rmjifacXA== X-Received: by 2002:a05:6358:618a:b0:1b8:688e:6ea3 with SMTP id e5c5f4694b2df-1c3784dedc0mr449907255d.18.1729106714352; Wed, 16 Oct 2024 12:25:14 -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-4607b38ce69sm20271651cf.90.2024.10.16.12.25.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 12:25:14 -0700 (PDT) From: Gregory Price To: x86@kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, david@redhat.com, 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, rppt@kernel.org, akpm@linux-foundation.org, alison.schofield@intel.com, Jonathan.Cameron@huawei.com, rrichter@amd.com, ytcoode@gmail.com, haibo1.xu@intel.com, dave.jiang@intel.com Subject: [PATCH v2 1/3] mm/memblock: implement memblock_advise_size_order and probe functions Date: Wed, 16 Oct 2024 15:24:43 -0400 Message-ID: <20241016192445.3118-2-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241016192445.3118-1-gourry@gourry.net> References: <20241016192445.3118-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Queue-Id: B5AB680008 X-Stat-Signature: f6zpzwr9ys5rr6k5x9ukcp6az76qzbcc X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1729106698-626098 X-HE-Meta: U2FsdGVkX1+d/mGpcXq4CUr8N/ypru3iHm2Q25PpNsYfKsvoxVdKGf33L2KxO/XHxrtDPaERgzYYu9T/m3rz53dzN/W3P5tt9s6mRsrAkk5R/aVlu95B0JcxcPiNxTtLwRbdyHUu3yGB/ozA8XnKtUytTyEaWr40cfPJ7fuZQyRF688HMvwbUmRHbS6wPemq83beBBIrZrtRarASenC9XapaLzQLl8R3grPt68/D3dc/mv+BBwH2MhAE395WApEIYdKWQvkP2j1cJ7ETmsEFNQ6GapSp+cIUix/u+l2WPZQzjO5ObpHxypG7q5IuLFeuFZcpCRxYMefb1BWR30WVvqlzA6NZI1y7PxKGN82IFsU2BSZ8ROMD05DjEuqciCXr4+1IE7uPtG9WZCsnFiU80t5wdAnobH3KVn5iPUHfj8pXMSZOvdpW9h5R3B9h+p7K0cxv79dZt3nN0aAegr8Q+0892AmofiPwZr5IZJOIH1/p72TqhYjN0kKqtsbVUlGRsHabByExzGKGMFfrhrHUeSS4+eofPoFK18ZjedFmCDQJYZFJP99FlKj3ca2m5HKlexap2VT+cS7HmDvIOhR3hK5xXtpbYJPkfgwIg1xmPeS7s/HETbFS8cDdqzvzpYx4u1DGAxAv+Bl9XTU2DjzYaEIRrzgD3KEzCxaP8JlzXHccvWmNlKUAJSsdp1H4XkojGupB5tnJQkkPaAEJwJR6Cruiml8kD0cUOHWNIpUJ3LE3fPb4ruJq9/aqBJGguKYR4PnCc10e2EAj8e/C2BH5k4mpoATZQtv6Op1v52g9rIg5XU9dsFbOZlp0a0OqSBvUKw6UmLpDJIqWIhAEnrxG8Yxy0iwfBd8c8XzzsiK/q29OJ7tcj5z5Bn9LGj+MmgMmMvuKCnqLy1jd6ZJX2A12kTKjLImDlyItF3RJYVgEhItI4de0IbKTOruDr4vaFs8ZiEDTV/LTQSod8qMLF49 EnLlvqYr NP866SPljAUWYzjJpsYo2lEwFyzRdA/ZHsiMzPHvR/OyoqJky1IxeR7RV8Se+r4xPbP1Ci3xbpY++UCoSOpK3dbVih7PLXBwHnBv/RDk/GzvC915icNkEfIqTyz55CAkbgd/mvfSebslZ2vYMto0y4pIICxJPIL4sxrDjzFBE0oMOcXhlSGuL4gKWC98KnN4CH1SvVXdevg9MIGJm+Rg1m7bz+5jZmzpteSRO9yuHlyllZ4M2+/sVfNdRs2QX39i9F2lhzf0XwP7XFVWwO9y+Wr9V4sKFcz79Wh2VbSp1lWcbf4D9dcZOEL94QuoaojR0zXkKV9vdzhc7/sDDQ+w3PEEROizeeauhCABkdsQSDBAkavkjL1mZQyOYKywZp7o+Fjcp 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 as small as 256MB with a matching physical alignment. Implement memblock_advise_size_order for use during early init, prior to allocator and smp init, for software to advise the system as to what the preferred block size should be. The probe function is meant for arch_init code to fetch this value once during memblock size calculation. Use of the advisement value is arch-specific, and no guarantee is made that it will be used. Calls to either function after probe results in -EBUSY to signal that advisement is ignored or that memblock_get_size_bytes should be used. Suggested-by: Ira Weiny Signed-off-by: Gregory Price --- include/linux/memblock.h | 2 ++ mm/memblock.c | 49 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index fc4d75c6cec3..efb1f7cfbd58 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -111,6 +111,8 @@ static inline void memblock_discard(void) {} #endif void memblock_allow_resize(void); +int memblock_advise_size_order(int order); +int memblock_probe_size_order(void); int memblock_add_node(phys_addr_t base, phys_addr_t size, int nid, enum memblock_flags flags); int memblock_add(phys_addr_t base, phys_addr_t size); diff --git a/mm/memblock.c b/mm/memblock.c index 3b9dc2d89b8a..e0bdba011564 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2009,6 +2009,55 @@ void __init memblock_allow_resize(void) memblock_can_resize = 1; } +/* + * @order: bit-order describing the preferred minimum block size + * + * Intended for use by early-boot software prior to smp and allocator init to + * advise the architecture what the minimum block size should be. Should only + * be called during arch init before allocator and smp init. + * + * This value can only decrease after it has been initially set, the intention + * is to identify the smallest supported alignment across all opinions. + * + * Use of this advisement value is arch-specific. + * + * Returns: 0 on success, -EINVAL if order is <=0, and -EBUSY if already probed + */ +static int memblock_sz_order; +#define MEMBLOCK_SZO_PROBED (-1) +int memblock_advise_size_order(int order) +{ + if (order <= 0) + return -EINVAL; + + if (memblock_sz_order == MEMBLOCK_SZO_PROBED) + return -EBUSY; + + if (memblock_sz_order) + memblock_sz_order = min(order, memblock_sz_order); + else + memblock_sz_order = order; + + return 0; +} + +/* + * memblock_probe_size_order is intended for arch init code to probe one time, + * for a suggested memory block size. After the first call, the result will + * always be -EBUSY. A late user should call memory_block_size_bytes instead to + * determine the actual block size in use. + * + * Should only be called during arch init prior to allocator and smp init. + * + * Returns: block size order, 0 if never set, or -EBUSY if previously probed. + */ +int memblock_probe_size_order(void) +{ + int rv = xchg(&memblock_sz_order, -1); + + return (rv == -1) ? -EBUSY : rv; +} + static int __init early_memblock(char *p) { if (p && strstr(p, "debug")) From patchwork Wed Oct 16 19:24:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13838790 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 BDC98D2A541 for ; Wed, 16 Oct 2024 19:25:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F01F66B0095; Wed, 16 Oct 2024 15:25:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E62BF6B0098; Wed, 16 Oct 2024 15:25:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C8DA96B0096; Wed, 16 Oct 2024 15:25:19 -0400 (EDT) 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 A5F2F6B0093 for ; Wed, 16 Oct 2024 15:25:19 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CF2D1ABFAA for ; Wed, 16 Oct 2024 19:24:58 +0000 (UTC) X-FDA: 82680443580.19.20C8A0E Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) by imf13.hostedemail.com (Postfix) with ESMTP id DCADD2000F for ; Wed, 16 Oct 2024 19:25:07 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=IEOAKjU9; spf=pass (imf13.hostedemail.com: domain of gourry@gourry.net designates 209.85.160.169 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=1729106525; 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=KhSiZfD9mtqxRJdpC7TxMcZ82+QcCBZVMQrw8INyhYE=; b=FxxhQzeDexionfs/BDyX6G5zwR4Fi9N6YIfvZiMEwkHBB5uxyQvgce2YGuRFtod93uCT7S Gk4cU54DYxCxKzvSJlZ85O+TyCAgH5/xkn/LcpY/P4G/cFjRIZIwCktW5Ya+03566ZqZ18 +HFFv7NDXTYBKKJ1036LBsYzLQ6M/Tc= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=IEOAKjU9; spf=pass (imf13.hostedemail.com: domain of gourry@gourry.net designates 209.85.160.169 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729106525; a=rsa-sha256; cv=none; b=SuhQxoPaJKBYBXVg8+CL1Dgi2Jq6YWYBxG0zpjZFZYPbv/wpcWeufEU1MCQG6u5UCwSd66 T3nnC0GxEy2YwmEjNR/2dRCaIntckpm/hoFtkK/AycQxNqbTtcH606O4JLpNSmCdyoKcxM PcxOerUGh+XFPcQCM9z63oys4MV838M= Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-4606347c791so1369271cf.2 for ; Wed, 16 Oct 2024 12:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1729106716; x=1729711516; 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=KhSiZfD9mtqxRJdpC7TxMcZ82+QcCBZVMQrw8INyhYE=; b=IEOAKjU99fmHCZTs2r9YabxxHim+VRbja0H2zDRMwSFLzVhXE/Oek8855VFOIxfa49 jQ+xJrPedfwA7oM/I+EnT9r37WX4oH5+aDEDPS/YNkNdK6cI3ZYW8Ly3m+Mw74jliahX MVtA4c/zGeHlBPxG5Bqw+33205LufuKILvedSb1I8PM0jW/Z2ODPN9VDd7qet6P6a+E7 GwNLS69h1T7K9a14yJokCDETHVlpwUL2WJzs3aOAztkntN5X0IwlkWgasCZyFNC10HqD hyWNNqwrn6N1gdMcv0x9zUWQwC7DsD6fY4jk4vrGFRq51/Mi6fkHYiMUw0zf2LZxZXUM JOPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729106716; x=1729711516; 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=KhSiZfD9mtqxRJdpC7TxMcZ82+QcCBZVMQrw8INyhYE=; b=CbFdu/HF8kS8iWJ5eswhX7EhUhT6R6VsxeD880FAAgQLVlZOYc9fEKaSpbbEXxmdlG 9aBImXM+jAlrZ4WS3wAs7zRiigPV4pbi3u4B9Q1ypfApWSNAIHinDBGG2hfXykylUVVV AKxGiwKOr6DigQRrInPqUuXT5Oe4qirasgsqY9vuyp6bsYG4bVwq3RZxuNXygY0dM4NN uP0qA5bh0p2AQEpQE2usVvfoaECmRD7rrySqEEgF5syt2QWDqqNsvhAfBITybCLsqib1 wcdBwMNPtuUSQZUWTRq8Sn+/K/iuMp3bVjlXbEzBfkTjolvIWI+4X282803WEVq70iSu 2ivA== X-Forwarded-Encrypted: i=1; AJvYcCV5dt+IbMY37G37Je1hUkhn13AkYe/Z+qfGUu9nzgjYAUTdaYufKVBmCp8HHhnivDAN+VU9kblljg==@kvack.org X-Gm-Message-State: AOJu0Yylp0OAo88iSxClHAXoSRbmSRMhxJD7a5YA0s95Uf9hVDAvBaYK IoWbVoCqOZ+/rR9HQwLJkbJhqQ3TEA64U3ZYnl3IL4y0pnLlDikiskIhM7y1KT4sZsgwnCfgOIp x X-Google-Smtp-Source: AGHT+IFAUHFf6NguMqIqPpOUU8ECxUJfxWjg38Snyk4DLApeDSEpJ+qoxL7DfuWK9Mow+ZcYMf8Ygg== X-Received: by 2002:a05:622a:244b:b0:45f:784:1b5a with SMTP id d75a77b69052e-46058444fa6mr282643391cf.25.1729106716169; Wed, 16 Oct 2024 12:25:16 -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-4607b38ce69sm20271651cf.90.2024.10.16.12.25.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 12:25:15 -0700 (PDT) From: Gregory Price To: x86@kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, david@redhat.com, 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, rppt@kernel.org, akpm@linux-foundation.org, alison.schofield@intel.com, Jonathan.Cameron@huawei.com, rrichter@amd.com, ytcoode@gmail.com, haibo1.xu@intel.com, dave.jiang@intel.com Subject: [PATCH v2 2/3] x86: probe memblock size advisement value during mm init Date: Wed, 16 Oct 2024 15:24:44 -0400 Message-ID: <20241016192445.3118-3-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241016192445.3118-1-gourry@gourry.net> References: <20241016192445.3118-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DCADD2000F X-Stat-Signature: dmxebb4gtup3fcgnmd81br17jt3xqpxj X-Rspam-User: X-HE-Tag: 1729106707-704459 X-HE-Meta: U2FsdGVkX18ag0S9H+IcAxNvIF54vaDYmcAdpO+gBQzE7WwRy8ZKa8PFeZBB/ZeobjDFPcigfyqPohVYnVEVNAe33tqeod2gZFP3CHuCB91dXe0GzvV6M1Lgq5YcWcUd3MBPrRIBHoy72X/IxWc06rbbcFOLiTWYxeSsAIy3+lSzGG1Kf/cGSVqNS8bDTBcSz8AoWFwFWM97LfIwaKmtTj2whzWY+t8OWQHLI91KddWfEjRH+CBSlW6omvWpeQC6YUBMldy3VDL/hZDT1jv8FxaT24FP6NLzNm/Na1bHnOE0uAD315TxcHMN33BPZePaOlZQkf1ZPpTpa0FG7KfTN0rSdCOrN+duCpFzePqOQOWLJzNvvsC2QzJqSuCjtbP9AgO5m5/DaSq/XHJSjq/eeeH+zifCDYidNCT/jJ/o1MZs9fAv4UmFDCRfikD8llism8+0BXohLjOyoOQvsWNSUmJ05xU+II6rPZhlLA5dYNlQyhJQhwhcS21fCgWpdJYGxTGxDN19xl9tyMIPLpS+tDZ2298u+LaWRxzTRia2/9amkHjaqMaBuSqjmj9yB1inC8E83OWNYlwto3qQfpPnf2KShsBzxSGvnkQBsAPhp4Qyn2R29b6br6d2CM+09lxAGhENmFT3yMkFFUTyPndoWPlKx3d5M0RgAZ6HaX4esFkmFdDJnepS6knA4bnbI7mMeJeHfqYoarfguz7eUfLMdCSVwMtdtuYASmQQzuJ8aBWQW7jPVscrWs0G6WV0m4lKSi5ta4gfvKhjE8lhJM7In7cW375e32EJxVlQXkjg0rHUZMiXcYMWIPOAM/GLSdMHI99KWg9j2920KhPaDvBfSVDYGxwHcsHAbWzfdTElDamQcqYPMF8Ch9L6hpAqxHe0SRgP7QnKuXdu3CoLXEGK7frKJfRV15b+0mZiP5TsbFRRVD3kKIra1pvFHJBVwe6OKBgxg+I6T4es7RJ0Mgh gYRYImKY fxKOl9rhbr9S1u6LR+tgKw+o00jgEmehSxlVGeXvOx29lTnBQZ2DMyF9TbzzDemqStq9+JRsFKOl5qHwKVenPYUpqHG8lXxHV7022IhwLnXhga71jzj/Qwf22uV+NbcmtJtZcHzFzyh81fZI94AUFQkT3VKffGxQ7qqLL1O2MG/tLJoSpt+jyuR3XIYBVXe4oMoigd13JFHCOAVejPrOGoiRZEW1/NZP4QMv78eSMGYmQ7o70/TJqKCDz75q9QPwmzQJkVi8ukZJOS8VJtdwzmTst65kk3ifav94pMu9LkYDXLt3MPW0WyO6vsE9VGyjTO+ohy3LvyfakRCk= 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) [new] hotplug advise: lesser of advise value or memory alignment 4) Max block size if system is bare-metal 5) Largest size that aligns to end of memory. Suggested-by: David Hildenbrand Signed-off-by: Gregory Price --- arch/x86/mm/init_64.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index ff253648706f..b72923b12d99 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1439,6 +1439,7 @@ static unsigned long probe_memory_block_size(void) { unsigned long boot_mem_end = max_pfn << PAGE_SHIFT; unsigned long bz; + int order; /* If memory block size has been set, then use it */ bz = set_memory_block_size; @@ -1451,6 +1452,21 @@ static unsigned long probe_memory_block_size(void) goto done; } + /* Consider hotplug advisement value (if set) */ + order = memblock_probe_size_order(); + bz = order > 0 ? (1UL << order) : 0; + if (bz) { + /* Align down to max and up to min supported */ + bz = max(min(bz, MAX_BLOCK_SIZE), MIN_MEMORY_BLOCK_SIZE); + /* Use lesser of advisement and end of memory alignment */ + for (; bz > MIN_MEMORY_BLOCK_SIZE; bz >>= 1) { + if (IS_ALIGNED(boot_mem_end, bz)) + goto done; + } + /* Barring clean alignment, default to min block size */ + goto done; + } + /* * Use max block size to minimize overhead on bare metal, where * alignment for memory hotplug isn't a concern. From patchwork Wed Oct 16 19:24: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: 13838791 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 A4677D2A542 for ; Wed, 16 Oct 2024 19:25:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E17406B0098; Wed, 16 Oct 2024 15:25:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DC95F6B0099; Wed, 16 Oct 2024 15:25:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1C426B009A; Wed, 16 Oct 2024 15:25:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A12366B0098 for ; Wed, 16 Oct 2024 15:25:21 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 67F7280A78 for ; Wed, 16 Oct 2024 19:25:12 +0000 (UTC) X-FDA: 82680443622.07.E4C4AE0 Received: from mail-vs1-f43.google.com (mail-vs1-f43.google.com [209.85.217.43]) by imf03.hostedemail.com (Postfix) with ESMTP id EBF1E2000C for ; Wed, 16 Oct 2024 19:25:14 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=FVPy8fU5; dmarc=none; spf=pass (imf03.hostedemail.com: domain of gourry@gourry.net designates 209.85.217.43 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=1729106560; 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=HrmbhAeCdsnN6DuwhCdjgoaV0xg9bEsX7zAMN4X3gqU=; b=NTshcZ/GqMlaVDbvFBRyxdrbbVFjSGUmdS94AugcthtDFjIhMiX8OQxcdVnIhfyEHreGYy R0wouP1S+GG+zI1v/b7ANOBCLOxDiWQldOx8cVnhSMgzdL+7lQEDAwireQwchShYqKNHZ3 kauDb+1dxqbAQW5Sl+0vimk3+k/vYJY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729106560; a=rsa-sha256; cv=none; b=hCBz75zH7R8jS0cnhcBvzYeBEEO6qzwn4pEPr/JOJ9u9dGNGNpz5IbiDPZFynE1fr7NiOq d3ncsDlj3WHjRMaqmuuHDbaMsEcdozriE13RqQG3wXf3r0GrprB7gbgsv045SzqFns+ib2 TElkw4BE5B4A4ZOkJNPdAC0XZfz33DY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=FVPy8fU5; dmarc=none; spf=pass (imf03.hostedemail.com: domain of gourry@gourry.net designates 209.85.217.43 as permitted sender) smtp.mailfrom=gourry@gourry.net Received: by mail-vs1-f43.google.com with SMTP id ada2fe7eead31-4a47fd930b8so34800137.1 for ; Wed, 16 Oct 2024 12:25:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1729106718; x=1729711518; 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=HrmbhAeCdsnN6DuwhCdjgoaV0xg9bEsX7zAMN4X3gqU=; b=FVPy8fU5moubTTMmhsTOMYg6V/fu0cV2TWNP7kTygsJJpw0K9kvph4L8WuakPEcGsk RcxG1EHlDSmiK+N+CuIUBnZwwu/jhtnnULsxqUaOJ9mJljj3kvO1XWpWxLD9leL+FNBA AGApZuIsYStHZ4Xbldmdo1kY2VOpYEAFz9i0wVBZufovExCppbyrIcmdefaa+yxgBk5O eb1LKCLRfnv2JUOx5CcsybzqDkEOEJSNcJCGOmNBxK8yHC5sESuSL2ve75x4sNcMFy8q MI/xprXj+MIm0siQ/O2FBKXBEDwzS4qTJjtbbovxcnGOJixXpsg0/yM4RmrDM4ILf+9H 7GZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729106718; x=1729711518; 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=HrmbhAeCdsnN6DuwhCdjgoaV0xg9bEsX7zAMN4X3gqU=; b=WxnrtWxV0htm4vVu38APik3wljcTt46HD9V/VzK+0zmRTxNyGP8nZYX4ohsIuFC1pO s3kGMGGZF8maYBgY0Tsbq/PsA0cWBsMvVV9RA0Xs/c/F6YNKQFw5M2gg7Ejg/yV0deZL W+0GWqpgp//VclS1WIUX5s2wBCA/73mxkv5lJ2XfcWSqj/0e3qlswhBaPjnqNZQwFiR+ kyoq4nv8eJ7SQl9vTECPoeYaB4zrj+dFQyGGC9+tHvAAM6Y0S6ddp1h7/Da0yY/EUxrs GwExK9gIZRLhVkuQj5RpSahsJL6NtMtumAAq5PlTdT/yff0RTxk4bJIh0ckuhmt3RC1q eacw== X-Forwarded-Encrypted: i=1; AJvYcCWWZhiP5y8yB1HMJutSzKrOMZJ69QhoFFo0Ae1shc1tQ/VE57fBfSwRNCq+XqsddwNKVZ/62PF9ig==@kvack.org X-Gm-Message-State: AOJu0YxtA2ZxmRqUFzoHmM1RWa6YMJ9VT/4bGSiLsg/m6OGd7uESTLoG w5cboFDjN8zZJV61vYEmNHjqeXbSexZiCN8xZgAS/IO+0wwHyksHUY3NB/oDYkk= X-Google-Smtp-Source: AGHT+IFClvWp9HyykvU9mzj84/mtwGebanX8vIYbiVaXquh13pEcA6fQ2yrNp4hn0Qu9cQWW9s3xDg== X-Received: by 2002:a05:6102:d92:b0:4a5:ba70:1c6e with SMTP id ada2fe7eead31-4a5ba702ba3mr3418941137.29.1729106718285; Wed, 16 Oct 2024 12:25:18 -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-4607b38ce69sm20271651cf.90.2024.10.16.12.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 12:25:17 -0700 (PDT) From: Gregory Price To: x86@kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, david@redhat.com, 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, rppt@kernel.org, akpm@linux-foundation.org, alison.schofield@intel.com, Jonathan.Cameron@huawei.com, rrichter@amd.com, ytcoode@gmail.com, haibo1.xu@intel.com, dave.jiang@intel.com Subject: [PATCH v2 3/3] acpi,srat: reduce memory block size if CFMWS has a smaller alignment Date: Wed, 16 Oct 2024 15:24:45 -0400 Message-ID: <20241016192445.3118-4-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241016192445.3118-1-gourry@gourry.net> References: <20241016192445.3118-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: EBF1E2000C X-Stat-Signature: pgzmyu7ksbkdbranfi1ez7dccgzowhbc X-Rspam-User: X-HE-Tag: 1729106714-810287 X-HE-Meta: U2FsdGVkX18EIJ5hVQYbfABV9bYtiFp6v6n9JnVB7t371ZfPWtN6SD5Wctb9g+UcwMZZvciTB1XJCIIfc/CK14QvR9+8UVb9AZmd0j13hzs6oWJ6HE3opnZejp7QmYogRFgdAdhKW0YQ4SYU0YtEPoBC9J98USKkJwsncr6bfIGekXfjehJKLl1ouZeFZc2HsTW9gKopFQZex2DHbHG/+Rsf1ncPqAS/hwM6xpPykfOBYdNulaXxYC+QU7eT6GGTSwFexWQd/78MQIiSWWkdmaDvBdVx9kEvKy/HINpbYdhqdkZP34XSuI2e5agZGLFkB0/zAHtchjuG0EgO4ie7HkwDAQT4oqSQ8GBm7FUI09Wy4EVCoV9ikcCwcRPcb6snSB+D7wCYJPlZ5gbAbOsu7oT4krsZvAPrJX2zN22oTgmqYWViBw/seKdYJysWfTTTi0ZmWlDBcq+vEGNzv+Lk8FQ4KGrgZjzlpEkSeldvCTS8ugWzXfvB2UMSWbZjdBF1wKWRmllzdNs49zjiQVVTahSWu+hiV1tC1KZHjyqKWyGpW0/nww+ZOmED5QWfbzxpZBLTndggPhRk85PbdTnNqyNwSOYZZKK7C+NgvnKoczfM/wmvbAxDU/I4doH20lnbsh/Md/avxZtgmbldkBFHCOEY7gbyyKUpjRNHVbUng2XKUFQo0O8SeO2Cix4K9aD/dOBql//nmTWZ7Orv6+iP7dWPkV9FatZzESxH3D5GOZbJACnOoqcuF3RJkqFpWUnPL+fb7Uq0eKXMEY4HDjNec3aPHmrqb3JgEJdqV8x6GSyeqEQ03QxEyn/DbaTZQmi9vYIOlTssnPn/Eaoozmex3rEJT454OuWus5j9IYWQxyBA9M18G8i4oLMjkAAJORhpGulai3TyG+eL5YHOdC7ZMUIT0Ma/w/yygmyxupI3OXUIH8fqP79nvztDLf8xAKibhkrK+ffkW+w8U5nAOps dQI8KIKz rjceaI3DDQeAU1rcwJ03mt1CU55MBvDme5KFbPEh10S7t1XDruBHue4FUNzpG9MIkLNlfHXRY5/WLGIpnkScXP1ET/PrOM0B1BvgHLA+mnSaPHyuX4fW8EDaue+yKa5DoqeY0spTqI1USMxy5GA6mmkZSzrEIiIThBAlkfoRJ2RQizE3fgnV26o4DOKD1KxwnDjdeiyMHlmsTPCS07Dm42Zinap247Vmz5sstFI8P+QomNlJ/FD2yqwSTtkgmrqYevZ8AV15iaaFITK1QWDERFlefYlYUlnxWZD4PeZ1qu63LGn6KC5iZ0nOqt5T3XlZXCYMlIRyY8dv3S0A= 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: 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 advise memblock to reduce the block size accordingly. Suggested-by: Dan Williams Signed-off-by: Gregory Price --- drivers/acpi/numa/srat.c | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c index 44f91f2c6c5d..5fc03a99570e 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,35 @@ acpi_parse_memory_affinity(union acpi_subtable_headers *header, return 0; } +/* + * 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; +} + static int __init acpi_parse_cfmws(union acpi_subtable_headers *header, void *arg, const unsigned long table_end) { @@ -501,6 +531,7 @@ acpi_table_parse_srat(enum acpi_srat_type id, int __init acpi_numa_init(void) { int i, fake_pxm, cnt = 0; + unsigned long bz = SZ_64T; if (acpi_disabled) return -EINVAL; @@ -552,6 +583,17 @@ int __init acpi_numa_init(void) } last_real_pxm = fake_pxm; fake_pxm++; + + /* Calculate and set largest supported memory block size alignment */ + acpi_table_parse_cedt(ACPI_CEDT_TYPE_CFMWS, acpi_align_cfmws, &bz); + if (bz >= SZ_256M) { + if (memblock_advise_size_order(ffs(bz)-1) < 0) + pr_warn("CFMWS: memblock size advise failed\n"); + else + pr_info("CFMWS: memblock advised size(%ld)\n", bz); + } + + /* Then parse and fill the numa nodes with the described memory */ acpi_table_parse_cedt(ACPI_CEDT_TYPE_CFMWS, acpi_parse_cfmws, &fake_pxm);