From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: ruixin.bao@ibm.com, jonathan.albrecht@linux.vnet.ibm.com,
cohuck@redhat.com, qemu-s390x@nongnu.org, david@redhat.com
Subject: [PATCH 5/5] linux-user/s390x: Save and restore psw.mask properly
Date: Mon, 14 Jun 2021 20:07:44 -0700 [thread overview]
Message-ID: <20210615030744.1252385-6-richard.henderson@linaro.org> (raw)
In-Reply-To: <20210615030744.1252385-1-richard.henderson@linaro.org>
At present, we're referencing env->psw.mask directly, which
fails to ensure that env->cc_op is incorporated or updated.
Use s390_cpu_{set_psw,get_psw_mask} to fix this.
Mirror the kernel's cleaning of the psw.mask in save_sigregs
and restore_sigregs. Ignore PSW_MASK_RI for now, as qemu does
not support that.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/s390x/signal.c | 37 ++++++++++++++++++++++++++++++++-----
1 file changed, 32 insertions(+), 5 deletions(-)
diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c
index ef136dae33..bf8a8fbfe9 100644
--- a/linux-user/s390x/signal.c
+++ b/linux-user/s390x/signal.c
@@ -112,15 +112,23 @@ get_sigframe(struct target_sigaction *ka, CPUS390XState *env, size_t frame_size)
return (sp - frame_size) & -8ul;
}
+#define PSW_USER_BITS (PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | \
+ PSW_MASK_MCHECK | PSW_MASK_PSTATE | PSW_ASC_PRIMARY)
+#define PSW_MASK_USER (PSW_MASK_ASC | PSW_MASK_CC | PSW_MASK_PM | \
+ PSW_MASK_64 | PSW_MASK_32)
+
static void save_sigregs(CPUS390XState *env, target_sigregs *sregs)
{
+ uint64_t psw_mask = s390_cpu_get_psw_mask(env);
int i;
/*
* Copy a 'clean' PSW mask to the user to avoid leaking
* information about whether PER is currently on.
+ * TODO: qemu does not support PSW_MASK_RI; it will never be set.
*/
- __put_user(env->psw.mask, &sregs->regs.psw.mask);
+ psw_mask = PSW_USER_BITS | (psw_mask & PSW_MASK_USER);
+ __put_user(psw_mask, &sregs->regs.psw.mask);
__put_user(env->psw.addr, &sregs->regs.psw.addr);
for (i = 0; i < 16; i++) {
@@ -289,7 +297,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
static void restore_sigregs(CPUS390XState *env, target_sigregs *sc)
{
- target_ulong prev_addr;
+ uint64_t prev_addr, prev_mask, mask, addr;
int i;
for (i = 0; i < 16; i++) {
@@ -297,9 +305,28 @@ static void restore_sigregs(CPUS390XState *env, target_sigregs *sc)
}
prev_addr = env->psw.addr;
- __get_user(env->psw.mask, &sc->regs.psw.mask);
- __get_user(env->psw.addr, &sc->regs.psw.addr);
- trace_user_s390x_restore_sigregs(env, env->psw.addr, prev_addr);
+ __get_user(mask, &sc->regs.psw.mask);
+ __get_user(addr, &sc->regs.psw.addr);
+ trace_user_s390x_restore_sigregs(env, addr, prev_addr);
+
+ /*
+ * Use current psw.mask to preserve PER bit.
+ * TODO:
+ * if (!is_ri_task(current) && (user_sregs.regs.psw.mask & PSW_MASK_RI))
+ * return -EINVAL;
+ * Simply do not allow it to be set in mask.
+ */
+ prev_mask = s390_cpu_get_psw_mask(env);
+ mask = (prev_mask & ~PSW_MASK_USER) | (mask & PSW_MASK_USER);
+ /* Check for invalid user address space control. */
+ if ((mask & PSW_MASK_ASC) == PSW_ASC_HOME) {
+ mask = (mask & ~PSW_MASK_ASC) | PSW_ASC_PRIMARY;
+ }
+ /* Check for invalid amode. */
+ if (mask & PSW_MASK_64) {
+ mask |= PSW_MASK_32;
+ }
+ s390_cpu_set_psw(env, mask, addr);
for (i = 0; i < 16; i++) {
__get_user(env->aregs[i], &sc->regs.acrs[i]);
--
2.25.1
next prev parent reply other threads:[~2021-06-15 3:10 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-15 3:07 [PATCH 0/5] linux-user/s390x: Fix psw.mask handling in signals Richard Henderson
2021-06-15 3:07 ` [PATCH 1/5] target/s390x: Expose load_psw and get_psw_mask to cpu.h Richard Henderson
2021-06-15 7:47 ` David Hildenbrand
2021-06-15 8:57 ` Alex Bennée
2021-06-15 3:07 ` [PATCH 2/5] target/s390x: Do not modify cpu state in s390_cpu_get_psw_mask Richard Henderson
2021-06-15 7:49 ` David Hildenbrand
2021-06-15 3:07 ` [PATCH 3/5] target/s390x: Improve s390_cpu_dump_state vs cc_op Richard Henderson
2021-06-15 7:51 ` David Hildenbrand
2021-06-15 3:07 ` [PATCH 4/5] target/s390x: Use s390_cpu_{set_psw, get_psw_mask} in gdbstub Richard Henderson
2021-06-15 7:52 ` David Hildenbrand
2021-06-15 3:07 ` Richard Henderson [this message]
2021-06-15 7:59 ` [PATCH 5/5] linux-user/s390x: Save and restore psw.mask properly David Hildenbrand
2021-06-15 9:02 ` [PATCH 0/5] linux-user/s390x: Fix psw.mask handling in signals Christian Borntraeger
2021-06-16 15:00 ` Cornelia Huck
2021-06-15 9:27 ` Alex Bennée
2021-06-15 9:51 ` Alex Bennée
2021-06-16 10:38 ` Cornelia Huck
2021-06-16 14:48 ` Richard Henderson
2021-06-16 14:59 ` Cornelia Huck
2021-06-15 18:03 ` jonathan.albrecht
2021-06-16 15:01 ` Cornelia Huck
2021-06-16 15:22 ` jonathan.albrecht
2021-06-17 8:33 ` Cornelia Huck
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=20210615030744.1252385-6-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=jonathan.albrecht@linux.vnet.ibm.com \
--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 read-only IMAP folder(s) and NNTP newsgroup(s).