[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 65/71] linux-user/aarch64: Move sve record checks into restore
From: |
Richard Henderson |
Subject: |
[PATCH 65/71] linux-user/aarch64: Move sve record checks into restore |
Date: |
Thu, 2 Jun 2022 14:48:47 -0700 |
Move the checks out of the parsing loop and into the
restore function. This more closely mirrors the code
structure in the kernel, and is slightly clearer.
Reject rather than silently skip incorrect VL and SVE record sizes.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/aarch64/signal.c | 51 +++++++++++++++++++++++++------------
1 file changed, 35 insertions(+), 16 deletions(-)
diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c
index 711fd19701..73b15038ad 100644
--- a/linux-user/aarch64/signal.c
+++ b/linux-user/aarch64/signal.c
@@ -250,12 +250,36 @@ static void target_restore_fpsimd_record(CPUARMState *env,
}
}
-static void target_restore_sve_record(CPUARMState *env,
- struct target_sve_context *sve, int vq)
+static bool target_restore_sve_record(CPUARMState *env,
+ struct target_sve_context *sve,
+ int size)
{
- int i, j;
+ int i, j, vl, vq;
- /* Note that SVE regs are stored as a byte stream, with each byte element
+ if (!cpu_isar_feature(aa64_sve, env_archcpu(env))) {
+ return false;
+ }
+
+ __get_user(vl, &sve->vl);
+ vq = sve_vq_cached(env);
+
+ /* Reject mismatched VL. */
+ if (vl != vq * TARGET_SVE_VQ_BYTES) {
+ return false;
+ }
+
+ /* Accept empty record -- used to clear PSTATE.SM. */
+ if (size <= sizeof(*sve)) {
+ return true;
+ }
+
+ /* Reject non-empty but incomplete record. */
+ if (size < TARGET_SVE_SIG_CONTEXT_SIZE(vq)) {
+ return false;
+ }
+
+ /*
+ * Note that SVE regs are stored as a byte stream, with each byte element
* at a subsequent address. This corresponds to a little-endian load
* of our 64-bit hunks.
*/
@@ -277,6 +301,7 @@ static void target_restore_sve_record(CPUARMState *env,
}
}
}
+ return true;
}
static int target_restore_sigframe(CPUARMState *env,
@@ -287,7 +312,7 @@ static int target_restore_sigframe(CPUARMState *env,
struct target_sve_context *sve = NULL;
uint64_t extra_datap = 0;
bool used_extra = false;
- int vq = 0, sve_size = 0;
+ int sve_size = 0;
target_restore_general_frame(env, sf);
@@ -321,15 +346,9 @@ static int target_restore_sigframe(CPUARMState *env,
if (sve || size < sizeof(struct target_sve_context)) {
goto err;
}
- if (cpu_isar_feature(aa64_sve, env_archcpu(env))) {
- vq = sve_vq_cached(env);
- sve_size = QEMU_ALIGN_UP(TARGET_SVE_SIG_CONTEXT_SIZE(vq), 16);
- if (size == sve_size) {
- sve = (struct target_sve_context *)ctx;
- break;
- }
- }
- goto err;
+ sve = (struct target_sve_context *)ctx;
+ sve_size = size;
+ break;
case TARGET_EXTRA_MAGIC:
if (extra || size != sizeof(struct target_extra_context)) {
@@ -362,8 +381,8 @@ static int target_restore_sigframe(CPUARMState *env,
}
/* SVE data, if present, overwrites FPSIMD data. */
- if (sve) {
- target_restore_sve_record(env, sve, vq);
+ if (sve && !target_restore_sve_record(env, sve, sve_size)) {
+ goto err;
}
unlock_user(extra, extra_datap, 0);
return 0;
--
2.34.1
- [PATCH 53/71] target/arm: Implement SME integer outer product, (continued)
- [PATCH 53/71] target/arm: Implement SME integer outer product, Richard Henderson, 2022/06/02
- [PATCH 60/71] linux-user/aarch64: Reset PSTATE.SM on syscalls, Richard Henderson, 2022/06/02
- [PATCH 61/71] linux-user/aarch64: Add SM bit to SVE signal context, Richard Henderson, 2022/06/02
- [PATCH 63/71] linux-user/aarch64: Do not allow duplicate or short sve records, Richard Henderson, 2022/06/02
- [PATCH 57/71] target/arm: Reset streaming sve state on exception boundaries, Richard Henderson, 2022/06/02
- [PATCH 59/71] linux-user/aarch64: Clear tpidr2_el0 if CLONE_SETTLS, Richard Henderson, 2022/06/02
- [PATCH 62/71] linux-user/aarch64: Tidy target_restore_sigframe error return, Richard Henderson, 2022/06/02
- [PATCH 47/71] target/arm: Export unpredicated ld/st from translate-sve.c, Richard Henderson, 2022/06/02
- [PATCH 66/71] linux-user/aarch64: Implement SME signal handling, Richard Henderson, 2022/06/02
- [PATCH 56/71] target/arm: Implement SCLAMP, UCLAMP, Richard Henderson, 2022/06/02
- [PATCH 65/71] linux-user/aarch64: Move sve record checks into restore,
Richard Henderson <=
- [PATCH 68/71] linux-user/aarch64: Implement PR_SME_GET_VL, PR_SME_SET_VL, Richard Henderson, 2022/06/02
- [PATCH 64/71] linux-user/aarch64: Verify extra record lock succeeded, Richard Henderson, 2022/06/02
- [PATCH 71/71] linux-user/aarch64: Add SME related hwcap entries, Richard Henderson, 2022/06/02
- [PATCH 67/71] linux-user: Rename sve prctls, Richard Henderson, 2022/06/02
- [PATCH 70/71] target/arm: Enable SME for user-only, Richard Henderson, 2022/06/02
- [PATCH 69/71] target/arm: Only set ZEN in reset if SVE present, Richard Henderson, 2022/06/02