Skip to contentSkip to conversation

target/s390x: Implement the MVPG condition-code-option bit

PATCH Applied David Hildenbrand 3 participants 5 messages Mar 15, 2021

lore
Share & tools
lore
#0 lore raw

v7 cover target/s390x: Implement the MVPG condition-code-option bit

Based on work from Richard and Thomas.

v6 -> v7:
- "target/s390x: Implement the MVPG condition-code-option bit" -- Fix PGM_PROTECTION for QEMU_USER_ONLY (overridden by patch #2)

v5 -> v6:
- "target/s390x: Implement the MVPG condition-code-option bit" -- Better handle CONFIG_USER_ONLY
-- Factor handling out into s390_probe_access().
- "target/s390x: Store r1/r2 for page-translation exceptions during MVPG" -- Store tec only for !PGM_ADDRESSING

v4 -> v5:
- Don't realy on TLB_INVALID_MASK
-- Check against tlb_fill_exc and return the exception right away
- Handle !CONFIG_USER_ONLY
-- Check against haddr
-- Properly store vaddr to env->__excp_addr and return PGM_ADDRESSING
- Exclude tlb_fill_tec/tlb_fill_exc for CONFIG_USER_ONLY
- While at it, tackle r1/r2 indication as well

KVM unit tests continue working as expected.

David Hildenbrand (1):
target/s390x: Store r1/r2 for page-translation exceptions during MVPG

Richard Henderson (1):
target/s390x: Implement the MVPG condition-code-option bit

 target/s390x/cpu.h         |   5 ++
 target/s390x/excp_helper.c |   3 +
 target/s390x/helper.h      |   2 +-
 target/s390x/insn-data.def |   2 +-
 target/s390x/mem_helper.c  | 160 ++++++++++++++++++++++++++++++-------
 target/s390x/translate.c   |   7 +-
 6 files changed, 146 insertions(+), 33 deletions(-)
Signature · 1 line
2.29.2
#1 lore raw

PATCH v7 1/2 target/s390x: Implement the MVPG condition-code-option bit

From: Richard Henderson <[email protected]>

If the CCO bit is set, MVPG should not generate an exception but report page translation faults via a CC code.

Create a new helper, access_prepare_nf, which can use probe_access_flags in non-faulting mode, and then handle watchpoints.

[thuth: Added logic to still inject protection exceptions]
[david: Look at env->tlb_fill_exc to determine if there was an exception]
---
 target/s390x/cpu.h         |   5 ++
 target/s390x/excp_helper.c |   3 +
 target/s390x/mem_helper.c  | 136 ++++++++++++++++++++++++++++++-------
 3 files changed, 121 insertions(+), 23 deletions(-)
target/s390x/cpu.h +5 -0
index 60d434d5ed..468b4430f3 100644
@@ -114,6 +114,11 @@ struct CPUS390XState {
 
     uint64_t diag318_info;
 
+#if !defined(CONFIG_USER_ONLY)
+    uint64_t tlb_fill_tec;   /* translation exception code during tlb_fill */
+    int tlb_fill_exc;        /* exception number seen during tlb_fill */
+#endif
+
     /* Fields up to this point are cleared by a CPU reset */
     struct {} end_reset_fields;
 
target/s390x/excp_helper.c +3 -0
index ce16af394b..c48cd6b46f 100644
@@ -164,6 +164,9 @@ bool s390_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
         tec = 0; /* unused */
     }
 
+    env->tlb_fill_exc = excp;
+    env->tlb_fill_tec = tec;
+
     if (!excp) {
         qemu_log_mask(CPU_LOG_MMU,
                       "%s: set tlb %" PRIx64 " -> %" PRIx64 " (%x)\n",
target/s390x/mem_helper.c +113 -23

162 lines not on this page · raw message

Signature · 1 line
2.29.2
#2 lore raw

PATCH v7 2/2 target/s390x: Store r1/r2 for page-translation exceptions during MVPG

In reply to David Hildenbrand

The PoP states:

When EDAT-1 does not apply, and a program interruption due to a page-translation exception is recognized by the MOVE PAGE instruction, the contents of the R1 field of the instruction are stored in bit positions 0-3 of location 162, and the contents of the R2 field are stored in bit positions 4-7.

If [...] an ASCE-type, region-first-translation, region-second-translation, region-third-translation, or segment-translation exception was recognized, the contents of location 162 are unpredictable.

So we have to write r1/r2 into the lowcore on page-translation exceptions. Simply handle all exceptions inside our mvpg helper now.

---
 target/s390x/helper.h      |  2 +-
 target/s390x/insn-data.def |  2 +-
 target/s390x/mem_helper.c  | 46 +++++++++++++++++++++++---------------
 target/s390x/translate.c   |  7 +++++-
 4 files changed, 36 insertions(+), 21 deletions(-)
target/s390x/helper.h +1 -1
index 55bd1551e6..d4e4f3388f 100644
@@ -18,7 +18,7 @@ DEF_HELPER_3(srstu, void, env, i32, i32)
 DEF_HELPER_4(clst, i64, env, i64, i64, i64)
 DEF_HELPER_FLAGS_4(mvn, TCG_CALL_NO_WG, void, env, i32, i64, i64)
 DEF_HELPER_FLAGS_4(mvo, TCG_CALL_NO_WG, void, env, i32, i64, i64)
-DEF_HELPER_FLAGS_4(mvpg, TCG_CALL_NO_WG, i32, env, i64, i64, i64)
+DEF_HELPER_FLAGS_4(mvpg, TCG_CALL_NO_WG, i32, env, i64, i32, i32)
 DEF_HELPER_FLAGS_4(mvz, TCG_CALL_NO_WG, void, env, i32, i64, i64)
 DEF_HELPER_3(mvst, i32, env, i32, i32)
 DEF_HELPER_4(ex, void, env, i32, i64, i64)
target/s390x/insn-data.def +1 -1
index e5b6efabf3..0bb1886a2e 100644
@@ -641,7 +641,7 @@
 /* MOVE NUMERICS */
     C(0xd100, MVN,     SS_a,  Z,   la1, a2, 0, 0, mvn, 0)
 /* MOVE PAGE */
-    C(0xb254, MVPG,    RRE,   Z,   r1_o, r2_o, 0, 0, mvpg, 0)
+    C(0xb254, MVPG,    RRE,   Z,   0, 0, 0, 0, mvpg, 0)
 /* MOVE STRING */
     C(0xb255, MVST,    RRE,   Z,   0, 0, 0, 0, mvst, 0)
 /* MOVE WITH OPTIONAL SPECIFICATION */
target/s390x/mem_helper.c +28 -18

70 lines not on this page · raw message

target/s390x/translate.c +6 -1
index 61dd0341e4..4f953ddfba 100644
@@ -3513,7 +3513,12 @@ static DisasJumpType op_mvo(DisasContext *s, DisasOps *o)
 
 static DisasJumpType op_mvpg(DisasContext *s, DisasOps *o)
 {
-    gen_helper_mvpg(cc_op, cpu_env, regs[0], o->in1, o->in2);
+    TCGv_i32 t1 = tcg_const_i32(get_field(s, r1));
+    TCGv_i32 t2 = tcg_const_i32(get_field(s, r2));
+
+    gen_helper_mvpg(cc_op, cpu_env, regs[0], t1, t2);
+    tcg_temp_free_i32(t1);
+    tcg_temp_free_i32(t2);
     set_cc_static(s);
     return DISAS_NEXT;
 }
Signature · 1 line
2.29.2
Tested-by on the v7 series
#3 lore raw
In reply to David Hildenbrand
Quoted 5 lines · David Hildenbrand

Based on work from Richard and Thomas.

v6 -> v7:
- "target/s390x: Implement the MVPG condition-code-option bit" -- Fix PGM_PROTECTION for QEMU_USER_ONLY (overridden by patch #2)

I just double-checked my version of the MVPG kvm-unit-test and some Linux guest images, and all seem to still work fine.

#4 lore raw
In reply to David Hildenbrand
Quoted 30 lines · On Mon, 15 Mar 2021 09:54:47 +0100 David Hildenbrand <[email protected]> wrote:

Based on work from Richard and Thomas.

v6 -> v7:
- "target/s390x: Implement the MVPG condition-code-option bit" -- Fix PGM_PROTECTION for QEMU_USER_ONLY (overridden by patch #2)

v5 -> v6:
- "target/s390x: Implement the MVPG condition-code-option bit" -- Better handle CONFIG_USER_ONLY
-- Factor handling out into s390_probe_access().
- "target/s390x: Store r1/r2 for page-translation exceptions during MVPG" -- Store tec only for !PGM_ADDRESSING

v4 -> v5:
- Don't realy on TLB_INVALID_MASK
-- Check against tlb_fill_exc and return the exception right away
- Handle !CONFIG_USER_ONLY
-- Check against haddr
-- Properly store vaddr to env->__excp_addr and return PGM_ADDRESSING
- Exclude tlb_fill_tec/tlb_fill_exc for CONFIG_USER_ONLY
- While at it, tackle r1/r2 indication as well

KVM unit tests continue working as expected.

David Hildenbrand (1):
target/s390x: Store r1/r2 for page-translation exceptions during MVPG

Richard Henderson (1):
target/s390x: Implement the MVPG condition-code-option bit

Quoted 8 lines
 target/s390x/cpu.h         |   5 ++
 target/s390x/excp_helper.c |   3 +
 target/s390x/helper.h      |   2 +-
 target/s390x/insn-data.def |   2 +-
 target/s390x/mem_helper.c  | 160 ++++++++++++++++++++++++++++++-------
 target/s390x/translate.c   |   7 +-
 6 files changed, 146 insertions(+), 33 deletions(-)

Thanks, applied.