From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Park Tae-sun <ts930@dgu.ac.kr>,
Andrew Morton <akpm@linux-foundation.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Shuah Khan <shuah@kernel.org>,
Brendan Jackman <brendan.jackman@linux.dev>,
Muhammad Usama Anjum <usama.anjum@arm.com>
Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests/mm: fix mlock2 errno handling and false PASS on ENOSYS
Date: Thu, 24 Sep 2026 21:25:07 +0200 [thread overview]
Message-ID: <2c1def7b-aceb-45c7-9cf0-8518ef26dff3@kernel.org> (raw)
In-Reply-To: <20260923-selftests-mm-mlock2-fix-v1-1-750b627854c6@dgu.ac.kr>
On 9/23/26 11:26, Park Tae-sun wrote:
> While inspecting selftests/mm syscall wrappers, I noticed that mlock2_()
> in mlock2.h handles the syscall return value differently from other
> wrappers:
>
> int ret = syscall(__NR_mlock2, start, len, flags);
> if (ret) {
> errno = ret;
> return -1;
> }
>
> Commit 1ddae9d67ee1 ("selftests/mm/mlock: print error on failure")
> introduced this intending to make mlock2_() behave like libc by setting
> errno and returning -1. However, glibc syscall(2) already returns -1 on
> failure and sets positive errno. Assigning "errno = ret;" overwrites
> errno with -1.
>
> To verify this, mlock2 was disabled in the kernel (via sys_ni_syscall) to
> return -ENOSYS. Testing revealed two interrelated defects:
>
> 1. In the unmodified test, mlock2_() clobbered errno to -1. The check
> "if (ret && errno == ENOSYS)" in main() was bypassed, resulting in an
> immediate crash in the first test:
>
> ~ # ./mlock2-tests
> TAP version 13
> 1..15
> Bail out! mlock2(0): Unknown error -1
> # Planned tests != run tests (15 != 0)
> # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
> (exit code: 1 - FAIL)
>
> 2. After restoring mlock2_() to directly return syscall(), errno correctly
> retained ENOSYS (38), entering the ENOSYS check in main(). However, it
> then called ksft_finished():
>
> ~ # ./mlock2-tests
> TAP version 13
> # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
> ~ # echo $?
> 0
>
> Because ksft_set_plan() had not been called yet (ksft_plan == 0) and
> zero tests ran (ksft_pass == 0), ksft_finished() evaluated 0 == 0 as
> success and exited with KSFT_PASS (code 0) without any TAP skip header.
>
> Fix both issues by:
> 1. Returning the syscall() result directly in mlock2_() so that errno is
> preserved.
> 2. Calling ksft_exit_skip() on ENOSYS so unsupported kernels report a TAP
> skip ("1..0 # SKIP ...") and exit with KSFT_SKIP (code 4).
>
> Verification on the mlock2-disabled kernel:
>
> ~ # ./mlock2-tests
> TAP version 13
> 1..0 # SKIP mlock2() syscall is not supported
> ~ # echo $?
> 4
>
> Re-enabling mlock2 in the kernel confirmed all 15 tests pass cleanly:
>
> ~ # ./mlock2-tests
> TAP version 13
> 1..15
> ok 1 test_mlock_lock: Locked
> ...
> ok 15 test_mlockall_future_droppable: droppable memory not locked
> # Totals: pass:15 fail:0 xfail:0 xpass:0 skip:0 error:0
> ~ # echo $?
> 0
>
> Fixes: 1ddae9d67ee1 ("selftests/mm/mlock: print error on failure")
> Fixes: 65c89684896d ("selftests/mm: mlock2-tests: conform test to TAP format output")
> Signed-off-by: Park Tae-sun <ts930@dgu.ac.kr>
> ---
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
prev parent reply other threads:[~2026-09-24 19:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 9:26 Park Tae-sun
2026-09-23 21:27 ` Gregory Price
2026-09-24 8:40 ` Usama Anjum
2026-09-24 19:25 ` David Hildenbrand (Arm) [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2c1def7b-aceb-45c7-9cf0-8518ef26dff3@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=brendan.jackman@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=ts930@dgu.ac.kr \
--cc=usama.anjum@arm.com \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®