Fix three probe and NUMA lookup issues in ramdax: - Select NUMA_KEEP_MEMINFO if NUMA_MEMBLKS in Kconfig so phys_to_target_node() resolves the target NUMA node instead of falling back to the stub in mm/numa.c that assumes node 0 (matching DEV_DAX_HMEM and CXL_BUS). - Reject resources with size <= LABEL_AREA_SIZE (128 KiB) before subtracting LABEL_AREA_SIZE, and skip non-IORESOURCE_MEM platform resources. - Reject driver_override binds from non-OF platform devices other than "e820_pmem" with -ENODEV instead of registering a bus and walking legacy e820 PMEM ranges. Fixes: 43bc0aa19a21 ("nvdimm: allow exposing RAM carveouts as NVDIMM DIMM devices") Signed-off-by: Suseendran Bhaskaran --- drivers/nvdimm/Kconfig | 1 + drivers/nvdimm/ramdax.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/Kconfig b/drivers/nvdimm/Kconfig index 44ab929a1ad5..33d83623bfc0 100644 --- a/drivers/nvdimm/Kconfig +++ b/drivers/nvdimm/Kconfig @@ -100,6 +100,7 @@ config OF_PMEM config RAMDAX tristate "Support persistent memory interfaces on RAM carveouts" depends on X86_PMEM_LEGACY || OF || COMPILE_TEST + select NUMA_KEEP_MEMINFO if NUMA_MEMBLKS default LIBNVDIMM help Allows creation of DAX devices on RAM carveouts. diff --git a/drivers/nvdimm/ramdax.c b/drivers/nvdimm/ramdax.c index cca470d071eb..4efffc3ee5a0 100644 --- a/drivers/nvdimm/ramdax.c +++ b/drivers/nvdimm/ramdax.c @@ -9,7 +9,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -76,6 +78,9 @@ static int ramdax_register_dimm(struct resource *res, void *data) unsigned long flags = 0, cmd_mask = 0; struct ramdax_dimm *dimm; + if (size <= LABEL_AREA_SIZE) + return -EINVAL; + dimm = devm_kzalloc_obj(dev, *dimm); if (!dimm) return -ENOMEM; @@ -198,8 +203,12 @@ static int ramdax_probe(struct platform_device *pdev) struct nvdimm_bus *nvdimm_bus; int rc = -ENODEV; - if (np && !of_match_node(ramdax_of_matches, np)) + if (np) { + if (!of_match_node(ramdax_of_matches, np)) + return -ENODEV; + } else if (strcmp(pdev->name, "e820_pmem") != 0) { return -ENODEV; + } nd_desc = devm_kzalloc_obj(dev, *nd_desc); if (!nd_desc) @@ -217,6 +226,8 @@ static int ramdax_probe(struct platform_device *pdev) if (np) { for (unsigned int i = 0; i < pdev->num_resources; i++) { + if (resource_type(&pdev->resource[i]) != IORESOURCE_MEM) + continue; rc = ramdax_register_dimm(&pdev->resource[i], dev); if (rc) break;