* [PATCH] mm/damon/ops-common: ignore migration request to invalid nodes
@ 2025-07-20 18:58 SeongJae Park
2025-07-21 15:28 ` Joshua Hahn
2025-07-22 2:56 ` Andrew Morton
0 siblings, 2 replies; 5+ messages in thread
From: SeongJae Park @ 2025-07-20 18:58 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Honggyu Kim, Hyeongtak Ji, damon, linux-kernel,
linux-mm, stable
damon_migrate_pages() try migration even if the target node is invalid.
If users mistakenly make such invalid requests via
DAMOS_MIGRATE_{HOT,COLD} action, below kernel BUG can happen.
[ 7831.883495] BUG: unable to handle page fault for address: 0000000000001f48
[ 7831.884160] #PF: supervisor read access in kernel mode
[ 7831.884681] #PF: error_code(0x0000) - not-present page
[ 7831.885203] PGD 0 P4D 0
[ 7831.885468] Oops: Oops: 0000 [#1] SMP PTI
[ 7831.885852] CPU: 31 UID: 0 PID: 94202 Comm: kdamond.0 Not tainted 6.16.0-rc5-mm-new-damon+ #93 PREEMPT(voluntary)
[ 7831.886913] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-4.el9 04/01/2014
[ 7831.887777] RIP: 0010:__alloc_frozen_pages_noprof (include/linux/mmzone.h:1724 include/linux/mmzone.h:1750 mm/page_alloc.c:4936 mm/page_alloc.c:5137)
[...]
[ 7831.895953] Call Trace:
[ 7831.896195] <TASK>
[ 7831.896397] __folio_alloc_noprof (mm/page_alloc.c:5183 mm/page_alloc.c:5192)
[ 7831.896787] migrate_pages_batch (mm/migrate.c:1189 mm/migrate.c:1851)
[ 7831.897228] ? __pfx_alloc_migration_target (mm/migrate.c:2137)
[ 7831.897735] migrate_pages (mm/migrate.c:2078)
[ 7831.898141] ? __pfx_alloc_migration_target (mm/migrate.c:2137)
[ 7831.898664] damon_migrate_folio_list (mm/damon/ops-common.c:321 mm/damon/ops-common.c:354)
[ 7831.899140] damon_migrate_pages (mm/damon/ops-common.c:405)
[...]
Add a target node validity check in damon_migrate_pages(). The validity
check is stolen from that of do_pages_move(), which is being used for
move_pages() system call.
Fixes: b51820ebea65 ("mm/damon/paddr: introduce DAMOS_MIGRATE_COLD action for demotion") # 6.11.x
Cc: stable@vger.kernel.org
Cc: Honggyu Kim <honggyu.kim@sk.com>
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/ops-common.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c
index 6a9797d1d7ff..99321ff5cb92 100644
--- a/mm/damon/ops-common.c
+++ b/mm/damon/ops-common.c
@@ -383,6 +383,10 @@ unsigned long damon_migrate_pages(struct list_head *folio_list, int target_nid)
if (list_empty(folio_list))
return nr_migrated;
+ if (target_nid < 0 || target_nid >= MAX_NUMNODES ||
+ !node_state(target_nid, N_MEMORY))
+ return nr_migrated;
+
noreclaim_flag = memalloc_noreclaim_save();
nid = folio_nid(lru_to_folio(folio_list));
base-commit: e2c90d41402c324ea81fa3d9c2c1d0f61906c161
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/damon/ops-common: ignore migration request to invalid nodes
2025-07-20 18:58 [PATCH] mm/damon/ops-common: ignore migration request to invalid nodes SeongJae Park
@ 2025-07-21 15:28 ` Joshua Hahn
2025-07-21 16:30 ` SeongJae Park
2025-07-22 2:56 ` Andrew Morton
1 sibling, 1 reply; 5+ messages in thread
From: Joshua Hahn @ 2025-07-21 15:28 UTC (permalink / raw)
To: SeongJae Park
Cc: Andrew Morton, Honggyu Kim, Hyeongtak Ji, damon, linux-kernel,
linux-mm, stable
On Sun, 20 Jul 2025 11:58:22 -0700 SeongJae Park <sj@kernel.org> wrote:
> damon_migrate_pages() try migration even if the target node is invalid.
> If users mistakenly make such invalid requests via
> DAMOS_MIGRATE_{HOT,COLD} action, below kernel BUG can happen.
>
> [ 7831.883495] BUG: unable to handle page fault for address: 0000000000001f48
> [ 7831.884160] #PF: supervisor read access in kernel mode
> [ 7831.884681] #PF: error_code(0x0000) - not-present page
> [ 7831.885203] PGD 0 P4D 0
> [ 7831.885468] Oops: Oops: 0000 [#1] SMP PTI
> [ 7831.885852] CPU: 31 UID: 0 PID: 94202 Comm: kdamond.0 Not tainted 6.16.0-rc5-mm-new-damon+ #93 PREEMPT(voluntary)
> [ 7831.886913] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-4.el9 04/01/2014
> [ 7831.887777] RIP: 0010:__alloc_frozen_pages_noprof (include/linux/mmzone.h:1724 include/linux/mmzone.h:1750 mm/page_alloc.c:4936 mm/page_alloc.c:5137)
> [...]
> [ 7831.895953] Call Trace:
> [ 7831.896195] <TASK>
> [ 7831.896397] __folio_alloc_noprof (mm/page_alloc.c:5183 mm/page_alloc.c:5192)
> [ 7831.896787] migrate_pages_batch (mm/migrate.c:1189 mm/migrate.c:1851)
> [ 7831.897228] ? __pfx_alloc_migration_target (mm/migrate.c:2137)
> [ 7831.897735] migrate_pages (mm/migrate.c:2078)
> [ 7831.898141] ? __pfx_alloc_migration_target (mm/migrate.c:2137)
> [ 7831.898664] damon_migrate_folio_list (mm/damon/ops-common.c:321 mm/damon/ops-common.c:354)
> [ 7831.899140] damon_migrate_pages (mm/damon/ops-common.c:405)
> [...]
>
> Add a target node validity check in damon_migrate_pages(). The validity
> check is stolen from that of do_pages_move(), which is being used for
> move_pages() system call.
>
> Fixes: b51820ebea65 ("mm/damon/paddr: introduce DAMOS_MIGRATE_COLD action for demotion") # 6.11.x
> Cc: stable@vger.kernel.org
> Cc: Honggyu Kim <honggyu.kim@sk.com>
> Signed-off-by: SeongJae Park <sj@kernel.org>
> ---
LGTM, thank you SJ!
On a side note... This seems like it would be a common check. However, doing a
(quick) search seems to return no function that checks whether a node is valid.
Perhaps it would make sense to look deeper and see how many other functions
make this check, and export this as a function? I can try spinning something
if it makes sense to you : -)
Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
Sent using hkml (https://github.com/sjp38/hackermail)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/damon/ops-common: ignore migration request to invalid nodes
2025-07-21 15:28 ` Joshua Hahn
@ 2025-07-21 16:30 ` SeongJae Park
0 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2025-07-21 16:30 UTC (permalink / raw)
To: Joshua Hahn
Cc: SeongJae Park, Andrew Morton, Honggyu Kim, Hyeongtak Ji, damon,
linux-kernel, linux-mm, stable
On Mon, 21 Jul 2025 08:28:26 -0700 Joshua Hahn <joshua.hahnjy@gmail.com> wrote:
> On Sun, 20 Jul 2025 11:58:22 -0700 SeongJae Park <sj@kernel.org> wrote:
>
> > damon_migrate_pages() try migration even if the target node is invalid.
> > If users mistakenly make such invalid requests via
> > DAMOS_MIGRATE_{HOT,COLD} action, below kernel BUG can happen.
[...]
> > Add a target node validity check in damon_migrate_pages(). The validity
> > check is stolen from that of do_pages_move(), which is being used for
> > move_pages() system call.
> >
> > Fixes: b51820ebea65 ("mm/damon/paddr: introduce DAMOS_MIGRATE_COLD action for demotion") # 6.11.x
> > Cc: stable@vger.kernel.org
> > Cc: Honggyu Kim <honggyu.kim@sk.com>
> > Signed-off-by: SeongJae Park <sj@kernel.org>
> > ---
>
> LGTM, thank you SJ!
>
> On a side note... This seems like it would be a common check. However, doing a
> (quick) search seems to return no function that checks whether a node is valid.
> Perhaps it would make sense to look deeper and see how many other functions
> make this check, and export this as a function? I can try spinning something
> if it makes sense to you : -)
My humble impression was that this check is short enough to be ok to be
open-coded, but please don't be blocked on my opinion :)
>
> Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
Thank you!
>
> Sent using hkml (https://github.com/sjp38/hackermail)
Thanks,
SJ
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/damon/ops-common: ignore migration request to invalid nodes
2025-07-20 18:58 [PATCH] mm/damon/ops-common: ignore migration request to invalid nodes SeongJae Park
2025-07-21 15:28 ` Joshua Hahn
@ 2025-07-22 2:56 ` Andrew Morton
2025-07-22 3:04 ` SeongJae Park
1 sibling, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2025-07-22 2:56 UTC (permalink / raw)
To: SeongJae Park
Cc: Honggyu Kim, Hyeongtak Ji, damon, linux-kernel, linux-mm, stable
On Sun, 20 Jul 2025 11:58:22 -0700 SeongJae Park <sj@kernel.org> wrote:
> damon_migrate_pages() try migration even if the target node is invalid.
> If users mistakenly make such invalid requests via
> DAMOS_MIGRATE_{HOT,COLD} action, below kernel BUG can happen.
>
> [ 7831.883495] BUG: unable to handle page fault for address: 0000000000001f48
> [ 7831.884160] #PF: supervisor read access in kernel mode
> [ 7831.884681] #PF: error_code(0x0000) - not-present page
> [ 7831.885203] PGD 0 P4D 0
> [ 7831.885468] Oops: Oops: 0000 [#1] SMP PTI
> [ 7831.885852] CPU: 31 UID: 0 PID: 94202 Comm: kdamond.0 Not tainted 6.16.0-rc5-mm-new-damon+ #93 PREEMPT(voluntary)
> [ 7831.886913] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-4.el9 04/01/2014
> [ 7831.887777] RIP: 0010:__alloc_frozen_pages_noprof (include/linux/mmzone.h:1724 include/linux/mmzone.h:1750 mm/page_alloc.c:4936 mm/page_alloc.c:5137)
> [...]
> [ 7831.895953] Call Trace:
> [ 7831.896195] <TASK>
> [ 7831.896397] __folio_alloc_noprof (mm/page_alloc.c:5183 mm/page_alloc.c:5192)
> [ 7831.896787] migrate_pages_batch (mm/migrate.c:1189 mm/migrate.c:1851)
> [ 7831.897228] ? __pfx_alloc_migration_target (mm/migrate.c:2137)
> [ 7831.897735] migrate_pages (mm/migrate.c:2078)
> [ 7831.898141] ? __pfx_alloc_migration_target (mm/migrate.c:2137)
> [ 7831.898664] damon_migrate_folio_list (mm/damon/ops-common.c:321 mm/damon/ops-common.c:354)
> [ 7831.899140] damon_migrate_pages (mm/damon/ops-common.c:405)
> [...]
>
> Add a target node validity check in damon_migrate_pages(). The validity
> check is stolen from that of do_pages_move(), which is being used for
> move_pages() system call.
>
> Fixes: b51820ebea65 ("mm/damon/paddr: introduce DAMOS_MIGRATE_COLD action for demotion") # 6.11.x
> Cc: stable@vger.kernel.org
>
> ...
>
> --- a/mm/damon/ops-common.c
> +++ b/mm/damon/ops-common.c
> @@ -383,6 +383,10 @@ unsigned long damon_migrate_pages(struct list_head *folio_list, int target_nid)
> if (list_empty(folio_list))
> return nr_migrated;
>
> + if (target_nid < 0 || target_nid >= MAX_NUMNODES ||
> + !node_state(target_nid, N_MEMORY))
> + return nr_migrated;
> +
> noreclaim_flag = memalloc_noreclaim_save();
>
> nid = folio_nid(lru_to_folio(folio_list));
>
OK. damon_migrate_pages() exists only in mm.git thanks to 13dde31db71f
("mm/damon: move migration helpers from paddr to ops-common"). I
assume that you'll send the -stable people a patch which adds this check into
damon_pa_migrate_pages() when called upon to do so.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/damon/ops-common: ignore migration request to invalid nodes
2025-07-22 2:56 ` Andrew Morton
@ 2025-07-22 3:04 ` SeongJae Park
0 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2025-07-22 3:04 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Honggyu Kim, Hyeongtak Ji, damon, linux-kernel,
linux-mm, stable
On Mon, 21 Jul 2025 19:56:58 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
> On Sun, 20 Jul 2025 11:58:22 -0700 SeongJae Park <sj@kernel.org> wrote:
>
[...]
> > Add a target node validity check in damon_migrate_pages(). The validity
> > check is stolen from that of do_pages_move(), which is being used for
> > move_pages() system call.
> >
> > Fixes: b51820ebea65 ("mm/damon/paddr: introduce DAMOS_MIGRATE_COLD action for demotion") # 6.11.x
> > Cc: stable@vger.kernel.org
> >
> > ...
> >
> > --- a/mm/damon/ops-common.c
> > +++ b/mm/damon/ops-common.c
> > @@ -383,6 +383,10 @@ unsigned long damon_migrate_pages(struct list_head *folio_list, int target_nid)
> > if (list_empty(folio_list))
> > return nr_migrated;
> >
> > + if (target_nid < 0 || target_nid >= MAX_NUMNODES ||
> > + !node_state(target_nid, N_MEMORY))
> > + return nr_migrated;
> > +
> > noreclaim_flag = memalloc_noreclaim_save();
> >
> > nid = folio_nid(lru_to_folio(folio_list));
> >
>
> OK. damon_migrate_pages() exists only in mm.git thanks to 13dde31db71f
> ("mm/damon: move migration helpers from paddr to ops-common"). I
> assume that you'll send the -stable people a patch which adds this check into
> damon_pa_migrate_pages() when called upon to do so.
That's very correct, Andrew. I am planning to do so as soon as this is merged
into the mainline :)
Thanks,
SJ
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-07-22 3:04 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-20 18:58 [PATCH] mm/damon/ops-common: ignore migration request to invalid nodes SeongJae Park
2025-07-21 15:28 ` Joshua Hahn
2025-07-21 16:30 ` SeongJae Park
2025-07-22 2:56 ` Andrew Morton
2025-07-22 3:04 ` SeongJae Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).