* [PATCH] selftests/mm: Specify requirement for PROC_MEM_ALWAYS_FORCE=y
@ 2026-04-16 18:40 Mark Brown
2026-04-16 18:56 ` Mike Rapoport
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Mark Brown @ 2026-04-16 18:40 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Shuah Khan
Cc: Aishwarya TCV, linux-mm, linux-kselftest, linux-kernel, Mark Brown
Several of the mm selftests made use of /proc/pid/mem as part of their
operation but we do not specify this in the config fragment for them, at
least mkdirty and ksm_functional_tests have this requirement.
This has been working fine in practice since PROC_MEM_ALWAYS_FORCE was the
default setting but commit 599bbba5a36f ("proc: make PROC_MEM_FORCE_PTRACE
the Kconfig default") that is no longer the case, meaning that tests run
on kernels built based on defconfigs have started having the new more
restrictive default and failing. Add PROC_MEM_ALWAYS_FORCE to the config
fragment for the mm selftests.
Thanks to Aishwarya TCV for spotting the issue and identifying the commit
that introduced it.
Reported-by: Aishwarya TCV <aishwarya.tcv@arm.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
tools/testing/selftests/mm/config | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/testing/selftests/mm/config b/tools/testing/selftests/mm/config
index 1dbe2b4558ab..06f78bd232e2 100644
--- a/tools/testing/selftests/mm/config
+++ b/tools/testing/selftests/mm/config
@@ -13,3 +13,4 @@ CONFIG_PROFILING=y
CONFIG_UPROBES=y
CONFIG_MEMORY_FAILURE=y
CONFIG_HWPOISON_INJECT=m
+CONFIG_PROC_MEM_ALWAYS_FORCE=y
---
base-commit: 599bbba5a36f6de57ab14c373c25881e2b5273f5
change-id: 20260416-selftests-mm-proc-mem-always-force-5ce1b26022c2
Best regards,
--
Mark Brown <broonie@kernel.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] selftests/mm: Specify requirement for PROC_MEM_ALWAYS_FORCE=y
2026-04-16 18:40 [PATCH] selftests/mm: Specify requirement for PROC_MEM_ALWAYS_FORCE=y Mark Brown
@ 2026-04-16 18:56 ` Mike Rapoport
2026-04-16 19:05 ` David Hildenbrand (Arm)
` (2 subsequent siblings)
3 siblings, 0 replies; 10+ messages in thread
From: Mike Rapoport @ 2026-04-16 18:56 UTC (permalink / raw)
To: Mark Brown
Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Suren Baghdasaryan,
Michal Hocko, Shuah Khan, Aishwarya TCV, linux-mm,
linux-kselftest, linux-kernel
On Thu, Apr 16, 2026 at 07:40:56PM +0100, Mark Brown wrote:
> Several of the mm selftests made use of /proc/pid/mem as part of their
> operation but we do not specify this in the config fragment for them, at
> least mkdirty and ksm_functional_tests have this requirement.
>
> This has been working fine in practice since PROC_MEM_ALWAYS_FORCE was the
> default setting but commit 599bbba5a36f ("proc: make PROC_MEM_FORCE_PTRACE
> the Kconfig default") that is no longer the case, meaning that tests run
> on kernels built based on defconfigs have started having the new more
> restrictive default and failing. Add PROC_MEM_ALWAYS_FORCE to the config
> fragment for the mm selftests.
>
> Thanks to Aishwarya TCV for spotting the issue and identifying the commit
> that introduced it.
>
> Reported-by: Aishwarya TCV <aishwarya.tcv@arm.com>
> Signed-off-by: Mark Brown <broonie@kernel.org>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> tools/testing/selftests/mm/config | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/testing/selftests/mm/config b/tools/testing/selftests/mm/config
> index 1dbe2b4558ab..06f78bd232e2 100644
> --- a/tools/testing/selftests/mm/config
> +++ b/tools/testing/selftests/mm/config
> @@ -13,3 +13,4 @@ CONFIG_PROFILING=y
> CONFIG_UPROBES=y
> CONFIG_MEMORY_FAILURE=y
> CONFIG_HWPOISON_INJECT=m
> +CONFIG_PROC_MEM_ALWAYS_FORCE=y
>
> ---
> base-commit: 599bbba5a36f6de57ab14c373c25881e2b5273f5
> change-id: 20260416-selftests-mm-proc-mem-always-force-5ce1b26022c2
>
> Best regards,
> --
> Mark Brown <broonie@kernel.org>
>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] selftests/mm: Specify requirement for PROC_MEM_ALWAYS_FORCE=y
2026-04-16 18:40 [PATCH] selftests/mm: Specify requirement for PROC_MEM_ALWAYS_FORCE=y Mark Brown
2026-04-16 18:56 ` Mike Rapoport
@ 2026-04-16 19:05 ` David Hildenbrand (Arm)
2026-04-16 19:10 ` Mark Brown
2026-04-17 2:57 ` Anshuman Khandual
2026-04-17 4:37 ` Dev Jain
3 siblings, 1 reply; 10+ messages in thread
From: David Hildenbrand (Arm) @ 2026-04-16 19:05 UTC (permalink / raw)
To: Mark Brown, Andrew Morton, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Shuah Khan
Cc: Aishwarya TCV, linux-mm, linux-kselftest, linux-kernel
On 4/16/26 20:40, Mark Brown wrote:
> Several of the mm selftests made use of /proc/pid/mem as part of their
> operation but we do not specify this in the config fragment for them, at
> least mkdirty and ksm_functional_tests have this requirement.
>
> This has been working fine in practice since PROC_MEM_ALWAYS_FORCE was the
> default setting but commit 599bbba5a36f ("proc: make PROC_MEM_FORCE_PTRACE
> the Kconfig default") that is no longer the case, meaning that tests run
> on kernels built based on defconfigs have started having the new more
> restrictive default and failing. Add PROC_MEM_ALWAYS_FORCE to the config
> fragment for the mm selftests.
>
> Thanks to Aishwarya TCV for spotting the issue and identifying the commit
> that introduced it.
>
> Reported-by: Aishwarya TCV <aishwarya.tcv@arm.com>
> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---
I guess we could teach most tests to SKIP if /proc/pid/mem is unusable.
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] selftests/mm: Specify requirement for PROC_MEM_ALWAYS_FORCE=y
2026-04-16 19:05 ` David Hildenbrand (Arm)
@ 2026-04-16 19:10 ` Mark Brown
2026-04-16 19:28 ` Mike Rapoport
0 siblings, 1 reply; 10+ messages in thread
From: Mark Brown @ 2026-04-16 19:10 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: Andrew Morton, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan,
Aishwarya TCV, linux-mm, linux-kselftest, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 665 bytes --]
On Thu, Apr 16, 2026 at 09:05:11PM +0200, David Hildenbrand (Arm) wrote:
> On 4/16/26 20:40, Mark Brown wrote:
> > Several of the mm selftests made use of /proc/pid/mem as part of their
> > operation but we do not specify this in the config fragment for them, at
> > least mkdirty and ksm_functional_tests have this requirement.
> I guess we could teach most tests to SKIP if /proc/pid/mem is unusable.
That would be nicer, yes. I imagine some of these will predate there
being a configuration option here at all, it's possible there's newer
tests that skip cleanly - I didn't look at the skips.
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Thanks.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] selftests/mm: Specify requirement for PROC_MEM_ALWAYS_FORCE=y
2026-04-16 19:10 ` Mark Brown
@ 2026-04-16 19:28 ` Mike Rapoport
2026-04-17 2:56 ` Anshuman Khandual
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Mike Rapoport @ 2026-04-16 19:28 UTC (permalink / raw)
To: Mark Brown
Cc: David Hildenbrand (Arm),
Andrew Morton, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Suren Baghdasaryan, Michal Hocko, Shuah Khan, Aishwarya TCV,
linux-mm, linux-kselftest, linux-kernel
On Thu, Apr 16, 2026 at 08:10:53PM +0100, Mark Brown wrote:
> On Thu, Apr 16, 2026 at 09:05:11PM +0200, David Hildenbrand (Arm) wrote:
> > On 4/16/26 20:40, Mark Brown wrote:
>
> > > Several of the mm selftests made use of /proc/pid/mem as part of their
> > > operation but we do not specify this in the config fragment for them, at
> > > least mkdirty and ksm_functional_tests have this requirement.
>
> > I guess we could teach most tests to SKIP if /proc/pid/mem is unusable.
>
> That would be nicer, yes. I imagine some of these will predate there
> being a configuration option here at all, it's possible there's newer
> tests that skip cleanly - I didn't look at the skips.
Enabling access to /proc/pid/mem keeps the coverage, not that it's great
right now, but still.
But sure graceful skips are better than failing the entire tests. Would be
something like this:
diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
index 8d874c4754f3..374b5a25f36d 100644
--- a/tools/testing/selftests/mm/ksm_functional_tests.c
+++ b/tools/testing/selftests/mm/ksm_functional_tests.c
@@ -37,7 +37,6 @@ enum ksm_merge_mode {
KSM_MERGE_NONE, /* PRCTL already set */
};
-static int mem_fd;
static int pages_to_scan_fd;
static int sleep_millisecs_fd;
static int pagemap_fd;
@@ -622,10 +621,17 @@ static void test_prot_none(void)
{
const unsigned int size = 2 * MiB;
char *map;
+ int mem_fd;
int i;
ksft_print_msg("[RUN] %s\n", __func__);
+ mem_fd = open("/proc/self/mem", O_RDWR);
+ if (mem_fd < 0) {
+ ksft_test_result_skip("opening /proc/self/mem failed\n");
+ return;
+ }
+
map = mmap_and_merge_range(0x11, size, PROT_NONE, KSM_MERGE_MADVISE);
if (map == MAP_FAILED)
goto unmap;
@@ -694,9 +700,6 @@ static void test_fork_ksm_merging_page_count(void)
static void init_global_file_handles(void)
{
- mem_fd = open("/proc/self/mem", O_RDWR);
- if (mem_fd < 0)
- ksft_exit_fail_msg("opening /proc/self/mem failed\n");
if (ksm_stop() < 0)
ksft_exit_skip("accessing \"/sys/kernel/mm/ksm/run\") failed\n");
if (ksm_get_full_scans() < 0)
diff --git a/tools/testing/selftests/mm/mkdirty.c b/tools/testing/selftests/mm/mkdirty.c
index 68dd447a5454..e4a94638018b 100644
--- a/tools/testing/selftests/mm/mkdirty.c
+++ b/tools/testing/selftests/mm/mkdirty.c
@@ -27,7 +27,6 @@
static size_t pagesize;
static size_t thpsize;
-static int mem_fd;
static int pagemap_fd;
static sigjmp_buf env;
@@ -86,11 +85,18 @@ static char *mmap_thp_range(int prot, char **_mmap_mem, size_t *_mmap_size)
static void test_ptrace_write(void)
{
char data = 1;
+ int mem_fd;
char *mem;
int ret;
ksft_print_msg("[INFO] PTRACE write access\n");
+ mem_fd = open("/proc/self/mem", O_RDWR);
+ if (mem_fd < 0) {
+ ksft_test_result_skip("opening /proc/self/mem failed\n");
+ return;
+ }
+
mem = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE|MAP_ANON, -1, 0);
if (mem == MAP_FAILED) {
ksft_test_result_fail("mmap() failed\n");
@@ -124,10 +130,17 @@ static void test_ptrace_write_thp(void)
char *mem, *mmap_mem;
size_t mmap_size;
char data = 1;
+ int mem_fd;
int ret;
ksft_print_msg("[INFO] PTRACE write access to THP\n");
+ mem_fd = open("/proc/self/mem", O_RDWR);
+ if (mem_fd < 0) {
+ ksft_test_result_skip("opening /proc/self/mem failed\n");
+ return;
+ }
+
mem = mmap_thp_range(PROT_READ, &mmap_mem, &mmap_size);
if (mem == MAP_FAILED)
return;
@@ -343,9 +356,6 @@ int main(void)
ksft_print_header();
ksft_set_plan(tests);
- mem_fd = open("/proc/self/mem", O_RDWR);
- if (mem_fd < 0)
- ksft_exit_fail_msg("opening /proc/self/mem failed\n");
pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
if (pagemap_fd < 0)
ksft_exit_fail_msg("opening /proc/self/pagemap failed\n");
> > Acked-by: David Hildenbrand (Arm) <david@kernel.org>
>
> Thanks.
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] selftests/mm: Specify requirement for PROC_MEM_ALWAYS_FORCE=y
2026-04-16 19:28 ` Mike Rapoport
@ 2026-04-17 2:56 ` Anshuman Khandual
2026-04-17 4:36 ` Dev Jain
2026-04-17 11:24 ` Mark Brown
2 siblings, 0 replies; 10+ messages in thread
From: Anshuman Khandual @ 2026-04-17 2:56 UTC (permalink / raw)
To: Mike Rapoport, Mark Brown
Cc: David Hildenbrand (Arm),
Andrew Morton, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Suren Baghdasaryan, Michal Hocko, Shuah Khan, Aishwarya TCV,
linux-mm, linux-kselftest, linux-kernel
On 17/04/26 12:58 AM, Mike Rapoport wrote:
> On Thu, Apr 16, 2026 at 08:10:53PM +0100, Mark Brown wrote:
>> On Thu, Apr 16, 2026 at 09:05:11PM +0200, David Hildenbrand (Arm) wrote:
>>> On 4/16/26 20:40, Mark Brown wrote:
>>
>>>> Several of the mm selftests made use of /proc/pid/mem as part of their
>>>> operation but we do not specify this in the config fragment for them, at
>>>> least mkdirty and ksm_functional_tests have this requirement.
>>
>>> I guess we could teach most tests to SKIP if /proc/pid/mem is unusable.
>>
>> That would be nicer, yes. I imagine some of these will predate there
>> being a configuration option here at all, it's possible there's newer
>> tests that skip cleanly - I didn't look at the skips.
>
> Enabling access to /proc/pid/mem keeps the coverage, not that it's great
> right now, but still.
>
> But sure graceful skips are better than failing the entire tests. Would be
> something like this:
>
> diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
> index 8d874c4754f3..374b5a25f36d 100644
> --- a/tools/testing/selftests/mm/ksm_functional_tests.c
> +++ b/tools/testing/selftests/mm/ksm_functional_tests.c
> @@ -37,7 +37,6 @@ enum ksm_merge_mode {
> KSM_MERGE_NONE, /* PRCTL already set */
> };
>
> -static int mem_fd;
> static int pages_to_scan_fd;
> static int sleep_millisecs_fd;
> static int pagemap_fd;
> @@ -622,10 +621,17 @@ static void test_prot_none(void)
> {
> const unsigned int size = 2 * MiB;
> char *map;
> + int mem_fd;
> int i;
>
> ksft_print_msg("[RUN] %s\n", __func__);
>
> + mem_fd = open("/proc/self/mem", O_RDWR);
> + if (mem_fd < 0) {
> + ksft_test_result_skip("opening /proc/self/mem failed\n");
> + return;
> + }
> +
> map = mmap_and_merge_range(0x11, size, PROT_NONE, KSM_MERGE_MADVISE);
> if (map == MAP_FAILED)
> goto unmap;
> @@ -694,9 +700,6 @@ static void test_fork_ksm_merging_page_count(void)
>
> static void init_global_file_handles(void)
> {
> - mem_fd = open("/proc/self/mem", O_RDWR);
> - if (mem_fd < 0)
> - ksft_exit_fail_msg("opening /proc/self/mem failed\n");
> if (ksm_stop() < 0)
> ksft_exit_skip("accessing \"/sys/kernel/mm/ksm/run\") failed\n");
> if (ksm_get_full_scans() < 0)
> diff --git a/tools/testing/selftests/mm/mkdirty.c b/tools/testing/selftests/mm/mkdirty.c
> index 68dd447a5454..e4a94638018b 100644
> --- a/tools/testing/selftests/mm/mkdirty.c
> +++ b/tools/testing/selftests/mm/mkdirty.c
> @@ -27,7 +27,6 @@
>
> static size_t pagesize;
> static size_t thpsize;
> -static int mem_fd;
> static int pagemap_fd;
> static sigjmp_buf env;
>
> @@ -86,11 +85,18 @@ static char *mmap_thp_range(int prot, char **_mmap_mem, size_t *_mmap_size)
> static void test_ptrace_write(void)
> {
> char data = 1;
> + int mem_fd;
> char *mem;
> int ret;
>
> ksft_print_msg("[INFO] PTRACE write access\n");
>
> + mem_fd = open("/proc/self/mem", O_RDWR);
> + if (mem_fd < 0) {
> + ksft_test_result_skip("opening /proc/self/mem failed\n");
> + return;
> + }
> +
> mem = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE|MAP_ANON, -1, 0);
> if (mem == MAP_FAILED) {
> ksft_test_result_fail("mmap() failed\n");
> @@ -124,10 +130,17 @@ static void test_ptrace_write_thp(void)
> char *mem, *mmap_mem;
> size_t mmap_size;
> char data = 1;
> + int mem_fd;
> int ret;
>
> ksft_print_msg("[INFO] PTRACE write access to THP\n");
>
> + mem_fd = open("/proc/self/mem", O_RDWR);
> + if (mem_fd < 0) {
> + ksft_test_result_skip("opening /proc/self/mem failed\n");
> + return;
> + }
> +
> mem = mmap_thp_range(PROT_READ, &mmap_mem, &mmap_size);
> if (mem == MAP_FAILED)
> return;
> @@ -343,9 +356,6 @@ int main(void)
> ksft_print_header();
> ksft_set_plan(tests);
>
> - mem_fd = open("/proc/self/mem", O_RDWR);
> - if (mem_fd < 0)
> - ksft_exit_fail_msg("opening /proc/self/mem failed\n");
> pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
> if (pagemap_fd < 0)
> ksft_exit_fail_msg("opening /proc/self/pagemap failed\n");
>
Change LGTM making these tests skip rather gracefully.
>>> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
>>
>> Thanks.
>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] selftests/mm: Specify requirement for PROC_MEM_ALWAYS_FORCE=y
2026-04-16 18:40 [PATCH] selftests/mm: Specify requirement for PROC_MEM_ALWAYS_FORCE=y Mark Brown
2026-04-16 18:56 ` Mike Rapoport
2026-04-16 19:05 ` David Hildenbrand (Arm)
@ 2026-04-17 2:57 ` Anshuman Khandual
2026-04-17 4:37 ` Dev Jain
3 siblings, 0 replies; 10+ messages in thread
From: Anshuman Khandual @ 2026-04-17 2:57 UTC (permalink / raw)
To: Mark Brown, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Shuah Khan
Cc: Aishwarya TCV, linux-mm, linux-kselftest, linux-kernel
On 17/04/26 12:10 AM, Mark Brown wrote:
> Several of the mm selftests made use of /proc/pid/mem as part of their
> operation but we do not specify this in the config fragment for them, at
> least mkdirty and ksm_functional_tests have this requirement.
>
> This has been working fine in practice since PROC_MEM_ALWAYS_FORCE was the
> default setting but commit 599bbba5a36f ("proc: make PROC_MEM_FORCE_PTRACE
> the Kconfig default") that is no longer the case, meaning that tests run
> on kernels built based on defconfigs have started having the new more
> restrictive default and failing. Add PROC_MEM_ALWAYS_FORCE to the config
> fragment for the mm selftests.
>
> Thanks to Aishwarya TCV for spotting the issue and identifying the commit
> that introduced it.
>
> Reported-by: Aishwarya TCV <aishwarya.tcv@arm.com>
> Signed-off-by: Mark Brown <broonie@kernel.org>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
> ---
> tools/testing/selftests/mm/config | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/testing/selftests/mm/config b/tools/testing/selftests/mm/config
> index 1dbe2b4558ab..06f78bd232e2 100644
> --- a/tools/testing/selftests/mm/config
> +++ b/tools/testing/selftests/mm/config
> @@ -13,3 +13,4 @@ CONFIG_PROFILING=y
> CONFIG_UPROBES=y
> CONFIG_MEMORY_FAILURE=y
> CONFIG_HWPOISON_INJECT=m
> +CONFIG_PROC_MEM_ALWAYS_FORCE=y
>
> ---
> base-commit: 599bbba5a36f6de57ab14c373c25881e2b5273f5
> change-id: 20260416-selftests-mm-proc-mem-always-force-5ce1b26022c2
>
> Best regards,
> --
> Mark Brown <broonie@kernel.org>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] selftests/mm: Specify requirement for PROC_MEM_ALWAYS_FORCE=y
2026-04-16 19:28 ` Mike Rapoport
2026-04-17 2:56 ` Anshuman Khandual
@ 2026-04-17 4:36 ` Dev Jain
2026-04-17 11:24 ` Mark Brown
2 siblings, 0 replies; 10+ messages in thread
From: Dev Jain @ 2026-04-17 4:36 UTC (permalink / raw)
To: Mike Rapoport, Mark Brown
Cc: David Hildenbrand (Arm),
Andrew Morton, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Suren Baghdasaryan, Michal Hocko, Shuah Khan, Aishwarya TCV,
linux-mm, linux-kselftest, linux-kernel
On 17/04/26 12:58 am, Mike Rapoport wrote:
> On Thu, Apr 16, 2026 at 08:10:53PM +0100, Mark Brown wrote:
>> On Thu, Apr 16, 2026 at 09:05:11PM +0200, David Hildenbrand (Arm) wrote:
>>> On 4/16/26 20:40, Mark Brown wrote:
>>
>>>> Several of the mm selftests made use of /proc/pid/mem as part of their
>>>> operation but we do not specify this in the config fragment for them, at
>>>> least mkdirty and ksm_functional_tests have this requirement.
>>
>>> I guess we could teach most tests to SKIP if /proc/pid/mem is unusable.
>>
>> That would be nicer, yes. I imagine some of these will predate there
>> being a configuration option here at all, it's possible there's newer
>> tests that skip cleanly - I didn't look at the skips.
>
> Enabling access to /proc/pid/mem keeps the coverage, not that it's great
> right now, but still.
>
> But sure graceful skips are better than failing the entire tests. Would be
> something like this:
>
> diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
> index 8d874c4754f3..374b5a25f36d 100644
> --- a/tools/testing/selftests/mm/ksm_functional_tests.c
> +++ b/tools/testing/selftests/mm/ksm_functional_tests.c
> @@ -37,7 +37,6 @@ enum ksm_merge_mode {
> KSM_MERGE_NONE, /* PRCTL already set */
> };
>
> -static int mem_fd;
> static int pages_to_scan_fd;
> static int sleep_millisecs_fd;
> static int pagemap_fd;
> @@ -622,10 +621,17 @@ static void test_prot_none(void)
> {
> const unsigned int size = 2 * MiB;
> char *map;
> + int mem_fd;
> int i;
>
> ksft_print_msg("[RUN] %s\n", __func__);
>
> + mem_fd = open("/proc/self/mem", O_RDWR);
> + if (mem_fd < 0) {
> + ksft_test_result_skip("opening /proc/self/mem failed\n");
> + return;
> + }
> +
> map = mmap_and_merge_range(0x11, size, PROT_NONE, KSM_MERGE_MADVISE);
> if (map == MAP_FAILED)
> goto unmap;
> @@ -694,9 +700,6 @@ static void test_fork_ksm_merging_page_count(void)
>
> static void init_global_file_handles(void)
> {
> - mem_fd = open("/proc/self/mem", O_RDWR);
> - if (mem_fd < 0)
> - ksft_exit_fail_msg("opening /proc/self/mem failed\n");
> if (ksm_stop() < 0)
> ksft_exit_skip("accessing \"/sys/kernel/mm/ksm/run\") failed\n");
> if (ksm_get_full_scans() < 0)
> diff --git a/tools/testing/selftests/mm/mkdirty.c b/tools/testing/selftests/mm/mkdirty.c
> index 68dd447a5454..e4a94638018b 100644
> --- a/tools/testing/selftests/mm/mkdirty.c
> +++ b/tools/testing/selftests/mm/mkdirty.c
> @@ -27,7 +27,6 @@
>
> static size_t pagesize;
> static size_t thpsize;
> -static int mem_fd;
> static int pagemap_fd;
> static sigjmp_buf env;
>
> @@ -86,11 +85,18 @@ static char *mmap_thp_range(int prot, char **_mmap_mem, size_t *_mmap_size)
> static void test_ptrace_write(void)
> {
> char data = 1;
> + int mem_fd;
> char *mem;
> int ret;
>
> ksft_print_msg("[INFO] PTRACE write access\n");
>
> + mem_fd = open("/proc/self/mem", O_RDWR);
> + if (mem_fd < 0) {
> + ksft_test_result_skip("opening /proc/self/mem failed\n");
> + return;
> + }
> +
> mem = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE|MAP_ANON, -1, 0);
> if (mem == MAP_FAILED) {
> ksft_test_result_fail("mmap() failed\n");
> @@ -124,10 +130,17 @@ static void test_ptrace_write_thp(void)
> char *mem, *mmap_mem;
> size_t mmap_size;
> char data = 1;
> + int mem_fd;
> int ret;
>
> ksft_print_msg("[INFO] PTRACE write access to THP\n");
>
> + mem_fd = open("/proc/self/mem", O_RDWR);
> + if (mem_fd < 0) {
> + ksft_test_result_skip("opening /proc/self/mem failed\n");
> + return;
> + }
> +
> mem = mmap_thp_range(PROT_READ, &mmap_mem, &mmap_size);
> if (mem == MAP_FAILED)
> return;
> @@ -343,9 +356,6 @@ int main(void)
> ksft_print_header();
> ksft_set_plan(tests);
>
> - mem_fd = open("/proc/self/mem", O_RDWR);
> - if (mem_fd < 0)
> - ksft_exit_fail_msg("opening /proc/self/mem failed\n");
> pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
> if (pagemap_fd < 0)
> ksft_exit_fail_msg("opening /proc/self/pagemap failed\n");
Looks fine, but would be better to close the fd before function exit?
I can review if you plan to send a patch : )
>
>>> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
>>
>> Thanks.
>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] selftests/mm: Specify requirement for PROC_MEM_ALWAYS_FORCE=y
2026-04-16 18:40 [PATCH] selftests/mm: Specify requirement for PROC_MEM_ALWAYS_FORCE=y Mark Brown
` (2 preceding siblings ...)
2026-04-17 2:57 ` Anshuman Khandual
@ 2026-04-17 4:37 ` Dev Jain
3 siblings, 0 replies; 10+ messages in thread
From: Dev Jain @ 2026-04-17 4:37 UTC (permalink / raw)
To: Mark Brown, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Shuah Khan
Cc: Aishwarya TCV, linux-mm, linux-kselftest, linux-kernel
On 17/04/26 12:10 am, Mark Brown wrote:
> Several of the mm selftests made use of /proc/pid/mem as part of their
> operation but we do not specify this in the config fragment for them, at
> least mkdirty and ksm_functional_tests have this requirement.
>
> This has been working fine in practice since PROC_MEM_ALWAYS_FORCE was the
> default setting but commit 599bbba5a36f ("proc: make PROC_MEM_FORCE_PTRACE
> the Kconfig default") that is no longer the case, meaning that tests run
> on kernels built based on defconfigs have started having the new more
> restrictive default and failing. Add PROC_MEM_ALWAYS_FORCE to the config
> fragment for the mm selftests.
>
> Thanks to Aishwarya TCV for spotting the issue and identifying the commit
> that introduced it.
>
> Reported-by: Aishwarya TCV <aishwarya.tcv@arm.com>
> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---
Reviewed-by: Dev Jain <dev.jain@arm.com>
> tools/testing/selftests/mm/config | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/testing/selftests/mm/config b/tools/testing/selftests/mm/config
> index 1dbe2b4558ab..06f78bd232e2 100644
> --- a/tools/testing/selftests/mm/config
> +++ b/tools/testing/selftests/mm/config
> @@ -13,3 +13,4 @@ CONFIG_PROFILING=y
> CONFIG_UPROBES=y
> CONFIG_MEMORY_FAILURE=y
> CONFIG_HWPOISON_INJECT=m
> +CONFIG_PROC_MEM_ALWAYS_FORCE=y
>
> ---
> base-commit: 599bbba5a36f6de57ab14c373c25881e2b5273f5
> change-id: 20260416-selftests-mm-proc-mem-always-force-5ce1b26022c2
>
> Best regards,
> --
> Mark Brown <broonie@kernel.org>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] selftests/mm: Specify requirement for PROC_MEM_ALWAYS_FORCE=y
2026-04-16 19:28 ` Mike Rapoport
2026-04-17 2:56 ` Anshuman Khandual
2026-04-17 4:36 ` Dev Jain
@ 2026-04-17 11:24 ` Mark Brown
2 siblings, 0 replies; 10+ messages in thread
From: Mark Brown @ 2026-04-17 11:24 UTC (permalink / raw)
To: Mike Rapoport
Cc: David Hildenbrand (Arm),
Andrew Morton, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Suren Baghdasaryan, Michal Hocko, Shuah Khan, Aishwarya TCV,
linux-mm, linux-kselftest, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1353 bytes --]
On Thu, Apr 16, 2026 at 10:28:29PM +0300, Mike Rapoport wrote:
> But sure graceful skips are better than failing the entire tests. Would be
> something like this:
> @@ -622,10 +621,17 @@ static void test_prot_none(void)
> + mem_fd = open("/proc/self/mem", O_RDWR);
> + if (mem_fd < 0) {
> + ksft_test_result_skip("opening /proc/self/mem failed\n");
> + return;
> + }
> +
The string reported in ksft_test_result_*() is the name of the test, it
should be the same name as is used for pass or fail. This is used to
correlate test results between runs. The error should be logged with a
separate print, in this case ksft_perror() is probably a good choice.
> {
> - mem_fd = open("/proc/self/mem", O_RDWR);
> - if (mem_fd < 0)
> - ksft_exit_fail_msg("opening /proc/self/mem failed\n");
Yes, this is a preexisting bug in the test which I see there are more
instances of :(
> --- a/tools/testing/selftests/mm/mkdirty.c
> +++ b/tools/testing/selftests/mm/mkdirty.c
> static void test_ptrace_write(void)
> {
> char data = 1;
> + int mem_fd;
> char *mem;
> int ret;
>
> ksft_print_msg("[INFO] PTRACE write access\n");
>
> + mem_fd = open("/proc/self/mem", O_RDWR);
> + if (mem_fd < 0) {
> + ksft_test_result_skip("opening /proc/self/mem failed\n");
> + return;
> + }
Same with mkdirty.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-04-17 11:24 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-16 18:40 [PATCH] selftests/mm: Specify requirement for PROC_MEM_ALWAYS_FORCE=y Mark Brown
2026-04-16 18:56 ` Mike Rapoport
2026-04-16 19:05 ` David Hildenbrand (Arm)
2026-04-16 19:10 ` Mark Brown
2026-04-16 19:28 ` Mike Rapoport
2026-04-17 2:56 ` Anshuman Khandual
2026-04-17 4:36 ` Dev Jain
2026-04-17 11:24 ` Mark Brown
2026-04-17 2:57 ` Anshuman Khandual
2026-04-17 4:37 ` Dev Jain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox