linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/hugetlb: Guard dequeue_hugetlb_folio_nodemask against NUMA_NO_NODE uses
@ 2024-06-12  8:29 Oscar Salvador
  2024-06-12  8:53 ` Muchun Song
  2024-06-12 17:25 ` Kasireddy, Vivek
  0 siblings, 2 replies; 3+ messages in thread
From: Oscar Salvador @ 2024-06-12  8:29 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, linux-mm, Muchun Song, Vivek Kasireddy,
	Oscar Salvador, syzbot+569ed13f4054f271087b

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/0000000000004f12bb061a9acf07@google.com/

Closes: https://lore.kernel.org/linux-mm/0000000000004f12bb061a9acf07@google.com/
Reported-and-tested-by: syzbot+569ed13f4054f271087b@syzkaller.appspotmail.com
Signed-off-by: Oscar Salvador <osalvador@suse.de>
---
 mm/hugetlb.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 3518321f6598..6a5ea898e4da 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -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:
-- 
2.45.2



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/hugetlb: Guard dequeue_hugetlb_folio_nodemask against NUMA_NO_NODE uses
  2024-06-12  8:29 [PATCH] mm/hugetlb: Guard dequeue_hugetlb_folio_nodemask against NUMA_NO_NODE uses Oscar Salvador
@ 2024-06-12  8:53 ` Muchun Song
  2024-06-12 17:25 ` Kasireddy, Vivek
  1 sibling, 0 replies; 3+ messages in thread
From: Muchun Song @ 2024-06-12  8:53 UTC (permalink / raw)
  To: Oscar Salvador
  Cc: Andrew Morton, LKML, Linux-MM, Vivek Kasireddy,
	syzbot+569ed13f4054f271087b



> On Jun 12, 2024, at 16:29, Oscar Salvador <osalvador@suse.de> wrote:
> 
> 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/0000000000004f12bb061a9acf07@google.com/
> 
> Closes: https://lore.kernel.org/linux-mm/0000000000004f12bb061a9acf07@google.com/
> Reported-and-tested-by: syzbot+569ed13f4054f271087b@syzkaller.appspotmail.com
> Signed-off-by: Oscar Salvador <osalvador@suse.de>

Reviewed-by: Muchun Song <muchun.song@linux.dev>

Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH] mm/hugetlb: Guard dequeue_hugetlb_folio_nodemask against NUMA_NO_NODE uses
  2024-06-12  8:29 [PATCH] mm/hugetlb: Guard dequeue_hugetlb_folio_nodemask against NUMA_NO_NODE uses Oscar Salvador
  2024-06-12  8:53 ` Muchun Song
@ 2024-06-12 17:25 ` Kasireddy, Vivek
  1 sibling, 0 replies; 3+ messages in thread
From: Kasireddy, Vivek @ 2024-06-12 17:25 UTC (permalink / raw)
  To: Oscar Salvador, Andrew Morton
  Cc: linux-kernel, linux-mm, Muchun Song, syzbot+569ed13f4054f271087b

> 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/0000000000004f12bb061a9acf07@google.com/
> 
> Closes: https://lore.kernel.org/linux-
> mm/0000000000004f12bb061a9acf07@google.com/
> Reported-and-tested-by:
> syzbot+569ed13f4054f271087b@syzkaller.appspotmail.com
> Signed-off-by: Oscar Salvador <osalvador@suse.de>
> ---
>  mm/hugetlb.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 3518321f6598..6a5ea898e4da 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -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);
Acked-by: Vivek Kasireddy <vivek.kasireddy@intel.com>

> 
>  retry_cpuset:
> --
> 2.45.2



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-12 17:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-12  8:29 [PATCH] mm/hugetlb: Guard dequeue_hugetlb_folio_nodemask against NUMA_NO_NODE uses Oscar Salvador
2024-06-12  8:53 ` Muchun Song
2024-06-12 17:25 ` Kasireddy, Vivek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox