From: Cornelia Huck <cohuck@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: David Hildenbrand <david@redhat.com>,
Cornelia Huck <cohuck@redhat.com>,
Richard Henderson <richard.henderson@linaro.org>,
qemu-devel@nongnu.org,
Christian Borntraeger <borntraeger@de.ibm.com>,
qemu-s390x@nongnu.org
Subject: [PULL 09/19] s390x/tcg: Implement MONITOR CALL
Date: Fri, 2 Oct 2020 14:11:08 +0200 [thread overview]
Message-ID: <20201002121118.180315-10-cohuck@redhat.com> (raw)
In-Reply-To: <20201002121118.180315-1-cohuck@redhat.com>
From: David Hildenbrand <david@redhat.com>
Recent upstream Linux uses the MONITOR CALL instruction for things like
BUG_ON() and WARN_ON(). We currently inject an operation exception when
we hit a MONITOR CALL instruction - which is wrong, as the instruction
is not glued to specific CPU features.
Doing a simple WARN_ON_ONCE() currently results in a panic:
[ 18.162801] illegal operation: 0001 ilc:2 [#1] SMP
[ 18.162889] Modules linked in:
[...]
[ 18.165476] Kernel panic - not syncing: Fatal exception: panic_on_oops
With a proper implementation, we now get:
[ 18.242754] ------------[ cut here ]------------
[ 18.242855] WARNING: CPU: 7 PID: 1 at init/main.c:1534 [...]
[ 18.242919] Modules linked in:
[...]
[ 18.246262] ---[ end trace a420477d71dc97b4 ]---
[ 18.259014] Freeing unused kernel memory: 4220K
Reported-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20200918085122.26132-1-david@redhat.com>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
---
target/s390x/excp_helper.c | 23 +++++++++++++++++++++++
target/s390x/helper.h | 1 +
target/s390x/insn-data.def | 3 +++
target/s390x/translate.c | 21 +++++++++++++++++++++
4 files changed, 48 insertions(+)
diff --git a/target/s390x/excp_helper.c b/target/s390x/excp_helper.c
index 3b58d10df3ca..0adfbbda2708 100644
--- a/target/s390x/excp_helper.c
+++ b/target/s390x/excp_helper.c
@@ -610,4 +610,27 @@ void s390x_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
tcg_s390_program_interrupt(env, PGM_SPECIFICATION, retaddr);
}
+static void QEMU_NORETURN monitor_event(CPUS390XState *env,
+ uint64_t monitor_code,
+ uint8_t monitor_class, uintptr_t ra)
+{
+ /* Store the Monitor Code and the Monitor Class Number into the lowcore */
+ stq_phys(env_cpu(env)->as,
+ env->psa + offsetof(LowCore, monitor_code), monitor_code);
+ stw_phys(env_cpu(env)->as,
+ env->psa + offsetof(LowCore, mon_class_num), monitor_class);
+
+ tcg_s390_program_interrupt(env, PGM_MONITOR, ra);
+}
+
+void HELPER(monitor_call)(CPUS390XState *env, uint64_t monitor_code,
+ uint32_t monitor_class)
+{
+ g_assert(monitor_class <= 0xff);
+
+ if (env->cregs[8] & (0x8000 >> monitor_class)) {
+ monitor_event(env, monitor_code, monitor_class, GETPC());
+ }
+}
+
#endif /* CONFIG_USER_ONLY */
diff --git a/target/s390x/helper.h b/target/s390x/helper.h
index b7887b552bbb..55bd1551e604 100644
--- a/target/s390x/helper.h
+++ b/target/s390x/helper.h
@@ -349,4 +349,5 @@ DEF_HELPER_3(sic, void, env, i64, i64)
DEF_HELPER_3(rpcit, void, env, i32, i32)
DEF_HELPER_5(pcistb, void, env, i32, i32, i64, i32)
DEF_HELPER_4(mpcifc, void, env, i32, i64, i32)
+DEF_HELPER_3(monitor_call, void, env, i64, i32)
#endif
diff --git a/target/s390x/insn-data.def b/target/s390x/insn-data.def
index d79ae9e3f114..e14cbd63fa0a 100644
--- a/target/s390x/insn-data.def
+++ b/target/s390x/insn-data.def
@@ -617,6 +617,9 @@
C(0x9a00, LAM, RS_a, Z, 0, a2, 0, 0, lam, 0)
C(0xeb9a, LAMY, RSY_a, LD, 0, a2, 0, 0, lam, 0)
+/* MONITOR CALL */
+ C(0xaf00, MC, SI, Z, la1, 0, 0, 0, mc, 0)
+
/* MOVE */
C(0xd200, MVC, SS_a, Z, la1, a2, 0, 0, mvc, 0)
C(0xe544, MVHHI, SIL, GIE, la1, i2, 0, m1_16, mov2, 0)
diff --git a/target/s390x/translate.c b/target/s390x/translate.c
index a777343821bb..90dc1740e7ab 100644
--- a/target/s390x/translate.c
+++ b/target/s390x/translate.c
@@ -3302,6 +3302,27 @@ static DisasJumpType op_lcbb(DisasContext *s, DisasOps *o)
return DISAS_NEXT;
}
+static DisasJumpType op_mc(DisasContext *s, DisasOps *o)
+{
+#if !defined(CONFIG_USER_ONLY)
+ TCGv_i32 i2;
+#endif
+ const uint16_t monitor_class = get_field(s, i2);
+
+ if (monitor_class & 0xff00) {
+ gen_program_exception(s, PGM_SPECIFICATION);
+ return DISAS_NORETURN;
+ }
+
+#if !defined(CONFIG_USER_ONLY)
+ i2 = tcg_const_i32(monitor_class);
+ gen_helper_monitor_call(cpu_env, o->addr1, i2);
+ tcg_temp_free_i32(i2);
+#endif
+ /* Defaults to a NOP. */
+ return DISAS_NEXT;
+}
+
static DisasJumpType op_mov2(DisasContext *s, DisasOps *o)
{
o->out = o->in2;
--
2.25.4
next prev parent reply other threads:[~2020-10-02 12:26 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-02 12:10 [PULL 00/19] s390x changes Cornelia Huck
2020-10-02 12:11 ` [PULL 01/19] hw/s390x/css: Remove double initialization Cornelia Huck
2020-10-02 12:11 ` [PULL 02/19] s390/sclp: get machine once during read scp/cpu info Cornelia Huck
2020-10-02 12:11 ` [PULL 03/19] s390/sclp: rework sclp boundary checks Cornelia Huck
2020-10-02 12:11 ` [PULL 04/19] s390/sclp: read sccb from mem based on provided length Cornelia Huck
2020-10-02 12:11 ` [PULL 05/19] s390/sclp: check sccb len before filling in data Cornelia Huck
2020-10-02 12:11 ` [PULL 06/19] s390/sclp: use cpu offset to locate cpu entries Cornelia Huck
2020-10-02 12:11 ` [PULL 07/19] s390/sclp: add extended-length sccb support for kvm guest Cornelia Huck
2020-10-02 12:11 ` [PULL 08/19] s390: guest support for diagnose 0x318 Cornelia Huck
2020-10-02 12:11 ` Cornelia Huck [this message]
2020-10-02 12:11 ` [PULL 10/19] vfio-ccw: plug memory leak while getting region info Cornelia Huck
2020-10-02 12:11 ` [PULL 11/19] s390x/cpumodel: S390_FEAT_MISC_INSTRUCTION_EXT -> S390_FEAT_MISC_INSTRUCTION_EXT2 Cornelia Huck
2020-10-02 12:11 ` [PULL 12/19] s390x/tcg: Implement ADD HALFWORD (AGH) Cornelia Huck
2020-10-02 12:11 ` [PULL 13/19] s390x/tcg: Implement SUBTRACT HALFWORD (SGH) Cornelia Huck
2020-10-02 12:11 ` [PULL 14/19] s390x/tcg: Implement MULTIPLY (MG, MGRK) Cornelia Huck
2020-10-02 12:11 ` [PULL 15/19] s390x/tcg: Implement MULTIPLY HALFWORD (MGH) Cornelia Huck
2020-10-02 12:11 ` [PULL 16/19] s390x/tcg: Implement BRANCH INDIRECT ON CONDITION (BIC) Cornelia Huck
2020-10-02 12:11 ` [PULL 17/19] s390x/tcg: Implement MULTIPLY SINGLE (MSC, MSGC, MSGRKC, MSRKC) Cornelia Huck
2020-10-02 12:11 ` [PULL 18/19] s390x/tcg: We support Miscellaneous-Instruction-Extensions Facility 2 Cornelia Huck
2020-10-02 12:11 ` [PULL 19/19] s390x/tcg: Implement CIPHER MESSAGE WITH AUTHENTICATION (KMA) Cornelia Huck
2020-10-02 15:19 ` [PULL 00/19] s390x changes Peter Maydell
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=20201002121118.180315-10-cohuck@redhat.com \
--to=cohuck@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=david@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
/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).