Skip to contentSkip to conversation

cleanups, fixes, and progress towards avoiding "make headers"

PATCH Superseded John Hubbard 5 participants 25 messages Jun 14, 2024 – Feb 13, 2025

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover cleanups, fixes, and progress towards avoiding "make headers"

Jeff Xu, I apologize for this churn: I was forced to drop your Reviewed-by and Tested-by tags from 2 of the 3 mseal patches, because the __NR_mseal fix is completely different now.

Changes since v1:

a) Reworked the mseal fix to use the kernel's in-tree unistd*.h files, instead of hacking in a __NR_mseal definition directly. (Thanks to David Hildenbrand for pointing out that this needed to be done.)

b) Fixed the subject line of the kvm and mdwe patch.

c) Reordered the patches so as to group the mseal changes together.

d) ADDED an additional patch, 6/6, to remove various __NR_xx items and checks from the mm selftests.

Cover letter, updated for v2:

Eventually, once the build succeeds on a sufficiently old distro, the idea is to delete $(KHDR_INCLUDES) from the selftests/mm build, and then after that, from selftests/lib.mk and all of the other selftest builds.

For now, this series merely achieves a clean build of selftests/mm on a not-so-old distro: Ubuntu 23.04. In other words, after this series is applied, it is possible to delete $(KHDR_INCLUDES) from selftests/mm/Makefile and the build will still succeed.

1. Add tools/uapi/asm/unistd_[32|x32|64].h files, which include definitions of __NR_mseal, and include them (indirectly) from the files that use __NR_mseal. The new files are copied from ./usr/include/asm, which is how we have agreed to do this sort of thing, see [1].

2. Add fs.h, similarly created: it was copied directly from a snapshot of ./usr/include/linux/fs.h after running "make headers".

3. Add a few selected prctl.h values that the ksm and mdwe tests require.

4. Factor out some common code from mseal_test.c and seal_elf.c, into a new mseal_helpers.h file.

5. Remove local __NR_* definitions and checks.

[1] commit e076eaca5906 ("selftests: break the dependency upon local header files")

John Hubbard (6):
selftests/mm: mseal, self_elf: fix missing __NR_mseal selftests/mm: mseal, self_elf: factor out test macros and other
duplicated items
selftests/mm: mseal, self_elf: rename TEST_END_CHECK to
REPORT_TEST_PASS
selftests/mm: fix vm_util.c build failures: add snapshot of fs.h selftests/mm: kvm, mdwe fixes to avoid requiring "make headers" selftests/mm: remove local __NR_* definitions

 tools/include/uapi/asm/unistd_32.h            | 458 ++++++++++++++++++
 tools/include/uapi/asm/unistd_64.h            | 380 +++++++++++++++
 tools/include/uapi/asm/unistd_x32.h           | 369 ++++++++++++++
 tools/include/uapi/linux/fs.h                 | 392 +++++++++++++++
 tools/testing/selftests/mm/hugepage-mremap.c  |   2 +-
 .../selftests/mm/ksm_functional_tests.c       |   8 +-
 tools/testing/selftests/mm/mdwe_test.c        |   1 +
 tools/testing/selftests/mm/memfd_secret.c     |  14 +-
 tools/testing/selftests/mm/mkdirty.c          |   8 +-
 tools/testing/selftests/mm/mlock2.h           |   1 +
 tools/testing/selftests/mm/mrelease_test.c    |   2 +-
 tools/testing/selftests/mm/mseal_helpers.h    |  41 ++
 tools/testing/selftests/mm/mseal_test.c       | 143 ++----
 tools/testing/selftests/mm/pagemap_ioctl.c    |   2 +-
 tools/testing/selftests/mm/protection_keys.c  |   2 +-
 tools/testing/selftests/mm/seal_elf.c         |  37 +-
 tools/testing/selftests/mm/uffd-common.c      |   4 -
 tools/testing/selftests/mm/uffd-stress.c      |  16 +-
 tools/testing/selftests/mm/uffd-unit-tests.c  |  14 +-
 tools/testing/selftests/mm/vm_util.h          |  15 +
 20 files changed, 1717 insertions(+), 192 deletions(-)
 create mode 100644 tools/include/uapi/asm/unistd_32.h
 create mode 100644 tools/include/uapi/asm/unistd_64.h
 create mode 100644 tools/include/uapi/asm/unistd_x32.h
 create mode 100644 tools/include/uapi/linux/fs.h
 create mode 100644 tools/testing/selftests/mm/mseal_helpers.h

base-commit: 2ccbdf43d5e758f8493a95252073cf9078a5fea5

Signature · 1 line
2.45.2
#1 lore raw

PATCH v2 1/6 selftests/mm: mseal, self_elf: fix missing __NR_mseal

The selftests/mm build isn't exactly "broken", according to the current documentation, which still claims that one must run "make headers", before building the kselftests. However, according to the new plan to get rid of that requirement [1], they are future-broken: attempting to build selftests/mm *without* first running "make headers" will fail due to not finding __NR_mseal.

Therefore, add ./usr/include/asm/unistd_[32|x32|64].h (created via "make headers") to tools/uapi/, and change the selftests/mm files that require __NR_mseal to include from the correct location. The way to do so is to include <linux/unistd.h> instead of just <unistd.h>.

[1] commit e076eaca5906 ("selftests: break the dependency upon local header files")

Fixes 4926c7a52de7 ("selftest mm/mseal memory sealing")
Cc Jeff Xu <[email protected]>
Cc David Hildenbrand <[email protected]>
---
 tools/include/uapi/asm/unistd_32.h      | 458 ++++++++++++++++++++++++
 tools/include/uapi/asm/unistd_64.h      | 380 ++++++++++++++++++++
 tools/include/uapi/asm/unistd_x32.h     | 369 +++++++++++++++++++
 tools/testing/selftests/mm/mseal_test.c |   2 +-
 tools/testing/selftests/mm/seal_elf.c   |   2 +-
 5 files changed, 1209 insertions(+), 2 deletions(-)
 create mode 100644 tools/include/uapi/asm/unistd_32.h
 create mode 100644 tools/include/uapi/asm/unistd_64.h
 create mode 100644 tools/include/uapi/asm/unistd_x32.h
