All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support
@ 2018-02-13 16:23 David Hildenbrand
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 01/11] s390x: fix TEST BLOCK tests David Hildenbrand
                   ` (11 more replies)
  0 siblings, 12 replies; 23+ messages in thread
From: David Hildenbrand @ 2018-02-13 16:23 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, Cornelia Huck, Christian Borntraeger

This series implements
- detection of installed physical memory
- setup of the physical allocator
- setup of the MMU / page tables / DAT
- setup of the virtual allocator

The CPU now runs with DAT enabled. I added a small test to make sure
malloc() indeed works and uses virtual adresses. Also, the sieve test
is added.

While at it, fix the TEST BLOCK test on newer compilers.

Tested with upsteam QEMU TCG and KVM. However, to pass under TCG a
fix is necessary ("[PATCH v1] s390x/tcg: fix disabling/enabling DAT").

v2 -> v3:
- split up configure_dat() to make use of two functions extract_psw_mask()
  and load_psw_mask(), it is now much cleaner and we might need these
  functions in the future.
- Minor cleanups / comment fixes


David Hildenbrand (11):
  s390x: fix TEST BLOCK tests
  s390x: use highest addresses for PGM_ADDRESSING errors
  s390x: set initital stack pointer to stackptr, not stacktop
  s390x: add missing sclp definitions from QEMU
  s390x: rename sclp_setup() to sclp_ascii_setup()
  s390x: detect installed memory
  s390x: initialize the physical allocator
  s390x: add vmalloc support
  s390x: enable DAT in PGM interrupt handler
  s390x: add test for (v)malloc
  s390x: add sieve test

 lib/s390x/asm/arch_def.h  |  58 ++++++++++++
 lib/s390x/asm/interrupt.h |   1 +
 lib/s390x/asm/page.h      |  24 +++++
 lib/s390x/asm/pgtable.h   | 224 ++++++++++++++++++++++++++++++++++++++++++++++
 lib/s390x/interrupt.c     |  11 +++
 lib/s390x/io.c            |   3 +-
 lib/s390x/mmu.c           | 108 ++++++++++++++++++++++
 lib/s390x/sclp-ascii.c    |   6 +-
 lib/s390x/sclp.c          |  72 +++++++++++++++
 lib/s390x/sclp.h          | 112 ++++++++++++++++++++++-
 s390x/Makefile            |   7 ++
 s390x/cstart64.S          |   2 +-
 s390x/intercept.c         |  14 +--
 s390x/selftest.c          |  31 ++++++-
 s390x/sieve.c             |  59 ++++++++++++
 s390x/unittests.cfg       |   6 ++
 16 files changed, 723 insertions(+), 15 deletions(-)
 create mode 100644 lib/s390x/asm/pgtable.h
 create mode 100644 lib/s390x/mmu.c
 create mode 100644 lib/s390x/sclp.c
 create mode 100644 s390x/sieve.c

-- 
2.14.3

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH kvm-unit-tests v3 01/11] s390x: fix TEST BLOCK tests
  2018-02-13 16:23 [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support David Hildenbrand
@ 2018-02-13 16:23 ` David Hildenbrand
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 02/11] s390x: use highest addresses for PGM_ADDRESSING errors David Hildenbrand
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 23+ messages in thread
From: David Hildenbrand @ 2018-02-13 16:23 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, Cornelia Huck, Christian Borntraeger,
	David Hildenbrand

While new compilers like
	s390x-linux-gnu-gcc (GCC) 7.2.1 20170915 (Red Hat Cross 7.2.1-1)
Complain, that R1 is missing, old compilers like
	gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)
will complain that R1 is not valid.

Let's just specify the instruction explicitly.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 s390x/intercept.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/s390x/intercept.c b/s390x/intercept.c
index 59e5fca..99dde0d 100644
--- a/s390x/intercept.c
+++ b/s390x/intercept.c
@@ -139,7 +139,7 @@ static void test_testblock(void)
 
 	asm volatile (
 		" lghi	%%r0,0\n"
-		" tb	%1\n"
+		" .insn	rre,0xb22c0000,0,%1\n"
 		" ipm	%0\n"
 		" srl	%0,28\n"
 		: "=d" (cc)
@@ -150,12 +150,12 @@ static void test_testblock(void)
 
 	expect_pgm_int();
 	low_prot_enable();
-	asm volatile (" tb %0 " : : "r"(4096));
+	asm volatile (" .insn	rre,0xb22c0000,0,%0\n" : : "r"(4096));
 	low_prot_disable();
 	check_pgm_int_code(PGM_INT_CODE_PROTECTION);
 
 	expect_pgm_int();
-	asm volatile (" tb %0 " : : "r"(-4096));
+	asm volatile (" .insn	rre,0xb22c0000,0,%0\n" : : "r"(-4096));
 	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
 }
 
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH kvm-unit-tests v3 02/11] s390x: use highest addresses for PGM_ADDRESSING errors
  2018-02-13 16:23 [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support David Hildenbrand
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 01/11] s390x: fix TEST BLOCK tests David Hildenbrand
@ 2018-02-13 16:23 ` David Hildenbrand
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 03/11] s390x: set initital stack pointer to stackptr, not stacktop David Hildenbrand
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 23+ messages in thread
From: David Hildenbrand @ 2018-02-13 16:23 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, Cornelia Huck, Christian Borntraeger,
	David Hildenbrand

Without the L, we get 32 bit addresses, resulting in different memory
addresses. This is necessary for enabling the MMU.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 s390x/intercept.c | 10 +++++-----
 s390x/selftest.c  |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/s390x/intercept.c b/s390x/intercept.c
index 99dde0d..404b4c6 100644
--- a/s390x/intercept.c
+++ b/s390x/intercept.c
@@ -46,7 +46,7 @@ static void test_stpx(void)
 	check_pgm_int_code(PGM_INT_CODE_SPECIFICATION);
 
 	expect_pgm_int();
-	asm volatile(" stpx 0(%0) " : : "r"(-8));
+	asm volatile(" stpx 0(%0) " : : "r"(-8L));
 	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
 }
 
@@ -78,7 +78,7 @@ static void test_spx(void)
 	check_pgm_int_code(PGM_INT_CODE_SPECIFICATION);
 
 	expect_pgm_int();
-	asm volatile(" spx 0(%0) " : : "r"(-8));
+	asm volatile(" spx 0(%0) " : : "r"(-8L));
 	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
 }
 
@@ -101,7 +101,7 @@ static void test_stap(void)
 	check_pgm_int_code(PGM_INT_CODE_SPECIFICATION);
 
 	expect_pgm_int();
-	asm volatile ("stap 0(%0)\n" : : "r"(-8));
+	asm volatile ("stap 0(%0)\n" : : "r"(-8L));
 	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
 }
 
@@ -126,7 +126,7 @@ static void test_stidp(void)
 	check_pgm_int_code(PGM_INT_CODE_SPECIFICATION);
 
 	expect_pgm_int();
-	asm volatile ("stidp 0(%0)\n" : : "r"(-8));
+	asm volatile ("stidp 0(%0)\n" : : "r"(-8L));
 	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
 }
 
@@ -155,7 +155,7 @@ static void test_testblock(void)
 	check_pgm_int_code(PGM_INT_CODE_PROTECTION);
 
 	expect_pgm_int();
-	asm volatile (" .insn	rre,0xb22c0000,0,%0\n" : : "r"(-4096));
+	asm volatile (" .insn	rre,0xb22c0000,0,%0\n" : : "r"(-4096L));
 	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
 }
 
diff --git a/s390x/selftest.c b/s390x/selftest.c
index 1c8d16a..905713f 100644
--- a/s390x/selftest.c
+++ b/s390x/selftest.c
@@ -33,7 +33,7 @@ static void test_pgm_int(void)
 	check_pgm_int_code(PGM_INT_CODE_OPERATION);
 
 	expect_pgm_int();
-	asm volatile("	stg %0,0(%0)\n" : : "r"(-1));
+	asm volatile("	stg %0,0(%0)\n" : : "r"(-1L));
 	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
 }
 
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH kvm-unit-tests v3 03/11] s390x: set initital stack pointer to stackptr, not stacktop
  2018-02-13 16:23 [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support David Hildenbrand
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 01/11] s390x: fix TEST BLOCK tests David Hildenbrand
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 02/11] s390x: use highest addresses for PGM_ADDRESSING errors David Hildenbrand
@ 2018-02-13 16:23 ` David Hildenbrand
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 04/11] s390x: add missing sclp definitions from QEMU David Hildenbrand
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 23+ messages in thread
From: David Hildenbrand @ 2018-02-13 16:23 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, Cornelia Huck, Christian Borntraeger,
	David Hildenbrand

... was wrong from the beginning and remained unnoticed until we started
playing with dynamic memory allocation.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 s390x/cstart64.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/s390x/cstart64.S b/s390x/cstart64.S
index 4d0c877..9a26ed3 100644
--- a/s390x/cstart64.S
+++ b/s390x/cstart64.S
@@ -18,7 +18,7 @@
 	.globl start
 start:
 	/* setup stack */
-	larl	%r15, stacktop
+	larl	%r15, stackptr
 	/* setup initial PSW mask + control registers*/
 	larl	%r1, initital_psw
 	lpswe	0(%r1)
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH kvm-unit-tests v3 04/11] s390x: add missing sclp definitions from QEMU
  2018-02-13 16:23 [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support David Hildenbrand
                   ` (2 preceding siblings ...)
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 03/11] s390x: set initital stack pointer to stackptr, not stacktop David Hildenbrand
@ 2018-02-13 16:23 ` David Hildenbrand
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 05/11] s390x: rename sclp_setup() to sclp_ascii_setup() David Hildenbrand
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 23+ messages in thread
From: David Hildenbrand @ 2018-02-13 16:23 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, Cornelia Huck, Christian Borntraeger,
	David Hildenbrand

Copy all missing definitions from QEMU (include/hw/s390x/sclp.h).
We cannot simply replace the file, as some ASCII definitions are missing
in the QEMU file (defined somewhere else in QEMU).

