* [PATCH 0/2] fix MAP_DROPPABLE not supported errno @ 2026-04-02 0:34 Anthony Yznaga 2026-04-02 0:34 ` [PATCH 1/2] mm: fix mmap errno value when MAP_DROPPABLE is not supported Anthony Yznaga 2026-04-02 0:34 ` [PATCH 2/2] selftests/mm: verify droppable mappings cannot be locked Anthony Yznaga 0 siblings, 2 replies; 8+ messages in thread From: Anthony Yznaga @ 2026-04-02 0:34 UTC (permalink / raw) To: linux-mm, linux-kernel, linux-kselftest Cc: akpm, david, ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, jannh, pfalcato, Jason, shuah Mark Brown reported seeing a regression in -next on 32 bit arm with the mlock selftests. Before exiting and marking the tests failed, the following message was logged after an attempt to create a MAP_DROPPABLE mapping: Bail out! mmap error: Unknown error 524 It turns out error 524 is ENOTSUPP which is an error that userspace is not supposed to see, but it indicates in this instance that MAP_DROPPABLE is not supported. The first patch changes the errno returned to EOPNOTSUPP. The second patch is a second version of a prior patch to introduce selftests to verify locking behavior with droppable mappings with the additonal change to skip the tests when MAP_DROPPABLE is not supported. Anthony Yznaga (2): mm: fix mmap errno value when MAP_DROPPABLE is not supported selftests/mm: verify droppable mappings cannot be locked mm/mmap.c | 2 +- tools/testing/selftests/mm/mlock2-tests.c | 91 ++++++++++++++++++++--- 2 files changed, 83 insertions(+), 10 deletions(-) -- 2.47.3 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] mm: fix mmap errno value when MAP_DROPPABLE is not supported 2026-04-02 0:34 [PATCH 0/2] fix MAP_DROPPABLE not supported errno Anthony Yznaga @ 2026-04-02 0:34 ` Anthony Yznaga 2026-04-02 0:44 ` Andrew Morton 2026-04-02 0:34 ` [PATCH 2/2] selftests/mm: verify droppable mappings cannot be locked Anthony Yznaga 1 sibling, 1 reply; 8+ messages in thread From: Anthony Yznaga @ 2026-04-02 0:34 UTC (permalink / raw) To: linux-mm, linux-kernel, linux-kselftest Cc: akpm, david, ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, jannh, pfalcato, Jason, shuah On configs where MAP_DROPPABLE is not supported (currently any 32-bit config except for PPC32), mmap fails with errno set to ENOTSUPP. However, ENOTSUPP is not a standard error value that userspace knows about. The acceptable userspace-visible errno to use is EOPNOTSUPP. checkpatch.pl has a warning to this affect. Fixes: 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings") Cc: <stable@vger.kernel.org> Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com> --- mm/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/mmap.c b/mm/mmap.c index 5754d1c36462..2311ae7c2ff4 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -504,7 +504,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr, break; case MAP_DROPPABLE: if (VM_DROPPABLE == VM_NONE) - return -ENOTSUPP; + return -EOPNOTSUPP; /* * A locked or stack area makes no sense to be droppable. * -- 2.47.3 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] mm: fix mmap errno value when MAP_DROPPABLE is not supported 2026-04-02 0:34 ` [PATCH 1/2] mm: fix mmap errno value when MAP_DROPPABLE is not supported Anthony Yznaga @ 2026-04-02 0:44 ` Andrew Morton 2026-04-02 7:17 ` David Hildenbrand (Arm) 0 siblings, 1 reply; 8+ messages in thread From: Andrew Morton @ 2026-04-02 0:44 UTC (permalink / raw) To: Anthony Yznaga Cc: linux-mm, linux-kernel, linux-kselftest, david, ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, jannh, pfalcato, Jason, shuah On Wed, 1 Apr 2026 17:34:16 -0700 Anthony Yznaga <anthony.yznaga@oracle.com> wrote: > On configs where MAP_DROPPABLE is not supported (currently any 32-bit > config except for PPC32), mmap fails with errno set to ENOTSUPP. > However, ENOTSUPP is not a standard error value that userspace knows > about. The acceptable userspace-visible errno to use is EOPNOTSUPP. > checkpatch.pl has a warning to this affect. Sounds very reasonable. EOPNOTSUPP is clearly a networking thing so what on earth is it doing coming out of mmap code? Our poor operator is now looking at a networking error code and wondering what this supposedly non-networking application is up to. But just that's a pet peeve - I lost that one decades ago. > Fixes: 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings") Nearly two years ago so I think I'll add this to mm-unstable for 7.1-rc1 and shall let it trickle back a little more slowly than might a 7.0-rcX hotfix. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] mm: fix mmap errno value when MAP_DROPPABLE is not supported 2026-04-02 0:44 ` Andrew Morton @ 2026-04-02 7:17 ` David Hildenbrand (Arm) 2026-04-02 23:13 ` anthony.yznaga 0 siblings, 1 reply; 8+ messages in thread From: David Hildenbrand (Arm) @ 2026-04-02 7:17 UTC (permalink / raw) To: Andrew Morton, Anthony Yznaga Cc: linux-mm, linux-kernel, linux-kselftest, ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, jannh, pfalcato, Jason, shuah On 4/2/26 02:44, Andrew Morton wrote: > On Wed, 1 Apr 2026 17:34:16 -0700 Anthony Yznaga <anthony.yznaga@oracle.com> wrote: > >> On configs where MAP_DROPPABLE is not supported (currently any 32-bit >> config except for PPC32), mmap fails with errno set to ENOTSUPP. >> However, ENOTSUPP is not a standard error value that userspace knows >> about. The acceptable userspace-visible errno to use is EOPNOTSUPP. >> checkpatch.pl has a warning to this affect. > > Sounds very reasonable. > > EOPNOTSUPP is clearly a networking thing so what on earth is it doing > coming out of mmap code? Our poor operator is now looking at a networking > error code and wondering what this supposedly non-networking > application is up to. > > But just that's a pet peeve - I lost that one decades ago. > >> Fixes: 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings") > > Nearly two years ago so I think I'll add this to mm-unstable for > 7.1-rc1 and shall let it trickle back a little more slowly than might a > 7.0-rcX hotfix. > > Acked-by: David Hildenbrand (Arm) <david@kernel.org> But ~/git/linux/mm$ git grep ENOTSUPP hugetlb_vmemmap.c: ret = -ENOTSUPP; mmap.c: return -ENOTSUPP; Should we fix up the other one as well? -- Cheers, David ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] mm: fix mmap errno value when MAP_DROPPABLE is not supported 2026-04-02 7:17 ` David Hildenbrand (Arm) @ 2026-04-02 23:13 ` anthony.yznaga 0 siblings, 0 replies; 8+ messages in thread From: anthony.yznaga @ 2026-04-02 23:13 UTC (permalink / raw) To: David Hildenbrand (Arm), Andrew Morton Cc: linux-mm, linux-kernel, linux-kselftest, ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, jannh, pfalcato, Jason, shuah On 4/2/26 12:17 AM, David Hildenbrand (Arm) wrote: > On 4/2/26 02:44, Andrew Morton wrote: >> On Wed, 1 Apr 2026 17:34:16 -0700 Anthony Yznaga <anthony.yznaga@oracle.com> wrote: >> >>> On configs where MAP_DROPPABLE is not supported (currently any 32-bit >>> config except for PPC32), mmap fails with errno set to ENOTSUPP. >>> However, ENOTSUPP is not a standard error value that userspace knows >>> about. The acceptable userspace-visible errno to use is EOPNOTSUPP. >>> checkpatch.pl has a warning to this affect. >> Sounds very reasonable. >> >> EOPNOTSUPP is clearly a networking thing so what on earth is it doing >> coming out of mmap code? Our poor operator is now looking at a networking >> error code and wondering what this supposedly non-networking >> application is up to. >> >> But just that's a pet peeve - I lost that one decades ago. >> >>> Fixes: 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings") >> Nearly two years ago so I think I'll add this to mm-unstable for >> 7.1-rc1 and shall let it trickle back a little more slowly than might a >> 7.0-rcX hotfix. >> >> > > Acked-by: David Hildenbrand (Arm) <david@kernel.org> > > > But > > ~/git/linux/mm$ git grep ENOTSUPP > hugetlb_vmemmap.c: ret = -ENOTSUPP; > mmap.c: return -ENOTSUPP; > > > Should we fix up the other one as well? > I'm looking into this. It's returned for the case where vmemmap mappings cannot be split/freed because they are self-hosted due to memory hotplug. Many callers end up ignoring the error, but there may be a way for it to be propagated to userspace as the errno for a failed write to a sysfs file. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] selftests/mm: verify droppable mappings cannot be locked 2026-04-02 0:34 [PATCH 0/2] fix MAP_DROPPABLE not supported errno Anthony Yznaga 2026-04-02 0:34 ` [PATCH 1/2] mm: fix mmap errno value when MAP_DROPPABLE is not supported Anthony Yznaga @ 2026-04-02 0:34 ` Anthony Yznaga 2026-04-02 7:28 ` David Hildenbrand (Arm) 1 sibling, 1 reply; 8+ messages in thread From: Anthony Yznaga @ 2026-04-02 0:34 UTC (permalink / raw) To: linux-mm, linux-kernel, linux-kselftest Cc: akpm, david, ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, jannh, pfalcato, Jason, shuah For configs that support MAP_DROPPABLE verify that a mapping created with MAP_DROPPABLE cannot be locked via mlock(), and that it will not be locked if it's created after mlockall(MCL_FUTURE). Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com> --- tools/testing/selftests/mm/mlock2-tests.c | 91 ++++++++++++++++++++--- 1 file changed, 82 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/mm/mlock2-tests.c b/tools/testing/selftests/mm/mlock2-tests.c index b474f2b20def..2750a3d6e8e4 100644 --- a/tools/testing/selftests/mm/mlock2-tests.c +++ b/tools/testing/selftests/mm/mlock2-tests.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #define _GNU_SOURCE #include <sys/mman.h> +#include <linux/mman.h> #include <stdint.h> #include <unistd.h> #include <string.h> @@ -163,14 +164,17 @@ static int lock_check(unsigned long addr) return (vma_rss == vma_size); } -static int unlock_lock_check(char *map) +static int unlock_lock_check(char *map, bool mlock_supported) { - if (is_vmflag_set((unsigned long)map, LOCKED)) { + if (!is_vmflag_set((unsigned long)map, LOCKED)) + return 0; + + if (mlock_supported) ksft_print_msg("VMA flag %s is present on page 1 after unlock\n", LOCKED); - return 1; - } + else + ksft_print_msg("VMA flag %s is present on an unsupported VMA\n", LOCKED); - return 0; + return 1; } static void test_mlock_lock(void) @@ -196,7 +200,7 @@ static void test_mlock_lock(void) ksft_exit_fail_msg("munlock(): %s\n", strerror(errno)); } - ksft_test_result(!unlock_lock_check(map), "%s: Unlocked\n", __func__); + ksft_test_result(!unlock_lock_check(map, true), "%s: Unlocked\n", __func__); munmap(map, 2 * page_size); } @@ -296,7 +300,7 @@ static void test_munlockall0(void) ksft_exit_fail_msg("munlockall(): %s\n", strerror(errno)); } - ksft_test_result(!unlock_lock_check(map), "%s: No locked memory\n", __func__); + ksft_test_result(!unlock_lock_check(map, true), "%s: No locked memory\n", __func__); munmap(map, 2 * page_size); } @@ -336,7 +340,74 @@ static void test_munlockall1(void) ksft_exit_fail_msg("munlockall() %s\n", strerror(errno)); } - ksft_test_result(!unlock_lock_check(map), "%s: No locked memory\n", __func__); + ksft_test_result(!unlock_lock_check(map, true), "%s: No locked memory\n", __func__); + munmap(map, 2 * page_size); +} + +/* + * Droppable memory should not be lockable. + */ +static void test_mlock_droppable(void) +{ + char *map; + unsigned long page_size = getpagesize(); + + /* + * Ensure MCL_FUTURE is not set. + */ + if (mlockall(MCL_CURRENT)) + ksft_exit_fail_msg("mlockall(MCL_CURRENT): %s\n", strerror(errno)); + if (munlockall()) + ksft_exit_fail_msg("munlockall() %s\n", strerror(errno)); + + map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0); + if (map == MAP_FAILED) { + if (errno == EOPNOTSUPP) { + ksft_test_result_skip("%s: MAP_DROPPABLE not supported\n", __func__); + return; + } + ksft_exit_fail_msg("mmap error: %s\n", strerror(errno)); + } + + if (mlock2_(map, 2 * page_size, 0)) { + munmap(map, 2 * page_size); + ksft_exit_fail_msg("mlock2(0): %s\n", strerror(errno)); + } + + ksft_test_result(!unlock_lock_check(map, false), "%s: droppable memory not locked\n", + __func__); + + munmap(map, 2 * page_size); +} + +static void test_mlockall_future_droppable(void) +{ + char *map; + unsigned long page_size = getpagesize(); + + if (mlockall(MCL_CURRENT | MCL_FUTURE)) + ksft_exit_fail_msg("mlockall(MCL_CURRENT | MCL_FUTURE): %s\n", strerror(errno)); + + map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0); + + if (map == MAP_FAILED) { + if (errno == EOPNOTSUPP) { + ksft_test_result_skip("%s: MAP_DROPPABLE not supported\n", __func__); + return; + } + ksft_exit_fail_msg("mmap error: %s\n", strerror(errno)); + } + + ksft_test_result(!unlock_lock_check(map, false), "%s: droppable memory not locked\n", + __func__); + + if (munlockall()) { + munmap(map, 2 * page_size); + ksft_exit_fail_msg("munlockall() %s\n", strerror(errno)); + } + munmap(map, 2 * page_size); } @@ -442,7 +513,7 @@ int main(int argc, char **argv) munmap(map, size); - ksft_set_plan(13); + ksft_set_plan(15); test_mlock_lock(); test_mlock_onfault(); @@ -451,6 +522,8 @@ int main(int argc, char **argv) test_lock_onfault_of_present(); test_vma_management(true); test_mlockall(); + test_mlock_droppable(); + test_mlockall_future_droppable(); ksft_finished(); } -- 2.47.3 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] selftests/mm: verify droppable mappings cannot be locked 2026-04-02 0:34 ` [PATCH 2/2] selftests/mm: verify droppable mappings cannot be locked Anthony Yznaga @ 2026-04-02 7:28 ` David Hildenbrand (Arm) 2026-04-02 23:16 ` anthony.yznaga 0 siblings, 1 reply; 8+ messages in thread From: David Hildenbrand (Arm) @ 2026-04-02 7:28 UTC (permalink / raw) To: Anthony Yznaga, linux-mm, linux-kernel, linux-kselftest Cc: akpm, ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, jannh, pfalcato, Jason, shuah > + > +/* > + * Droppable memory should not be lockable. > + */ > +static void test_mlock_droppable(void) > +{ > + char *map; > + unsigned long page_size = getpagesize(); > + > + /* > + * Ensure MCL_FUTURE is not set. > + */ > + if (mlockall(MCL_CURRENT)) > + ksft_exit_fail_msg("mlockall(MCL_CURRENT): %s\n", strerror(errno)); Why do we need the prior mlockall()? If that is really required, the comment should be clearer why the munlockall() is insufficient. Also, why can't we fail only the test? > + if (munlockall()) > + ksft_exit_fail_msg("munlockall() %s\n", strerror(errno)); Why can't we fail only the test? > + > + map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, > + MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0); > + if (map == MAP_FAILED) { > + if (errno == EOPNOTSUPP) { > + ksft_test_result_skip("%s: MAP_DROPPABLE not supported\n", __func__); > + return; > + } > + ksft_exit_fail_msg("mmap error: %s\n", strerror(errno)); same. > + } > + > + if (mlock2_(map, 2 * page_size, 0)) { > + munmap(map, 2 * page_size); Not required when exiting either way? > + ksft_exit_fail_msg("mlock2(0): %s\n", strerror(errno)); > + } > + > + ksft_test_result(!unlock_lock_check(map, false), "%s: droppable memory not locked\n", > + __func__); > + > + munmap(map, 2 * page_size); > +} > + > +static void test_mlockall_future_droppable(void) > +{ > + char *map; > + unsigned long page_size = getpagesize(); > + > + if (mlockall(MCL_CURRENT | MCL_FUTURE)) > + ksft_exit_fail_msg("mlockall(MCL_CURRENT | MCL_FUTURE): %s\n", strerror(errno)); Similar comments as for the other path regarding ksft_exit_fail_msg() etc. > + > + map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, > + MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0); > + > + if (map == MAP_FAILED) { > + if (errno == EOPNOTSUPP) { > + ksft_test_result_skip("%s: MAP_DROPPABLE not supported\n", __func__); > + return; > + } > + ksft_exit_fail_msg("mmap error: %s\n", strerror(errno)); > + } > + > + ksft_test_result(!unlock_lock_check(map, false), "%s: droppable memory not locked\n", > + __func__); > + > + if (munlockall()) { > + munmap(map, 2 * page_size); > + ksft_exit_fail_msg("munlockall() %s\n", strerror(errno)); > + } > + > munmap(map, 2 * page_size); > } -- Cheers, David ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] selftests/mm: verify droppable mappings cannot be locked 2026-04-02 7:28 ` David Hildenbrand (Arm) @ 2026-04-02 23:16 ` anthony.yznaga 0 siblings, 0 replies; 8+ messages in thread From: anthony.yznaga @ 2026-04-02 23:16 UTC (permalink / raw) To: David Hildenbrand (Arm), linux-mm, linux-kernel, linux-kselftest Cc: akpm, ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, jannh, pfalcato, Jason, shuah On 4/2/26 12:28 AM, David Hildenbrand (Arm) wrote: >> + >> +/* >> + * Droppable memory should not be lockable. >> + */ >> +static void test_mlock_droppable(void) >> +{ >> + char *map; >> + unsigned long page_size = getpagesize(); >> + >> + /* >> + * Ensure MCL_FUTURE is not set. >> + */ >> + if (mlockall(MCL_CURRENT)) >> + ksft_exit_fail_msg("mlockall(MCL_CURRENT): %s\n", strerror(errno)); > Why do we need the prior mlockall()? If that is really required, the > comment should be clearer why the munlockall() is insufficient. The mlockall() is not needed. Will remove. > > Also, why can't we fail only the test? The tests can be failed without the exit. I'll update them. Thanks, Anthony > >> + if (munlockall()) >> + ksft_exit_fail_msg("munlockall() %s\n", strerror(errno)); > Why can't we fail only the test? > >> + >> + map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, >> + MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0); >> + if (map == MAP_FAILED) { >> + if (errno == EOPNOTSUPP) { >> + ksft_test_result_skip("%s: MAP_DROPPABLE not supported\n", __func__); >> + return; >> + } >> + ksft_exit_fail_msg("mmap error: %s\n", strerror(errno)); > same. > >> + } >> + >> + if (mlock2_(map, 2 * page_size, 0)) { >> + munmap(map, 2 * page_size); > Not required when exiting either way? > >> + ksft_exit_fail_msg("mlock2(0): %s\n", strerror(errno)); >> + } >> + >> + ksft_test_result(!unlock_lock_check(map, false), "%s: droppable memory not locked\n", >> + __func__); >> + >> + munmap(map, 2 * page_size); >> +} >> + >> +static void test_mlockall_future_droppable(void) >> +{ >> + char *map; >> + unsigned long page_size = getpagesize(); >> + >> + if (mlockall(MCL_CURRENT | MCL_FUTURE)) >> + ksft_exit_fail_msg("mlockall(MCL_CURRENT | MCL_FUTURE): %s\n", strerror(errno)); > Similar comments as for the other path regarding ksft_exit_fail_msg() etc. > >> + >> + map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, >> + MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0); >> + >> + if (map == MAP_FAILED) { >> + if (errno == EOPNOTSUPP) { >> + ksft_test_result_skip("%s: MAP_DROPPABLE not supported\n", __func__); >> + return; >> + } >> + ksft_exit_fail_msg("mmap error: %s\n", strerror(errno)); >> + } >> + >> + ksft_test_result(!unlock_lock_check(map, false), "%s: droppable memory not locked\n", >> + __func__); >> + >> + if (munlockall()) { >> + munmap(map, 2 * page_size); >> + ksft_exit_fail_msg("munlockall() %s\n", strerror(errno)); >> + } >> + >> munmap(map, 2 * page_size); >> } ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-04-02 23:16 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-04-02 0:34 [PATCH 0/2] fix MAP_DROPPABLE not supported errno Anthony Yznaga 2026-04-02 0:34 ` [PATCH 1/2] mm: fix mmap errno value when MAP_DROPPABLE is not supported Anthony Yznaga 2026-04-02 0:44 ` Andrew Morton 2026-04-02 7:17 ` David Hildenbrand (Arm) 2026-04-02 23:13 ` anthony.yznaga 2026-04-02 0:34 ` [PATCH 2/2] selftests/mm: verify droppable mappings cannot be locked Anthony Yznaga 2026-04-02 7:28 ` David Hildenbrand (Arm) 2026-04-02 23:16 ` anthony.yznaga
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox