From 47f1e83e06dc39dfff9b2893c6a1c55e2b06e623 Mon Sep 17 00:00:00 2001 From: Zach O'Keefe Date: Tue, 24 Jan 2023 17:57:37 -0800 Subject: [PATCH] mm/MADV_COLLAPSE: set EAGAIN on unexpected page refcount commit 2653eeffe53ce2b131f7c7b53ebafadbeb8fe72d upstream. During collapse, in a few places we check to see if a given small page has any unaccounted references. If the refcount on the page doesn't match our expectations, it must be there is an unknown user concurrently interested in the page, and so it's not safe to move the contents elsewhere. However, the unaccounted pins are likely an ephemeral state. In this situation, MADV_COLLAPSE returns -EINVAL when it should return -EAGAIN. This could cause userspace to conclude that the syscall failed, when it in fact could succeed by retrying. Link: https://lkml.kernel.org/r/20230125015738.912924-1-zokeefe@google.com Fixes: 0dd06833e1a1 ("mm/madvise: introduce MADV_COLLAPSE sync hugepage collapse") Signed-off-by: Zach O'Keefe Reported-by: Hugh Dickins Acked-by: Hugh Dickins Reviewed-by: Yang Shi Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/khugepaged.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index e0c7bbd69b33e..77a76bcf15f57 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2608,6 +2608,7 @@ static int madvise_collapse_errno(enum scan_result r) case SCAN_CGROUP_CHARGE_FAIL: return -EBUSY; /* Resource temporary unavailable - trying again might succeed */ + case SCAN_PAGE_COUNT: case SCAN_PAGE_LOCK: case SCAN_PAGE_LRU: case SCAN_DEL_PAGE_LRU: -- 2.39.5