tools/include/uapi/asm/unistd_32.h new file +458 -0
new file mode 100644
index 000000000000..fb7b8b169bfa
@@ -0,0 +1,458 @@
+#ifndef _ASM_UNISTD_32_H
+#define _ASM_UNISTD_32_H
+
+#define __NR_restart_syscall 0
+#define __NR_exit 1
+#define __NR_fork 2
+#define __NR_read 3
+#define __NR_write 4
+#define __NR_open 5
+#define __NR_close 6
+#define __NR_waitpid 7
+#define __NR_creat 8
+#define __NR_link 9
+#define __NR_unlink 10
+#define __NR_execve 11
+#define __NR_chdir 12
+#define __NR_time 13
+#define __NR_mknod 14
+#define __NR_chmod 15
+#define __NR_lchown 16
+#define __NR_break 17
+#define __NR_oldstat 18
+#define __NR_lseek 19
+#define __NR_getpid 20
+#define __NR_mount 21
+#define __NR_umount 22
+#define __NR_setuid 23
+#define __NR_getuid 24
+#define __NR_stime 25
+#define __NR_ptrace 26
+#define __NR_alarm 27
+#define __NR_oldfstat 28
+#define __NR_pause 29
+#define __NR_utime 30
+#define __NR_stty 31
+#define __NR_gtty 32
+#define __NR_access 33
+#define __NR_nice 34
+#define __NR_ftime 35
+#define __NR_sync 36
+#define __NR_kill 37
+#define __NR_rename 38
+#define __NR_mkdir 39
+#define __NR_rmdir 40
+#define __NR_dup 41
+#define __NR_pipe 42
+#define __NR_times 43
+#define __NR_prof 44
+#define __NR_brk 45
+#define __NR_setgid 46
+#define __NR_getgid 47
+#define __NR_signal 48
+#define __NR_geteuid 49
+#define __NR_getegid 50
+#define __NR_acct 51
+#define __NR_umount2 52
+#define __NR_lock 53
+#define __NR_ioctl 54
+#define __NR_fcntl 55
+#define __NR_mpx 56
+#define __NR_setpgid 57
+#define __NR_ulimit 58
+#define __NR_oldolduname 59
+#define __NR_umask 60
+#define __NR_chroot 61
+#define __NR_ustat 62
+#define __NR_dup2 63
+#define __NR_getppid 64
+#define __NR_getpgrp 65
+#define __NR_setsid 66
+#define __NR_sigaction 67
+#define __NR_sgetmask 68
+#define __NR_ssetmask 69
+#define __NR_setreuid 70
+#define __NR_setregid 71
+#define __NR_sigsuspend 72
+#define __NR_sigpending 73
+#define __NR_sethostname 74
+#define __NR_setrlimit 75
+#define __NR_getrlimit 76
+#define __NR_getrusage 77
+#define __NR_gettimeofday 78
+#define __NR_settimeofday 79
+#define __NR_getgroups 80
+#define __NR_setgroups 81
+#define __NR_select 82
+#define __NR_symlink 83
+#define __NR_oldlstat 84
+#define __NR_readlink 85
+#define __NR_uselib 86
+#define __NR_swapon 87
+#define __NR_reboot 88
+#define __NR_readdir 89
+#define __NR_mmap 90
+#define __NR_munmap 91
+#define __NR_truncate 92
+#define __NR_ftruncate 93
+#define __NR_fchmod 94
+#define __NR_fchown 95
+#define __NR_getpriority 96
+#define __NR_setpriority 97
+#define __NR_profil 98
+#define __NR_statfs 99
+#define __NR_fstatfs 100
+#define __NR_ioperm 101
+#define __NR_socketcall 102
+#define __NR_syslog 103
+#define __NR_setitimer 104
+#define __NR_getitimer 105
+#define __NR_stat 106
+#define __NR_lstat 107
+#define __NR_fstat 108
+#define __NR_olduname 109
+#define __NR_iopl 110
+#define __NR_vhangup 111
+#define __NR_idle 112
+#define __NR_vm86old 113
+#define __NR_wait4 114
+#define __NR_swapoff 115
+#define __NR_sysinfo 116
+#define __NR_ipc 117
+#define __NR_fsync 118
+#define __NR_sigreturn 119
+#define __NR_clone 120
+#define __NR_setdomainname 121
+#define __NR_uname 122
+#define __NR_modify_ldt 123
+#define __NR_adjtimex 124
+#define __NR_mprotect 125
+#define __NR_sigprocmask 126
+#define __NR_create_module 127
+#define __NR_init_module 128
+#define __NR_delete_module 129
+#define __NR_get_kernel_syms 130
+#define __NR_quotactl 131
+#define __NR_getpgid 132
+#define __NR_fchdir 133
+#define __NR_bdflush 134
+#define __NR_sysfs 135
+#define __NR_personality 136
+#define __NR_afs_syscall 137
+#define __NR_setfsuid 138
+#define __NR_setfsgid 139
+#define __NR__llseek 140
+#define __NR_getdents 141
+#define __NR__newselect 142
+#define __NR_flock 143
+#define __NR_msync 144
+#define __NR_readv 145
+#define __NR_writev 146
+#define __NR_getsid 147
+#define __NR_fdatasync 148
+#define __NR__sysctl 149
+#define __NR_mlock 150
+#define __NR_munlock 151
+#define __NR_mlockall 152
+#define __NR_munlockall 153
+#define __NR_sched_setparam 154
+#define __NR_sched_getparam 155
+#define __NR_sched_setscheduler 156
+#define __NR_sched_getscheduler 157
+#define __NR_sched_yield 158
+#define __NR_sched_get_priority_max 159
+#define __NR_sched_get_priority_min 160
+#define __NR_sched_rr_get_interval 161
+#define __NR_nanosleep 162
+#define __NR_mremap 163
+#define __NR_setresuid 164
+#define __NR_getresuid 165
+#define __NR_vm86 166
+#define __NR_query_module 167
+#define __NR_poll 168
+#define __NR_nfsservctl 169
+#define __NR_setresgid 170
+#define __NR_getresgid 171
+#define __NR_prctl 172
+#define __NR_rt_sigreturn 173
+#define __NR_rt_sigaction 174
+#define __NR_rt_sigprocmask 175
+#define __NR_rt_sigpending 176
+#define __NR_rt_sigtimedwait 177
+#define __NR_rt_sigqueueinfo 178
+#define __NR_rt_sigsuspend 179
+#define __NR_pread64 180
+#define __NR_pwrite64 181
+#define __NR_chown 182
+#define __NR_getcwd 183
+#define __NR_capget 184
+#define __NR_capset 185
+#define __NR_sigaltstack 186
+#define __NR_sendfile 187
+#define __NR_getpmsg 188
+#define __NR_putpmsg 189
+#define __NR_vfork 190
+#define __NR_ugetrlimit 191
+#define __NR_mmap2 192
+#define __NR_truncate64 193
+#define __NR_ftruncate64 194
+#define __NR_stat64 195
+#define __NR_lstat64 196
+#define __NR_fstat64 197
+#define __NR_lchown32 198
+#define __NR_getuid32 199
+#define __NR_getgid32 200
+#define __NR_geteuid32 201
+#define __NR_getegid32 202
+#define __NR_setreuid32 203
+#define __NR_setregid32 204
+#define __NR_getgroups32 205
+#define __NR_setgroups32 206
+#define __NR_fchown32 207
+#define __NR_setresuid32 208
+#define __NR_getresuid32 209
+#define __NR_setresgid32 210
+#define __NR_getresgid32 211
+#define __NR_chown32 212
+#define __NR_setuid32 213
+#define __NR_setgid32 214
+#define __NR_setfsuid32 215
+#define __NR_setfsgid32 216
+#define __NR_pivot_root 217
+#define __NR_mincore 218
+#define __NR_madvise 219
+#define __NR_getdents64 220
+#define __NR_fcntl64 221
+#define __NR_gettid 224
+#define __NR_readahead 225
+#define __NR_setxattr 226
+#define __NR_lsetxattr 227
+#define __NR_fsetxattr 228
+#define __NR_getxattr 229
+#define __NR_lgetxattr 230
+#define __NR_fgetxattr 231
+#define __NR_listxattr 232
+#define __NR_llistxattr 233
+#define __NR_flistxattr 234
+#define __NR_removexattr 235
+#define __NR_lremovexattr 236
+#define __NR_fremovexattr 237
+#define __NR_tkill 238
+#define __NR_sendfile64 239
+#define __NR_futex 240
+#define __NR_sched_setaffinity 241
+#define __NR_sched_getaffinity 242
+#define __NR_set_thread_area 243
+#define __NR_get_thread_area 244
+#define __NR_io_setup 245
+#define __NR_io_destroy 246
+#define __NR_io_getevents 247
+#define __NR_io_submit 248
+#define __NR_io_cancel 249
+#define __NR_fadvise64 250
+#define __NR_exit_group 252
+#define __NR_lookup_dcookie 253
+#define __NR_epoll_create 254
+#define __NR_epoll_ctl 255
+#define __NR_epoll_wait 256
+#define __NR_remap_file_pages 257
+#define __NR_set_tid_address 258
+#define __NR_timer_create 259
+#define __NR_timer_settime 260
+#define __NR_timer_gettime 261
+#define __NR_timer_getoverrun 262
+#define __NR_timer_delete 263
+#define __NR_clock_settime 264
+#define __NR_clock_gettime 265
+#define __NR_clock_getres 266
+#define __NR_clock_nanosleep 267
+#define __NR_statfs64 268
+#define __NR_fstatfs64 269
+#define __NR_tgkill 270
+#define __NR_utimes 271
+#define __NR_fadvise64_64 272
+#define __NR_vserver 273
+#define __NR_mbind 274
+#define __NR_get_mempolicy 275
+#define __NR_set_mempolicy 276
+#define __NR_mq_open 277
+#define __NR_mq_unlink 278
+#define __NR_mq_timedsend 279
+#define __NR_mq_timedreceive 280
+#define __NR_mq_notify 281
+#define __NR_mq_getsetattr 282
+#define __NR_kexec_load 283
+#define __NR_waitid 284
+#define __NR_add_key 286
+#define __NR_request_key 287
+#define __NR_keyctl 288
+#define __NR_ioprio_set 289
+#define __NR_ioprio_get 290
+#define __NR_inotify_init 291
+#define __NR_inotify_add_watch 292
+#define __NR_inotify_rm_watch 293
+#define __NR_migrate_pages 294
+#define __NR_openat 295
+#define __NR_mkdirat 296
+#define __NR_mknodat 297
+#define __NR_fchownat 298
+#define __NR_futimesat 299
+#define __NR_fstatat64 300
+#define __NR_unlinkat 301
+#define __NR_renameat 302
+#define __NR_linkat 303
+#define __NR_symlinkat 304
+#define __NR_readlinkat 305
+#define __NR_fchmodat 306
+#define __NR_faccessat 307
+#define __NR_pselect6 308
+#define __NR_ppoll 309
+#define __NR_unshare 310
+#define __NR_set_robust_list 311
+#define __NR_get_robust_list 312
+#define __NR_splice 313
+#define __NR_sync_file_range 314
+#define __NR_tee 315
+#define __NR_vmsplice 316
+#define __NR_move_pages 317
+#define __NR_getcpu 318
+#define __NR_epoll_pwait 319
+#define __NR_utimensat 320
+#define __NR_signalfd 321
+#define __NR_timerfd_create 322
+#define __NR_eventfd 323
+#define __NR_fallocate 324
+#define __NR_timerfd_settime 325
+#define __NR_timerfd_gettime 326
+#define __NR_signalfd4 327
+#define __NR_eventfd2 328
+#define __NR_epoll_create1 329
+#define __NR_dup3 330
+#define __NR_pipe2 331
+#define __NR_inotify_init1 332
+#define __NR_preadv 333
+#define __NR_pwritev 334
+#define __NR_rt_tgsigqueueinfo 335
+#define __NR_perf_event_open 336
+#define __NR_recvmmsg 337
+#define __NR_fanotify_init 338
+#define __NR_fanotify_mark 339
+#define __NR_prlimit64 340
+#define __NR_name_to_handle_at 341
+#define __NR_open_by_handle_at 342
+#define __NR_clock_adjtime 343
+#define __NR_syncfs 344
+#define __NR_sendmmsg 345
+#define __NR_setns 346
+#define __NR_process_vm_readv 347
+#define __NR_process_vm_writev 348
+#define __NR_kcmp 349
+#define __NR_finit_module 350
+#define __NR_sched_setattr 351
+#define __NR_sched_getattr 352
+#define __NR_renameat2 353
+#define __NR_seccomp 354
+#define __NR_getrandom 355
+#define __NR_memfd_create 356
+#define __NR_bpf 357
+#define __NR_execveat 358
+#define __NR_socket 359
+#define __NR_socketpair 360
+#define __NR_bind 361
+#define __NR_connect 362
+#define __NR_listen 363
+#define __NR_accept4 364
+#define __NR_getsockopt 365
+#define __NR_setsockopt 366
+#define __NR_getsockname 367
+#define __NR_getpeername 368
+#define __NR_sendto 369
+#define __NR_sendmsg 370
+#define __NR_recvfrom 371
+#define __NR_recvmsg 372
+#define __NR_shutdown 373
+#define __NR_userfaultfd 374
+#define __NR_membarrier 375
+#define __NR_mlock2 376
+#define __NR_copy_file_range 377
+#define __NR_preadv2 378
+#define __NR_pwritev2 379
+#define __NR_pkey_mprotect 380
+#define __NR_pkey_alloc 381
+#define __NR_pkey_free 382
+#define __NR_statx 383
+#define __NR_arch_prctl 384
+#define __NR_io_pgetevents 385
+#define __NR_rseq 386
+#define __NR_semget 393
+#define __NR_semctl 394
+#define __NR_shmget 395
+#define __NR_shmctl 396
+#define __NR_shmat 397
+#define __NR_shmdt 398
+#define __NR_msgget 399
+#define __NR_msgsnd 400
+#define __NR_msgrcv 401
+#define __NR_msgctl 402
+#define __NR_clock_gettime64 403
+#define __NR_clock_settime64 404
+#define __NR_clock_adjtime64 405
+#define __NR_clock_getres_time64 406
+#define __NR_clock_nanosleep_time64 407
+#define __NR_timer_gettime64 408
+#define __NR_timer_settime64 409
+#define __NR_timerfd_gettime64 410
+#define __NR_timerfd_settime64 411
+#define __NR_utimensat_time64 412
+#define __NR_pselect6_time64 413
+#define __NR_ppoll_time64 414
+#define __NR_io_pgetevents_time64 416
+#define __NR_recvmmsg_time64 417
+#define __NR_mq_timedsend_time64 418
+#define __NR_mq_timedreceive_time64 419
+#define __NR_semtimedop_time64 420
+#define __NR_rt_sigtimedwait_time64 421
+#define __NR_futex_time64 422
+#define __NR_sched_rr_get_interval_time64 423
+#define __NR_pidfd_send_signal 424
+#define __NR_io_uring_setup 425
+#define __NR_io_uring_enter 426
+#define __NR_io_uring_register 427
+#define __NR_open_tree 428
+#define __NR_move_mount 429
+#define __NR_fsopen 430
+#define __NR_fsconfig 431
+#define __NR_fsmount 432
+#define __NR_fspick 433
+#define __NR_pidfd_open 434
+#define __NR_clone3 435
+#define __NR_close_range 436
+#define __NR_openat2 437
+#define __NR_pidfd_getfd 438
+#define __NR_faccessat2 439
+#define __NR_process_madvise 440
+#define __NR_epoll_pwait2 441
+#define __NR_mount_setattr 442
+#define __NR_quotactl_fd 443
+#define __NR_landlock_create_ruleset 444
+#define __NR_landlock_add_rule 445
+#define __NR_landlock_restrict_self 446
+#define __NR_memfd_secret 447
+#define __NR_process_mrelease 448
+#define __NR_futex_waitv 449
+#define __NR_set_mempolicy_home_node 450
+#define __NR_cachestat 451
+#define __NR_fchmodat2 452
+#define __NR_map_shadow_stack 453
+#define __NR_futex_wake 454
+#define __NR_futex_wait 455
+#define __NR_futex_requeue 456
+#define __NR_statmount 457
+#define __NR_listmount 458
+#define __NR_lsm_get_self_attr 459
+#define __NR_lsm_set_self_attr 460
+#define __NR_lsm_list_modules 461
+#define __NR_mseal 462
+
+
+#endif /* _ASM_UNISTD_32_H */
tools/include/uapi/asm/unistd_64.h new file +380 -0

380 lines not on this page · raw message

tools/include/uapi/asm/unistd_x32.h new file +369 -0

369 lines not on this page · raw message

tools/testing/selftests/mm/mseal_test.c +1 -1
index 41998cf1dcf5..b65bc20c04fc 100644
@@ -3,7 +3,7 @@
 #include <linux/mman.h>
 #include <sys/mman.h>
 #include <stdint.h>
-#include <unistd.h>
+#include <linux/unistd.h>
 #include <string.h>
 #include <sys/time.h>
 #include <sys/resource.h>
tools/testing/selftests/mm/seal_elf.c +1 -1
index f2babec79bb6..6212434bd6e3 100644
@@ -2,7 +2,7 @@
 #define _GNU_SOURCE
 #include <sys/mman.h>
 #include <stdint.h>
-#include <unistd.h>
+#include <linux/unistd.h>
 #include <string.h>
 #include <sys/time.h>
 #include <sys/resource.h>
Signature · 1 line
2.45.2
Acked-by on v2 1/6
#2 lore raw

Re: [PATCH v2 1/6] selftests/mm: mseal, self_elf: fix missing __NR_mseal

Quoted 12 lines · John Hubbard

