qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Cornelia Huck <cohuck@redhat.com>
To: peter.maydell@linaro.org
Cc: qemu-devel@nongnu.org, qemu-s390x@nongnu.org, rth@twiddle.net,
	agraf@suse.de, thuth@redhat.com, borntraeger@de.ibm.com,
	david@redhat.com, Cornelia Huck <cohuck@redhat.com>
Subject: [Qemu-devel] [PULL 30/46] s390x/tcg: refactor stfl(e) to use s390_get_feat_block()
Date: Fri, 20 Oct 2017 13:54:02 +0200	[thread overview]
Message-ID: <20171020115418.2050-31-cohuck@redhat.com> (raw)
In-Reply-To: <20171020115418.2050-1-cohuck@redhat.com>

From: David Hildenbrand <david@redhat.com>

Refactor it to use s390_get_feat_block(). Directly write into the mapped
lowcore with stfl and make sure it is really only compiled if needed.

While at it, add an alignment check for STFLE and avoid
potential_page_fault() by properly restoring the CPU state.

Due to s390_get_feat_block(), we will now also indicate the
"Configuration-z-architectural-mode", which is with new SIGP code the
right thing to do.

Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20170928203708.9376-30-david@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
---
 target/s390x/misc_helper.c | 67 ++++++++++++++++++++--------------------------
 target/s390x/translate.c   |  1 -
 2 files changed, 29 insertions(+), 39 deletions(-)

diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c
index 0b3613ea5f..4afd90b969 100644
--- a/target/s390x/misc_helper.c
+++ b/target/s390x/misc_helper.c
@@ -475,66 +475,57 @@ void HELPER(per_ifetch)(CPUS390XState *env, uint64_t addr)
 }
 #endif
 
-/* The maximum bit defined at the moment is 129.  */
-#define MAX_STFL_WORDS  3
+static uint8_t stfl_bytes[2048];
+static unsigned int used_stfl_bytes;
 
