Skip to contentSkip to conversation

f2fs: move ioctl interface definitions to separated file

PATCH In review Chao Yu 3 participants 4 messages Nov 2, 2020 – Nov 3, 2020

Subsystems (2)
lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH v3 1/1 f2fs: move ioctl interface definitions to separated file

Like other filesystem does, we introduce a new file f2fs.h in path of include/uapi/linux/, and move f2fs-specified ioctl interface definitions to that file, after then, in order to use those definitions, userspace developer only need to include the new header file rather than copy & paste definitions from fs/f2fs/f2fs.h.

---
v3:
- use __u{32,64} rather than u{32,64} in userspace header file.

 MAINTAINERS                 |  1 +
 fs/f2fs/f2fs.h              | 79 ---------------------------------
 fs/f2fs/file.c              |  1 +
 include/trace/events/f2fs.h |  1 +
 include/uapi/linux/f2fs.h   | 87 +++++++++++++++++++++++++++++++++++++
 5 files changed, 90 insertions(+), 79 deletions(-)
 create mode 100644 include/uapi/linux/f2fs.h
MAINTAINERS +1 -0
index e73636b75f29..9f02671e874e 100644
@@ -6685,6 +6685,7 @@ F:	Documentation/filesystems/f2fs.rst
 F:	fs/f2fs/
 F:	include/linux/f2fs_fs.h
 F:	include/trace/events/f2fs.h
+F:	include/uapi/linux/f2fs.h
 
 F71805F HARDWARE MONITORING DRIVER
 M:	Jean Delvare <[email protected]>
fs/f2fs/f2fs.h +0 -79

85 lines not on this page · raw message

fs/f2fs/file.c +1 -0
index ee861c6d9ff0..d898f1e2764b 100644
@@ -31,6 +31,7 @@
 #include "gc.h"
 #include "trace.h"
 #include <trace/events/f2fs.h>
+#include <uapi/linux/f2fs.h>
 
 static vm_fault_t f2fs_filemap_fault(struct vm_fault *vmf)
 {
include/trace/events/f2fs.h +1 -0
index f8f1e85ff130..56b113e3cd6a 100644
@@ -6,6 +6,7 @@
 #define _TRACE_F2FS_H
 
 #include <linux/tracepoint.h>
+#include <uapi/linux/f2fs.h>
 
 #define show_dev(dev)		MAJOR(dev), MINOR(dev)
 #define show_dev_ino(entry)	show_dev(entry->dev), (unsigned long)entry->ino
include/uapi/linux/f2fs.h new file +87 -0

87 lines not on this page · raw message

Signature · 1 line
2.26.2
#1 lore raw
Quoted 2 lines · Chao Yu
include/uapi/linux/f2fs.h new file +2 -0
+#define F2FS_IOC_MOVE_RANGE		_IOWR(F2FS_IOCTL_MAGIC, 9,	\
+						struct f2fs_move_range)

[...]

Quoted 2 lines
include/uapi/linux/f2fs.h new file +2 -0
+#define F2FS_IOC_GARBAGE_COLLECT_RANGE	_IOW(F2FS_IOCTL_MAGIC, 11,	\
+						struct f2fs_gc_range)

[...]

Quoted 6 lines
include/uapi/linux/f2fs.h new file +6 -0
+
+struct f2fs_gc_range {
+	__u32 sync;
+	__u64 start;
+	__u64 len;
+};

[...]

include/uapi/linux/f2fs.h line 74

Quoted 6 lines
include/uapi/linux/f2fs.h new file +6 -0
+struct f2fs_move_range {
+	__u32 dst_fd;		/* destination fd */
+	__u64 pos_in;		/* start position in src_fd */
+	__u64 pos_out;		/* start position in dst_fd */
+	__u64 len;		/* size to move */
+};

These two structs are weird because there is implicit padding between the __u32 field and the following __u64 field on some 32-bit architectures (e.g. x86_32) but not others (e.g. arm32).

But f2fs_compat_ioctl() doesn't handle these two ioctls specially, but rather just calls through to f2fs_ioctl(). That's wrong, and it means that F2FS_IOC_MOVE_RANGE and F2FS_IOC_GARBAGE_COLLECT_RANGE won't work when called from an x86_32 binary on an x86_64 kernel.

So something needs to be fixed. I wonder if it's safe to just explicitly add the padding field after the fact. If no one is actually using these two ioctls in a case where both userspace and the kernel lack the implicit padding (e.g., x86_32 userspace with x86_32 kernel), it should be fine...

- Eric

author
#2 lore raw
Quoted 25 lines · Eric Biggers
Quoted 2 lines · Chao Yu
include/uapi/linux/f2fs.h new file +2 -0
+#define F2FS_IOC_MOVE_RANGE		_IOWR(F2FS_IOCTL_MAGIC, 9,	\
+						struct f2fs_move_range)

[...]

Quoted 2 lines
include/uapi/linux/f2fs.h new file +2 -0
+#define F2FS_IOC_GARBAGE_COLLECT_RANGE	_IOW(F2FS_IOCTL_MAGIC, 11,	\
+						struct f2fs_gc_range)