The selftests/mm build isn't exactly "broken", according to the current documentation, which still claims that one must run "make headers", before building the kselftests. However, according to the new plan to get rid of that requirement [1], they are future-broken: attempting to build selftests/mm *without* first running "make headers" will fail due to not finding __NR_mseal.

Therefore, add ./usr/include/asm/unistd_[32|x32|64].h (created via "make headers") to tools/uapi/, and change the selftests/mm files that require __NR_mseal to include from the correct location. The way to do so is to include <linux/unistd.h> instead of just <unistd.h>.

Quoted 8 lines

[1] commit e076eaca5906 ("selftests: break the dependency upon local header files")

Fixes 4926c7a52de7 ("selftest mm/mseal memory sealing")
Cc Jeff Xu <[email protected]>
Cc David Hildenbrand <[email protected]>

---

If it works, great

Signature · 3 lines
Cheers,

David / dhildenb
#3 lore raw

Re: [PATCH v2 1/6] selftests/mm: mseal, self_elf: fix missing __NR_mseal

Quoted 16 lines · David Hildenbrand
Quoted 15 lines · John Hubbard

The selftests/mm build isn't exactly "broken", according to the current documentation, which still claims that one must run "make headers", before building the kselftests. However, according to the new plan to get rid of that requirement [1], they are future-broken: attempting to build selftests/mm *without* first running "make headers" will fail due to not finding __NR_mseal.

Therefore, add ./usr/include/asm/unistd_[32|x32|64].h (created via "make headers") to tools/uapi/, and change the selftests/mm files that require __NR_mseal to include from the correct location. The way to do so is to include <linux/unistd.h> instead of just <unistd.h>.

[1] commit e076eaca5906 ("selftests: break the dependency upon local header files")

Quoted 7 lines
Quoted 5 lines
Fixes 4926c7a52de7 ("selftest mm/mseal memory sealing")
Cc Jeff Xu <[email protected]>
Cc David Hildenbrand <[email protected]>

---

If it works, great

... thinking again, are some of these headers arch-specific (IOW, generating them per-arch would result in something slightly different)?

In tools/include/uapi/asm-generic/unistd.h, we already do have __NR_mseal ...

Signature · 3 lines
Cheers,

David / dhildenb
#4 lore raw

Re: [PATCH v2 1/6] selftests/mm: mseal, self_elf: fix missing __NR_mseal

Quoted 23 lines · David Hildenbrand
Quoted 22 lines · David Hildenbrand
Quoted 20 lines · John Hubbard

The selftests/mm build isn't exactly "broken", according to the current documentation, which still claims that one must run "make headers", before building the kselftests. However, according to the new plan to get rid of that requirement [1], they are future-broken: attempting to build selftests/mm *without* first running "make headers" will fail due to not finding __NR_mseal.

Therefore,  add ./usr/include/asm/unistd_[32|x32|64].h (created via "make headers") to tools/uapi/, and change the selftests/mm files that require __NR_mseal to include from the correct location. The way to do so is to include <linux/unistd.h> instead of just <unistd.h>.

[1] commit e076eaca5906 ("selftests: break the dependency upon local header files")

Fixes 4926c7a52de7 ("selftest mm/mseal memory sealing")
Cc Jeff Xu <[email protected]>
Cc David Hildenbrand <[email protected]>

---

Quoted 3 lines
Quoted 1 line

If it works, great

... thinking again, are some of these headers arch-specific (IOW, generating them per-arch would result in something slightly different)?

Oh wow, yes they are. I'm guilty of x86-centric thinking (again).

hmm, this is going to make it really a lot of trouble to do this approach. But there's no point in turning back now, so I guess I'd better fire up the cross-compilers and generate for all the arches.

Quoted 2 lines

In tools/include/uapi/asm-generic/unistd.h, we already do have __NR_mseal ...

Yes, but it doesn't get used in selftests/mm, with the way headers are set up right now.

thanks,

Signature · 2 lines
John Hubbard
NVIDIA
#5 lore raw

Re: [PATCH v2 1/6] selftests/mm: mseal, self_elf: fix missing __NR_mseal

Quoted 26 lines · John Hubbard
Quoted 25 lines · David Hildenbrand
Quoted 23 lines · David Hildenbrand
Quoted 12 lines · John Hubbard

The selftests/mm build isn't exactly "broken", according to the current documentation, which still claims that one must run "make headers", before building the kselftests. However, according to the new plan to get rid of that requirement [1], they are future-broken: attempting to build selftests/mm *without* first running "make headers" will fail due to not finding __NR_mseal.

Therefore,  add ./usr/include/asm/unistd_[32|x32|64].h (created via "make headers") to tools/uapi/, and change the selftests/mm files that require __NR_mseal to include from the correct location. The way to do so is to include <linux/unistd.h> instead of just <unistd.h>.

Quoted 8 lines

[1] commit e076eaca5906 ("selftests: break the dependency upon local header files")

Fixes 4926c7a52de7 ("selftest mm/mseal memory sealing")
Cc Jeff Xu <[email protected]>
Cc David Hildenbrand <[email protected]>

---

If it works, great

Quoted 9 lines
Quoted 2 lines

... thinking again, are some of these headers arch-specific (IOW, generating them per-arch would result in something slightly different)?

Oh wow, yes they are. I'm guilty of x86-centric thinking (again).

hmm, this is going to make it really a lot of trouble to do this approach. But there's no point in turning back now, so I guess I'd better fire up the cross-compilers and generate for all the arches.

Cross compilers might not be required.

At least for me, at simple

rm -rf usr/include
export ARCH=s390
make headers
make headers_install

Installed the proper s390 headers, and "usr/include/asm" would contain the s390 specifics.

Some scripting would be required to make this much easier to generate+wire up for all archs semi-automatically.

Quoted 6 lines
Quoted 3 lines

In tools/include/uapi/asm-generic/unistd.h, we already do have __NR_mseal ...

Yes, but it doesn't get used in selftests/mm, with the way headers are set up right now.

Right

Signature · 3 lines
Cheers,

David / dhildenb
#6 lore raw

Re: [PATCH v2 1/6] selftests/mm: mseal, self_elf: fix missing __NR_mseal

Quoted 4 lines · David Hildenbrand
Quoted 3 lines · John Hubbard
Quoted 2 lines · David Hildenbrand
Quoted 1 line · David Hildenbrand

On 14.06.24 04:30, John Hubbard wrote:

...

Quoted 12 lines
Quoted 9 lines
Quoted 2 lines

... thinking again, are some of these headers arch-specific (IOW, generating them per-arch would result in something slightly different)?

Oh wow, yes they are. I'm guilty of x86-centric thinking (again).

hmm, this is going to make it really a lot of trouble to do this approach. But there's no point in turning back now, so I guess I'd better fire up the cross-compilers and generate for all the arches.

Cross compilers might not be required.

Quoted 8 lines

At least for me, at simple

rm -rf usr/include
export ARCH=s390
make headers
make headers_install

Installed the proper s390 headers, and "usr/include/asm" would contain the s390 specifics.

Yes.

Quoted 2 lines

Some scripting would be required to make this much easier to generate+wire up for all archs semi-automatically.

After exploring this, and eventually re-inventing the concept of asm-generic, I now understand What To Do.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

In tools/include/uapi/asm-generic/unistd.h, we already do have __NR_mseal ...

Yes, but it doesn't get used in selftests/mm, with the way headers are set up right now.

Right

...it turns out that the right answer is to simply include asm-generic/unistd.h. That is the only way to safely use system call numbers across CPU architectures, and we already have it. So the entire patch simplifies back down to two lines of diff:

tools/testing/selftests/mm/mseal_test.c +1 -1
index 41998cf1dcf5..58c888529f42 100644
@@ -3,7 +3,7 @@
 #include <linux/mman.h>
 #include <sys/mman.h>
 #include <stdint.h>
-#include <unistd.h>
+#include <asm-generic/unistd.h>
 #include <string.h>
 #include <sys/time.h>
 #include <sys/resource.h>
tools/testing/selftests/mm/seal_elf.c +1 -1
index f2babec79bb6..27bf2f84231d 100644
@@ -2,7 +2,7 @@
 #define _GNU_SOURCE
 #include <sys/mman.h>
 #include <stdint.h>
-#include <unistd.h>
+#include <asm-generic/unistd.h>
 #include <string.h>
 #include <sys/time.h>
 #include <sys/resource.h>

Which is a little embarrassing, after all this churn, but it's not always clear how these headers are meant to be used, at first. Now it's clear. I think. :)

I'll post a v3 shortly

thanks,

Signature · 2 lines
John Hubbard
NVIDIA
#7 lore raw

PATCH v2 2/6 selftests/mm: mseal, self_elf: factor out test macros and other duplicated items

In reply to John Hubbard

Clean up and move some copy-pasted items into a new mseal_helpers.h.

1. The test macros can be made safer and simpler, by observing that they are invariably called when about to return. This means that the macros do not need an intrusive label to goto; they can simply return.

2. PKEY* items. We cannot, unfortunately use pkey-helpers.h. The best we can do is to factor out these few items into mseal_helpers.h.

3. These tests still need their own definition of u64, so also move that to the header file.

Cc Jeff Xu <[email protected]>
Cc David Hildenbrand <[email protected]>
---
 tools/testing/selftests/mm/mseal_helpers.h | 41 ++++++++++++++++++
 tools/testing/selftests/mm/mseal_test.c    | 49 +---------------------
 tools/testing/selftests/mm/seal_elf.c      | 33 +--------------
 3 files changed, 43 insertions(+), 80 deletions(-)
 create mode 100644 tools/testing/selftests/mm/mseal_helpers.h
tools/testing/selftests/mm/mseal_helpers.h new file +41 -0
new file mode 100644
index 000000000000..108d3fd0becb
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#define FAIL_TEST_IF_FALSE(test_passed)					\
+	do {								\
+		if (!(test_passed)) {					\
+			ksft_test_result_fail("%s: line:%d\n",		\
+						__func__, __LINE__);	\
+			return;						\
+		}							\
+	} while (0)
+
+#define SKIP_TEST_IF_FALSE(test_passed)					\
+	do {								\
+		if (!(test_passed)) {					\
+			ksft_test_result_skip("%s: line:%d\n",		\
+						__func__, __LINE__);	\
+			return;						\
+		}							\
+	} while (0)
+
+#define TEST_END_CHECK() ksft_test_result_pass("%s\n", __func__)
+
+#ifndef PKEY_DISABLE_ACCESS
+#define PKEY_DISABLE_ACCESS	0x1
+#endif
+
+#ifndef PKEY_DISABLE_WRITE
+#define PKEY_DISABLE_WRITE	0x2
+#endif
+
+#ifndef PKEY_BITS_PER_PKEY
+#define PKEY_BITS_PER_PKEY	2
+#endif
+
+#ifndef PKEY_MASK
+#define PKEY_MASK	(PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE)
+#endif
+
+#ifndef u64
+#define u64 unsigned long long
+#endif
tools/testing/selftests/mm/mseal_test.c +1 -48

55 lines not on this page · raw message

tools/testing/selftests/mm/seal_elf.c +1 -32
index 6212434bd6e3..7f6a95613dd6 100644
@@ -16,38 +16,7 @@
 #include <sys/ioctl.h>
 #include <sys/vfs.h>
 #include <sys/stat.h>
