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/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hlSGuL4gKWC98KnN4CH1SvVXdevg9MIGJm+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"))