[...]

Quoted 6 lines
include/uapi/linux/f2fs.h new file +6 -0
+
+struct f2fs_gc_range {
+	__u32 sync;
+	__u64 start;
+	__u64 len;
+};

[...]

include/uapi/linux/f2fs.h line 74

Quoted 6 lines
include/uapi/linux/f2fs.h new file +6 -0
+struct f2fs_move_range {
+	__u32 dst_fd;		/* destination fd */
+	__u64 pos_in;		/* start position in src_fd */
+	__u64 pos_out;		/* start position in dst_fd */
+	__u64 len;		/* size to move */
+};

These two structs are weird because there is implicit padding between the __u32 field and the following __u64 field on some 32-bit architectures (e.g. x86_32) but not others (e.g. arm32).

Quoted 4 lines

But f2fs_compat_ioctl() doesn't handle these two ioctls specially, but rather just calls through to f2fs_ioctl(). That's wrong, and it means that F2FS_IOC_MOVE_RANGE and F2FS_IOC_GARBAGE_COLLECT_RANGE won't work when called from an x86_32 binary on an x86_64 kernel.

Nice catch!

Quoted 5 lines

So something needs to be fixed. I wonder if it's safe to just explicitly add the padding field after the fact. If no one is actually using these two ioctls in a case where both userspace and the kernel lack the implicit padding (e.g., x86_32 userspace with x86_32 kernel), it should be fine...

IIRC, Jaegeuk added those interfaces, I hope it's not the requirement from other f2fs userspace developers...if it is, there may be users.

I found one patch in ext4 which fixes the similar issue, I guess we can fix this with the same way, thoughts?

commit 4d92dc0f00a775dc2e1267b0e00befb783902fe7

Author: Ben Hutchings <[email protected]>
Date:   Mon May 17 06:00:00 2010 -0400

ext4: Fix compat EXT4_IOC_ADD_GROUP

struct ext4_new_group_input needs to be converted because u64 has only 32-bit alignment on some 32-bit architectures, notably i386.

Thanks,

Quoted 4 lines

- Eric
.

maintainer
#3 lore raw
Quoted 39 lines · Chao Yu
Quoted 25 lines · Eric Biggers
Quoted 2 lines · Chao Yu
include/uapi/linux/f2fs.h new file +2 -0
+#define F2FS_IOC_MOVE_RANGE		_IOWR(F2FS_IOCTL_MAGIC, 9,	\
+						struct f2fs_move_range)

[...]

Quoted 2 lines
include/uapi/linux/f2fs.h new file +2 -0
+#define F2FS_IOC_GARBAGE_COLLECT_RANGE	_IOW(F2FS_IOCTL_MAGIC, 11,	\
+						struct f2fs_gc_range)

[...]

Quoted 6 lines
include/uapi/linux/f2fs.h new file +6 -0
+
+struct f2fs_gc_range {
+	__u32 sync;
+	__u64 start;
+	__u64 len;
+};

[...]

include/uapi/linux/f2fs.h line 74

Quoted 6 lines
include/uapi/linux/f2fs.h new file +6 -0
+struct f2fs_move_range {
+	__u32 dst_fd;		/* destination fd */
+	__u64 pos_in;		/* start position in src_fd */
+	__u64 pos_out;		/* start position in dst_fd */
+	__u64 len;		/* size to move */
+};

These two structs are weird because there is implicit padding between the __u32 field and the following __u64 field on some 32-bit architectures (e.g. x86_32) but not others (e.g. arm32).

Quoted 4 lines

But f2fs_compat_ioctl() doesn't handle these two ioctls specially, but rather just calls through to f2fs_ioctl(). That's wrong, and it means that F2FS_IOC_MOVE_RANGE and F2FS_IOC_GARBAGE_COLLECT_RANGE won't work when called from an x86_32 binary on an x86_64 kernel.

Nice catch!

Quoted 5 lines

So something needs to be fixed. I wonder if it's safe to just explicitly add the padding field after the fact. If no one is actually using these two ioctls in a case where both userspace and the kernel lack the implicit padding (e.g., x86_32 userspace with x86_32 kernel), it should be fine...

Quoted 5 lines

IIRC, Jaegeuk added those interfaces, I hope it's not the requirement from other f2fs userspace developers...if it is, there may be users.

I found one patch in ext4 which fixes the similar issue, I guess we can fix this with the same way, thoughts?

Agreed. Please fix along with f2fs-tools/f2fs_io.

Quoted 16 lines

commit 4d92dc0f00a775dc2e1267b0e00befb783902fe7

Author: Ben Hutchings <[email protected]>
Date:   Mon May 17 06:00:00 2010 -0400

ext4: Fix compat EXT4_IOC_ADD_GROUP

struct ext4_new_group_input needs to be converted because u64 has only 32-bit alignment on some 32-bit architectures, notably i386.

Thanks,

Quoted 4 lines

- Eric
.