diff options
Diffstat (limited to 'app-emulation/qemu/files')
3 files changed, 270 insertions, 0 deletions
diff --git a/app-emulation/qemu/files/qemu-7.1.0-faccessat2.patch b/app-emulation/qemu/files/qemu-7.1.0-faccessat2.patch new file mode 100644 index 000000000000..ea168f609fc8 --- /dev/null +++ b/app-emulation/qemu/files/qemu-7.1.0-faccessat2.patch @@ -0,0 +1,78 @@ +From 35a2c85f7d691db7aa2c47181902ac87478eef7a Mon Sep 17 00:00:00 2001 +From: WANG Xuerui <xen0n@gentoo.org> +Date: Sun, 9 Oct 2022 14:08:13 +0800 +Subject: [PATCH] linux-user: Implement faccessat2 +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +User space has been preferring this syscall for a while, due to its +closer match with C semantics, and newer platforms such as LoongArch +apparently have libc implementations that don't fallback to faccessat +so normal access checks are failing without the emulation in place. + +Tested by successfully emerging several packages within a Gentoo loong +stage3 chroot, emulated on amd64 with help of static qemu-loongarch64. + +Reported-by: Andreas K. Hüttel <dilfridge@gentoo.org> +Signed-off-by: WANG Xuerui <xen0n@gentoo.org> +Message-Id: <20221009060813.2289077-1-xen0n@gentoo.org> +[lv: removing defined(__NR_faccessat2) in syscall.c, + adding defined(TARGET_NR_faccessat2) on print_faccessat()] +Signed-off-by: Laurent Vivier <laurent@vivier.eu> +--- + linux-user/strace.c | 2 +- + linux-user/strace.list | 3 +++ + linux-user/syscall.c | 9 +++++++++ + 3 files changed, 13 insertions(+), 1 deletion(-) + +diff --git a/linux-user/strace.c b/linux-user/strace.c +index 86c081c83f..9ae5a812cd 100644 +--- a/linux-user/strace.c ++++ b/linux-user/strace.c +@@ -1969,7 +1969,7 @@ print_execv(CPUArchState *cpu_env, const struct syscallname *name, + } + #endif + +-#ifdef TARGET_NR_faccessat ++#if defined(TARGET_NR_faccessat) || defined(TARGET_NR_faccessat2) + static void + print_faccessat(CPUArchState *cpu_env, const struct syscallname *name, + abi_long arg0, abi_long arg1, abi_long arg2, +diff --git a/linux-user/strace.list b/linux-user/strace.list +index a87415bf3d..3df2184580 100644 +--- a/linux-user/strace.list ++++ b/linux-user/strace.list +@@ -178,6 +178,9 @@ + #ifdef TARGET_NR_faccessat + { TARGET_NR_faccessat, "faccessat" , NULL, print_faccessat, NULL }, + #endif ++#ifdef TARGET_NR_faccessat2 ++{ TARGET_NR_faccessat2, "faccessat2" , NULL, print_faccessat, NULL }, ++#endif + #ifdef TARGET_NR_fadvise64 + { TARGET_NR_fadvise64, "fadvise64" , NULL, NULL, NULL }, + #endif +diff --git a/linux-user/syscall.c b/linux-user/syscall.c +index d499cac1d5..e985ad167f 100644 +--- a/linux-user/syscall.c ++++ b/linux-user/syscall.c +@@ -9143,6 +9143,15 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, + unlock_user(p, arg2, 0); + return ret; + #endif ++#if defined(TARGET_NR_faccessat2) ++ case TARGET_NR_faccessat2: ++ if (!(p = lock_user_string(arg2))) { ++ return -TARGET_EFAULT; ++ } ++ ret = get_errno(faccessat(arg1, p, arg3, arg4)); ++ unlock_user(p, arg2, 0); ++ return ret; ++#endif + #ifdef TARGET_NR_nice /* not on alpha */ + case TARGET_NR_nice: + return get_errno(nice(arg1)); +-- +2.37.4 + diff --git a/app-emulation/qemu/files/qemu-7.1.0-loong-stat.patch b/app-emulation/qemu/files/qemu-7.1.0-loong-stat.patch new file mode 100644 index 000000000000..85fd2c98914a --- /dev/null +++ b/app-emulation/qemu/files/qemu-7.1.0-loong-stat.patch @@ -0,0 +1,98 @@ +From xen0n@gentoo.org Thu Oct 06 10:07:10 2022 +Return-Path: <xen0n@gentoo.org> +X-Original-To: dilfridge@gentoo.org +Delivered-To: dilfridge@gentoo.org +From: WANG Xuerui <xen0n@gentoo.org> +To: qemu-devel@nongnu.org +Cc: Richard Henderson <richard.henderson@linaro.org>, + =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= <f4bug@amsat.org>, + WANG Xuerui <xen0n@gentoo.org>, + Song Gao <gaosong@loongson.cn>, + Xiaojuan Yang <yangxiaojuan@loongson.cn>, + =?UTF-8?q?Andreas=20K=20=2E=20H=C3=BCttel?= <dilfridge@gentoo.org> +Subject: [PATCH RESEND] linux-user: Fix struct statfs ABI on loongarch64 +Date: Thu, 6 Oct 2022 18:07:10 +0800 +Message-Id: <20221006100710.427252-1-xen0n@gentoo.org> +X-Mailer: git-send-email 2.38.0 +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Previously the 32-bit version was incorrectly chosen, leading to funny +but incorrect output from e.g. df(1). Simply select the version +corresponding to the 64-bit asm-generic definition. + +For reference, this program should produce the same output no matter +natively compiled or not, for loongarch64 or not: + +```c +#include <stdio.h> +#include <sys/statfs.h> + +int main(int argc, const char *argv[]) +{ + struct statfs b; + if (statfs(argv[0], &b)) + return 1; + + printf("f_type = 0x%lx\n", b.f_type); + printf("f_bsize = %ld\n", b.f_bsize); + printf("f_blocks = %ld\n", b.f_blocks); + printf("f_bfree = %ld\n", b.f_bfree); + printf("f_bavail = %ld\n", b.f_bavail); + + return 0; +} + +// Example output on my amd64 box, with the test binary residing on a +// btrfs partition. + +// Native and emulated output after the fix: +// +// f_type = 0x9123683e +// f_bsize = 4096 +// f_blocks = 268435456 +// f_bfree = 168406890 +// f_bavail = 168355058 + +// Output before the fix, note the messed layout: +// +// f_type = 0x10009123683e +// f_bsize = 723302085239504896 +// f_blocks = 168355058 +// f_bfree = 2250817541779750912 +// f_bavail = 1099229433104 +``` + +Fixes: 1f63019632 ("linux-user: Add LoongArch syscall support") +Signed-off-by: WANG Xuerui <xen0n@gentoo.org> +Cc: Song Gao <gaosong@loongson.cn> +Cc: Xiaojuan Yang <yangxiaojuan@loongson.cn> +Cc: Andreas K. Hüttel <dilfridge@gentoo.org> +--- + +Resend with amended commit message to 100% clarify the example output +are generated on my box and will differ for everyone else. Sorry for +the noise. + + linux-user/syscall_defs.h | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h +index 01ee10a88f..77864de57f 100644 +--- a/linux-user/syscall_defs.h ++++ b/linux-user/syscall_defs.h +@@ -2262,7 +2262,8 @@ struct target_statfs64 { + }; + #elif (defined(TARGET_PPC64) || defined(TARGET_X86_64) || \ + defined(TARGET_SPARC64) || defined(TARGET_AARCH64) || \ +- defined(TARGET_RISCV)) && !defined(TARGET_ABI32) ++ defined(TARGET_RISCV) || defined(TARGET_LOONGARCH64)) && \ ++ !defined(TARGET_ABI32) + struct target_statfs { + abi_long f_type; + abi_long f_bsize; +-- +2.38.0 + + diff --git a/app-emulation/qemu/files/qemu-7.1.0-mips-n32-syscalls.patch b/app-emulation/qemu/files/qemu-7.1.0-mips-n32-syscalls.patch new file mode 100644 index 000000000000..5ed67668d0a6 --- /dev/null +++ b/app-emulation/qemu/files/qemu-7.1.0-mips-n32-syscalls.patch @@ -0,0 +1,94 @@ +From xen0n@gentoo.org Thu Oct 06 08:55:00 2022 +Return-Path: <xen0n@gentoo.org> +X-Original-To: dilfridge@gentoo.org +Delivered-To: dilfridge@gentoo.org +From: WANG Xuerui <xen0n@gentoo.org> +To: qemu-devel@nongnu.org +Cc: WANG Xuerui <xen0n@gentoo.org>, + =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= <f4bug@amsat.org>, + Jiaxun Yang <jiaxun.yang@flygoat.com>, + =?UTF-8?q?Andreas=20K=20=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>, + Joshua Kinard <kumba@gentoo.org> +Subject: [PATCH] linux-user: Fix more MIPS n32 syscall ABI issues +Date: Thu, 6 Oct 2022 16:55:00 +0800 +Message-Id: <20221006085500.290341-1-xen0n@gentoo.org> +X-Mailer: git-send-email 2.38.0 +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +In commit 80f0fe3a85 ("linux-user: Fix syscall parameter handling for +MIPS n32") the ABI problem regarding offset64 on MIPS n32 was fixed, +but still some cases remain where the n32 is incorrectly treated as any +other 32-bit ABI that passes 64-bit arguments in pairs of GPRs. Fix by +excluding TARGET_ABI_MIPSN32 from various TARGET_ABI_BITS == 32 checks. + +Closes: https://gitlab.com/qemu-project/qemu/-/issues/1238 +Signed-off-by: WANG Xuerui <xen0n@gentoo.org> +Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> +Cc: Jiaxun Yang <jiaxun.yang@flygoat.com> +Cc: Andreas K. Hüttel <dilfridge@gentoo.org> +Cc: Joshua Kinard <kumba@gentoo.org> +--- + +Note: I can't reproduce the crash with neither MIPS n32 sysroot at my hand +(a self-built one for Loongson-2F, and stage3-mips64_n32-openrc-20221001T170527Z), +so I can only verify by looking at the (host and qemu) strace outputs, and +would have to ask you to review/test this harder. Thanks. + + linux-user/syscall.c | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/linux-user/syscall.c b/linux-user/syscall.c +index 2e954d8dbd..8b2d39fe73 100644 +--- a/linux-user/syscall.c ++++ b/linux-user/syscall.c +@@ -11793,7 +11793,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, + return -host_to_target_errno(ret); + #endif + +-#if TARGET_ABI_BITS == 32 ++#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) + + #ifdef TARGET_NR_fadvise64_64 + case TARGET_NR_fadvise64_64: +@@ -11920,7 +11920,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, + return get_errno(sys_gettid()); + #ifdef TARGET_NR_readahead + case TARGET_NR_readahead: +-#if TARGET_ABI_BITS == 32 ++#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) + if (regpairs_aligned(cpu_env, num)) { + arg2 = arg3; + arg3 = arg4; +@@ -12612,7 +12612,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, + #endif /* CONFIG_EVENTFD */ + #if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate) + case TARGET_NR_fallocate: +-#if TARGET_ABI_BITS == 32 ++#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) + ret = get_errno(fallocate(arg1, arg2, target_offset64(arg3, arg4), + target_offset64(arg5, arg6))); + #else +@@ -12623,7 +12623,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, + #if defined(CONFIG_SYNC_FILE_RANGE) + #if defined(TARGET_NR_sync_file_range) + case TARGET_NR_sync_file_range: +-#if TARGET_ABI_BITS == 32 ++#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) + #if defined(TARGET_MIPS) + ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4), + target_offset64(arg5, arg6), arg7)); +@@ -12645,7 +12645,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, + case TARGET_NR_arm_sync_file_range: + #endif + /* This is like sync_file_range but the arguments are reordered */ +-#if TARGET_ABI_BITS == 32 ++#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) + ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4), + target_offset64(arg5, arg6), arg2)); + #else +-- +2.38.0 + + |