Chen Wandun
b89a641056
mm/khugepaged: avoid underflow in madvise_collapse for sub-PMD MADV_COLLAPSE
madvise_collapse() computes the THP-aligned window:
hstart = ALIGN(start, HPAGE_PMD_SIZE); /* round up */
hend = ALIGN_DOWN(end, HPAGE_PMD_SIZE); /* round down */
The following case will cause hstart > hend, and result in underflow in
the return statement, avoid it by returning zero early when hstart > hend.
The return value is due to input is valid to madvise(), and there is
nothing to collapse.
madvise(PMD-aligned + PAGE_SIZE, PAGE_SIZE, MADV_COLLAPSE);
In addition, kmalloc_obj(), mmgrab() and lru_add_drain_all() are
unnecessary when hstart == hend, so skip these operations by returning
early too.
Link: https://lore.kernel.org/20260513055428.1664898-1-chenwandun@lixiang.com
Signed-off-by: Chen Wandun <chenwandun@lixiang.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Lorenzo Stoakes <ljs@kernel.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Nico Pache <npache@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2026-06-21 11:37:31 -07:00
..
2026-06-04 14:45:02 -07:00
2026-06-04 14:45:02 -07:00
2026-05-28 21:04:52 -07:00
2026-02-21 17:09:51 -08:00
2026-01-31 14:22:40 -08:00
2026-04-18 23:24:27 -07:00
2026-01-31 14:22:36 -08:00
2026-06-02 15:22:11 -07:00
2026-01-21 09:38:16 -08:00
2026-05-28 20:50:33 -07:00
2026-02-21 17:09:51 -08:00
2026-05-28 20:50:34 -07:00
2025-05-22 14:55:36 -07:00
2026-06-08 18:21:25 -07:00
2025-05-12 23:50:38 -07:00
2026-04-05 13:53:11 -07:00
2025-11-20 13:43:57 -08:00
2026-02-21 17:09:51 -08:00
2025-07-01 13:25:36 -06:00
2026-01-26 20:02:26 -08:00
2026-04-05 13:53:34 -07:00
2026-04-05 13:52:53 -07:00
2026-06-21 11:37:15 -07:00
2026-02-06 15:47:16 -08:00
2026-02-06 15:47:16 -08:00
2026-05-28 21:04:41 -07:00
2026-01-31 14:22:38 -08:00
2026-03-20 12:05:56 +01:00
2026-06-21 11:37:17 -07:00
2026-02-21 17:09:51 -08:00
2026-06-02 15:22:16 -07:00
2026-01-26 20:02:28 -08:00
2025-11-20 13:43:57 -08:00
2026-01-20 19:24:50 -08:00
2025-11-20 13:43:57 -08:00
2026-05-31 21:50:24 -07:00
2025-03-16 22:06:29 -07:00
2026-06-02 15:06:49 -07:00
2025-09-21 14:22:21 -07:00
2026-01-19 12:30:00 -08:00
2026-06-08 18:21:25 -07:00
2026-04-05 13:53:13 -07:00
2025-03-16 22:06:23 -07:00
2026-06-21 11:37:15 -07:00
2026-04-18 00:10:48 -07:00
2026-06-21 11:37:31 -07:00
2026-05-28 21:05:09 -07:00
2026-04-05 13:53:40 -07:00
2026-06-08 18:21:24 -07:00
2025-07-09 22:42:22 -07:00
2026-05-28 21:04:57 -07:00
2026-06-02 15:22:23 -07:00
2025-11-16 17:27:58 -08:00
2026-04-19 08:01:17 -07:00
2026-06-02 15:22:23 -07:00
2026-04-18 00:10:47 -07:00
2026-06-08 18:21:25 -07:00
2026-05-04 14:03:16 +00:00
2026-05-21 19:06:11 -07:00
2026-06-02 15:22:12 -07:00
2026-06-02 15:22:33 -07:00
2026-04-05 13:53:33 -07:00
2026-06-08 18:21:25 -07:00
2026-06-08 18:21:23 -07:00
2026-02-21 17:09:51 -08:00
2026-05-28 21:04:54 -07:00
2026-01-09 11:53:51 +02:00
2026-05-28 21:04:47 -07:00
2026-06-04 14:45:08 -07:00
2025-11-24 15:08:52 -08:00
2026-04-18 00:10:44 -07:00
2026-06-08 18:21:25 -07:00
2026-01-31 14:22:51 -08:00
2026-05-28 21:04:48 -07:00
2026-04-05 13:53:05 -07:00
2026-04-15 12:59:16 -07:00
2025-09-13 16:55:07 -07:00
2026-04-18 00:10:55 -07:00
2026-04-05 13:53:40 -07:00
2026-06-02 15:22:15 -07:00
2026-04-05 13:53:28 -07:00
2025-08-20 16:31:23 +03:00
2026-02-21 09:58:22 -08:00
2025-05-12 23:50:38 -07:00
2026-04-05 13:53:17 -07:00
2026-06-21 11:31:29 -07:00
2025-03-17 00:05:35 -07:00
2026-01-21 12:51:48 +01:00
2026-04-05 13:53:02 -07:00
2026-06-02 15:22:23 -07:00
2026-05-28 21:05:05 -07:00
2026-05-28 21:04:48 -07:00
2026-04-05 13:53:17 -07:00
2026-03-13 00:07:47 +01:00
2026-06-08 18:21:26 -07:00
2026-04-27 05:54:24 -07:00
2026-04-05 13:53:37 -07:00
2026-06-02 15:22:13 -07:00
2025-09-21 14:22:04 -07:00
2025-07-13 16:38:23 -07:00
2025-11-16 17:27:54 -08:00
2026-04-18 00:10:44 -07:00
2026-04-05 13:53:35 -07:00
2025-11-16 17:27:52 -08:00
2026-06-02 15:22:16 -07:00
2026-05-28 21:04:57 -07:00
2026-04-05 13:53:18 -07:00
2026-02-21 01:02:28 -08:00
2026-06-04 14:45:06 -07:00
2026-04-08 06:52:47 +10:00
2026-01-26 20:02:25 -08:00
2026-06-02 15:22:17 -07:00
2026-05-14 14:56:58 +02:00
2026-04-15 12:59:16 -07:00
2026-05-22 06:23:56 -07:00
2026-06-08 18:21:30 -07:00
2026-05-28 21:04:49 -07:00
2026-06-08 18:21:25 -07:00
2026-06-02 15:22:23 -07:00
2026-06-04 14:45:02 -07:00
2026-06-02 15:22:23 -07:00
2026-06-08 18:21:32 -07:00
2026-06-21 11:37:16 -07:00
2025-11-13 11:01:08 +01:00
2026-06-08 18:21:29 -07:00
2026-06-04 14:45:00 -07:00
2026-04-05 13:53:40 -07:00
2025-10-02 18:18:33 -07:00
2026-02-12 15:42:53 -08:00
2026-06-04 14:44:59 -07:00
2026-04-05 13:53:44 -07:00
2026-06-02 15:22:32 -07:00
2026-05-28 21:04:50 -07:00
2026-06-08 18:21:32 -07:00
2026-04-19 08:01:17 -07:00
2026-06-04 14:45:02 -07:00
2025-09-21 14:21:59 -07:00
2026-06-21 11:31:28 -07:00
2026-06-02 15:22:21 -07:00