From: David Hildenbrand <david@redhat.com>
To: wang lian <lianux.mm@gmail.com>,
linux-mm@kvack.org, akpm@linux-foundation.org,
lorenzo.stoakes@oracle.com
Cc: Liam.Howlett@oracle.com, brauner@kernel.org,
gkwang@linx-info.com, jannh@google.com,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
p1ucky0923@gmail.com, ryncsn@gmail.com, shuah@kernel.org,
sj@kernel.org, vbabka@suse.cz, zijing.zhang@proton.me
Subject: Re: [PATCH v2] selftests/mm: Add process_madvise() tests
Date: Tue, 1 Jul 2025 15:18:32 +0200 [thread overview]
Message-ID: <1d67a048-00c0-4d2b-96ec-5e8d6d672dbd@redhat.com> (raw)
In-Reply-To: <20250630140957.4000-1-lianux.mm@gmail.com>
On 30.06.25 16:09, wang lian wrote:
> This patch adds tests for the process_madvise(), focusing on
> verifying behavior under various conditions including valid
> usage and error cases.
>
> Signed-off-by: wang lian<lianux.mm@gmail.com>
> Suggested-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> Suggested-by: David Hildenbrand <david@redhat.com>
> ---
>
> Changelog v2:
> - Drop MADV_DONTNEED tests based on feedback
> - Focus solely on process_madvise() syscall
> - Improve error handling and structure
> - Add future-proof flag test
> - Style and comment cleanups
>
> tools/testing/selftests/mm/.gitignore | 1 +
> tools/testing/selftests/mm/Makefile | 1 +
> tools/testing/selftests/mm/process_madv.c | 414 ++++++++++++++++++++++
> tools/testing/selftests/mm/run_vmtests.sh | 5 +
> 4 files changed, 421 insertions(+)
> create mode 100644 tools/testing/selftests/mm/process_madv.c
>
> diff --git a/tools/testing/selftests/mm/.gitignore b/tools/testing/selftests/mm/.gitignore
> index 911f39d634be..a8c3be02188c 100644
> --- a/tools/testing/selftests/mm/.gitignore
> +++ b/tools/testing/selftests/mm/.gitignore
> @@ -42,6 +42,7 @@ memfd_secret
> hugetlb_dio
> pkey_sighandler_tests_32
> pkey_sighandler_tests_64
> +process_madv
> soft-dirty
> split_huge_page_test
> ksm_tests
> diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile
> index 2352252f3914..725612e09582 100644
> --- a/tools/testing/selftests/mm/Makefile
> +++ b/tools/testing/selftests/mm/Makefile
> @@ -86,6 +86,7 @@ TEST_GEN_FILES += mseal_test
> TEST_GEN_FILES += on-fault-limit
> TEST_GEN_FILES += pagemap_ioctl
> TEST_GEN_FILES += pfnmap
> +TEST_GEN_FILES += process_madv
> TEST_GEN_FILES += thuge-gen
> TEST_GEN_FILES += transhuge-stress
> TEST_GEN_FILES += uffd-stress
> diff --git a/tools/testing/selftests/mm/process_madv.c b/tools/testing/selftests/mm/process_madv.c
> new file mode 100644
> index 000000000000..73999c8e3570
> --- /dev/null
> +++ b/tools/testing/selftests/mm/process_madv.c
> @@ -0,0 +1,414 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +
> +#define _GNU_SOURCE
> +#include "../kselftest_harness.h"
> +#include <errno.h>
> +#include <setjmp.h>
> +#include <signal.h>
> +#include <stdbool.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <sys/mman.h>
> +#include <sys/syscall.h>
> +#include <unistd.h>
> +#include <sched.h>
> +#include <sys/pidfd.h>
> +#include "vm_util.h"
> +
> +#include "../pidfd/pidfd.h"
> +
> +/*
> + * Ignore the checkpatch warning, as per the C99 standard, section 7.14.1.1:
> + *
> + * "If the signal occurs other than as the result of calling the abort or raise
> + * function, the behavior is undefined if the signal handler refers to any
> + * object with static storage duration other than by assigning a value to an
> + * object declared as volatile sig_atomic_t"
> + */
> +static volatile sig_atomic_t signal_jump_set;
> +static sigjmp_buf signal_jmp_buf;
> +
> +/*
> + * Ignore the checkpatch warning, we must read from x but don't want to do
> + * anything with it in order to trigger a read page fault. We therefore must use
> + * volatile to stop the compiler from optimising this away.
> + */
> +#define FORCE_READ(x) (*(volatile typeof(x) *)x)
Instead of copying that, it should probably be moved to vm_util.h.
Essentially, also the comments for signal_jump_set are copy-pasted from
guard-regions.c. Is there a way to avoid that?
For example, we could place stuff like signal_jump_set in vm_util.c instead.
> +
> +static void handle_fatal(int c)
> +{
> + if (!signal_jump_set)
> + return;
> +
> + siglongjmp(signal_jmp_buf, c);
> +}
Also copy-pasted.
> +
> +FIXTURE(process_madvise)
> +{
> + int pidfd;
> + int flag;
> +};
> +
> +static void setup_sighandler(void)
> +{
> + struct sigaction act = {
> + .sa_handler = &handle_fatal,
> + .sa_flags = SA_NODEFER,
> + };
> +
> + sigemptyset(&act.sa_mask);
> + if (sigaction(SIGSEGV, &act, NULL))
> + ksft_exit_fail_perror("sigaction");
> +}
> +
> +static void teardown_sighandler(void)
> +{
> + struct sigaction act = {
> + .sa_handler = SIG_DFL,
> + .sa_flags = SA_NODEFER,
> + };
> +
> + sigemptyset(&act.sa_mask);
> + sigaction(SIGSEGV, &act, NULL);
> +}
These two as well.
Let's avoid that much copy-pasting.
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2025-07-01 13:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-30 14:09 [PATCH v2] selftests/mm: Add process_madvise() tests wang lian
2025-07-01 3:06 ` SeongJae Park
2025-07-01 13:03 ` wang lian
2025-07-01 13:18 ` David Hildenbrand [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-07-02 10:01 wang lian
2025-07-02 10:03 wang lian
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=1d67a048-00c0-4d2b-96ec-5e8d6d672dbd@redhat.com \
--to=david@redhat.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=gkwang@linx-info.com \
--cc=jannh@google.com \
--cc=lianux.mm@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=p1ucky0923@gmail.com \
--cc=ryncsn@gmail.com \
--cc=shuah@kernel.org \
--cc=sj@kernel.org \
--cc=vbabka@suse.cz \
--cc=zijing.zhang@proton.me \
/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;
as well as URLs for NNTP newsgroup(s).