Skip to contentSkip to conversation

Fix and enable pmem as RAM device on arm64

PATCH Superseded Jia He 8 participants 49 messages Jul 7, 2020 – Jul 10, 2020

Subsystems (6)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jia He

author
#0 lore raw

v2 cover Fix and enable pmem as RAM device on arm64

This fix a few issues when I tried to enable pmem as RAM device on arm64.

Tested on ThunderX2 host/qemu "-M virt" guest with a nvdimm device. The memblocks from the dax pmem device can be either hot-added or hot-removed on arm64 guest.

Changes:
v2: - Drop unneccessary patch to harden try_offline_node
- Use new solution(by David) to fix dev->target_node=-1 during probing
- Refine the mem_hotplug_begin/done patch

v1: https://lkml.org/lkml/2020/7/5/381

Jia He (3):
arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL
device-dax: use fallback nid when numa_node is invalid mm/memory_hotplug: fix unpaired mem_hotplug_begin/done

 arch/arm64/mm/numa.c |  5 +++--
 drivers/dax/kmem.c   | 22 ++++++++++++++--------
 mm/memory_hotplug.c  |  5 ++---
 3 files changed, 19 insertions(+), 13 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/3 arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +3 -2
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
-	pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
Signature · 1 line
2.17.1
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 20 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 10 lines
arch/arm64/mm/numa.c +3 -2
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
-	pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

We could turn that into a pr_info() instead, but the effect is visible to user space (e.g., which memory blocks belong to which node in sysfs), so this can be debugged easily on demand.

Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

In reply to Jia He
Quoted 19 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 10 lines
arch/arm64/mm/numa.c +3 -2
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
-	pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Signature · 2 lines
Michal Hocko
SUSE Labs
#4 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 18 lines · Michal Hocko
Quoted 17 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
Quoted 16 lines

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 12 lines
arch/arm64/mm/numa.c +3 -2
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
-	pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

We'll need to either add a CONFIG_ option or arch specific callback to make both non-empty (x86, powerpc, ia64) and empty (arm64, sh) implementations coexist ...

Quoted 3 lines
Signature · 2 lines
Michal Hocko
SUSE Labs
Signature · 2 lines
Sincerely yours,
Mike.
#5 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 36 lines · Mike Rapoport
Quoted 18 lines · Michal Hocko
Quoted 17 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
Quoted 16 lines

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 12 lines
arch/arm64/mm/numa.c +3 -2
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
-	pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Quoted 3 lines

We'll need to either add a CONFIG_ option or arch specific callback to make both non-empty (x86, powerpc, ia64) and empty (arm64, sh) implementations coexist ...

Note: I have a similar dummy (return 0) patch for s390x lying around here.

Signature · 3 lines
Thanks,

David / dhildenb
#6 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 37 lines · David Hildenbrand
Quoted 36 lines · Mike Rapoport
Quoted 34 lines · Michal Hocko
Quoted 19 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 10 lines
arch/arm64/mm/numa.c +3 -2
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
-	pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Quoted 5 lines
Quoted 3 lines

We'll need to either add a CONFIG_ option or arch specific callback to make both non-empty (x86, powerpc, ia64) and empty (arm64, sh) implementations coexist ...

Note: I have a similar dummy (return 0) patch for s390x lying around here.

Then we'll call it a tie - 3:3 ;-)

Quoted 5 lines
Signature · 3 lines
Thanks,

David / dhildenb
Signature · 2 lines
Sincerely yours,
Mike.
#7 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 39 lines · Mike Rapoport
Quoted 37 lines · David Hildenbrand
Quoted 36 lines · Mike Rapoport
Quoted 34 lines · Michal Hocko
Quoted 19 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 10 lines
arch/arm64/mm/numa.c +3 -2
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
- pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
  return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

We'll need to either add a CONFIG_ option or arch specific callback to make both non-empty (x86, powerpc, ia64) and empty (arm64, sh) implementations coexist ...

Note: I have a similar dummy (return 0) patch for s390x lying around here.

Then we'll call it a tie - 3:3 ;-)

So I'd be happy to jump on the train of people wanting to export the ARM stub for this (and add a new ARM stub for phys_to_target_node()), but Will did have a plausibly better idea that I have been meaning to circle back to:

http://lore.kernel.org/r/20200325111039.GA32109@willie-the-truck

...i.e. iterate over node data to do the lookup. This would seem to work generically for multiple archs unless I am missing something?

#8 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 53 lines · Dan Williams
Quoted 39 lines · Mike Rapoport
Quoted 37 lines · David Hildenbrand
Quoted 36 lines · Mike Rapoport
Quoted 34 lines · Michal Hocko
Quoted 19 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 10 lines
arch/arm64/mm/numa.c +3 -2
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
- pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
  return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

We'll need to either add a CONFIG_ option or arch specific callback to make both non-empty (x86, powerpc, ia64) and empty (arm64, sh) implementations coexist ...

Note: I have a similar dummy (return 0) patch for s390x lying around here.

Then we'll call it a tie - 3:3 ;-)

So I'd be happy to jump on the train of people wanting to export the ARM stub for this (and add a new ARM stub for phys_to_target_node()), but Will did have a plausibly better idea that I have been meaning to circle back to:

Quoted 4 lines

http://lore.kernel.org/r/20200325111039.GA32109@willie-the-truck

...i.e. iterate over node data to do the lookup. This would seem to work generically for multiple archs unless I am missing something?

I think it would work on arm64, power and, most propbably on s390 (David?), but not on x86. x86 does not have reserved memory in pgdat, it's never memblock_add()'ed (see e820__memblock_setup()).

I've suggested to add E820_*_RESERVED to memblock.memory a while ago [1], but apparently there are systems that cannot tolerate OS mappings of the BIOS reserved areas.

[1] https://lore.kernel.org/lkml/[email protected]/

Signature · 2 lines
Sincerely yours,
Mike.
#9 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 54 lines · Mike Rapoport
Quoted 53 lines · Dan Williams
Quoted 39 lines · Mike Rapoport
Quoted 37 lines · David Hildenbrand
Quoted 36 lines · Mike Rapoport
Quoted 34 lines · Michal Hocko
Quoted 19 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 10 lines
arch/arm64/mm/numa.c +3 -2
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
- pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
  return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

We'll need to either add a CONFIG_ option or arch specific callback to make both non-empty (x86, powerpc, ia64) and empty (arm64, sh) implementations coexist ...

Note: I have a similar dummy (return 0) patch for s390x lying around here.

Then we'll call it a tie - 3:3 ;-)

So I'd be happy to jump on the train of people wanting to export the ARM stub for this (and add a new ARM stub for phys_to_target_node()), but Will did have a plausibly better idea that I have been meaning to circle back to:

Quoted 4 lines
Quoted 4 lines

http://lore.kernel.org/r/20200325111039.GA32109@willie-the-truck

...i.e. iterate over node data to do the lookup. This would seem to work generically for multiple archs unless I am missing something?

IIRC, only memory assigned to/onlined to a ZONE is represented in the pgdat node span. E.g., not offline memory blocks.

Esp., when hotplugging + onlining consecutive memory, there won't really be any intersections in most cases if I am not wrong. It would not be "intersection" but rather "closest fit".

With overlapping nodes it's even more unclear. Which one to pick?

Quoted 2 lines

I think it would work on arm64, power and, most propbably on s390

With only a single dummy node I guess it should work (searching when there is only a single node does not make too much sense).

Quoted 2 lines

(David?), but not on x86. x86 does not have reserved memory in pgdat, it's never memblock_add()'ed (see e820__memblock_setup()).

Can you enlighten me why that is relevant for the memory hotplug path? (or is it just a general comment to make the function as accurate as possible for all addresses?)

Signature · 6 lines
Thanks,

David / dhildenb
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#10 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 75 lines · David Hildenbrand
Quoted 54 lines · Mike Rapoport
Quoted 53 lines · Dan Williams
Quoted 39 lines · Mike Rapoport
Quoted 37 lines · David Hildenbrand
Quoted 36 lines · Mike Rapoport
Quoted 34 lines · Michal Hocko
Quoted 19 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 10 lines
arch/arm64/mm/numa.c +3 -2
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
- pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
  return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

We'll need to either add a CONFIG_ option or arch specific callback to make both non-empty (x86, powerpc, ia64) and empty (arm64, sh) implementations coexist ...

Note: I have a similar dummy (return 0) patch for s390x lying around here.

Then we'll call it a tie - 3:3 ;-)

So I'd be happy to jump on the train of people wanting to export the ARM stub for this (and add a new ARM stub for phys_to_target_node()), but Will did have a plausibly better idea that I have been meaning to circle back to:

Quoted 4 lines
Quoted 4 lines

http://lore.kernel.org/r/20200325111039.GA32109@willie-the-truck

...i.e. iterate over node data to do the lookup. This would seem to work generically for multiple archs unless I am missing something?

IIRC, only memory assigned to/onlined to a ZONE is represented in the pgdat node span. E.g., not offline memory blocks.

Esp., when hotplugging + onlining consecutive memory, there won't really be any intersections in most cases if I am not wrong. It would not be "intersection" but rather "closest fit".

With overlapping nodes it's even more unclear. Which one to pick?

Quoted 2 lines

I think it would work on arm64, power and, most propbably on s390

With only a single dummy node I guess it should work (searching when there is only a single node does not make too much sense).

Quoted 6 lines
Quoted 2 lines

(David?), but not on x86. x86 does not have reserved memory in pgdat, it's never memblock_add()'ed (see e820__memblock_setup()).

Can you enlighten me why that is relevant for the memory hotplug path? (or is it just a general comment to make the function as accurate as possible for all addresses?)

phys_to_target_node() on x86 falls back to numa_reserved_meminfo which holds memory that is never listed in a node.

Quoted 5 lines
Signature · 3 lines
Thanks,

David / dhildenb
Signature · 2 lines
Sincerely yours,
Mike.
#11 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 79 lines · Mike Rapoport
Quoted 78 lines · David Hildenbrand
Quoted 54 lines · Mike Rapoport
Quoted 53 lines · Dan Williams
Quoted 39 lines · Mike Rapoport
Quoted 37 lines · David Hildenbrand
Quoted 36 lines · Mike Rapoport
Quoted 34 lines · Michal Hocko
Quoted 19 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 10 lines
arch/arm64/mm/numa.c +3 -2
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
- pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
  return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

We'll need to either add a CONFIG_ option or arch specific callback to make both non-empty (x86, powerpc, ia64) and empty (arm64, sh) implementations coexist ...

Note: I have a similar dummy (return 0) patch for s390x lying around here.

Then we'll call it a tie - 3:3 ;-)

So I'd be happy to jump on the train of people wanting to export the ARM stub for this (and add a new ARM stub for phys_to_target_node()), but Will did have a plausibly better idea that I have been meaning to circle back to:

Quoted 4 lines
Quoted 4 lines

http://lore.kernel.org/r/20200325111039.GA32109@willie-the-truck

...i.e. iterate over node data to do the lookup. This would seem to work generically for multiple archs unless I am missing something?

IIRC, only memory assigned to/onlined to a ZONE is represented in the pgdat node span. E.g., not offline memory blocks.

Esp., when hotplugging + onlining consecutive memory, there won't really be any intersections in most cases if I am not wrong. It would not be "intersection" but rather "closest fit".

With overlapping nodes it's even more unclear. Which one to pick?

Quoted 2 lines

I think it would work on arm64, power and, most propbably on s390

With only a single dummy node I guess it should work (searching when there is only a single node does not make too much sense).

Quoted 2 lines

(David?), but not on x86. x86 does not have reserved memory in pgdat, it's never memblock_add()'ed (see e820__memblock_setup()).

Quoted 7 lines
Quoted 3 lines

Can you enlighten me why that is relevant for the memory hotplug path? (or is it just a general comment to make the function as accurate as possible for all addresses?)

phys_to_target_node() on x86 falls back to numa_reserved_meminfo which holds memory that is never listed in a node.

Ah, I see - thanks.

Signature · 3 lines
Thanks,

David / dhildenb
#12 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

In reply to David Hildenbrand
Quoted 56 lines · David Hildenbrand
Quoted 54 lines · Mike Rapoport
Quoted 53 lines · Dan Williams
Quoted 39 lines · Mike Rapoport
Quoted 37 lines · David Hildenbrand
Quoted 36 lines · Mike Rapoport
Quoted 34 lines · Michal Hocko
Quoted 19 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 10 lines
arch/arm64/mm/numa.c +3 -2
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
- pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
  return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

We'll need to either add a CONFIG_ option or arch specific callback to make both non-empty (x86, powerpc, ia64) and empty (arm64, sh) implementations coexist ...

Note: I have a similar dummy (return 0) patch for s390x lying around here.

Then we'll call it a tie - 3:3 ;-)

So I'd be happy to jump on the train of people wanting to export the ARM stub for this (and add a new ARM stub for phys_to_target_node()), but Will did have a plausibly better idea that I have been meaning to circle back to:

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

http://lore.kernel.org/r/20200325111039.GA32109@willie-the-truck