-
-/*
- * need those definition for manually build using gcc.
- * gcc -I ../../../../usr/include   -DDEBUG -O3  -DDEBUG -O3 seal_elf.c -o seal_elf
- */
-#define FAIL_TEST_IF_FALSE(c) do {\
-		if (!(c)) {\
-			ksft_test_result_fail("%s, line:%d\n", __func__, __LINE__);\
-			goto test_end;\
-		} \
-	} \
-	while (0)
-
-#define SKIP_TEST_IF_FALSE(c) do {\
-		if (!(c)) {\
-			ksft_test_result_skip("%s, line:%d\n", __func__, __LINE__);\
-			goto test_end;\
-		} \
-	} \
-	while (0)
-
-
-#define TEST_END_CHECK() {\
-		ksft_test_result_pass("%s\n", __func__);\
-		return;\
-test_end:\
-		return;\
-}
-
-#ifndef u64
-#define u64 unsigned long long
-#endif
+#include "mseal_helpers.h"
 
 /*
  * define sys_xyx to call syscall directly.
Signature · 1 line
2.45.2
Acked-by on v2 2/6
#8 lore raw

Re: [PATCH v2 2/6] selftests/mm: mseal, self_elf: factor out test macros and other duplicated items

Quoted 9 lines · John Hubbard

Clean up and move some copy-pasted items into a new mseal_helpers.h.

1. The test macros can be made safer and simpler, by observing that they are invariably called when about to return. This means that the macros do not need an intrusive label to goto; they can simply return.

2. PKEY* items. We cannot, unfortunately use pkey-helpers.h. The best we can do is to factor out these few items into mseal_helpers.h.

Quoted 7 lines

3. These tests still need their own definition of u64, so also move that to the header file.

Cc Jeff Xu <[email protected]>
Cc David Hildenbrand <[email protected]>

---

Signature · 3 lines
Cheers,

David / dhildenb
Reviewed-by
#9 lore raw

Re: [PATCH v2 2/6] selftests/mm: mseal, self_elf: factor out test macros and other duplicated items

Quoted 14 lines · David Hildenbrand
Quoted 12 lines · John Hubbard

Clean up and move some copy-pasted items into a new mseal_helpers.h.

1. The test macros can be made safer and simpler, by observing that they are invariably called when about to return. This means that the macros do not need an intrusive label to goto; they can simply return.

2. PKEY* items. We cannot, unfortunately use pkey-helpers.h. The best we can do is to factor out these few items into mseal_helpers.h.

3. These tests still need their own definition of u64, so also move that to the header file.

Quoted 6 lines
Quoted 4 lines
Cc Jeff Xu <[email protected]>
Cc David Hildenbrand <[email protected]>

---

Quoted 6 lines

--
Cheers,

David / dhildenb

#10 lore raw

PATCH v2 3/6 selftests/mm: mseal, self_elf: rename TEST_END_CHECK to REPORT_TEST_PASS

In reply to John Hubbard

Now that the test macros are factored out into their final location, and simplified, it's time to rename TEST_END_CHECK to something that represents its new functionality: REPORT_TEST_PASS.

---
 tools/testing/selftests/mm/mseal_helpers.h |  2 +-
 tools/testing/selftests/mm/mseal_test.c    | 92 +++++++++++-----------
 tools/testing/selftests/mm/seal_elf.c      |  2 +-
 3 files changed, 48 insertions(+), 48 deletions(-)
tools/testing/selftests/mm/mseal_helpers.h +1 -1
index 108d3fd0becb..0cfce31c76d2 100644
@@ -18,7 +18,7 @@
 		}							\
 	} while (0)
 
-#define TEST_END_CHECK() ksft_test_result_pass("%s\n", __func__)
+#define REPORT_TEST_PASS() ksft_test_result_pass("%s\n", __func__)
 
 #ifndef PKEY_DISABLE_ACCESS
 #define PKEY_DISABLE_ACCESS	0x1
tools/testing/selftests/mm/mseal_test.c +46 -46

368 lines not on this page · raw message

tools/testing/selftests/mm/seal_elf.c +1 -1
index 7f6a95613dd6..619da94b9f33 100644
@@ -127,7 +127,7 @@ static void test_seal_elf(void)
 	FAIL_TEST_IF_FALSE(ret < 0);
 	ksft_print_msg("somestr is sealed, mprotect is rejected\n");
 
-	TEST_END_CHECK();
+	REPORT_TEST_PASS();
 }
 
 int main(int argc, char **argv)
Signature · 1 line
2.45.2
Acked-by on v2 3/6
#11 lore raw

Re: [PATCH v2 3/6] selftests/mm: mseal, self_elf: rename TEST_END_CHECK to REPORT_TEST_PASS

Quoted 9 lines · John Hubbard

Now that the test macros are factored out into their final location, and simplified, it's time to rename TEST_END_CHECK to something that represents its new functionality: REPORT_TEST_PASS.

---

Signature · 3 lines
Cheers,

David / dhildenb
#12 lore raw

PATCH v2 4/6 selftests/mm: fix vm_util.c build failures: add snapshot of fs.h

In reply to John Hubbard

On Ubuntu 23.04, on a clean git tree, the selftests/mm build fails due 10 or 20 missing items, all of which are found in fs.h, which is created via "make headers". However, as per [1], the idea is to stop requiring "make headers", and instead, take a snapshot of the files and check them in.

Here are a few of the build errors:

vm_util.c:34:21: error: variable has incomplete type 'struct pm_scan_arg'

        struct pm_scan_arg arg;

...
vm_util.c:45:28: error: use of undeclared identifier 'PAGE_IS_WPALLOWED'
...
vm_util.c:55:21: error: variable has incomplete type 'struct page_region'
...
vm_util.c:105:20: error: use of undeclared identifier 'PAGE_IS_SOFT_DIRTY'

To fix this, add fs.h, taken from a snapshot of ./usr/include/linux/fs.h after running "make headers".

[1] commit e076eaca5906 ("selftests: break the dependency upon local header files")

Cc David Hildenbrand <[email protected]>
---
 tools/include/uapi/linux/fs.h | 392 ++++++++++++++++++++++++++++++++++
 1 file changed, 392 insertions(+)
 create mode 100644 tools/include/uapi/linux/fs.h
tools/include/uapi/linux/fs.h new file +392 -0
new file mode 100644
index 000000000000..ca9d754bae04
@@ -0,0 +1,392 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _LINUX_FS_H
+#define _LINUX_FS_H
+
+/*
+ * This file has definitions for some important file table structures
+ * and constants and structures used by various generic file system
+ * ioctl's.  Please do not make any changes in this file before
+ * sending patches for review to [email protected] and
+ * [email protected].
+ */
+
+#include <linux/limits.h>
+#include <linux/ioctl.h>
+#include <linux/types.h>
+#include <linux/fscrypt.h>
+
+/* Use of MS_* flags within the kernel is restricted to core mount(2) code. */
+#include <linux/mount.h>
+
+/*
+ * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
+ * the file limit at runtime and only root can increase the per-process
+ * nr_file rlimit, so it's safe to set up a ridiculously high absolute
+ * upper limit on files-per-process.
+ *
+ * Some programs (notably those using select()) may have to be 
+ * recompiled to take full advantage of the new limits..  
+ */
+
+/* Fixed constants first: */
+#undef NR_OPEN
+#define INR_OPEN_CUR 1024	/* Initial setting for nfile rlimits */
+#define INR_OPEN_MAX 4096	/* Hard limit for nfile rlimits */
+
+#define BLOCK_SIZE_BITS 10
+#define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
+
+#define SEEK_SET	0	/* seek relative to beginning of file */
+#define SEEK_CUR	1	/* seek relative to current file position */
+#define SEEK_END	2	/* seek relative to end of file */
+#define SEEK_DATA	3	/* seek to the next data */
+#define SEEK_HOLE	4	/* seek to the next hole */
+#define SEEK_MAX	SEEK_HOLE
+
+#define RENAME_NOREPLACE	(1 << 0)	/* Don't overwrite target */
+#define RENAME_EXCHANGE		(1 << 1)	/* Exchange source and dest */
+#define RENAME_WHITEOUT		(1 << 2)	/* Whiteout source */
+
+struct file_clone_range {
+	__s64 src_fd;
+	__u64 src_offset;
+	__u64 src_length;
+	__u64 dest_offset;
+};
+
+struct fstrim_range {
+	__u64 start;
+	__u64 len;
+	__u64 minlen;
+};
+
+/*
+ * We include a length field because some filesystems (vfat) have an identifier
+ * that we do want to expose as a UUID, but doesn't have the standard length.
+ *
+ * We use a fixed size buffer beacuse this interface will, by fiat, never
+ * support "UUIDs" longer than 16 bytes; we don't want to force all downstream
+ * users to have to deal with that.
+ */
+struct fsuuid2 {
+	__u8	len;
+	__u8	uuid[16];
+};
+
+struct fs_sysfs_path {
+	__u8			len;
+	__u8			name[128];
+};
+
+/* extent-same (dedupe) ioctls; these MUST match the btrfs ioctl definitions */
+#define FILE_DEDUPE_RANGE_SAME		0
+#define FILE_DEDUPE_RANGE_DIFFERS	1
+
+/* from struct btrfs_ioctl_file_extent_same_info */
+struct file_dedupe_range_info {
+	__s64 dest_fd;		/* in - destination file */
+	__u64 dest_offset;	/* in - start of extent in destination */
+	__u64 bytes_deduped;	/* out - total # of bytes we were able
+				 * to dedupe from this file. */
+	/* status of this dedupe operation:
+	 * < 0 for error
+	 * == FILE_DEDUPE_RANGE_SAME if dedupe succeeds
+	 * == FILE_DEDUPE_RANGE_DIFFERS if data differs
+	 */
+	__s32 status;		/* out - see above description */
+	__u32 reserved;		/* must be zero */
+};
+
+/* from struct btrfs_ioctl_file_extent_same_args */
+struct file_dedupe_range {
+	__u64 src_offset;	/* in - start of extent in source */
+	__u64 src_length;	/* in - length of extent */
+	__u16 dest_count;	/* in - total elements in info array */
+	__u16 reserved1;	/* must be zero */
+	__u32 reserved2;	/* must be zero */
+	struct file_dedupe_range_info info[];
+};
+
+/* And dynamically-tunable limits and defaults: */
+struct files_stat_struct {
+	unsigned long nr_files;		/* read only */
+	unsigned long nr_free_files;	/* read only */
+	unsigned long max_files;		/* tunable */
+};
+
+struct inodes_stat_t {
+	long nr_inodes;
+	long nr_unused;
+	long dummy[5];		/* padding for sysctl ABI compatibility */
+};
+
+
+#define NR_FILE  8192	/* this can well be larger on a larger system */
+
+/*
+ * Structure for FS_IOC_FSGETXATTR[A] and FS_IOC_FSSETXATTR.
+ */
+struct fsxattr {
+	__u32		fsx_xflags;	/* xflags field value (get/set) */
+	__u32		fsx_extsize;	/* extsize field value (get/set)*/
+	__u32		fsx_nextents;	/* nextents field value (get)	*/
+	__u32		fsx_projid;	/* project identifier (get/set) */
+	__u32		fsx_cowextsize;	/* CoW extsize field value (get/set)*/
+	unsigned char	fsx_pad[8];
+};
+
+/*
+ * Flags for the fsx_xflags field
+ */
+#define FS_XFLAG_REALTIME	0x00000001	/* data in realtime volume */
+#define FS_XFLAG_PREALLOC	0x00000002	/* preallocated file extents */
+#define FS_XFLAG_IMMUTABLE	0x00000008	/* file cannot be modified */
+#define FS_XFLAG_APPEND		0x00000010	/* all writes append */
+#define FS_XFLAG_SYNC		0x00000020	/* all writes synchronous */
+#define FS_XFLAG_NOATIME	0x00000040	/* do not update access time */
+#define FS_XFLAG_NODUMP		0x00000080	/* do not include in backups */
+#define FS_XFLAG_RTINHERIT	0x00000100	/* create with rt bit set */
+#define FS_XFLAG_PROJINHERIT	0x00000200	/* create with parents projid */
+#define FS_XFLAG_NOSYMLINKS	0x00000400	/* disallow symlink creation */
+#define FS_XFLAG_EXTSIZE	0x00000800	/* extent size allocator hint */
+#define FS_XFLAG_EXTSZINHERIT	0x00001000	/* inherit inode extent size */
+#define FS_XFLAG_NODEFRAG	0x00002000	/* do not defragment */
+#define FS_XFLAG_FILESTREAM	0x00004000	/* use filestream allocator */
+#define FS_XFLAG_DAX		0x00008000	/* use DAX for IO */
+#define FS_XFLAG_COWEXTSIZE	0x00010000	/* CoW extent size allocator hint */
+#define FS_XFLAG_HASATTR	0x80000000	/* no DIFLAG for this	*/
+
+/* the read-only stuff doesn't really belong here, but any other place is
+   probably as bad and I don't want to create yet another include file. */
+
+#define BLKROSET   _IO(0x12,93)	/* set device read-only (0 = read-write) */
+#define BLKROGET   _IO(0x12,94)	/* get read-only status (0 = read_write) */
+#define BLKRRPART  _IO(0x12,95)	/* re-read partition table */
+#define BLKGETSIZE _IO(0x12,96)	/* return device size /512 (long *arg) */
+#define BLKFLSBUF  _IO(0x12,97)	/* flush buffer cache */
+#define BLKRASET   _IO(0x12,98)	/* set read ahead for block device */
+#define BLKRAGET   _IO(0x12,99)	/* get current read ahead setting */
+#define BLKFRASET  _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
+#define BLKFRAGET  _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
+#define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
+#define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
+#define BLKSSZGET  _IO(0x12,104)/* get block device sector size */
+#if 0
+#define BLKPG      _IO(0x12,105)/* See blkpg.h */
+
+/* Some people are morons.  Do not use sizeof! */
+
+#define BLKELVGET  _IOR(0x12,106,size_t)/* elevator get */
+#define BLKELVSET  _IOW(0x12,107,size_t)/* elevator set */
+/* This was here just to show that the number is taken -
+   probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */
+#endif
+/* A jump here: 108-111 have been used for various private purposes. */
+#define BLKBSZGET  _IOR(0x12,112,size_t)
+#define BLKBSZSET  _IOW(0x12,113,size_t)
+#define BLKGETSIZE64 _IOR(0x12,114,size_t)	/* return device size in bytes (u64 *arg) */
+#define BLKTRACESETUP _IOWR(0x12,115,struct blk_user_trace_setup)
+#define BLKTRACESTART _IO(0x12,116)
+#define BLKTRACESTOP _IO(0x12,117)
+#define BLKTRACETEARDOWN _IO(0x12,118)
+#define BLKDISCARD _IO(0x12,119)
+#define BLKIOMIN _IO(0x12,120)
+#define BLKIOOPT _IO(0x12,121)
+#define BLKALIGNOFF _IO(0x12,122)
+#define BLKPBSZGET _IO(0x12,123)
+#define BLKDISCARDZEROES _IO(0x12,124)
+#define BLKSECDISCARD _IO(0x12,125)
+#define BLKROTATIONAL _IO(0x12,126)
+#define BLKZEROOUT _IO(0x12,127)
+#define BLKGETDISKSEQ _IOR(0x12,128,__u64)
+/*
+ * A jump here: 130-136 are reserved for zoned block devices
+ * (see uapi/linux/blkzoned.h)
+ */
+
+#define BMAP_IOCTL 1		/* obsolete - kept for compatibility */
+#define FIBMAP	   _IO(0x00,1)	/* bmap access */
+#define FIGETBSZ   _IO(0x00,2)	/* get the block size used for bmap */
+#define FIFREEZE	_IOWR('X', 119, int)	/* Freeze */
+#define FITHAW		_IOWR('X', 120, int)	/* Thaw */
+#define FITRIM		_IOWR('X', 121, struct fstrim_range)	/* Trim */
+#define FICLONE		_IOW(0x94, 9, int)
+#define FICLONERANGE	_IOW(0x94, 13, struct file_clone_range)
+#define FIDEDUPERANGE	_IOWR(0x94, 54, struct file_dedupe_range)
+
+#define FSLABEL_MAX 256	/* Max chars for the interface; each fs may differ */
+
+#define	FS_IOC_GETFLAGS			_IOR('f', 1, long)
+#define	FS_IOC_SETFLAGS			_IOW('f', 2, long)
+#define	FS_IOC_GETVERSION		_IOR('v', 1, long)
+#define	FS_IOC_SETVERSION		_IOW('v', 2, long)
+#define FS_IOC_FIEMAP			_IOWR('f', 11, struct fiemap)
+#define FS_IOC32_GETFLAGS		_IOR('f', 1, int)
+#define FS_IOC32_SETFLAGS		_IOW('f', 2, int)
+#define FS_IOC32_GETVERSION		_IOR('v', 1, int)
+#define FS_IOC32_SETVERSION		_IOW('v', 2, int)
+#define FS_IOC_FSGETXATTR		_IOR('X', 31, struct fsxattr)
+#define FS_IOC_FSSETXATTR		_IOW('X', 32, struct fsxattr)
+#define FS_IOC_GETFSLABEL		_IOR(0x94, 49, char[FSLABEL_MAX])
+#define FS_IOC_SETFSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
+/* Returns the external filesystem UUID, the same one blkid returns */
+#define FS_IOC_GETFSUUID		_IOR(0x15, 0, struct fsuuid2)
+/*
+ * Returns the path component under /sys/fs/ that refers to this filesystem;
+ * also /sys/kernel/debug/ for filesystems with debugfs exports
+ */
+#define FS_IOC_GETFSSYSFSPATH		_IOR(0x15, 1, struct fs_sysfs_path)
+
+/*
+ * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)
+ *
+ * Note: for historical reasons, these flags were originally used and
+ * defined for use by ext2/ext3, and then other file systems started
+ * using these flags so they wouldn't need to write their own version
+ * of chattr/lsattr (which was shipped as part of e2fsprogs).  You
+ * should think twice before trying to use these flags in new
+ * contexts, or trying to assign these flags, since they are used both
+ * as the UAPI and the on-disk encoding for ext2/3/4.  Also, we are
+ * almost out of 32-bit flags.  :-)
+ *
+ * We have recently hoisted FS_IOC_FSGETXATTR / FS_IOC_FSSETXATTR from
+ * XFS to the generic FS level interface.  This uses a structure that
+ * has padding and hence has more room to grow, so it may be more
+ * appropriate for many new use cases.
+ *
+ * Please do not change these flags or interfaces before checking with
+ * [email protected] and [email protected].
+ */
+#define	FS_SECRM_FL			0x00000001 /* Secure deletion */
+#define	FS_UNRM_FL			0x00000002 /* Undelete */
+#define	FS_COMPR_FL			0x00000004 /* Compress file */
+#define FS_SYNC_FL			0x00000008 /* Synchronous updates */
+#define FS_IMMUTABLE_FL			0x00000010 /* Immutable file */
+#define FS_APPEND_FL			0x00000020 /* writes to file may only append */
+#define FS_NODUMP_FL			0x00000040 /* do not dump file */
+#define FS_NOATIME_FL			0x00000080 /* do not update atime */
+/* Reserved for compression usage... */
+#define FS_DIRTY_FL			0x00000100
+#define FS_COMPRBLK_FL			0x00000200 /* One or more compressed clusters */
+#define FS_NOCOMP_FL			0x00000400 /* Don't compress */
+/* End compression flags --- maybe not all used */
+#define FS_ENCRYPT_FL			0x00000800 /* Encrypted file */
+#define FS_BTREE_FL			0x00001000 /* btree format dir */
+#define FS_INDEX_FL			0x00001000 /* hash-indexed directory */
+#define FS_IMAGIC_FL			0x00002000 /* AFS directory */
+#define FS_JOURNAL_DATA_FL		0x00004000 /* Reserved for ext3 */
+#define FS_NOTAIL_FL			0x00008000 /* file tail should not be merged */
+#define FS_DIRSYNC_FL			0x00010000 /* dirsync behaviour (directories only) */
+#define FS_TOPDIR_FL			0x00020000 /* Top of directory hierarchies*/
+#define FS_HUGE_FILE_FL			0x00040000 /* Reserved for ext4 */
+#define FS_EXTENT_FL			0x00080000 /* Extents */
+#define FS_VERITY_FL			0x00100000 /* Verity protected inode */
+#define FS_EA_INODE_FL			0x00200000 /* Inode used for large EA */
+#define FS_EOFBLOCKS_FL			0x00400000 /* Reserved for ext4 */
+#define FS_NOCOW_FL			0x00800000 /* Do not cow file */
+#define FS_DAX_FL			0x02000000 /* Inode is DAX */
+#define FS_INLINE_DATA_FL		0x10000000 /* Reserved for ext4 */
+#define FS_PROJINHERIT_FL		0x20000000 /* Create with parents projid */
+#define FS_CASEFOLD_FL			0x40000000 /* Folder is case insensitive */
+#define FS_RESERVED_FL			0x80000000 /* reserved for ext2 lib */
+
+#define FS_FL_USER_VISIBLE		0x0003DFFF /* User visible flags */
+#define FS_FL_USER_MODIFIABLE		0x000380FF /* User modifiable flags */
+
+
+#define SYNC_FILE_RANGE_WAIT_BEFORE	1
+#define SYNC_FILE_RANGE_WRITE		2
+#define SYNC_FILE_RANGE_WAIT_AFTER	4
+#define SYNC_FILE_RANGE_WRITE_AND_WAIT	(SYNC_FILE_RANGE_WRITE | \
+					 SYNC_FILE_RANGE_WAIT_BEFORE | \
+					 SYNC_FILE_RANGE_WAIT_AFTER)
+
+/*
+ * Flags for preadv2/pwritev2:
+ */
+
+typedef int __bitwise __kernel_rwf_t;
+
+/* high priority request, poll if possible */
+#define RWF_HIPRI	((__kernel_rwf_t)0x00000001)
+
+/* per-IO O_DSYNC */
+#define RWF_DSYNC	((__kernel_rwf_t)0x00000002)
+
+/* per-IO O_SYNC */
+#define RWF_SYNC	((__kernel_rwf_t)0x00000004)
+
+/* per-IO, return -EAGAIN if operation would block */
+#define RWF_NOWAIT	((__kernel_rwf_t)0x00000008)
+
+/* per-IO O_APPEND */
+#define RWF_APPEND	((__kernel_rwf_t)0x00000010)
+
+/* per-IO negation of O_APPEND */
+#define RWF_NOAPPEND	((__kernel_rwf_t)0x00000020)
+
+/* mask of flags supported by the kernel */
+#define RWF_SUPPORTED	(RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\
+			 RWF_APPEND | RWF_NOAPPEND)
+
+/* Pagemap ioctl */
+#define PAGEMAP_SCAN	_IOWR('f', 16, struct pm_scan_arg)
+
+/* Bitmasks provided in pm_scan_args masks and reported in page_region.categories. */
+#define PAGE_IS_WPALLOWED	(1 << 0)
+#define PAGE_IS_WRITTEN		(1 << 1)
+#define PAGE_IS_FILE		(1 << 2)
+#define PAGE_IS_PRESENT		(1 << 3)
+#define PAGE_IS_SWAPPED		(1 << 4)
+#define PAGE_IS_PFNZERO		(1 << 5)
+#define PAGE_IS_HUGE		(1 << 6)
+#define PAGE_IS_SOFT_DIRTY	(1 << 7)
+
+/*
+ * struct page_region - Page region with flags
+ * @start:	Start of the region
+ * @end:	End of the region (exclusive)
+ * @categories:	PAGE_IS_* category bitmask for the region
+ */
+struct page_region {
+	__u64 start;
+	__u64 end;
+	__u64 categories;
+};
+
+/* Flags for PAGEMAP_SCAN ioctl */
+#define PM_SCAN_WP_MATCHING	(1 << 0)	/* Write protect the pages matched. */
+#define PM_SCAN_CHECK_WPASYNC	(1 << 1)	/* Abort the scan when a non-WP-enabled page is found. */
+
+/*
+ * struct pm_scan_arg - Pagemap ioctl argument
+ * @size:		Size of the structure
+ * @flags:		Flags for the IOCTL
+ * @start:		Starting address of the region
+ * @end:		Ending address of the region
+ * @walk_end		Address where the scan stopped (written by kernel).
+ *			walk_end == end (address tags cleared) informs that the scan completed on entire range.
+ * @vec:		Address of page_region struct array for output
+ * @vec_len:		Length of the page_region struct array
+ * @max_pages:		Optional limit for number of returned pages (0 = disabled)
+ * @category_inverted:	PAGE_IS_* categories which values match if 0 instead of 1
+ * @category_mask:	Skip pages for which any category doesn't match
+ * @category_anyof_mask: Skip pages for which no category matches
+ * @return_mask:	PAGE_IS_* categories that are to be reported in `page_region`s returned
+ */
+struct pm_scan_arg {
+	__u64 size;
+	__u64 flags;
+	__u64 start;
+	__u64 end;
+	__u64 walk_end;
+	__u64 vec;
+	__u64 vec_len;
+	__u64 max_pages;
+	__u64 category_inverted;
+	__u64 category_mask;
+	__u64 category_anyof_mask;
+	__u64 return_mask;
+};
+
+#endif /* _LINUX_FS_H */
Signature · 1 line
2.45.2
Acked-by on v2 4/6
#13 lore raw

