Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/mm: reduce uffd-unit-test poison test to minimum

The test will still generate quite some unwanted MCE error messages to
syslog. There was old proposal ratelimiting the MCE messages from kernel,
but that has risk of hiding real useful information on production systems.

We can at least reduce the test to minimum to not over-pollute dmesg,
however trying to not lose its coverage too much.

[peterx@redhat.com: reduce uffd-unit-test poison test to minimum]
Link: https://lkml.kernel.org/r/aF2RSsjuEOtzXcUa@x1.local
Link: https://lkml.kernel.org/r/20250620150058.1729489-1-peterx@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Brendan Jackman <jackmanb@google.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Peter Xu and committed by
Andrew Morton
ab7ed56a 592b939b

+14 -6
+14 -6
tools/testing/selftests/mm/uffd-unit-tests.c
··· 1027 1027 do_uffdio_poison(uffd, offset); 1028 1028 } 1029 1029 1030 + /* Make sure to cover odd/even, and minimum duplications */ 1031 + #define UFFD_POISON_TEST_NPAGES 4 1032 + 1030 1033 static void uffd_poison_test(uffd_test_args_t *targs) 1031 1034 { 1032 1035 pthread_t uffd_mon; ··· 1037 1034 struct uffd_args args = { 0 }; 1038 1035 struct sigaction act = { 0 }; 1039 1036 unsigned long nr_sigbus = 0; 1040 - unsigned long nr; 1037 + unsigned long nr, poison_pages = UFFD_POISON_TEST_NPAGES; 1038 + 1039 + if (nr_pages < poison_pages) { 1040 + uffd_test_skip("Too few pages for POISON test"); 1041 + return; 1042 + } 1041 1043 1042 1044 fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); 1043 1045 1044 - uffd_register_poison(uffd, area_dst, nr_pages * page_size); 1045 - memset(area_src, 0, nr_pages * page_size); 1046 + uffd_register_poison(uffd, area_dst, poison_pages * page_size); 1047 + memset(area_src, 0, poison_pages * page_size); 1046 1048 1047 1049 args.handle_fault = uffd_poison_handle_fault; 1048 1050 if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &args)) ··· 1059 1051 if (sigaction(SIGBUS, &act, 0)) 1060 1052 err("sigaction"); 1061 1053 1062 - for (nr = 0; nr < nr_pages; ++nr) { 1054 + for (nr = 0; nr < poison_pages; ++nr) { 1063 1055 unsigned long offset = nr * page_size; 1064 1056 const char *bytes = (const char *) area_dst + offset; 1065 1057 const char *i; ··· 1086 1078 if (pthread_join(uffd_mon, NULL)) 1087 1079 err("pthread_join()"); 1088 1080 1089 - if (nr_sigbus != nr_pages / 2) 1081 + if (nr_sigbus != poison_pages / 2) 1090 1082 err("expected to receive %lu SIGBUS, actually received %lu", 1091 - nr_pages / 2, nr_sigbus); 1083 + poison_pages / 2, nr_sigbus); 1092 1084 1093 1085 uffd_test_pass(); 1094 1086 }