Skip to contentSkip to conversation

dax/kmem: Pass valid argument to memory_group_register_static

PATCH Superseded Tarun Sahu 3 participants 5 messages Jun 20, 2023 – Jun 22, 2023

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Tarun Sahu

author
#0 lore raw

PATCH 1/1 dax/kmem: Pass valid argument to memory_group_register_static

memory_group_register_static takes maximum number of pages as the argument while dev_dax_kmem_probe passes total_len (in bytes) as the argument.

---
 drivers/dax/kmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dax/kmem.c +1 -1
index 7b36db6f1cbd..898ca9505754 100644
@@ -99,7 +99,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax)
 	if (!data->res_name)
 		goto err_res_name;
 
-	rc = memory_group_register_static(numa_node, total_len);
+	rc = memory_group_register_static(numa_node, PFN_UP(total_len));
 	if (rc < 0)
 		goto err_reg_mgid;
 	data->mgid = rc;
Signature · 1 line
2.31.1
maintainer
#1 lore raw
Quoted 2 lines · Tarun Sahu

memory_group_register_static takes maximum number of pages as the argument while dev_dax_kmem_probe passes total_len (in bytes) as the argument.

This sounds like a fix. An explanation of the impact and a fixes tag may be needed. Also, wondering how you found it.

Alison

Quoted 22 lines
---
 drivers/dax/kmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dax/kmem.c +1 -1
index 7b36db6f1cbd..898ca9505754 100644
@@ -99,7 +99,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax)
 	if (!data->res_name)
 		goto err_res_name;
 
-	rc = memory_group_register_static(numa_node, total_len);
+	rc = memory_group_register_static(numa_node, PFN_UP(total_len));
 	if (rc < 0)
 		goto err_reg_mgid;
 	data->mgid = rc;
Signature · 1 line
2.31.1
author
#2 lore raw

Hi Alison,

Quoted 7 lines · Alison Schofield
Quoted 2 lines · Tarun Sahu

memory_group_register_static takes maximum number of pages as the argument while dev_dax_kmem_probe passes total_len (in bytes) as the argument.

This sounds like a fix. An explanation of the impact and a fixes tag may be needed. Also, wondering how you found it.

Yes, it is a fix, I found it during dry code walk-through. There is not any impact as such. As, memory_group_register_static just set the max_pages limit which is used in auto_movable_zone_for_pfn to determine the zone.

which might cause these condition to behave differently,

This will be true always so jump will happen to kernel_zone

	if (!auto_movable_can_online_movable(NUMA_NO_NODE, group, nr_pages))
		goto kernel_zone;
---
kernel_zone:
	return default_kernel_zone_for_pfn(nid, pfn, nr_pages);

---

Here, In below, zone_intersects compare range will be larger as nr_pages will be higher (derived from total_len passed in dev_dax_kmem_probe).

static struct zone *default_kernel_zone_for_pfn(int nid, unsigned long start_pfn,
unsigned long nr_pages)

{
	struct pglist_data *pgdat = NODE_DATA(nid);
	int zid;

	for (zid = 0; zid < ZONE_NORMAL; zid++) {
		struct zone *zone = &pgdat->node_zones[zid];

		if (zone_intersects(zone, start_pfn, nr_pages))
			return zone;
	}

	return &pgdat->node_zones[ZONE_NORMAL];
}

In Mostly cases, ZONE_NORMAL will be returned. But there is no crash/panic issues involved here, only decision making on selecting zone is affected.

Quoted 24 lines

Alison

Quoted 22 lines
---
 drivers/dax/kmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dax/kmem.c +1 -1
index 7b36db6f1cbd..898ca9505754 100644
@@ -99,7 +99,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax)
 	if (!data->res_name)
 		goto err_res_name;
 
-	rc = memory_group_register_static(numa_node, total_len);
+	rc = memory_group_register_static(numa_node, PFN_UP(total_len));
 	if (rc < 0)
 		goto err_reg_mgid;
 	data->mgid = rc;
