From: Thomas Huth <thuth@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PULL 05/23] target/s390x: The MVCP and MVCS instructions are not privileged
Date: Wed, 14 Dec 2022 11:08:53 +0100 [thread overview]
Message-ID: <20221214100911.165291-6-thuth@redhat.com> (raw)
In-Reply-To: <20221214100911.165291-1-thuth@redhat.com>
The "MOVE TO PRIMARY/SECONDARY" instructions can also be called
from problem state. We just should properly check whether the
secondary-space access key is valid here, too, and inject a
privileged program exception if it is invalid.
Message-Id: <20221205125852.81848-1-thuth@redhat.com>
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
target/s390x/helper.h | 4 ++--
target/s390x/tcg/insn-data.h.inc | 4 ++--
target/s390x/tcg/mem_helper.c | 16 ++++++++++++----
target/s390x/tcg/translate.c | 6 ++++--
4 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/target/s390x/helper.h b/target/s390x/helper.h
index bf33d86f74..93923ca153 100644
--- a/target/s390x/helper.h
+++ b/target/s390x/helper.h
@@ -353,8 +353,8 @@ DEF_HELPER_FLAGS_3(tprot, TCG_CALL_NO_WG, i32, env, i64, i64)
DEF_HELPER_2(iske, i64, env, i64)
DEF_HELPER_3(sske, void, env, i64, i64)
DEF_HELPER_2(rrbe, i32, env, i64)
-DEF_HELPER_4(mvcs, i32, env, i64, i64, i64)
-DEF_HELPER_4(mvcp, i32, env, i64, i64, i64)
+DEF_HELPER_5(mvcs, i32, env, i64, i64, i64, i64)
+DEF_HELPER_5(mvcp, i32, env, i64, i64, i64, i64)
DEF_HELPER_4(sigp, i32, env, i64, i32, i32)
DEF_HELPER_FLAGS_2(sacf, TCG_CALL_NO_WG, void, env, i64)
DEF_HELPER_FLAGS_4(idte, TCG_CALL_NO_RWG, void, env, i64, i64, i32)
diff --git a/target/s390x/tcg/insn-data.h.inc b/target/s390x/tcg/insn-data.h.inc
index 54d4250c9f..79c6ab509a 100644
--- a/target/s390x/tcg/insn-data.h.inc
+++ b/target/s390x/tcg/insn-data.h.inc
@@ -1355,9 +1355,9 @@
E(0xb24b, LURA, RRE, Z, 0, ra2, new, r1_32, lura, 0, MO_TEUL, IF_PRIV)
E(0xb905, LURAG, RRE, Z, 0, ra2, r1, 0, lura, 0, MO_TEUQ, IF_PRIV)
/* MOVE TO PRIMARY */
- F(0xda00, MVCP, SS_d, Z, la1, a2, 0, 0, mvcp, 0, IF_PRIV)
+ C(0xda00, MVCP, SS_d, Z, la1, a2, 0, 0, mvcp, 0)
/* MOVE TO SECONDARY */
- F(0xdb00, MVCS, SS_d, Z, la1, a2, 0, 0, mvcs, 0, IF_PRIV)
+ C(0xdb00, MVCS, SS_d, Z, la1, a2, 0, 0, mvcs, 0)
/* PURGE TLB */
F(0xb20d, PTLB, S, Z, 0, 0, 0, 0, ptlb, 0, IF_PRIV)
/* RESET REFERENCE BIT EXTENDED */
diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c
index 006b6798a7..cb82cd1c1d 100644
--- a/target/s390x/tcg/mem_helper.c
+++ b/target/s390x/tcg/mem_helper.c
@@ -2295,7 +2295,8 @@ uint32_t HELPER(rrbe)(CPUS390XState *env, uint64_t r2)
return re >> 1;
}
-uint32_t HELPER(mvcs)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2)
+uint32_t HELPER(mvcs)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2,
+ uint64_t key)
{
const uint8_t psw_as = (env->psw.mask & PSW_MASK_ASC) >> PSW_SHIFT_ASC;
S390Access srca, desta;
@@ -2310,6 +2311,10 @@ uint32_t HELPER(mvcs)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2)
s390_program_interrupt(env, PGM_SPECIAL_OP, ra);
}
+ if (!psw_key_valid(env, (key >> 4) & 0xf)) {
+ s390_program_interrupt(env, PGM_PRIVILEGED, ra);
+ }
+
l = wrap_length32(env, l);
if (l > 256) {
/* max 256 */
@@ -2319,14 +2324,14 @@ uint32_t HELPER(mvcs)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2)
return cc;
}
- /* TODO: Access key handling */
srca = access_prepare(env, a2, l, MMU_DATA_LOAD, MMU_PRIMARY_IDX, ra);
desta = access_prepare(env, a1, l, MMU_DATA_STORE, MMU_SECONDARY_IDX, ra);
access_memmove(env, &desta, &srca, ra);
return cc;
}
-uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2)
+uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2,
+ uint64_t key)
{
const uint8_t psw_as = (env->psw.mask & PSW_MASK_ASC) >> PSW_SHIFT_ASC;
S390Access srca, desta;
@@ -2341,6 +2346,10 @@ uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2)
s390_program_interrupt(env, PGM_SPECIAL_OP, ra);
}
+ if (!psw_key_valid(env, (key >> 4) & 0xf)) {
+ s390_program_interrupt(env, PGM_PRIVILEGED, ra);
+ }
+
l = wrap_length32(env, l);
if (l > 256) {
/* max 256 */
@@ -2350,7 +2359,6 @@ uint32_t HELPER(mvcp)(CPUS390XState *env, uint64_t l, uint64_t a1, uint64_t a2)
return cc;
}
- /* TODO: Access key handling */
srca = access_prepare(env, a2, l, MMU_DATA_LOAD, MMU_SECONDARY_IDX, ra);
desta = access_prepare(env, a1, l, MMU_DATA_STORE, MMU_PRIMARY_IDX, ra);
access_memmove(env, &desta, &srca, ra);
diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c
index 1e599ac259..a339b277e9 100644
--- a/target/s390x/tcg/translate.c
+++ b/target/s390x/tcg/translate.c
@@ -3476,7 +3476,8 @@ static DisasJumpType op_mvcos(DisasContext *s, DisasOps *o)
static DisasJumpType op_mvcp(DisasContext *s, DisasOps *o)
{
int r1 = get_field(s, l1);
- gen_helper_mvcp(cc_op, cpu_env, regs[r1], o->addr1, o->in2);
+ int r3 = get_field(s, r3);
+ gen_helper_mvcp(cc_op, cpu_env, regs[r1], o->addr1, o->in2, regs[r3]);
set_cc_static(s);
return DISAS_NEXT;
}
@@ -3484,7 +3485,8 @@ static DisasJumpType op_mvcp(DisasContext *s, DisasOps *o)
static DisasJumpType op_mvcs(DisasContext *s, DisasOps *o)
{
int r1 = get_field(s, l1);
- gen_helper_mvcs(cc_op, cpu_env, regs[r1], o->addr1, o->in2);
+ int r3 = get_field(s, r3);
+ gen_helper_mvcs(cc_op, cpu_env, regs[r1], o->addr1, o->in2, regs[r3]);
set_cc_static(s);
return DISAS_NEXT;
}
--
2.31.1
next prev parent reply other threads:[~2022-12-14 10:13 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-14 10:08 [PULL 00/23] First batch of s390x, qtest, CI and misc patches for 8.0 Thomas Huth
2022-12-14 10:08 ` [PULL 01/23] s390x/pci: coalesce unmap operations Thomas Huth
2022-12-14 10:08 ` [PULL 02/23] s390x/pci: shrink DMA aperture to be bound by vfio DMA limit Thomas Huth
2022-12-14 10:08 ` [PULL 03/23] s390x/pci: reset ISM passthrough devices on shutdown and system reset Thomas Huth
2022-12-14 10:08 ` [PULL 04/23] target/s390x/tcg/mem_helper: Test the right bits in psw_key_valid() Thomas Huth
2022-12-14 10:08 ` Thomas Huth [this message]
2022-12-14 10:08 ` [PULL 06/23] monitor/misc: Remove superfluous include statements Thomas Huth
2022-12-14 10:08 ` [PULL 07/23] scripts/make-release: Add a simple help text for the script Thomas Huth
2022-12-14 10:08 ` [PULL 08/23] scripts/make-release: Only clone single branches to speed up " Thomas Huth
2022-12-14 10:08 ` [PULL 09/23] util/qemu-config: Fix "query-command-line-options" to provide the right values Thomas Huth
2022-12-14 10:08 ` [PULL 10/23] util/oslib-win32: Remove obsolete reference to g_poll code Thomas Huth
2022-12-14 10:08 ` [PULL 11/23] MAINTAINERS: Add documentation files to the corresponding sections Thomas Huth
2022-12-14 10:09 ` [PULL 12/23] hw: Include the VMWare devices only in the x86 targets Thomas Huth
2022-12-14 10:09 ` [PULL 13/23] tests/qtest/libqos/e1000e: Remove "other" interrupts Thomas Huth
2022-12-14 10:09 ` [PULL 14/23] tests/qtest/e1000e-test: De-duplicate constants Thomas Huth
2022-12-14 10:09 ` [PULL 15/23] tests/qtest/libqos/e1000e: Correctly group register accesses Thomas Huth
2022-12-14 10:09 ` [PULL 16/23] .gitlab-ci.d/windows.yml: Unify the prerequisite packages Thomas Huth
2022-12-14 10:09 ` [PULL 17/23] .gitlab-ci.d/windows.yml: Keep 64-bit and 32-bit build scripts consistent Thomas Huth
2022-12-14 10:09 ` [PULL 18/23] .gitlab-ci.d/windows.yml: Exclude qTests from 64-bit CI job for now Thomas Huth
2022-12-14 10:09 ` [PULL 19/23] tests/qtest: Enable qtest build on Windows Thomas Huth
2022-12-14 10:09 ` [PULL 20/23] FreeBSD: Upgrade to 12.4 release Thomas Huth
2022-12-14 10:09 ` [PULL 21/23] gitlab-ci: Check building ppc64 without TCG Thomas Huth
2022-12-14 10:09 ` [PULL 22/23] .gitlab/issue_templates: Move suggestions into comments Thomas Huth
2022-12-14 10:09 ` [PULL 23/23] tests/qtest/vhost-user-blk-test: don't abort all qtests on missing envar Thomas Huth
2022-12-15 13:38 ` [PULL 00/23] First batch of s390x, qtest, CI and misc patches for 8.0 Peter Maydell
2022-12-15 14:14 ` Thomas Huth
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=20221214100911.165291-6-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=iii@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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).