...i.e. iterate over node data to do the lookup. This would seem to work generically for multiple archs unless I am missing something?

IIRC, only memory assigned to/onlined to a ZONE is represented in the pgdat node span. E.g., not offline memory blocks.

So this dovetails somewhat with Will's idea. What if we populated node_data for "offline" ranges? I started there, but then saw ARCH_KEEP_MEMBLOCK and thought it would be safer to just teach phys_to_target_node() to use that rather than update other code paths to expect node_data might not always reflect online data.

Quoted 5 lines

Esp., when hotplugging + onlining consecutive memory, there won't really be any intersections in most cases if I am not wrong. It would not be "intersection" but rather "closest fit".

With overlapping nodes it's even more unclear. Which one to pick?

In the overlap case you get what you get. Some signal is better than the noise of a dummy function. The consequences of picking the wrong node might be that the kernel can't properly associate a memory range to its performance data tables in firmware, but then again firmware messed up with an overlapping node definition in the first instance.

#13 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 62 lines · Dan Williams
Quoted 61 lines · David Hildenbrand
Quoted 58 lines · Mike Rapoport
Quoted 57 lines · Dan Williams
Quoted 39 lines · Mike Rapoport
Quoted 37 lines · David Hildenbrand
Quoted 36 lines · Mike Rapoport
Quoted 34 lines · Michal Hocko
Quoted 19 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 10 lines
arch/arm64/mm/numa.c +3 -2
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
- pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
  return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

We'll need to either add a CONFIG_ option or arch specific callback to make both non-empty (x86, powerpc, ia64) and empty (arm64, sh) implementations coexist ...

Note: I have a similar dummy (return 0) patch for s390x lying around here.

Then we'll call it a tie - 3:3 ;-)

So I'd be happy to jump on the train of people wanting to export the ARM stub for this (and add a new ARM stub for phys_to_target_node()), but Will did have a plausibly better idea that I have been meaning to circle back to:

http://lore.kernel.org/r/20200325111039.GA32109@willie-the-truck

...i.e. iterate over node data to do the lookup. This would seem to work generically for multiple archs unless I am missing something?

Quoted 8 lines
Quoted 2 lines

IIRC, only memory assigned to/onlined to a ZONE is represented in the pgdat node span. E.g., not offline memory blocks.

So this dovetails somewhat with Will's idea. What if we populated node_data for "offline" ranges? I started there, but then saw ARCH_KEEP_MEMBLOCK and thought it would be safer to just teach phys_to_target_node() to use that rather than update other code paths to expect node_data might not always reflect online data.

We currently need a somewhat-accurate pgdat node span to detect when to offline a node. See try_offline_node(). This works fairly reliable.

Shrinking the node span is currently fairly easy for !ZONE_DEVICE memory, because we can rely on pfn_to_online_page() + pfn_to_nid(pfn). See e.g., find_biggest_section_pfn().

If we glue growing/shrinking the node span to adding/removing of memory (instead of e.g., onlining/offlining), we can no longer base shrinking on memmap data. We would have to get the information ("how far can I shrink the node span, is it empty?") from somewhere else. E.g., for_each_memory_block() - but that one does not cover ZONE_DEVICE. And there are memory blocks which cover multiple nodes, in which case we only store one of them ... unreliable.

This certainly needs more thought :/

Quoted 5 lines
Quoted 5 lines

Esp., when hotplugging + onlining consecutive memory, there won't really be any intersections in most cases if I am not wrong. It would not be "intersection" but rather "closest fit".

Quoted 7 lines
Quoted 1 line

With overlapping nodes it's even more unclear. Which one to pick?

In the overlap case you get what you get. Some signal is better than the noise of a dummy function. The consequences of picking the wrong node might be that the kernel can't properly associate a memory range to its performance data tables in firmware, but then again firmware messed up with an overlapping node definition in the first instance.

I'd be curious if what we are trying to optimize here is actually worth optimizing. IOW, is there a well-known scenario where the dummy value on arm64 would be problematic and is worth the effort?

I mean, in all performance relevant setups (ignoring hv_balloon/xen-balloon/prove_store(), which also use memory_add_physaddr_to_nid()), we should have a proper PXM/node specified by the hardware on memory hotadd. The fallback of memory_add_physaddr_to_nid() is not relevant in these scenarios.

Signature · 3 lines
Thanks,

David / dhildenb
#14 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 38 lines · David Hildenbrand
Quoted 20 lines · Dan Williams
Quoted 19 lines · David Hildenbrand
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines · Jia He
Quoted 17 lines

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
Quoted 16 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
arch/arm64/mm/numa.c +3 -2
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
- pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
  return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Quoted 3 lines

I'd be curious if what we are trying to optimize here is actually worth optimizing. IOW, is there a well-known scenario where the dummy value on arm64 would be problematic and is worth the effort?

Well, it started with Michal's comment above that EXPORT_SYMBOL_GPL() for a stub might be an overkill.

I think Jia's suggestion [1] with addition of a comment that explains why and when the stub will be used, can work for both memory_add_physaddr_to_nid() and phys_to_target_node().

But on more theoretical/fundmanetal level, I think we lack a generic abstraction similar to e.g. x86 'struct numa_meminfo' that serves as translaton of firmware supplied information into data that can be used by the generic mm without need to reimplement it for each and every arch.

[1] https://lore.kernel.org/lkml/AM6PR08MB406907F9F2B13DA6DC893AD9F7670@AM6PR08MB4069.eurprd08.prod.outlook.com

Quoted 11 lines

I mean, in all performance relevant setups (ignoring hv_balloon/xen-balloon/prove_store(), which also use memory_add_physaddr_to_nid()), we should have a proper PXM/node specified by the hardware on memory hotadd. The fallback of memory_add_physaddr_to_nid() is not relevant in these scenarios.

Signature · 3 lines
Thanks,

David / dhildenb
Signature · 2 lines
Sincerely yours,
Mike.
#15 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 43 lines · Mike Rapoport
Quoted 38 lines · David Hildenbrand
Quoted 20 lines · Dan Williams
Quoted 19 lines · David Hildenbrand
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines · Jia He
Quoted 17 lines

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
Quoted 16 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
arch/arm64/mm/numa.c +3 -2
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
- pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
  return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Quoted 3 lines

I'd be curious if what we are trying to optimize here is actually worth optimizing. IOW, is there a well-known scenario where the dummy value on arm64 would be problematic and is worth the effort?

Quoted 6 lines

Well, it started with Michal's comment above that EXPORT_SYMBOL_GPL() for a stub might be an overkill.

I think Jia's suggestion [1] with addition of a comment that explains why and when the stub will be used, can work for both memory_add_physaddr_to_nid() and phys_to_target_node().

Agreed.

Quoted 6 lines

But on more theoretical/fundmanetal level, I think we lack a generic abstraction similar to e.g. x86 'struct numa_meminfo' that serves as translaton of firmware supplied information into data that can be used by the generic mm without need to reimplement it for each and every arch.

Right. As I expressed, I am not a friend of using memblock for that, and the pgdat node span is tricky.

Maybe abstracting that x86 concept is possible in some way (and we could restrict the information to boot-time properties, so we don't have to mess with memory hot(un)plug - just as done for numa_meminfo AFAIKS).

Signature · 3 lines
Thanks,

David / dhildenb
#16 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 60 lines · David Hildenbrand
Quoted 43 lines · Mike Rapoport
Quoted 38 lines · David Hildenbrand
Quoted 20 lines · Dan Williams
Quoted 19 lines · David Hildenbrand
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines · Jia He
Quoted 17 lines

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
Quoted 16 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
arch/arm64/mm/numa.c +3 -2
 /*
  * We hope that we will be hotplugging memory on nodes we already know about,
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
- pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
  return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Quoted 3 lines

I'd be curious if what we are trying to optimize here is actually worth optimizing. IOW, is there a well-known scenario where the dummy value on arm64 would be problematic and is worth the effort?

Quoted 6 lines

Well, it started with Michal's comment above that EXPORT_SYMBOL_GPL() for a stub might be an overkill.

I think Jia's suggestion [1] with addition of a comment that explains why and when the stub will be used, can work for both memory_add_physaddr_to_nid() and phys_to_target_node().

Agreed.

Quoted 6 lines

But on more theoretical/fundmanetal level, I think we lack a generic abstraction similar to e.g. x86 'struct numa_meminfo' that serves as translaton of firmware supplied information into data that can be used by the generic mm without need to reimplement it for each and every arch.

Quoted 6 lines

Right. As I expressed, I am not a friend of using memblock for that, and the pgdat node span is tricky.

Maybe abstracting that x86 concept is possible in some way (and we could restrict the information to boot-time properties, so we don't have to mess with memory hot(un)plug - just as done for numa_meminfo AFAIKS).

I agree with pgdat part and disagree about memblock. It already has non-init physmap, why won't we add memblock.memory to the mix? ;-)

Now, seriously, memblock already has all the necessary information about the coldplug memory for several architectures. x86 being an exception because for some reason the reserved memory is not considered memory there. The infrastructure for quiering and iterating memory regions is already there. We just need to leave out the irrelevant parts, like memblock.reserved and allocation funcions.

Otherwise we'll add yet another 'struct { start, end }', a horde of covnersion and re-initialization functions that will do more or less the same things as current memblock APIs.

Quoted 6 lines
Signature · 3 lines
Thanks,

David / dhildenb
Signature · 5 lines
Sincerely yours,
Mike.
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#17 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 64 lines · Mike Rapoport
Quoted 63 lines · David Hildenbrand
Quoted 43 lines · Mike Rapoport
Quoted 38 lines · David Hildenbrand
Quoted 20 lines · Dan Williams
Quoted 19 lines · David Hildenbrand
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines · Jia He
Quoted 17 lines

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case
NUMA_NO_NID is detected.

Suggested-by: David Hildenbrand <[email protected]>
Signed-off-by: Jia He <[email protected]>
---
arch/arm64/mm/numa.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/mm/numa.c b/arch/arm64/mm/numa.c
index aafcee3e3f7e..7eeb31740248 100644
--- a/arch/arm64/mm/numa.c
+++ b/arch/arm64/mm/numa.c
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)

Quoted 16 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

/*
* We hope that we will be hotplugging memory on nodes we already know about,
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present, the node
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback option.
*/
int memory_add_physaddr_to_nid(u64 addr)
{
- pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr);
return 0;
}
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Quoted 3 lines

I'd be curious if what we are trying to optimize here is actually worth optimizing. IOW, is there a well-known scenario where the dummy value on arm64 would be problematic and is worth the effort?

Quoted 6 lines

Well, it started with Michal's comment above that EXPORT_SYMBOL_GPL() for a stub might be an overkill.

I think Jia's suggestion [1] with addition of a comment that explains why and when the stub will be used, can work for both memory_add_physaddr_to_nid() and phys_to_target_node().

Agreed.

Quoted 6 lines

But on more theoretical/fundmanetal level, I think we lack a generic abstraction similar to e.g. x86 'struct numa_meminfo' that serves as translaton of firmware supplied information into data that can be used by the generic mm without need to reimplement it for each and every arch.

Right. As I expressed, I am not a friend of using memblock for that, and the pgdat node span is tricky.

Quoted 6 lines
Quoted 3 lines

