s390x: vmalloc support
v2 cover s390x: vmalloc support
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.
While at it, fix the TEST BLOCK test on newer compilers.
Tested with upsteam QEMU TCG and KVM. However, to pass under TCG a couple of fixes are necessary (e.g. disabling DAT does not work). Will post them shortly.
v1 -> v2:
- "s390x: use highest addresses for PGM_ADDRESSING errors"
- UL -> L
- "s390x: set initital stack pointer to stackptr, not stacktop"
- added
- "s390x: add missing sclp definitions from QEMU"
- fix copyright statement
- "s390x: rename sclp_setup() to sclp_ascii_setup()"
- also expose the buffer
- "s390x: detect installed memory"
- use tprot correctly (we have to test for exceptions, too)
- fix tprot address in asm (r vs Q)
- "s390x: initialize the physical allocator"
- move freemem_start into mem_init()
- get rid of the "+ PAGE_SIZE" hack
- "s390x: add vmalloc support"
- not adding always_inline, as functions in headers are always inlined (and always_inline will not compile)
- configure_dat():
- move to mmu.c
- use labels 0/1 and reference by 0f/1f, otherwise we might have duplicate labels and the compiler complains when inlining
- use two local variables, fix store
- don't enable DAT in PGM interrupt as default
- "s390x: enable DAT in PGM interrupt handler"
- added
- "s390x: add test for (v)malloc"
- use a mb() and read values to check validity
- test only for the highest bits
- disable DAT to test if we actually have a virtual address
- "s390x: add sieve test"
- copied it (unfortunately no copyright statement?)
- minor styl corrections + temporarily disable DAT
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 | 31 +++++++ 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 | 125 ++++++++++++++++++++++++++ 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, 713 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
Signature · 1 line
2.14.3
PATCH v2 1/11 s390x: fix TEST BLOCK tests
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.
--- s390x/intercept.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
s390x/intercept.c +3 -3
@@ -139,7 +139,7 @@ static void test_testblock(void) asmvolatile (" 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 (); - asmvolatile (" tb %0 " : :"r" (4096 )); + asmvolatile (" .insn rre,0xb22c0000,0,%0\n" : :"r" (4096 ));low_prot_disable ();check_pgm_int_code (PGM_INT_CODE_PROTECTION );expect_pgm_int (); - asmvolatile (" tb %0 " : :"r" (-4096 )); + asmvolatile (" .insn rre,0xb22c0000,0,%0\n" : :"r" (-4096 ));check_pgm_int_code (PGM_INT_CODE_ADDRESSING ); }
Signature · 1 line
2.14.3
PATCH v2 2/11 s390x: use highest addresses for PGM_ADDRESSING errors
In reply to David HildenbrandWithout the UL, we get 32 bit addresses, resulting in different memory addresses. This is necessary for enabling the MMU.
--- s390x/intercept.c | 10 +++++----- s390x/selftest.c | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-)
s390x/intercept.c +5 -5
@@ -46,7 +46,7 @@ static void test_stpx(void)check_pgm_int_code (PGM_INT_CODE_SPECIFICATION );expect_pgm_int (); - asmvolatile (" stpx 0(%0) " : :"r" (-8 )); + asmvolatile (" 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 (); - asmvolatile (" spx 0(%0) " : :"r" (-8 )); + asmvolatile (" 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 (); - asmvolatile ("stap 0(%0)\n" : :"r" (-8 )); + asmvolatile ("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 (); - asmvolatile ("stidp 0(%0)\n" : :"r" (-8 )); + asmvolatile ("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 (); - asmvolatile (" .insn rre,0xb22c0000,0,%0\n" : :"r" (-4096 )); + asmvolatile (" .insn rre,0xb22c0000,0,%0\n" : :"r" (-4096L ));check_pgm_int_code (PGM_INT_CODE_ADDRESSING ); }
s390x/selftest.c +1 -1
@@ -33,7 +33,7 @@ static void test_pgm_int(void)check_pgm_int_code (PGM_INT_CODE_OPERATION );expect_pgm_int (); - asmvolatile (" stg %0,0(%0)\n" : :"r" (-1 )); + asmvolatile (" stg %0,0(%0)\n" : :"r" (-1L ));check_pgm_int_code (PGM_INT_CODE_ADDRESSING ); }
Signature · 1 line
2.14.3
PATCH v2 3/11 s390x: set initital stack pointer to stackptr, not stacktop
In reply to David Hildenbrand... was wrong from the beginning and remained unnoticed until we started playing with dynamic memory allocation.
--- s390x/cstart64.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/cstart64.S +1 -1
@@ -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)
Signature · 1 line
2.14.3
PATCH v2 4/11 s390x: add missing sclp definitions from QEMU
In reply to David HildenbrandCopy 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.
--- lib/s390x/sclp.h | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-)
lib/s390x/sclp.h +106 -1
@@ -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 <[email protected]> * +* and based on the file include/hw/s390x/sclp.h from QEMU +* Copyright IBM, Corp. 2012 +* Author: Christian Borntraeger <[email protected]> +* * 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];
Signature · 1 line
2.14.3
PATCH v2 5/11 s390x: rename sclp_setup() to sclp_ascii_setup()
In reply to David HildenbrandWe'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).
--- lib/s390x/io.c | 2 +- lib/s390x/sclp-ascii.c | 6 +++--- lib/s390x/sclp.h | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-)
lib/s390x/io.c +1 -1
@@ -42,7 +42,7 @@ void setup() {setup_args_progname (ipl_args);setup_facilities (); -sclp_setup (); +sclp_ascii_setup (); }void exit (int code)
lib/s390x/sclp-ascii.c +3 -3
@@ -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 (); }
lib/s390x/sclp.h +3 -1
@@ -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 */
Signature · 1 line
2.14.3
PATCH v2 7/11 s390x: initialize the physical allocator
In reply to David HildenbrandWe now have the range of free memory, let's initialize the physical allocator. It is now possible to use alloc_page()/alloc_pages().
--- lib/s390x/sclp.c | 12 ++++++++++++ s390x/Makefile | 3 +++ 2 files changed, 15 insertions(+)
lib/s390x/sclp.c +12 -0
@@ -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); }
s390x/Makefile +3 -0
@@ -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
Signature · 1 line
2.14.3
PATCH v2 6/11 s390x: detect installed memory
In reply to David HildenbrandUnfortunately, 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.
--- 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
lib/s390x/asm/arch_def.h +12 -0
@@ -151,4 +151,16 @@ struct cpuid { uint64_t reserved : 15; }; +static inline int tprot (unsigned long addr) +{ +int cc; + + asmvolatile ( +" tprot 0(%1),0\n" +" ipm %0\n" +" srl %0,28\n" + :"=d" (cc) :"a" (addr) :"cc" ); +return cc; +} +#endif
lib/s390x/asm/interrupt.h +1 -0
@@ -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 */
lib/s390x/interrupt.c +11 -0
@@ -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 ();
lib/s390x/io.c +1 -0
@@ -43,6 +43,7 @@ void setup()setup_args_progname (ipl_args);setup_facilities ();sclp_ascii_setup (); +sclp_memory_setup (); }void exit (int code)
lib/s390x/sclp.c new file +58 -0
58 lines not on this page · raw message
lib/s390x/sclp.h +1 -0
@@ -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 */
s390x/Makefile +1 -0
@@ -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
Signature · 1 line
2.14.3
PATCH v2 8/11 s390x: add vmalloc support
In reply to David HildenbrandTo 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.
--- lib/s390x/asm/arch_def.h | 17 ++++ lib/s390x/asm/page.h | 24 +++++ lib/s390x/asm/pgtable.h | 224 +++++++++++++++++++++++++++++++++++++++++++++++ lib/s390x/mmu.c | 121 +++++++++++++++++++++++++ lib/s390x/sclp.c | 2 + s390x/Makefile | 2 + 6 files changed, 390 insertions(+) create mode 100644 lib/s390x/asm/pgtable.h create mode 100644 lib/s390x/mmu.c
lib/s390x/asm/arch_def.h +17 -0
@@ -163,4 +163,21 @@ static inline int tprot(unsigned long addr) return cc; } +static inline void lctlg (int cr,uint64_t value) +{ + asmvolatile ( +" lctlg %1,%1,%0\n" + : :"Q" (value),"i" (cr)); +} + +static inline uint64_t stctg (int cr) +{ +uint64_t value; + + asmvolatile ( +" stctg %1,%1,%0\n" + :"=Q" (value) :"i" (cr) :"memory" ); +return value; +} +#endif
lib/s390x/asm/page.h +24 -0
@@ -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
lib/s390x/asm/pgtable.h new file +224 -0
224 lines not on this page · raw message
lib/s390x/mmu.c new file +121 -0
121 lines not on this page · raw message
lib/s390x/sclp.c +2 -0
@@ -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 )
s390x/Makefile +2 -0
@@ -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
Signature · 1 line
2.14.3
PATCH v2 9/11 s390x: enable DAT in PGM interrupt handler
In reply to David HildenbrandConfigure it in setup_vm().
--- lib/s390x/asm/arch_def.h | 2 ++ lib/s390x/mmu.c | 4 ++++ 2 files changed, 6 insertions(+)
lib/s390x/asm/arch_def.h +2 -0
@@ -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 */
lib/s390x/mmu.c +4 -0
@@ -47,6 +47,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 ;
@@ -56,6 +57,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)
Signature · 1 line
2.14.3
PATCH v2 10/11 s390x: add test for (v)malloc
In reply to David HildenbrandLet's test if basic allocation works and we get virtual addresses.
--- s390x/selftest.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
s390x/selftest.c +29 -0
@@ -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 (); }
Signature · 1 line
2.14.3
PATCH v2 11/11 s390x: add sieve test
In reply to David HildenbrandCopied 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.
--- s390x/Makefile | 1 + s390x/sieve.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 6 ++++++ 3 files changed, 66 insertions(+) create mode 100644 s390x/sieve.c
s390x/Makefile +1 -0
@@ -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
s390x/sieve.c new file +59 -0
59 lines not on this page · raw message
s390x/unittests.cfg +6 -0
@@ -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
Signature · 1 line
2.14.3
Re: [PATCH kvm-unit-tests v2 03/11] s390x: set initital stack pointer to stackptr, not stacktop
In reply to David HildenbrandQuoted 14 lines · David Hildenbrand
... was wrong from the beginning and remained unnoticed until we started playing with dynamic memory allocation.
Signed-off-by David Hildenbrand <[email protected]>--- s390x/cstart64.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)s390x/cstart64.S +0
-0
s390x/cstart64.S line 24
Quoted 8 lines
s390x/cstart64.S +1
-1@@ -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)
Re: [PATCH kvm-unit-tests v2 07/11] s390x: initialize the physical allocator
In reply to David HildenbrandQuoted 2 lines · David Hildenbrand
We now have the range of free memory, let's initialize the physical allocator. It is now possible to use alloc_page()/alloc_pages().
Commit message isn't quite right. After this patch it's possible to use malloc and memalign, based on the early-ops, but alloc_pages() requires the freelist to be initialized first by free_pages(), done by setup_vm().
Actually, since we have four states of memory management setup, then I think we either need three setup calls:
state 1: no setup done, no call
state 2: phys-alloc is set up by the phys_alloc_init() call state 3: alloc_page() is set up, need call that allocates chunk with the
phys-allocator for free_pages()
(Instead of a chunk, all memory could be given, but then either a
new set of early-ops should be provided that are based on alloc_page(), or all early memory allocations must use alloc_page())
state 4: virtual memory is set up by the setup_vm() call
Or, simply remove state 2 and its code and alloc-ops, changing all early allocations to use alloc_page(). If each arch provides an mmu_enabled() call, then the alloc_ops->memalign call in memalign could be replaced with
if (mmu_enabled())
vm_memalign(...)
else
/* fallback to alloc_pages() */I probably should have written all this in a separate thread, because I wouldn't want to hold this series up on a rework of the general memory management framework. But, anyway, thoughts on that? Paolo?
Thanks,
drew
Quoted 57 lines
Signed-off-by David Hildenbrand <[email protected]>--- lib/s390x/sclp.c | 12 ++++++++++++ s390x/Makefile | 3 +++ 2 files changed, 15 insertions(+)lib/s390x/sclp.c +12
-0@@ -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); }s390x/Makefile +3
-0@@ -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.oSignature · 1 line
2.14.3
Re: [PATCH kvm-unit-tests v2 07/11] s390x: initialize the physical allocator
Quoted 8 lines · Andrew Jones
Quoted 2 lines · David Hildenbrand
We now have the range of free memory, let's initialize the physical allocator. It is now possible to use alloc_page()/alloc_pages().
Commit message isn't quite right. After this patch it's possible to use malloc and memalign, based on the early-ops, but
alloc_pages()requires the freelist to be initialized first byfree_pages(), done bysetup_vm().
That's interesting, as I am using alloc_pages() during setup_vm() I haven't noticed it.
Quoted 13 lines
Actually, since we have four states of memory management setup, then I think we either need three setup calls:
state 1: no setup done, no call
state 2: phys-alloc is set up by thephys_alloc_init()call state 3:alloc_page()is set up, need call that allocates chunk with the
phys-allocator forfree_pages()(Instead of a chunk, all memory could be given, but then either a
new set of early-ops should be provided that are based onalloc_page(), or all early memory allocations must usealloc_page())
Quoted 6 lines
state 4: virtual memory is set up by the
setup_vm()callOr, simply remove state 2 and its code and alloc-ops, changing all early allocations to use
alloc_page(). If each arch provides anmmu_enabled()call, then thealloc_ops->memaligncall in memalign could be replaced with
I think I'd prefer that. Unless somebody needs the flexibility of this extra state.
But let's hear what the others say.
Quoted 12 lines
if (
mmu_enabled())vm_memalign(...) else /* fallback to alloc_pages() */I probably should have written all this in a separate thread, because I wouldn't want to hold this series up on a rework of the general memory management framework. But, anyway, thoughts on that? Paolo?> Thanks,
drew
Signature · 3 lines
Thanks, David / dhildenb
Paolo Bonzini
maintainerRe: [PATCH kvm-unit-tests v2 07/11] s390x: initialize the physical allocator
Quoted 7 lines · David Hildenbrand
Quoted 4 lines
Commit message isn't quite right. After this patch it's possible to use malloc and memalign, based on the early-ops, but
alloc_pages()requires the freelist to be initialized first byfree_pages(), done bysetup_vm().That's interesting, as I am using
alloc_pages()duringsetup_vm()I haven't noticed it.
You're using it during setup_mmu, not setup_vm.
Paolo
Re: [PATCH kvm-unit-tests v2 07/11] s390x: initialize the physical allocator
Quoted 10 lines · Paolo Bonzini
Quoted 7 lines · David Hildenbrand
Quoted 4 lines
Commit message isn't quite right. After this patch it's possible to use malloc and memalign, based on the early-ops, but
alloc_pages()requires the freelist to be initialized first byfree_pages(), done bysetup_vm().That's interesting, as I am using
alloc_pages()duringsetup_vm()I haven't noticed it.You're using it during
setup_mmu, notsetup_vm.
... which is only called from setup_vm().
Quoted 3 lines
Paolo
Signature · 3 lines
Thanks, David / dhildenb
Paolo Bonzini
maintainerRe: [PATCH kvm-unit-tests v2 07/11] s390x: initialize the physical allocator
In reply to Andrew JonesQuoted 16 lines · Andrew Jones
state 2: phys-alloc is set up by the
phys_alloc_init()callstate 3:
alloc_page()is set up, need call that allocates chunk with the
phys-allocator forfree_pages()(Instead of a chunk, all memory could be given, but then either a
new set of early-ops should be provided that are based onalloc_page(), or all early memory allocations must usealloc_page())state 4: virtual memory is set up by the
setup_vm()callOr, simply remove state 2 and its code and alloc-ops, changing all early allocations to use
alloc_page(). If each arch provides anmmu_enabled()call, then thealloc_ops->memaligncall in memalign could be replaced with
Quoted 8 lines
if (
mmu_enabled())vm_memalign(...) else /* fallback to alloc_pages() */I probably should have written all this in a separate thread, because I wouldn't want to hold this series up on a rework of the general memory management framework. But, anyway, thoughts on that? Paolo?
State 3 should only exist in setup_mmu, so indeed the commit message here is not accurate. setup_vm does the transition from phys_alloc to page_alloc before calling setup_mmu, exactly because setup_mmu already needs to allocate pages:
phys_alloc_get_unused(&base, &top);
base = (base + PAGE_SIZE - 1) & -PAGE_SIZE;
top = top & -PAGE_SIZE;
free_pages(phys_to_virt(base), top - base);
page_root = setup_mmu(top);
alloc_ops = &vmalloc_ops;The reason for state 2 to exist is that right now on x86 it is optional to use the MMU. You could use page-granularity allocation, but that would be a waste of memory if we switch to a GTest-like API that needs to dynamically allocate memory.
However, maybe it would make sense to make it internal just like state
3. That would mean enabling the MMU directly where we now call phys_alloc_init. This is independent of course of this s390 series.
Paolo
Re: [PATCH kvm-unit-tests v2 07/11] s390x: initialize the physical allocator
In reply to Andrew JonesQuoted 3 lines · Andrew Jones
Quoted 2 lines · David Hildenbrand
We now have the range of free memory, let's initialize the physical allocator. It is now possible to use alloc_page()/alloc_pages().
Will rephrase to:
"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)."
Thanks!
Quoted 36 lines
Commit message isn't quite right. After this patch it's possible to use malloc and memalign, based on the early-ops, but
alloc_pages()requires the freelist to be initialized first byfree_pages(), done bysetup_vm().Actually, since we have four states of memory management setup, then I think we either need three setup calls:
state 1: no setup done, no call
state 2: phys-alloc is set up by thephys_alloc_init()call state 3:alloc_page()is set up, need call that allocates chunk with the
phys-allocator forfree_pages()(Instead of a chunk, all memory could be given, but then either a
new set of early-ops should be provided that are based onalloc_page(), or all early memory allocations must usealloc_page())state 4: virtual memory is set up by the
setup_vm()callOr, simply remove state 2 and its code and alloc-ops, changing all early allocations to use
alloc_page(). If each arch provides anmmu_enabled()call, then thealloc_ops->memaligncall in memalign could be replaced withif (
mmu_enabled())vm_memalign(...) else /* fallback to alloc_pages() */I probably should have written all this in a separate thread, because I wouldn't want to hold this series up on a rework of the general memory management framework. But, anyway, thoughts on that? Paolo?
Thanks,
drew
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH kvm-unit-tests v2 04/11] s390x: add missing sclp definitions from QEMU
In reply to David HildenbrandQuoted 10 lines · 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_PACKEDaccordingly and copy the copyright statement.Signed-off-by David Hildenbrand <[email protected]>--- lib/s390x/sclp.h | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-)
Re: [PATCH kvm-unit-tests v2 07/11] s390x: initialize the physical allocator
In reply to Paolo BonziniQuoted 38 lines · Paolo Bonzini
Quoted 16 lines · Andrew Jones
state 2: phys-alloc is set up by the
phys_alloc_init()callstate 3:
alloc_page()is set up, need call that allocates chunk with the
phys-allocator forfree_pages()(Instead of a chunk, all memory could be given, but then either a
new set of early-ops should be provided that are based onalloc_page(), or all early memory allocations must usealloc_page())state 4: virtual memory is set up by the
setup_vm()callOr, simply remove state 2 and its code and alloc-ops, changing all early allocations to use
alloc_page(). If each arch provides anmmu_enabled()call, then thealloc_ops->memaligncall in memalign could be replaced withQuoted 8 lines
if (
mmu_enabled())vm_memalign(...) else /* fallback to alloc_pages() */I probably should have written all this in a separate thread, because I wouldn't want to hold this series up on a rework of the general memory management framework. But, anyway, thoughts on that? Paolo?
State 3 should only exist in
setup_mmu, so indeed the commit message here is not accurate.setup_vmdoes the transition fromphys_alloctopage_allocbefore callingsetup_mmu, exactly becausesetup_mmualready needs to allocate pages:phys_alloc_get_unused(&base, &top); base = (base + PAGE_SIZE - 1) & -PAGE_SIZE; top = top & -PAGE_SIZE; free_pages(phys_to_virt(base), top - base); page_root = setup_mmu(top); alloc_ops = &vmalloc_ops;
Quoted 9 lines
The reason for state 2 to exist is that right now on x86 it is optional to use the MMU. You could use page-granularity allocation, but that would be a waste of memory if we switch to a GTest-like API that needs to dynamically allocate memory.
However, maybe it would make sense to make it internal just like state
3. That would mean enabling the MMU directly where we now callphys_alloc_init. This is independent of course of this s390 series.
I'm still looking at making the MMU enablement of ARM optional, and, like you say, it already is optional for x86, so I don't think we'd want to reduce the flexibility by making more setup internal. If we need the phys-allocator, then I think introducing an external setup call for state 3, allowing alloc_page() to be used before (without) the MMU being enabled, probably makes the most sense.
Thanks,
drew
Re: [PATCH kvm-unit-tests v2 06/11] s390x: detect installed memory
In reply to David HildenbrandQuoted 5 lines · 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.
Signed-off-by David Hildenbrand <[email protected]>
Quoted 10 lines
--- 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
Re: [PATCH kvm-unit-tests v2 10/11] s390x: add test for (v)malloc
In reply to David HildenbrandQuoted 6 lines · David Hildenbrand
Let's test if basic allocation works and we get virtual addresses.
Signed-off-by David Hildenbrand <[email protected]>--- s390x/selftest.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)