Skip to content

Commit e986260

Browse files
vt-altroxanan1996
authored andcommitted
selftests/mm: Fix build with _FORTIFY_SOURCE
BugLink: https://bugs.launchpad.net/bugs/2060531 [ Upstream commit 8b65ef5ad4862904e476a8f3d4e4418c950ddb90 ] Add missing flags argument to open(2) call with O_CREAT. Some tests fail to compile if _FORTIFY_SOURCE is defined (to any valid value) (together with -O), resulting in similar error messages such as: In file included from /usr/include/fcntl.h:342, from gup_test.c:1: In function 'open', inlined from 'main' at gup_test.c:206:10: /usr/include/bits/fcntl2.h:50:11: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments 50 | __open_missing_mode (); | ^~~~~~~~~~~~~~~~~~~~~~ _FORTIFY_SOURCE is enabled by default in some distributions, so the tests are not built by default and are skipped. open(2) man-page warns about missing flags argument: "if it is not supplied, some arbitrary bytes from the stack will be applied as the file mode." Link: https://lkml.kernel.org/r/20240318023445.3192922-1-vt@altlinux.org Fixes: aeb85ed ("tools/testing/selftests/vm/gup_benchmark.c: allow user specified file") Fixes: fbe3750 ("mm: huge_memory: debugfs for file-backed THP split") Fixes: c942f5b ("selftests: soft-dirty: add test for mprotect") Signed-off-by: Vitaly Chikunov <vt@altlinux.org> Reviewed-by: Zi Yan <ziy@nvidia.com> Reviewed-by: David Hildenbrand <david@redhat.com> Cc: Keith Busch <kbusch@kernel.org> Cc: Peter Xu <peterx@redhat.com> Cc: Yang Shi <shy828301@gmail.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Nadav Amit <nadav.amit@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
1 parent cca74a5 commit e986260

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

tools/testing/selftests/mm/gup_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ int main(int argc, char **argv)
203203
ksft_print_header();
204204
ksft_set_plan(nthreads);
205205

206-
filed = open(file, O_RDWR|O_CREAT);
206+
filed = open(file, O_RDWR|O_CREAT, 0664);
207207
if (filed < 0)
208208
ksft_exit_fail_msg("Unable to open %s: %s\n", file, strerror(errno));
209209

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static void test_mprotect(int pagemap_fd, int pagesize, bool anon)
137137
if (!map)
138138
ksft_exit_fail_msg("anon mmap failed\n");
139139
} else {
140-
test_fd = open(fname, O_RDWR | O_CREAT);
140+
test_fd = open(fname, O_RDWR | O_CREAT, 0664);
141141
if (test_fd < 0) {
142142
ksft_test_result_skip("Test %s open() file failed\n", __func__);
143143
return;

tools/testing/selftests/mm/split_huge_page_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ void split_file_backed_thp(void)
253253
goto cleanup;
254254
}
255255

256-
fd = open(testfile, O_CREAT|O_WRONLY);
256+
fd = open(testfile, O_CREAT|O_WRONLY, 0664);
257257
if (fd == -1) {
258258
perror("Cannot open testing file\n");
259259
goto cleanup;

0 commit comments

Comments
 (0)