Re: [PATCH v2 4/6] selftests/mm: fix vm_util.c build failures: add snapshot of fs.h

Quoted 20 lines · John Hubbard

On Ubuntu 23.04, on a clean git tree, the selftests/mm build fails due 10 or 20 missing items, all of which are found in fs.h, which is created via "make headers". However, as per [1], the idea is to stop requiring "make headers", and instead, take a snapshot of the files and check them in.

Here are a few of the build errors:

vm_util.c:34:21: error: variable has incomplete type 'struct pm_scan_arg'

         struct pm_scan_arg arg;

...
vm_util.c:45:28: error: use of undeclared identifier 'PAGE_IS_WPALLOWED'
...
vm_util.c:55:21: error: variable has incomplete type 'struct page_region'
...
vm_util.c:105:20: error: use of undeclared identifier 'PAGE_IS_SOFT_DIRTY'

To fix this, add fs.h, taken from a snapshot of ./usr/include/linux/fs.h after running "make headers".

Quoted 6 lines

[1] commit e076eaca5906 ("selftests: break the dependency upon local header files")

Cc David Hildenbrand <[email protected]>

---

Signature · 3 lines
Cheers,

David / dhildenb
#14 lore raw

PATCH v2 5/6 selftests/mm: kvm, mdwe fixes to avoid requiring "make headers"

