]> git.baikalelectronics.ru Git - kernel.git/commit
mm/MADV_COLLAPSE: set EAGAIN on unexpected page refcount
authorZach O'Keefe <zokeefe@google.com>
Wed, 25 Jan 2023 01:57:37 +0000 (17:57 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Feb 2023 11:59:49 +0000 (12:59 +0100)
commit47f1e83e06dc39dfff9b2893c6a1c55e2b06e623
tree6af561fe7f27e54f04d22b2b4f852734be9e58cf
parent283d3c470eee7f4d2dd11435343868cb73411ec3
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 <zokeefe@google.com>
Reported-by: Hugh Dickins <hughd@google.com>
Acked-by: Hugh Dickins <hughd@google.com>
Reviewed-by: Yang Shi <shy828301@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
mm/khugepaged.c