linux-user/aarch64: Clear TPIDR2_EL0 when delivering signals
linux-user/aarch64: Support TPIDR2_MAGIC signal frame record linux-user/aarch64: Support ZT_MAGIC signal frame record -----BEGIN PGP SIGNATURE----- iQFRBAABCgA7FiEEekgeeIaLTbaoWgXAZN846K9+IV8FAmiF1rwdHHJpY2hhcmQu aGVuZGVyc29uQGxpbmFyby5vcmcACgkQZN846K9+IV935wf7BXGiD3m1MfLofofa w5/j4AjKw2sNAS3gVhmu9+BKKdctvNDxpNv4vx79j58iTuPCpi6roQ3vOEJWR0Vb 0UdJc/vNvFrXWLTW+W5nncKjCYZeTgSbWy3xwfnR3u4fk8YkUbGjVZ9TAgXl3dA1 NGagGqrlCqJpDYxbRWRIhXE+dF5zfNqU4gDTLG+C8xCN/gT7TkDIOU9sNb2uu1PC eI/SplpZYBDpdzpjko35peyq0tqUJrYT6P1MMjQckGpnKTSMynQmYvKVkloALRpW Zx3mBu9cWl77D57Fw4AijEiuUGhN0kZB12gH9VRp29rlTRr/MR4Y0seOU6XDc341 eGe5pg== =avvX -----END PGP SIGNATURE----- Merge tag 'pull-lu-20250726' of https://gitlab.com/rth7680/qemu into staging linux-user/aarch64: Clear TPIDR2_EL0 when delivering signals linux-user/aarch64: Support TPIDR2_MAGIC signal frame record linux-user/aarch64: Support ZT_MAGIC signal frame record # -----BEGIN PGP SIGNATURE----- # # iQFRBAABCgA7FiEEekgeeIaLTbaoWgXAZN846K9+IV8FAmiF1rwdHHJpY2hhcmQu # aGVuZGVyc29uQGxpbmFyby5vcmcACgkQZN846K9+IV935wf7BXGiD3m1MfLofofa # w5/j4AjKw2sNAS3gVhmu9+BKKdctvNDxpNv4vx79j58iTuPCpi6roQ3vOEJWR0Vb # 0UdJc/vNvFrXWLTW+W5nncKjCYZeTgSbWy3xwfnR3u4fk8YkUbGjVZ9TAgXl3dA1 # NGagGqrlCqJpDYxbRWRIhXE+dF5zfNqU4gDTLG+C8xCN/gT7TkDIOU9sNb2uu1PC # eI/SplpZYBDpdzpjko35peyq0tqUJrYT6P1MMjQckGpnKTSMynQmYvKVkloALRpW # Zx3mBu9cWl77D57Fw4AijEiuUGhN0kZB12gH9VRp29rlTRr/MR4Y0seOU6XDc341 # eGe5pg== # =avvX # -----END PGP SIGNATURE----- # gpg: Signature made Sun 27 Jul 2025 03:35:24 EDT # gpg: using RSA key 7A481E78868B4DB6A85A05C064DF38E8AF7E215F # gpg: issuer "richard.henderson@linaro.org" # gpg: Good signature from "Richard Henderson <richard.henderson@linaro.org>" [full] # Primary key fingerprint: 7A48 1E78 868B 4DB6 A85A 05C0 64DF 38E8 AF7E 215F * tag 'pull-lu-20250726' of https://gitlab.com/rth7680/qemu: linux-user/aarch64: Support ZT_MAGIC signal frame record linux-user/aarch64: Support TPIDR2_MAGIC signal frame record linux-user/aarch64: Clear TPIDR2_EL0 when delivering signals Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
commit
bf7da34454
1 changed files with 136 additions and 3 deletions
|
|
@ -121,6 +121,30 @@ struct target_za_context {
|
|||
#define TARGET_ZA_SIG_CONTEXT_SIZE(VQ) \
|
||||
TARGET_ZA_SIG_ZAV_OFFSET(VQ, VQ * TARGET_SVE_VQ_BYTES)
|
||||
|
||||
#define TARGET_TPIDR2_MAGIC 0x54504902
|
||||
|
||||
struct target_tpidr2_context {
|
||||
struct target_aarch64_ctx head;
|
||||
uint64_t tpidr2;
|
||||
};
|
||||
|
||||
#define TARGET_ZT_MAGIC 0x5a544e01
|
||||
|
||||
struct target_zt_context {
|
||||
struct target_aarch64_ctx head;
|
||||
uint16_t nregs;
|
||||
uint16_t reserved[3];
|
||||
/* ZTn register data immediately follows */
|
||||
};
|
||||
|
||||
#define TARGET_ZT_SIG_REG_BYTES (512 / 8)
|
||||
#define TARGET_ZT_SIG_REGS_SIZE(n) (TARGET_ZT_SIG_REG_BYTES * (n))
|
||||
#define TARGET_ZT_SIG_CONTEXT_SIZE(n) (sizeof(struct target_zt_context) + \
|
||||
TARGET_ZT_SIG_REGS_SIZE(n))
|
||||
#define TARGET_ZT_SIG_REGS_OFFSET sizeof(struct target_zt_context)
|
||||
QEMU_BUILD_BUG_ON(TARGET_ZT_SIG_REG_BYTES != \
|
||||
sizeof_field(CPUARMState, za_state.zt0));
|
||||
|
||||
struct target_rt_sigframe {
|
||||
struct target_siginfo info;
|
||||
struct target_ucontext uc;
|
||||
|
|
@ -253,6 +277,36 @@ static void target_setup_za_record(struct target_za_context *za,
|
|||
}
|
||||
}
|
||||
|
||||
static void target_setup_tpidr2_record(struct target_tpidr2_context *tpidr2,
|
||||
CPUARMState *env)
|
||||
{
|
||||
__put_user(TARGET_TPIDR2_MAGIC, &tpidr2->head.magic);
|
||||
__put_user(sizeof(struct target_tpidr2_context), &tpidr2->head.size);
|
||||
__put_user(env->cp15.tpidr2_el0, &tpidr2->tpidr2);
|
||||
}
|
||||
|
||||
static void target_setup_zt_record(struct target_zt_context *zt,
|
||||
CPUARMState *env, int size)
|
||||
{
|
||||
uint64_t *z;
|
||||
|
||||
memset(zt, 0, sizeof(*zt));
|
||||
__put_user(TARGET_ZT_MAGIC, &zt->head.magic);
|
||||
__put_user(size, &zt->head.size);
|
||||
/*
|
||||
* The record format allows for multiple ZT regs, but
|
||||
* currently there is only one, ZT0.
|
||||
*/
|
||||
__put_user(1, &zt->nregs);
|
||||
assert(size == TARGET_ZT_SIG_CONTEXT_SIZE(1));
|
||||
|
||||
/* ZT0 is the same byte-stream format as SVE regs and ZA */
|
||||
z = (void *)zt + TARGET_ZT_SIG_REGS_OFFSET;
|
||||
for (int i = 0; i < ARRAY_SIZE(env->za_state.zt0); i++) {
|
||||
__put_user_e(env->za_state.zt0[i], z + i, le);
|
||||
}
|
||||
}
|
||||
|
||||
static void target_restore_general_frame(CPUARMState *env,
|
||||
struct target_rt_sigframe *sf)
|
||||
{
|
||||
|
|
@ -403,6 +457,36 @@ static bool target_restore_za_record(CPUARMState *env,
|
|||
return true;
|
||||
}
|
||||
|
||||
static void target_restore_tpidr2_record(CPUARMState *env,
|
||||
struct target_tpidr2_context *tpidr2)
|
||||
{
|
||||
__get_user(env->cp15.tpidr2_el0, &tpidr2->tpidr2);
|
||||
}
|
||||
|
||||
static bool target_restore_zt_record(CPUARMState *env,
|
||||
struct target_zt_context *zt, int size,
|
||||
int svcr)
|
||||
{
|
||||
uint16_t nregs;
|
||||
uint64_t *z;
|
||||
|
||||
if (!(FIELD_EX64(svcr, SVCR, ZA))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
__get_user(nregs, &zt->nregs);
|
||||
|
||||
if (nregs != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
z = (void *)zt + TARGET_ZT_SIG_REGS_OFFSET;
|
||||
for (int i = 0; i < ARRAY_SIZE(env->za_state.zt0); i++) {
|
||||
__get_user_e(env->za_state.zt0[i], z + i, le);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int target_restore_sigframe(CPUARMState *env,
|
||||
struct target_rt_sigframe *sf)
|
||||
{
|
||||
|
|
@ -410,10 +494,13 @@ static int target_restore_sigframe(CPUARMState *env,
|
|||
struct target_fpsimd_context *fpsimd = NULL;
|
||||
struct target_sve_context *sve = NULL;
|
||||
struct target_za_context *za = NULL;
|
||||
struct target_tpidr2_context *tpidr2 = NULL;
|
||||
struct target_zt_context *zt = NULL;
|
||||
uint64_t extra_datap = 0;
|
||||
bool used_extra = false;
|
||||
int sve_size = 0;
|
||||
int za_size = 0;
|
||||
int zt_size = 0;
|
||||
int svcr = 0;
|
||||
|
||||
target_restore_general_frame(env, sf);
|
||||
|
|
@ -460,6 +547,23 @@ static int target_restore_sigframe(CPUARMState *env,
|
|||
za_size = size;
|
||||
break;
|
||||
|
||||
case TARGET_TPIDR2_MAGIC:
|
||||
if (tpidr2 || size != sizeof(struct target_tpidr2_context) ||
|
||||
!cpu_isar_feature(aa64_sme, env_archcpu(env))) {
|
||||
goto err;
|
||||
}
|
||||
tpidr2 = (struct target_tpidr2_context *)ctx;
|
||||
break;
|
||||
|
||||
case TARGET_ZT_MAGIC:
|
||||
if (zt || size != TARGET_ZT_SIG_CONTEXT_SIZE(1) ||
|
||||
!cpu_isar_feature(aa64_sme2, env_archcpu(env))) {
|
||||
goto err;
|
||||
}
|
||||
zt = (struct target_zt_context *)ctx;
|
||||
zt_size = size;
|
||||
break;
|
||||
|
||||
case TARGET_EXTRA_MAGIC:
|
||||
if (extra || size != sizeof(struct target_extra_context)) {
|
||||
goto err;
|
||||
|
|
@ -497,6 +601,16 @@ static int target_restore_sigframe(CPUARMState *env,
|
|||
if (za && !target_restore_za_record(env, za, za_size, &svcr)) {
|
||||
goto err;
|
||||
}
|
||||
if (tpidr2) {
|
||||
target_restore_tpidr2_record(env, tpidr2);
|
||||
}
|
||||
/*
|
||||
* NB that we must restore ZT after ZA so the check that there's
|
||||
* no ZT record if SVCR.ZA is 0 gets the right value of SVCR.
|
||||
*/
|
||||
if (zt && !target_restore_zt_record(env, zt, zt_size, svcr)) {
|
||||
goto err;
|
||||
}
|
||||
if (env->svcr != svcr) {
|
||||
env->svcr = svcr;
|
||||
arm_rebuild_hflags(env);
|
||||
|
|
@ -568,8 +682,9 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
|
|||
.total_size = offsetof(struct target_rt_sigframe,
|
||||
uc.tuc_mcontext.__reserved),
|
||||
};
|
||||
int fpsimd_ofs, fr_ofs, sve_ofs = 0, za_ofs = 0;
|
||||
int sve_size = 0, za_size = 0;
|
||||
int fpsimd_ofs, fr_ofs, sve_ofs = 0, za_ofs = 0, tpidr2_ofs = 0;
|
||||
int zt_ofs = 0;
|
||||
int sve_size = 0, za_size = 0, tpidr2_size = 0, zt_size = 0;
|
||||
struct target_rt_sigframe *frame;
|
||||
struct target_rt_frame_record *fr;
|
||||
abi_ulong frame_addr, return_addr;
|
||||
|
|
@ -585,6 +700,8 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
|
|||
sve_ofs = alloc_sigframe_space(sve_size, &layout);
|
||||
}
|
||||
if (cpu_isar_feature(aa64_sme, env_archcpu(env))) {
|
||||
tpidr2_size = sizeof(struct target_tpidr2_context);
|
||||
tpidr2_ofs = alloc_sigframe_space(tpidr2_size, &layout);
|
||||
/* ZA state needs saving only if it is enabled. */
|
||||
if (FIELD_EX64(env->svcr, SVCR, ZA)) {
|
||||
za_size = TARGET_ZA_SIG_CONTEXT_SIZE(sme_vq(env));
|
||||
|
|
@ -593,6 +710,12 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
|
|||
}
|
||||
za_ofs = alloc_sigframe_space(za_size, &layout);
|
||||
}
|
||||
if (cpu_isar_feature(aa64_sme2, env_archcpu(env)) &&
|
||||
FIELD_EX64(env->svcr, SVCR, ZA)) {
|
||||
/* If SME ZA storage is enabled, we must also save SME2 ZT0 */
|
||||
zt_size = TARGET_ZT_SIG_CONTEXT_SIZE(1);
|
||||
zt_ofs = alloc_sigframe_space(zt_size, &layout);
|
||||
}
|
||||
|
||||
if (layout.extra_ofs) {
|
||||
/* Reserve space for the extra end marker. The standard end marker
|
||||
|
|
@ -644,6 +767,12 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
|
|||
if (za_ofs) {
|
||||
target_setup_za_record((void *)frame + za_ofs, env, za_size);
|
||||
}
|
||||
if (tpidr2_ofs) {
|
||||
target_setup_tpidr2_record((void *)frame + tpidr2_ofs, env);
|
||||
}
|
||||
if (zt_ofs) {
|
||||
target_setup_zt_record((void *)frame + zt_ofs, env, zt_size);
|
||||
}
|
||||
|
||||
/* Set up the stack frame for unwinding. */
|
||||
fr = (void *)frame + fr_ofs;
|
||||
|
|
@ -666,8 +795,12 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
|
|||
env->btype = 2;
|
||||
}
|
||||
|
||||
/* Invoke the signal handler with both SM and ZA disabled. */
|
||||
/*
|
||||
* Invoke the signal handler with a clean SME state: both SM and ZA
|
||||
* disabled and TPIDR2_EL0 cleared.
|
||||
*/
|
||||
aarch64_set_svcr(env, 0, R_SVCR_SM_MASK | R_SVCR_ZA_MASK);
|
||||
env->cp15.tpidr2_el0 = 0;
|
||||
|
||||
if (info) {
|
||||
frame->info = *info;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue