[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 63/66] linux-user: Add code for PR_GET/SET_UNALIGN
From: |
Richard Henderson |
Subject: |
[PATCH v6 63/66] linux-user: Add code for PR_GET/SET_UNALIGN |
Date: |
Sat, 30 Oct 2021 10:16:32 -0700 |
This requires extra work for each target, but adds the
common syscall code, and the necessary flag in CPUState.
Reviewed-by: Warner Losh <imp@bsdimp.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/hw/core/cpu.h | 3 +++
linux-user/generic/target_prctl_unalign.h | 27 +++++++++++++++++++++++
cpu.c | 20 ++++++++++++-----
linux-user/syscall.c | 13 +++++++++--
4 files changed, 56 insertions(+), 7 deletions(-)
create mode 100644 linux-user/generic/target_prctl_unalign.h
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 1a10497af3..6202bbf9c3 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -412,6 +412,9 @@ struct CPUState {
bool ignore_memory_transaction_failures;
+ /* Used for user-only emulation of prctl(PR_SET_UNALIGN). */
+ bool prctl_unalign_sigbus;
+
struct hax_vcpu_state *hax_vcpu;
struct hvf_vcpu_state *hvf;
diff --git a/linux-user/generic/target_prctl_unalign.h
b/linux-user/generic/target_prctl_unalign.h
new file mode 100644
index 0000000000..bc3b83af2a
--- /dev/null
+++ b/linux-user/generic/target_prctl_unalign.h
@@ -0,0 +1,27 @@
+/*
+ * Generic prctl unalign functions for linux-user
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef GENERIC_TARGET_PRCTL_UNALIGN_H
+#define GENERIC_TARGET_PRCTL_UNALIGN_H
+
+static abi_long do_prctl_get_unalign(CPUArchState *env, target_long arg2)
+{
+ CPUState *cs = env_cpu(env);
+ uint32_t res = PR_UNALIGN_NOPRINT;
+ if (cs->prctl_unalign_sigbus) {
+ res |= PR_UNALIGN_SIGBUS;
+ }
+ return put_user_u32(res, arg2);
+}
+#define do_prctl_get_unalign do_prctl_get_unalign
+
+static abi_long do_prctl_set_unalign(CPUArchState *env, target_long arg2)
+{
+ env_cpu(env)->prctl_unalign_sigbus = arg2 & PR_UNALIGN_SIGBUS;
+ return 0;
+}
+#define do_prctl_set_unalign do_prctl_set_unalign
+
+#endif /* GENERIC_TARGET_PRCTL_UNALIGN_H */
diff --git a/cpu.c b/cpu.c
index 9bce67ef55..9e388d9cd3 100644
--- a/cpu.c
+++ b/cpu.c
@@ -179,13 +179,23 @@ void cpu_exec_unrealizefn(CPUState *cpu)
cpu_list_remove(cpu);
}
+/*
+ * This can't go in hw/core/cpu.c because that file is compiled only
+ * once for both user-mode and system builds.
+ */
static Property cpu_common_props[] = {
-#ifndef CONFIG_USER_ONLY
+#ifdef CONFIG_USER_ONLY
/*
- * Create a memory property for softmmu CPU object,
- * so users can wire up its memory. (This can't go in hw/core/cpu.c
- * because that file is compiled only once for both user-mode
- * and system builds.) The default if no link is set up is to use
+ * Create a property for the user-only object, so users can
+ * adjust prctl(PR_SET_UNALIGN) from the command-line.
+ * Has no effect if the target does not support the feature.
+ */
+ DEFINE_PROP_BOOL("prctl-unalign-sigbus", CPUState,
+ prctl_unalign_sigbus, false),
+#else
+ /*
+ * Create a memory property for softmmu CPU object, so users can
+ * wire up its memory. The default if no link is set up is to use
* the system address space.
*/
DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION,
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7635c2397a..ac3bc8a330 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6375,6 +6375,12 @@ static abi_long do_prctl_inval1(CPUArchState *env,
abi_long arg2)
#ifndef do_prctl_get_tagged_addr_ctrl
#define do_prctl_get_tagged_addr_ctrl do_prctl_inval0
#endif
+#ifndef do_prctl_get_unalign
+#define do_prctl_get_unalign do_prctl_inval1
+#endif
+#ifndef do_prctl_set_unalign
+#define do_prctl_set_unalign do_prctl_inval1
+#endif
static abi_long do_prctl(CPUArchState *env, abi_long option, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
@@ -6438,6 +6444,11 @@ static abi_long do_prctl(CPUArchState *env, abi_long
option, abi_long arg2,
}
return do_prctl_get_tagged_addr_ctrl(env);
+ case PR_GET_UNALIGN:
+ return do_prctl_get_unalign(env, arg2);
+ case PR_SET_UNALIGN:
+ return do_prctl_set_unalign(env, arg2);
+
case PR_GET_DUMPABLE:
case PR_SET_DUMPABLE:
case PR_GET_KEEPCAPS:
@@ -6480,8 +6491,6 @@ static abi_long do_prctl(CPUArchState *env, abi_long
option, abi_long arg2,
case PR_SET_THP_DISABLE:
case PR_GET_TSC:
case PR_SET_TSC:
- case PR_GET_UNALIGN:
- case PR_SET_UNALIGN:
default:
/* Disable to prevent the target disabling stuff we need. */
return -TARGET_EINVAL;
--
2.25.1
- [PATCH v6 59/66] tcg: Add helper_unaligned_{ld, st} for user-only sigbus, (continued)
- [PATCH v6 59/66] tcg: Add helper_unaligned_{ld, st} for user-only sigbus, Richard Henderson, 2021/10/30
- [PATCH v6 57/66] accel/tcg: Report unaligned atomics for user-only, Richard Henderson, 2021/10/30
- [PATCH v6 60/66] linux-user: Handle BUS_ADRALN in host_signal_handler, Richard Henderson, 2021/10/30
- [PATCH v6 56/66] target/sparc: Set fault address in sparc_cpu_do_unaligned_access, Richard Henderson, 2021/10/30
- [PATCH v6 62/66] linux-user: Disable more prctl subcodes, Richard Henderson, 2021/10/30
- [PATCH v6 54/66] target/sparc: Remove DEBUG_UNALIGNED, Richard Henderson, 2021/10/30
- [PATCH v6 53/66] target/sh4: Set fault address in superh_cpu_do_unaligned_access, Richard Henderson, 2021/10/30
- [PATCH v6 65/66] target/hppa: Implement prctl_unalign_sigbus, Richard Henderson, 2021/10/30
- [PATCH v6 48/66] target/ppc: Move SPR_DSISR setting to powerpc_excp, Richard Henderson, 2021/10/30
- [PATCH v6 58/66] accel/tcg: Report unaligned load/store for user-only, Richard Henderson, 2021/10/30
- [PATCH v6 63/66] linux-user: Add code for PR_GET/SET_UNALIGN,
Richard Henderson <=
- [PATCH v6 47/66] target/microblaze: Do not set MO_ALIGN for user-only, Richard Henderson, 2021/10/30
- [PATCH v6 55/66] target/sparc: Split out build_sfsr, Richard Henderson, 2021/10/30
- [PATCH v6 61/66] linux-user: Split out do_prctl and subroutines, Richard Henderson, 2021/10/30
- [PATCH v6 64/66] target/alpha: Implement prctl_unalign_sigbus, Richard Henderson, 2021/10/30
- [PATCH v6 66/66] target/sh4: Implement prctl_unalign_sigbus, Richard Henderson, 2021/10/30
- Re: [PATCH v6 00/66] user-only: Cleanup SIGSEGV and SIGBUS handling, Philippe Mathieu-Daudé, 2021/10/31