Re: [PATCH 1/2] uapi: split openat2(2) definitions from fcntl.h

5 messages, 3 authors, 2019-12-20 · open the first message on its own page

Re: [PATCH 1/2] uapi: split openat2(2) definitions from fcntl.h

From: Florian Weimer <hidden>
Date: 2019-12-19 11:07:29

* Aleksa Sarai:
quoted hunk
diff --git a/include/uapi/linux/openat2.h b/include/uapi/linux/openat2.h
new file mode 100644
index 000000000000..19ef775e8e5e
--- /dev/null
+++ b/include/uapi/linux/openat2.h
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI_LINUX_OPENAT2_H
+#define _UAPI_LINUX_OPENAT2_H
I think you should include the relevant header for __align_u64
etc. here.

[…]
+ * Arguments for how openat2(2) should open the target path. If @resolve is
+ * zero, then openat2(2) operates very similarly to openat(2).
+ *
+ * However, unlike openat(2), unknown bits in @flags result in -EINVAL rather
+ * than being silently ignored. @mode must be zero unless one of {O_CREAT,
+ * O_TMPFILE} are set.
+ *
+ * @flags: O_* flags.
+ * @mode: O_CREAT/O_TMPFILE file mode.
+ * @resolve: RESOLVE_* flags.
+ */
+struct open_how {
+	__aligned_u64 flags;
+	__u16 mode;
+	__u16 __padding[3]; /* must be zeroed */
+	__aligned_u64 resolve;
+};
+
+#define OPEN_HOW_SIZE_VER0	24 /* sizeof first published struct */
+#define OPEN_HOW_SIZE_LATEST	OPEN_HOW_SIZE_VER0
Are these really useful for the UAPI header?  Is there a situation where
OPEN_HOW_SIZE_LATEST would be different from sizeof (struct open_how)?

The header is not compatible with the assembler anyway, so the numeric
constant does not seem useful.

Thanks,
Florian

Re: [PATCH 1/2] uapi: split openat2(2) definitions from fcntl.h

From: Aleksa Sarai <hidden>
Date: 2019-12-19 13:45:50

On 2019-12-19, Florian Weimer [off-list ref] wrote:
* Aleksa Sarai:
quoted
diff --git a/include/uapi/linux/openat2.h b/include/uapi/linux/openat2.h
new file mode 100644
index 000000000000..19ef775e8e5e
--- /dev/null
+++ b/include/uapi/linux/openat2.h
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI_LINUX_OPENAT2_H
+#define _UAPI_LINUX_OPENAT2_H
I think you should include the relevant header for __align_u64
etc. here.
Right -- no idea why I forgot to include them.
[…]
quoted
+ * Arguments for how openat2(2) should open the target path. If @resolve is
+ * zero, then openat2(2) operates very similarly to openat(2).
+ *
+ * However, unlike openat(2), unknown bits in @flags result in -EINVAL rather
+ * than being silently ignored. @mode must be zero unless one of {O_CREAT,
+ * O_TMPFILE} are set.
+ *
+ * @flags: O_* flags.
+ * @mode: O_CREAT/O_TMPFILE file mode.
+ * @resolve: RESOLVE_* flags.
+ */
+struct open_how {
+	__aligned_u64 flags;
+	__u16 mode;
+	__u16 __padding[3]; /* must be zeroed */
+	__aligned_u64 resolve;
+};
+
+#define OPEN_HOW_SIZE_VER0	24 /* sizeof first published struct */
+#define OPEN_HOW_SIZE_LATEST	OPEN_HOW_SIZE_VER0
Are these really useful for the UAPI header?  Is there a situation where
OPEN_HOW_SIZE_LATEST would be different from sizeof (struct open_how)?

The header is not compatible with the assembler anyway, so the numeric
constant does not seem useful.
OPEN_HOW_SIZE_VER0 could conceivably be useful (in the future we may do
size-based checks) but maybe we can just expose it if someone actually
ends up needing it.

I will move them to the in-kernel header (we use them for BUILD_BUG_ONs
to make sure that the sizes are correct).

-- 
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
<https://www.cyphar.com/>

RE: [PATCH 1/2] uapi: split openat2(2) definitions from fcntl.h

From: David Laight <hidden>
Date: 2019-12-19 14:05:11

From: Aleksa Sarai
Sent: 19 December 2019 13:45
On 2019-12-19, Florian Weimer [off-list ref] wrote:
quoted
* Aleksa Sarai:
quoted
diff --git a/include/uapi/linux/openat2.h b/include/uapi/linux/openat2.h
new file mode 100644
index 000000000000..19ef775e8e5e
--- /dev/null
+++ b/include/uapi/linux/openat2.h
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI_LINUX_OPENAT2_H
+#define _UAPI_LINUX_OPENAT2_H
I think you should include the relevant header for __align_u64
etc. here.
Right -- no idea why I forgot to include them.
I'm guessing that is just 64bit aligned on 32bit archs like x86?

No need to enforce it provided the structure will have no padding
on archs where the 64bit fields are 64bit aligned.
A plain __u64 should be fine.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Re: [PATCH 1/2] uapi: split openat2(2) definitions from fcntl.h

From: Aleksa Sarai <hidden>
Date: 2019-12-20 09:32:42

On 2019-12-19, David Laight [off-list ref] wrote:
From: Aleksa Sarai
quoted
Sent: 19 December 2019 13:45
On 2019-12-19, Florian Weimer [off-list ref] wrote:
quoted
* Aleksa Sarai:
quoted
diff --git a/include/uapi/linux/openat2.h b/include/uapi/linux/openat2.h
new file mode 100644
index 000000000000..19ef775e8e5e
--- /dev/null
+++ b/include/uapi/linux/openat2.h
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI_LINUX_OPENAT2_H
+#define _UAPI_LINUX_OPENAT2_H
I think you should include the relevant header for __align_u64
etc. here.
Right -- no idea why I forgot to include them.
I'm guessing that is just 64bit aligned on 32bit archs like x86?
Yeah,

#define __aligned_u64 __u64 __attribute__((aligned(8)))
No need to enforce it provided the structure will have no padding on
archs where the 64bit fields are 64bit aligned. A plain __u64 should
be fine.
Will this cause problems for x86-on-x86_64 emulation? Requiring an
8-byte alignment for 'struct open_how' really isn't that undue of a
burden IMHO. Then again, clone3 is a bit of an outlier since both
perf_event_open and sched_setattr just use __u64s.

-- 
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
<https://www.cyphar.com/>

RE: [PATCH 1/2] uapi: split openat2(2) definitions from fcntl.h

From: David Laight <hidden>
Date: 2019-12-20 10:18:32

From: Aleksa Sarai
Sent: 20 December 2019 09:32
...
quoted
I'm guessing that is just 64bit aligned on 32bit archs like x86?
Yeah,

#define __aligned_u64 __u64 __attribute__((aligned(8)))
quoted
No need to enforce it provided the structure will have no padding on
archs where the 64bit fields are 64bit aligned. A plain __u64 should
be fine.
Will this cause problems for x86-on-x86_64 emulation? Requiring an
8-byte alignment for 'struct open_how' really isn't that undue of a
burden IMHO. Then again, clone3 is a bit of an outlier since both
perf_event_open and sched_setattr just use __u64s.
Makes diddly-squit difference.
The 64bit kernel will 64bit align the structure.
The kernel must allow for the userspace structure having arbitrary alignment.
So there is no reason to (try to) align the user structure.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help