linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RESEND v7 0/3] memory,x86,acpi: hotplug memory alignment advisement
@ 2025-01-13 17:44 Gregory Price
  2025-01-13 17:44 ` [RESEND v7 1/3] memory: implement memory_block_advise/probe_max_size Gregory Price
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Gregory Price @ 2025-01-13 17:44 UTC (permalink / raw)
  To: linux-mm, linux-acpi
  Cc: kernel-team, x86, linux-kernel, dave.hansen, luto, peterz, tglx,
	mingo, bp, hpa, rafael, lenb, david, osalvador, gregkh, akpm,
	dan.j.williams, Jonathan.Cameron, alison.schofield, rrichter,
	rppt, gourry, bfaccini, haibo1.xu, dave.jiang, Ira Weiny, Fan Ni

resend: Not clear if this should go through -mm or -acpi
	clean rebase on mm-unstable as of Jan 13, no changes


When physical address regions are not aligned to memory block size,
the misaligned portion is lost (stranded capacity).

Block size (min/max/selected) is architecture defined. Most architectures
tend to use the minimum block size or some simplistic heurist. On x86,
memory block size increases up to 2GB, and is otherwise fitted to the
alignment of non-hotplug (i.e. not special purpose memory).

CXL exposes its memory for management through the ACPI CEDT (CXL Early
Detection Table) in a field called the CXL Fixed Memory Window.  Per
the CXL specification, this memory must be aligned to at least 256MB.

When a CFMW aligns on a size less than the block size, this causes a
loss of up to 2GB per CFMW on x86.  It is not uncommon for CFMW to be
allocated per-device - though this behavior is BIOS defined.

This patch set provides 3 things:
 1) implement advise/query functions in driverse/base/memory.c to
    report/query architecture agnostic hotplug block alignment advice.
 2) update x86 memblock size logic to consider the hotplug advice
 3) add code in acpi/numa/srat.c to report CFMW alignment advice

The advisement interfaces are design to be called during arch_init
code prior to allocator and smp_init.  start_kernel will call these
through setup_arch() (via acpi and mm/init_64.c on x86), which occurs
prior to mm_core_init and smp_init - so no need for atomics.

There's an attempt to signal callers to advise() that query has already
occurred, but this is predicated on the notion that query actually
occurs (which presently only happens on the x86 arch). This is to
assist debugging future users.  Otherwise, the advise() call has
been marked __init to help static discovery of bad call times.

Once query is called the first time, it will always return the same value.

Interfaces return -EBUSY and 0 respectively on systems without hotplug.

Suggested-by: Ira Weiny <ira.weiny@intel.com>
Suggested-by: David Hildenbrand <david@redhat.com>
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Dan Williams <dan.j.williams@intel.com>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Signed-off-by: Gregory Price <gourry@gourry.net>
Tested-by: Fan Ni <fan.ni@samsung.com>

Gregory Price (3):
  memory: implement memory_block_advise/probe_max_size
  x86: probe memory block size advisement value during mm init
  acpi,srat: give memory block size advice based on CFMWS alignment

 arch/x86/mm/init_64.c    | 15 ++++++++----
 drivers/acpi/numa/srat.c | 12 ++++++++-
 drivers/base/memory.c    | 53 ++++++++++++++++++++++++++++++++++++++++
 include/linux/memory.h   | 10 ++++++++
 4 files changed, 84 insertions(+), 6 deletions(-)

-- 
2.47.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [RESEND v7 1/3] memory: implement memory_block_advise/probe_max_size
  2025-01-13 17:44 [RESEND v7 0/3] memory,x86,acpi: hotplug memory alignment advisement Gregory Price
@ 2025-01-13 17:44 ` Gregory Price
  2025-01-13 20:51   ` Ira Weiny
  2025-01-13 17:44 ` [RESEND v7 2/3] x86: probe memory block size advisement value during mm init Gregory Price
  2025-01-13 17:44 ` [RESEND v7 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Gregory Price
  2 siblings, 1 reply; 9+ messages in thread
From: Gregory Price @ 2025-01-13 17:44 UTC (permalink / raw)
  To: linux-mm, linux-acpi
  Cc: kernel-team, x86, linux-kernel, dave.hansen, luto, peterz, tglx,
	mingo, bp, hpa, rafael, lenb, david, osalvador, gregkh, akpm,
	dan.j.williams, Jonathan.Cameron, alison.schofield, rrichter,
	rppt, gourry, bfaccini, haibo1.xu, dave.jiang, Ira Weiny, Fan Ni

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 <ira.weiny@intel.com>
Signed-off-by: Gregory Price <gourry@gourry.net>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: Dan Williams <dan.j.williams@intel.com>
Tested-by: Fan Ni <fan.ni@samsung.com>
---
 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 348c5dbbfa68..e59378ec5b00 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 */
 
 /*
-- 
2.47.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [RESEND v7 2/3] x86: probe memory block size advisement value during mm init
  2025-01-13 17:44 [RESEND v7 0/3] memory,x86,acpi: hotplug memory alignment advisement Gregory Price
  2025-01-13 17:44 ` [RESEND v7 1/3] memory: implement memory_block_advise/probe_max_size Gregory Price
@ 2025-01-13 17:44 ` Gregory Price
  2025-01-13 20:56   ` Ira Weiny
  2025-01-13 17:44 ` [RESEND v7 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Gregory Price
  2 siblings, 1 reply; 9+ messages in thread
From: Gregory Price @ 2025-01-13 17:44 UTC (permalink / raw)
  To: linux-mm, linux-acpi
  Cc: kernel-team, x86, linux-kernel, dave.hansen, luto, peterz, tglx,
	mingo, bp, hpa, rafael, lenb, david, osalvador, gregkh, akpm,
	dan.j.williams, Jonathan.Cameron, alison.schofield, rrichter,
	rppt, gourry, bfaccini, haibo1.xu, dave.jiang, Fan Ni

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 <bp@alien8.de>
Suggested-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Gregory Price <gourry@gourry.net>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: Dan Williams <dan.j.williams@intel.com>
Tested-by: Fan Ni <fan.ni@samsung.com>
---
 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 01ea7c6df303..58ace82874eb 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -1462,16 +1462,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;
 	}
-- 
2.47.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [RESEND v7 3/3] acpi,srat: give memory block size advice based on CFMWS alignment
  2025-01-13 17:44 [RESEND v7 0/3] memory,x86,acpi: hotplug memory alignment advisement Gregory Price
  2025-01-13 17:44 ` [RESEND v7 1/3] memory: implement memory_block_advise/probe_max_size Gregory Price
  2025-01-13 17:44 ` [RESEND v7 2/3] x86: probe memory block size advisement value during mm init Gregory Price
@ 2025-01-13 17:44 ` Gregory Price
  2025-01-13 19:10   ` Rafael J. Wysocki
  2025-01-13 20:59   ` Ira Weiny
  2 siblings, 2 replies; 9+ messages in thread
From: Gregory Price @ 2025-01-13 17:44 UTC (permalink / raw)
  To: linux-mm, linux-acpi
  Cc: kernel-team, x86, linux-kernel, dave.hansen, luto, peterz, tglx,
	mingo, bp, hpa, rafael, lenb, david, osalvador, gregkh, akpm,
	dan.j.williams, Jonathan.Cameron, alison.schofield, rrichter,
	rppt, gourry, bfaccini, haibo1.xu, dave.jiang, Fan Ni

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 <dan.j.williams@intel.com>
Signed-off-by: Gregory Price <gourry@gourry.net>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Dan Williams <dan.j.williams@intel.com>
Tested-by: Fan Ni <fan.ni@samsung.com>
---
 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 59fffe34c9d0..7526119fe945 100644
--- a/drivers/acpi/numa/srat.c
+++ b/drivers/acpi/numa/srat.c
@@ -14,6 +14,7 @@
 #include <linux/errno.h>
 #include <linux/acpi.h>
 #include <linux/memblock.h>
+#include <linux/memory.h>
 #include <linux/numa.h>
 #include <linux/nodemask.h>
 #include <linux/topology.h>