Maybe abstracting that x86 concept is possible in some way (and we could restrict the information to boot-time properties, so we don't have to mess with memory hot(un)plug - just as done for numa_meminfo AFAIKS).

I agree with pgdat part and disagree about memblock. It already has non-init physmap, why won't we add memblock.memory to the mix? ;-)

Can we generalize and tweak physmap to contain node info? That's all we need, no? (the special mem= parameter handling should not matter for our use case, where "physmap" and "memory" would differ)

Quoted 7 lines

Now, seriously, memblock already has all the necessary information about the coldplug memory for several architectures. x86 being an exception because for some reason the reserved memory is not considered memory there. The infrastructure for quiering and iterating memory regions is already there. We just need to leave out the irrelevant parts, like memblock.reserved and allocation funcions.

I *really* don't want to mess with memblocks on memory hot(un)plug on x86 and s390x (+other architectures in the future). I also thought about stopping to create memblocks for hotplugged memory on arm64, by tweaking pfn_valid() to query memblocks only for early sections.

If "physmem" is not an option, can we at least introduce something like ARCH_UPDTAE_MEMBLOCK_ON_HOTPLUG to avoid doing that on x86 and s390x for now (and later maybe for others)?

Signature · 3 lines
Thanks,

David / dhildenb
#18 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 15 lines · David Hildenbrand
Quoted 14 lines · Mike Rapoport
Quoted 13 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

But on more theoretical/fundmanetal level, I think we lack a generic abstraction similar to e.g. x86 'struct numa_meminfo' that serves as translaton of firmware supplied information into data that can be used by the generic mm without need to reimplement it for each and every arch.

Right. As I expressed, I am not a friend of using memblock for that, and the pgdat node span is tricky.

Maybe abstracting that x86 concept is possible in some way (and we could restrict the information to boot-time properties, so we don't have to mess with memory hot(un)plug - just as done for numa_meminfo AFAIKS).

Quoted 6 lines
Quoted 2 lines

I agree with pgdat part and disagree about memblock. It already has non-init physmap, why won't we add memblock.memory to the mix? ;-)

Can we generalize and tweak physmap to contain node info? That's all we need, no? (the special mem= parameter handling should not matter for our use case, where "physmap" and "memory" would differ)

TBH, I have only random vague thoughts at the moment. This might be an option. But then we need to enable physmap on !s390, right?

Quoted 7 lines
Quoted 6 lines

Now, seriously, memblock already has all the necessary information about the coldplug memory for several architectures. x86 being an exception because for some reason the reserved memory is not considered memory there. The infrastructure for quiering and iterating memory regions is already there. We just need to leave out the irrelevant parts, like memblock.reserved and allocation funcions.

Quoted 8 lines

I *really* don't want to mess with memblocks on memory hot(un)plug on x86 and s390x (+other architectures in the future). I also thought about stopping to create memblocks for hotplugged memory on arm64, by tweaking pfn_valid() to query memblocks only for early sections.

If "physmem" is not an option, can we at least introduce something like ARCH_UPDTAE_MEMBLOCK_ON_HOTPLUG to avoid doing that on x86 and s390x for now (and later maybe for others)?

I have to do more memory hotplug howework to answer that ;-)

My general point is that we don't have to reinvent the wheel to have coldplug memory representation, it's already there. We just need a way to use it properly.

Quoted 5 lines
Signature · 3 lines
Thanks,

David / dhildenb
Signature · 2 lines
Sincerely yours,
Mike.
#19 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 19 lines · Mike Rapoport
Quoted 18 lines · David Hildenbrand
Quoted 16 lines · Mike Rapoport
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

But on more theoretical/fundmanetal level, I think we lack a generic abstraction similar to e.g. x86 'struct numa_meminfo' that serves as translaton of firmware supplied information into data that can be used by the generic mm without need to reimplement it for each and every arch.

Quoted 6 lines

Right. As I expressed, I am not a friend of using memblock for that, and the pgdat node span is tricky.

Maybe abstracting that x86 concept is possible in some way (and we could restrict the information to boot-time properties, so we don't have to mess with memory hot(un)plug - just as done for numa_meminfo AFAIKS).

I agree with pgdat part and disagree about memblock. It already has non-init physmap, why won't we add memblock.memory to the mix? ;-)

Quoted 6 lines
Quoted 3 lines

Can we generalize and tweak physmap to contain node info? That's all we need, no? (the special mem= parameter handling should not matter for our use case, where "physmap" and "memory" would differ)

TBH, I have only random vague thoughts at the moment. This might be an option. But then we need to enable physmap on !s390, right?

Yes, looks like it.

Quoted 17 lines
Quoted 8 lines
Quoted 7 lines

Now, seriously, memblock already has all the necessary information about the coldplug memory for several architectures. x86 being an exception because for some reason the reserved memory is not considered memory there. The infrastructure for quiering and iterating memory regions is already there. We just need to leave out the irrelevant parts, like memblock.reserved and allocation funcions.

Quoted 8 lines

I *really* don't want to mess with memblocks on memory hot(un)plug on x86 and s390x (+other architectures in the future). I also thought about stopping to create memblocks for hotplugged memory on arm64, by tweaking pfn_valid() to query memblocks only for early sections.

If "physmem" is not an option, can we at least introduce something like ARCH_UPDTAE_MEMBLOCK_ON_HOTPLUG to avoid doing that on x86 and s390x for now (and later maybe for others)?

Quoted 5 lines

I have to do more memory hotplug howework to answer that ;-)

My general point is that we don't have to reinvent the wheel to have coldplug memory representation, it's already there. We just need a way to use it properly.

Yes, I tend to agree. Details to be clarified :)

Signature · 6 lines
Thanks,

David / dhildenb
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#20 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 47 lines · David Hildenbrand
Quoted 19 lines · Mike Rapoport
Quoted 18 lines · David Hildenbrand
Quoted 16 lines · Mike Rapoport
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

But on more theoretical/fundmanetal level, I think we lack a generic abstraction similar to e.g. x86 'struct numa_meminfo' that serves as translaton of firmware supplied information into data that can be used by the generic mm without need to reimplement it for each and every arch.

Quoted 6 lines

Right. As I expressed, I am not a friend of using memblock for that, and the pgdat node span is tricky.

Maybe abstracting that x86 concept is possible in some way (and we could restrict the information to boot-time properties, so we don't have to mess with memory hot(un)plug - just as done for numa_meminfo AFAIKS).

I agree with pgdat part and disagree about memblock. It already has non-init physmap, why won't we add memblock.memory to the mix? ;-)

Quoted 6 lines
Quoted 3 lines

Can we generalize and tweak physmap to contain node info? That's all we need, no? (the special mem= parameter handling should not matter for our use case, where "physmap" and "memory" would differ)

TBH, I have only random vague thoughts at the moment. This might be an option. But then we need to enable physmap on !s390, right?

Yes, looks like it.

Quoted 17 lines
Quoted 16 lines
Quoted 7 lines

Now, seriously, memblock already has all the necessary information about the coldplug memory for several architectures. x86 being an exception because for some reason the reserved memory is not considered memory there. The infrastructure for quiering and iterating memory regions is already there. We just need to leave out the irrelevant parts, like memblock.reserved and allocation funcions.

I *really* don't want to mess with memblocks on memory hot(un)plug on x86 and s390x (+other architectures in the future). I also thought about stopping to create memblocks for hotplugged memory on arm64, by tweaking pfn_valid() to query memblocks only for early sections.

If "physmem" is not an option, can we at least introduce something like ARCH_UPDTAE_MEMBLOCK_ON_HOTPLUG to avoid doing that on x86 and s390x for now (and later maybe for others)?

Quoted 7 lines
Quoted 5 lines

I have to do more memory hotplug howework to answer that ;-)

My general point is that we don't have to reinvent the wheel to have coldplug memory representation, it's already there. We just need a way to use it properly.

Yes, I tend to agree. Details to be clarified :)

I'm not quite understanding the concern, or requirement about "updating memblock" in the hotplug path. The routines memory_add_physaddr_to_nid() and phys_to_target_node() are helpers to interrogate platform-firmware numa info through a common abstraction. They place no burden on the memory hotplug code they're just used to see if a hot-added range lies within an existing node span when platform-firmware otherwise fails to communicate a node. x86 can continue to back those helpers with numa_meminfo, arm64 can use a generic memblock implementation and other archs can follow the arm64 example if they want better numa answers for drivers.

#21 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 56 lines · Dan Williams
Quoted 47 lines · David Hildenbrand
Quoted 19 lines · Mike Rapoport
Quoted 18 lines · David Hildenbrand
Quoted 16 lines · Mike Rapoport
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

But on more theoretical/fundmanetal level, I think we lack a generic abstraction similar to e.g. x86 'struct numa_meminfo' that serves as translaton of firmware supplied information into data that can be used by the generic mm without need to reimplement it for each and every arch.

Quoted 6 lines

Right. As I expressed, I am not a friend of using memblock for that, and the pgdat node span is tricky.

Maybe abstracting that x86 concept is possible in some way (and we could restrict the information to boot-time properties, so we don't have to mess with memory hot(un)plug - just as done for numa_meminfo AFAIKS).

I agree with pgdat part and disagree about memblock. It already has non-init physmap, why won't we add memblock.memory to the mix? ;-)

Quoted 6 lines
Quoted 3 lines

Can we generalize and tweak physmap to contain node info? That's all we need, no? (the special mem= parameter handling should not matter for our use case, where "physmap" and "memory" would differ)

TBH, I have only random vague thoughts at the moment. This might be an option. But then we need to enable physmap on !s390, right?

Yes, looks like it.

Quoted 17 lines
Quoted 16 lines
Quoted 7 lines

Now, seriously, memblock already has all the necessary information about the coldplug memory for several architectures. x86 being an exception because for some reason the reserved memory is not considered memory there. The infrastructure for quiering and iterating memory regions is already there. We just need to leave out the irrelevant parts, like memblock.reserved and allocation funcions.

I *really* don't want to mess with memblocks on memory hot(un)plug on x86 and s390x (+other architectures in the future). I also thought about stopping to create memblocks for hotplugged memory on arm64, by tweaking pfn_valid() to query memblocks only for early sections.

If "physmem" is not an option, can we at least introduce something like ARCH_UPDTAE_MEMBLOCK_ON_HOTPLUG to avoid doing that on x86 and s390x for now (and later maybe for others)?

Quoted 7 lines
Quoted 5 lines

I have to do more memory hotplug howework to answer that ;-)

My general point is that we don't have to reinvent the wheel to have coldplug memory representation, it's already there. We just need a way to use it properly.

Yes, I tend to agree. Details to be clarified :)

Quoted 11 lines

I'm not quite understanding the concern, or requirement about "updating memblock" in the hotplug path. The routines memory_add_physaddr_to_nid() and phys_to_target_node() are helpers to interrogate platform-firmware numa info through a common abstraction. They place no burden on the memory hotplug code they're just used to see if a hot-added range lies within an existing node span when platform-firmware otherwise fails to communicate a node. x86 can continue to back those helpers with numa_meminfo, arm64 can use a generic memblock implementation and other archs can follow the arm64 example if they want better numa answers for drivers.

See memblock_add_node()/memblock_remove() in mm/memory_hotplug.c. I don't want that code be reactivated for x86/s390x. That's all I am saying.

Signature · 6 lines
Thanks,

David / dhildenb
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#22 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 16 lines · David Hildenbrand
Quoted 14 lines · Dan Williams
Quoted 1 line · David Hildenbrand

I'm not quite understanding the concern, or requirement about "updating memblock" in the hotplug path. The routines memory_add_physaddr_to_nid() and phys_to_target_node() are helpers to interrogate platform-firmware numa info through a common abstraction. They place no burden on the memory hotplug code they're just used to see if a hot-added range lies within an existing node span when platform-firmware otherwise fails to communicate a node. x86 can continue to back those helpers with numa_meminfo, arm64 can use a generic memblock implementation and other archs can follow the arm64 example if they want better numa answers for drivers.

Quoted 2 lines

See memblock_add_node()/memblock_remove() in mm/memory_hotplug.c. I don't want that code be reactivated for x86/s390x. That's all I am saying.

And these have actual meaning only on arm64 because powerpc does not rely on memblock for memory hot(un)plug, AFAIU.

Anyway, at the moment we can use memblock on hotplug path only on arm64 and I don't think its the path worth exploring.

Quoted 5 lines
Signature · 3 lines
Thanks,

David / dhildenb
Signature · 2 lines
Sincerely yours,
Mike.
author
#23 lore raw

RE: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

In reply to Michal Hocko

Hi Michal and David

Quoted 45 lines

-----Original Message-----
From: Michal Hocko <[email protected]>
Sent: Tuesday, July 7, 2020 7:55 PM
To: Justin He <[email protected]>
Cc: Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Dan Williams <[email protected]>; Vishal Verma <[email protected]>; Dave Jiang <[email protected]>; Andrew Morton <[email protected]>; Mike Rapoport <[email protected]>; Baoquan He <[email protected]>; Chuhong Yuan <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]; Kaly Xin <[email protected]>
Subject: Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 16 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 466

Quoted 3 lines
arch/arm64/mm/numa.c +0 -0
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know

about,

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 467

Quoted 2 lines
arch/arm64/mm/numa.c +1 -1
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present,

the node

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 468

Quoted 1 line
arch/arm64/mm/numa.c +1 -0
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback

option.

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 471

Quoted 4 lines
arch/arm64/mm/numa.c +0 -1
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
-	pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n",

addr);

Quoted 7 lines

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 3 lines
arch/arm64/mm/numa.c +1 -0
 	return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Okay, I can make a change in memory_hotplug.h, sth like:

include/linux/memory_hotplug.h +3 -3
@@ -149,13 +149,13 @@ int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
              struct mhp_params *params);
 #endif /* ARCH_HAS_ADD_PAGES */
 
-#ifdef CONFIG_NUMA
-extern int memory_add_physaddr_to_nid(u64 start);
-#else
+#if !defined(CONFIG_NUMA) || !defined(memory_add_physaddr_to_nid)
 static inline int memory_add_physaddr_to_nid(u64 start)
 {
        return 0;
 }
+#else
+extern int memory_add_physaddr_to_nid(u64 start);
 #endif
 

And then check the memory_add_physaddr_to_nid() helper on all arches, if it is noop(return 0), I can simply remove it.
if it is not noop, after the helper,
#define memory_add_physaddr_to_nid

What do you think of this proposal?

--
Cheers,
Justin (Jia He)

_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]

#24 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 80 lines · Justin He

Hi Michal and David

Quoted 44 lines

-----Original Message-----
From: Michal Hocko <[email protected]>
Sent: Tuesday, July 7, 2020 7:55 PM
To: Justin He <[email protected]>
Cc: Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Dan Williams <[email protected]>; Vishal Verma <[email protected]>; Dave Jiang <[email protected]>; Andrew Morton <[email protected]>; Mike Rapoport <[email protected]>; Baoquan He <[email protected]>; Chuhong Yuan <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]; Kaly Xin <[email protected]>
Subject: Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 16 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 466

