Skip to content

Commit c01044c

Browse files
djbwtorvalds
authored andcommitted
ACPI: HMAT: refactor hmat_register_target_device to hmem_register_device
In preparation for exposing "Soft Reserved" memory ranges without an HMAT, move the hmem device registration to its own compilation unit and make the implementation generic. The generic implementation drops usage acpi_map_pxm_to_online_node() that was translating ACPI proximity domain values and instead relies on numa_map_to_online_node() to determine the numa node for the device. [joao.m.martins@oracle.com: CONFIG_DEV_DAX_HMEM_DEVICES should depend on CONFIG_DAX=y] Link: https://lkml.kernel.org/r/8f34727f-ec2d-9395-cb18-969ec8a5d0d4@oracle.com Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Joao Martins <joao.m.martins@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Ben Skeggs <bskeggs@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Brice Goglin <Brice.Goglin@inria.fr> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Daniel Vetter <daniel@ffwll.ch> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Dave Jiang <dave.jiang@intel.com> Cc: David Airlie <airlied@linux.ie> Cc: David Hildenbrand <david@redhat.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Ira Weiny <ira.weiny@intel.com> Cc: Jason Gunthorpe <jgg@mellanox.com> Cc: Jeff Moyer <jmoyer@redhat.com> Cc: Jia He <justin.he@arm.com> Cc: Joao Martins <joao.m.martins@oracle.com> Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Mike Rapoport <rppt@linux.ibm.com> Cc: Paul Mackerras <paulus@ozlabs.org> Cc: Pavel Tatashin <pasha.tatashin@soleen.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tom Lendacky <thomas.lendacky@amd.com> Cc: Vishal Verma <vishal.l.verma@intel.com> Cc: Wei Yang <richard.weiyang@linux.alibaba.com> Cc: Will Deacon <will@kernel.org> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Ard Biesheuvel <ardb@kernel.org> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Hulk Robot <hulkci@huawei.com> Cc: Jason Yan <yanaijie@huawei.com> Cc: "Jérôme Glisse" <jglisse@redhat.com> Cc: Juergen Gross <jgross@suse.com> Cc: kernel test robot <lkp@intel.com> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: Stefano Stabellini <sstabellini@kernel.org> Cc: Vivek Goyal <vgoyal@redhat.com> Link: https://lkml.kernel.org/r/159643096584.4062302.5035370788475153738.stgit@dwillia2-desk3.amr.corp.intel.com Link: https://lore.kernel.org/r/158318761484.2216124.2049322072599482736.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 88e9a5b commit c01044c

7 files changed

Lines changed: 90 additions & 65 deletions

File tree

‎drivers/acpi/numa/hmat.c‎

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/mutex.h>
2525
#include <linux/node.h>
2626
#include <linux/sysfs.h>
27+
#include <linux/dax.h>
2728

2829
static u8 hmat_revision;
2930
static int hmat_disable __initdata;
@@ -640,66 +641,6 @@ static void hmat_register_target_perf(struct memory_target *target)
640641
node_set_perf_attrs(mem_nid, &target->hmem_attrs, 0);
641642
}
642643

643-
static void hmat_register_target_device(struct memory_target *target,
644-
struct resource *r)
645-
{
646-
/* define a clean / non-busy resource for the platform device */
647-
struct resource res = {
648-
.start = r->start,
649-
.end = r->end,
650-
.flags = IORESOURCE_MEM,
651-
};
652-
struct platform_device *pdev;
653-
struct memregion_info info;
654-
int rc, id;
655-
656-
rc = region_intersects(res.start, resource_size(&res), IORESOURCE_MEM,
657-
IORES_DESC_SOFT_RESERVED);
658-
if (rc != REGION_INTERSECTS)
659-
return;
660-
661-
id = memregion_alloc(GFP_KERNEL);
662-
if (id < 0) {
663-
pr_err("memregion allocation failure for %pr\n", &res);
664-
return;
665-
}
666-
667-
pdev = platform_device_alloc("hmem", id);
668-
if (!pdev) {
669-
pr_err("hmem device allocation failure for %pr\n", &res);
670-
goto out_pdev;
671-
}
672-
673-
pdev->dev.numa_node = acpi_map_pxm_to_online_node(target->memory_pxm);
674-
info = (struct memregion_info) {
675-
.target_node = acpi_map_pxm_to_node(target->memory_pxm),
676-
};
677-
rc = platform_device_add_data(pdev, &info, sizeof(info));
678-
if (rc < 0) {
679-
pr_err("hmem memregion_info allocation failure for %pr\n", &res);
680-
goto out_pdev;
681-
}
682-
683-
rc = platform_device_add_resources(pdev, &res, 1);
684-
if (rc < 0) {
685-
pr_err("hmem resource allocation failure for %pr\n", &res);
686-
goto out_resource;
687-
}
688-
689-
rc = platform_device_add(pdev);
690-
if (rc < 0) {
691-
dev_err(&pdev->dev, "device add failed for %pr\n", &res);
692-
goto out_resource;
693-
}
694-
695-
return;
696-
697-
out_resource:
698-
put_device(&pdev->dev);
699-
out_pdev:
700-
memregion_free(id);
701-
}
702-
703644
static void hmat_register_target_devices(struct memory_target *target)
704645
{
705646
struct resource *res;
@@ -711,8 +652,11 @@ static void hmat_register_target_devices(struct memory_target *target)
711652
if (!IS_ENABLED(CONFIG_DEV_DAX_HMEM))
712653
return;
713654

714-
for (res = target->memregions.child; res; res = res->sibling)
715-
hmat_register_target_device(target, res);
655+
for (res = target->memregions.child; res; res = res->sibling) {
656+
int target_nid = acpi_map_pxm_to_node(target->memory_pxm);
657+
658+
hmem_register_device(target_nid, res);
659+
}
716660
}
717661

