2024-06-08 02:10:40

by John Hubbard

[permalink] [raw]
Subject: [PATCH 0/5] cleanups, fixes, and progress towards avoiding "make headers"

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:

1. Add __NR_mseal.

2. Add fs.h, taken as usual from a snapshot of ./usr/include/linux/fs.h
after running "make headers". This is how we have agreed to do this sort
of thing, see [1].

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

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

John Hubbard (5):
selftests/mm: mseal, self_elf: fix missing __NR_mseal
selftests/mm: fix vm_util.c build failures: add snapshot of fs.h
mm/selftests: kvm, mdwe fixes to avoid requiring "make headers"
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

tools/include/uapi/linux/fs.h | 392 +++++++++++++++++++++
tools/testing/selftests/mm/mdwe_test.c | 1 +
tools/testing/selftests/mm/mseal_helpers.h | 45 +++
tools/testing/selftests/mm/mseal_test.c | 141 +++-----
tools/testing/selftests/mm/seal_elf.c | 35 +-
tools/testing/selftests/mm/vm_util.h | 15 +
6 files changed, 502 insertions(+), 127 deletions(-)
create mode 100644 tools/include/uapi/linux/fs.h
create mode 100644 tools/testing/selftests/mm/mseal_helpers.h


base-commit: 8a92980606e3585d72d510a03b59906e96755b8a
--
2.45.2



2024-06-08 02:10:55

by John Hubbard

[permalink] [raw]
Subject: [PATCH 1/5] 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 __NR_mseal, to a new mseal_helpers.h file. That file is
small right now, but subsequent patches will add a lot more content to
it.

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

Fixes: 4926c7a52de7 ("selftest mm/mseal memory sealing")
Cc: Jeff Xu <[email protected]>
Signed-off-by: John Hubbard <[email protected]>
---
tools/testing/selftests/mm/mseal_helpers.h | 5 +++++
tools/testing/selftests/mm/mseal_test.c | 1 +
tools/testing/selftests/mm/seal_elf.c | 1 +
3 files changed, 7 insertions(+)
create mode 100644 tools/testing/selftests/mm/mseal_helpers.h

diff --git a/tools/testing/selftests/mm/mseal_helpers.h b/tools/testing/selftests/mm/mseal_helpers.h
new file mode 100644
index 000000000000..b922d453a014
--- /dev/null
+++ b/tools/testing/selftests/mm/mseal_helpers.h
@@ -0,0 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __NR_mseal
+#define __NR_mseal 462
+#endif
diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c
index 41998cf1dcf5..20949617a036 100644
--- a/tools/testing/selftests/mm/mseal_test.c
+++ b/tools/testing/selftests/mm/mseal_test.c
@@ -17,6 +17,7 @@
#include <sys/ioctl.h>
#include <sys/vfs.h>
#include <sys/stat.h>
+#include "mseal_helpers.h"

/*
* need those definition for manually build using gcc.
diff --git a/tools/testing/selftests/mm/seal_elf.c b/tools/testing/selftests/mm/seal_elf.c
index f2babec79bb6..4053951a535c 100644
--- a/tools/testing/selftests/mm/seal_elf.c
+++ b/tools/testing/selftests/mm/seal_elf.c
@@ -16,6 +16,7 @@
#include <sys/ioctl.h>
#include <sys/vfs.h>
#include <sys/stat.h>
+#include "mseal_helpers.h"

/*
* need those definition for manually build using gcc.
--
2.45.2


2024-06-08 02:11:05

by John Hubbard

[permalink] [raw]
Subject: [PATCH 2/5] selftests/mm: fix vm_util.c build failures: add snapshot of fs.h

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")

Signed-off-by: John Hubbard <[email protected]>
---
tools/include/uapi/linux/fs.h | 392 ++++++++++++++++++++++++++++++++++
1 file changed, 392 insertions(+)
create mode 100644 tools/include/uapi/linux/fs.h

diff --git a/tools/include/uapi/linux/fs.h b/tools/include/uapi/linux/fs.h
new file mode 100644
index 000000000000..ca9d754bae04
--- /dev/null
+++ b/tools/include/uapi/linux/fs.h
@@ -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 */
--
2.45.2


2024-06-08 02:11:11

by John Hubbard

[permalink] [raw]
Subject: [PATCH 3/5] mm/selftests: kvm, mdwe fixes to avoid requiring "make headers"

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.

Signed-off-by: John Hubbard <[email protected]>
---
tools/testing/selftests/mm/mdwe_test.c | 1 +
tools/testing/selftests/mm/vm_util.h | 15 +++++++++++++++
2 files changed, 16 insertions(+)

diff --git a/tools/testing/selftests/mm/mdwe_test.c b/tools/testing/selftests/mm/mdwe_test.c
index 200bedcdc32e..cfe0b64d1567 100644
--- a/tools/testing/selftests/mm/mdwe_test.c
+++ b/tools/testing/selftests/mm/mdwe_test.c
@@ -15,6 +15,7 @@
#include <unistd.h>

#include "../kselftest_harness.h"
+#include "vm_util.h"

#ifndef __aarch64__
# define PROT_BTI 0
diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
index 9007c420d52c..99cbb7c0ea9d 100644
--- a/tools/testing/selftests/mm/vm_util.h
+++ b/tools/testing/selftests/mm/vm_util.h
@@ -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
--
2.45.2


2024-06-08 02:11:16

by John Hubbard

[permalink] [raw]
Subject: [PATCH 4/5] selftests/mm: mseal, self_elf: factor out test macros and other duplicated items

Clean up and move some copy-pasted items into 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]>
Signed-off-by: John Hubbard <[email protected]>
---
tools/testing/selftests/mm/mseal_helpers.h | 40 ++++++++++++++++++
tools/testing/selftests/mm/mseal_test.c | 48 ----------------------
tools/testing/selftests/mm/seal_elf.c | 32 ---------------
3 files changed, 40 insertions(+), 80 deletions(-)

diff --git a/tools/testing/selftests/mm/mseal_helpers.h b/tools/testing/selftests/mm/mseal_helpers.h
index b922d453a014..8c3bf77dcf19 100644
--- a/tools/testing/selftests/mm/mseal_helpers.h
+++ b/tools/testing/selftests/mm/mseal_helpers.h
@@ -3,3 +3,43 @@
#ifndef __NR_mseal
#define __NR_mseal 462
#endif
+
+#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
diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c
index 20949617a036..a29935d82027 100644
--- a/tools/testing/selftests/mm/mseal_test.c
+++ b/tools/testing/selftests/mm/mseal_test.c
@@ -19,54 +19,6 @@
#include <sys/stat.h>
#include "mseal_helpers.h"

-/*
- * need those definition for manually build using gcc.
- * gcc -I ../../../../usr/include -DDEBUG -O3 -DDEBUG -O3 mseal_test.c -o mseal_test
- */
-#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
-
-#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
-
static unsigned long get_vma_size(void *addr, int *prot)
{
FILE *maps;
diff --git a/tools/testing/selftests/mm/seal_elf.c b/tools/testing/selftests/mm/seal_elf.c
index 4053951a535c..0fd129259647 100644
--- a/tools/testing/selftests/mm/seal_elf.c
+++ b/tools/testing/selftests/mm/seal_elf.c
@@ -18,38 +18,6 @@
#include <sys/stat.h>
#include "mseal_helpers.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
-
/*
* define sys_xyx to call syscall directly.
*/
--
2.45.2


2024-06-08 02:11:59

by John Hubbard

[permalink] [raw]
Subject: [PATCH 5/5] selftests/mm: mseal, self_elf: rename TEST_END_CHECK to REPORT_TEST_PASS

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.

Cc: Jeff Xu <[email protected]>
Signed-off-by: John Hubbard <[email protected]>
---
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(-)

diff --git a/tools/testing/selftests/mm/mseal_helpers.h b/tools/testing/selftests/mm/mseal_helpers.h
index 8c3bf77dcf19..65ece62fdd0c 100644
--- a/tools/testing/selftests/mm/mseal_helpers.h
+++ b/tools/testing/selftests/mm/mseal_helpers.h
@@ -22,7 +22,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
diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c
index a29935d82027..f8e1c59f298e 100644
--- a/tools/testing/selftests/mm/mseal_test.c
+++ b/tools/testing/selftests/mm/mseal_test.c
@@ -240,7 +240,7 @@ static void test_seal_addseal(void)
ret = sys_mseal(ptr, size);
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_unmapped_start(void)
@@ -268,7 +268,7 @@ static void test_seal_unmapped_start(void)
ret = sys_mseal(ptr + 2 * page_size, 2 * page_size);
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_unmapped_middle(void)
@@ -300,7 +300,7 @@ static void test_seal_unmapped_middle(void)
ret = sys_mseal(ptr + 3 * page_size, page_size);
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_unmapped_end(void)
@@ -329,7 +329,7 @@ static void test_seal_unmapped_end(void)
ret = sys_mseal(ptr, 2 * page_size);
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_multiple_vmas(void)
@@ -360,7 +360,7 @@ static void test_seal_multiple_vmas(void)
ret = sys_mseal(ptr, size);
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_split_start(void)
@@ -385,7 +385,7 @@ static void test_seal_split_start(void)
ret = sys_mseal(ptr + page_size, 3 * page_size);
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_split_end(void)
@@ -410,7 +410,7 @@ static void test_seal_split_end(void)
ret = sys_mseal(ptr, 3 * page_size);
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_invalid_input(void)
@@ -445,7 +445,7 @@ static void test_seal_invalid_input(void)
ret = sys_mseal(ptr - page_size, 5 * page_size);
FAIL_TEST_IF_FALSE(ret < 0);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_zero_length(void)
@@ -469,7 +469,7 @@ static void test_seal_zero_length(void)
ret = sys_mprotect(ptr, size, PROT_READ | PROT_WRITE);
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_zero_address(void)
@@ -495,7 +495,7 @@ static void test_seal_zero_address(void)
ret = sys_mprotect(ptr, size, PROT_READ | PROT_WRITE);
FAIL_TEST_IF_FALSE(ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_twice(void)
@@ -515,7 +515,7 @@ static void test_seal_twice(void)
ret = sys_mseal(ptr, size);
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mprotect(bool seal)
@@ -539,7 +539,7 @@ static void test_seal_mprotect(bool seal)
else
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_start_mprotect(bool seal)
@@ -569,7 +569,7 @@ static void test_seal_start_mprotect(bool seal)
PROT_READ | PROT_WRITE);
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_end_mprotect(bool seal)
@@ -599,7 +599,7 @@ static void test_seal_end_mprotect(bool seal)
else
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mprotect_unalign_len(bool seal)
@@ -628,7 +628,7 @@ static void test_seal_mprotect_unalign_len(bool seal)
PROT_READ | PROT_WRITE);
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mprotect_unalign_len_variant_2(bool seal)
@@ -656,7 +656,7 @@ static void test_seal_mprotect_unalign_len_variant_2(bool seal)
PROT_READ | PROT_WRITE);
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mprotect_two_vma(bool seal)
@@ -691,7 +691,7 @@ static void test_seal_mprotect_two_vma(bool seal)
else
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mprotect_two_vma_with_split(bool seal)
@@ -738,7 +738,7 @@ static void test_seal_mprotect_two_vma_with_split(bool seal)
PROT_READ | PROT_WRITE);
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mprotect_partial_mprotect(bool seal)
@@ -764,7 +764,7 @@ static void test_seal_mprotect_partial_mprotect(bool seal)
else
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mprotect_two_vma_with_gap(bool seal)
@@ -807,7 +807,7 @@ static void test_seal_mprotect_two_vma_with_gap(bool seal)
ret = sys_mprotect(ptr + 3 * page_size, page_size, PROT_READ);
FAIL_TEST_IF_FALSE(ret == 0);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mprotect_split(bool seal)
@@ -844,7 +844,7 @@ static void test_seal_mprotect_split(bool seal)
else
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mprotect_merge(bool seal)
@@ -878,7 +878,7 @@ static void test_seal_mprotect_merge(bool seal)
ret = sys_mprotect(ptr + 2 * page_size, 2 * page_size, PROT_READ);
FAIL_TEST_IF_FALSE(ret == 0);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_munmap(bool seal)
@@ -903,7 +903,7 @@ static void test_seal_munmap(bool seal)
else
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