-/* Canonicalize the current cpu's features into the 64-bit words required
-   by STFLE.  Return the index-1 of the max word that is non-zero.  */
-static unsigned do_stfle(CPUS390XState *env, uint64_t words[MAX_STFL_WORDS])
+static void prepare_stfl(void)
 {
-    S390CPU *cpu = s390_env_get_cpu(env);
-    const unsigned long *features = cpu->model->features;
-    unsigned max_bit = 0;
-    S390Feat feat;
-
-    memset(words, 0, sizeof(uint64_t) * MAX_STFL_WORDS);
+    static bool initialized;
+    int i;
 
-    if (test_bit(S390_FEAT_ZARCH, features)) {
-        /* z/Architecture is always active if around */
-        words[0] = 1ull << (63 - 2);
+    /* racy, but we don't care, the same values are always written */
+    if (initialized) {
+        return;
     }
 
-    for (feat = find_first_bit(features, S390_FEAT_MAX);
-         feat < S390_FEAT_MAX;
-         feat = find_next_bit(features, S390_FEAT_MAX, feat + 1)) {
-        const S390FeatDef *def = s390_feat_def(feat);
-        if (def->type == S390_FEAT_TYPE_STFL) {
-            unsigned bit = def->bit;
-            if (bit > max_bit) {
-                max_bit = bit;
-            }
-            assert(bit / 64 < MAX_STFL_WORDS);
-            words[bit / 64] |= 1ULL << (63 - bit % 64);
+    s390_get_feat_block(S390_FEAT_TYPE_STFL, stfl_bytes);
+    for (i = 0; i < sizeof(stfl_bytes); i++) {
+        if (stfl_bytes[i]) {
+            used_stfl_bytes = i + 1;
         }
     }
-
-    return max_bit / 64;
+    initialized = true;
 }
 
 #ifndef CONFIG_USER_ONLY
 void HELPER(stfl)(CPUS390XState *env)
 {
-    uint64_t words[MAX_STFL_WORDS];
     LowCore *lowcore;
 
     lowcore = cpu_map_lowcore(env);
-    do_stfle(env, words);
-    lowcore->stfl_fac_list = cpu_to_be32(words[0] >> 32);
+    prepare_stfl();
+    memcpy(&lowcore->stfl_fac_list, stfl_bytes, sizeof(lowcore->stfl_fac_list));
     cpu_unmap_lowcore(lowcore);
 }
 #endif
 
 uint32_t HELPER(stfle)(CPUS390XState *env, uint64_t addr)
 {
-    uint64_t words[MAX_STFL_WORDS];
-    unsigned count_m1 = env->regs[0] & 0xff;
-    unsigned max_m1 = do_stfle(env, words);
-    unsigned i;
+    const uintptr_t ra = GETPC();
+    const int count_bytes = ((env->regs[0] & 0xff) + 1) * 8;
+    const int max_bytes = ROUND_UP(used_stfl_bytes, 8);
+    int i;
+
+    if (addr & 0x7) {
+        cpu_restore_state(ENV_GET_CPU(env), ra);
+        program_interrupt(env, PGM_SPECIFICATION, 4);
+    }
 
-    for (i = 0; i <= count_m1; ++i) {
-        cpu_stq_data(env, addr + 8 * i, words[i]);
+    prepare_stfl();
+    for (i = 0; i < count_bytes; ++i) {
+        cpu_stb_data_ra(env, addr + i, stfl_bytes[i], ra);
     }
 
-    env->regs[0] = deposit64(env->regs[0], 0, 8, max_m1);
-    return (count_m1 >= max_m1 ? 0 : 3);
+    env->regs[0] = deposit64(env->regs[0], 0, 8, (max_bytes / 8) - 1);
+    return count_bytes >= max_bytes ? 0 : 3;
 }
diff --git a/target/s390x/translate.c b/target/s390x/translate.c
index 22e0f42a2a..6ecf764a98 100644
--- a/target/s390x/translate.c
+++ b/target/s390x/translate.c
@@ -4143,7 +4143,6 @@ static ExitStatus op_sturg(DisasContext *s, DisasOps *o)
 
 static ExitStatus op_stfle(DisasContext *s, DisasOps *o)
 {
-    potential_page_fault(s);
     gen_helper_stfle(cc_op, cpu_env, o->in2);
     set_cc_static(s);
     return NO_EXIT;
-- 
2.13.6

  parent reply	other threads:[~2017-10-20 11:56 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-20 11:53 [Qemu-devel] [PULL 00/46] more s390x patches for 2.11 Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 01/46] S390: use g_new() family of functions Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 02/46] s390x/css: be more consistent if broken beyond repair Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 03/46] s390x/tcg: turn INTERRUPT_EXT into a mask Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 04/46] s390x/tcg: cleanup service interrupt injection Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 05/46] s390x/tcg: injection of emergency signals and external calls Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 06/46] s390x/tcg: rework checking for deliverable interrupts Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 07/46] s390x/tcg: take care of external interrupt subclasses Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 08/46] s390x/tcg: STOPPED cpus can never wake up Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 09/46] s390x/tcg: a CPU cannot switch state due to an interrupt Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 10/46] target/s390x: factor out handling of WAIT PSW into s390_handle_wait() Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 11/46] s390x/tcg: handle WAIT PSWs during interrupt injection Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 12/46] target/s390x: interpret PSW_MASK_WAIT only for TCG Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 13/46] s390x/kvm: pass ipb directly into handle_sigp() Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 14/46] s390x/kvm: generalize SIGP stop and restart interrupt injection Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 15/46] s390x/kvm: factor out storing of CPU status Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 16/46] s390x/kvm: factor out storing of adtl " Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 17/46] s390x/kvm: drop two debug prints Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 18/46] s390x/kvm: factor out SIGP code into sigp.c Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 19/46] s390x/kvm: factor out actual handling of STOP interrupts Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 20/46] s390x/tcg: implement SIGP SENSE RUNNING STATUS Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 21/46] s390x/tcg: implement SIGP SENSE Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 22/46] s390x/tcg: implement SIGP EXTERNAL CALL Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 23/46] s390x/tcg: implement SIGP EMERGENCY SIGNAL Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 24/46] s390x/tcg: implement SIGP CONDITIONAL " Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 25/46] s390x/tcg: implement STOP and RESET interrupts for TCG Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 26/46] s390x/tcg: flush the tlb on SIGP SET PREFIX Cornelia Huck
2017-10-20 11:53 ` [Qemu-devel] [PULL 27/46] s390x/tcg: switch to new SIGP handling code Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 28/46] s390x/cpumodel: allow to enable SENSE RUNNING STATUS for qemu Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 29/46] s390x/tcg: unlock NMI Cornelia Huck
2017-10-20 11:54 ` Cornelia Huck [this message]
2017-10-20 11:54 ` [Qemu-devel] [PULL 31/46] target/s390x: special handling when starting a CPU with WAIT PSW Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 32/46] virtio-ccw: Add the virtio-input devices for CCW bus Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 33/46] s390x/MAINTAINERS: add mailing list Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 34/46] s390x/event-facility: variable-length event masks Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 35/46] s390x: fix cpu object referrence leak in s390x_new_cpu() Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 36/46] s390x: move s390x_new_cpu() into board code Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 37/46] s390x/css: IO instr handler ending control Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 38/46] s390x: improve error handling for SSCH and RSCH Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 39/46] s390x: refactor error handling for XSCH handler Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 40/46] s390x: refactor error handling for CSCH handler Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 41/46] s390x: refactor error handling for HSCH handler Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 42/46] s390x: refactor error handling for MSCH handler Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 43/46] libqtest: Add qtest_[v]startf() Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 44/46] tests: Enable the very simple virtio tests on s390x, too Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 45/46] accel/tcg: allow to invalidate a write TLB entry immediately Cornelia Huck
2017-10-20 11:54 ` [Qemu-devel] [PULL 46/46] s390x/tcg: low-address protection support Cornelia Huck
2017-10-20 14:03 ` [Qemu-devel] [PULL 00/46] more s390x patches for 2.11 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=20171020115418.2050-31-cohuck@redhat.com \
    --to=cohuck@redhat.com \
    --cc=agraf@suse.de \
    --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=rth@twiddle.net \
    --cc=thuth@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).