In reply to John Hubbard

On Ubuntu 23.04, the kvm and mdwe selftests/mm build fails due to missing a few items that are found in prctl.h. Here is an excerpt of the build failures:

ksm_tests.c:252:13: error: use of undeclared identifier 'PR_SET_MEMORY_MERGE'
...
mdwe_test.c:26:18: error: use of undeclared identifier 'PR_SET_MDWE' mdwe_test.c:38:18: error: use of undeclared identifier 'PR_GET_MDWE'

Fix these errors by adding the missing items to vm_util.h, and include vm_util.h from mdwe_test.c.

Cc David Hildenbrand <[email protected]>
---
 tools/testing/selftests/mm/mdwe_test.c |  1 +
 tools/testing/selftests/mm/vm_util.h   | 15 +++++++++++++++
 2 files changed, 16 insertions(+)
tools/testing/selftests/mm/mdwe_test.c +1 -0
index 200bedcdc32e..cfe0b64d1567 100644
@@ -15,6 +15,7 @@
 #include <unistd.h>
 
 #include "../kselftest_harness.h"
+#include "vm_util.h"
 
 #ifndef __aarch64__
 # define PROT_BTI	0
tools/testing/selftests/mm/vm_util.h +15 -0
index 9007c420d52c..99cbb7c0ea9d 100644
@@ -61,3 +61,18 @@ unsigned long get_free_hugepages(void);
 
 #define PAGEMAP_PRESENT(ent)	(((ent) & (1ull << 63)) != 0)
 #define PAGEMAP_PFN(ent)	((ent) & ((1ull << 55) - 1))
+
+#ifndef PR_SET_MEMORY_MERGE
+#define PR_SET_MEMORY_MERGE		67
+#endif
+
+#ifndef PR_GET_MEMORY_MERGE
+#define PR_GET_MEMORY_MERGE		68
+#endif
+
+#ifndef PR_SET_MDWE
+#define PR_SET_MDWE			65
+#define PR_MDWE_REFUSE_EXEC_GAIN	(1UL << 0)
+#define PR_MDWE_NO_INHERIT		(1UL << 1)
+#define PR_GET_MDWE			66
+#endif
Signature · 1 line
2.45.2
#15 lore raw

Re: [PATCH v2 5/6] selftests/mm: kvm, mdwe fixes to avoid requiring "make headers"

Quoted 44 lines · John Hubbard

On Ubuntu 23.04, the kvm and mdwe selftests/mm build fails due to missing a few items that are found in prctl.h. Here is an excerpt of the build failures:

ksm_tests.c:252:13: error: use of undeclared identifier 'PR_SET_MEMORY_MERGE'
...
mdwe_test.c:26:18: error: use of undeclared identifier 'PR_SET_MDWE' mdwe_test.c:38:18: error: use of undeclared identifier 'PR_GET_MDWE'

Fix these errors by adding the missing items to vm_util.h, and include vm_util.h from mdwe_test.c.

Cc David Hildenbrand <[email protected]>
---
  tools/testing/selftests/mm/mdwe_test.c |  1 +
  tools/testing/selftests/mm/vm_util.h   | 15 +++++++++++++++
  2 files changed, 16 insertions(+)
tools/testing/selftests/mm/mdwe_test.c +1 -0
index 200bedcdc32e..cfe0b64d1567 100644
@@ -15,6 +15,7 @@
  #include <unistd.h>
 
  #include "../kselftest_harness.h"
+#include "vm_util.h"
 
  #ifndef __aarch64__
  # define PROT_BTI	0
tools/testing/selftests/mm/vm_util.h +5 -0
index 9007c420d52c..99cbb7c0ea9d 100644
@@ -61,3 +61,18 @@ unsigned long get_free_hugepages(void);
 
  #define PAGEMAP_PRESENT(ent)	(((ent) & (1ull << 63)) != 0)
  #define PAGEMAP_PFN(ent)	((ent) & ((1ull << 55) - 1))
+
+#ifndef PR_SET_MEMORY_MERGE
+#define PR_SET_MEMORY_MERGE		67
+#endif
+

tools/testing/selftests/mm/vm_util.h unsigned long get_free_hugepages(void); · line 78

Quoted 10 lines
tools/testing/selftests/mm/vm_util.h +10 -0
+#ifndef PR_GET_MEMORY_MERGE
+#define PR_GET_MEMORY_MERGE		68
+#endif
+
+#ifndef PR_SET_MDWE
+#define PR_SET_MDWE			65
+#define PR_MDWE_REFUSE_EXEC_GAIN	(1UL << 0)
+#define PR_MDWE_NO_INHERIT		(1UL << 1)
+#define PR_GET_MDWE			66
+#endif

What's the reason we don't target "linux/prctl.h" here? :)

Signature · 3 lines
Cheers,

David / dhildenb
#16 lore raw

Re: [PATCH v2 5/6] selftests/mm: kvm, mdwe fixes to avoid requiring "make headers"

Quoted 1 line · David Hildenbrand

On 14.06.24 04:30, John Hubbard wrote:

...

Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/mm/vm_util.h +8 -0
+#ifndef PR_SET_MEMORY_MERGE
+#define PR_SET_MEMORY_MERGE        67
+#endif
+
+#ifndef PR_GET_MEMORY_MERGE
+#define PR_GET_MEMORY_MERGE        68
+#endif
+
Quoted 8 lines

tools/testing/selftests/mm/vm_util.h unsigned long get_free_hugepages(void); · line 78

Quoted 6 lines
tools/testing/selftests/mm/vm_util.h +6 -0
+#ifndef PR_SET_MDWE
+#define PR_SET_MDWE            65
+#define PR_MDWE_REFUSE_EXEC_GAIN    (1UL << 0)
+#define PR_MDWE_NO_INHERIT        (1UL << 1)
+#define PR_GET_MDWE            66
+#endif

What's the reason we don't target "linux/prctl.h" here? :)

Very good point. This is the Old Way of fixing these up, and I overlooked that even though I'm busy adding the New Way. :)

I'll change this to use a new tools/include/uapi/linux/prctl.h and post a v3, thanks for pointing this out.

thanks,

Signature · 2 lines
John Hubbard
NVIDIA
#17 lore raw

PATCH v2 6/6 selftests/mm: remove local __NR_* definitions

In reply to John Hubbard

This continues the work on getting the selftests to build without requiring people to first run "make headers" [1].

Now that the system call numbers are in the correct, checked-in locations in the kernel tree (./tools/include/uapi/asm/unistd*.h), make sure that the mm selftests include that file (indirectly).

Doing so provides guaranteed definitions at build time, so remove all of the checks for "ifdef __NR_xxx" in the mm selftests, because they will always be true (defined).

[1] commit e076eaca5906 ("selftests: break the dependency upon local header files")

Cc David Hildenbrand <[email protected]>
Cc Jeff Xu <[email protected]>
---
 tools/testing/selftests/mm/hugepage-mremap.c     |  2 +-
 .../testing/selftests/mm/ksm_functional_tests.c  |  8 +-------
 tools/testing/selftests/mm/memfd_secret.c        | 14 +-------------
 tools/testing/selftests/mm/mkdirty.c             |  8 +-------
 tools/testing/selftests/mm/mlock2.h              |  1 +
 tools/testing/selftests/mm/mrelease_test.c       |  2 +-
 tools/testing/selftests/mm/pagemap_ioctl.c       |  2 +-
 tools/testing/selftests/mm/protection_keys.c     |  2 +-
 tools/testing/selftests/mm/uffd-common.c         |  4 ----
 tools/testing/selftests/mm/uffd-stress.c         | 16 +---------------
 tools/testing/selftests/mm/uffd-unit-tests.c     | 14 +-------------
 11 files changed, 10 insertions(+), 63 deletions(-)
tools/testing/selftests/mm/hugepage-mremap.c +1 -1
index c463d1c09c9b..2893bc002639 100644
@@ -15,7 +15,7 @@
 #define _GNU_SOURCE
 #include <stdlib.h>
 #include <stdio.h>
-#include <unistd.h>
+#include <linux/unistd.h>
 #include <sys/mman.h>
 #include <errno.h>
 #include <fcntl.h> /* Definition of O_* constants */
tools/testing/selftests/mm/ksm_functional_tests.c +1 -7
index 37de82da9be7..1d584a415bde 100644
@@ -11,7 +11,7 @@
 #include <string.h>
 #include <stdbool.h>
 #include <stdint.h>
-#include <unistd.h>
+#include <linux/unistd.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/mman.h>
@@ -369,7 +369,6 @@ static void test_unmerge_discarded(void)
 	munmap(map, size);
 }
 
-#ifdef __NR_userfaultfd
 static void test_unmerge_uffd_wp(void)
 {
 	struct uffdio_writeprotect uffd_writeprotect;
@@ -430,7 +429,6 @@ static void test_unmerge_uffd_wp(void)
 unmap:
 	munmap(map, size);
 }
-#endif
 
 /* Verify that KSM can be enabled / queried with prctl. */
 static void test_prctl(void)
@@ -665,9 +663,7 @@ int main(int argc, char **argv)
 		exit(test_child_ksm());
 	}
 
-#ifdef __NR_userfaultfd
 	tests++;
-#endif
 
 	ksft_print_header();
 	ksft_set_plan(tests);
@@ -694,9 +690,7 @@ int main(int argc, char **argv)
 	test_unmerge();
 	test_unmerge_zero_pages();
 	test_unmerge_discarded();
-#ifdef __NR_userfaultfd
 	test_unmerge_uffd_wp();
-#endif
 
 	test_prot_none();
 
tools/testing/selftests/mm/memfd_secret.c +1 -13
index 9a0597310a76..1fcf65c08c87 100644
@@ -17,7 +17,7 @@
 
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
+#include <linux/unistd.h>
 #include <errno.h>
 #include <stdio.h>
 #include <fcntl.h>