718662
static void hmat_register_target(struct memory_target *target)

‎drivers/dax/Kconfig‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ config DEV_DAX_HMEM
4848

4949
Say M if unsure.
5050

51+
config DEV_DAX_HMEM_DEVICES
52+
depends on DEV_DAX_HMEM && DAX=y
53+
def_bool y
54+
5155
config DEV_DAX_KMEM
5256
tristate "KMEM DAX: volatile-use of persistent memory"
5357
default DEV_DAX

‎drivers/dax/Makefile‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
obj-$(CONFIG_DAX) += dax.o
33
obj-$(CONFIG_DEV_DAX) += device_dax.o
44
obj-$(CONFIG_DEV_DAX_KMEM) += kmem.o
5-
obj-$(CONFIG_DEV_DAX_HMEM) += dax_hmem.o
65

76
dax-y := super.o
87
dax-y += bus.o
98
device_dax-y := device.o
10-
dax_hmem-y := hmem.o
119

1210
obj-y += pmem/
11+
obj-y += hmem/

‎drivers/dax/hmem/Makefile‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
obj-$(CONFIG_DEV_DAX_HMEM) += dax_hmem.o
3+
obj-$(CONFIG_DEV_DAX_HMEM_DEVICES) += device.o
4+
5+
dax_hmem-y := hmem.o

‎drivers/dax/hmem/device.c‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <linux/platform_device.h>
3+
#include <linux/memregion.h>
4+
#include <linux/module.h>
5+
#include <linux/dax.h>
6+
#include <linux/mm.h>
7+
8+
void hmem_register_device(int target_nid, struct resource *r)
9+
{
10+
/* define a clean / non-busy resource for the platform device */
11+
struct resource res = {
12+
.start = r->start,
13+
.end = r->end,
14+
.flags = IORESOURCE_MEM,
15+
};
16+
struct platform_device *pdev;
17+
struct memregion_info info;
18+
int rc, id;
19+
20+
rc = region_intersects(res.start, resource_size(&res), IORESOURCE_MEM,
21+
IORES_DESC_SOFT_RESERVED);
22+
if (rc != REGION_INTERSECTS)
23+
return;
24+
25+
id = memregion_alloc(GFP_KERNEL);
26+
if (id < 0) {
27+
pr_err("memregion allocation failure for %pr\n", &res);
28+
return;
29+
}
30+
31+
pdev = platform_device_alloc("hmem", id);
32+
if (!pdev) {
33+
pr_err("hmem device allocation failure for %pr\n", &res);
34+
goto out_pdev;
35+
}
36+
37+
pdev->dev.numa_node = numa_map_to_online_node(target_nid);
38+
info = (struct memregion_info) {
39+
.target_node = target_nid,
40+
};
41+
rc = platform_device_add_data(pdev, &info, sizeof(info));
42+
if (rc < 0) {
43+
pr_err("hmem memregion_info allocation failure for %pr\n", &res);
44+
goto out_pdev;
45+
}
46+
47+
rc = platform_device_add_resources(pdev, &res, 1);
48+
if (rc < 0) {
49+
pr_err("hmem resource allocation failure for %pr\n", &res);
50+
goto out_resource;
51+
}
52+
53+
rc = platform_device_add(pdev);
54+
if (rc < 0) {
55+
dev_err(&pdev->dev, "device add failed for %pr\n", &res);
56+
goto out_resource;
57+
}
58+
59+
return;
60+
61+
out_resource:
62+
put_device(&pdev->dev);
63+
out_pdev:
64+
memregion_free(id);
65+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <linux/memregion.h>
44
#include <linux/module.h>
55
#include <linux/pfn_t.h>
6-
#include "bus.h"
6+
#include "../bus.h"
77

88
static int dax_hmem_probe(struct platform_device *pdev)
99
{

‎include/linux/dax.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,12 @@ static inline bool dax_mapping(struct address_space *mapping)
238238
return mapping->host && IS_DAX(mapping->host);
239239
}
240240

241+
#ifdef CONFIG_DEV_DAX_HMEM_DEVICES
242+
void hmem_register_device(int target_nid, struct resource *r);
243+
#else
244+
static inline void hmem_register_device(int target_nid, struct resource *r)
245+
{
246+
}
247+
#endif
248+
241249
#endif

0 commit comments

Comments
 (0)