linux-user: implement fsmount(2) series of syscalls
cover linux-user: implement fsmount(2) series of syscalls
The motivation of the implementation is to make the systemd-nspawn container to boot guest OSes with systemd v259+, otherwise any systemd service requires importing credentials will fail, including journald, D-Bus service and getty. We used to work around this issue by patching systemd to retry the clone() without CLONE_NEWNS, which is not and can not be implemented in QEMU user emulation.
mount(8) from util-linux works because it will fallback to the old mount(2) syscall if fsmount(8) series of syscalls is not available.
Tested good on an x86-64 host, with:
- an AOSC OS mips64r6el guest, which boots successfully with full systemd support using systemd-nspawn(1).
- a Gentoo ppc (big endian) guest, which boots successfully with full systemd support, using systemd-nspawn(1).
Xinhui Yang (2):
linux-user: implement fsmount(2) series of syscalls linux-user/strace: add fsmount series of syscalls
linux-user/strace.c | 102 +++++++++++++++++++++++++++++++++++++++++ linux-user/strace.list | 15 ++++++ linux-user/syscall.c | 77 +++++++++++++++++++++++++++++++ 3 files changed, 194 insertions(+)
Signature · 1 line
2.52.0
My apologies, I made a typo in the destination address of the patches. The patches were CC'd to the correct mailing list - should I send again?
Quoted 17 lines · Xinhui Yang
The motivation of the implementation is to make the systemd-nspawn container to boot guest OSes with systemd v259+, otherwise any systemd service requires importing credentials will fail, including journald, D-Bus service and getty. We used to work around this issue by patching systemd to retry the
clone()withoutCLONE_NEWNS, which is not and can not be implemented in QEMU user emulation.mount(8) from util-linux works because it will fallback to the old mount(2) syscall if fsmount(8) series of syscalls is not available.
Tested good on an x86-64 host, with:
- an AOSC OS mips64r6el guest, which boots successfully with full systemd support using systemd-nspawn(1).
- a Gentoo ppc (big endian) guest, which boots successfully with full systemd support, using systemd-nspawn(1).
Quoted 9 lines
Xinhui Yang (2):
linux-user: implement fsmount(2) series of syscalls linux-user/strace: add fsmount series of syscallslinux-user/strace.c | 102 +++++++++++++++++++++++++++++++++++++++++ linux-user/strace.list | 15 ++++++ linux-user/syscall.c | 77 +++++++++++++++++++++++++++++++ 3 files changed, 194 insertions(+)
Xinhui
PATCH 1/2 linux-user: implement fsmount(2) series of syscalls
In reply to Xinhui YangThis series of syscalls replaces the old mount(2) syscall with a series of syscalls that operates around a filesystem context. This series of syscalls are available since Linux 5.2 and glibc 2.36+.
Their users include systemd since v259 and libmount from util-linux, and possibly other widely used projects.
Preliminary checks are implemented to ensure the validity of the interface.
--- linux-user/syscall.c | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+)
linux-user/syscall.c +77 -0
@@ -14412,6 +14412,83 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,return do_map_shadow_stack (cpu_env, arg1, arg2, arg3);#endif +#if defined(TARGET_NR_fsopen) +case TARGET_NR_fsopen: + { + p =lock_user_string (arg1); +if (!p) { +return -TARGET_EFAULT ; + } + ret =get_errno (fsopen (p, arg2)); +unlock_user (p, arg1,0 ); + } +return ret; +case TARGET_NR_fsconfig: + { +/* +* fsconfig(int, int, char *, void *, int) +* NOTE: p4 is nullable and its type might not be a string. +*/ +void *p3, *p4; +int cmd = (int ) arg2; +switch (cmd) { +case FSCONFIG_SET_BINARY : +case FSCONFIG_SET_STRING : +case FSCONFIG_SET_PATH : +case FSCONFIG_SET_PATH_EMPTY : + p3 =lock_user_string (arg3); +if (cmd !=FSCONFIG_SET_BINARY ) { +/* key and value must be strings. */ + p4 =lock_user_string (arg4); + }else { +/* Otherise the value must be a raw buffer. */ + p4 =lock_user (VERIFY_READ , arg4, arg5,1 ); + } +if (!p3 || !p4) { +return -TARGET_EFAULT ; + } + ret =get_errno (fsconfig (arg1, arg2, p3, p4, arg5)); +unlock_user (p3, arg3,0 ); +unlock_user (p4, arg4,0 ); +break ; + +case FSCONFIG_SET_FLAG : +case FSCONFIG_SET_FD : +/* value must be NULL. */ + p3 =lock_user_string (arg3); +if (!p3 || arg4) { +return -TARGET_EFAULT ; + } + ret =get_errno (fsconfig (arg1, arg2, p3,NULL , arg5)); +unlock_user (p3, arg3,0 ); +break ; +case FSCONFIG_CMD_CREATE : +case FSCONFIG_CMD_RECONFIGURE : +#ifdef FSCONFIG_CMD_CREATE_EXCL +case FSCONFIG_CMD_CREATE_EXCL : +#endif +/* key and value must be NULL, aux must be 0. */ +if (arg3 || arg4 || arg5) { +return -TARGET_EFAULT ; + } + ret =get_errno (fsconfig (arg1, arg2,NULL ,NULL ,0 )); +break ; +default : +return -TARGET_EFAULT ; + } + } +return ret; +case TARGET_NR_fsmount: + ret =get_errno (fsmount (arg1, arg2, arg3)); +return ret; +case TARGET_NR_fspick: + { + p =lock_user_string (arg2); + ret =get_errno (fspick (arg1, p, arg3)); +unlock_user (p, arg2,0 ); + } +return ret; +#endif default :qemu_log_mask (LOG_UNIMP ,"Unsupported syscall: %d\n" , num);return -TARGET_ENOSYS ;
Signature · 1 line
2.52.0
PATCH 2/2 linux-user/strace: add fsmount series of syscalls
In reply to Xinhui YangFollowing the addition of fsmount(2) series of syscalls in the syscall handler, strace support is added, with a dedicated function to print the parameters of fsconfig(2), which contains parameters that can be interpreted as multiple types.
Snippet of the strace dump when running mount -t tmpfs tmpfs /dir:
18 fsopen(tmpfs,1) = 3
18 read(3,0x407fcf1c,8191) = -1 errno=61 (No data available) 18 fsconfig(3,FSCONFIG_SET_STRING,"source","tmpfs",0) = 0
18 read(3,0x407fce3c,8191) = -1 errno=61 (No data available) 18 fsconfig(3,FSCONFIG_CMD_CREATE,NULL,NULL,0) = 0
18 read(3,0x407fce3c,8191) = -1 errno=61 (No data available) 18 fsmount(3,1,0) = 4
18 read(3,0x407fce3c,8191) = -1 errno=61 (No data available) 18 statx(4,"",AT_EMPTY_PATH|AT_STATX_SYNC_AS_STAT,0x1000,0x407fee98) = 0 18 move_mount(4,,-100,/media,4) = 0
18 read(3,0x407fcfcc,8191) = -1 errno=61 (No data available) 18 close(3) = 0
18 close(4) = 0
--- linux-user/strace.c | 102 +++++++++++++++++++++++++++++++++++++++++ linux-user/strace.list | 15 ++++++ 2 files changed, 117 insertions(+)
linux-user/strace.c +102 -0
@@ -4344,6 +4344,108 @@ print_statx(CPUArchState *cpu_env, const struct syscallname *name, }#endif +#ifdef TARGET_NR_fsconfig +static void +print_fsconfig_cmd_name (int cmd) +{ +switch (cmd) { +case FSCONFIG_SET_FLAG : +qemu_log ("%s%s" ,"FSCONFIG_SET_FLAG" ,get_comma (0 )); +break ; +case FSCONFIG_SET_STRING : +qemu_log ("%s%s" ,"FSCONFIG_SET_STRING" ,get_comma (0 )); +break ; +case FSCONFIG_SET_BINARY : +qemu_log ("%s%s" ,"FSCONFIG_SET_BINARY" ,get_comma (0 )); +break ; +case FSCONFIG_SET_PATH : +qemu_log ("%s%s" ,"FSCONFIG_SET_PATH" ,get_comma (0 )); +break ; +case FSCONFIG_SET_PATH_EMPTY : +qemu_log ("%s%s" ,"FSCONFIG_SET_PATH_EMPTY" ,get_comma (0 )); +break ; +case FSCONFIG_SET_FD : +qemu_log ("%s%s" ,"FSCONFIG_SET_FD" ,get_comma (0 )); +break ; +case FSCONFIG_CMD_CREATE : +qemu_log ("%s%s" ,"FSCONFIG_CMD_CREATE" ,get_comma (0 )); +break ; +case FSCONFIG_CMD_RECONFIGURE : +qemu_log ("%s%s" ,"FSCONFIG_CMD_RECONFIGURE" ,get_comma (0 )); +break ; +case FSCONFIG_CMD_CREATE_EXCL : +qemu_log ("%s%s" ,"FSCONFIG_CMD_CREATE_EXCL" ,get_comma (0 )); +break ; +default : +qemu_log ("%s (%d)%s" ,"UNKNOWN_CMD" , cmd,get_comma (0 )); +break ; + } +} + +static void +print_fsconfig (CPUArchState *cpu_env,const struct syscallname *name, +abi_long arg0,abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +/* +* fsconfig(int fd, int cmd, char* key, void* value, int aux) +* Where: +* fd: file descriptor returned by fsopen(). +* cmd: integer constant specifying a command. +* key: a string, can be NULL on certain commands. +* value: any data in a buffer, can be NULL, raw buffer or a string. +* aux: axillary values such as flags for FSCONFIG_SET_PATH. +*/ +int cmd = (int ) arg1; +print_syscall_prologue (name); +print_raw_param ("%d" , arg0,0 ); +print_fsconfig_cmd_name (cmd); +/* Process arg2 (key). */ +switch (cmd) { +case FSCONFIG_SET_FLAG : +case FSCONFIG_SET_STRING : +case FSCONFIG_SET_BINARY : +case FSCONFIG_SET_PATH : +case FSCONFIG_SET_PATH_EMPTY : +case FSCONFIG_SET_FD : +print_string (arg2,0 ); +break ; +default : +print_pointer (arg2,0 ); +break ; + } +/* Process arg3 (value). */ +switch (cmd) { +case FSCONFIG_SET_STRING : +case FSCONFIG_SET_PATH : +case FSCONFIG_SET_PATH_EMPTY : +print_string (arg3,0 ); +break ; +default : +print_pointer (arg3,0 ); +break ; + } +/* +* Process arg4 (aux). +* On FSCONFIG_SET_PATH and FSCONFIG_SET_PATH_EMPTY, aux can +* be either 0 or AT_FDCWD. +* On FSCONFIG_SET_BINARY, aux is an integer to state the length +* of the buffer pointed by arg3. +* Otherwise, it must be 0. +*/ +switch (cmd) { +case FSCONFIG_SET_PATH : +case FSCONFIG_SET_PATH_EMPTY : +print_at_dirfd (arg4,1 ); +break ; +default : +print_raw_param ("%d" , arg4,1 ); +break ; + } +print_syscall_epilogue (name); +} +#endif +#ifdef TARGET_NR_ioctl static void print_ioctl(CPUArchState *cpu_env, const struct syscallname *name,
linux-user/strace.list +15 -0
@@ -1722,3 +1722,18 @@ #ifdef TARGET_NR_rseq { TARGET_NR_rseq, "rseq" , "%s(%p,%u,%d,%#x)", NULL, NULL }, #endif +#ifdef TARGET_NR_fsopen +{ TARGET_NR_fsopen, "fsopen", "%s(%s,%d)", NULL, NULL }, +#endif +#ifdef TARGET_NR_fsconfig +{ TARGET_NR_fsconfig, "fsconfig", NULL, print_fsconfig, NULL }, +#endif +#ifdef TARGET_NR_fsmount +{ TARGET_NR_fsmount, "fsmount", "%s(%d,%d,%d)", NULL, NULL }, +#endif +#ifdef TARGET_NR_move_mount +{ TARGET_NR_move_mount, "move_mount", "%s(%d,%s,%d,%s,%d)", NULL, NULL }, +#endif +#ifdef TARGET_NR_fspick +{ TARGET_NR_fspick, "fspick", "%s(%d,%s,%d)", NULL, NULL }, +#endif
Signature · 1 line
2.52.0
Quoted 17 lines · Xinhui Yang
The motivation of the implementation is to make the systemd-nspawn container to boot guest OSes with systemd v259+, otherwise any systemd service requires importing credentials will fail, including journald, D-Bus service and getty. We used to work around this issue by patching systemd to retry the
clone()withoutCLONE_NEWNS, which is not and can not be implemented in QEMU user emulation.mount(8) from util-linux works because it will fallback to the old mount(2) syscall if fsmount(8) series of syscalls is not available.
Tested good on an x86-64 host, with:
- an AOSC OS mips64r6el guest, which boots successfully with full systemd support using systemd-nspawn(1).
- a Gentoo ppc (big endian) guest, which boots successfully with full systemd support, using systemd-nspawn(1).
Quoted 8 lines
Xinhui Yang (2):
linux-user: implement fsmount(2) series of syscalls linux-user/strace: add fsmount series of syscallslinux-user/strace.c | 102 +++++++++++++++++++++++++++++++++++++++++ linux-user/strace.list | 15 ++++++ linux-user/syscall.c | 77 +++++++++++++++++++++++++++++++ 3 files changed, 194 insertions(+)
I'm picking this up for the active qemu stable series. This is a new feature, but the new interfaces are used in more and more software, so it becomes a defect not to have that interface :)
Thanks,
/mjt