/*
@@ -943,7 +943,7 @@ static void test_seal_munmap_two_vma(bool seal)
else
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

/*
@@ -981,7 +981,7 @@ static void test_seal_munmap_vma_with_gap(bool seal)
ret = sys_munmap(ptr, size);
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_munmap_start_freed(bool seal)
@@ -1021,7 +1021,7 @@ static void test_munmap_start_freed(bool seal)
FAIL_TEST_IF_FALSE(size == 0);
}

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_munmap_end_freed(bool seal)
@@ -1051,7 +1051,7 @@ static void test_munmap_end_freed(bool seal)
else
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_munmap_middle_freed(bool seal)
@@ -1095,7 +1095,7 @@ static void test_munmap_middle_freed(bool seal)
FAIL_TEST_IF_FALSE(size == 0);
}

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mremap_shrink(bool seal)
@@ -1124,7 +1124,7 @@ static void test_seal_mremap_shrink(bool seal)

}

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mremap_expand(bool seal)
@@ -1156,7 +1156,7 @@ static void test_seal_mremap_expand(bool seal)

}

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mremap_move(bool seal)
@@ -1189,7 +1189,7 @@ static void test_seal_mremap_move(bool seal)

}

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mmap_overwrite_prot(bool seal)
@@ -1217,7 +1217,7 @@ static void test_seal_mmap_overwrite_prot(bool seal)
} else
FAIL_TEST_IF_FALSE(ret2 == ptr);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mmap_expand(bool seal)
@@ -1248,7 +1248,7 @@ static void test_seal_mmap_expand(bool seal)
} else
FAIL_TEST_IF_FALSE(ret2 == ptr);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mmap_shrink(bool seal)
@@ -1276,7 +1276,7 @@ static void test_seal_mmap_shrink(bool seal)
} else
FAIL_TEST_IF_FALSE(ret2 == ptr);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mremap_shrink_fixed(bool seal)
@@ -1307,7 +1307,7 @@ static void test_seal_mremap_shrink_fixed(bool seal)
} else
FAIL_TEST_IF_FALSE(ret2 == newAddr);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mremap_expand_fixed(bool seal)
@@ -1338,7 +1338,7 @@ static void test_seal_mremap_expand_fixed(bool seal)
} else
FAIL_TEST_IF_FALSE(ret2 == newAddr);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mremap_move_fixed(bool seal)
@@ -1368,7 +1368,7 @@ static void test_seal_mremap_move_fixed(bool seal)
} else
FAIL_TEST_IF_FALSE(ret2 == newAddr);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mremap_move_fixed_zero(bool seal)
@@ -1400,7 +1400,7 @@ static void test_seal_mremap_move_fixed_zero(bool seal)

}

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mremap_move_dontunmap(bool seal)
@@ -1429,7 +1429,7 @@ static void test_seal_mremap_move_dontunmap(bool seal)

}

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_mremap_move_dontunmap_anyaddr(bool seal)
@@ -1463,7 +1463,7 @@ static void test_seal_mremap_move_dontunmap_anyaddr(bool seal)

}

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}


@@ -1556,7 +1556,7 @@ static void test_seal_merge_and_split(void)
FAIL_TEST_IF_FALSE(size == 22 * page_size);
FAIL_TEST_IF_FALSE(prot == 0x4);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_discard_ro_anon_on_rw(bool seal)
@@ -1585,7 +1585,7 @@ static void test_seal_discard_ro_anon_on_rw(bool seal)
else
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_discard_ro_anon_on_pkey(bool seal)
@@ -1632,7 +1632,7 @@ static void test_seal_discard_ro_anon_on_pkey(bool seal)
else
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_discard_ro_anon_on_filebacked(bool seal)
@@ -1669,7 +1669,7 @@ static void test_seal_discard_ro_anon_on_filebacked(bool seal)
FAIL_TEST_IF_FALSE(!ret);
close(fd);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_discard_ro_anon_on_shared(bool seal)
@@ -1698,7 +1698,7 @@ static void test_seal_discard_ro_anon_on_shared(bool seal)
else
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

static void test_seal_discard_ro_anon(bool seal)
@@ -1728,7 +1728,7 @@ static void test_seal_discard_ro_anon(bool seal)
else
FAIL_TEST_IF_FALSE(!ret);

- TEST_END_CHECK();
+ REPORT_TEST_PASS();
}

int main(int argc, char **argv)
diff --git a/tools/testing/selftests/mm/seal_elf.c b/tools/testing/selftests/mm/seal_elf.c
index 0fd129259647..131fc13cd422 100644
--- a/tools/testing/selftests/mm/seal_elf.c
+++ b/tools/testing/selftests/mm/seal_elf.c
@@ -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)
--
2.45.2


2024-06-08 02:16:24

by John Hubbard

[permalink] [raw]
Subject: Re: [PATCH 3/5] mm/selftests: kvm, mdwe fixes to avoid requiring "make headers"

On 6/7/24 7:10 PM, John Hubbard wrote:
> 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:

The subject line is confused: it really should start with "selftests/mm",
not "mm/selftests". :)


thanks,
John Hubbard
NVIDIA

>
> 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.
>
> Signed-off-by: John Hubbard <[email protected]>
> ---
> tools/testing/selftests/mm/mdwe_test.c | 1 +
> tools/testing/selftests/mm/vm_util.h | 15 +++++++++++++++
> 2 files changed, 16 insertions(+)
>
> diff --git a/tools/testing/selftests/mm/mdwe_test.c b/tools/testing/selftests/mm/mdwe_test.c
> index 200bedcdc32e..cfe0b64d1567 100644
> --- a/tools/testing/selftests/mm/mdwe_test.c
> +++ b/tools/testing/selftests/mm/mdwe_test.c
> @@ -15,6 +15,7 @@
> #include <unistd.h>
>
> #include "../kselftest_harness.h"
> +#include "vm_util.h"
>
> #ifndef __aarch64__
> # define PROT_BTI 0
> diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
> index 9007c420d52c..99cbb7c0ea9d 100644
> --- a/tools/testing/selftests/mm/vm_util.h
> +++ b/tools/testing/selftests/mm/vm_util.h
> @@ -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


2024-06-11 04:21:34

by Jeff Xu

[permalink] [raw]
Subject: Re: [PATCH 0/5] cleanups, fixes, and progress towards avoiding "make headers"

Hi


On Fri, Jun 7, 2024 at 7:10 PM John Hubbard <[email protected]> wrote:
>
> 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:
>
> 1. Add __NR_mseal.
>
> 2. Add fs.h, taken as usual from a snapshot of ./usr/include/linux/fs.h
> after running "make headers". This is how we have agreed to do this sort
> of thing, see [1].
>
What is the "official" way to build selftests/mm ?
I tried a few ways, but it never worked, i.e. due to head missing.

1>
cd tools/testing/selftests/mm
make

migration.c:10:10: fatal error: numa.h: No such file or directory
10 | #include <numa.h>
| ^~~~~~~~
compilation terminated.

2>
make headers
make -C tools/testing/selftests

make[1]: Entering directory
'/usr/local/google/home/jeffxu/mm/tools/testing/selftests/mm'
CC migration
migration.c:10:10: fatal error: numa.h: No such file or directory
10 | #include <numa.h>

Thanks!
-Jeff

2024-06-11 04:26:32

by Jeff Xu

[permalink] [raw]
Subject: Re: [PATCH 1/5] selftests/mm: mseal, self_elf: fix missing __NR_mseal

Hi

On Fri, Jun 7, 2024 at 7:10 PM John Hubbard <[email protected]> wrote:
>
> 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 __NR_mseal, to a new mseal_helpers.h file. That file is
> small right now, but subsequent patches will add a lot more content to
> it.
>
> [1] commit e076eaca5906 ("selftests: break the dependency upon local
> header files")
>
> Fixes: 4926c7a52de7 ("selftest mm/mseal memory sealing")
> Cc: Jeff Xu <[email protected]>
> Signed-off-by: John Hubbard <[email protected]>

Reviewed-by: Jeff Xu <[email protected]>
Tested-by: Jeff Xu <[email protected]>

> ---
> tools/testing/selftests/mm/mseal_helpers.h | 5 +++++
> tools/testing/selftests/mm/mseal_test.c | 1 +
> tools/testing/selftests/mm/seal_elf.c | 1 +
> 3 files changed, 7 insertions(+)
> create mode 100644 tools/testing/selftests/mm/mseal_helpers.h
>
> diff --git a/tools/testing/selftests/mm/mseal_helpers.h b/tools/testing/selftests/mm/mseal_helpers.h
> new file mode 100644
> index 000000000000..b922d453a014
> --- /dev/null
> +++ b/tools/testing/selftests/mm/mseal_helpers.h
> @@ -0,0 +1,5 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#ifndef __NR_mseal
> +#define __NR_mseal 462
> +#endif
> diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c
> index 41998cf1dcf5..20949617a036 100644
> --- a/tools/testing/selftests/mm/mseal_test.c
> +++ b/tools/testing/selftests/mm/mseal_test.c
> @@ -17,6 +17,7 @@
> #include <sys/ioctl.h>
> #include <sys/vfs.h>
> #include <sys/stat.h>
> +#include "mseal_helpers.h"
>
> /*
> * need those definition for manually build using gcc.
> diff --git a/tools/testing/selftests/mm/seal_elf.c b/tools/testing/selftests/mm/seal_elf.c
> index f2babec79bb6..4053951a535c 100644
> --- a/tools/testing/selftests/mm/seal_elf.c
> +++ b/tools/testing/selftests/mm/seal_elf.c
> @@ -16,6 +16,7 @@
> #include <sys/ioctl.h>
> #include <sys/vfs.h>
> #include <sys/stat.h>
> +#include "mseal_helpers.h"
>
> /*
> * need those definition for manually build using gcc.
> --
> 2.45.2
>

2024-06-11 04:28:19

by Jeff Xu

[permalink] [raw]
Subject: Re: [PATCH 4/5] selftests/mm: mseal, self_elf: factor out test macros and other duplicated items

On Fri, Jun 7, 2024 at 7:10 PM John Hubbard <[email protected]> wrote:
>
> Clean up and move some copy-pasted items into 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]>
> Signed-off-by: John Hubbard <[email protected]>

Reviewed-by: Jeff Xu <[email protected]>
Tested-by: Jeff Xu <[email protected]>

> ---
> tools/testing/selftests/mm/mseal_helpers.h | 40 ++++++++++++++++++
> tools/testing/selftests/mm/mseal_test.c | 48 ----------------------
> tools/testing/selftests/mm/seal_elf.c | 32 ---------------
> 3 files changed, 40 insertions(+), 80 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/mseal_helpers.h b/tools/testing/selftests/mm/mseal_helpers.h
> index b922d453a014..8c3bf77dcf19 100644
> --- a/tools/testing/selftests/mm/mseal_helpers.h
> +++ b/tools/testing/selftests/mm/mseal_helpers.h
> @@ -3,3 +3,43 @@
> #ifndef __NR_mseal
> #define __NR_mseal 462
> #endif
> +
> +#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
> diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c
> index 20949617a036..a29935d82027 100644
> --- a/tools/testing/selftests/mm/mseal_test.c
> +++ b/tools/testing/selftests/mm/mseal_test.c
> @@ -19,54 +19,6 @@
> #include <sys/stat.h>
> #include "mseal_helpers.h"
>
> -/*
> - * need those definition for manually build using gcc.
> - * gcc -I ../../../../usr/include -DDEBUG -O3 -DDEBUG -O3 mseal_test.c -o mseal_test
> - */
> -#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
> -
> -#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
> -
> static unsigned long get_vma_size(void *addr, int *prot)
> {
> FILE *maps;
> diff --git a/tools/testing/selftests/mm/seal_elf.c b/tools/testing/selftests/mm/seal_elf.c
> index 4053951a535c..0fd129259647 100644
> --- a/tools/testing/selftests/mm/seal_elf.c
> +++ b/tools/testing/selftests/mm/seal_elf.c
> @@ -18,38 +18,6 @@
> #include <sys/stat.h>
> #include "mseal_helpers.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
> -
> /*
> * define sys_xyx to call syscall directly.
> */
> --
> 2.45.2
>

2024-06-11 04:29:12

by Jeff Xu

[permalink] [raw]
Subject: Re: [PATCH 5/5] selftests/mm: mseal, self_elf: rename TEST_END_CHECK to REPORT_TEST_PASS

Hi

On Fri, Jun 7, 2024 at 7:10 PM John Hubbard <[email protected]> wrote:
>
> 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.
>
> Cc: Jeff Xu <[email protected]>
> Signed-off-by: John Hubbard <[email protected]>

Reviewed-by: Jeff Xu <[email protected]>
Tested-by: Jeff Xu <[email protected]>

> ---
> 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(-)
>
> diff --git a/tools/testing/selftests/mm/mseal_helpers.h b/tools/testing/selftests/mm/mseal_helpers.h
> index 8c3bf77dcf19..65ece62fdd0c 100644
> --- a/tools/testing/selftests/mm/mseal_helpers.h
> +++ b/tools/testing/selftests/mm/mseal_helpers.h
> @@ -22,7 +22,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
> diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c
> index a29935d82027..f8e1c59f298e 100644
> --- a/tools/testing/selftests/mm/mseal_test.c
> +++ b/tools/testing/selftests/mm/mseal_test.c
> @@ -240,7 +240,7 @@ static void test_seal_addseal(void)
> ret = sys_mseal(ptr, size);
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_unmapped_start(void)
> @@ -268,7 +268,7 @@ static void test_seal_unmapped_start(void)
> ret = sys_mseal(ptr + 2 * page_size, 2 * page_size);
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_unmapped_middle(void)
> @@ -300,7 +300,7 @@ static void test_seal_unmapped_middle(void)
> ret = sys_mseal(ptr + 3 * page_size, page_size);
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_unmapped_end(void)
> @@ -329,7 +329,7 @@ static void test_seal_unmapped_end(void)
> ret = sys_mseal(ptr, 2 * page_size);
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_multiple_vmas(void)
> @@ -360,7 +360,7 @@ static void test_seal_multiple_vmas(void)
> ret = sys_mseal(ptr, size);
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_split_start(void)
> @@ -385,7 +385,7 @@ static void test_seal_split_start(void)
> ret = sys_mseal(ptr + page_size, 3 * page_size);
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_split_end(void)
> @@ -410,7 +410,7 @@ static void test_seal_split_end(void)
> ret = sys_mseal(ptr, 3 * page_size);
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_invalid_input(void)
> @@ -445,7 +445,7 @@ static void test_seal_invalid_input(void)
> ret = sys_mseal(ptr - page_size, 5 * page_size);
> FAIL_TEST_IF_FALSE(ret < 0);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_zero_length(void)
> @@ -469,7 +469,7 @@ static void test_seal_zero_length(void)
> ret = sys_mprotect(ptr, size, PROT_READ | PROT_WRITE);
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_zero_address(void)
> @@ -495,7 +495,7 @@ static void test_seal_zero_address(void)
> ret = sys_mprotect(ptr, size, PROT_READ | PROT_WRITE);
> FAIL_TEST_IF_FALSE(ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_twice(void)
> @@ -515,7 +515,7 @@ static void test_seal_twice(void)
> ret = sys_mseal(ptr, size);
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mprotect(bool seal)
> @@ -539,7 +539,7 @@ static void test_seal_mprotect(bool seal)
> else
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_start_mprotect(bool seal)
> @@ -569,7 +569,7 @@ static void test_seal_start_mprotect(bool seal)
> PROT_READ | PROT_WRITE);
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_end_mprotect(bool seal)
> @@ -599,7 +599,7 @@ static void test_seal_end_mprotect(bool seal)
> else
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mprotect_unalign_len(bool seal)
> @@ -628,7 +628,7 @@ static void test_seal_mprotect_unalign_len(bool seal)
> PROT_READ | PROT_WRITE);
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mprotect_unalign_len_variant_2(bool seal)
> @@ -656,7 +656,7 @@ static void test_seal_mprotect_unalign_len_variant_2(bool seal)
> PROT_READ | PROT_WRITE);
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mprotect_two_vma(bool seal)
> @@ -691,7 +691,7 @@ static void test_seal_mprotect_two_vma(bool seal)
> else
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mprotect_two_vma_with_split(bool seal)
> @@ -738,7 +738,7 @@ static void test_seal_mprotect_two_vma_with_split(bool seal)
> PROT_READ | PROT_WRITE);
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mprotect_partial_mprotect(bool seal)
> @@ -764,7 +764,7 @@ static void test_seal_mprotect_partial_mprotect(bool seal)
> else
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mprotect_two_vma_with_gap(bool seal)
> @@ -807,7 +807,7 @@ static void test_seal_mprotect_two_vma_with_gap(bool seal)
> ret = sys_mprotect(ptr + 3 * page_size, page_size, PROT_READ);
> FAIL_TEST_IF_FALSE(ret == 0);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mprotect_split(bool seal)
> @@ -844,7 +844,7 @@ static void test_seal_mprotect_split(bool seal)
> else
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mprotect_merge(bool seal)
> @@ -878,7 +878,7 @@ static void test_seal_mprotect_merge(bool seal)
> ret = sys_mprotect(ptr + 2 * page_size, 2 * page_size, PROT_READ);
> FAIL_TEST_IF_FALSE(ret == 0);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_munmap(bool seal)
> @@ -903,7 +903,7 @@ static void test_seal_munmap(bool seal)
> else
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> /*
> @@ -943,7 +943,7 @@ static void test_seal_munmap_two_vma(bool seal)
> else
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> /*
> @@ -981,7 +981,7 @@ static void test_seal_munmap_vma_with_gap(bool seal)
> ret = sys_munmap(ptr, size);
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_munmap_start_freed(bool seal)
> @@ -1021,7 +1021,7 @@ static void test_munmap_start_freed(bool seal)
> FAIL_TEST_IF_FALSE(size == 0);
> }
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_munmap_end_freed(bool seal)
> @@ -1051,7 +1051,7 @@ static void test_munmap_end_freed(bool seal)
> else
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_munmap_middle_freed(bool seal)
> @@ -1095,7 +1095,7 @@ static void test_munmap_middle_freed(bool seal)
> FAIL_TEST_IF_FALSE(size == 0);
> }
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mremap_shrink(bool seal)
> @@ -1124,7 +1124,7 @@ static void test_seal_mremap_shrink(bool seal)
>
> }
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mremap_expand(bool seal)
> @@ -1156,7 +1156,7 @@ static void test_seal_mremap_expand(bool seal)
>
> }
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mremap_move(bool seal)
> @@ -1189,7 +1189,7 @@ static void test_seal_mremap_move(bool seal)
>
> }
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mmap_overwrite_prot(bool seal)
> @@ -1217,7 +1217,7 @@ static void test_seal_mmap_overwrite_prot(bool seal)
> } else
> FAIL_TEST_IF_FALSE(ret2 == ptr);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mmap_expand(bool seal)
> @@ -1248,7 +1248,7 @@ static void test_seal_mmap_expand(bool seal)
> } else
> FAIL_TEST_IF_FALSE(ret2 == ptr);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mmap_shrink(bool seal)
> @@ -1276,7 +1276,7 @@ static void test_seal_mmap_shrink(bool seal)
> } else
> FAIL_TEST_IF_FALSE(ret2 == ptr);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mremap_shrink_fixed(bool seal)
> @@ -1307,7 +1307,7 @@ static void test_seal_mremap_shrink_fixed(bool seal)
> } else
> FAIL_TEST_IF_FALSE(ret2 == newAddr);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mremap_expand_fixed(bool seal)
> @@ -1338,7 +1338,7 @@ static void test_seal_mremap_expand_fixed(bool seal)
> } else
> FAIL_TEST_IF_FALSE(ret2 == newAddr);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mremap_move_fixed(bool seal)
> @@ -1368,7 +1368,7 @@ static void test_seal_mremap_move_fixed(bool seal)
> } else
> FAIL_TEST_IF_FALSE(ret2 == newAddr);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mremap_move_fixed_zero(bool seal)
> @@ -1400,7 +1400,7 @@ static void test_seal_mremap_move_fixed_zero(bool seal)
>
> }
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mremap_move_dontunmap(bool seal)
> @@ -1429,7 +1429,7 @@ static void test_seal_mremap_move_dontunmap(bool seal)
>
> }
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_mremap_move_dontunmap_anyaddr(bool seal)
> @@ -1463,7 +1463,7 @@ static void test_seal_mremap_move_dontunmap_anyaddr(bool seal)
>
> }
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
>
> @@ -1556,7 +1556,7 @@ static void test_seal_merge_and_split(void)
> FAIL_TEST_IF_FALSE(size == 22 * page_size);
> FAIL_TEST_IF_FALSE(prot == 0x4);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_discard_ro_anon_on_rw(bool seal)
> @@ -1585,7 +1585,7 @@ static void test_seal_discard_ro_anon_on_rw(bool seal)
> else
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_discard_ro_anon_on_pkey(bool seal)
> @@ -1632,7 +1632,7 @@ static void test_seal_discard_ro_anon_on_pkey(bool seal)
> else
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_discard_ro_anon_on_filebacked(bool seal)
> @@ -1669,7 +1669,7 @@ static void test_seal_discard_ro_anon_on_filebacked(bool seal)
> FAIL_TEST_IF_FALSE(!ret);
> close(fd);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_discard_ro_anon_on_shared(bool seal)
> @@ -1698,7 +1698,7 @@ static void test_seal_discard_ro_anon_on_shared(bool seal)
> else
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> static void test_seal_discard_ro_anon(bool seal)
> @@ -1728,7 +1728,7 @@ static void test_seal_discard_ro_anon(bool seal)
> else
> FAIL_TEST_IF_FALSE(!ret);
>
> - TEST_END_CHECK();
> + REPORT_TEST_PASS();
> }
>
> int main(int argc, char **argv)
> diff --git a/tools/testing/selftests/mm/seal_elf.c b/tools/testing/selftests/mm/seal_elf.c
> index 0fd129259647..131fc13cd422 100644
> --- a/tools/testing/selftests/mm/seal_elf.c
> +++ b/tools/testing/selftests/mm/seal_elf.c
> @@ -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)
> --
> 2.45.2
>

2024-06-11 04:34:27

by John Hubbard

[permalink] [raw]
Subject: Re: [PATCH 0/5] cleanups, fixes, and progress towards avoiding "make headers"

On 6/10/24 9:21 PM, Jeff Xu wrote:
> Hi
>
>
> On Fri, Jun 7, 2024 at 7:10 PM John Hubbard <[email protected]> wrote:
>>
>> 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:
>>
>> 1. Add __NR_mseal.
>>
>> 2. Add fs.h, taken as usual from a snapshot of ./usr/include/linux/fs.h
>> after running "make headers". This is how we have agreed to do this sort
>> of thing, see [1].
>>
> What is the "official" way to build selftests/mm ?

From Documentation/dev-tools/kselftest.rst, it is:

$ make headers
$ make -C tools/testing/selftests

> I tried a few ways, but it never worked, i.e. due to head missing.

You are correct. Today's rules require "make headers" first. But
I'm working on getting rid of that requirement, because it causes
problems for some people and situations.

(Even worse is the follow-up rule, in today's documentation,
that tells us to *run* the selftests from within Make! This
is just madness. Because the tests need to run as root in
many cases. And Make will try to rebuild if necessary...thus
filling your tree full of root-owned files...but that's for
another time.)

>
> 1>
> cd tools/testing/selftests/mm
> make
>
> migration.c:10:10: fatal error: numa.h: No such file or directory
> 10 | #include <numa.h>
> | ^~~~~~~~
> compilation terminated.
>
> 2>
> make headers
> make -C tools/testing/selftests
>
> make[1]: Entering directory
> '/usr/local/google/home/jeffxu/mm/tools/testing/selftests/mm'
> CC migration
> migration.c:10:10: fatal error: numa.h: No such file or directory
> 10 | #include <numa.h>
>

Well, actually, for these, one should install libnuma-dev and
numactl (those are Ubuntu package names. Arch Linux would be:
numactl).

I think. The idea is: use system headers if they are there, and
local kernel tree header files if the items are so new that they
haven't made it to $OLDEST_DISTO_REASONABLE.

Something like that.

So if you systematically install various packages on your machine,
then apply the various patches that I have floating around, then
you will be able to build selftests/mm without "make headers", at
this point. Or so I claim.

thanks,
--
John Hubbard
NVIDIA


2024-06-11 04:35:30

by John Hubbard

[permalink] [raw]
Subject: Re: [PATCH 5/5] selftests/mm: mseal, self_elf: rename TEST_END_CHECK to REPORT_TEST_PASS

On 6/10/24 9:27 PM, Jeff Xu wrote:
> Hi
>
> On Fri, Jun 7, 2024 at 7:10 PM John Hubbard <[email protected]> wrote:
>>
>> 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.
>>
>> Cc: Jeff Xu <[email protected]>
>> Signed-off-by: John Hubbard <[email protected]>
>
> Reviewed-by: Jeff Xu <[email protected]>
> Tested-by: Jeff Xu <[email protected]>
>

Thanks for the reviews!

thanks,
--
John Hubbard
NVIDIA

>> ---
>> 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(-)
>>
>> diff --git a/tools/testing/selftests/mm/mseal_helpers.h b/tools/testing/selftests/mm/mseal_helpers.h
>> index 8c3bf77dcf19..65ece62fdd0c 100644
>> --- a/tools/testing/selftests/mm/mseal_helpers.h
>> +++ b/tools/testing/selftests/mm/mseal_helpers.h
>> @@ -22,7 +22,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
>> diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c
>> index a29935d82027..f8e1c59f298e 100644
>> --- a/tools/testing/selftests/mm/mseal_test.c
>> +++ b/tools/testing/selftests/mm/mseal_test.c
>> @@ -240,7 +240,7 @@ static void test_seal_addseal(void)
>> ret = sys_mseal(ptr, size);
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_unmapped_start(void)
>> @@ -268,7 +268,7 @@ static void test_seal_unmapped_start(void)
>> ret = sys_mseal(ptr + 2 * page_size, 2 * page_size);
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_unmapped_middle(void)
>> @@ -300,7 +300,7 @@ static void test_seal_unmapped_middle(void)
>> ret = sys_mseal(ptr + 3 * page_size, page_size);
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_unmapped_end(void)
>> @@ -329,7 +329,7 @@ static void test_seal_unmapped_end(void)
>> ret = sys_mseal(ptr, 2 * page_size);
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_multiple_vmas(void)
>> @@ -360,7 +360,7 @@ static void test_seal_multiple_vmas(void)
>> ret = sys_mseal(ptr, size);
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_split_start(void)
>> @@ -385,7 +385,7 @@ static void test_seal_split_start(void)
>> ret = sys_mseal(ptr + page_size, 3 * page_size);
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_split_end(void)
>> @@ -410,7 +410,7 @@ static void test_seal_split_end(void)
>> ret = sys_mseal(ptr, 3 * page_size);
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_invalid_input(void)
>> @@ -445,7 +445,7 @@ static void test_seal_invalid_input(void)
>> ret = sys_mseal(ptr - page_size, 5 * page_size);
>> FAIL_TEST_IF_FALSE(ret < 0);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_zero_length(void)
>> @@ -469,7 +469,7 @@ static void test_seal_zero_length(void)
>> ret = sys_mprotect(ptr, size, PROT_READ | PROT_WRITE);
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_zero_address(void)
>> @@ -495,7 +495,7 @@ static void test_seal_zero_address(void)
>> ret = sys_mprotect(ptr, size, PROT_READ | PROT_WRITE);
>> FAIL_TEST_IF_FALSE(ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_twice(void)
>> @@ -515,7 +515,7 @@ static void test_seal_twice(void)
>> ret = sys_mseal(ptr, size);
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mprotect(bool seal)
>> @@ -539,7 +539,7 @@ static void test_seal_mprotect(bool seal)
>> else
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_start_mprotect(bool seal)
>> @@ -569,7 +569,7 @@ static void test_seal_start_mprotect(bool seal)
>> PROT_READ | PROT_WRITE);
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_end_mprotect(bool seal)
>> @@ -599,7 +599,7 @@ static void test_seal_end_mprotect(bool seal)
>> else
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mprotect_unalign_len(bool seal)
>> @@ -628,7 +628,7 @@ static void test_seal_mprotect_unalign_len(bool seal)
>> PROT_READ | PROT_WRITE);
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mprotect_unalign_len_variant_2(bool seal)
>> @@ -656,7 +656,7 @@ static void test_seal_mprotect_unalign_len_variant_2(bool seal)
>> PROT_READ | PROT_WRITE);
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mprotect_two_vma(bool seal)
>> @@ -691,7 +691,7 @@ static void test_seal_mprotect_two_vma(bool seal)
>> else
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mprotect_two_vma_with_split(bool seal)
>> @@ -738,7 +738,7 @@ static void test_seal_mprotect_two_vma_with_split(bool seal)
>> PROT_READ | PROT_WRITE);
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mprotect_partial_mprotect(bool seal)
>> @@ -764,7 +764,7 @@ static void test_seal_mprotect_partial_mprotect(bool seal)
>> else
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mprotect_two_vma_with_gap(bool seal)
>> @@ -807,7 +807,7 @@ static void test_seal_mprotect_two_vma_with_gap(bool seal)
>> ret = sys_mprotect(ptr + 3 * page_size, page_size, PROT_READ);
>> FAIL_TEST_IF_FALSE(ret == 0);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mprotect_split(bool seal)
>> @@ -844,7 +844,7 @@ static void test_seal_mprotect_split(bool seal)
>> else
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mprotect_merge(bool seal)
>> @@ -878,7 +878,7 @@ static void test_seal_mprotect_merge(bool seal)
>> ret = sys_mprotect(ptr + 2 * page_size, 2 * page_size, PROT_READ);
>> FAIL_TEST_IF_FALSE(ret == 0);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_munmap(bool seal)
>> @@ -903,7 +903,7 @@ static void test_seal_munmap(bool seal)
>> else
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> /*
>> @@ -943,7 +943,7 @@ static void test_seal_munmap_two_vma(bool seal)
>> else
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> /*
>> @@ -981,7 +981,7 @@ static void test_seal_munmap_vma_with_gap(bool seal)
>> ret = sys_munmap(ptr, size);
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_munmap_start_freed(bool seal)
>> @@ -1021,7 +1021,7 @@ static void test_munmap_start_freed(bool seal)
>> FAIL_TEST_IF_FALSE(size == 0);
>> }
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_munmap_end_freed(bool seal)
>> @@ -1051,7 +1051,7 @@ static void test_munmap_end_freed(bool seal)
>> else
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_munmap_middle_freed(bool seal)
>> @@ -1095,7 +1095,7 @@ static void test_munmap_middle_freed(bool seal)
>> FAIL_TEST_IF_FALSE(size == 0);
>> }
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mremap_shrink(bool seal)
>> @@ -1124,7 +1124,7 @@ static void test_seal_mremap_shrink(bool seal)
>>
>> }
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mremap_expand(bool seal)
>> @@ -1156,7 +1156,7 @@ static void test_seal_mremap_expand(bool seal)
>>
>> }
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mremap_move(bool seal)
>> @@ -1189,7 +1189,7 @@ static void test_seal_mremap_move(bool seal)
>>
>> }
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mmap_overwrite_prot(bool seal)
>> @@ -1217,7 +1217,7 @@ static void test_seal_mmap_overwrite_prot(bool seal)
>> } else
>> FAIL_TEST_IF_FALSE(ret2 == ptr);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mmap_expand(bool seal)
>> @@ -1248,7 +1248,7 @@ static void test_seal_mmap_expand(bool seal)
>> } else
>> FAIL_TEST_IF_FALSE(ret2 == ptr);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mmap_shrink(bool seal)
>> @@ -1276,7 +1276,7 @@ static void test_seal_mmap_shrink(bool seal)
>> } else
>> FAIL_TEST_IF_FALSE(ret2 == ptr);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mremap_shrink_fixed(bool seal)
>> @@ -1307,7 +1307,7 @@ static void test_seal_mremap_shrink_fixed(bool seal)
>> } else
>> FAIL_TEST_IF_FALSE(ret2 == newAddr);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mremap_expand_fixed(bool seal)
>> @@ -1338,7 +1338,7 @@ static void test_seal_mremap_expand_fixed(bool seal)
>> } else
>> FAIL_TEST_IF_FALSE(ret2 == newAddr);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mremap_move_fixed(bool seal)
>> @@ -1368,7 +1368,7 @@ static void test_seal_mremap_move_fixed(bool seal)
>> } else
>> FAIL_TEST_IF_FALSE(ret2 == newAddr);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mremap_move_fixed_zero(bool seal)
>> @@ -1400,7 +1400,7 @@ static void test_seal_mremap_move_fixed_zero(bool seal)
>>
>> }
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mremap_move_dontunmap(bool seal)
>> @@ -1429,7 +1429,7 @@ static void test_seal_mremap_move_dontunmap(bool seal)
>>
>> }
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_mremap_move_dontunmap_anyaddr(bool seal)
>> @@ -1463,7 +1463,7 @@ static void test_seal_mremap_move_dontunmap_anyaddr(bool seal)
>>
>> }
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>>
>> @@ -1556,7 +1556,7 @@ static void test_seal_merge_and_split(void)
>> FAIL_TEST_IF_FALSE(size == 22 * page_size);
>> FAIL_TEST_IF_FALSE(prot == 0x4);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_discard_ro_anon_on_rw(bool seal)
>> @@ -1585,7 +1585,7 @@ static void test_seal_discard_ro_anon_on_rw(bool seal)
>> else
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_discard_ro_anon_on_pkey(bool seal)
>> @@ -1632,7 +1632,7 @@ static void test_seal_discard_ro_anon_on_pkey(bool seal)
>> else
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_discard_ro_anon_on_filebacked(bool seal)
>> @@ -1669,7 +1669,7 @@ static void test_seal_discard_ro_anon_on_filebacked(bool seal)
>> FAIL_TEST_IF_FALSE(!ret);
>> close(fd);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_discard_ro_anon_on_shared(bool seal)
>> @@ -1698,7 +1698,7 @@ static void test_seal_discard_ro_anon_on_shared(bool seal)
>> else
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> static void test_seal_discard_ro_anon(bool seal)
>> @@ -1728,7 +1728,7 @@ static void test_seal_discard_ro_anon(bool seal)
>> else
>> FAIL_TEST_IF_FALSE(!ret);
>>
>> - TEST_END_CHECK();
>> + REPORT_TEST_PASS();
>> }
>>
>> int main(int argc, char **argv)
>> diff --git a/tools/testing/selftests/mm/seal_elf.c b/tools/testing/selftests/mm/seal_elf.c
>> index 0fd129259647..131fc13cd422 100644
>> --- a/tools/testing/selftests/mm/seal_elf.c
>> +++ b/tools/testing/selftests/mm/seal_elf.c
>> @@ -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)
>> --
>> 2.45.2
>>



2024-06-11 04:46:20

by Jeff Xu

[permalink] [raw]
Subject: Re: [PATCH 0/5] cleanups, fixes, and progress towards avoiding "make headers"

On Mon, Jun 10, 2024 at 9:34 PM John Hubbard <[email protected]> wrote:
>
> On 6/10/24 9:21 PM, Jeff Xu wrote:
> > Hi
> >
> >
> > On Fri, Jun 7, 2024 at 7:10 PM John Hubbard <[email protected]> wrote:
> >>
> >> 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:
> >>
> >> 1. Add __NR_mseal.
> >>
> >> 2. Add fs.h, taken as usual from a snapshot of ./usr/include/linux/fs.h
> >> after running "make headers". This is how we have agreed to do this sort
> >> of thing, see [1].
> >>
> > What is the "official" way to build selftests/mm ?
>
> From Documentation/dev-tools/kselftest.rst, it is:
>
> $ make headers
> $ make -C tools/testing/selftests
>
> > I tried a few ways, but it never worked, i.e. due to head missing.
>
> You are correct. Today's rules require "make headers" first. But
> I'm working on getting rid of that requirement, because it causes
> problems for some people and situations.
>
> (Even worse is the follow-up rule, in today's documentation,
> that tells us to *run* the selftests from within Make! This
> is just madness.

That is hilarious! :)

> Because the tests need to run as root in
> many cases. And Make will try to rebuild if necessary...thus
> filling your tree full of root-owned files...but that's for
> another time.)
>
> >
> > 1>
> > cd tools/testing/selftests/mm
> > make
> >
> > migration.c:10:10: fatal error: numa.h: No such file or directory
> > 10 | #include <numa.h>
> > | ^~~~~~~~
> > compilation terminated.
> >
> > 2>
> > make headers
> > make -C tools/testing/selftests
> >
> > make[1]: Entering directory
> > '/usr/local/google/home/jeffxu/mm/tools/testing/selftests/mm'
> > CC migration
> > migration.c:10:10: fatal error: numa.h: No such file or directory
> > 10 | #include <numa.h>
> >
>
> Well, actually, for these, one should install libnuma-dev and
> numactl (those are Ubuntu package names. Arch Linux would be:
> numactl).
>
> I think. The idea is: use system headers if they are there, and
> local kernel tree header files if the items are so new that they
> haven't made it to $OLDEST_DISTO_REASONABLE.
>
> Something like that.
>
But I don't want to install random packages if possible.

Can makefile rule continue to the next target in case of failure though ?
right now it stopped at migration.c , if it continues to the next target, then
I don't need to use gcc to manually build mseal_test.

> So if you systematically install various packages on your machine,
> then apply the various patches that I have floating around, then
> you will be able to build selftests/mm without "make headers", at
> this point. Or so I claim.
>
> thanks,
> --
> John Hubbard
> NVIDIA
>

Thanks
-Jeff

2024-06-11 06:26:22

by John Hubbard

[permalink] [raw]
Subject: Re: [PATCH 0/5] cleanups, fixes, and progress towards avoiding "make headers"

On 6/10/24 9:45 PM, Jeff Xu wrote:
> On Mon, Jun 10, 2024 at 9:34 PM John Hubbard <[email protected]> wrote:
>> On 6/10/24 9:21 PM, Jeff Xu wrote:
>>> Hi
>>>
>>>
>>> On Fri, Jun 7, 2024 at 7:10 PM John Hubbard <[email protected]> wrote:
>>>>
>>>> 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:
>>>>
>>>> 1. Add __NR_mseal.
>>>>
>>>> 2. Add fs.h, taken as usual from a snapshot of ./usr/include/linux/fs.h
>>>> after running "make headers". This is how we have agreed to do this sort
>>>> of thing, see [1].
>>>>
>>> What is the "official" way to build selftests/mm ?
>>
>> From Documentation/dev-tools/kselftest.rst, it is:
>>
>> $ make headers
>> $ make -C tools/testing/selftests
>>
>>> I tried a few ways, but it never worked, i.e. due to head missing.
>>
>> You are correct. Today's rules require "make headers" first. But
>> I'm working on getting rid of that requirement, because it causes
>> problems for some people and situations.
>>
>> (Even worse is the follow-up rule, in today's documentation,
>> that tells us to *run* the selftests from within Make! This
>> is just madness.
>
> That is hilarious! :)

:)

>
>> Because the tests need to run as root in
>> many cases. And Make will try to rebuild if necessary...thus
>> filling your tree full of root-owned files...but that's for
>> another time.)
>>
>>>
>>> 1>
>>> cd tools/testing/selftests/mm
>>> make
>>>
>>> migration.c:10:10: fatal error: numa.h: No such file or directory
>>> 10 | #include <numa.h>
>>> | ^~~~~~~~
>>> compilation terminated.
>>>
>>> 2>
>>> make headers
>>> make -C tools/testing/selftests
>>>
>>> make[1]: Entering directory
>>> '/usr/local/google/home/jeffxu/mm/tools/testing/selftests/mm'
>>> CC migration
>>> migration.c:10:10: fatal error: numa.h: No such file or directory
>>> 10 | #include <numa.h>
>>>
>>
>> Well, actually, for these, one should install libnuma-dev and
>> numactl (those are Ubuntu package names. Arch Linux would be:
>> numactl).
>>
>> I think. The idea is: use system headers if they are there, and
>> local kernel tree header files if the items are so new that they
>> haven't made it to $OLDEST_DISTO_REASONABLE.
>>
>> Something like that.
>>
> But I don't want to install random packages if possible.

Well...keep in mind that it's not really random. If a test program
requires numa.h, it's typically because it also links against libnuma,
which *must* be supplied by the distro if you want to build. Because
it doesn't come with the kernel, of course.

So what you're really saying is that you'd like to build and run
whatever you can at the moment--the build should soldier on past
failures as much as possible.

>
> Can makefile rule continue to the next target in case of failure though ?

That could be done, in general. The question is if that's really what
we want, or should want. Maybe...

> right now it stopped at migration.c , if it continues to the next target, then
> I don't need to use gcc to manually build mseal_test.

Let me take a peek at it in the morning.



thanks,
--
John Hubbard
NVIDIA


2024-06-11 09:33:21

by David Hildenbrand

[permalink] [raw]
Subject: Re: [PATCH 0/5] cleanups, fixes, and progress towards avoiding "make headers"

On 11.06.24 08:25, John Hubbard wrote:
> On 6/10/24 9:45 PM, Jeff Xu wrote:
>> On Mon, Jun 10, 2024 at 9:34 PM John Hubbard <[email protected]> wrote:
>>> On 6/10/24 9:21 PM, Jeff Xu wrote:
>>>> Hi
>>>>
>>>>
>>>> On Fri, Jun 7, 2024 at 7:10 PM John Hubbard <[email protected]> wrote:
>>>>>
>>>>> 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:
>>>>>
>>>>> 1. Add __NR_mseal.
>>>>>
>>>>> 2. Add fs.h, taken as usual from a snapshot of ./usr/include/linux/fs.h
>>>>> after running "make headers". This is how we have agreed to do this sort
>>>>> of thing, see [1].
>>>>>
>>>> What is the "official" way to build selftests/mm ?
>>>
>>> From Documentation/dev-tools/kselftest.rst, it is:
>>>
>>> $ make headers
>>> $ make -C tools/testing/selftests
>>>
>>>> I tried a few ways, but it never worked, i.e. due to head missing.
>>>
>>> You are correct. Today's rules require "make headers" first. But
>>> I'm working on getting rid of that requirement, because it causes
>>> problems for some people and situations.
>>>
>>> (Even worse is the follow-up rule, in today's documentation,
>>> that tells us to *run* the selftests from within Make! This
>>> is just madness.
>>
>> That is hilarious! :)
>
> :)
>
>>
>>> Because the tests need to run as root in
>>> many cases. And Make will try to rebuild if necessary...thus
>>> filling your tree full of root-owned files...but that's for
>>> another time.)
>>>
>>>>
>>>> 1>
>>>> cd tools/testing/selftests/mm
>>>> make
>>>>
>>>> migration.c:10:10: fatal error: numa.h: No such file or directory
>>>> 10 | #include <numa.h>
>>>> | ^~~~~~~~
>>>> compilation terminated.
>>>>
>>>> 2>
>>>> make headers
>>>> make -C tools/testing/selftests
>>>>
>>>> make[1]: Entering directory
>>>> '/usr/local/google/home/jeffxu/mm/tools/testing/selftests/mm'
>>>> CC migration
>>>> migration.c:10:10: fatal error: numa.h: No such file or directory
>>>> 10 | #include <numa.h>
>>>>
>>>
>>> Well, actually, for these, one should install libnuma-dev and
>>> numactl (those are Ubuntu package names. Arch Linux would be:
>>> numactl).
>>>
>>> I think. The idea is: use system headers if they are there, and
>>> local kernel tree header files if the items are so new that they
>>> haven't made it to $OLDEST_DISTO_REASONABLE.
>>>
>>> Something like that.
>>>
>> But I don't want to install random packages if possible.
>
> Well...keep in mind that it's not really random. If a test program
> requires numa.h, it's typically because it also links against libnuma,
> which *must* be supplied by the distro if you want to build. Because
> it doesn't come with the kernel, of course.
>
> So what you're really saying is that you'd like to build and run
> whatever you can at the moment--the build should soldier on past
> failures as much as possible.
>
>>
>> Can makefile rule continue to the next target in case of failure though ?
>
> That could be done, in general. The question is if that's really what
> we want, or should want. Maybe...

In cow.c, we warn if liburing is not around and build the test without
these test cases. check_config.sh senses support.

We could do the same for numactl (numa.h), but maybe there would not be
any test case to run in there without libnuma (did not check). Some
tests also require lcap.

--
Cheers,

David / dhildenb


2024-06-11 09:36:25

by David Hildenbrand

[permalink] [raw]
Subject: Re: [PATCH 0/5] cleanups, fixes, and progress towards avoiding "make headers"

On 08.06.24 04:10, John Hubbard wrote:
> 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:

Wasn't the plan to rely on the tools/include headers, and pull in there
whatever we need?

>
> 1. Add __NR_mseal.
>

For example, making sure that tools/include/uapi/asm-generic/unistd.h is
updated to contain __NR_mseal?

... to avoid hand-crafted defines we have to maintain for selftests.

But maybe I am remembering something outdated.

--
Cheers,

David / dhildenb


2024-06-11 14:14:24

by Jeff Xu

[permalink] [raw]
Subject: Re: [PATCH 0/5] cleanups, fixes, and progress towards avoiding "make headers"

On Mon, Jun 10, 2024 at 11:26 PM John Hubbard <[email protected]> wrote:
>
> On 6/10/24 9:45 PM, Jeff Xu wrote:
> > On Mon, Jun 10, 2024 at 9:34 PM John Hubbard <[email protected]> wrote:
> >> On 6/10/24 9:21 PM, Jeff Xu wrote:
> >>> Hi
> >>>
> >>>
> >>> On Fri, Jun 7, 2024 at 7:10 PM John Hubbard <[email protected]> wrote:
> >>>>
> >>>> 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:
> >>>>
> >>>> 1. Add __NR_mseal.
> >>>>
> >>>> 2. Add fs.h, taken as usual from a snapshot of ./usr/include/linux/fs.h
> >>>> after running "make headers". This is how we have agreed to do this sort
> >>>> of thing, see [1].
> >>>>
> >>> What is the "official" way to build selftests/mm ?
> >>
> >> From Documentation/dev-tools/kselftest.rst, it is:
> >>
> >> $ make headers
> >> $ make -C tools/testing/selftests
> >>
> >>> I tried a few ways, but it never worked, i.e. due to head missing.
> >>
> >> You are correct. Today's rules require "make headers" first. But
> >> I'm working on getting rid of that requirement, because it causes
> >> problems for some people and situations.
> >>
> >> (Even worse is the follow-up rule, in today's documentation,
> >> that tells us to *run* the selftests from within Make! This
> >> is just madness.
> >
> > That is hilarious! :)
>
> :)
>
> >
> >> Because the tests need to run as root in
> >> many cases. And Make will try to rebuild if necessary...thus
> >> filling your tree full of root-owned files...but that's for
> >> another time.)
> >>
> >>>
> >>> 1>
> >>> cd tools/testing/selftests/mm
> >>> make
> >>>
> >>> migration.c:10:10: fatal error: numa.h: No such file or directory
> >>> 10 | #include <numa.h>
> >>> | ^~~~~~~~
> >>> compilation terminated.
> >>>
> >>> 2>
> >>> make headers
> >>> make -C tools/testing/selftests
> >>>
> >>> make[1]: Entering directory
> >>> '/usr/local/google/home/jeffxu/mm/tools/testing/selftests/mm'
> >>> CC migration
> >>> migration.c:10:10: fatal error: numa.h: No such file or directory
> >>> 10 | #include <numa.h>
> >>>
> >>
> >> Well, actually, for these, one should install libnuma-dev and
> >> numactl (those are Ubuntu package names. Arch Linux would be:
> >> numactl).
> >>
> >> I think. The idea is: use system headers if they are there, and
> >> local kernel tree header files if the items are so new that they
> >> haven't made it to $OLDEST_DISTO_REASONABLE.
> >>
> >> Something like that.
> >>
> > But I don't want to install random packages if possible.
>
> Well...keep in mind that it's not really random. If a test program
> requires numa.h, it's typically because it also links against libnuma,
> which *must* be supplied by the distro if you want to build. Because
> it doesn't come with the kernel, of course.
>
Agreed.

> So what you're really saying is that you'd like to build and run
> whatever you can at the moment--the build should soldier on past
> failures as much as possible.
>
Yes. That is what I meant. It would be a convenient feature.

> >
> > Can makefile rule continue to the next target in case of failure though ?
>
> That could be done, in general. The question is if that's really what
> we want, or should want. Maybe...
>
> > right now it stopped at migration.c , if it continues to the next target, then
> > I don't need to use gcc to manually build mseal_test.
>
> Let me take a peek at it in the morning.
>
>
>
> thanks,
> --
> John Hubbard
> NVIDIA
>

2024-06-11 20:55:15

by John Hubbard

[permalink] [raw]
Subject: Re: [PATCH 0/5] cleanups, fixes, and progress towards avoiding "make headers"

On 6/11/24 2:36 AM, David Hildenbrand wrote:
> On 08.06.24 04:10, John Hubbard wrote:
>> 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:
>
> Wasn't the plan to rely on the tools/include headers, and pull in there whatever we need?

Yes, it is. You are correct.

>
>>
>> 1. Add __NR_mseal.
>>
>
> For example, making sure that tools/include/uapi/asm-generic/unistd.h is updated to contain __NR_mseal?

Well, here it gets less clear cut, because the selftests pull in *lots* of
system headers. In this case /usr/include/unistd.h gets pulled in. If we
force tools/include/uapi/asm-generic/unistd.h to be included, then we'll
get many many warnings of redefinitions of __NR_* items.

So what's really going on here is that we have this uneasy mix of system
headers from the test machine, and newer versions of some of those headers
in the kernel tree. And some of those are easier to combine with system
headers, than others. unistd.h is clearly not going quietly, which is
why, I believe, the "#ifndef __NR_* " approach has flowered in the
selftests.

>
> ... to avoid hand-crafted defines we have to maintain for selftests.
>
> But maybe I am remembering something outdated.
>

You remembered correctly, but the situation is slighly muddier than
one would prefer. :)


thanks,
--
John Hubbard
NVIDIA


2024-06-12 08:24:42

by David Hildenbrand

[permalink] [raw]
Subject: Re: [PATCH 0/5] cleanups, fixes, and progress towards avoiding "make headers"

On 11.06.24 22:54, John Hubbard wrote:
> On 6/11/24 2:36 AM, David Hildenbrand wrote:
>> On 08.06.24 04:10, John Hubbard wrote:
>>> 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:
>>
>> Wasn't the plan to rely on the tools/include headers, and pull in there whatever we need?
>
> Yes, it is. You are correct.
>
>>
>>>
>>> 1. Add __NR_mseal.
>>>
>>
>> For example, making sure that tools/include/uapi/asm-generic/unistd.h is updated to contain __NR_mseal?
>
> Well, here it gets less clear cut, because the selftests pull in *lots* of
> system headers. In this case /usr/include/unistd.h gets pulled in. If we
> force tools/include/uapi/asm-generic/unistd.h to be included, then we'll
> get many many warnings of redefinitions of __NR_* items.

I think, there is a difference between unistd.h and linux/unistd.h. We
want to continue including unistd.h from the distro, but might want to
stop including the linux one from the distro.

My thinking was that we start maintaining our own linux headers copy
in-tree, and start converting our tests from including <linux/> supplied
by the distro to include the in-tree ones.

For mseal_test.c, that might mean stopping including "linux/mman.h", and
instead including the in-tree one.

>
> So what's really going on here is that we have this uneasy mix of system
> headers from the test machine, and newer versions of some of those headers
> in the kernel tree. And some of those are easier to combine with system
> headers, than others. unistd.h is clearly not going quietly, which is
> why, I believe, the "#ifndef __NR_* " approach has flowered in the
> selftests.

Right, these mixtures are not what we want I think. But I have no idea
how easy it would be to convert individual tests.

Maybe all it takes is updating the in-tree headers and then including
"TBD/linux/whatever.h" instead of <linux/whatever.h>

In QEMU, we maintain some (not all) kernel headers ourselves, and
include them via

"standard-headers/linux/whatever.h"

>
>>
>> ... to avoid hand-crafted defines we have to maintain for selftests.
>>
>> But maybe I am remembering something outdated.
>>
>
> You remembered correctly, but the situation is slighly muddier than
> one would prefer. :)


Absolutely, and I appreciate that you are trying to improve the situation.

--
Cheers,

David / dhildenb


2024-06-13 02:13:16

by John Hubbard

[permalink] [raw]
Subject: Re: [PATCH 0/5] cleanups, fixes, and progress towards avoiding "make headers"

On 6/12/24 1:24 AM, David Hildenbrand wrote:
> On 11.06.24 22:54, John Hubbard wrote:
>> On 6/11/24 2:36 AM, David Hildenbrand wrote:
>>> On 08.06.24 04:10, John Hubbard wrote:
>>>> 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:
>>>
>>> Wasn't the plan to rely on the tools/include headers, and pull in there whatever we need?
>>
>> Yes, it is. You are correct.
>>
>>>
>>>>
>>>> 1. Add __NR_mseal.
>>>>
>>>
>>> For example, making sure that tools/include/uapi/asm-generic/unistd.h is updated to contain __NR_mseal?
>>
>> Well, here it gets less clear cut, because the selftests pull in *lots* of
>> system headers. In this case /usr/include/unistd.h gets pulled in. If we
>> force tools/include/uapi/asm-generic/unistd.h to be included, then we'll
>> get many many warnings of redefinitions of __NR_* items.
>
> I think, there is a difference between unistd.h and linux/unistd.h. We want to continue including unistd.h from the distro, but might want to stop including the linux one from the distro.
>
> My thinking was that we start maintaining our own linux headers copy in-tree, and start converting our tests from including <linux/> supplied by the distro to include the in-tree ones.
>
> For mseal_test.c, that might mean stopping including "linux/mman.h", and instead including the in-tree one.

Yes. Something like that.

$ find /usr -name 'unistd*.h' | wc -l
14
$ find /kernel_work/linux-github/ -name 'unistd*.h' | wc -l
54

heh. :)

>
>>
>> So what's really going on here is that we have this uneasy mix of system
>> headers from the test machine, and newer versions of some of those headers
>> in the kernel tree. And some of those are easier to combine with system
>> headers, than others. unistd.h is clearly not going quietly, which is
>> why, I believe, the "#ifndef __NR_* " approach has flowered in the
>> selftests.
>
> Right, these mixtures are not what we want I think. But I have no idea how easy it would be to convert individual tests.
>
> Maybe all it takes is updating the in-tree headers and then including "TBD/linux/whatever.h" instead of <linux/whatever.h>
>
> In QEMU, we maintain some (not all) kernel headers ourselves, and include them via
>
> "standard-headers/linux/whatever.h"

Let me look into it. Maybe it's fairly simple, we shall see.

>
>>
>>>
>>> ... to avoid hand-crafted defines we have to maintain for selftests.
>>>
>>> But maybe I am remembering something outdated.
>>>
>>
>> You remembered correctly, but the situation is slighly muddier than
>> one would prefer. :)
>
>
> Absolutely, and I appreciate that you are trying to improve the situation.
>

I think the attempts to further tease apart the include headers could
go into a separate, subsequent series, yes? And let this one go in
unmolested for now?


thanks,
--
John Hubbard
NVIDIA


2024-06-13 21:31:48

by John Hubbard

[permalink] [raw]
Subject: Re: [PATCH 0/5] cleanups, fixes, and progress towards avoiding "make headers"

On 6/12/24 7:11 PM, John Hubbard wrote:
> On 6/12/24 1:24 AM, David Hildenbrand wrote:
>> On 11.06.24 22:54, John Hubbard wrote:
>>> On 6/11/24 2:36 AM, David Hildenbrand wrote:
>>>> On 08.06.24 04:10, John Hubbard wrote:
...
>>> You remembered correctly, but the situation is slighly muddier than
>>> one would prefer. :)
>>
>>
>> Absolutely, and I appreciate that you are trying to improve the situation.
>>
>
> I think the attempts to further tease apart the include headers could
> go into a separate, subsequent series, yes? And let this one go in
> unmolested for now?


On second thought, it is actually much easier than I thought, let me
post a v2 with the unistd.h header fixes, after all.

thanks,
--
John Hubbard
NVIDIA


2024-06-14 11:42:50

by David Hildenbrand

[permalink] [raw]
Subject: Re: [PATCH 0/5] cleanups, fixes, and progress towards avoiding "make headers"

On 13.06.24 23:27, John Hubbard wrote:
> On 6/12/24 7:11 PM, John Hubbard wrote:
>> On 6/12/24 1:24 AM, David Hildenbrand wrote:
>>> On 11.06.24 22:54, John Hubbard wrote:
>>>> On 6/11/24 2:36 AM, David Hildenbrand wrote:
>>>>> On 08.06.24 04:10, John Hubbard wrote:
> ...
>>>> You remembered correctly, but the situation is slighly muddier than
>>>> one would prefer. :)
>>>
>>>
>>> Absolutely, and I appreciate that you are trying to improve the situation.
>>>
>>
>> I think the attempts to further tease apart the include headers could
>> go into a separate, subsequent series, yes? And let this one go in
>> unmolested for now?
>
>
> On second thought, it is actually much easier than I thought, let me
> post a v2 with the unistd.h header fixes, after all.

Great! :)

--
Cheers,

David / dhildenb