]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests/mm: skip soft-dirty tests when CONFIG_MEM_SOFT_DIRTY is disabled
authorLance Yang <lance.yang@linux.dev>
Wed, 17 Sep 2025 13:31:37 +0000 (21:31 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 23 Sep 2025 21:14:16 +0000 (14:14 -0700)
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: 9f3265db6ae8 ("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>
tools/testing/selftests/mm/madv_populate.c
tools/testing/selftests/mm/soft-dirty.c
tools/testing/selftests/mm/vm_util.c
tools/testing/selftests/mm/vm_util.h

index b6fabd5c27ed6149630dd994450811b886779445..d8d11bc67ddced25a3ea90cd9caa88bbfb5c7397 100644 (file)
@@ -264,23 +264,6 @@ static void test_softdirty(void)
        munmap(addr, SIZE);
 }
 
-static int system_has_softdirty(void)
-{
-       /*
-        * There is no way to check if the kernel supports soft-dirty, other
-        * than by writing to a page and seeing if the bit was set. But the
-        * tests are intended to check that the bit gets set when it should, so
-        * doing that check would turn a potentially legitimate fail into a
-        * skip. Fortunately, we know for sure that arm64 does not support
-        * soft-dirty. So for now, let's just use the arch as a corse guide.
-        */
-#if defined(__aarch64__)
-       return 0;
-#else
-       return 1;
-#endif
-}
-
 int main(int argc, char **argv)
 {
        int nr_tests = 16;
@@ -288,7 +271,7 @@ int main(int argc, char **argv)
 
        pagesize = getpagesize();
 
-       if (system_has_softdirty())
+       if (softdirty_supported())
                nr_tests += 5;
 
        ksft_print_header();
@@ -300,7 +283,7 @@ int main(int argc, char **argv)
        test_holes();
        test_populate_read();
        test_populate_write();
-       if (system_has_softdirty())
+       if (softdirty_supported())
                test_softdirty();
 
        err = ksft_get_fail_cnt();
index 8a3f2b4b218698775313c5ca4ea7003482446043..4ee4db3750c16c63c301f0bafa2b7e35e4c9c365 100644 (file)
@@ -200,8 +200,11 @@ int main(int argc, char **argv)
        int pagesize;
 
        ksft_print_header();
-       ksft_set_plan(15);
 
+       if (!softdirty_supported())
+               ksft_exit_skip("soft-dirty is not support\n");
+
+       ksft_set_plan(15);
        pagemap_fd = open(PAGEMAP_FILE_PATH, O_RDONLY);
        if (pagemap_fd < 0)
                ksft_exit_fail_msg("Failed to open %s\n", PAGEMAP_FILE_PATH);
index 56e9bd541edd556f6b4a64e48b0c7dbfe684f211..e33cda301dada08afcb3c1e47894c5eb18c5fd58 100644 (file)
@@ -449,6 +449,23 @@ bool check_vmflag_pfnmap(void *addr)
        return check_vmflag(addr, "pf");
 }
 
+bool softdirty_supported(void)
+{
+       char *addr;
+       bool supported = false;
+       const size_t pagesize = getpagesize();
+
+       /* New mappings are expected to be marked with VM_SOFTDIRTY (sd). */
+       addr = mmap(0, pagesize, PROT_READ | PROT_WRITE,
+                   MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
+       if (!addr)
+               ksft_exit_fail_msg("mmap failed\n");
+
+       supported = check_vmflag(addr, "sd");
+       munmap(addr, pagesize);
+       return supported;
+}
+
 /*
  * Open an fd at /proc/$pid/maps and configure procmap_out ready for
  * PROCMAP_QUERY query. Returns 0 on success, or an error code otherwise.
index 07c4acfd84b62d571bbef23e5666d17225c3dccc..26c30fdc02415991a909b4d933070e89c1a8112d 100644 (file)
@@ -104,6 +104,7 @@ bool find_vma_procmap(struct procmap_fd *procmap, void *address);
 int close_procmap(struct procmap_fd *procmap);
 int write_sysfs(const char *file_path, unsigned long val);
 int read_sysfs(const char *file_path, unsigned long *val);
+bool softdirty_supported(void);
 
 static inline int open_self_procmap(struct procmap_fd *procmap_out)
 {