Quoted 3 lines
arch/arm64/mm/numa.c +0 -0
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know

about,

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 467

Quoted 2 lines
arch/arm64/mm/numa.c +1 -1
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present,

the node

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 468

Quoted 1 line
arch/arm64/mm/numa.c +1 -0
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback

option.

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 471

Quoted 4 lines
arch/arm64/mm/numa.c +0 -1
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
-   pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n",
Quoted 8 lines

addr);

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 3 lines
arch/arm64/mm/numa.c +1 -0
    return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Okay, I can make a change in memory_hotplug.h, sth like:

include/linux/memory_hotplug.h +3 -3
@@ -149,13 +149,13 @@ int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
              struct mhp_params *params);
 #endif /* ARCH_HAS_ADD_PAGES */
 
-#ifdef CONFIG_NUMA
-extern int memory_add_physaddr_to_nid(u64 start);
-#else
+#if !defined(CONFIG_NUMA) || !defined(memory_add_physaddr_to_nid)
 static inline int memory_add_physaddr_to_nid(u64 start)
 {
        return 0;
 }
+#else
+extern int memory_add_physaddr_to_nid(u64 start);
 #endif
 
 And then check the memory_add_physaddr_to_nid() helper on all arches,

if it is noop(return 0), I can simply remove it.
if it is not noop, after the helper,
#define memory_add_physaddr_to_nid

Quoted 1 line

What do you think of this proposal?

Especially for architectures that use memblock info for numa info (which seems to be everyone except x86) why not implement a generic memory_add_physaddr_to_nid() that does:

int memory_add_physaddr_to_nid(u64 addr)

{
        unsigned long start_pfn, end_pfn, pfn = PHYS_PFN(addr);
        int nid;

        for_each_online_node(nid) {
                get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
                if (pfn >= start_pfn && pfn <= end_pfn)
                        return nid;
        }
        return NUMA_NO_NODE;
}
author
#25 lore raw

RE: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Hi Dan

Quoted 113 lines

-----Original Message-----
From: Dan Williams <[email protected]>
Sent: Wednesday, July 8, 2020 11:57 AM
To: Justin He <[email protected]>
Cc: Michal Hocko <[email protected]>; David Hildenbrand <[email protected]>; Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Vishal Verma <[email protected]>; Dave Jiang <[email protected]>; Andrew Morton <[email protected]>; Mike Rapoport <[email protected]>; Baoquan He <[email protected]>; Chuhong Yuan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; [email protected]; Kaly Xin <[email protected]>
Subject: Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 9 lines · Justin He

Hi Michal and David

Quoted 6 lines

-----Original Message-----
From: Michal Hocko <[email protected]>
Sent: Tuesday, July 7, 2020 7:55 PM
To: Justin He <[email protected]>
Cc: Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Dan Williams <[email protected]>; Vishal

Verma

Quoted 3 lines
Quoted 3 lines

<[email protected]>; Dave Jiang <[email protected]>; Andrew Morton <[email protected]>; Mike Rapoport <[email protected]>; Baoquan He <[email protected]>; Chuhong Yuan <[email protected]>;

linux-

Quoted 3 lines
Quoted 3 lines

[email protected]; [email protected]; linux- [email protected]; [email protected]; Kaly Xin <[email protected]>
Subject: Re: [PATCH v2 1/3] arm64/numa: export

memory_add_physaddr_to_nid

Quoted 6 lines
Quoted 6 lines

as EXPORT_SYMBOL_GPL

Quoted 3 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in

case

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 8 lines
Quoted 8 lines

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 466

Quoted 8 lines
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already

know

Quoted 2 lines
Quoted 2 lines

about,

Quoted 1 line
arch/arm64/mm/numa.c +0 -1
- * such that acpi_get_node() succeeds and we never fall back to

this...

Quoted 3 lines
Quoted 3 lines

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 467

Quoted 1 line
arch/arm64/mm/numa.c +1 -0
+ * such that acpi_get_node() succeeds. But when SRAT is not present,

the node

Quoted 1 line
arch/arm64/mm/numa.c +1 -0
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a

fallback

Quoted 5 lines
Quoted 5 lines

option.

Quoted 4 lines
arch/arm64/mm/numa.c +0 -1
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
-   pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n",
Quoted 7 lines
Quoted 7 lines

addr);

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 3 lines
arch/arm64/mm/numa.c +1 -0
    return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't

checked

Quoted 1 line
Quoted 1 line

whether there is an easy way to do that sanely bu this just hit my

eyes.

include/linux/memory_hotplug.h int add_pages(int nid, unsigned long start_pfn,

Quoted 5 lines

Okay, I can make a change in memory_hotplug.h, sth like:

include/linux/memory_hotplug.h +0 -0
@@ -149,13 +149,13 @@ int add_pages(int nid, unsigned long start_pfn,

unsigned long nr_pages,

Quoted 20 lines
include/linux/memory_hotplug.h +3 -3
              struct mhp_params *params);
 #endif /* ARCH_HAS_ADD_PAGES */
 
-#ifdef CONFIG_NUMA
-extern int memory_add_physaddr_to_nid(u64 start);
-#else
+#if !defined(CONFIG_NUMA) || !defined(memory_add_physaddr_to_nid)
 static inline int memory_add_physaddr_to_nid(u64 start)
 {
        return 0;
 }
+#else
+extern int memory_add_physaddr_to_nid(u64 start);
 #endif
 
 And then check the memory_add_physaddr_to_nid() helper on all arches,

if it is noop(return 0), I can simply remove it.
if it is not noop, after the helper,
#define memory_add_physaddr_to_nid

Quoted 1 line

What do you think of this proposal?

Especially for architectures that use memblock info for numa info (which seems to be everyone except x86) why not implement a generic memory_add_physaddr_to_nid() that does:

int memory_add_physaddr_to_nid(u64 addr)

Quoted 11 lines
{
        unsigned long start_pfn, end_pfn, pfn = PHYS_PFN(addr);
        int nid;

        for_each_online_node(nid) {
                get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
                if (pfn >= start_pfn && pfn <= end_pfn)
                        return nid;
        }
        return NUMA_NO_NODE;
}

Thanks for your suggestion,
Could I wrap the codes and let memory_add_physaddr_to_nid simply invoke phys_to_target_node()?

--
Cheers,
Justin (Jia He)

#26 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

On Tue, Jul 7, 2020 at 9:08 PM Justin He <[email protected]> wrote:
[..]

Quoted 17 lines
Quoted 5 lines

Especially for architectures that use memblock info for numa info (which seems to be everyone except x86) why not implement a generic memory_add_physaddr_to_nid() that does:

int memory_add_physaddr_to_nid(u64 addr)

Quoted 11 lines
{
        unsigned long start_pfn, end_pfn, pfn = PHYS_PFN(addr);
        int nid;

        for_each_online_node(nid) {
                get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
                if (pfn >= start_pfn && pfn <= end_pfn)
                        return nid;
        }
        return NUMA_NO_NODE;
}
Quoted 3 lines

Thanks for your suggestion,
Could I wrap the codes and let memory_add_physaddr_to_nid simply invoke phys_to_target_node()?

I think it needs to be the reverse. phys_to_target_node() should call memory_add_physaddr_to_nid() by default, but fall back to searching reserved memory address ranges in memblock. See phys_to_target_node() in arch/x86/mm/numa.c. That one uses numa_meminfo instead of memblock, but the principle is the same i.e. that a target node may not be represented in memblock.memory, but memblock.reserved. I'm working on a patch to provide a function similar to get_pfn_range_for_nid() that operates on reserved memory.

#27 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 23 lines · Dan Williams

On Tue, Jul 7, 2020 at 9:08 PM Justin He <[email protected]> wrote:
[..]

Quoted 17 lines
Quoted 5 lines

Especially for architectures that use memblock info for numa info (which seems to be everyone except x86) why not implement a generic memory_add_physaddr_to_nid() that does:

int memory_add_physaddr_to_nid(u64 addr)

Quoted 11 lines
{
        unsigned long start_pfn, end_pfn, pfn = PHYS_PFN(addr);
        int nid;

        for_each_online_node(nid) {
                get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
                if (pfn >= start_pfn && pfn <= end_pfn)
                        return nid;
        }
        return NUMA_NO_NODE;
}
Quoted 3 lines

Thanks for your suggestion,
Could I wrap the codes and let memory_add_physaddr_to_nid simply invoke phys_to_target_node()?

Quoted 8 lines

I think it needs to be the reverse. phys_to_target_node() should call memory_add_physaddr_to_nid() by default, but fall back to searching reserved memory address ranges in memblock. See phys_to_target_node() in arch/x86/mm/numa.c. That one uses numa_meminfo instead of memblock, but the principle is the same i.e. that a target node may not be represented in memblock.memory, but memblock.reserved. I'm working on a patch to provide a function similar to get_pfn_range_for_nid() that operates on reserved memory.

Do we really need yet another memblock iterator?
I think only x86 has memory that is not in memblock.memory but only in memblock.reserved.

Signature · 2 lines
Sincerely yours,
Mike.
#28 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

On Tue, Jul 7, 2020 at 11:22 PM Mike Rapoport <[email protected]> wrote:
[..]

Quoted 13 lines
Quoted 4 lines
Quoted 3 lines

Thanks for your suggestion,
Could I wrap the codes and let memory_add_physaddr_to_nid simply invoke phys_to_target_node()?

Quoted 8 lines

I think it needs to be the reverse. phys_to_target_node() should call memory_add_physaddr_to_nid() by default, but fall back to searching reserved memory address ranges in memblock. See phys_to_target_node() in arch/x86/mm/numa.c. That one uses numa_meminfo instead of memblock, but the principle is the same i.e. that a target node may not be represented in memblock.memory, but memblock.reserved. I'm working on a patch to provide a function similar to get_pfn_range_for_nid() that operates on reserved memory.

Quoted 3 lines

Do we really need yet another memblock iterator?
I think only x86 has memory that is not in memblock.memory but only in memblock.reserved.

Well, that's what led me here. EFI has introduced a memory attribute called "EFI Special Purpose Memory". I mapped it to a new Linux concept called Soft Reserved memory (commit b617c5266eed "efi: Common enable/disable infrastructure for EFI soft reservation"). The driver I want to claim that memory, device-dax, wants to be able to look up numa information for an address range that is marked reserved in memblock. The device-dax facility has the ability to either let userspace map a device, or assign the memory backing that device to the page allocator. In both scenarios the driver needs numa info to either populate the 'numa_node' property of the device in sysfs, or to pass an node-id to add_memory_resource() when it is hot-plugged.

I was thwarted by the lack of phys_to_target_node() on arm64, and rather than add another stub like memory_add_physaddr_to_nid() I wanted to see if it could be solved properly / generically with memblock data.

#29 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

In reply to Mike Rapoport
Quoted 33 lines · Mike Rapoport
Quoted 23 lines · Dan Williams

On Tue, Jul 7, 2020 at 9:08 PM Justin He <[email protected]> wrote:
[..]

Quoted 17 lines
Quoted 5 lines

Especially for architectures that use memblock info for numa info (which seems to be everyone except x86) why not implement a generic memory_add_physaddr_to_nid() that does:

int memory_add_physaddr_to_nid(u64 addr)

Quoted 11 lines
{
        unsigned long start_pfn, end_pfn, pfn = PHYS_PFN(addr);
        int nid;

        for_each_online_node(nid) {
                get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
                if (pfn >= start_pfn && pfn <= end_pfn)
                        return nid;
        }
        return NUMA_NO_NODE;
}
Quoted 3 lines

Thanks for your suggestion,
Could I wrap the codes and let memory_add_physaddr_to_nid simply invoke phys_to_target_node()?

Quoted 8 lines

I think it needs to be the reverse. phys_to_target_node() should call memory_add_physaddr_to_nid() by default, but fall back to searching reserved memory address ranges in memblock. See phys_to_target_node() in arch/x86/mm/numa.c. That one uses numa_meminfo instead of memblock, but the principle is the same i.e. that a target node may not be represented in memblock.memory, but memblock.reserved. I'm working on a patch to provide a function similar to get_pfn_range_for_nid() that operates on reserved memory.

Quoted 3 lines

Do we really need yet another memblock iterator?
I think only x86 has memory that is not in memblock.memory but only in memblock.reserved.

Reading about abusing the memblock allcoator once again in memory hotplug paths makes me shiver.

Signature · 3 lines
Thanks,

David / dhildenb
#30 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 35 lines · David Hildenbrand
Quoted 33 lines · Mike Rapoport
Quoted 31 lines · Dan Williams

On Tue, Jul 7, 2020 at 9:08 PM Justin He <[email protected]> wrote:
[..]

Quoted 17 lines
Quoted 5 lines

Especially for architectures that use memblock info for numa info (which seems to be everyone except x86) why not implement a generic memory_add_physaddr_to_nid() that does:

int memory_add_physaddr_to_nid(u64 addr)

Quoted 11 lines
{
        unsigned long start_pfn, end_pfn, pfn = PHYS_PFN(addr);
        int nid;

        for_each_online_node(nid) {
                get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
                if (pfn >= start_pfn && pfn <= end_pfn)
                        return nid;
        }
        return NUMA_NO_NODE;
}
Quoted 3 lines

Thanks for your suggestion,
Could I wrap the codes and let memory_add_physaddr_to_nid simply invoke phys_to_target_node()?

I think it needs to be the reverse. phys_to_target_node() should call memory_add_physaddr_to_nid() by default, but fall back to searching reserved memory address ranges in memblock. See phys_to_target_node() in arch/x86/mm/numa.c. That one uses numa_meminfo instead of memblock, but the principle is the same i.e. that a target node may not be represented in memblock.memory, but memblock.reserved. I'm working on a patch to provide a function similar to get_pfn_range_for_nid() that operates on reserved memory.

Quoted 6 lines
Quoted 3 lines

Do we really need yet another memblock iterator?
I think only x86 has memory that is not in memblock.memory but only in memblock.reserved.

Reading about abusing the memblock allcoator once again in memory hotplug paths makes me shiver.

Technical reasoning please?

arm64 numa information is established from memblock data. It seems counterproductive to ignore that fact if we're already touching memory_add_physaddr_to_nid() and have a use case for a driver to call it.

#31 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 36 lines · Dan Williams
Quoted 35 lines · David Hildenbrand
Quoted 33 lines · Mike Rapoport
Quoted 31 lines · Dan Williams

On Tue, Jul 7, 2020 at 9:08 PM Justin He <[email protected]> wrote:
[..]

Quoted 17 lines
Quoted 5 lines

Especially for architectures that use memblock info for numa info (which seems to be everyone except x86) why not implement a generic memory_add_physaddr_to_nid() that does:

int memory_add_physaddr_to_nid(u64 addr)

Quoted 11 lines
{
        unsigned long start_pfn, end_pfn, pfn = PHYS_PFN(addr);
        int nid;

        for_each_online_node(nid) {
                get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
                if (pfn >= start_pfn && pfn <= end_pfn)
                        return nid;
        }
        return NUMA_NO_NODE;
}
Quoted 3 lines

Thanks for your suggestion,
Could I wrap the codes and let memory_add_physaddr_to_nid simply invoke phys_to_target_node()?

I think it needs to be the reverse. phys_to_target_node() should call memory_add_physaddr_to_nid() by default, but fall back to searching reserved memory address ranges in memblock. See phys_to_target_node() in arch/x86/mm/numa.c. That one uses numa_meminfo instead of memblock, but the principle is the same i.e. that a target node may not be represented in memblock.memory, but memblock.reserved. I'm working on a patch to provide a function similar to get_pfn_range_for_nid() that operates on reserved memory.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Do we really need yet another memblock iterator?
I think only x86 has memory that is not in memblock.memory but only in memblock.reserved.

Reading about abusing the memblock allcoator once again in memory hotplug paths makes me shiver.

Technical reasoning please?

ARCH_KEEP_MEMBLOCK is (AFAIK) only a hack for arm64 to implement pfn_valid(), because they zap out individual pages corresponding to memory holes of full sections.

I am not a friend of adding more post-init code to rely on memblock data. It just makes it harder to eventually get rid of ARCH_KEEP_MEMBLOCK.

Quoted 5 lines

arm64 numa information is established from memblock data. It seems counterproductive to ignore that fact if we're already touching memory_add_physaddr_to_nid() and have a use case for a driver to call it.

... and we are trying to handle the "only a single dummy node" case (patch #2), or what am I missing? What is there to optimize currently?

Signature · 3 lines
Thanks,

David / dhildenb
#32 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 44 lines · David Hildenbrand
Quoted 43 lines · Dan Williams
Quoted 41 lines · David Hildenbrand
Quoted 33 lines · Mike Rapoport
Quoted 23 lines · Dan Williams

On Tue, Jul 7, 2020 at 9:08 PM Justin He <[email protected]> wrote:
[..]

Quoted 17 lines
Quoted 5 lines

Especially for architectures that use memblock info for numa info (which seems to be everyone except x86) why not implement a generic memory_add_physaddr_to_nid() that does:

int memory_add_physaddr_to_nid(u64 addr)

Quoted 11 lines
{
        unsigned long start_pfn, end_pfn, pfn = PHYS_PFN(addr);
        int nid;

        for_each_online_node(nid) {
                get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
                if (pfn >= start_pfn && pfn <= end_pfn)
                        return nid;
        }
        return NUMA_NO_NODE;
}
Quoted 3 lines

Thanks for your suggestion,
Could I wrap the codes and let memory_add_physaddr_to_nid simply invoke phys_to_target_node()?

Quoted 8 lines

I think it needs to be the reverse. phys_to_target_node() should call memory_add_physaddr_to_nid() by default, but fall back to searching reserved memory address ranges in memblock. See phys_to_target_node() in arch/x86/mm/numa.c. That one uses numa_meminfo instead of memblock, but the principle is the same i.e. that a target node may not be represented in memblock.memory, but memblock.reserved. I'm working on a patch to provide a function similar to get_pfn_range_for_nid() that operates on reserved memory.

Quoted 3 lines

Do we really need yet another memblock iterator?
I think only x86 has memory that is not in memblock.memory but only in memblock.reserved.

Reading about abusing the memblock allcoator once again in memory hotplug paths makes me shiver.

Quoted 8 lines
Quoted 1 line

Technical reasoning please?

ARCH_KEEP_MEMBLOCK is (AFAIK) only a hack for arm64 to implement pfn_valid(), because they zap out individual pages corresponding to memory holes of full sections.

I am not a friend of adding more post-init code to rely on memblock data. It just makes it harder to eventually get rid of ARCH_KEEP_MEMBLOCK.

The most heavy user of memblock in post-init code is powerpc. It won't be easy to get rid of it there.

Quoted 13 lines
Quoted 4 lines

arm64 numa information is established from memblock data. It seems counterproductive to ignore that fact if we're already touching memory_add_physaddr_to_nid() and have a use case for a driver to call it.

... and we are trying to handle the "only a single dummy node" case (patch #2), or what am I missing? What is there to optimize currently?

Signature · 3 lines
Thanks,

David / dhildenb
Signature · 2 lines
Sincerely yours,
Mike.
#33 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

In reply to Dan Williams
Quoted 81 lines · Dan Williams
Quoted 80 lines · Justin He

Hi Michal and David

Quoted 44 lines

-----Original Message-----
From: Michal Hocko <[email protected]>
Sent: Tuesday, July 7, 2020 7:55 PM
To: Justin He <[email protected]>
Cc: Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Dan Williams <[email protected]>; Vishal Verma <[email protected]>; Dave Jiang <[email protected]>; Andrew Morton <[email protected]>; Mike Rapoport <[email protected]>; Baoquan He <[email protected]>; Chuhong Yuan <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]; Kaly Xin <[email protected]>
Subject: Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 16 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 466

Quoted 3 lines
arch/arm64/mm/numa.c +0 -0
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know

about,

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 467

Quoted 2 lines
arch/arm64/mm/numa.c +1 -1
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present,

the node

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 468

Quoted 1 line
arch/arm64/mm/numa.c +1 -0
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback

option.

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 471

Quoted 4 lines
arch/arm64/mm/numa.c +0 -1
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
-   pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n",
Quoted 8 lines

addr);

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 3 lines
arch/arm64/mm/numa.c +1 -0
    return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Okay, I can make a change in memory_hotplug.h, sth like:

include/linux/memory_hotplug.h +3 -3
@@ -149,13 +149,13 @@ int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
              struct mhp_params *params);
 #endif /* ARCH_HAS_ADD_PAGES */
 
