* [PATCH 1/1 fyi] tools include UAPI: Sync linux/fcntl.h copy with the kernel sources
@ 2024-09-30 15:47 Arnaldo Carvalho de Melo
2024-09-30 16:24 ` Aleksa Sarai
0 siblings, 1 reply; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-09-30 15:47 UTC (permalink / raw)
To: linux-kernel
Cc: Adrian Hunter, Aleksa Sarai, Christian Brauner, Ian Rogers,
Jiri Olsa, Kan Liang, Namhyung Kim, Tejun Heo
Picking the changes from:
4356d575ef0f39a3 ("fhandle: expose u64 mount id to name_to_handle_at(2)")
b4fef22c2fb97fa2 ("uapi: explain how per-syscall AT_* flags should be allocated")
820a185896b77814 ("fcntl: add F_CREATED_QUERY")
It just moves AT_REMOVEDIR around, and adds a bunch more AT_ for
renameat2() and name_to_handle_at(). We need to improve this situation,
as not all AT_ defines are applicable to all fs flags...
This adds support for those new AT_ defines, addressing this build
warning:
diff -u tools/perf/trace/beauty/include/uapi/sound/asound.h include/uapi/sound/asound.h
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Aleksa Sarai <cyphar@cyphar.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Link: https://lore.kernel.org/lkml/
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/trace/beauty/fs_at_flags.sh | 5 ++
.../trace/beauty/include/uapi/linux/fcntl.h | 84 +++++++++++++------
2 files changed, 65 insertions(+), 24 deletions(-)
diff --git a/tools/perf/trace/beauty/fs_at_flags.sh b/tools/perf/trace/beauty/fs_at_flags.sh
index 456f59addf741062..e3f13f96a27c227c 100755
--- a/tools/perf/trace/beauty/fs_at_flags.sh
+++ b/tools/perf/trace/beauty/fs_at_flags.sh
@@ -13,9 +13,14 @@ printf "static const char *fs_at_flags[] = {\n"
regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+AT_([^_]+[[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*'
# AT_EACCESS is only meaningful to faccessat, so we will special case it there...
# AT_STATX_SYNC_TYPE is not a bit, its a mask of AT_STATX_SYNC_AS_STAT, AT_STATX_FORCE_SYNC and AT_STATX_DONT_SYNC
+# AT_HANDLE_FID and AT_HANDLE_MNT_ID_UNIQUE are reusing values and are valid only for name_to_handle_at()
+# AT_RENAME_NOREPLACE reuses 0x1 and is valid only for renameat2()
grep -E $regex ${linux_fcntl} | \
grep -v AT_EACCESS | \
grep -v AT_STATX_SYNC_TYPE | \
+ grep -v AT_HANDLE_FID | \
+ grep -v AT_HANDLE_MNT_ID_UNIQUE | \
+ grep -v AT_RENAME_NOREPLACE | \
sed -r "s/$regex/\2 \1/g" | \
xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n"
printf "};\n"
diff --git a/tools/perf/trace/beauty/include/uapi/linux/fcntl.h b/tools/perf/trace/beauty/include/uapi/linux/fcntl.h
index c0bcc185fa48f852..87e2dec79fea4ef2 100644
--- a/tools/perf/trace/beauty/include/uapi/linux/fcntl.h
+++ b/tools/perf/trace/beauty/include/uapi/linux/fcntl.h
@@ -16,6 +16,9 @@
#define F_DUPFD_QUERY (F_LINUX_SPECIFIC_BASE + 3)
+/* Was the file just created? */
+#define F_CREATED_QUERY (F_LINUX_SPECIFIC_BASE + 4)
+
/*
* Cancel a blocking posix lock; internal use only until we expose an
* asynchronous lock api to userspace:
@@ -87,37 +90,70 @@
#define DN_ATTRIB 0x00000020 /* File changed attibutes */
#define DN_MULTISHOT 0x80000000 /* Don't remove notifier */
+#define AT_FDCWD -100 /* Special value for dirfd used to
+ indicate openat should use the
+ current working directory. */
+
+
+/* Generic flags for the *at(2) family of syscalls. */
+
+/* Reserved for per-syscall flags 0xff. */
+#define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic
+ links. */
+/* Reserved for per-syscall flags 0x200 */
+#define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */
+#define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount
+ traversal. */
+#define AT_EMPTY_PATH 0x1000 /* Allow empty relative
+ pathname to operate on dirfd
+ directly. */
+/*
+ * These flags are currently statx(2)-specific, but they could be made generic
+ * in the future and so they should not be used for other per-syscall flags.
+ */
+#define AT_STATX_SYNC_TYPE 0x6000 /* Type of synchronisation required from statx() */
+#define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */
+#define AT_STATX_FORCE_SYNC 0x2000 /* - Force the attributes to be sync'd with the server */
+#define AT_STATX_DONT_SYNC 0x4000 /* - Don't sync attributes with the server */
+
+#define AT_RECURSIVE 0x8000 /* Apply to the entire subtree */
+
/*
- * The constants AT_REMOVEDIR and AT_EACCESS have the same value. AT_EACCESS is
- * meaningful only to faccessat, while AT_REMOVEDIR is meaningful only to
- * unlinkat. The two functions do completely different things and therefore,
- * the flags can be allowed to overlap. For example, passing AT_REMOVEDIR to
- * faccessat would be undefined behavior and thus treating it equivalent to
- * AT_EACCESS is valid undefined behavior.
+ * Per-syscall flags for the *at(2) family of syscalls.
+ *
+ * These are flags that are so syscall-specific that a user passing these flags
+ * to the wrong syscall is so "clearly wrong" that we can safely call such
+ * usage "undefined behaviour".
+ *
+ * For example, the constants AT_REMOVEDIR and AT_EACCESS have the same value.
+ * AT_EACCESS is meaningful only to faccessat, while AT_REMOVEDIR is meaningful
+ * only to unlinkat. The two functions do completely different things and
+ * therefore, the flags can be allowed to overlap. For example, passing
+ * AT_REMOVEDIR to faccessat would be undefined behavior and thus treating it
+ * equivalent to AT_EACCESS is valid undefined behavior.
+ *
+ * Note for implementers: When picking a new per-syscall AT_* flag, try to
+ * reuse already existing flags first. This leaves us with as many unused bits
+ * as possible, so we can use them for generic bits in the future if necessary.
*/
-#define AT_FDCWD -100 /* Special value used to indicate
- openat should use the current
- working directory. */
-#define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */
+
+/* Flags for renameat2(2) (must match legacy RENAME_* flags). */
+#define AT_RENAME_NOREPLACE 0x0001
+#define AT_RENAME_EXCHANGE 0x0002
+#define AT_RENAME_WHITEOUT 0x0004
+
+/* Flag for faccessat(2). */
#define AT_EACCESS 0x200 /* Test access permitted for
effective IDs, not real IDs. */
+/* Flag for unlinkat(2). */
#define AT_REMOVEDIR 0x200 /* Remove directory instead of
unlinking file. */
-#define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */
-#define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount traversal */
-#define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname */
-
-#define AT_STATX_SYNC_TYPE 0x6000 /* Type of synchronisation required from statx() */
-#define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */
-#define AT_STATX_FORCE_SYNC 0x2000 /* - Force the attributes to be sync'd with the server */
-#define AT_STATX_DONT_SYNC 0x4000 /* - Don't sync attributes with the server */
-
-#define AT_RECURSIVE 0x8000 /* Apply to the entire subtree */
+/* Flags for name_to_handle_at(2). */
+#define AT_HANDLE_FID 0x200 /* File handle is needed to compare
+ object identity and may not be
+ usable with open_by_handle_at(2). */
+#define AT_HANDLE_MNT_ID_UNIQUE 0x001 /* Return the u64 unique mount ID. */
-/* Flags for name_to_handle_at(2). We reuse AT_ flag space to save bits... */
-#define AT_HANDLE_FID AT_REMOVEDIR /* file handle is needed to
- compare object identity and may not
- be usable to open_by_handle_at(2) */
#if defined(__KERNEL__)
#define AT_GETATTR_NOSEC 0x80000000
#endif
--
2.46.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1 fyi] tools include UAPI: Sync linux/fcntl.h copy with the kernel sources
2024-09-30 15:47 [PATCH 1/1 fyi] tools include UAPI: Sync linux/fcntl.h copy with the kernel sources Arnaldo Carvalho de Melo
@ 2024-09-30 16:24 ` Aleksa Sarai
2024-09-30 20:23 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 3+ messages in thread
From: Aleksa Sarai @ 2024-09-30 16:24 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: linux-kernel, Adrian Hunter, Christian Brauner, Ian Rogers,
Jiri Olsa, Kan Liang, Namhyung Kim, Tejun Heo
[-- Attachment #1: Type: text/plain, Size: 8255 bytes --]
On 2024-09-30, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> Picking the changes from:
>
> 4356d575ef0f39a3 ("fhandle: expose u64 mount id to name_to_handle_at(2)")
> b4fef22c2fb97fa2 ("uapi: explain how per-syscall AT_* flags should be allocated")
> 820a185896b77814 ("fcntl: add F_CREATED_QUERY")
>
> It just moves AT_REMOVEDIR around, and adds a bunch more AT_ for
> renameat2() and name_to_handle_at(). We need to improve this situation,
> as not all AT_ defines are applicable to all fs flags...
>
> This adds support for those new AT_ defines, addressing this build
> warning:
>
> diff -u tools/perf/trace/beauty/include/uapi/sound/asound.h include/uapi/sound/asound.h
Thanks, feel free to take my
Reviewed-by: Aleksa Sarai <cyphar@cyphar.com>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Aleksa Sarai <cyphar@cyphar.com>
> Cc: Christian Brauner <brauner@kernel.org>
> Cc: Ian Rogers <irogers@google.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Kan Liang <kan.liang@linux.intel.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Tejun Heo <tj@kernel.org>
> Link: https://lore.kernel.org/lkml/
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
> tools/perf/trace/beauty/fs_at_flags.sh | 5 ++
> .../trace/beauty/include/uapi/linux/fcntl.h | 84 +++++++++++++------
> 2 files changed, 65 insertions(+), 24 deletions(-)
>
> diff --git a/tools/perf/trace/beauty/fs_at_flags.sh b/tools/perf/trace/beauty/fs_at_flags.sh
> index 456f59addf741062..e3f13f96a27c227c 100755
> --- a/tools/perf/trace/beauty/fs_at_flags.sh
> +++ b/tools/perf/trace/beauty/fs_at_flags.sh
> @@ -13,9 +13,14 @@ printf "static const char *fs_at_flags[] = {\n"
> regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+AT_([^_]+[[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*'
> # AT_EACCESS is only meaningful to faccessat, so we will special case it there...
> # AT_STATX_SYNC_TYPE is not a bit, its a mask of AT_STATX_SYNC_AS_STAT, AT_STATX_FORCE_SYNC and AT_STATX_DONT_SYNC
> +# AT_HANDLE_FID and AT_HANDLE_MNT_ID_UNIQUE are reusing values and are valid only for name_to_handle_at()
> +# AT_RENAME_NOREPLACE reuses 0x1 and is valid only for renameat2()
> grep -E $regex ${linux_fcntl} | \
> grep -v AT_EACCESS | \
> grep -v AT_STATX_SYNC_TYPE | \
> + grep -v AT_HANDLE_FID | \
> + grep -v AT_HANDLE_MNT_ID_UNIQUE | \
> + grep -v AT_RENAME_NOREPLACE | \
> sed -r "s/$regex/\2 \1/g" | \
> xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n"
> printf "};\n"
> diff --git a/tools/perf/trace/beauty/include/uapi/linux/fcntl.h b/tools/perf/trace/beauty/include/uapi/linux/fcntl.h
> index c0bcc185fa48f852..87e2dec79fea4ef2 100644
> --- a/tools/perf/trace/beauty/include/uapi/linux/fcntl.h
> +++ b/tools/perf/trace/beauty/include/uapi/linux/fcntl.h
> @@ -16,6 +16,9 @@
>
> #define F_DUPFD_QUERY (F_LINUX_SPECIFIC_BASE + 3)
>
> +/* Was the file just created? */
> +#define F_CREATED_QUERY (F_LINUX_SPECIFIC_BASE + 4)
> +
> /*
> * Cancel a blocking posix lock; internal use only until we expose an
> * asynchronous lock api to userspace:
> @@ -87,37 +90,70 @@
> #define DN_ATTRIB 0x00000020 /* File changed attibutes */
> #define DN_MULTISHOT 0x80000000 /* Don't remove notifier */
>
> +#define AT_FDCWD -100 /* Special value for dirfd used to
> + indicate openat should use the
> + current working directory. */
> +
> +
> +/* Generic flags for the *at(2) family of syscalls. */
> +
> +/* Reserved for per-syscall flags 0xff. */
> +#define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic
> + links. */
> +/* Reserved for per-syscall flags 0x200 */
> +#define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */
> +#define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount
> + traversal. */
> +#define AT_EMPTY_PATH 0x1000 /* Allow empty relative
> + pathname to operate on dirfd
> + directly. */
> +/*
> + * These flags are currently statx(2)-specific, but they could be made generic
> + * in the future and so they should not be used for other per-syscall flags.
> + */
> +#define AT_STATX_SYNC_TYPE 0x6000 /* Type of synchronisation required from statx() */
> +#define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */
> +#define AT_STATX_FORCE_SYNC 0x2000 /* - Force the attributes to be sync'd with the server */
> +#define AT_STATX_DONT_SYNC 0x4000 /* - Don't sync attributes with the server */
> +
> +#define AT_RECURSIVE 0x8000 /* Apply to the entire subtree */
> +
> /*
> - * The constants AT_REMOVEDIR and AT_EACCESS have the same value. AT_EACCESS is
> - * meaningful only to faccessat, while AT_REMOVEDIR is meaningful only to
> - * unlinkat. The two functions do completely different things and therefore,
> - * the flags can be allowed to overlap. For example, passing AT_REMOVEDIR to
> - * faccessat would be undefined behavior and thus treating it equivalent to
> - * AT_EACCESS is valid undefined behavior.
> + * Per-syscall flags for the *at(2) family of syscalls.
> + *
> + * These are flags that are so syscall-specific that a user passing these flags
> + * to the wrong syscall is so "clearly wrong" that we can safely call such
> + * usage "undefined behaviour".
> + *
> + * For example, the constants AT_REMOVEDIR and AT_EACCESS have the same value.
> + * AT_EACCESS is meaningful only to faccessat, while AT_REMOVEDIR is meaningful
> + * only to unlinkat. The two functions do completely different things and
> + * therefore, the flags can be allowed to overlap. For example, passing
> + * AT_REMOVEDIR to faccessat would be undefined behavior and thus treating it
> + * equivalent to AT_EACCESS is valid undefined behavior.
> + *
> + * Note for implementers: When picking a new per-syscall AT_* flag, try to
> + * reuse already existing flags first. This leaves us with as many unused bits
> + * as possible, so we can use them for generic bits in the future if necessary.
> */
> -#define AT_FDCWD -100 /* Special value used to indicate
> - openat should use the current
> - working directory. */
> -#define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */
> +
> +/* Flags for renameat2(2) (must match legacy RENAME_* flags). */
> +#define AT_RENAME_NOREPLACE 0x0001
> +#define AT_RENAME_EXCHANGE 0x0002
> +#define AT_RENAME_WHITEOUT 0x0004
> +
> +/* Flag for faccessat(2). */
> #define AT_EACCESS 0x200 /* Test access permitted for
> effective IDs, not real IDs. */
> +/* Flag for unlinkat(2). */
> #define AT_REMOVEDIR 0x200 /* Remove directory instead of
> unlinking file. */
> -#define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */
> -#define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount traversal */
> -#define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname */
> -
> -#define AT_STATX_SYNC_TYPE 0x6000 /* Type of synchronisation required from statx() */
> -#define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */
> -#define AT_STATX_FORCE_SYNC 0x2000 /* - Force the attributes to be sync'd with the server */
> -#define AT_STATX_DONT_SYNC 0x4000 /* - Don't sync attributes with the server */
> -
> -#define AT_RECURSIVE 0x8000 /* Apply to the entire subtree */
> +/* Flags for name_to_handle_at(2). */
> +#define AT_HANDLE_FID 0x200 /* File handle is needed to compare
> + object identity and may not be
> + usable with open_by_handle_at(2). */
> +#define AT_HANDLE_MNT_ID_UNIQUE 0x001 /* Return the u64 unique mount ID. */
>
> -/* Flags for name_to_handle_at(2). We reuse AT_ flag space to save bits... */
> -#define AT_HANDLE_FID AT_REMOVEDIR /* file handle is needed to
> - compare object identity and may not
> - be usable to open_by_handle_at(2) */
> #if defined(__KERNEL__)
> #define AT_GETATTR_NOSEC 0x80000000
> #endif
> --
> 2.46.0
>
--
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
<https://www.cyphar.com/>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1 fyi] tools include UAPI: Sync linux/fcntl.h copy with the kernel sources
2024-09-30 16:24 ` Aleksa Sarai
@ 2024-09-30 20:23 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-09-30 20:23 UTC (permalink / raw)
To: Aleksa Sarai
Cc: linux-kernel, Adrian Hunter, Christian Brauner, Ian Rogers,
Jiri Olsa, Kan Liang, Namhyung Kim, Tejun Heo
On Mon, Sep 30, 2024 at 06:24:50PM +0200, Aleksa Sarai wrote:
> On 2024-09-30, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> > Picking the changes from:
> >
> > 4356d575ef0f39a3 ("fhandle: expose u64 mount id to name_to_handle_at(2)")
> > b4fef22c2fb97fa2 ("uapi: explain how per-syscall AT_* flags should be allocated")
> > 820a185896b77814 ("fcntl: add F_CREATED_QUERY")
> >
> > It just moves AT_REMOVEDIR around, and adds a bunch more AT_ for
> > renameat2() and name_to_handle_at(). We need to improve this situation,
> > as not all AT_ defines are applicable to all fs flags...
> >
> > This adds support for those new AT_ defines, addressing this build
> > warning:
> >
> > diff -u tools/perf/trace/beauty/include/uapi/sound/asound.h include/uapi/sound/asound.h
>
> Thanks, feel free to take my
>
> Reviewed-by: Aleksa Sarai <cyphar@cyphar.com>
Thanks, added.
- Arnaldo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-30 20:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-30 15:47 [PATCH 1/1 fyi] tools include UAPI: Sync linux/fcntl.h copy with the kernel sources Arnaldo Carvalho de Melo
2024-09-30 16:24 ` Aleksa Sarai
2024-09-30 20:23 ` Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox