qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, aurel@aurel32.net,
	Aurelien Jarno <aurelien@aurel32.net>,
	rth@twiddle.net
Subject: [Qemu-devel] [PULL 12/34] target-s390x: fix MMU index computation
Date: Fri,  5 Jun 2015 01:41:42 +0200	[thread overview]
Message-ID: <1433461324-23584-13-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1433461324-23584-1-git-send-email-agraf@suse.de>

From: Aurelien Jarno <aurelien@aurel32.net>

The cpu_mmu_index function wrongly looks at PSW P bit to determine the
MMU index, while this bit actually only control the use of priviledge
instructions. The addressing mode is detected by looking at the PSW ASC
bits instead.

This used to work more or less correctly up to kernel 3.6 as the kernel
was running in primary space and userland in secondary space. Since
kernel 3.7 the default is to run the kernel in home space and userland
in primary space. While the current QEMU code seems to work it open some
security issues, like accessing the lowcore memory in R/W mode from a
userspace process once it has been accessed by the kernel (it is then
cached by the QEMU TLB).

At the same time change the MMU_USER_IDX value so that it matches the
value used in recent kernels.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Alexander Graf <agraf@suse.de>
---
 target-s390x/cpu.h | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 3140f75..adb9a84 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -48,7 +48,7 @@
 #define MMU_MODE1_SUFFIX _secondary
 #define MMU_MODE2_SUFFIX _home
 
-#define MMU_USER_IDX 1
+#define MMU_USER_IDX 0
 
 #define MAX_EXT_QUEUE 16
 #define MAX_IO_QUEUE 16
@@ -304,11 +304,18 @@ static inline CPU_DoubleU *get_freg(CPUS390XState *cs, int nr)
 
 static inline int cpu_mmu_index (CPUS390XState *env)
 {
-    if (env->psw.mask & PSW_MASK_PSTATE) {
+    switch (env->psw.mask & PSW_MASK_ASC) {
+    case PSW_ASC_PRIMARY:
+        return 0;
+    case PSW_ASC_SECONDARY:
         return 1;
+    case PSW_ASC_HOME:
+        return 2;
+    case PSW_ASC_ACCREG:
+        /* Fallthrough: access register mode is not yet supported */
+    default:
+        abort();
     }
-
-    return 0;
 }
 
 static inline void cpu_get_tb_cpu_state(CPUS390XState* env, target_ulong *pc,
-- 
1.7.12.4

  parent reply	other threads:[~2015-06-04 23:42 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-04 23:41 [Qemu-devel] [PULL 00/34] s390 patch queue 2015-06-05 Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 01/34] target-s390x: fix CC computation for EX instruction Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 02/34] target-s390x: fix CC computation for LOAD POSITIVE instructions Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 03/34] target-s390x: optimize (negative-) abs computation Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 04/34] target-s390x: remove unused helpers Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 05/34] target-s390x: add a tod2time function Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 06/34] target-s390x: simplify SCKC helper Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 07/34] target-s390x: streamline STCK helper Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 08/34] target-s390x: implement STCKC helper Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 09/34] target-s390x: implement STPT helper Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 10/34] target-s390x: fix LOAD MULTIPLE instruction on page boundary Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 11/34] target-s390x: fix PSW value on dynamical exception from helpers Alexander Graf
2015-06-04 23:41 ` Alexander Graf [this message]
2015-06-04 23:41 ` [Qemu-devel] [PULL 13/34] target-s390x: define default NaN values Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 14/34] target-s390x: silence NaNs for LOAD LENGTHENED and LOAD ROUNDED Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 15/34] target-s390x: detect tininess before rounding for FP operations Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 16/34] target-s390x: move a few instructions to the correct facility Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 17/34] target-s390x: implement LAY and LAEY instructions Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 18/34] target-s390x: fix exception for invalid operation code Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 19/34] target-s390x: fix CLGIT instruction Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 20/34] target-s390x: change CHRL and CGHRL format to RIL-b Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 21/34] target-s390x: move STORE CLOCK FAST to the correct facility Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 22/34] target-s390x: move SET DFP ROUNDING MODE " Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 23/34] target-s390x: implement LOAD FP INTEGER instructions Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 24/34] target-s390x: implement TRANSLATE AND TEST instruction Alexander Graf
2015-06-20 21:06   ` Paolo Bonzini
2015-06-21 14:24     ` Aurelien Jarno
2015-06-04 23:41 ` [Qemu-devel] [PULL 25/34] target-s390x: implement TRANSLATE EXTENDED instruction Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 26/34] target-s390x: implement LPDFR and LNDFR instructions Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 27/34] target-s390x: implement miscellaneous-instruction-extensions facility Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 28/34] target-s390x: implement load-and-trap facility Alexander Graf
2015-06-04 23:41 ` [Qemu-devel] [PULL 29/34] target-s390x: implement high-word facility Alexander Graf
2015-06-04 23:42 ` [Qemu-devel] [PULL 30/34] target-s390x: add a cpu_mmu_idx_to_asc function Alexander Graf
2015-06-04 23:42 ` [Qemu-devel] [PULL 31/34] target-s390x: support non current ASC in s390_cpu_handle_mmu_fault Alexander Graf
2015-06-04 23:42 ` [Qemu-devel] [PULL 32/34] target-s390x: use softmmu functions for mvcp/mvcs Alexander Graf
2015-06-04 23:42 ` [Qemu-devel] [PULL 33/34] target-s390x: fix MVC instruction when areas overlap Alexander Graf
2015-06-04 23:42 ` [Qemu-devel] [PULL 34/34] target-s390x: Only access allocated storage keys Alexander Graf
2015-06-05 12:01 ` [Qemu-devel] [PULL 00/34] s390 patch queue 2015-06-05 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=1433461324-23584-13-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=aurel@aurel32.net \
    --cc=aurelien@aurel32.net \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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).