Convert QEMU_PACKED accordingly and copy the copyright statement.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 lib/s390x/sclp.h | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 106 insertions(+), 1 deletion(-)

diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h
index 3f4c138..a1d0a5e 100644
--- a/lib/s390x/sclp.h
+++ b/lib/s390x/sclp.h
@@ -1,8 +1,13 @@
 /*
- * SCLP ASCII access driver
+ * SCLP definitions
  *
+ * Based on the file pc-bios/s390-ccw/sclp.h from QEMU
  * Copyright (c) 2013 Alexander Graf <agraf@suse.de>
  *
+ * and based on the file include/hw/s390x/sclp.h from QEMU
+ * Copyright IBM, Corp. 2012
+ * Author: Christian Borntraeger <borntraeger@de.ibm.com>
+ *
  * This work is licensed under the terms of the GNU GPL, version 2 or (at
  * your option) any later version. See the COPYING file in the top-level
  * directory.
@@ -11,21 +16,51 @@
 #ifndef SCLP_H
 #define SCLP_H
 
+#define SCLP_CMD_CODE_MASK                      0xffff00ff
+
 /* SCLP command codes */
 #define SCLP_CMDW_READ_SCP_INFO                 0x00020001
 #define SCLP_CMDW_READ_SCP_INFO_FORCED          0x00120001
+#define SCLP_READ_STORAGE_ELEMENT_INFO          0x00040001
+#define SCLP_ATTACH_STORAGE_ELEMENT             0x00080001
+#define SCLP_ASSIGN_STORAGE                     0x000D0001
 #define SCLP_CMD_READ_EVENT_DATA                0x00770005
 #define SCLP_CMD_WRITE_EVENT_DATA               0x00760005
 #define SCLP_CMD_READ_EVENT_DATA                0x00770005
 #define SCLP_CMD_WRITE_EVENT_DATA               0x00760005
 #define SCLP_CMD_WRITE_EVENT_MASK               0x00780005
 
+/* SCLP Memory hotplug codes */
+#define SCLP_FC_ASSIGN_ATTACH_READ_STOR         0xE00000000000ULL
+#define SCLP_STARTING_SUBINCREMENT_ID           0x10001
+#define SCLP_INCREMENT_UNIT                     0x10000
+#define MAX_AVAIL_SLOTS                         32
+#define MAX_STORAGE_INCREMENTS                  1020
+
+/* CPU hotplug SCLP codes */
+#define SCLP_HAS_CPU_INFO                       0x0C00000000000000ULL
+#define SCLP_CMDW_READ_CPU_INFO                 0x00010001
+#define SCLP_CMDW_CONFIGURE_CPU                 0x00110001
+#define SCLP_CMDW_DECONFIGURE_CPU               0x00100001
+
+/* SCLP PCI codes */
+#define SCLP_HAS_IOA_RECONFIG                   0x0000000040000000ULL
+#define SCLP_CMDW_CONFIGURE_IOA                 0x001a0001
+#define SCLP_CMDW_DECONFIGURE_IOA               0x001b0001
+#define SCLP_RECONFIG_PCI_ATYPE                 2
+
 /* SCLP response codes */
 #define SCLP_RC_NORMAL_READ_COMPLETION          0x0010
 #define SCLP_RC_NORMAL_COMPLETION               0x0020
+#define SCLP_RC_SCCB_BOUNDARY_VIOLATION         0x0100
+#define SCLP_RC_NO_ACTION_REQUIRED              0x0120
 #define SCLP_RC_INVALID_SCLP_COMMAND            0x01f0
 #define SCLP_RC_CONTAINED_EQUIPMENT_CHECK       0x0340
 #define SCLP_RC_INSUFFICIENT_SCCB_LENGTH        0x0300
+#define SCLP_RC_STANDBY_READ_COMPLETION         0x0410
+#define SCLP_RC_ADAPTER_IN_RESERVED_STATE       0x05f0
+#define SCLP_RC_ADAPTER_TYPE_NOT_RECOGNIZED     0x06f0
+#define SCLP_RC_ADAPTER_ID_NOT_RECOGNIZED       0x09f0
 #define SCLP_RC_INVALID_FUNCTION                0x40f0
 #define SCLP_RC_NO_EVENT_BUFFERS_STORED         0x60f0
 #define SCLP_RC_INVALID_SELECTION_MASK          0x70f0
@@ -50,13 +85,83 @@ typedef struct SCCBHeader {
 } __attribute__((packed)) SCCBHeader;
 
 #define SCCB_DATA_LEN (SCCB_SIZE - sizeof(SCCBHeader))
+#define SCCB_CPU_FEATURE_LEN 6
+
+/* CPU information */
+typedef struct CPUEntry {
+    uint8_t address;
+    uint8_t reserved0;
+    uint8_t features[SCCB_CPU_FEATURE_LEN];
+    uint8_t reserved2[6];
+    uint8_t type;
+    uint8_t reserved1;
+} __attribute__((packed)) CPUEntry;
 
 typedef struct ReadInfo {
     SCCBHeader h;
     uint16_t rnmax;
     uint8_t rnsize;
+    uint8_t  _reserved1[16 - 11];       /* 11-15 */
+    uint16_t entries_cpu;               /* 16-17 */
+    uint16_t offset_cpu;                /* 18-19 */
+    uint8_t  _reserved2[24 - 20];       /* 20-23 */
+    uint8_t  loadparm[8];               /* 24-31 */
+    uint8_t  _reserved3[48 - 32];       /* 32-47 */
+    uint64_t facilities;                /* 48-55 */
+    uint8_t  _reserved0[76 - 56];       /* 56-75 */
+    uint32_t ibc_val;
+    uint8_t  conf_char[99 - 80];        /* 80-98 */
+    uint8_t mha_pow;
+    uint32_t rnsize2;
+    uint64_t rnmax2;
+    uint8_t  _reserved6[116 - 112];     /* 112-115 */
+    uint8_t  conf_char_ext[120 - 116];   /* 116-119 */
+    uint16_t highest_cpu;
+    uint8_t  _reserved5[124 - 122];     /* 122-123 */
+    uint32_t hmfai;
+    struct CPUEntry entries[0];
 } __attribute__((packed)) ReadInfo;
 
+typedef struct ReadCpuInfo {
+    SCCBHeader h;
+    uint16_t nr_configured;         /* 8-9 */
+    uint16_t offset_configured;     /* 10-11 */
+    uint16_t nr_standby;            /* 12-13 */
+    uint16_t offset_standby;        /* 14-15 */
+    uint8_t reserved0[24-16];       /* 16-23 */
+    struct CPUEntry entries[0];
+} __attribute__((packed)) ReadCpuInfo;
+
+typedef struct ReadStorageElementInfo {
+    SCCBHeader h;
+    uint16_t max_id;
+    uint16_t assigned;
+    uint16_t standby;
+    uint8_t _reserved0[16 - 14]; /* 14-15 */
+    uint32_t entries[0];
+} __attribute__((packed)) ReadStorageElementInfo;
+
+typedef struct AttachStorageElement {
+    SCCBHeader h;
+    uint8_t _reserved0[10 - 8];  /* 8-9 */
+    uint16_t assigned;
+    uint8_t _reserved1[16 - 12]; /* 12-15 */
+    uint32_t entries[0];
+} __attribute__((packed)) AttachStorageElement;
+
+typedef struct AssignStorage {
+    SCCBHeader h;
+    uint16_t rn;
+} __attribute__((packed)) AssignStorage;
+
+typedef struct IoaCfgSccb {
+    SCCBHeader header;
+    uint8_t atype;
+    uint8_t reserved1;
+    uint16_t reserved2;
+    uint32_t aid;
+} __attribute__((packed)) IoaCfgSccb;
+
 typedef struct SCCB {
     SCCBHeader h;
     char data[SCCB_DATA_LEN];
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH kvm-unit-tests v3 05/11] s390x: rename sclp_setup() to sclp_ascii_setup()
  2018-02-13 16:23 [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support David Hildenbrand
                   ` (3 preceding siblings ...)
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 04/11] s390x: add missing sclp definitions from QEMU David Hildenbrand
@ 2018-02-13 16:23 ` David Hildenbrand
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 06/11] s390x: detect installed memory David Hildenbrand
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 23+ messages in thread
From: David Hildenbrand @ 2018-02-13 16:23 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, Cornelia Huck, Christian Borntraeger,
	David Hildenbrand

We'll be introducing some other sclp related files including setup
functions soon. Also allow to call sclp_service_call() from these
(including reusing the buffer).

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 lib/s390x/io.c         | 2 +-
 lib/s390x/sclp-ascii.c | 6 +++---
 lib/s390x/sclp.h       | 4 +++-
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/s390x/io.c b/lib/s390x/io.c
index 12f9d26..3121a78 100644
--- a/lib/s390x/io.c
+++ b/lib/s390x/io.c
@@ -42,7 +42,7 @@ void setup()
 {
 	setup_args_progname(ipl_args);
 	setup_facilities();
-	sclp_setup();
+	sclp_ascii_setup();
 }
 
 void exit(int code)
diff --git a/lib/s390x/sclp-ascii.c b/lib/s390x/sclp-ascii.c
index dfb9e68..893ca17 100644
--- a/lib/s390x/sclp-ascii.c
+++ b/lib/s390x/sclp-ascii.c
@@ -13,10 +13,10 @@
 #include <asm/page.h>
 #include "sclp.h"
 
-static char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096)));
+char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096)));
 
 /* Perform service call. Return 0 on success, non-zero otherwise. */
-static int sclp_service_call(unsigned int command, void *sccb)
+int sclp_service_call(unsigned int command, void *sccb)
 {
         int cc;
 
@@ -47,7 +47,7 @@ static void sclp_set_write_mask(void)
     sclp_service_call(SCLP_CMD_WRITE_EVENT_MASK, sccb);
 }
 
-void sclp_setup(void)
+void sclp_ascii_setup(void)
 {
     sclp_set_write_mask();
 }
diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h
index a1d0a5e..d113cf8 100644
--- a/lib/s390x/sclp.h
+++ b/lib/s390x/sclp.h
@@ -207,7 +207,9 @@ typedef struct ReadEventData {
     uint32_t mask;
 } __attribute__((packed)) ReadEventData;
 
-void sclp_setup(void);
+void sclp_ascii_setup(void);
 void sclp_print(const char *str);
+extern char _sccb[];
+int sclp_service_call(unsigned int command, void *sccb);
 
 #endif /* SCLP_H */
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH kvm-unit-tests v3 06/11] s390x: detect installed memory
  2018-02-13 16:23 [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support David Hildenbrand
                   ` (4 preceding siblings ...)
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 05/11] s390x: rename sclp_setup() to sclp_ascii_setup() David Hildenbrand
@ 2018-02-13 16:23 ` David Hildenbrand
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 07/11] s390x: initialize the physical allocator David Hildenbrand
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 23+ messages in thread
From: David Hildenbrand @ 2018-02-13 16:23 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, Cornelia Huck, Christian Borntraeger,
	David Hildenbrand

Unfortunately, there is no easy way to simply read out the amount
of installed memory. We have to probe (via TEST PROTECTION) for installed
memory in a given range.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 lib/s390x/asm/arch_def.h  | 12 ++++++++++
 lib/s390x/asm/interrupt.h |  1 +
 lib/s390x/interrupt.c     | 11 +++++++++
 lib/s390x/io.c            |  1 +
 lib/s390x/sclp.c          | 58 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/s390x/sclp.h          |  1 +
 s390x/Makefile            |  1 +
 7 files changed, 85 insertions(+)
 create mode 100644 lib/s390x/sclp.c

diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h
index 72e5c60..ee4c96f 100644
--- a/lib/s390x/asm/arch_def.h
+++ b/lib/s390x/asm/arch_def.h
@@ -151,4 +151,16 @@ struct cpuid {
 	uint64_t reserved : 15;
 };
 
+static inline int tprot(unsigned long addr)
+{
+	int cc;
+
+	asm volatile(
+		"	tprot	0(%1),0\n"
+		"	ipm	%0\n"
+		"	srl	%0,28\n"
+		: "=d" (cc) : "a" (addr) : "cc");
+	return cc;
+}
+
 #endif
diff --git a/lib/s390x/asm/interrupt.h b/lib/s390x/asm/interrupt.h
index 41be039..3ccc8e3 100644
--- a/lib/s390x/asm/interrupt.h
+++ b/lib/s390x/asm/interrupt.h
@@ -13,6 +13,7 @@
 
 void handle_pgm_int(void);
 void expect_pgm_int(void);
+uint16_t clear_pgm_int(void);
 void check_pgm_int_code(uint16_t code);
 
 /* Activate low-address protection */
diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c
index 8d861a2..67d581b 100644
--- a/lib/s390x/interrupt.c
+++ b/lib/s390x/interrupt.c
@@ -23,6 +23,17 @@ void expect_pgm_int(void)
 	mb();
 }
 
+uint16_t clear_pgm_int(void)
+{
+	uint16_t code;
+
+	mb();
+	code = lc->pgm_int_code;
+	lc->pgm_int_code = 0;
+	pgm_int_expected = false;
+	return code;
+}
+
 void check_pgm_int_code(uint16_t code)
 {
 	mb();
diff --git a/lib/s390x/io.c b/lib/s390x/io.c
index 3121a78..eb4d171 100644
--- a/lib/s390x/io.c
+++ b/lib/s390x/io.c
@@ -43,6 +43,7 @@ void setup()
 	setup_args_progname(ipl_args);
 	setup_facilities();
 	sclp_ascii_setup();
+	sclp_memory_setup();
 }
 
 void exit(int code)
diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c
new file mode 100644
index 0000000..199405c
--- /dev/null
+++ b/lib/s390x/sclp.c
@@ -0,0 +1,58 @@
+/*
+ * s390x SCLP driver
+ *
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ *  David Hildenbrand <david@redhat.com>
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License version 2.
+ */
+
+#include <libcflat.h>
+#include <asm/page.h>
+#include <asm/arch_def.h>
+#include <asm/interrupt.h>
+#include "sclp.h"
+
+static uint64_t storage_increment_size;
+static uint64_t max_ram_size;
+static uint64_t ram_size;
+
+void sclp_memory_setup(void)
+{
+	ReadInfo *ri = (void *)_sccb;
+	uint64_t rnmax, rnsize;
+	int cc;
+
+	ri->h.length = SCCB_SIZE;
+	sclp_service_call(SCLP_CMDW_READ_SCP_INFO_FORCED, ri);
+
+	/* calculate the storage increment size */
+	rnsize = ri->rnsize;
+	if (!rnsize) {
+		rnsize = ri->rnsize2;
+	}
+	storage_increment_size = rnsize << 20;
+
+	/* calculate the maximum memory size */
+	rnmax = ri->rnmax;
+	if (!rnmax) {
+		rnmax = ri->rnmax2;
+	}
+	max_ram_size = rnmax * storage_increment_size;
+
+	/* lowcore is always accessible, so the first increment is accessible */
+	ram_size = storage_increment_size;
+
+	/* probe for r/w memory up to max memory size */
+	while (ram_size < max_ram_size) {
+		expect_pgm_int();
+		cc = tprot(ram_size + storage_increment_size - 1);
+		/* stop once we receive an exception or have protected memory */
+		if (clear_pgm_int() || cc != 0)
+			break;
+		ram_size += storage_increment_size;
+	}
+}
diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h
index d113cf8..21d482b 100644
--- a/lib/s390x/sclp.h
+++ b/lib/s390x/sclp.h
@@ -211,5 +211,6 @@ void sclp_ascii_setup(void);
 void sclp_print(const char *str);
 extern char _sccb[];
 int sclp_service_call(unsigned int command, void *sccb);
+void sclp_memory_setup(void);
 
 #endif /* SCLP_H */
diff --git a/s390x/Makefile b/s390x/Makefile
index f585faf..ce63dd1 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -24,6 +24,7 @@ cflatobjs += lib/util.o
 cflatobjs += lib/alloc_phys.o
 cflatobjs += lib/s390x/io.o
 cflatobjs += lib/s390x/stack.o
+cflatobjs += lib/s390x/sclp.o
 cflatobjs += lib/s390x/sclp-ascii.o
 cflatobjs += lib/s390x/interrupt.o
 
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH kvm-unit-tests v3 07/11] s390x: initialize the physical allocator
  2018-02-13 16:23 [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support David Hildenbrand
                   ` (5 preceding siblings ...)
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 06/11] s390x: detect installed memory David Hildenbrand
@ 2018-02-13 16:23 ` David Hildenbrand
  2018-02-14 12:05   ` Thomas Huth
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 08/11] s390x: add vmalloc support David Hildenbrand
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 23+ messages in thread
From: David Hildenbrand @ 2018-02-13 16:23 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, Cornelia Huck, Christian Borntraeger,
	David Hildenbrand

We now have the range of free memory, let's initialize the physical
allocator. It is now possible to use use malloc and memalign, based on the
early-ops. alloc_pages() cannot be used yet (as it has to be initialized
via free_pages() - e.g. via setup_vm() - first)

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 lib/s390x/sclp.c | 12 ++++++++++++
 s390x/Makefile   |  3 +++
 2 files changed, 15 insertions(+)

diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c
index 199405c..c7471b1 100644
--- a/lib/s390x/sclp.c
+++ b/lib/s390x/sclp.c
@@ -15,11 +15,21 @@
 #include <asm/arch_def.h>
 #include <asm/interrupt.h>
 #include "sclp.h"
+#include <alloc_phys.h>
+
+extern unsigned long stacktop;
 
 static uint64_t storage_increment_size;
 static uint64_t max_ram_size;
 static uint64_t ram_size;
 
+static void mem_init(phys_addr_t mem_end)
+{
+	phys_addr_t freemem_start = (phys_addr_t)&stacktop & PAGE_MASK;
+
+	phys_alloc_init(freemem_start, mem_end - freemem_start);
+}
+
 void sclp_memory_setup(void)
 {
 	ReadInfo *ri = (void *)_sccb;
@@ -55,4 +65,6 @@ void sclp_memory_setup(void)
 			break;
 		ram_size += storage_increment_size;
 	}
+
+	mem_init(ram_size);
 }
diff --git a/s390x/Makefile b/s390x/Makefile
index ce63dd1..4198fdc 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -21,6 +21,9 @@ asm-offsets = lib/$(ARCH)/asm-offsets.h
 include $(SRCDIR)/scripts/asm-offsets.mak
 
 cflatobjs += lib/util.o
+cflatobjs += lib/alloc.o
+cflatobjs += lib/alloc_phys.o
+cflatobjs += lib/alloc_page.o
 cflatobjs += lib/alloc_phys.o
 cflatobjs += lib/s390x/io.o
 cflatobjs += lib/s390x/stack.o
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH kvm-unit-tests v3 08/11] s390x: add vmalloc support
  2018-02-13 16:23 [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support David Hildenbrand
                   ` (6 preceding siblings ...)
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 07/11] s390x: initialize the physical allocator David Hildenbrand
@ 2018-02-13 16:23 ` David Hildenbrand
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 09/11] s390x: enable DAT in PGM interrupt handler David Hildenbrand
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 23+ messages in thread
From: David Hildenbrand @ 2018-02-13 16:23 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, Cornelia Huck, Christian Borntraeger,
	David Hildenbrand

To use virtual addresses, we have to
- build page tables with identity mapping
- setup the primary ASCE in cr1
- enable DAT in the PSW

Not using the Linux definitions/implementation as they contain too much
software defined stuff / things we don't need.

Written from scratch. Tried to stick to the general Linux naming
schemes.

As we currently don't invalidate anything except page table entries, it
is sufficient to only use ipte for now.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 lib/s390x/asm/arch_def.h |  46 ++++++++++
 lib/s390x/asm/page.h     |  24 +++++
 lib/s390x/asm/pgtable.h  | 224 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/s390x/mmu.c          | 104 ++++++++++++++++++++++
 lib/s390x/sclp.c         |   2 +
 s390x/Makefile           |   2 +
 6 files changed, 402 insertions(+)
 create mode 100644 lib/s390x/asm/pgtable.h
 create mode 100644 lib/s390x/mmu.c

diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h
index ee4c96f..620dca4 100644
--- a/lib/s390x/asm/arch_def.h
+++ b/lib/s390x/asm/arch_def.h
@@ -15,6 +15,8 @@ struct psw {
 	uint64_t	addr;
 };
 
+#define PSW_MASK_DAT			0x0400000000000000UL
+
 struct lowcore {
 	uint8_t		pad_0x0000[0x0080 - 0x0000];	/* 0x0000 */
 	uint32_t	ext_int_param;			/* 0x0080 */
@@ -163,4 +165,48 @@ static inline int tprot(unsigned long addr)
 	return cc;
 }
 
+static inline void lctlg(int cr, uint64_t value)
+{
+	asm volatile(
+		"	lctlg	%1,%1,%0\n"
+		: : "Q" (value), "i" (cr));
+}
+
+static inline uint64_t stctg(int cr)
+{
+	uint64_t value;
+
+	asm volatile(
+		"	stctg	%1,%1,%0\n"
+		: "=Q" (value) : "i" (cr) : "memory");
+	return value;
+}
+
+static inline uint64_t extract_psw_mask(void)
+{
+	uint32_t mask_upper = 0, mask_lower = 0;
+
+	asm volatile(
+		"	epsw	%0,%1\n"
+		: "+r" (mask_upper), "+r" (mask_lower) : : );
+
+	return (uint64_t) mask_upper << 32 | mask_lower;
+}
+
+static inline void load_psw_mask(uint64_t mask)
+{
+	struct psw psw = {
+		.mask = mask,
+		.addr = 0,
+	};
+	uint64_t tmp = 0;
+
+	asm volatile(
+		"	larl	%0,0f\n"
+		"	stg	%0,8(%1)\n"
+		"	lpswe	0(%1)\n"
+		"0:\n"
+		: "+r" (tmp) :  "a" (&psw) : "memory", "cc" );
+}
+
 #endif
diff --git a/lib/s390x/asm/page.h b/lib/s390x/asm/page.h
index 141a456..bc19154 100644
--- a/lib/s390x/asm/page.h
+++ b/lib/s390x/asm/page.h
@@ -13,4 +13,28 @@
 
 #include <asm-generic/page.h>
 
+typedef uint64_t pgdval_t;		/* Region-1 table entry */
+typedef uint64_t p4dval_t;		/* Region-2 table entry*/
+typedef uint64_t pudval_t;		/* Region-3 table entry */
+typedef uint64_t pmdval_t;		/* Segment table entry */
+typedef uint64_t pteval_t;		/* Page table entry */
+
+typedef struct { pgdval_t pgd; } pgd_t;
+typedef struct { p4dval_t p4d; } p4d_t;
+typedef struct { pudval_t pud; } pud_t;
+typedef struct { pmdval_t pmd; } pmd_t;
+typedef struct { pteval_t pte; } pte_t;
+
+#define pgd_val(x)	((x).pgd)
+#define p4d_val(x)	((x).p4d)
+#define pud_val(x)	((x).pud)
+#define pmd_val(x)	((x).pmd)
+#define pte_val(x)	((x).pte)
+
+#define __pgd(x)	((pgd_t) { (x) } )
+#define __p4d(x)	((p4d_t) { (x) } )
+#define __pud(x)	((pud_t) { (x) } )
+#define __pmd(x)	((pmd_t) { (x) } )
+#define __pte(x)	((pte_t) { (x) } )
+
 #endif
diff --git a/lib/s390x/asm/pgtable.h b/lib/s390x/asm/pgtable.h
new file mode 100644
index 0000000..e15bee9
--- /dev/null
+++ b/lib/s390x/asm/pgtable.h
@@ -0,0 +1,224 @@
+/*
+ * s390x page table definitions and functions
+ *
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ *  David Hildenbrand <david@redhat.com>
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License version 2.
+ */
+#ifndef _ASMS390X_PGTABLE_H_
+#define _ASMS390X_PGTABLE_H_
+
+#include <asm/page.h>
+#include <alloc_page.h>
+
+#define ASCE_ORIGIN			0xfffffffffffff000UL
+#define ASCE_G				0x0000000000000200UL
+#define ASCE_P				0x0000000000000100UL
+#define ASCE_S				0x0000000000000080UL
+#define ASCE_X				0x0000000000000040UL
+#define ASCE_R				0x0000000000000020UL
+#define ASCE_DT				0x000000000000000cUL
+#define ASCE_TL				0x0000000000000003UL
+
+#define ASCE_DT_REGION1			0x000000000000000cUL
+#define ASCE_DT_REGION2			0x0000000000000008UL
+#define ASCE_DT_REGION3			0x0000000000000004UL
+#define ASCE_DT_SEGMENT			0x0000000000000000UL
+
+#define REGION_TABLE_ORDER		2
+#define REGION_TABLE_ENTRIES		2048
+#define REGION_TABLE_LENGTH		3
+
+#define REGION1_SHIFT			53
+#define REGION2_SHIFT			42
+#define REGION3_SHIFT			31
+
+#define REGION_ENTRY_ORIGIN		0xfffffffffffff000UL
+#define REGION_ENTRY_P			0x0000000000000200UL
+#define REGION_ENTRY_TF			0x00000000000000c0UL
+#define REGION_ENTRY_I			0x0000000000000020UL
+#define REGION_ENTRY_TT			0x000000000000000cUL
+#define REGION_ENTRY_TL			0x0000000000000003UL
+
+#define REGION_ENTRY_TT_REGION1		0x000000000000000cUL
+#define REGION_ENTRY_TT_REGION2		0x0000000000000008UL
+#define REGION_ENTRY_TT_REGION3		0x0000000000000004UL
+
+#define REGION3_ENTRY_RFAA		0xffffffff80000000UL
+#define REGION3_ENTRY_AV		0x0000000000010000UL
+#define REGION3_ENTRY_ACC		0x000000000000f000UL
+#define REGION3_ENTRY_F			0x0000000000000800UL
+#define REGION3_ENTRY_FC		0x0000000000000400UL
+#define REGION3_ENTRY_IEP		0x0000000000000100UL
+#define REGION3_ENTRY_CR		0x0000000000000010UL
+
+#define SEGMENT_TABLE_ORDER		2
+#define SEGMENT_TABLE_ENTRIES		2048
+#define SEGMENT_TABLE_LENGTH		3
+#define SEGMENT_SHIFT			20
+
+#define SEGMENT_ENTRY_ORIGIN		0xfffffffffffff800UL
+#define SEGMENT_ENTRY_SFAA		0xfffffffffff80000UL
+#define SEGMENT_ENTRY_AV		0x0000000000010000UL
+#define SEGMENT_ENTRY_ACC		0x000000000000f000UL
+#define SEGMENT_ENTRY_F			0x0000000000000800UL
+#define SEGMENT_ENTRY_FC		0x0000000000000400UL
+#define SEGMENT_ENTRY_P			0x0000000000000200UL
+#define SEGMENT_ENTRY_IEP		0x0000000000000100UL
+#define SEGMENT_ENTRY_I			0x0000000000000020UL
+#define SEGMENT_ENTRY_CS		0x0000000000000010UL
+#define SEGMENT_ENTRY_TT		0x000000000000000cUL
+
+#define SEGMENT_ENTRY_TT_REGION1	0x000000000000000cUL
+#define SEGMENT_ENTRY_TT_REGION2	0x0000000000000008UL
+#define SEGMENT_ENTRY_TT_REGION3	0x0000000000000004UL
+#define SEGMENT_ENTRY_TT_SEGMENT	0x0000000000000000UL
+
+#define PAGE_TABLE_ORDER		0
+#define PAGE_TABLE_ENTRIES		256
+
+#define PAGE_ENTRY_I			0x0000000000000400UL
+#define PAGE_ENTRY_P			0x0000000000000200UL
+#define PAGE_ENTRY_IEP			0x0000000000000100UL
+
+#define PTRS_PER_PGD			REGION_TABLE_ENTRIES
+#define PTRS_PER_P4D			REGION_TABLE_ENTRIES
+#define PTRS_PER_PUD			REGION_TABLE_ENTRIES
+#define PTRS_PER_PMD			SEGMENT_TABLE_ENTRIES
+#define PTRS_PER_PTE			PAGE_TABLE_ENTRIES
+
+#define PGDIR_SHIFT			REGION1_SHIFT
+#define P4D_SHIFT			REGION2_SHIFT
+#define PUD_SHIFT			REGION3_SHIFT
+#define PMD_SHIFT			SEGMENT_SHIFT
+
+#define pgd_none(entry) (pgd_val(entry) & REGION_ENTRY_I)
+#define p4d_none(entry) (p4d_val(entry) & REGION_ENTRY_I)
+#define pud_none(entry) (pud_val(entry) & REGION_ENTRY_I)
+#define pmd_none(entry) (pmd_val(entry) & SEGMENT_ENTRY_I)
+#define pte_none(entry) (pte_val(entry) & PAGE_ENTRY_I)
+
+#define pgd_addr(entry) __va(pgd_val(entry) & REGION_ENTRY_ORIGIN)
+#define p4d_addr(entry) __va(p4d_val(entry) & REGION_ENTRY_ORIGIN)
+#define pud_addr(entry) __va(pud_val(entry) & REGION_ENTRY_ORIGIN)
+#define pmd_addr(entry) __va(pmd_val(entry) & SEGMENT_ENTRY_ORIGIN)
+#define pte_addr(entry) __va(pte_val(entry) & PAGE_MASK)
+
+#define pgd_index(addr) (((addr) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
+#define p4d_index(addr) (((addr) >> P4D_SHIFT) & (PTRS_PER_P4D - 1))
+#define pud_index(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
+#define pmd_index(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
+#define pte_index(addr) (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
+
+#define pgd_offset(table, addr) ((pgd_t *)(table) + pgd_index(addr))
+#define p4d_offset(pgd, addr) ((p4d_t *)pgd_addr(*(pgd)) + p4d_index(addr))
+#define pud_offset(p4d, addr) ((pud_t *)p4d_addr(*(p4d)) + pud_index(addr))
+#define pmd_offset(pud, addr) ((pmd_t *)pud_addr(*(pud)) + pmd_index(addr))
+#define pte_offset(pmd, addr) ((pte_t *)pmd_addr(*(pmd)) + pte_index(addr))
+
+static inline pgd_t *pgd_alloc_one(void)
+{
+	pgd_t *pgd = alloc_pages(REGION_TABLE_ORDER);
+	int i;
+
+	for (i = 0; i < REGION_TABLE_ENTRIES; i++)
+		pgd_val(pgd[i]) = REGION_ENTRY_TT_REGION1 | REGION_ENTRY_I;
+	return pgd;
+}
+
+static inline p4d_t *p4d_alloc_one(void)
+{
+	p4d_t *p4d = alloc_pages(REGION_TABLE_ORDER);
+	int i;
+
+	for (i = 0; i < REGION_TABLE_ENTRIES; i++)
+		p4d_val(p4d[i]) = REGION_ENTRY_TT_REGION2 | REGION_ENTRY_I;
+	return p4d;
+}
+
+static inline p4d_t *p4d_alloc(pgd_t *pgd, unsigned long addr)
+{
+	if (pgd_none(*pgd)) {
+		p4d_t *p4d = p4d_alloc_one();
+		pgd_val(*pgd) = __pa(p4d) | REGION_ENTRY_TT_REGION1 |
+				REGION_TABLE_LENGTH;
+	}
+	return p4d_offset(pgd, addr);
+}
+
+static inline pud_t *pud_alloc_one(void)
+{
+	pud_t *pud = alloc_pages(REGION_TABLE_ORDER);
+	int i;
+
+	for (i = 0; i < REGION_TABLE_ENTRIES; i++)
+		pud_val(pud[i]) = REGION_ENTRY_TT_REGION3 | REGION_ENTRY_I;
+	return pud;
+}
+
+static inline pud_t *pud_alloc(p4d_t *p4d, unsigned long addr)
+{
+	if (p4d_none(*p4d)) {
+		pud_t *pud = pud_alloc_one();
+		p4d_val(*p4d) = __pa(pud) | REGION_ENTRY_TT_REGION2 |
+				REGION_TABLE_LENGTH;
+	}
+	return pud_offset(p4d, addr);
+}
+
+static inline pmd_t *pmd_alloc_one(void)
+{
+	pmd_t *pmd = alloc_pages(SEGMENT_TABLE_ORDER);
+	int i;
+
+	for (i = 0; i < SEGMENT_TABLE_ENTRIES; i++)
+		pmd_val(pmd[i]) = SEGMENT_ENTRY_TT_SEGMENT | SEGMENT_ENTRY_I;
+	return pmd;
+}
+
+static inline pmd_t *pmd_alloc(pud_t *pud, unsigned long addr)
+{
+	if (pud_none(*pud)) {
+		pmd_t *pmd = pmd_alloc_one();
+		pud_val(*pud) = __pa(pmd) | REGION_ENTRY_TT_REGION3 |
+				REGION_TABLE_LENGTH;
+	}
+	return pmd_offset(pud, addr);
+}
+
+static inline pte_t *pte_alloc_one(void)
+{
+	pte_t *pte = alloc_pages(PAGE_TABLE_ORDER);
+	int i;
+
+	for (i = 0; i < PAGE_TABLE_ENTRIES; i++)
+		pte_val(pte[i]) = PAGE_ENTRY_I;
+	return pte;
+}
+
+static inline pte_t *pte_alloc(pmd_t *pmd, unsigned long addr)
+{
+	if (pmd_none(*pmd)) {
+		pte_t *pte = pte_alloc_one();
+		pmd_val(*pmd) = __pa(pte) | SEGMENT_ENTRY_TT_SEGMENT |
+				SEGMENT_TABLE_LENGTH;
+	}
+	return pte_offset(pmd, addr);
+}
+
+static inline void ipte(unsigned long vaddr, pteval_t *p_pte)
+{
+	unsigned long table_origin = (unsigned long)p_pte & PAGE_MASK;
+
+	asm volatile(
+		"	ipte %0,%1\n"
+		: : "a" (table_origin), "a" (vaddr) : "memory");
+}
+
+void configure_dat(int enable);
+
+#endif /* _ASMS390X_PGTABLE_H_ */
diff --git a/lib/s390x/mmu.c b/lib/s390x/mmu.c
new file mode 100644
index 0000000..f0ec7c3
--- /dev/null
+++ b/lib/s390x/mmu.c
@@ -0,0 +1,104 @@
+/*
+ * s390x MMU
+ *
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ *  David Hildenbrand <david@redhat.com>
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License version 2.
+ */
+
+#include <libcflat.h>
+#include <asm/pgtable.h>
+#include <asm/arch_def.h>
+#include <asm/barrier.h>
+#include <vmalloc.h>
+
+void configure_dat(int enable)
+{
+	uint64_t mask;
+
+	if (enable)
+		mask = extract_psw_mask() | PSW_MASK_DAT;
+	else
+		mask = extract_psw_mask() & ~PSW_MASK_DAT;
+
+	load_psw_mask(mask);
+}
+
+static void mmu_enable(pgd_t *pgtable)
+{
+	const uint64_t asce = __pa(pgtable) | ASCE_DT_REGION1 |
+			      REGION_TABLE_LENGTH;
+
+	/* set primary asce */
+	lctlg(1, asce);
+	assert(stctg(1) == asce);
+
+	/* enable dat (primary == 0 set as default) */
+	configure_dat(1);
+}
+
+static pteval_t *get_pte(pgd_t *pgtable, uintptr_t vaddr)
+{
+	pgd_t *pgd = pgd_offset(pgtable, vaddr);
+	p4d_t *p4d = p4d_alloc(pgd, vaddr);
+	pud_t *pud = pud_alloc(p4d, vaddr);
+	pmd_t *pmd = pmd_alloc(pud, vaddr);
+	pte_t *pte = pte_alloc(pmd, vaddr);
+
+	return &pte_val(*pte);
+}
+
+phys_addr_t virt_to_pte_phys(pgd_t *pgtable, void *vaddr)
+{
+	return (*get_pte(pgtable, (uintptr_t)vaddr) & PAGE_MASK) +
+	       ((unsigned long)vaddr & ~PAGE_MASK);
+}
+
+pteval_t *install_page(pgd_t *pgtable, phys_addr_t phys, void *vaddr)
+{
+	pteval_t *p_pte = get_pte(pgtable, (uintptr_t)vaddr);
+
+	/* first flush the old entry (if we're replacing anything) */
+	if (!(*p_pte & PAGE_ENTRY_I))
+		ipte((uintptr_t)vaddr, p_pte);
+
+	*p_pte = __pa(phys);
+	return p_pte;
+}
+
+static void setup_identity(pgd_t *pgtable, phys_addr_t start_addr,
+			   phys_addr_t end_addr)
+{
+	phys_addr_t cur;
+
+	start_addr &= PAGE_MASK;
+	for (cur = start_addr; true; cur += PAGE_SIZE) {
+		if (start_addr < end_addr && cur >= end_addr)
+			break;
+		if (start_addr > end_addr && cur <= end_addr)
+			break;
+		install_page(pgtable, cur, __va(cur));
+	}
+}
+
+void *setup_mmu(phys_addr_t phys_end){
+	pgd_t *page_root;
+
+	/* allocate a region-1 table */
+	page_root = pgd_alloc_one();
+
+	/* map all physical memory 1:1 */
+	setup_identity(page_root, 0, phys_end);
+
+	/* generate 128MB of invalid adresses at the end (for testing PGM) */
+	init_alloc_vpage((void *) -(1UL << 27));
+	setup_identity(page_root, -(1UL << 27), 0);
+
+	/* finally enable DAT with the new table */
+	mmu_enable(page_root);
+	return page_root;
+}
diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c
index c7471b1..005ae52 100644
--- a/lib/s390x/sclp.c
+++ b/lib/s390x/sclp.c
@@ -28,6 +28,8 @@ static void mem_init(phys_addr_t mem_end)
 	phys_addr_t freemem_start = (phys_addr_t)&stacktop & PAGE_MASK;
 
 	phys_alloc_init(freemem_start, mem_end - freemem_start);
+
+	setup_vm();
 }
 
 void sclp_memory_setup(void)
diff --git a/s390x/Makefile b/s390x/Makefile
index 4198fdc..d9bef37 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -24,12 +24,14 @@ cflatobjs += lib/util.o
 cflatobjs += lib/alloc.o
 cflatobjs += lib/alloc_phys.o
 cflatobjs += lib/alloc_page.o
+cflatobjs += lib/vmalloc.o
 cflatobjs += lib/alloc_phys.o
 cflatobjs += lib/s390x/io.o
 cflatobjs += lib/s390x/stack.o
 cflatobjs += lib/s390x/sclp.o
 cflatobjs += lib/s390x/sclp-ascii.o
 cflatobjs += lib/s390x/interrupt.o
+cflatobjs += lib/s390x/mmu.o
 
 OBJDIRS += lib/s390x
 
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH kvm-unit-tests v3 09/11] s390x: enable DAT in PGM interrupt handler
  2018-02-13 16:23 [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support David Hildenbrand
                   ` (7 preceding siblings ...)
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 08/11] s390x: add vmalloc support David Hildenbrand
@ 2018-02-13 16:23 ` David Hildenbrand
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 10/11] s390x: add test for (v)malloc David Hildenbrand
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 23+ messages in thread
From: David Hildenbrand @ 2018-02-13 16:23 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, Cornelia Huck, Christian Borntraeger,
	David Hildenbrand

Configure it in setup_vm().

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 lib/s390x/mmu.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/s390x/mmu.c b/lib/s390x/mmu.c
index f0ec7c3..288f835 100644
--- a/lib/s390x/mmu.c
+++ b/lib/s390x/mmu.c
@@ -30,6 +30,7 @@ void configure_dat(int enable)
 
 static void mmu_enable(pgd_t *pgtable)
 {
+	struct lowcore *lc = NULL;
 	const uint64_t asce = __pa(pgtable) | ASCE_DT_REGION1 |
 			      REGION_TABLE_LENGTH;
 
@@ -39,6 +40,9 @@ static void mmu_enable(pgd_t *pgtable)
 
 	/* enable dat (primary == 0 set as default) */
 	configure_dat(1);
+
+	/* we can now also use DAT unconditionally in our PGM handler */
+	lc->pgm_new_psw.mask |= PSW_MASK_DAT;
 }
 
 static pteval_t *get_pte(pgd_t *pgtable, uintptr_t vaddr)
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH kvm-unit-tests v3 10/11] s390x: add test for (v)malloc
  2018-02-13 16:23 [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support David Hildenbrand
                   ` (8 preceding siblings ...)
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 09/11] s390x: enable DAT in PGM interrupt handler David Hildenbrand
@ 2018-02-13 16:23 ` David Hildenbrand
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 11/11] s390x: add sieve test David Hildenbrand
  2018-02-14 11:52 ` [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support Paolo Bonzini
  11 siblings, 0 replies; 23+ messages in thread
From: David Hildenbrand @ 2018-02-13 16:23 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, Cornelia Huck, Christian Borntraeger,
	David Hildenbrand

Let's test if basic allocation works and we get virtual addresses.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 s390x/selftest.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/s390x/selftest.c b/s390x/selftest.c
index 905713f..18a40e1 100644
--- a/s390x/selftest.c
+++ b/s390x/selftest.c
@@ -10,7 +10,10 @@
  */
 #include <libcflat.h>
 #include <util.h>
+#include <alloc.h>
 #include <asm/interrupt.h>
+#include <asm/barrier.h>
+#include <asm/pgtable.h>
 
 static void test_fp(void)
 {
@@ -37,6 +40,31 @@ static void test_pgm_int(void)
 	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
 }
 
+static void test_malloc(void)
+{
+	int *tmp = malloc(sizeof(int));
+	int *tmp2 = malloc(sizeof(int));
+
+	*tmp = 123456789;
+	*tmp2 = 123456789;
+	mb();
+
+	report("malloc: got vaddr", (uintptr_t)tmp & 0xf000000000000000ul);
+	report("malloc: access works", *tmp == 123456789);
+	report("malloc: got 2nd vaddr", (uintptr_t)tmp2 & 0xf000000000000000ul);
+	report("malloc: access works", (*tmp2 == 123456789));
+	report("malloc: addresses differ", tmp != tmp2);
+
+	expect_pgm_int();
+	configure_dat(0);
+	*tmp = 987654321;
+	configure_dat(1);
+	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
+
+	free(tmp);
+	free(tmp2);
+}
+
 int main(int argc, char**argv)
 {
 	report_prefix_push("selftest");
@@ -49,6 +77,7 @@ int main(int argc, char**argv)
 
 	test_fp();
 	test_pgm_int();
+	test_malloc();
 
 	return report_summary();
 }
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH kvm-unit-tests v3 11/11] s390x: add sieve test
  2018-02-13 16:23 [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support David Hildenbrand
                   ` (9 preceding siblings ...)
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 10/11] s390x: add test for (v)malloc David Hildenbrand
@ 2018-02-13 16:23 ` David Hildenbrand
  2018-02-13 16:26   ` Christian Borntraeger
  2018-02-14 11:52 ` [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support Paolo Bonzini
  11 siblings, 1 reply; 23+ messages in thread
From: David Hildenbrand @ 2018-02-13 16:23 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, Cornelia Huck, Christian Borntraeger,
	David Hildenbrand

Copied from x86/sieve.c. Modifications:
- proper code formatting.
- as setup_vm() is already called, temporarily disable DAT.

The test takes fairly long, especially because we only have 128MB of ram
and allocate 3 times in a row ~100mb of virtual memory.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 s390x/Makefile      |  1 +
 s390x/sieve.c       | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg |  6 ++++++
 3 files changed, 66 insertions(+)
 create mode 100644 s390x/sieve.c

diff --git a/s390x/Makefile b/s390x/Makefile
index d9bef37..2d3336c 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -1,6 +1,7 @@
 tests = $(TEST_DIR)/selftest.elf
 tests += $(TEST_DIR)/intercept.elf
 tests += $(TEST_DIR)/emulator.elf
+tests += $(TEST_DIR)/sieve.elf
 
 all: directories test_cases
 
diff --git a/s390x/sieve.c b/s390x/sieve.c
new file mode 100644
index 0000000..28d4d1e
--- /dev/null
+++ b/s390x/sieve.c
@@ -0,0 +1,59 @@
+/*
+ * Copied from x86/sieve.c
+ */
+
+#include <libcflat.h>
+#include <alloc.h>
+#include <asm/pgtable.h>
+
+int sieve(char* data, int size)
+{
+	int i, j, r = 0;
+
+	for (i = 0; i < size; ++i)
+		data[i] = 1;
+
+	data[0] = data[1] = 0;
+
+	for (i = 2; i < size; ++i)
+		if (data[i]) {
+			++r;
+			for (j = i * 2; j < size; j += i)
+				data[j] = 0;
+		}
+	return r;
+}
+
+void test_sieve(const char *msg, char *data, int size)
+{
+	int r;
+
+	printf("%s:", msg);
+	r = sieve(data, size);
+	printf("%d out of %d\n", r, size);
+}
+
+#define STATIC_SIZE 1000000
+#define VSIZE 100000000
+char static_data[STATIC_SIZE];
+
+int main()
+{
+	void *v;
+	int i;
+
+	printf("starting sieve\n");
+
+	configure_dat(0);
+	test_sieve("static", static_data, STATIC_SIZE);
+	configure_dat(1);
+
+	test_sieve("mapped", static_data, STATIC_SIZE);
+	for (i = 0; i < 3; ++i) {
+		v = malloc(VSIZE);
+		test_sieve("virtual", v, VSIZE);
+		free(v);
+	}
+
+	return 0;
+}
diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
index 1343a19..4a1e469 100644
--- a/s390x/unittests.cfg
+++ b/s390x/unittests.cfg
@@ -28,3 +28,9 @@ file = intercept.elf
 
 [emulator]
 file = emulator.elf
+
+[sieve]
+file = sieve.elf
+groups = selftest
+# can take fairly long even on KVM guests
+timeout = 600
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH kvm-unit-tests v3 11/11] s390x: add sieve test
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 11/11] s390x: add sieve test David Hildenbrand
@ 2018-02-13 16:26   ` Christian Borntraeger
  2018-02-13 16:44     ` Paolo Bonzini
  2018-02-13 17:09     ` David Hildenbrand
  0 siblings, 2 replies; 23+ messages in thread
From: Christian Borntraeger @ 2018-02-13 16:26 UTC (permalink / raw)
  To: David Hildenbrand, kvm
  Cc: Paolo Bonzini, Radim Krčmář, Thomas Huth, Cornelia Huck



On 02/13/2018 05:23 PM, David Hildenbrand wrote:
> Copied from x86/sieve.c. Modifications:
> - proper code formatting.
> - as setup_vm() is already called, temporarily disable DAT.
> 
> The test takes fairly long, especially because we only have 128MB of ram
> and allocate 3 times in a row ~100mb of virtual memory.

Does it make sense to change the memory size in the unittests.cfg file? e.g. via extra_params?


> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  s390x/Makefile      |  1 +
>  s390x/sieve.c       | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  s390x/unittests.cfg |  6 ++++++
>  3 files changed, 66 insertions(+)
>  create mode 100644 s390x/sieve.c
> 
> diff --git a/s390x/Makefile b/s390x/Makefile
> index d9bef37..2d3336c 100644
> --- a/s390x/Makefile
> +++ b/s390x/Makefile
> @@ -1,6 +1,7 @@
>  tests = $(TEST_DIR)/selftest.elf
>  tests += $(TEST_DIR)/intercept.elf
>  tests += $(TEST_DIR)/emulator.elf
> +tests += $(TEST_DIR)/sieve.elf
> 
>  all: directories test_cases
> 
> diff --git a/s390x/sieve.c b/s390x/sieve.c
> new file mode 100644
> index 0000000..28d4d1e
> --- /dev/null
> +++ b/s390x/sieve.c
> @@ -0,0 +1,59 @@
> +/*
> + * Copied from x86/sieve.c
> + */
> +
> +#include <libcflat.h>
> +#include <alloc.h>
> +#include <asm/pgtable.h>
> +
> +int sieve(char* data, int size)
> +{
> +	int i, j, r = 0;
> +
> +	for (i = 0; i < size; ++i)
> +		data[i] = 1;
> +
> +	data[0] = data[1] = 0;
> +
> +	for (i = 2; i < size; ++i)
> +		if (data[i]) {
> +			++r;
> +			for (j = i * 2; j < size; j += i)
> +				data[j] = 0;
> +		}
> +	return r;
> +}
> +
> +void test_sieve(const char *msg, char *data, int size)
> +{
> +	int r;
> +
> +	printf("%s:", msg);
> +	r = sieve(data, size);
> +	printf("%d out of %d\n", r, size);
> +}
> +
> +#define STATIC_SIZE 1000000
> +#define VSIZE 100000000
> +char static_data[STATIC_SIZE];
> +
> +int main()
> +{
> +	void *v;
> +	int i;
> +
> +	printf("starting sieve\n");
> +
> +	configure_dat(0);
> +	test_sieve("static", static_data, STATIC_SIZE);
> +	configure_dat(1);
> +
> +	test_sieve("mapped", static_data, STATIC_SIZE);
> +	for (i = 0; i < 3; ++i) {
> +		v = malloc(VSIZE);
> +		test_sieve("virtual", v, VSIZE);
> +		free(v);
> +	}
> +
> +	return 0;
> +}
> diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
> index 1343a19..4a1e469 100644
> --- a/s390x/unittests.cfg
> +++ b/s390x/unittests.cfg
> @@ -28,3 +28,9 @@ file = intercept.elf
> 
>  [emulator]
>  file = emulator.elf
> +
> +[sieve]
> +file = sieve.elf
> +groups = selftest
> +# can take fairly long even on KVM guests
> +timeout = 600
> 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH kvm-unit-tests v3 11/11] s390x: add sieve test
  2018-02-13 16:26   ` Christian Borntraeger
@ 2018-02-13 16:44     ` Paolo Bonzini
  2018-02-13 17:02       ` David Hildenbrand
  2018-02-13 17:09     ` David Hildenbrand
  1 sibling, 1 reply; 23+ messages in thread
From: Paolo Bonzini @ 2018-02-13 16:44 UTC (permalink / raw)
  To: Christian Borntraeger, David Hildenbrand, kvm
  Cc: Radim Krčmář, Thomas Huth, Cornelia Huck

On 13/02/2018 17:26, Christian Borntraeger wrote:
>> The test takes fairly long, especially because we only have 128MB of ram
>> and allocate 3 times in a row ~100mb of virtual memory.
>
> Does it make sense to change the memory size in the unittests.cfg file? e.g. via extra_params?

The test takes 5 seconds on x86 KVM and about a minute on TCG (lots of
TLB misses).  Maybe it's an s390-specific bug in the test?

Thanks,

Paolo

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH kvm-unit-tests v3 11/11] s390x: add sieve test
  2018-02-13 16:44     ` Paolo Bonzini
@ 2018-02-13 17:02       ` David Hildenbrand
  2018-02-13 17:08         ` David Hildenbrand
  0 siblings, 1 reply; 23+ messages in thread
From: David Hildenbrand @ 2018-02-13 17:02 UTC (permalink / raw)
  To: Paolo Bonzini, Christian Borntraeger, kvm
  Cc: Radim Krčmář, Thomas Huth, Cornelia Huck

On 13.02.2018 17:44, Paolo Bonzini wrote:
> On 13/02/2018 17:26, Christian Borntraeger wrote:
>>> The test takes fairly long, especially because we only have 128MB of ram
>>> and allocate 3 times in a row ~100mb of virtual memory.
>>
>> Does it make sense to change the memory size in the unittests.cfg file? e.g. via extra_params?
> 
> The test takes 5 seconds on x86 KVM and about a minute on TCG (lots of
> TLB misses).  Maybe it's an s390-specific bug in the test?

Under TCG: 1m 6,823s

I have to idea how long it takes under LPAR.  Right now, I only have a
z/VM based system available, so we are already using nested
virtualization (implemented by z/VM). I expect things to be slow :)

Will try to find a LPAR to test with ...

> 
> Thanks,
> 
> Paolo
> 


-- 

Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH kvm-unit-tests v3 11/11] s390x: add sieve test
  2018-02-13 17:02       ` David Hildenbrand
@ 2018-02-13 17:08         ` David Hildenbrand
  2018-02-14 11:51           ` Paolo Bonzini
  0 siblings, 1 reply; 23+ messages in thread
From: David Hildenbrand @ 2018-02-13 17:08 UTC (permalink / raw)
  To: Paolo Bonzini, Christian Borntraeger, kvm
  Cc: Radim Krčmář, Thomas Huth, Cornelia Huck

On 13.02.2018 18:02, David Hildenbrand wrote:
> On 13.02.2018 17:44, Paolo Bonzini wrote:
>> On 13/02/2018 17:26, Christian Borntraeger wrote:
>>>> The test takes fairly long, especially because we only have 128MB of ram
>>>> and allocate 3 times in a row ~100mb of virtual memory.
>>>
>>> Does it make sense to change the memory size in the unittests.cfg file? e.g. via extra_params?
>>
>> The test takes 5 seconds on x86 KVM and about a minute on TCG (lots of
>> TLB misses).  Maybe it's an s390-specific bug in the test?
> 
> Under TCG: 1m 6,823s
> 
> I have to idea how long it takes under LPAR.  Right now, I only have a
> z/VM based system available, so we are already using nested
> virtualization (implemented by z/VM). I expect things to be slow :)
> 
> Will try to find a LPAR to test with ...
> 

LPAR: 0m 6.552s
z/VM: > 6m

So I don't think its a BUG. It's really nested virtualization kicking in.

-- 

Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH kvm-unit-tests v3 11/11] s390x: add sieve test
  2018-02-13 16:26   ` Christian Borntraeger
  2018-02-13 16:44     ` Paolo Bonzini
@ 2018-02-13 17:09     ` David Hildenbrand
  1 sibling, 0 replies; 23+ messages in thread
From: David Hildenbrand @ 2018-02-13 17:09 UTC (permalink / raw)
  To: Christian Borntraeger, kvm
  Cc: Paolo Bonzini, Radim Krčmář, Thomas Huth, Cornelia Huck

On 13.02.2018 17:26, Christian Borntraeger wrote:
> 
> 
> On 02/13/2018 05:23 PM, David Hildenbrand wrote:
>> Copied from x86/sieve.c. Modifications:
>> - proper code formatting.
>> - as setup_vm() is already called, temporarily disable DAT.
>>
>> The test takes fairly long, especially because we only have 128MB of ram
>> and allocate 3 times in a row ~100mb of virtual memory.
> 
> Does it make sense to change the memory size in the unittests.cfg file? e.g. via extra_params?

As the long runtime only seems to be a problem when running nested under
z/VM, I don't think this should be a problem.

-- 

Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH kvm-unit-tests v3 11/11] s390x: add sieve test
  2018-02-13 17:08         ` David Hildenbrand
@ 2018-02-14 11:51           ` Paolo Bonzini
  2018-02-14 12:56             ` David Hildenbrand
  0 siblings, 1 reply; 23+ messages in thread
From: Paolo Bonzini @ 2018-02-14 11:51 UTC (permalink / raw)
  To: David Hildenbrand, Christian Borntraeger, kvm
  Cc: Radim Krčmář, Thomas Huth, Cornelia Huck

On 13/02/2018 18:08, David Hildenbrand wrote:
> On 13.02.2018 18:02, David Hildenbrand wrote:
>> On 13.02.2018 17:44, Paolo Bonzini wrote:
>>> On 13/02/2018 17:26, Christian Borntraeger wrote:
>>>>> The test takes fairly long, especially because we only have 128MB of ram
>>>>> and allocate 3 times in a row ~100mb of virtual memory.
>>>>
>>>> Does it make sense to change the memory size in the unittests.cfg file? e.g. via extra_params?
>>>
>>> The test takes 5 seconds on x86 KVM and about a minute on TCG (lots of
>>> TLB misses).  Maybe it's an s390-specific bug in the test?
>>
>> Under TCG: 1m 6,823s
>>
>> I have to idea how long it takes under LPAR.  Right now, I only have a
>> z/VM based system available, so we are already using nested
>> virtualization (implemented by z/VM). I expect things to be slow :)
>>
>> Will try to find a LPAR to test with ...
>>
> 
> LPAR: 0m 6.552s
> z/VM: > 6m
> 
> So I don't think its a BUG. It's really nested virtualization kicking in.

Whoa.  How does KVM-on-KVM-on-LPAR fare?

I'll change the comment to

# can take fairly long when KVM is nested inside z/VM

Thanks,

Paolo

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support
  2018-02-13 16:23 [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support David Hildenbrand
                   ` (10 preceding siblings ...)
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 11/11] s390x: add sieve test David Hildenbrand
@ 2018-02-14 11:52 ` Paolo Bonzini
  11 siblings, 0 replies; 23+ messages in thread
From: Paolo Bonzini @ 2018-02-14 11:52 UTC (permalink / raw)
  To: David Hildenbrand, kvm
  Cc: Radim Krčmář,
	Thomas Huth, Cornelia Huck, Christian Borntraeger

On 13/02/2018 17:23, David Hildenbrand wrote:
> This series implements
> - detection of installed physical memory
> - setup of the physical allocator
> - setup of the MMU / page tables / DAT
> - setup of the virtual allocator
> 
> The CPU now runs with DAT enabled. I added a small test to make sure
> malloc() indeed works and uses virtual adresses. Also, the sieve test
> is added.
> 
> While at it, fix the TEST BLOCK test on newer compilers.
> 
> Tested with upsteam QEMU TCG and KVM. However, to pass under TCG a
> fix is necessary ("[PATCH v1] s390x/tcg: fix disabling/enabling DAT").
> 
> v2 -> v3:
> - split up configure_dat() to make use of two functions extract_psw_mask()
>   and load_psw_mask(), it is now much cleaner and we might need these
>   functions in the future.
> - Minor cleanups / comment fixes

Applied, thanks.  Happy that the arm/x86 code generalized decently to s390!

Paolo

> 
> 
> David Hildenbrand (11):
>   s390x: fix TEST BLOCK tests
>   s390x: use highest addresses for PGM_ADDRESSING errors
>   s390x: set initital stack pointer to stackptr, not stacktop
>   s390x: add missing sclp definitions from QEMU
>   s390x: rename sclp_setup() to sclp_ascii_setup()
>   s390x: detect installed memory
>   s390x: initialize the physical allocator
>   s390x: add vmalloc support
>   s390x: enable DAT in PGM interrupt handler
>   s390x: add test for (v)malloc
>   s390x: add sieve test
> 
>  lib/s390x/asm/arch_def.h  |  58 ++++++++++++
>  lib/s390x/asm/interrupt.h |   1 +
>  lib/s390x/asm/page.h      |  24 +++++
>  lib/s390x/asm/pgtable.h   | 224 ++++++++++++++++++++++++++++++++++++++++++++++
>  lib/s390x/interrupt.c     |  11 +++
>  lib/s390x/io.c            |   3 +-
>  lib/s390x/mmu.c           | 108 ++++++++++++++++++++++
>  lib/s390x/sclp-ascii.c    |   6 +-
>  lib/s390x/sclp.c          |  72 +++++++++++++++
>  lib/s390x/sclp.h          | 112 ++++++++++++++++++++++-
>  s390x/Makefile            |   7 ++
>  s390x/cstart64.S          |   2 +-
>  s390x/intercept.c         |  14 +--
>  s390x/selftest.c          |  31 ++++++-
>  s390x/sieve.c             |  59 ++++++++++++
>  s390x/unittests.cfg       |   6 ++
>  16 files changed, 723 insertions(+), 15 deletions(-)
>  create mode 100644 lib/s390x/asm/pgtable.h
>  create mode 100644 lib/s390x/mmu.c
>  create mode 100644 lib/s390x/sclp.c
>  create mode 100644 s390x/sieve.c
> 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH kvm-unit-tests v3 07/11] s390x: initialize the physical allocator
  2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 07/11] s390x: initialize the physical allocator David Hildenbrand
@ 2018-02-14 12:05   ` Thomas Huth
  2018-02-14 12:22     ` David Hildenbrand
  0 siblings, 1 reply; 23+ messages in thread
From: Thomas Huth @ 2018-02-14 12:05 UTC (permalink / raw)
  To: David Hildenbrand, kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Cornelia Huck, Christian Borntraeger

On 13.02.2018 17:23, David Hildenbrand wrote:
> We now have the range of free memory, let's initialize the physical
> allocator. It is now possible to use use malloc and memalign, based on the
> early-ops. alloc_pages() cannot be used yet (as it has to be initialized
> via free_pages() - e.g. via setup_vm() - first)
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  lib/s390x/sclp.c | 12 ++++++++++++
>  s390x/Makefile   |  3 +++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c
> index 199405c..c7471b1 100644
> --- a/lib/s390x/sclp.c
> +++ b/lib/s390x/sclp.c
> @@ -15,11 +15,21 @@
>  #include <asm/arch_def.h>
>  #include <asm/interrupt.h>
>  #include "sclp.h"
> +#include <alloc_phys.h>
> +
> +extern unsigned long stacktop;
>  
>  static uint64_t storage_increment_size;
>  static uint64_t max_ram_size;
>  static uint64_t ram_size;
>  
> +static void mem_init(phys_addr_t mem_end)
> +{
> +	phys_addr_t freemem_start = (phys_addr_t)&stacktop & PAGE_MASK;

Should be ok since stacktop should be aligned. Otherwise this should
maybe better be (stacktop + PAGE_SIZE - 1) & PAGE_MASK ?

 Thomas

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH kvm-unit-tests v3 07/11] s390x: initialize the physical allocator
  2018-02-14 12:05   ` Thomas Huth
@ 2018-02-14 12:22     ` David Hildenbrand
  0 siblings, 0 replies; 23+ messages in thread
From: David Hildenbrand @ 2018-02-14 12:22 UTC (permalink / raw)
  To: Thomas Huth, kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Cornelia Huck, Christian Borntraeger

On 14.02.2018 13:05, Thomas Huth wrote:
> On 13.02.2018 17:23, David Hildenbrand wrote:
>> We now have the range of free memory, let's initialize the physical
>> allocator. It is now possible to use use malloc and memalign, based on the
>> early-ops. alloc_pages() cannot be used yet (as it has to be initialized
>> via free_pages() - e.g. via setup_vm() - first)
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>>  lib/s390x/sclp.c | 12 ++++++++++++
>>  s390x/Makefile   |  3 +++
>>  2 files changed, 15 insertions(+)
>>
>> diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c
>> index 199405c..c7471b1 100644
>> --- a/lib/s390x/sclp.c
>> +++ b/lib/s390x/sclp.c
>> @@ -15,11 +15,21 @@
>>  #include <asm/arch_def.h>
>>  #include <asm/interrupt.h>
>>  #include "sclp.h"
>> +#include <alloc_phys.h>
>> +
>> +extern unsigned long stacktop;
>>  
>>  static uint64_t storage_increment_size;
>>  static uint64_t max_ram_size;
>>  static uint64_t ram_size;
>>  
>> +static void mem_init(phys_addr_t mem_end)
>> +{
>> +	phys_addr_t freemem_start = (phys_addr_t)&stacktop & PAGE_MASK;
> 
> Should be ok since stacktop should be aligned. Otherwise this should
> maybe better be (stacktop + PAGE_SIZE - 1) & PAGE_MASK ?
> 

Either that or drop the "& PAGE_MASK". But guess this doesn't really
make a difference right now. Thanks!

>  Thomas
> 


-- 

Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH kvm-unit-tests v3 11/11] s390x: add sieve test
  2018-02-14 11:51           ` Paolo Bonzini
@ 2018-02-14 12:56             ` David Hildenbrand
  2018-02-14 13:15               ` David Hildenbrand
  0 siblings, 1 reply; 23+ messages in thread
From: David Hildenbrand @ 2018-02-14 12:56 UTC (permalink / raw)
  To: Paolo Bonzini, Christian Borntraeger, kvm
  Cc: Radim Krčmář, Thomas Huth, Cornelia Huck

On 14.02.2018 12:51, Paolo Bonzini wrote:
> On 13/02/2018 18:08, David Hildenbrand wrote:
>> On 13.02.2018 18:02, David Hildenbrand wrote:
>>> On 13.02.2018 17:44, Paolo Bonzini wrote:
>>>> On 13/02/2018 17:26, Christian Borntraeger wrote:
>>>>>> The test takes fairly long, especially because we only have 128MB of ram
>>>>>> and allocate 3 times in a row ~100mb of virtual memory.
>>>>>
>>>>> Does it make sense to change the memory size in the unittests.cfg file? e.g. via extra_params?
>>>>
>>>> The test takes 5 seconds on x86 KVM and about a minute on TCG (lots of
>>>> TLB misses).  Maybe it's an s390-specific bug in the test?
>>>
>>> Under TCG: 1m 6,823s
>>>
>>> I have to idea how long it takes under LPAR.  Right now, I only have a
>>> z/VM based system available, so we are already using nested
>>> virtualization (implemented by z/VM). I expect things to be slow :)
>>>
>>> Will try to find a LPAR to test with ...
>>>
>>
>> LPAR: 0m 6.552s
>> z/VM: > 6m
>>
>> So I don't think its a BUG. It's really nested virtualization kicking in.
> 
> Whoa.  How does KVM-on-KVM-on-LPAR fare?

We do a lot of IPTE calls, which flush the TLB on all CPUs.

But I think this could also be because the z/VM machine I am running on
is simply overloaded. But of course also because our nested virt
implementation in KVM is better ;)

Just tried nested under KVM (KVM-on-KVM-on-LPAR):

real    0m 9.411s

> 
> I'll change the comment to
> 
> # can take fairly long when KVM is nested inside z/VM
> 
> Thanks,
> 
> Paolo
> 


-- 

Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH kvm-unit-tests v3 11/11] s390x: add sieve test
  2018-02-14 12:56             ` David Hildenbrand
@ 2018-02-14 13:15               ` David Hildenbrand
  0 siblings, 0 replies; 23+ messages in thread
From: David Hildenbrand @ 2018-02-14 13:15 UTC (permalink / raw)
  To: Paolo Bonzini, Christian Borntraeger, kvm
  Cc: Radim Krčmář, Thomas Huth, Cornelia Huck

On 14.02.2018 13:56, David Hildenbrand wrote:
> On 14.02.2018 12:51, Paolo Bonzini wrote:
>> On 13/02/2018 18:08, David Hildenbrand wrote:
>>> On 13.02.2018 18:02, David Hildenbrand wrote:
>>>> On 13.02.2018 17:44, Paolo Bonzini wrote:
>>>>> On 13/02/2018 17:26, Christian Borntraeger wrote:
>>>>>>> The test takes fairly long, especially because we only have 128MB of ram
>>>>>>> and allocate 3 times in a row ~100mb of virtual memory.
>>>>>>
>>>>>> Does it make sense to change the memory size in the unittests.cfg file? e.g. via extra_params?
>>>>>
>>>>> The test takes 5 seconds on x86 KVM and about a minute on TCG (lots of
>>>>> TLB misses).  Maybe it's an s390-specific bug in the test?
>>>>
>>>> Under TCG: 1m 6,823s
>>>>
>>>> I have to idea how long it takes under LPAR.  Right now, I only have a
>>>> z/VM based system available, so we are already using nested
>>>> virtualization (implemented by z/VM). I expect things to be slow :)
>>>>
>>>> Will try to find a LPAR to test with ...
>>>>
>>>
>>> LPAR: 0m 6.552s
>>> z/VM: > 6m
>>>
>>> So I don't think its a BUG. It's really nested virtualization kicking in.
>>
>> Whoa.  How does KVM-on-KVM-on-LPAR fare?
> 
> We do a lot of IPTE calls, which flush the TLB on all CPUs.
> 
> But I think this could also be because the z/VM machine I am running on
> is simply overloaded. But of course also because our nested virt
> implementation in KVM is better ;)

Just double checked, as we are not reusing virtual addresses, we are not
issuing any IPTE instructions right now. So also no TLB flushes. This
makes it very strange why z/VM performs (for me reproducible) that bad.

> 
> Just tried nested under KVM (KVM-on-KVM-on-LPAR):
> 
> real    0m 9.411s
> 
>>
>> I'll change the comment to
>>
>> # can take fairly long when KVM is nested inside z/VM
>>
>> Thanks,
>>
>> Paolo
>>
> 
> 


-- 

Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2018-02-14 13:16 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-13 16:23 [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 01/11] s390x: fix TEST BLOCK tests David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 02/11] s390x: use highest addresses for PGM_ADDRESSING errors David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 03/11] s390x: set initital stack pointer to stackptr, not stacktop David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 04/11] s390x: add missing sclp definitions from QEMU David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 05/11] s390x: rename sclp_setup() to sclp_ascii_setup() David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 06/11] s390x: detect installed memory David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 07/11] s390x: initialize the physical allocator David Hildenbrand
2018-02-14 12:05   ` Thomas Huth
2018-02-14 12:22     ` David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 08/11] s390x: add vmalloc support David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 09/11] s390x: enable DAT in PGM interrupt handler David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 10/11] s390x: add test for (v)malloc David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 11/11] s390x: add sieve test David Hildenbrand
2018-02-13 16:26   ` Christian Borntraeger
2018-02-13 16:44     ` Paolo Bonzini
2018-02-13 17:02       ` David Hildenbrand
2018-02-13 17:08         ` David Hildenbrand
2018-02-14 11:51           ` Paolo Bonzini
2018-02-14 12:56             ` David Hildenbrand
2018-02-14 13:15               ` David Hildenbrand
2018-02-13 17:09     ` David Hildenbrand
2018-02-14 11:52 ` [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.