@@ -28,8 +28,6 @@
 #define pass(fmt, ...) ksft_test_result_pass(fmt, ##__VA_ARGS__)
 #define skip(fmt, ...) ksft_test_result_skip(fmt, ##__VA_ARGS__)
 
-#ifdef __NR_memfd_secret
-
 #define PATTERN	0x55
 
 static const int prot = PROT_READ | PROT_WRITE;
@@ -334,13 +332,3 @@ int main(int argc, char *argv[])
 
 	ksft_finished();
 }
-
-#else /* __NR_memfd_secret */
-
-int main(int argc, char *argv[])
-{
-	printf("skip: skipping memfd_secret test (missing __NR_memfd_secret)\n");
-	return KSFT_SKIP;
-}
-
-#endif /* __NR_memfd_secret */
tools/testing/selftests/mm/mkdirty.c +1 -7
index b8a7efe9204e..7dde5b9a9ef5 100644
@@ -9,7 +9,7 @@
  */
 #include <fcntl.h>
 #include <signal.h>
-#include <unistd.h>
+#include <linux/unistd.h>
 #include <string.h>
 #include <errno.h>
 #include <stdlib.h>
@@ -265,7 +265,6 @@ static void test_pte_mapped_thp(void)
 	munmap(mmap_mem, mmap_size);
 }
 
-#ifdef __NR_userfaultfd
 static void test_uffdio_copy(void)
 {
 	struct uffdio_register uffdio_register;
@@ -322,7 +321,6 @@ static void test_uffdio_copy(void)
 	munmap(dst, pagesize);
 	free(src);
 }
-#endif /* __NR_userfaultfd */
 
 int main(void)
 {
@@ -335,9 +333,7 @@ int main(void)
 			       thpsize / 1024);
 		tests += 3;
 	}
-#ifdef __NR_userfaultfd
 	tests += 1;
-#endif /* __NR_userfaultfd */
 
 	ksft_print_header();
 	ksft_set_plan(tests);
@@ -367,9 +363,7 @@ int main(void)
 	if (thpsize)
 		test_pte_mapped_thp();
 	/* Placing a fresh page via userfaultfd may set the PTE dirty. */
-#ifdef __NR_userfaultfd
 	test_uffdio_copy();
-#endif /* __NR_userfaultfd */
 
 	err = ksft_get_fail_cnt();
 	if (err)
tools/testing/selftests/mm/mlock2.h +1 -0
index 4417eaa5cfb7..b74ddf0a2c39 100644
@@ -3,6 +3,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <linux/unistd.h>
 
 static int mlock2_(void *start, size_t len, int flags)
 {
tools/testing/selftests/mm/mrelease_test.c +1 -1
index 100370a7111d..a1b761940058 100644
@@ -10,7 +10,7 @@
 #include <sys/syscall.h>
 #include <sys/wait.h>
 #include <unistd.h>
-#include <asm-generic/unistd.h>
+#include <linux/unistd.h>
 #include "vm_util.h"
 #include "../kselftest.h"
 
tools/testing/selftests/mm/pagemap_ioctl.c +1 -1
index 2d785aca72a5..5652e5930854 100644
@@ -15,7 +15,7 @@
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <math.h>
-#include <asm/unistd.h>
+#include <linux/unistd.h>
 #include <pthread.h>
 #include <sys/resource.h>
 #include <assert.h>
tools/testing/selftests/mm/protection_keys.c +1 -1
index 48dc151f8fca..ec968db9e6c7 100644
@@ -42,7 +42,7 @@
 #include <sys/wait.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <unistd.h>
+#include <linux/unistd.h>
 #include <sys/ptrace.h>
 #include <setjmp.h>
 
tools/testing/selftests/mm/uffd-common.c +0 -4
index 7ad6ba660c7d..717539eddf98 100644
@@ -673,11 +673,7 @@ int uffd_open_dev(unsigned int flags)
 
 int uffd_open_sys(unsigned int flags)
 {
-#ifdef __NR_userfaultfd
 	return syscall(__NR_userfaultfd, flags);
-#else
-	return -1;
-#endif
 }
 
 int uffd_open(unsigned int flags)
tools/testing/selftests/mm/uffd-stress.c +1 -15
index f78bab0f3d45..6aff0e8cd961 100644
@@ -33,11 +33,9 @@
  * pthread_mutex_lock will also verify the atomicity of the memory
  * transfer (UFFDIO_COPY).
  */
-
+#include <linux/unistd.h>
 #include "uffd-common.h"
 
-#ifdef __NR_userfaultfd
-
 #define BOUNCE_RANDOM		(1<<0)
 #define BOUNCE_RACINGFAULTS	(1<<1)
 #define BOUNCE_VERIFY		(1<<2)
@@ -466,15 +464,3 @@ int main(int argc, char **argv)
 	       nr_pages, nr_pages_per_cpu);
 	return userfaultfd_stress();
 }
-
-#else /* __NR_userfaultfd */
-
-#warning "missing __NR_userfaultfd definition"
-
-int main(void)
-{
-	printf("skip: Skipping userfaultfd test (missing __NR_userfaultfd)\n");
-	return KSFT_SKIP;
-}
-
-#endif /* __NR_userfaultfd */
tools/testing/selftests/mm/uffd-unit-tests.c +1 -13
index 21ec23206ab4..6298a2045095 100644
@@ -5,12 +5,11 @@
  *  Copyright (C) 2015-2023  Red Hat, Inc.
  */
 
+#include <linux/unistd.h>
 #include "uffd-common.h"
 
 #include "../../../../mm/gup_test.h"
 
-#ifdef __NR_userfaultfd
-
 /* The unit test doesn't need a large or random size, make it 32MB for now */
 #define  UFFD_TEST_MEM_SIZE               (32UL << 20)
 
@@ -1554,14 +1553,3 @@ int main(int argc, char *argv[])
 	return ksft_get_fail_cnt() ? KSFT_FAIL : KSFT_PASS;
 }
 
-#else /* __NR_userfaultfd */
-
-#warning "missing __NR_userfaultfd definition"
-
-int main(void)
-{
-	printf("Skipping %s (missing __NR_userfaultfd)\n", __file__);
-	return KSFT_SKIP;
-}
-
-#endif /* __NR_userfaultfd */
Signature · 1 line
2.45.2
Acked-by on v2 6/6
#18 lore raw

Re: [PATCH v2 6/6] selftests/mm: remove local __NR_* definitions

Quoted 11 lines · John Hubbard

This continues the work on getting the selftests to build without requiring people to first run "make headers" [1].

Now that the system call numbers are in the correct, checked-in locations in the kernel tree (./tools/include/uapi/asm/unistd*.h), make sure that the mm selftests include that file (indirectly).

Doing so provides guaranteed definitions at build time, so remove all of the checks for "ifdef __NR_xxx" in the mm selftests, because they will always be true (defined).

Quoted 7 lines

[1] commit e076eaca5906 ("selftests: break the dependency upon local header files")

Cc David Hildenbrand <[email protected]>
Cc Jeff Xu <[email protected]>

---

Lovely

Signature · 3 lines
Cheers,

David / dhildenb
#19 lore raw

Re: [PATCH v2 6/6] selftests/mm: remove local __NR_* definitions

In reply to John Hubbard

Hi John,

tools/testing/selftests/mm/protection_keys.c line 47

Quoted 10 lines · John Hubbard
tools/testing/selftests/mm/protection_keys.c +1 -1
@@ -42,7 +42,7 @@
 #include <sys/wait.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <unistd.h>
+#include <linux/unistd.h>
 #include <sys/ptrace.h>
 #include <setjmp.h>

I'm not quite sure how but this broke the protection_keys.c selftest for me. Before this commit (a5c6bc590094a1a73cf6fa3f505e1945d2bf2461) things are fine. But after, I get:

running PKEY tests for unsupported CPU/OS

The "unsupported" test just makes a pkey_alloc() syscall. It's probably calling the wrong syscall number or something.

I think it's still broken in mainline. What's the right fix?

#20 lore raw

Re: [PATCH v2 6/6] selftests/mm: remove local __NR_* definitions

Quoted 18 lines · Dave Hansen

Hi John,

tools/testing/selftests/mm/protection_keys.c line 47

Quoted 10 lines · John Hubbard
tools/testing/selftests/mm/protection_keys.c +1 -1
@@ -42,7 +42,7 @@
  #include <sys/wait.h>
  #include <sys/stat.h>
  #include <fcntl.h>
-#include <unistd.h>
+#include <linux/unistd.h>
  #include <sys/ptrace.h>
  #include <setjmp.h>

I'm not quite sure how but this broke the protection_keys.c selftest for me. Before this commit (a5c6bc590094a1a73cf6fa3f505e1945d2bf2461) things are fine. But after, I get:

Quoted 6 lines

running PKEY tests for unsupported CPU/OS

The "unsupported" test just makes a pkey_alloc() syscall. It's probably calling the wrong syscall number or something.

I think it's still broken in mainline. What's the right fix?

omg I think this is an asm-generic include mistake, I'll check on it in an hour or so, in more depth.

thanks,

Signature · 1 line
John Hubbard
#21 lore raw

Re: [PATCH v2 6/6] selftests/mm: remove local __NR_* definitions

Hi John,

Quoted 21 lines · John Hubbard
Quoted 20 lines · Dave Hansen

Hi John,

tools/testing/selftests/mm/protection_keys.c line 47

Quoted 10 lines · John Hubbard
tools/testing/selftests/mm/protection_keys.c +1 -1
@@ -42,7 +42,7 @@
  #include <sys/wait.h>
  #include <sys/stat.h>
  #include <fcntl.h>
-#include <unistd.h>
+#include <linux/unistd.h>
  #include <sys/ptrace.h>
  #include <setjmp.h>

I'm not quite sure how but this broke the protection_keys.c selftest for me. Before this commit (a5c6bc590094a1a73cf6fa3f505e1945d2bf2461) things are fine. But after, I get:

running PKEY tests for unsupported CPU/OS

Quoted 8 lines
Quoted 4 lines

The "unsupported" test just makes a pkey_alloc() syscall. It's probably calling the wrong syscall number or something.

I think it's still broken in mainline. What's the right fix?

omg I think this is an asm-generic include mistake, I'll check on it in an hour or so, in more depth.

I just found that mlock2_() return a wrong value in mlock2-test, I guess that was caused by including the wrong header file <asm-generic/unistd.h>, which might define a different syscall number than what the kernel uses on the test system.

Shouldn't we make use of <unistd.h> directly?

Signature · 2 lines
Regards,
Li Wang
#22 lore raw

Re: [PATCH v2 6/6] selftests/mm: remove local __NR_* definitions

Quoted 30 lines · Li Wang

Hi John,

On Thu, Feb 13, 2025 at 6:31 AM John Hubbard <[email protected] <mailto:[email protected]>> wrote:

On 2/12/25 12:34 PM, Dave Hansen wrote:
> Hi John,
>
> On 6/13/24 19:30, John Hubbard wrote:
>> --- a/tools/testing/selftests/mm/protection_keys.c
>> +++ b/tools/testing/selftests/mm/protection_keys.c
>> @@ -42,7 +42,7 @@
>>   #include <sys/wait.h>
>>   #include <sys/stat.h>
>>   #include <fcntl.h>
>> -#include <unistd.h>
>> +#include <linux/unistd.h>
>>   #include <sys/ptrace.h>
>>   #include <setjmp.h>
>
> I'm not quite sure how but this broke the protection_keys.c selftest for > me. Before this commit (a5c6bc590094a1a73cf6fa3f505e1945d2bf2461) things > are fine.  But after, I get:
>
>       running PKEY tests for unsupported CPU/OS
>
> The "unsupported" test just makes a pkey_alloc() syscall. It's probably > calling the wrong syscall number or something.
>
> I think it's still broken in mainline. What's the right fix?

Quoted 8 lines

omg I think this is an asm-generic include mistake, I'll check on it in an hour or so, in more depth.

I just found that mlock2_() return a wrong valuein mlock2-test, I guess that was caused by including the wrong header file <asm-generic/unistd.h>,which might define a different syscall number than what the kernel uses on the test system.

Agreed.

Quoted 2 lines

Shouldn't we make use of <unistd.h> directly?

Well, yes and no. For now, there appear to be two commits involved in causing these problems, and the __NR_* parts need to be reverted.

I'll explain more when I post later today, but for the moment, the first, mseal- related commit below has some hints about how we got here:

504d8a5e0fd4 selftests/mm: mseal, self_elf: fix missing __NR_mseal a5c6bc590094 selftests/mm: remove local __NR_* definitions

thanks,

Signature · 1 line
John Hubbard
#23 lore raw

Re: [PATCH v2 6/6] selftests/mm: remove local __NR_* definitions

In reply to Dave Hansen
Quoted 18 lines · Dave Hansen

Hi John,

tools/testing/selftests/mm/protection_keys.c line 47

Quoted 10 lines · John Hubbard
tools/testing/selftests/mm/protection_keys.c +1 -1
@@ -42,7 +42,7 @@
  #include <sys/wait.h>
  #include <sys/stat.h>
  #include <fcntl.h>
-#include <unistd.h>
+#include <linux/unistd.h>
  #include <sys/ptrace.h>
  #include <setjmp.h>

I'm not quite sure how but this broke the protection_keys.c selftest for me. Before this commit (a5c6bc590094a1a73cf6fa3f505e1945d2bf2461) things are fine. But after, I get:

Quoted 6 lines

running PKEY tests for unsupported CPU/OS

The "unsupported" test just makes a pkey_alloc() syscall. It's probably calling the wrong syscall number or something.

I think it's still broken in mainline. What's the right fix?

A couple of thoughts:

1) I now think that that commit was a bad idea, because it turns out kselftests doesn't make it easy to set up an asm/header.h approach. And this partial approach seems like it won't work at all for syscalls in particular.

I think reverting the commit is appropriate. It doesn't revert cleanly at top of tree, but a very small fix allows a revert.

I'm attaching a patch that does that.

2) I'm unable to reproduce what you saw, because in ALL cases (before or after the commit, and with or without a revert), I get the same results on my Intel test machine:

    $ ./protection_keys_64
    has pkeys: 0
    running PKEY tests for unsupported CPU/OS

...so that's why I'm attaching a patch, in case you can verify that a revert fixes it.

thanks,

Signature · 1 line
John Hubbard

From 7f24274ccf3dfe7c66f4b50e353211ba3ade8f34 Mon Sep 17 00:00:00 2001
From: John Hubbard <[email protected]>
Date: Wed, 12 Feb 2025 23:38:21 -0800
Subject: [PATCH] Revert "selftests/mm: remove local __NR_* definitions"
X-NVConfidentiality: public
Cc: John Hubbard <[email protected]>

This reverts commit a5c6bc590094a1a73cf6fa3f505e1945d2bf2461 .

Details to follow, if this works. --jhubbard

---
 tools/testing/selftests/mm/hugepage-mremap.c      |  2 +-
 tools/testing/selftests/mm/ksm_functional_tests.c |  8 +++++++-
 tools/testing/selftests/mm/memfd_secret.c         | 14 +++++++++++++-
 tools/testing/selftests/mm/mkdirty.c              |  8 +++++++-
 tools/testing/selftests/mm/mlock2.h               |  1 -
 tools/testing/selftests/mm/protection_keys.c      |  2 +-
 tools/testing/selftests/mm/uffd-common.c          |  4 ++++
 tools/testing/selftests/mm/uffd-stress.c          | 15 ++++++++++++++-
 tools/testing/selftests/mm/uffd-unit-tests.c      | 14 +++++++++++++-
 9 files changed, 60 insertions(+), 8 deletions(-)
tools/testing/selftests/mm/hugepage-mremap.c +1 -1
index ada9156cc497..c463d1c09c9b 100644
@@ -15,7 +15,7 @@
 #define _GNU_SOURCE
 #include <stdlib.h>
 #include <stdio.h>
-#include <asm-generic/unistd.h>
+#include <unistd.h>
 #include <sys/mman.h>
 #include <errno.h>
 #include <fcntl.h> /* Definition of O_* constants */
tools/testing/selftests/mm/ksm_functional_tests.c +7 -1
index 66b4e111b5a2..b61803e36d1c 100644
@@ -11,7 +11,7 @@
 #include <string.h>
 #include <stdbool.h>
 #include <stdint.h>
-#include <asm-generic/unistd.h>
+#include <unistd.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/mman.h>
@@ -369,6 +369,7 @@ static void test_unmerge_discarded(void)
 	munmap(map, size);
 }
 
+#ifdef __NR_userfaultfd
 static void test_unmerge_uffd_wp(void)
 {
 	struct uffdio_writeprotect uffd_writeprotect;
@@ -429,6 +430,7 @@ static void test_unmerge_uffd_wp(void)
 unmap:
 	munmap(map, size);
 }
+#endif
 
 /* Verify that KSM can be enabled / queried with prctl. */
 static void test_prctl(void)
@@ -684,7 +686,9 @@ int main(int argc, char **argv)
 		exit(test_child_ksm());
 	}
 
+#ifdef __NR_userfaultfd
 	tests++;
+#endif
 
 	ksft_print_header();
 	ksft_set_plan(tests);
@@ -696,7 +700,9 @@ int main(int argc, char **argv)
 	test_unmerge();
 	test_unmerge_zero_pages();
 	test_unmerge_discarded();
+#ifdef __NR_userfaultfd
 	test_unmerge_uffd_wp();
+#endif
 
 	test_prot_none();
 
tools/testing/selftests/mm/memfd_secret.c +13 -1
index 74c911aa3aea..9a0597310a76 100644
@@ -17,7 +17,7 @@
 
 #include <stdlib.h>
 #include <string.h>
-#include <asm-generic/unistd.h>
+#include <unistd.h>
 #include <errno.h>
 #include <stdio.h>
 #include <fcntl.h>
@@ -28,6 +28,8 @@
 #define pass(fmt, ...) ksft_test_result_pass(fmt, ##__VA_ARGS__)
 #define skip(fmt, ...) ksft_test_result_skip(fmt, ##__VA_ARGS__)
 
+#ifdef __NR_memfd_secret
+
 #define PATTERN	0x55
 
 static const int prot = PROT_READ | PROT_WRITE;
@@ -332,3 +334,13 @@ int main(int argc, char *argv[])
 
 	ksft_finished();
 }
+
+#else /* __NR_memfd_secret */
+
+int main(int argc, char *argv[])
+{
+	printf("skip: skipping memfd_secret test (missing __NR_memfd_secret)\n");
+	return KSFT_SKIP;
+}
+
+#endif /* __NR_memfd_secret */
tools/testing/selftests/mm/mkdirty.c +7 -1
index af2fce496912..09feeb453646 100644
@@ -9,7 +9,7 @@
  */
 #include <fcntl.h>
 #include <signal.h>
-#include <asm-generic/unistd.h>
+#include <unistd.h>
 #include <string.h>
 #include <errno.h>
 #include <stdlib.h>
@@ -265,6 +265,7 @@ static void test_pte_mapped_thp(void)
 	munmap(mmap_mem, mmap_size);
 }
 
+#ifdef __NR_userfaultfd
 static void test_uffdio_copy(void)
 {
 	struct uffdio_register uffdio_register;
@@ -322,6 +323,7 @@ static void test_uffdio_copy(void)
 	munmap(dst, pagesize);
 	free(src);
 }
+#endif /* __NR_userfaultfd */
 
 int main(void)
 {
@@ -334,7 +336,9 @@ int main(void)
 			       thpsize / 1024);
 		tests += 3;
 	}
+#ifdef __NR_userfaultfd
 	tests += 1;
+#endif /* __NR_userfaultfd */
 
 	ksft_print_header();
 	ksft_set_plan(tests);
@@ -364,7 +368,9 @@ int main(void)
 	if (thpsize)
 		test_pte_mapped_thp();
 	/* Placing a fresh page via userfaultfd may set the PTE dirty. */
+#ifdef __NR_userfaultfd
 	test_uffdio_copy();
+#endif /* __NR_userfaultfd */
 
 	err = ksft_get_fail_cnt();
 	if (err)
tools/testing/selftests/mm/mlock2.h +0 -1
index 1e5731bab499..4417eaa5cfb7 100644
@@ -3,7 +3,6 @@
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <asm-generic/unistd.h>
 
 static int mlock2_(void *start, size_t len, int flags)
 {
tools/testing/selftests/mm/protection_keys.c +1 -1
index a4683f2476f2..35565af308af 100644
@@ -42,7 +42,7 @@
 #include <sys/wait.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <asm-generic/unistd.h>
+#include <unistd.h>
 #include <sys/ptrace.h>
 #include <setjmp.h>
 
tools/testing/selftests/mm/uffd-common.c +4 -0
index 717539eddf98..7ad6ba660c7d 100644
@@ -673,7 +673,11 @@ int uffd_open_dev(unsigned int flags)
 
 int uffd_open_sys(unsigned int flags)
 {
+#ifdef __NR_userfaultfd
 	return syscall(__NR_userfaultfd, flags);
+#else
+	return -1;
+#endif
 }
 
 int uffd_open(unsigned int flags)
tools/testing/selftests/mm/uffd-stress.c +14 -1
index a4b83280998a..944d559ade21 100644
@@ -33,10 +33,11 @@
  * pthread_mutex_lock will also verify the atomicity of the memory
  * transfer (UFFDIO_COPY).
  */
-#include <asm-generic/unistd.h>
+
 #include "uffd-common.h"
 
 uint64_t features;
+#ifdef __NR_userfaultfd
 
 #define BOUNCE_RANDOM		(1<<0)
 #define BOUNCE_RACINGFAULTS	(1<<1)
@@ -471,3 +472,15 @@ int main(int argc, char **argv)
 	       nr_pages, nr_pages_per_cpu);
 	return userfaultfd_stress();
 }
+
+#else /* __NR_userfaultfd */
+
+#warning "missing __NR_userfaultfd definition"
+
+int main(void)
+{
+	printf("skip: Skipping userfaultfd test (missing __NR_userfaultfd)\n");
+	return KSFT_SKIP;
+}
+
+#endif /* __NR_userfaultfd */
tools/testing/selftests/mm/uffd-unit-tests.c +13 -1
index 9ff71fa1f9bf..74c8bc02b506 100644
@@ -5,11 +5,12 @@
  *  Copyright (C) 2015-2023  Red Hat, Inc.
  */
 
-#include <asm-generic/unistd.h>
 #include "uffd-common.h"
 
 #include "../../../../mm/gup_test.h"
 
+#ifdef __NR_userfaultfd
+
 /* The unit test doesn't need a large or random size, make it 32MB for now */
 #define  UFFD_TEST_MEM_SIZE               (32UL << 20)
 
@@ -1558,3 +1559,14 @@ int main(int argc, char *argv[])
 	return ksft_get_fail_cnt() ? KSFT_FAIL : KSFT_PASS;
 }
 
+#else /* __NR_userfaultfd */
+
+#warning "missing __NR_userfaultfd definition"
+
+int main(void)
+{
+	printf("Skipping %s (missing __NR_userfaultfd)\n", __file__);
+	return KSFT_SKIP;
+}
+
+#endif /* __NR_userfaultfd */
Signature · 1 line
2.48.1
#24 lore raw

Re: [PATCH v2 6/6] selftests/mm: remove local __NR_* definitions

Quoted 11 lines · John Hubbard

2) I'm unable to reproduce what you saw, because in ALL cases (before or after the commit, and with or without a revert), I get the same results on my Intel test machine:

    $ ./protection_keys_64
    has pkeys: 0
    running PKEY tests for unsupported CPU/OS

...so that's why I'm attaching a patch, in case you can verify that a revert fixes it.

The revert fixes it for me, thanks!

You probably just have hardware without pkey support. This isn't 100% definitive, but you can check:

cat /proc/cpuinfo | grep ospke

If that doesn't match the "flags" line, then your hardware doesn't have support in the first place and the message is totally expected.