-#ifdef CONFIG_NUMA
-extern int memory_add_physaddr_to_nid(u64 start);
-#else
+#if !defined(CONFIG_NUMA) || !defined(memory_add_physaddr_to_nid)
 static inline int memory_add_physaddr_to_nid(u64 start)
 {
        return 0;
 }
+#else
+extern int memory_add_physaddr_to_nid(u64 start);
 #endif
 
 And then check the memory_add_physaddr_to_nid() helper on all arches,

if it is noop(return 0), I can simply remove it.
if it is not noop, after the helper,
#define memory_add_physaddr_to_nid

Quoted 5 lines
Quoted 1 line

What do you think of this proposal?

Especially for architectures that use memblock info for numa info (which seems to be everyone except x86) why not implement a generic memory_add_physaddr_to_nid() that does:

That would be only arm64.

Quoted 12 lines

int memory_add_physaddr_to_nid(u64 addr)

{
        unsigned long start_pfn, end_pfn, pfn = PHYS_PFN(addr);
        int nid;

        for_each_online_node(nid) {
                get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
                if (pfn >= start_pfn && pfn <= end_pfn)
                        return nid;
        }
        return NUMA_NO_NODE;
}
Signature · 2 lines
Sincerely yours,
Mike.
#34 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 83 lines · Mike Rapoport
Quoted 81 lines · Dan Williams
Quoted 80 lines · Justin He

Hi Michal and David

Quoted 44 lines

-----Original Message-----
From: Michal Hocko <[email protected]>
Sent: Tuesday, July 7, 2020 7:55 PM
To: Justin He <[email protected]>
Cc: Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Dan Williams <[email protected]>; Vishal Verma <[email protected]>; Dave Jiang <[email protected]>; Andrew Morton <[email protected]>; Mike Rapoport <[email protected]>; Baoquan He <[email protected]>; Chuhong Yuan <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]; Kaly Xin <[email protected]>
Subject: Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 16 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 466

Quoted 3 lines
arch/arm64/mm/numa.c +0 -0
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know

about,

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 467

Quoted 2 lines
arch/arm64/mm/numa.c +1 -1
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present,

the node

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 468

Quoted 1 line
arch/arm64/mm/numa.c +1 -0
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback

option.

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 471

Quoted 4 lines
arch/arm64/mm/numa.c +0 -1
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
-   pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n",
Quoted 8 lines

addr);

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 3 lines
arch/arm64/mm/numa.c +1 -0
    return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Okay, I can make a change in memory_hotplug.h, sth like:

include/linux/memory_hotplug.h +3 -3
@@ -149,13 +149,13 @@ int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
              struct mhp_params *params);
 #endif /* ARCH_HAS_ADD_PAGES */
 
-#ifdef CONFIG_NUMA
-extern int memory_add_physaddr_to_nid(u64 start);
-#else
+#if !defined(CONFIG_NUMA) || !defined(memory_add_physaddr_to_nid)
 static inline int memory_add_physaddr_to_nid(u64 start)
 {
        return 0;
 }
+#else
+extern int memory_add_physaddr_to_nid(u64 start);
 #endif
 
 And then check the memory_add_physaddr_to_nid() helper on all arches,

if it is noop(return 0), I can simply remove it.
if it is not noop, after the helper,
#define memory_add_physaddr_to_nid

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

What do you think of this proposal?

Especially for architectures that use memblock info for numa info (which seems to be everyone except x86) why not implement a generic memory_add_physaddr_to_nid() that does:

That would be only arm64.

Darn, I saw ARCH_KEEP_MEMBLOCK and had delusions of grandeur that it could solve my numa api woes. At least for x86 the problem is already solved with reserved numa_meminfo, but now I'm trying to write generic drivers that use those apis and finding these gaps on other archs.

#35 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 90 lines · Dan Williams
Quoted 89 lines · Mike Rapoport
Quoted 86 lines · Dan Williams
Quoted 80 lines · Justin He

Hi Michal and David

Quoted 44 lines

-----Original Message-----
From: Michal Hocko <[email protected]>
Sent: Tuesday, July 7, 2020 7:55 PM
To: Justin He <[email protected]>
Cc: Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Dan Williams <[email protected]>; Vishal Verma <[email protected]>; Dave Jiang <[email protected]>; Andrew Morton <[email protected]>; Mike Rapoport <[email protected]>; Baoquan He <[email protected]>; Chuhong Yuan <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]; Kaly Xin <[email protected]>
Subject: Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 16 lines · Jia He

This exports memory_add_physaddr_to_nid() for module driver to use.

memory_add_physaddr_to_nid() is a fallback option to get the nid in case NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 466

Quoted 3 lines
arch/arm64/mm/numa.c +0 -0
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we already know

about,

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 467

Quoted 2 lines
arch/arm64/mm/numa.c +1 -1
- * such that acpi_get_node() succeeds and we never fall back to this...
+ * such that acpi_get_node() succeeds. But when SRAT is not present,

the node

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 468

Quoted 1 line
arch/arm64/mm/numa.c +1 -0
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a fallback

option.

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 471

Quoted 4 lines
arch/arm64/mm/numa.c +0 -1
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
-   pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n",
Quoted 8 lines

addr);

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 3 lines
arch/arm64/mm/numa.c +1 -0
    return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more sense to simply make it static inline somewhere in a header? I haven't checked whether there is an easy way to do that sanely bu this just hit my eyes.

Okay, I can make a change in memory_hotplug.h, sth like:

include/linux/memory_hotplug.h +3 -3
@@ -149,13 +149,13 @@ int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
              struct mhp_params *params);
 #endif /* ARCH_HAS_ADD_PAGES */
 
