Skip to contentSkip to conversation

mm/hugetlb: Guard dequeue_hugetlb_folio_nodemask against NUMA_NO_NODE uses

PATCH Applied Oscar Salvador 3 participants 3 messages Jun 12, 2024

Subsystems (2)
lore
Share & tools
lore

Oscar Salvador

author maintainer
#0 lore raw

PATCH 1/1 mm/hugetlb: Guard dequeue_hugetlb_folio_nodemask against NUMA_NO_NODE uses

dequeue_hugetlb_folio_nodemask() expects a preferred node where to get the hugetlb page from.
It does not expect, though, users to pass NUMA_NO_NODE, otherwise we will get trash when trying to get the zonelist from that node.
All current users are careful enough to not pass NUMA_NO_NODE, but it opens the door for new users to get this wrong since it is not documented [0].
Guard against this by getting the local nid if NUMA_NO_NODE was passed.

[0] https://lore.kernel.org/linux-mm/[email protected]/

---
 mm/hugetlb.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/hugetlb.c +4 -0
index 3518321f6598..6a5ea898e4da 100644
@@ -1355,6 +1355,10 @@ static struct folio *dequeue_hugetlb_folio_nodemask(struct hstate *h, gfp_t gfp_
 	struct zoneref *z;
 	int node = NUMA_NO_NODE;
 
+	/* 'nid' should not be NUMA_NO_NODE. Try to catch any misuse of it and rectifiy. */
+	if (nid == NUMA_NO_NODE)
+		nid = numa_node_id();
+
 	zonelist = node_zonelist(nid, gfp_mask);
 
 retry_cpuset:
Signature · 1 line
2.45.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Oscar Salvador

dequeue_hugetlb_folio_nodemask() expects a preferred node where to get the hugetlb page from.
It does not expect, though, users to pass NUMA_NO_NODE, otherwise we will get trash when trying to get the zonelist from that node.
All current users are careful enough to not pass NUMA_NO_NODE, but it opens the door for new users to get this wrong since it is not documented [0].
Guard against this by getting the local nid if NUMA_NO_NODE was passed.

Quoted 5 lines

[0] https://lore.kernel.org/linux-mm/[email protected]/

Thanks.

Acked-by on v1 1/1
#2 lore raw
In reply to Oscar Salvador
Quoted 34 lines

dequeue_hugetlb_folio_nodemask() expects a preferred node where to get the
hugetlb page from.
It does not expect, though, users to pass NUMA_NO_NODE, otherwise we will
get trash when trying to get the zonelist from that node. All current users are careful enough to not pass NUMA_NO_NODE, but it opens the door for new users to get this wrong since it is not documented [0].
Guard against this by getting the local nid if NUMA_NO_NODE was passed.

[0] https://lore.kernel.org/linux-
mm/[email protected]/

mm/[email protected]/ Reported-and-tested-by:
[email protected]

---
 mm/hugetlb.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/hugetlb.c +1 -0
index 3518321f6598..6a5ea898e4da 100644
@@ -1355,6 +1355,10 @@ static struct folio
 *dequeue_hugetlb_folio_nodemask(struct hstate *h, gfp_t gfp_
 	struct zoneref *z;
 	int node = NUMA_NO_NODE;
 
+	/* 'nid' should not be NUMA_NO_NODE. Try to catch any misuse of it

and rectifiy. */

mm/hugetlb.c static struct folio *dequeue_hugetlb_folio_nodemask(struct hstate *h, gfp_t gfp_ · line 1362

Quoted 4 lines
mm/hugetlb.c +3 -0
+	if (nid == NUMA_NO_NODE)
+		nid = numa_node_id();
+
 	zonelist = node_zonelist(nid, gfp_mask);
Quoted 4 lines

retry_cpuset:
--
2.45.2