[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 39/45] linux-user/aarch64: Move sve record checks into restore
From: |
Richard Henderson |
Subject: |
[PATCH v5 39/45] linux-user/aarch64: Move sve record checks into restore |
Date: |
Wed, 6 Jul 2022 13:54:05 +0530 |
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,
bringing our checks in to line with those the kernel does.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
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 9ff79da4be..22d0b8b4ec 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(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(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 v5 35/45] linux-user/aarch64: Add SM bit to SVE signal context, (continued)
- [PATCH v5 35/45] linux-user/aarch64: Add SM bit to SVE signal context, Richard Henderson, 2022/07/06
- [PATCH v5 36/45] linux-user/aarch64: Tidy target_restore_sigframe error return, Richard Henderson, 2022/07/06
- [PATCH v5 38/45] linux-user/aarch64: Verify extra record lock succeeded, Richard Henderson, 2022/07/06
- [PATCH v5 28/45] target/arm: Implement PSEL, Richard Henderson, 2022/07/06
- [PATCH v5 31/45] target/arm: Reset streaming sve state on exception boundaries, Richard Henderson, 2022/07/06
- [PATCH v5 33/45] linux-user/aarch64: Clear tpidr2_el0 if CLONE_SETTLS, Richard Henderson, 2022/07/06
- [PATCH v5 34/45] linux-user/aarch64: Reset PSTATE.SM on syscalls, Richard Henderson, 2022/07/06
- [PATCH v5 37/45] linux-user/aarch64: Do not allow duplicate or short sve records, Richard Henderson, 2022/07/06
- [PATCH v5 39/45] linux-user/aarch64: Move sve record checks into restore,
Richard Henderson <=
- [PATCH v5 40/45] linux-user/aarch64: Implement SME signal handling, Richard Henderson, 2022/07/06
- [PATCH v5 41/45] linux-user: Rename sve prctls, Richard Henderson, 2022/07/06
- [PATCH v5 42/45] linux-user/aarch64: Implement PR_SME_GET_VL, PR_SME_SET_VL, Richard Henderson, 2022/07/06
- [PATCH v5 43/45] target/arm: Only set ZEN in reset if SVE present, Richard Henderson, 2022/07/06
- [PATCH v5 44/45] target/arm: Enable SME for user-only, Richard Henderson, 2022/07/06
- [PATCH v5 45/45] linux-user/aarch64: Add SME related hwcap entries, Richard Henderson, 2022/07/06
- Re: [PATCH v5 00/45] target/arm: Scalable Matrix Extension, Peter Maydell, 2022/07/07