@@ -425,13 +426,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
-- 
2.47.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RESEND v7 3/3] acpi,srat: give memory block size advice based on CFMWS alignment
  2025-01-13 17:44 ` [RESEND v7 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Gregory Price
@ 2025-01-13 19:10   ` Rafael J. Wysocki
  2025-01-13 20:59   ` Ira Weiny
  1 sibling, 0 replies; 9+ messages in thread
From: Rafael J. Wysocki @ 2025-01-13 19:10 UTC (permalink / raw)
  To: gourry
  Cc: linux-mm, linux-acpi, kernel-team, x86, linux-kernel,
	dave.hansen, luto, peterz, tglx, mingo, bp, hpa, rafael, lenb,
	david, osalvador, gregkh, akpm, dan.j.williams, Jonathan.Cameron,
	alison.schofield, rrichter, rppt, bfaccini, haibo1.xu,
	dave.jiang, Fan Ni

On Mon, Jan 13, 2025 at 6:44 PM Gregory Price <gourry@gourry.net> wrote:
>
> 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 <dan.j.williams@intel.com>
> Signed-off-by: Gregory Price <gourry@gourry.net>
> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> Acked-by: David Hildenbrand <david@redhat.com>
> Acked-by: Dan Williams <dan.j.williams@intel.com>
> Tested-by: Fan Ni <fan.ni@samsung.com>

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

> ---
>  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 59fffe34c9d0..7526119fe945 100644
> --- a/drivers/acpi/numa/srat.c
> +++ b/drivers/acpi/numa/srat.c
> @@ -14,6 +14,7 @@
>  #include <linux/errno.h>
>  #include <linux/acpi.h>
>  #include <linux/memblock.h>
> +#include <linux/memory.h>
>  #include <linux/numa.h>
>  #include <linux/nodemask.h>
>  #include <linux/topology.h>
> @@ -425,13 +426,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
> --
> 2.47.1
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RESEND v7 1/3] memory: implement memory_block_advise/probe_max_size
  2025-01-13 17:44 ` [RESEND v7 1/3] memory: implement memory_block_advise/probe_max_size Gregory Price
@ 2025-01-13 20:51   ` Ira Weiny
  0 siblings, 0 replies; 9+ messages in thread
From: Ira Weiny @ 2025-01-13 20:51 UTC (permalink / raw)
  To: Gregory Price, linux-mm, linux-acpi
  Cc: kernel-team, x86, linux-kernel, dave.hansen, luto, peterz, tglx,
	mingo, bp, hpa, rafael, lenb, david, osalvador, gregkh, akpm,
	dan.j.williams, Jonathan.Cameron, alison.schofield, rrichter,
	rppt, gourry, bfaccini, haibo1.xu, dave.jiang, Ira Weiny, Fan Ni

Gregory Price wrote:
> 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 <ira.weiny@intel.com>
> Signed-off-by: Gregory Price <gourry@gourry.net>
> Acked-by: David Hildenbrand <david@redhat.com>
> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> Acked-by: Dan Williams <dan.j.williams@intel.com>
> Tested-by: Fan Ni <fan.ni@samsung.com>
> ---

[snip]

> +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;
> +	}

NIT: Style: single statements don't need '{}'

Other than that it looks ok.

Reviewed-by: Ira Weiny <ira.weiny@intel.com>

[snip]


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RESEND v7 2/3] x86: probe memory block size advisement value during mm init
  2025-01-13 17:44 ` [RESEND v7 2/3] x86: probe memory block size advisement value during mm init Gregory Price
