Skip to content

Commit 472faf7

Browse files
committed
device-dax: Fix duplicate 'hmem' device registration
So called "soft-reserved" memory is an EFI conventional memory range with the EFI_MEMORY_SP attribute set. That attribute indicates that the memory is not part of the platform general purpose memory pool and may want some consideration from the system administrator about whether to keep that memory set aside for dedicated access through device-dax (map a device file), or assigned to the page allocator as another general purpose memory node target. Absent an ACPI HMAT table the default device-dax registration creates coarse grained devices that are delineated by EFI Memory Map entries. With the HMAT the devices are delineated by the finer grained ranges associated with the proximity domain of the memory target. I.e. the HMAT describes the properties of performance differentiated memory and each unique performance description results in a unique target proximity domain where each memory proximity domain has an associated SRAT entry that delineates the address range. The intent was that SRAT-defined device-dax instances are registered first. Then any left-over address range with the EFI_MEMORY_SP attribute, but not covered by the SRAT, would have a coarse grained device-dax instance established. However, the scheme to detect what ranges are left to be assigned to a device was buggy and resulted in multiple overlapping device-dax instances. Fix this by using explicit tracking for which ranges have been handled. Now, this new approach may leave memory stranded in the presence of broken platform firmware that fails to fully describe all EFI_MEMORY_SP ranges in the HMAT. That requires a deeper fix if it becomes a problem in practice. Reported-by: "Tallam Mahendra Kumar" <[email protected]> Reported-by: Mustafa Hajeer <[email protected]> Debugged-by: Vishal Verma <[email protected]> Tested-by: Vishal Verma <[email protected]> Link: https://lore.kernel.org/r/166890823379.4183293.15333502171004313377.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent 48d4180 commit 472faf7

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

drivers/dax/hmem/device.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
static bool nohmem;
99
module_param_named(disable, nohmem, bool, 0444);
1010

11+
static struct resource hmem_active = {
12+
.name = "HMEM devices",
13+
.start = 0,
14+
.end = -1,
15+
.flags = IORESOURCE_MEM,
16+
};
17+
1118
void hmem_register_device(int target_nid, struct resource *r)
1219
{
1320
/* define a clean / non-busy resource for the platform device */
@@ -41,6 +48,12 @@ void hmem_register_device(int target_nid, struct resource *r)
4148
goto out_pdev;
4249
}
4350

51+
if (!__request_region(&hmem_active, res.start, resource_size(&res),
52+
dev_name(&pdev->dev), 0)) {
53+
dev_dbg(&pdev->dev, "hmem range %pr already active\n", &res);
54+
goto out_active;
55+
}
56+
4457
pdev->dev.numa_node = numa_map_to_online_node(target_nid);
4558
info = (struct memregion_info) {
4659
.target_node = target_nid,
@@ -66,22 +79,15 @@ void hmem_register_device(int target_nid, struct resource *r)
6679
return;
6780

6881
out_resource:
82+
__release_region(&hmem_active, res.start, resource_size(&res));
83+
out_active:
6984
platform_device_put(pdev);
7085
out_pdev:
7186
memregion_free(id);
7287
}
7388

7489
static __init int hmem_register_one(struct resource *res, void *data)
7590
{
76-
/*
77-
* If the resource is not a top-level resource it was already
78-
* assigned to a device by the HMAT parsing.
79-
*/
80-
if (res->parent != &iomem_resource) {
81-
pr_info("HMEM: skip %pr, already claimed\n", res);
82-
return 0;
83-
}
84-
8591
hmem_register_device(phys_to_target_node(res->start), res);
8692

8793
return 0;

0 commit comments

Comments
 (0)