Skip to content

Commit 0389c30

Browse files
ioworker0akpm00
authored andcommitted
selftests/mm: skip soft-dirty tests when CONFIG_MEM_SOFT_DIRTY is disabled
The madv_populate and soft-dirty kselftests currently fail on systems where CONFIG_MEM_SOFT_DIRTY is disabled. Introduce a new helper softdirty_supported() into vm_util.c/h to ensure tests are properly skipped when the feature is not enabled. Link: https://lkml.kernel.org/r/20250917133137.62802-1-lance.yang@linux.dev Fixes: 9f3265d ("selftests: vm: add test for Soft-Dirty PTE bit") Signed-off-by: Lance Yang <lance.yang@linux.dev> Acked-by: David Hildenbrand <david@redhat.com> Suggested-by: David Hildenbrand <david@redhat.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Gabriel Krisman Bertazi <krisman@collabora.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 8d009da commit 0389c30

4 files changed

Lines changed: 24 additions & 20 deletions

File tree

tools/testing/selftests/mm/madv_populate.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -264,31 +264,14 @@ static void test_softdirty(void)
264264
munmap(addr, SIZE);
265265
}
266266

267-
static int system_has_softdirty(void)
268-
{
269-
/*
270-
* There is no way to check if the kernel supports soft-dirty, other
271-
* than by writing to a page and seeing if the bit was set. But the
272-
* tests are intended to check that the bit gets set when it should, so
273-
* doing that check would turn a potentially legitimate fail into a
274-
* skip. Fortunately, we know for sure that arm64 does not support
275-
* soft-dirty. So for now, let's just use the arch as a corse guide.
276-
*/
277-
#if defined(__aarch64__)
278-
return 0;
279-
#else
280-
return 1;
281-
#endif
282-
}
283-
284267
int main(int argc, char **argv)
285268
{
286269
int nr_tests = 16;
287270
int err;
288271

289272
pagesize = getpagesize();
290273

291-
if (system_has_softdirty())
274+
if (softdirty_supported())
292275
nr_tests += 5;
293276

294277
ksft_print_header();
@@ -300,7 +283,7 @@ int main(int argc, char **argv)
300283
test_holes();
301284
test_populate_read();
302285
test_populate_write();
303-
if (system_has_softdirty())
286+
if (softdirty_supported())
304287
test_softdirty();
305288

306289
err = ksft_get_fail_cnt();

tools/testing/selftests/mm/soft-dirty.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,11 @@ int main(int argc, char **argv)
200200
int pagesize;
201201

202202
ksft_print_header();
203-
ksft_set_plan(15);
204203

204+
if (!softdirty_supported())
205+
ksft_exit_skip("soft-dirty is not support\n");
206+
207+
ksft_set_plan(15);
205208
pagemap_fd = open(PAGEMAP_FILE_PATH, O_RDONLY);
206209
if (pagemap_fd < 0)
207210
ksft_exit_fail_msg("Failed to open %s\n", PAGEMAP_FILE_PATH);

tools/testing/selftests/mm/vm_util.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,23 @@ bool check_vmflag_pfnmap(void *addr)
449449
return check_vmflag(addr, "pf");
450450
}
451451

452+
bool softdirty_supported(void)
453+
{
454+
char *addr;
455+
bool supported = false;
456+
const size_t pagesize = getpagesize();
457+
458+
/* New mappings are expected to be marked with VM_SOFTDIRTY (sd). */
459+
addr = mmap(0, pagesize, PROT_READ | PROT_WRITE,
460+
MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
461+
if (!addr)
462+
ksft_exit_fail_msg("mmap failed\n");
463+
464+
supported = check_vmflag(addr, "sd");
465+
munmap(addr, pagesize);
466+
return supported;
467+
}
468+
452469
/*
453470
* Open an fd at /proc/$pid/maps and configure procmap_out ready for
454471
* PROCMAP_QUERY query. Returns 0 on success, or an error code otherwise.

tools/testing/selftests/mm/vm_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ bool find_vma_procmap(struct procmap_fd *procmap, void *address);
104104
int close_procmap(struct procmap_fd *procmap);
105105
int write_sysfs(const char *file_path, unsigned long val);
106106
int read_sysfs(const char *file_path, unsigned long *val);
107+
bool softdirty_supported(void);
107108

108109
static inline int open_self_procmap(struct procmap_fd *procmap_out)
109110
{

0 commit comments

Comments
 (0)