@ 2025-01-13 20:56   ` Ira Weiny
  0 siblings, 0 replies; 9+ messages in thread
From: Ira Weiny @ 2025-01-13 20:56 UTC (permalink / raw)
  To: Gregory Price, linux-mm, linux-acpi
  Cc: kernel-team, x86, linux-kernel, dave.hansen, luto, peterz, tglx,
	mingo, bp, hpa, rafael, lenb, david, osalvador, gregkh, akpm,
	dan.j.williams, Jonathan.Cameron, alison.schofield, rrichter,
	rppt, gourry, bfaccini, haibo1.xu, dave.jiang, Fan Ni

Gregory Price wrote:
> 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 <bp@alien8.de>
> Suggested-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Gregory Price <gourry@gourry.net>
> Acked-by: David Hildenbrand <david@redhat.com>
> Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> Acked-by: Dan Williams <dan.j.williams@intel.com>
> Tested-by: Fan Ni <fan.ni@samsung.com>

Reviewed-by: Ira Weiny <ira.weiny@intel.com>

[snip]


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RESEND v7 3/3] acpi,srat: give memory block size advice based on CFMWS alignment
  2025-01-13 17:44 ` [RESEND v7 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Gregory Price
  2025-01-13 19:10   ` Rafael J. Wysocki
@ 2025-01-13 20:59   ` Ira Weiny
  2025-01-13 21:06     ` Gregory Price
  1 sibling, 1 reply; 9+ messages in thread
From: Ira Weiny @ 2025-01-13 20:59 UTC (permalink / raw)
  To: Gregory Price, linux-mm, linux-acpi
  Cc: kernel-team, x86, linux-kernel, dave.hansen, luto, peterz, tglx,
	mingo, bp, hpa, rafael, lenb, david, osalvador, gregkh, akpm,
	dan.j.williams, Jonathan.Cameron, alison.schofield, rrichter,
	rppt, gourry, bfaccini, haibo1.xu, dave.jiang, Fan Ni

Gregory Price wrote:
> 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 <dan.j.williams@intel.com>
> Signed-off-by: Gregory Price <gourry@gourry.net>
> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> Acked-by: David Hildenbrand <david@redhat.com>
> Acked-by: Dan Williams <dan.j.williams@intel.com>
> Tested-by: Fan Ni <fan.ni@samsung.com>
> ---
>  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 59fffe34c9d0..7526119fe945 100644
> --- a/drivers/acpi/numa/srat.c
> +++ b/drivers/acpi/numa/srat.c
> @@ -14,6 +14,7 @@
>  #include <linux/errno.h>
>  #include <linux/acpi.h>
>  #include <linux/memblock.h>
> +#include <linux/memory.h>
>  #include <linux/numa.h>
>  #include <linux/nodemask.h>
>  #include <linux/topology.h>
> @@ -425,13 +426,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");

I wonder if it would be good to print the return value here so the user
knows why this failed?

But either way.

Reviewed-by: Ira Weiny <ira.weiny@intel.com>

> +	} 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
> -- 
> 2.47.1
> 
> 




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RESEND v7 3/3] acpi,srat: give memory block size advice based on CFMWS alignment
  2025-01-13 20:59   ` Ira Weiny
@ 2025-01-13 21:06     ` Gregory Price
  0 siblings, 0 replies; 9+ messages in thread
From: Gregory Price @ 2025-01-13 21:06 UTC (permalink / raw)
  To: Ira Weiny
  Cc: linux-mm, linux-acpi, kernel-team, x86, linux-kernel,
	dave.hansen, luto, peterz, tglx, mingo, bp, hpa, rafael, lenb,
	david, osalvador, gregkh, akpm, dan.j.williams, Jonathan.Cameron,
	alison.schofield, rrichter, rppt, bfaccini, haibo1.xu,
	dave.jiang, Fan Ni

On Mon, Jan 13, 2025 at 02:59:22PM -0600, Ira Weiny wrote:
> Gregory Price wrote:
> > +	/* 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");
> 
> I wonder if it would be good to print the return value here so the user
> knows why this failed?
> 

As someone who is often annoyed by this exact pattern, I am apparently
just as guilty at producing it *facepalm*

I'll pick this up and push it tomorrow.

> But either way.
> 
> Reviewed-by: Ira Weiny <ira.weiny@intel.com>
> 
> > +	} 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
> > -- 
> > 2.47.1
> > 
> > 
> 
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-01-13 21:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-13 17:44 [RESEND v7 0/3] memory,x86,acpi: hotplug memory alignment advisement Gregory Price
2025-01-13 17:44 ` [RESEND v7 1/3] memory: implement memory_block_advise/probe_max_size Gregory Price
2025-01-13 20:51   ` Ira Weiny
2025-01-13 17:44 ` [RESEND v7 2/3] x86: probe memory block size advisement value during mm init Gregory Price
2025-01-13 20:56   ` Ira Weiny
2025-01-13 17:44 ` [RESEND v7 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Gregory Price
2025-01-13 19:10   ` Rafael J. Wysocki
2025-01-13 20:59   ` Ira Weiny
2025-01-13 21:06     ` Gregory Price

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox