From: Jonathan Albrecht <jonathan.albrecht@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: ruixin.bao@ibm.com, qemu-s390x@nongnu.org,
Jonathan Albrecht <jonathan.albrecht@linux.vnet.ibm.com>,
Laurent Vivier <laurent@vivier.eu>,
jonathan.albrecht@ibm.com
Subject: [PATCH RFC 1/1] linux-user/s390x: save/restore condition code state during signal handling
Date: Thu, 10 Jun 2021 14:58:23 -0400 [thread overview]
Message-ID: <20210610185823.14817-2-jonathan.albrecht@linux.vnet.ibm.com> (raw)
In-Reply-To: <20210610185823.14817-1-jonathan.albrecht@linux.vnet.ibm.com>
When handling a signal, the signal handler may have clobbered the
condition code set by the interrupted thread.
Signed-off-by: Jonathan Albrecht <jonathan.albrecht@linux.vnet.ibm.com>
Buglink: https://bugs.launchpad.net/qemu/+bug/1886793
Buglink: https://bugs.launchpad.net/qemu/+bug/1893040
---
linux-user/s390x/signal.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c
index ef136dae33..03cacb2829 100644
--- a/linux-user/s390x/signal.c
+++ b/linux-user/s390x/signal.c
@@ -65,6 +65,10 @@ typedef struct {
uint8_t callee_used_stack[__SIGNAL_FRAMESIZE];
target_sigcontext sc;
target_sigregs sregs;
+ uint32_t scc_op;
+ uint64_t scc_src;
+ uint64_t scc_dst;
+ uint64_t scc_vr;
int signo;
target_sigregs_ext sregs_ext;
uint16_t retcode;
@@ -86,6 +90,10 @@ typedef struct {
uint8_t callee_used_stack[__SIGNAL_FRAMESIZE];
uint16_t retcode;
struct target_siginfo info;
+ uint32_t scc_op;
+ uint64_t scc_src;
+ uint64_t scc_dst;
+ uint64_t scc_vr;
struct target_ucontext uc;
} rt_sigframe;
@@ -224,6 +232,12 @@ void setup_frame(int sig, struct target_sigaction *ka,
env->regs[5] = 0; /* FIXME: regs->int_parm_long */
env->regs[6] = 0; /* FIXME: current->thread.last_break */
+ /* Some programs could clobber the condition code, so save it here */
+ __put_user(env->cc_op, &frame->scc_op);
+ __put_user(env->cc_src, &frame->scc_src);
+ __put_user(env->cc_dst, &frame->scc_dst);
+ __put_user(env->cc_vr, &frame->scc_vr);
+
unlock_user_struct(frame, frame_addr, 1);
}
@@ -273,6 +287,12 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
save_sigregs_ext(env, &frame->uc.tuc_mcontext_ext);
tswap_sigset(&frame->uc.tuc_sigmask, set);
+ /* Some programs could clobber the condition code, so save it here */
+ __put_user(env->cc_op, &frame->scc_op);
+ __put_user(env->cc_src, &frame->scc_src);
+ __put_user(env->cc_dst, &frame->scc_dst);
+ __put_user(env->cc_vr, &frame->scc_vr);
+
/* Set up registers for signal handler */
env->regs[14] = restorer;
env->regs[15] = frame_addr;
@@ -285,6 +305,10 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
env->regs[3] = frame_addr + offsetof(typeof(*frame), info);
env->regs[4] = frame_addr + offsetof(typeof(*frame), uc);
env->regs[5] = 0; /* FIXME: current->thread.last_break */
+
+ /* QUESTION: Was there a missing unlock user struct here? */
+ unlock_user_struct(frame, frame_addr, 1);
+ return;
}
static void restore_sigregs(CPUS390XState *env, target_sigregs *sc)
@@ -350,6 +374,12 @@ long do_sigreturn(CPUS390XState *env)
restore_sigregs(env, &frame->sregs);
restore_sigregs_ext(env, &frame->sregs_ext);
+ /* restore the condition code */
+ __get_user(env->cc_op, &frame->scc_op);
+ __get_user(env->cc_src, &frame->scc_src);
+ __get_user(env->cc_dst, &frame->scc_dst);
+ __get_user(env->cc_vr, &frame->scc_vr);
+
unlock_user_struct(frame, frame_addr, 0);
return -TARGET_QEMU_ESIGRETURN;
}
@@ -372,6 +402,11 @@ long do_rt_sigreturn(CPUS390XState *env)
restore_sigregs(env, &frame->uc.tuc_mcontext);
restore_sigregs_ext(env, &frame->uc.tuc_mcontext_ext);
+ /* restore the condition code */
+ __get_user(env->cc_op, &frame->scc_op);
+ __get_user(env->cc_src, &frame->scc_src);
+ __get_user(env->cc_dst, &frame->scc_dst);
+ __get_user(env->cc_vr, &frame->scc_vr);
target_restore_altstack(&frame->uc.tuc_stack, env);
unlock_user_struct(frame, frame_addr, 0);
--
2.31.1
next prev parent reply other threads:[~2021-06-10 21:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-10 18:58 [PATCH RFC 0/1] linux-user/s390x: save/restore condition code state during signal handling Jonathan Albrecht
2021-06-10 18:58 ` Jonathan Albrecht [this message]
2021-06-11 15:18 ` [PATCH RFC 1/1] " Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210610185823.14817-2-jonathan.albrecht@linux.vnet.ibm.com \
--to=jonathan.albrecht@linux.vnet.ibm.com \
--cc=jonathan.albrecht@ibm.com \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=ruixin.bao@ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).