Signature · 1 line
2.31.1
maintainer Reviewed-by
#3 lore raw
Quoted 43 lines · Tarun Sahu

Hi Alison,

Quoted 7 lines · Alison Schofield
Quoted 2 lines · Tarun Sahu

memory_group_register_static takes maximum number of pages as the argument while dev_dax_kmem_probe passes total_len (in bytes) as the argument.

This sounds like a fix. An explanation of the impact and a fixes tag may be needed. Also, wondering how you found it.

Yes, it is a fix, I found it during dry code walk-through. There is not any impact as such. As, memory_group_register_static just set the max_pages limit which is used in auto_movable_zone_for_pfn to determine the zone.

which might cause these condition to behave differently,

This will be true always so jump will happen to kernel_zone
        if (!auto_movable_can_online_movable(NUMA_NO_NODE, group, nr_pages)) goto kernel_zone;
---
kernel_zone:
        return default_kernel_zone_for_pfn(nid, pfn, nr_pages);

---

Here, In below, zone_intersects compare range will be larger as nr_pages will be higher (derived from total_len passed in dev_dax_kmem_probe).

static struct zone *default_kernel_zone_for_pfn(int nid, unsigned long start_pfn, unsigned long nr_pages)
{
        struct pglist_data *pgdat = NODE_DATA(nid);
        int zid;

        for (zid = 0; zid < ZONE_NORMAL; zid++) { struct zone *zone = &pgdat->node_zones[zid];

                if (zone_intersects(zone, start_pfn, nr_pages)) return zone;
        }

Quoted 7 lines

        return &pgdat->node_zones[ZONE_NORMAL];
}

In Mostly cases, ZONE_NORMAL will be returned. But there is no crash/panic issues involved here, only decision making on selecting zone is affected.

Hi Tarun,

Good find! With a Fixes tag, and perhaps inclusion of a bit more of this detail described in the commit message, feel free to add:

author
#4 lore raw

Hi Vishal,

Quoted 52 lines · Vishal L
Quoted 43 lines · Tarun Sahu

Hi Alison,

Quoted 7 lines · Alison Schofield
Quoted 2 lines · Tarun Sahu

memory_group_register_static takes maximum number of pages as the argument while dev_dax_kmem_probe passes total_len (in bytes) as the argument.

This sounds like a fix. An explanation of the impact and a fixes tag may be needed. Also, wondering how you found it.

Yes, it is a fix, I found it during dry code walk-through. There is not any impact as such. As, memory_group_register_static just set the max_pages limit which is used in auto_movable_zone_for_pfn to determine the zone.

which might cause these condition to behave differently,

This will be true always so jump will happen to kernel_zone
        if (!auto_movable_can_online_movable(NUMA_NO_NODE, group, nr_pages)) goto kernel_zone;
---
kernel_zone:
        return default_kernel_zone_for_pfn(nid, pfn, nr_pages);

---

Here, In below, zone_intersects compare range will be larger as nr_pages will be higher (derived from total_len passed in dev_dax_kmem_probe).

static struct zone *default_kernel_zone_for_pfn(int nid, unsigned long start_pfn, unsigned long nr_pages)
{
        struct pglist_data *pgdat = NODE_DATA(nid);
        int zid;

        for (zid = 0; zid < ZONE_NORMAL; zid++) { struct zone *zone = &pgdat->node_zones[zid];

                if (zone_intersects(zone, start_pfn, nr_pages)) return zone;
        }

Quoted 7 lines

        return &pgdat->node_zones[ZONE_NORMAL];
}

In Mostly cases, ZONE_NORMAL will be returned. But there is no crash/panic issues involved here, only decision making on selecting zone is affected.

Quoted 5 lines

Hi Tarun,

Good find! With a Fixes tag, and perhaps inclusion of a bit more of this detail described in the commit message, feel free to add:

Thanks for reviewing, sent the updated version.

Quoted 1 line