-#ifdef CONFIG_NUMA
-extern int memory_add_physaddr_to_nid(u64 start);
-#else
+#if !defined(CONFIG_NUMA) || !defined(memory_add_physaddr_to_nid)
 static inline int memory_add_physaddr_to_nid(u64 start)
 {
        return 0;
 }
+#else
+extern int memory_add_physaddr_to_nid(u64 start);
 #endif
 
 And then check the memory_add_physaddr_to_nid() helper on all arches,

if it is noop(return 0), I can simply remove it.
if it is not noop, after the helper,
#define memory_add_physaddr_to_nid

Quoted 1 line

What do you think of this proposal?

Especially for architectures that use memblock info for numa info (which seems to be everyone except x86) why not implement a generic memory_add_physaddr_to_nid() that does:

Quoted 7 lines
Quoted 2 lines

That would be only arm64.

Darn, I saw ARCH_KEEP_MEMBLOCK and had delusions of grandeur that it could solve my numa api woes. At least for x86 the problem is already solved with reserved numa_meminfo, but now I'm trying to write generic drivers that use those apis and finding these gaps on other archs.

I'm not sure if x86's numa_meminfo is a part of the solution or a part of the problem ;-)
Anyway, this all indeed messy and there is a lot to improve there.

Signature · 2 lines
Sincerely yours,
Mike.
#36 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

On Tue, Jul 7, 2020 at 11:20 PM Mike Rapoport <[email protected]> wrote:
[..]

Quoted 7 lines
Quoted 4 lines

Darn, I saw ARCH_KEEP_MEMBLOCK and had delusions of grandeur that it could solve my numa api woes. At least for x86 the problem is already solved with reserved numa_meminfo, but now I'm trying to write generic drivers that use those apis and finding these gaps on other archs.

I'm not sure if x86's numa_meminfo is a part of the solution or a part of the problem ;-)

More the latter, but hopefully it can remain an exception and not the rule.

author
#37 lore raw

RE: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

In reply to Dan Williams

Hi Dan

Quoted 123 lines

-----Original Message-----
From: Dan Williams <[email protected]>
Sent: Wednesday, July 8, 2020 1:48 PM
To: Mike Rapoport <[email protected]>
Cc: Justin He <[email protected]>; Michal Hocko <[email protected]>; David Hildenbrand <[email protected]>; Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Vishal Verma <[email protected]>; Dave Jiang <[email protected]>; Andrew Morton <akpm@linux- foundation.org>; Baoquan He <[email protected]>; Chuhong Yuan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; [email protected]; Kaly Xin <[email protected]>
Subject: Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 4 lines · Mike Rapoport
Quoted 2 lines · Dan Williams
Quoted 1 line · Justin He
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Hi Michal and David

Quoted 6 lines

-----Original Message-----
From: Michal Hocko <[email protected]>
Sent: Tuesday, July 7, 2020 7:55 PM
To: Justin He <[email protected]>
Cc: Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Dan Williams <[email protected]>; Vishal

Verma

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

<[email protected]>; Dave Jiang <[email protected]>;

Andrew

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Morton <[email protected]>; Mike Rapoport

<[email protected]>;

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Baoquan He <[email protected]>; Chuhong Yuan <[email protected]>;

linux-

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

[email protected]; [email protected];

linux-

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

[email protected]; [email protected]; Kaly Xin

<[email protected]>

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Subject: Re: [PATCH v2 1/3] arm64/numa: export

memory_add_physaddr_to_nid

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

as EXPORT_SYMBOL_GPL

Quoted 1 line · Jia He

This exports memory_add_physaddr_to_nid() for module driver to

use.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

memory_add_physaddr_to_nid() is a fallback option to get the nid

in case

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 466

Quoted 8 lines
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we

already know

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

about,

Quoted 1 line
arch/arm64/mm/numa.c +0 -1
- * such that acpi_get_node() succeeds and we never fall back to

this...

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 467

Quoted 1 line
arch/arm64/mm/numa.c +1 -0
+ * such that acpi_get_node() succeeds. But when SRAT is not

present,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

the node

Quoted 1 line
arch/arm64/mm/numa.c +1 -0
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a

fallback

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

option.

Quoted 4 lines
arch/arm64/mm/numa.c +0 -1
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
-   pr_warn("Unknown node for memory at 0x%llx, assuming node

0\n",

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

addr);

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 3 lines
arch/arm64/mm/numa.c +1 -0
    return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more

sense

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to simply make it static inline somewhere in a header? I haven't

checked

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

whether there is an easy way to do that sanely bu this just hit my

eyes.

Quoted 5 lines
Quoted 5 lines

include/linux/memory_hotplug.h int add_pages(int nid, unsigned long start_pfn,

Quoted 5 lines

Okay, I can make a change in memory_hotplug.h, sth like:

include/linux/memory_hotplug.h +0 -0
@@ -149,13 +149,13 @@ int add_pages(int nid, unsigned long start_pfn,

unsigned long nr_pages,

Quoted 26 lines
Quoted 25 lines
Quoted 20 lines
include/linux/memory_hotplug.h +3 -3
              struct mhp_params *params);
 #endif /* ARCH_HAS_ADD_PAGES */
 
-#ifdef CONFIG_NUMA
-extern int memory_add_physaddr_to_nid(u64 start);
-#else
+#if !defined(CONFIG_NUMA) || !defined(memory_add_physaddr_to_nid)
 static inline int memory_add_physaddr_to_nid(u64 start)
 {
        return 0;
 }
+#else
+extern int memory_add_physaddr_to_nid(u64 start);
 #endif
 
 And then check the memory_add_physaddr_to_nid() helper on all arches,

if it is noop(return 0), I can simply remove it.
if it is not noop, after the helper,
#define memory_add_physaddr_to_nid

Quoted 1 line

What do you think of this proposal?

Especially for architectures that use memblock info for numa info (which seems to be everyone except x86) why not implement a generic memory_add_physaddr_to_nid() that does:

Quoted 7 lines
Quoted 2 lines

That would be only arm64.

Darn, I saw ARCH_KEEP_MEMBLOCK and had delusions of grandeur that it could solve my numa api woes. At least for x86 the problem is already solved with reserved numa_meminfo, but now I'm trying to write generic drivers that use those apis and finding these gaps on other archs.

Even on arm64, there is a dependency issue in dax_pmem kmem case. If dax pmem uses memory_add_physaddr_to_nid() to decide which node that memblock should add into, get_pfn_range_for_nid() might not have the correct memblock info at that time. That is, get_pfn_range_for_nid() can't get the correct memblock info before add_memory()

So IMO, memory_add_physaddr_to_nid() still have to implement as noop on arm64 (return 0) together with sh,s390x? Powerpc, x86,ia64 can use their own implementation. And phys_to_target_node() can use your suggested( for_each_online_node() ...)

What do you think of it? Thanks

--
Cheers,
Justin (Jia He)

_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]

#38 lore raw

Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 139 lines · Justin He

Hi Dan

Quoted 123 lines

-----Original Message-----
From: Dan Williams <[email protected]>
Sent: Wednesday, July 8, 2020 1:48 PM
To: Mike Rapoport <[email protected]>
Cc: Justin He <[email protected]>; Michal Hocko <[email protected]>; David Hildenbrand <[email protected]>; Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Vishal Verma <[email protected]>; Dave Jiang <[email protected]>; Andrew Morton <akpm@linux- foundation.org>; Baoquan He <[email protected]>; Chuhong Yuan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; [email protected]; Kaly Xin <[email protected]>
Subject: Re: [PATCH v2 1/3] arm64/numa: export memory_add_physaddr_to_nid as EXPORT_SYMBOL_GPL

Quoted 4 lines · Mike Rapoport
Quoted 2 lines · Dan Williams
Quoted 1 line · Justin He
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Hi Michal and David

Quoted 6 lines

-----Original Message-----
From: Michal Hocko <[email protected]>
Sent: Tuesday, July 7, 2020 7:55 PM
To: Justin He <[email protected]>
Cc: Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Dan Williams <[email protected]>; Vishal

Verma

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

<[email protected]>; Dave Jiang <[email protected]>;

Andrew

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Morton <[email protected]>; Mike Rapoport

<[email protected]>;

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Baoquan He <[email protected]>; Chuhong Yuan <[email protected]>;

linux-

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

[email protected]; [email protected];

linux-

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

[email protected]; [email protected]; Kaly Xin

<[email protected]>

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Subject: Re: [PATCH v2 1/3] arm64/numa: export

memory_add_physaddr_to_nid

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

as EXPORT_SYMBOL_GPL

Quoted 1 line · Jia He

This exports memory_add_physaddr_to_nid() for module driver to

use.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

memory_add_physaddr_to_nid() is a fallback option to get the nid

in case

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

NUMA_NO_NID is detected.

---
 arch/arm64/mm/numa.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 466

Quoted 8 lines
arch/arm64/mm/numa.c +0 -0
index aafcee3e3f7e..7eeb31740248 100644
@@ -464,10 +464,11 @@ void __init arm64_numa_init(void)
 
 /*
  * We hope that we will be hotplugging memory on nodes we

already know

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

about,

Quoted 1 line
arch/arm64/mm/numa.c +0 -1
- * such that acpi_get_node() succeeds and we never fall back to

this...

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 467

Quoted 1 line
arch/arm64/mm/numa.c +1 -0
+ * such that acpi_get_node() succeeds. But when SRAT is not

present,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

the node

Quoted 1 line
arch/arm64/mm/numa.c +1 -0
+ * id may be probed as NUMA_NO_NODE by acpi, Here provide a

fallback

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

option.

Quoted 4 lines
arch/arm64/mm/numa.c +0 -1
  */
 int memory_add_physaddr_to_nid(u64 addr)
 {
-   pr_warn("Unknown node for memory at 0x%llx, assuming node

0\n",

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

addr);

arch/arm64/mm/numa.c void __init arm64_numa_init(void) · line 474

Quoted 3 lines
arch/arm64/mm/numa.c +1 -0
    return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);

Does it make sense to export a noop function? Wouldn't make more

sense

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to simply make it static inline somewhere in a header? I haven't

checked

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

whether there is an easy way to do that sanely bu this just hit my

eyes.

Quoted 5 lines
Quoted 5 lines

include/linux/memory_hotplug.h int add_pages(int nid, unsigned long start_pfn,

Quoted 5 lines

Okay, I can make a change in memory_hotplug.h, sth like:

include/linux/memory_hotplug.h +0 -0
@@ -149,13 +149,13 @@ int add_pages(int nid, unsigned long start_pfn,

unsigned long nr_pages,

Quoted 26 lines
Quoted 25 lines
Quoted 20 lines
include/linux/memory_hotplug.h +3 -3
              struct mhp_params *params);
 #endif /* ARCH_HAS_ADD_PAGES */
 
-#ifdef CONFIG_NUMA
-extern int memory_add_physaddr_to_nid(u64 start);
-#else
+#if !defined(CONFIG_NUMA) || !defined(memory_add_physaddr_to_nid)
 static inline int memory_add_physaddr_to_nid(u64 start)
 {
        return 0;
 }
+#else
+extern int memory_add_physaddr_to_nid(u64 start);
 #endif
 
 And then check the memory_add_physaddr_to_nid() helper on all arches,

if it is noop(return 0), I can simply remove it.
if it is not noop, after the helper,
#define memory_add_physaddr_to_nid

Quoted 1 line

What do you think of this proposal?

Especially for architectures that use memblock info for numa info (which seems to be everyone except x86) why not implement a generic memory_add_physaddr_to_nid() that does:

Quoted 7 lines
Quoted 2 lines

That would be only arm64.

Darn, I saw ARCH_KEEP_MEMBLOCK and had delusions of grandeur that it could solve my numa api woes. At least for x86 the problem is already solved with reserved numa_meminfo, but now I'm trying to write generic drivers that use those apis and finding these gaps on other archs.

Even on arm64, there is a dependency issue in dax_pmem kmem case. If dax pmem uses memory_add_physaddr_to_nid() to decide which node that memblock should add into, get_pfn_range_for_nid() might not have the correct memblock info at that time. That is, get_pfn_range_for_nid() can't get the correct memblock info before add_memory()

Quoted 6 lines

So IMO, memory_add_physaddr_to_nid() still have to implement as noop on arm64 (return 0) together with sh,s390x? Powerpc, x86,ia64 can use their own implementation. And phys_to_target_node() can use your suggested( for_each_online_node() ...)

What do you think of it? Thanks

You are trying to fix the "we only have one dummy node" AFAIU, so what you propose here is certainly good enough for now.

Signature · 3 lines
Thanks,

David / dhildenb
author
#39 lore raw

RFC PATCH v2 2/3 device-dax: use fallback nid when numa_node is invalid

In reply to Jia He

Previously, numa_off is set unconditionally at the end of dummy_numa_init(), even with a fake numa node. Then ACPI detects node id as NUMA_NO_NODE(-1) in acpi_map_pxm_to_node() because it regards numa_off as turning off the numa node. Hence dev_dax->target_node is NUMA_NO_NODE on arm64 with fake numa.

Without this patch, pmem can't be probed as a RAM device on arm64 if SRAT table isn't present:
$ndctl create-namespace -fe namespace0.0 --mode=devdax --map=dev -s 1g -a 64K kmem dax0.0: rejecting DAX region [mem 0x240400000-0x2bfffffff] with invalid node: -1
kmem: probe of dax0.0 failed with error -22

This fixes it by using fallback memory_add_physaddr_to_nid() as nid.

---
I noticed that on powerpc memory_add_physaddr_to_nid is not exported for module driver. Set it to RFC due to this concern.

 drivers/dax/kmem.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
drivers/dax/kmem.c +14 -8
index 275aa5f87399..68e693ca6d59 100644
@@ -28,20 +28,22 @@ int dev_dax_kmem_probe(struct device *dev)
 	resource_size_t kmem_end;
 	struct resource *new_res;
 	const char *new_res_name;
-	int numa_node;
+	int numa_node, new_node;
 	int rc;
 
 	/*
 	 * Ensure good NUMA information for the persistent memory.
-	 * Without this check, there is a risk that slow memory
-	 * could be mixed in a node with faster memory, causing
-	 * unavoidable performance issues.
+	 * Without this check, there is a risk but not fatal that slow
+	 * memory could be mixed in a node with faster memory, causing
+	 * unavoidable performance issues. Furthermore, fallback node
+	 * id can be used when numa_node is invalid.
 	 */
 	numa_node = dev_dax->target_node;
 	if (numa_node < 0) {
-		dev_warn(dev, "rejecting DAX region %pR with invalid node: %d\n",
-			 res, numa_node);
-		return -EINVAL;
+		new_node = memory_add_physaddr_to_nid(kmem_start);
+		dev_info(dev, "changing nid from %d to %d for DAX region %pR\n",
+			numa_node, new_node, res);
+		numa_node = new_node;
 	}
 
 	/* Hotplug starting at the beginning of the next block: */
@@ -100,6 +102,7 @@ static int dev_dax_kmem_remove(struct device *dev)
 	resource_size_t kmem_start = res->start;
 	resource_size_t kmem_size = resource_size(res);
 	const char *res_name = res->name;
+	int numa_node = dev_dax->target_node;
 	int rc;
 
 	/*
@@ -108,7 +111,10 @@ static int dev_dax_kmem_remove(struct device *dev)
 	 * there is no way to hotremove this memory until reboot because device
 	 * unbind will succeed even if we return failure.
 	 */
-	rc = remove_memory(dev_dax->target_node, kmem_start, kmem_size);
+	if (numa_node < 0)
+		numa_node = memory_add_physaddr_to_nid(kmem_start);
+
+	rc = remove_memory(numa_node, kmem_start, kmem_size);
 	if (rc) {
 		any_hotremove_failed = true;
 		dev_err(dev,
Signature · 1 line
2.17.1
author
#40 lore raw

RE: [RFC PATCH v2 2/3] device-dax: use fallback nid when numa_node is invalid

[+] add Powerpc maintainers to check my concern about memory_add_physaddr_to_nid Exporting

--
Cheers,
Justin (Jia He)

Quoted 102 lines

-----Original Message-----
From: Jia He <[email protected]>
Sent: Tuesday, July 7, 2020 1:59 PM
To: Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Dan Williams <[email protected]>; Vishal Verma <[email protected]>; Dave Jiang <[email protected]>
Cc: Michal Hocko <[email protected]>; Andrew Morton <akpm@linux- foundation.org>; Mike Rapoport <[email protected]>; Baoquan He <[email protected]>; Chuhong Yuan <[email protected]>; linux-arm- [email protected]; [email protected]; linux- [email protected]; [email protected]; Kaly Xin <[email protected]>; Justin He <[email protected]>
Subject: [RFC PATCH v2 2/3] device-dax: use fallback nid when numa_node is invalid

Previously, numa_off is set unconditionally at the end of dummy_numa_init(),
even with a fake numa node. Then ACPI detects node id as NUMA_NO_NODE(-1) in
acpi_map_pxm_to_node() because it regards numa_off as turning off the numa node. Hence dev_dax->target_node is NUMA_NO_NODE on arm64 with fake numa.

Without this patch, pmem can't be probed as a RAM device on arm64 if SRAT table
isn't present:
$ndctl create-namespace -fe namespace0.0 --mode=devdax --map=dev -s 1g -a 64K
kmem dax0.0: rejecting DAX region [mem 0x240400000-0x2bfffffff] with invalid node: -1
kmem: probe of dax0.0 failed with error -22

This fixes it by using fallback memory_add_physaddr_to_nid() as nid.

---
I noticed that on powerpc memory_add_physaddr_to_nid is not exported for module
driver. Set it to RFC due to this concern.

 drivers/dax/kmem.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
drivers/dax/kmem.c +9 -7
index 275aa5f87399..68e693ca6d59 100644
@@ -28,20 +28,22 @@ int dev_dax_kmem_probe(struct device *dev)
 	resource_size_t kmem_end;
 	struct resource *new_res;
 	const char *new_res_name;
-	int numa_node;
+	int numa_node, new_node;
 	int rc;
 
 	/*
 	 * Ensure good NUMA information for the persistent memory.
-	 * Without this check, there is a risk that slow memory
-	 * could be mixed in a node with faster memory, causing
-	 * unavoidable performance issues.
+	 * Without this check, there is a risk but not fatal that slow
+	 * memory could be mixed in a node with faster memory, causing
+	 * unavoidable performance issues. Furthermore, fallback node
+	 * id can be used when numa_node is invalid.
 	 */
 	numa_node = dev_dax->target_node;
 	if (numa_node < 0) {
-		dev_warn(dev, "rejecting DAX region %pR with invalid
 node: %d\n",
-			 res, numa_node);
-		return -EINVAL;
+		new_node = memory_add_physaddr_to_nid(kmem_start);
+		dev_info(dev, "changing nid from %d to %d for DAX
 region %pR\n",
+			numa_node, new_node, res);
+		numa_node = new_node;
 	}
drivers/dax/kmem.c +1 -0
 	/* Hotplug starting at the beginning of the next block: */
@@ -100,6 +102,7 @@ static int dev_dax_kmem_remove(struct device *dev)
 	resource_size_t kmem_start = res->start;
 	resource_size_t kmem_size = resource_size(res);
 	const char *res_name = res->name;
+	int numa_node = dev_dax->target_node;
 	int rc;
 
 	/*
@@ -108,7 +111,10 @@ static int dev_dax_kmem_remove(struct device *dev)
 	 * there is no way to hotremove this memory until reboot because

device

drivers/dax/kmem.c +4 -2
 	 * unbind will succeed even if we return failure.
 	 */
-	rc = remove_memory(dev_dax->target_node, kmem_start, kmem_size);
+	if (numa_node < 0)
+		numa_node = memory_add_physaddr_to_nid(kmem_start);
+
+	rc = remove_memory(numa_node, kmem_start, kmem_size);
 	if (rc) {
 		any_hotremove_failed = true;
 		dev_err(dev,
--

2.17.1

#41 lore raw

Re: [RFC PATCH v2 2/3] device-dax: use fallback nid when numa_node is invalid

In reply to Jia He
Quoted 43 lines · Jia He

Previously, numa_off is set unconditionally at the end of dummy_numa_init(), even with a fake numa node. Then ACPI detects node id as NUMA_NO_NODE(-1) in acpi_map_pxm_to_node() because it regards numa_off as turning off the numa node. Hence dev_dax->target_node is NUMA_NO_NODE on arm64 with fake numa.

Without this patch, pmem can't be probed as a RAM device on arm64 if SRAT table isn't present:
$ndctl create-namespace -fe namespace0.0 --mode=devdax --map=dev -s 1g -a 64K kmem dax0.0: rejecting DAX region [mem 0x240400000-0x2bfffffff] with invalid node: -1
kmem: probe of dax0.0 failed with error -22

This fixes it by using fallback memory_add_physaddr_to_nid() as nid.

---
I noticed that on powerpc memory_add_physaddr_to_nid is not exported for module driver. Set it to RFC due to this concern.

 drivers/dax/kmem.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
drivers/dax/kmem.c +5 -4
index 275aa5f87399..68e693ca6d59 100644
@@ -28,20 +28,22 @@ int dev_dax_kmem_probe(struct device *dev)
 	resource_size_t kmem_end;
 	struct resource *new_res;
 	const char *new_res_name;
-	int numa_node;
+	int numa_node, new_node;
 	int rc;
 
 	/*
 	 * Ensure good NUMA information for the persistent memory.
-	 * Without this check, there is a risk that slow memory
-	 * could be mixed in a node with faster memory, causing
-	 * unavoidable performance issues.
+	 * Without this check, there is a risk but not fatal that slow
+	 * memory could be mixed in a node with faster memory, causing
+	 * unavoidable performance issues. Furthermore, fallback node
+	 * id can be used when numa_node is invalid.

drivers/dax/kmem.c int dev_dax_kmem_probe(struct device *dev) · line 46

Quoted 10 lines
drivers/dax/kmem.c +4 -3
 	 */
 	numa_node = dev_dax->target_node;
 	if (numa_node < 0) {
-		dev_warn(dev, "rejecting DAX region %pR with invalid node: %d\n",
-			 res, numa_node);
-		return -EINVAL;
+		new_node = memory_add_physaddr_to_nid(kmem_start);
+		dev_info(dev, "changing nid from %d to %d for DAX region %pR\n",
+			numa_node, new_node, res);
+		numa_node = new_node;

Now, the warning does not really make sense. We have NUMA_NO_NODE (< 0), that is not a change in the nid, but a selection of a nid. Printing NUMA_NO_NODE does not make too much sense. I suggest just getting rid of new_node and turning the dev_info() into something like

dev_info(dev, "using nid %d for DAX region with undefined nid %pR\n",

         numa_node, res);
Signature · 3 lines
Thanks,

David / dhildenb
author
#42 lore raw

RE: [RFC PATCH v2 2/3] device-dax: use fallback nid when numa_node is invalid

Hi David

Quoted 84 lines

-----Original Message-----
From: David Hildenbrand <[email protected]>
Sent: Tuesday, July 7, 2020 7:34 PM
To: Justin He <[email protected]>; Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Dan Williams <[email protected]>; Vishal Verma <[email protected]>; Dave Jiang <[email protected]>
Cc: Michal Hocko <[email protected]>; Andrew Morton <akpm@linux- foundation.org>; Mike Rapoport <[email protected]>; Baoquan He <[email protected]>; Chuhong Yuan <[email protected]>; linux-arm- [email protected]; [email protected]; linux- [email protected]; [email protected]; Kaly Xin <[email protected]>
Subject: Re: [RFC PATCH v2 2/3] device-dax: use fallback nid when numa_node is invalid

Quoted 1 line · Jia He

Previously, numa_off is set unconditionally at the end of

dummy_numa_init(),

Quoted 1 line

even with a fake numa node. Then ACPI detects node id as NUMA_NO_NODE(-1)

in

Quoted 1 line

acpi_map_pxm_to_node() because it regards numa_off as turning off the

numa

Quoted 3 lines

node. Hence dev_dax->target_node is NUMA_NO_NODE on arm64 with fake numa.

Without this patch, pmem can't be probed as a RAM device on arm64 if

SRAT table

Quoted 2 lines

isn't present:
$ndctl create-namespace -fe namespace0.0 --mode=devdax --map=dev -s 1g -

a 64K

Quoted 1 line

kmem dax0.0: rejecting DAX region [mem 0x240400000-0x2bfffffff] with

invalid node: -1

Quoted 8 lines

kmem: probe of dax0.0 failed with error -22

This fixes it by using fallback memory_add_physaddr_to_nid() as nid.

---
I noticed that on powerpc memory_add_physaddr_to_nid is not exported for

module

Quoted 20 lines

driver. Set it to RFC due to this concern.

 drivers/dax/kmem.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
drivers/dax/kmem.c +1 -2
index 275aa5f87399..68e693ca6d59 100644
@@ -28,20 +28,22 @@ int dev_dax_kmem_probe(struct device *dev)
 	resource_size_t kmem_end;
 	struct resource *new_res;
 	const char *new_res_name;
-	int numa_node;
+	int numa_node, new_node;
 	int rc;
 
 	/*
 	 * Ensure good NUMA information for the persistent memory.
-	 * Without this check, there is a risk that slow memory

drivers/dax/kmem.c int dev_dax_kmem_probe(struct device *dev) · line 42

Quoted 10 lines
drivers/dax/kmem.c +4 -3
-	 * could be mixed in a node with faster memory, causing
-	 * unavoidable performance issues.
+	 * Without this check, there is a risk but not fatal that slow
+	 * memory could be mixed in a node with faster memory, causing
+	 * unavoidable performance issues. Furthermore, fallback node
+	 * id can be used when numa_node is invalid.
 	 */
 	numa_node = dev_dax->target_node;
 	if (numa_node < 0) {
-		dev_warn(dev, "rejecting DAX region %pR with invalid

node: %d\n",

drivers/dax/kmem.c int dev_dax_kmem_probe(struct device *dev)

Quoted 4 lines
drivers/dax/kmem.c +2 -2
-			 res, numa_node);
-		return -EINVAL;
+		new_node = memory_add_physaddr_to_nid(kmem_start);
+		dev_info(dev, "changing nid from %d to %d for DAX

region %pR\n",

drivers/dax/kmem.c int dev_dax_kmem_probe(struct device *dev) · line 46

Quoted 2 lines
drivers/dax/kmem.c +2 -0
+			numa_node, new_node, res);
+		numa_node = new_node;

Now, the warning does not really make sense. We have NUMA_NO_NODE (< 0), that is not a change in the nid, but a selection of a nid. Printing NUMA_NO_NODE does not make too much sense. I suggest just getting rid of new_node and turning the dev_info() into something like

Quoted 3 lines

dev_info(dev, "using nid %d for DAX region with undefined nid %pR\n",

         numa_node, res);

Okay, I will update it as your sugguestion. Thanks

--
Cheers,
Justin (Jia He)

_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]

#43 lore raw

Re: [RFC PATCH v2 2/3] device-dax: use fallback nid when numa_node is invalid

In reply to Jia He
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use as documented in https://git-scm.com/docs/git-format-patch]

Hi Jia,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on soc/for-next kvmarm/next linus/master v5.8-rc4 next-20200707] [cannot apply to arm-perf/for-next/perf arm/for-next xlnx/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Jia-He/Fix-and-enable-pmem-as-RAM-device-on-arm64/20200707-140156
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
config: powerpc-rhel-kconfig (attached as .config)
compiler: powerpc64le-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/dax/kmem.ko] undefined!

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#44 lore raw

Re: [RFC PATCH v2 2/3] device-dax: use fallback nid when numa_node is invalid

In reply to Jia He
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use as documented in https://git-scm.com/docs/git-format-patch]

Hi Jia,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on arm64/for-next/core]
[also build test WARNING on soc/for-next kvmarm/next linus/master v5.8-rc4 next-20200707] [cannot apply to arm-perf/for-next/perf arm/for-next xlnx/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Jia-He/Fix-and-enable-pmem-as-RAM-device-on-arm64/20200707-140156
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
config: x86_64-allyesconfig (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 02946de3802d3bc65bc9f2eb9b8d4969b5a7add8)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

drivers/dax/kmem.c:22:5: warning: no previous prototype for function 'dev_dax_kmem_probe' [-Wmissing-prototypes] int dev_dax_kmem_probe(struct device *dev)

       ^
   drivers/dax/kmem.c:22:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int dev_dax_kmem_probe(struct device *dev)
   ^
   static 
>> drivers/dax/kmem.c:43:41: warning: variable 'kmem_start' is uninitialized when used here [-Wuninitialized]
                   new_node = memory_add_physaddr_to_nid(kmem_start);
                                                         ^~~~~~~~~~
   drivers/dax/kmem.c:26:28: note: initialize the variable 'kmem_start' to silence this warning
           resource_size_t kmem_start;
                                     ^
                                      = 0

2 warnings generated.

vim +/kmem_start +43 drivers/dax/kmem.c

    21	
    22	int dev_dax_kmem_probe(struct device *dev)
    23	{
    24		struct dev_dax *dev_dax = to_dev_dax(dev);
    25		struct resource *res = &dev_dax->region->res;
    26		resource_size_t kmem_start;
    27		resource_size_t kmem_size;
    28		resource_size_t kmem_end;
    29		struct resource *new_res;
    30		const char *new_res_name;
    31		int numa_node, new_node;
    32		int rc;
    33	
    34		/*
    35		 * Ensure good NUMA information for the persistent memory.
    36		 * Without this check, there is a risk but not fatal that slow
    37		 * memory could be mixed in a node with faster memory, causing
    38		 * unavoidable performance issues. Furthermore, fallback node
    39		 * id can be used when numa_node is invalid.
    40		 */
    41		numa_node = dev_dax->target_node;
    42		if (numa_node < 0) {
  > 43			new_node = memory_add_physaddr_to_nid(kmem_start);
    44			dev_info(dev, "changing nid from %d to %d for DAX region %pR\n",
    45				numa_node, new_node, res);
    46			numa_node = new_node;
    47		}
    48	
    49		/* Hotplug starting at the beginning of the next block: */
    50		kmem_start = ALIGN(res->start, memory_block_size_bytes());
    51	
    52		kmem_size = resource_size(res);
    53		/* Adjust the size down to compensate for moving up kmem_start: */
    54		kmem_size -= kmem_start - res->start;
    55		/* Align the size down to cover only complete blocks: */
    56		kmem_size &= ~(memory_block_size_bytes() - 1);
    57		kmem_end = kmem_start + kmem_size;
    58	
    59		new_res_name = kstrdup(dev_name(dev), GFP_KERNEL);
    60		if (!new_res_name)
    61			return -ENOMEM;
    62	
    63		/* Region is permanently reserved if hotremove fails. */
    64		new_res = request_mem_region(kmem_start, kmem_size, new_res_name);
    65		if (!new_res) {
    66			dev_warn(dev, "could not reserve region [%pa-%pa]\n",
    67				 &kmem_start, &kmem_end);
    68			kfree(new_res_name);
    69			return -EBUSY;
    70		}
    71	
    72		/*
    73		 * Set flags appropriate for System RAM.  Leave ..._BUSY clear
    74		 * so that add_memory() can add a child resource.  Do not
    75		 * inherit flags from the parent since it may set new flags
    76		 * unknown to us that will break add_memory() below.
    77		 */
    78		new_res->flags = IORESOURCE_SYSTEM_RAM;
    79	
    80		/*
    81		 * Ensure that future kexec'd kernels will not treat this as RAM
    82		 * automatically.
    83		 */
    84		rc = add_memory_driver_managed(numa_node, new_res->start,
    85					       resource_size(new_res), kmem_name);
    86		if (rc) {
    87			release_resource(new_res);
    88			kfree(new_res);
    89			kfree(new_res_name);
    90			return rc;
    91		}
    92		dev_dax->dax_kmem_res = new_res;
    93	
    94		return 0;
    95	}
    96	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author
#45 lore raw

PATCH v2 3/3 mm/memory_hotplug: fix unpaired mem_hotplug_begin/done

In reply to Jia He

When check_memblock_offlined_cb() returns failed rc(e.g. the memblock is online at that time), mem_hotplug_begin/done is unpaired in such case.

Therefore a warning:

 Call Trace:
  percpu_up_write+0x33/0x40
  try_remove_memory+0x66/0x120
  ? _cond_resched+0x19/0x30
  remove_memory+0x2b/0x40
  dev_dax_kmem_remove+0x36/0x72 [kmem]
  device_release_driver_internal+0xf0/0x1c0
  device_release_driver+0x12/0x20
  bus_remove_device+0xe1/0x150
  device_del+0x17b/0x3e0
  unregister_dev_dax+0x29/0x60
  devm_action_release+0x15/0x20
  release_nodes+0x19a/0x1e0
  devres_release_all+0x3f/0x50
  device_release_driver_internal+0x100/0x1c0
  driver_detach+0x4c/0x8f
  bus_remove_driver+0x5c/0xd0
  driver_unregister+0x31/0x50
  dax_pmem_exit+0x10/0xfe0 [dax_pmem]
Fixes f1037ec0cc8a ("mm/memory_hotplug: fix remove_memory() lockdep splat")
---
 mm/memory_hotplug.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/memory_hotplug.c +2 -3
index da374cd3d45b..76c75a599da3 100644
@@ -1742,7 +1742,7 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
 	 */
 	rc = walk_memory_blocks(start, size, NULL, check_memblock_offlined_cb);
 	if (rc)
-		goto done;
+		return rc;
 
 	/* remove memmap entry */
 	firmware_map_remove(start, start + size, "System RAM");
@@ -1766,9 +1766,8 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
 
 	try_offline_node(nid);
 
-done:
 	mem_hotplug_done();
-	return rc;
+	return 0;
 }
 
 /**
Signature · 1 line
2.17.1
Acked-by on v2 3/3
#46 lore raw

Re: [PATCH v2 3/3] mm/memory_hotplug: fix unpaired mem_hotplug_begin/done

Quoted 24 lines · Jia He

When check_memblock_offlined_cb() returns failed rc(e.g. the memblock is online at that time), mem_hotplug_begin/done is unpaired in such case.

Therefore a warning:

 Call Trace:
  percpu_up_write+0x33/0x40
  try_remove_memory+0x66/0x120
  ? _cond_resched+0x19/0x30
  remove_memory+0x2b/0x40
  dev_dax_kmem_remove+0x36/0x72 [kmem]
  device_release_driver_internal+0xf0/0x1c0
  device_release_driver+0x12/0x20
  bus_remove_device+0xe1/0x150
  device_del+0x17b/0x3e0
  unregister_dev_dax+0x29/0x60
  devm_action_release+0x15/0x20
  release_nodes+0x19a/0x1e0
  devres_release_all+0x3f/0x50
  device_release_driver_internal+0x100/0x1c0
  driver_detach+0x4c/0x8f
  bus_remove_driver+0x5c/0xd0
  driver_unregister+0x31/0x50
  dax_pmem_exit+0x10/0xfe0 [dax_pmem]
Quoted 3 lines
Fixes f1037ec0cc8a ("mm/memory_hotplug: fix remove_memory() lockdep splat")

Ups, I have missed that when reviewing that commit. Thanks for catching this up!

Quoted 30 lines
---
 mm/memory_hotplug.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/memory_hotplug.c +2 -3
index da374cd3d45b..76c75a599da3 100644
@@ -1742,7 +1742,7 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
 	 */
 	rc = walk_memory_blocks(start, size, NULL, check_memblock_offlined_cb);
 	if (rc)
-		goto done;
+		return rc;
 
 	/* remove memmap entry */
 	firmware_map_remove(start, start + size, "System RAM");
@@ -1766,9 +1766,8 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
 
 	try_offline_node(nid);
 
-done:
 	mem_hotplug_done();
-	return rc;
+	return 0;
 }
 
 /**
Signature · 1 line
2.17.1
Signature · 2 lines
Michal Hocko
SUSE Labs
Reviewed-by on v2 3/3
#47 lore raw

Re: [PATCH v2 3/3] mm/memory_hotplug: fix unpaired mem_hotplug_begin/done

In reply to Jia He
Quoted 46 lines · Jia He

When check_memblock_offlined_cb() returns failed rc(e.g. the memblock is online at that time), mem_hotplug_begin/done is unpaired in such case.

Therefore a warning:

 Call Trace:
  percpu_up_write+0x33/0x40
  try_remove_memory+0x66/0x120
  ? _cond_resched+0x19/0x30
  remove_memory+0x2b/0x40
  dev_dax_kmem_remove+0x36/0x72 [kmem]
  device_release_driver_internal+0xf0/0x1c0
  device_release_driver+0x12/0x20
  bus_remove_device+0xe1/0x150
  device_del+0x17b/0x3e0
  unregister_dev_dax+0x29/0x60
  devm_action_release+0x15/0x20
  release_nodes+0x19a/0x1e0
  devres_release_all+0x3f/0x50
  device_release_driver_internal+0x100/0x1c0
  driver_detach+0x4c/0x8f
  bus_remove_driver+0x5c/0xd0
  driver_unregister+0x31/0x50
  dax_pmem_exit+0x10/0xfe0 [dax_pmem]
Fixes f1037ec0cc8a ("mm/memory_hotplug: fix remove_memory() lockdep splat")
---
 mm/memory_hotplug.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/memory_hotplug.c +1 -1
index da374cd3d45b..76c75a599da3 100644
@@ -1742,7 +1742,7 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
 	 */
 	rc = walk_memory_blocks(start, size, NULL, check_memblock_offlined_cb);
 	if (rc)
-		goto done;
+		return rc;
 
 	/* remove memmap entry */
 	firmware_map_remove(start, start + size, "System RAM");

mm/memory_hotplug.c static int __ref try_remove_memory(int nid, u64 start, u64 size) · line 1773

Quoted 10 lines
mm/memory_hotplug.c +1 -2
@@ -1766,9 +1766,8 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
 
 	try_offline_node(nid);
 
-done:
 	mem_hotplug_done();
-	return rc;
+	return 0;
 }
 
 /**
Signature · 3 lines
Thanks,

David / dhildenb
maintainer
#48 lore raw

Re: [PATCH v2 3/3] mm/memory_hotplug: fix unpaired mem_hotplug_begin/done

In reply to Jia He

Hi

[This is an automated email]

This commit has been processed because it contains a "Fixes:" tag fixing commit: f1037ec0cc8a ("mm/memory_hotplug: fix remove_memory() lockdep splat").

The bot has tested the following trees: v5.7.7, v5.4.50, v4.19.131.

v5.7.7: Build OK!
v5.4.50: Build OK!
v4.19.131: Failed to apply! Possible dependencies:
eca499ab3749a ("mm/hotplug: make remove_memory() interface usable")

NOTE: The patch will not be queued to stable trees until it is upstream.

How should we proceed with this patch?

Signature · 2 lines
Thanks
Sasha