s390x: rework guest memory access
cover s390x: rework guest memory access
Cornelia, Alex, Christian,
this patches are a rework of guest memory access to allow access to guest logical address space.
Frank Blaschka (1):
s390x/pci: Rework memory access in zpci instruction
Thomas Huth (24):
s390x/mmu: Move mmu_translate() and friends to separate file s390x/mmu: Fix the check for the real-space designation bit s390x/mmu: Fix the handling of the table levels s390x/mmu: Check table length and offset fields s390x/mmu: Skip exceptions properly when translating addresses for
debug
s390x/mmu: Fix translation exception code in lowcore s390x/mmu: Fix exception types when checking the ASCEs s390x/mmu: Fix the exception codes for illegal table entries s390x/mmu: Add support for read-only regions
s390x/mmu: Renaming related to the ASCE confusion s390x/mmu: Check bit 52 in page table entry
s390x/mmu: Clean up mmu_translate_asc()
s390x/kvm: Add function for injecting pgm access exceptions s390x/mmu: Add function for accessing guest memory s390x/css: Make schib parameter of css_do_msch const s390x/ioinst: Rework memory access in MSCH instruction s390x/ioinst: Rework memory access in SSCH instruction s390x/ioinst: Rework memory access in STSCH instruction s390x/ioinst: Set condition code in ioinst_handle_tsch() handler s390x/ioinst: Rework memory access in TSCH instruction s390x/ioinst: Rework memory access in STCRW instruction s390x/ioinst: Rework memory access in CHSC instruction s390x/ioinst: Rework memory access in TPI instruction s390x/helper: Remove s390_cpu_physical_memory_map
hw/s390x/css.c | 60 ++++-- hw/s390x/s390-pci-inst.c | 37 +++- target-s390x/Makefile.objs | 2 +- target-s390x/cpu.h | 32 ++- target-s390x/helper.c | 356 +--------------------------------- target-s390x/ioinst.c | 172 ++++++++--------- target-s390x/ioinst.h | 4 +- target-s390x/kvm.c | 21 +- target-s390x/mem_helper.c | 12 +- target-s390x/mmu_helper.c | 472 +++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 681 insertions(+), 487 deletions(-) create mode 100644 target-s390x/mmu_helper.c
Signature · 1 line
2.1.4
PATCH 1/25 s390x/mmu: Move mmu_translate() and friends to separate file
From: Thomas Huth <[email protected]>
helper.c is quite overcrowded already, so let's move the MMU translation to a separate file instead (like it has been done with the other targets already).
--- target-s390x/Makefile.objs | 2 +- target-s390x/cpu.h | 1 + target-s390x/helper.c | 323 +--------------------------------------- target-s390x/mmu_helper.c | 356 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 359 insertions(+), 323 deletions(-) create mode 100644 target-s390x/mmu_helper.c
target-s390x/Makefile.objs +1 -1
@@ -1,5 +1,5 @@ obj-y += translate.o helper.o cpu.o interrupt.o obj-y += int_helper.o fpu_helper.o cc_helper.o mem_helper.o misc_helper.o obj-y += gdbstub.o -obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o +obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o mmu_helper.o obj-$(CONFIG_KVM) += kvm.o
target-s390x/cpu.h +1 -0
@@ -331,6 +331,7 @@ static inline int get_ilen(uint8_t opc)to re-compute the length by examining the insn in memory. */ #define ILEN_LATER 0x20#define ILEN_LATER_INC 0x21 +void trigger_pgm_exception (CPUS390XState *env,uint32_t code,uint32_t ilen);#endif S390CPU *cpu_s390x_init (const char *cpu_model);
target-s390x/helper.c +1 -322
347 lines not on this page · raw message
target-s390x/mmu_helper.c new file +356 -0
356 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH 01/25] s390x/mmu: Move mmu_translate() and friends to separate file
Quoted 8 lines · Jens Freimann
From: Thomas Huth <[email protected]>
helper.cis quite overcrowded already, so let's move the MMU translation to a separate file instead (like it has been done with the other targets already).Signed-off-by Thomas Huth <[email protected]>Signed-off-by Jens Freimann <[email protected]>
Alex
PATCH 2/25 s390x/mmu: Fix the check for the real-space designation bit
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
The real-space designation bits live in the ASCEs, not in the table entries, so the check must be done before we start walking the MMU table.
--- target-s390x/mmu_helper.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
target-s390x/mmu_helper.c +6 -7
@@ -180,13 +180,6 @@ static int mmu_translate_asce(CPUS390XState *env, target_ulong vaddr,return -1 ; } -if (asce & _ASCE_REAL_SPACE) { -/* direct mapping */ - - *raddr = vaddr; -return 0 ; - } - origin = asce & _ASCE_ORIGIN;switch (level) {
@@ -252,6 +245,12 @@ static int mmu_translate_asc(CPUS390XState *env, target_ulong vaddr,break ; } +if (asce & _ASCE_REAL_SPACE) { +/* direct mapping */ + *raddr = vaddr; +return 0 ; + } +switch (asce & _ASCE_TYPE_MASK) {case _ASCE_TYPE_REGION1:break ;
Signature · 1 line
2.1.4
PATCH 3/25 s390x/mmu: Fix the handling of the table levels
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
The current code used a wrong and very confusing way of dealing with the table levels by introducing a "fake level above current". However, the real problem was simply that the checks for the region/segment invalid bit and for the matching region/segment level was done at the wrong spot in the code - it has to be done after the first table entry has been looked up instead (e.g. there is also no "invalid" bit in the ASCE itself and the current "level" has to be the same as the level in the entry that we just looked up).
Also the entries for the segment table are quite a bit different compared to the region table entries. So this patch moves the related code into the function mmu_translate_segment() to make it clear at which table level we currently are and to get rid of the ugly switch-statement in the function mmu_translate_region().
--- target-s390x/mmu_helper.c | 115 +++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 68 deletions(-)
target-s390x/mmu_helper.c +47 -68
@@ -134,92 +134,76 @@ static int mmu_translate_pte(CPUS390XState *env, target_ulong vaddr,return 0 ; } -/* Decode EDAT1 segment frame absolute address (1MB page) */ -static int mmu_translate_sfaa (CPUS390XState *env,target_ulong vaddr, -uint64_t asc,uint64_t asce,target_ulong *raddr, -int *flags,int rw) +#define VADDR_PX 0xff000/* Page index bits */ + +/* Decode segment table entry */ +static int mmu_translate_segment (CPUS390XState *env,target_ulong vaddr, +uint64_t asc,uint64_t st_entry, +target_ulong *raddr,int *flags,int rw) { -if (asce & _SEGMENT_ENTRY_INV) { -DPRINTF ("%s: SEG=0x%" PRIx64" invalid\n" , __func__, asce); -trigger_page_fault (env, vaddr,PGM_SEGMENT_TRANS , asc, rw); -return -1 ; - } +CPUState *cs =CPU (s390_env_get_cpu (env)); +uint64_t origin, offs, pt_entry; -if (asce & _SEGMENT_ENTRY_RO) { +if (st_entry & _SEGMENT_ENTRY_RO) { *flags &= ~PAGE_WRITE ; } - *raddr = (asce &0xfffffffffff00000ULL ) | (vaddr &0xfffff ); - -PTE_DPRINTF ("%s: SEG=0x%" PRIx64"\n" , __func__, asce); +if ((st_entry & _SEGMENT_ENTRY_FC) && (env->cregs[0 ] &CR0_EDAT )) { +/* Decode EDAT1 segment frame absolute address (1MB page) */ + *raddr = (st_entry &0xfffffffffff00000ULL ) | (vaddr &0xfffff ); +PTE_DPRINTF ("%s: SEG=0x%" PRIx64"\n" , __func__, st_entry); +return 0 ; + } -return 0 ; +/* Look up 4KB page entry */ + origin = st_entry & _SEGMENT_ENTRY_ORIGIN; + offs = (vaddr &VADDR_PX ) >>9 ; + pt_entry =ldq_phys (cs->as, origin + offs); +PTE_DPRINTF ("%s: 0x%" PRIx64" + 0x%" PRIx64" => 0x%016" PRIx64"\n" , + __func__, origin, offs, pt_entry); +return mmu_translate_pte (env, vaddr, asc, pt_entry, raddr, flags, rw); } -static int mmu_translate_asce (CPUS390XState *env,target_ulong vaddr, -uint64_t asc,uint64_t asce,int level, -target_ulong *raddr,int *flags,int rw) +/* Decode region table entries */ +static int mmu_translate_region (CPUS390XState *env,target_ulong vaddr, +uint64_t asc,uint64_t entry,int level, +target_ulong *raddr,int *flags,int rw) {CPUState *cs =CPU (s390_env_get_cpu (env)); -uint64_t offs =0 ; -uint64_t origin; -uint64_t new_asce; +uint64_t origin, offs, new_entry; + +PTE_DPRINTF ("%s: 0x%" PRIx64"\n" , __func__, entry); -PTE_DPRINTF ("%s: 0x%" PRIx64"\n" , __func__, asce); + origin = entry & _REGION_ENTRY_ORIGIN; + offs = (vaddr >> (17 +11 * level /4 )) &0x3ff8 ; + + new_entry =ldq_phys (cs->as, origin + offs); +PTE_DPRINTF ("%s: 0x%" PRIx64" + 0x%" PRIx64" => 0x%016" PRIx64"\n" , + __func__, origin, offs, new_entry); -if (((level != _ASCE_TYPE_SEGMENT) && (asce & _REGION_ENTRY_INV)) || - ((level == _ASCE_TYPE_SEGMENT) && (asce & _SEGMENT_ENTRY_INV))) { +if ((new_entry & _REGION_ENTRY_INV) !=0 ) {/* XXX different regions have different faults */ DPRINTF ("%s: invalid region\n" , __func__);trigger_page_fault (env, vaddr,PGM_SEGMENT_TRANS , asc, rw);return -1 ; } -if ((level <= _ASCE_TYPE_MASK) && ((asce & _ASCE_TYPE_MASK) != level)) { +if ((new_entry & _REGION_ENTRY_TYPE_MASK) != level) {trigger_page_fault (env, vaddr,PGM_TRANS_SPEC , asc, rw);return -1 ; } - origin = asce & _ASCE_ORIGIN; - -switch (level) { -case _ASCE_TYPE_REGION1 +4 : - offs = (vaddr >>50 ) &0x3ff8 ; -break ; -case _ASCE_TYPE_REGION1: - offs = (vaddr >>39 ) &0x3ff8 ; -break ; -case _ASCE_TYPE_REGION2: - offs = (vaddr >>28 ) &0x3ff8 ; -break ; -case _ASCE_TYPE_REGION3: - offs = (vaddr >>17 ) &0x3ff8 ; -break ; -case _ASCE_TYPE_SEGMENT: - offs = (vaddr >>9 ) &0x07f8 ; - origin = asce & _SEGMENT_ENTRY_ORIGIN; -break ; - } -/* XXX region protection flags */ /* *flags &= ~PAGE_WRITE */ - new_asce =ldq_phys (cs->as, origin + offs); -PTE_DPRINTF ("%s: 0x%" PRIx64" + 0x%" PRIx64" => 0x%016" PRIx64"\n" , - __func__, origin, offs, new_asce); -if (level == _ASCE_TYPE_SEGMENT) { -/* 4KB page */ -return mmu_translate_pte (env, vaddr, asc, new_asce, raddr, flags, rw); - }else if (level -4 == _ASCE_TYPE_SEGMENT && - (new_asce & _SEGMENT_ENTRY_FC) && (env->cregs[0 ] &CR0_EDAT )) { -/* 1MB page */ -return mmu_translate_sfaa (env, vaddr, asc, new_asce, raddr, flags, rw); - }else { -/* yet another region */ -return mmu_translate_asce (env, vaddr, asc, new_asce, level -4 , raddr, - flags, rw); +return mmu_translate_segment (env, vaddr, asc, new_entry, raddr, flags, + rw); } + +/* yet another region */ +return mmu_translate_region (env, vaddr, asc, new_entry, level -4 , + raddr, flags, rw); } static int mmu_translate_asc(CPUS390XState *env, target_ulong vaddr,
@@ -227,7 +211,7 @@ static int mmu_translate_asc(CPUS390XState *env, target_ulong vaddr, int rw) {uint64_t asce =0 ; -int level, new_level; +int level;int r;switch (asc) {
@@ -251,7 +235,8 @@ static int mmu_translate_asc(CPUS390XState *env, target_ulong vaddr,return 0 ; } -switch (asce & _ASCE_TYPE_MASK) { + level = asce & _ASCE_TYPE_MASK; +switch (level) {case _ASCE_TYPE_REGION1:break ;case _ASCE_TYPE_REGION2:
@@ -280,13 +265,7 @@ static int mmu_translate_asc(CPUS390XState *env, target_ulong vaddr,break ; } -/* fake level above current */ - level = asce & _ASCE_TYPE_MASK; - new_level = level +4 ; - asce = (asce & ~_ASCE_TYPE_MASK) | (new_level & _ASCE_TYPE_MASK); - - r =mmu_translate_asce (env, vaddr, asc, asce, new_level, raddr, flags, rw); - + r =mmu_translate_region (env, vaddr, asc, asce, level, raddr, flags, rw);if ((rw ==1 ) && !(*flags &PAGE_WRITE )) {trigger_prot_fault (env, vaddr, asc);return -1 ;
Signature · 1 line
2.1.4
PATCH 4/25 s390x/mmu: Check table length and offset fields
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
The ACSEs have a table length field and the region entries have table length and offset fields which must be checked during translation to see whether the given virtual address is really covered by the translation table.
--- target-s390x/cpu.h | 1 + target-s390x/mmu_helper.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
target-s390x/cpu.h +1 -0
@@ -837,6 +837,7 @@ struct sysib_322 {#define _ASCE_TABLE_LENGTH 0x03/* region table length */ #define _REGION_ENTRY_ORIGIN ~0xfffULL/* region/segment table origin */ +#define _REGION_ENTRY_TF 0xc0/* region/segment table offset */ #define _REGION_ENTRY_INV 0x20/* invalid region table entry */ #define _REGION_ENTRY_TYPE_MASK 0x0c/* region/segment table type mask */ #define _REGION_ENTRY_TYPE_R1 0x0c/* region first table type */
target-s390x/mmu_helper.c +29 -0
@@ -171,6 +171,10 @@ static int mmu_translate_region(CPUS390XState *env, target_ulong vaddr, {CPUState *cs =CPU (s390_env_get_cpu (env));uint64_t origin, offs, new_entry; +const int pchks[4 ] = { +PGM_SEGMENT_TRANS ,PGM_REG_THIRD_TRANS , +PGM_REG_SEC_TRANS ,PGM_REG_FIRST_TRANS + };PTE_DPRINTF ("%s: 0x%" PRIx64"\n" , __func__, entry);
@@ -201,6 +205,15 @@ static int mmu_translate_region(CPUS390XState *env, target_ulong vaddr, rw); } +/* Check region table offset and length */ + offs = (vaddr >> (28 +11 * (level -4 ) /4 )) &3 ; +if (offs < ((new_entry & _REGION_ENTRY_TF) >>6 ) + || offs > (new_entry & _REGION_ENTRY_LENGTH)) { +DPRINTF ("%s: invalid offset or len (%lx)\n" , __func__, new_entry); +trigger_page_fault (env, vaddr, pchks[level /4 -1 ], asc, rw); +return -1 ; + } +/* yet another region */ return mmu_translate_region (env, vaddr, asc, new_entry, level -4 , raddr, flags, rw);
@@ -238,6 +251,10 @@ static int mmu_translate_asc(CPUS390XState *env, target_ulong vaddr, level = asce & _ASCE_TYPE_MASK;switch (level) {case _ASCE_TYPE_REGION1: +if ((vaddr >>62 ) > (asce & _ASCE_TABLE_LENGTH)) { +trigger_page_fault (env, vaddr,PGM_REG_FIRST_TRANS , asc, rw); +return -1 ; + }break ;case _ASCE_TYPE_REGION2:if (vaddr &0xffe0000000000000ULL ) {
@@ -246,6 +263,10 @@ static int mmu_translate_asc(CPUS390XState *env, target_ulong vaddr,trigger_page_fault (env, vaddr,PGM_TRANS_SPEC , asc, rw);return -1 ; } +if ((vaddr >>51 &3 ) > (asce & _ASCE_TABLE_LENGTH)) { +trigger_page_fault (env, vaddr,PGM_REG_SEC_TRANS , asc, rw); +return -1 ; + }break ;case _ASCE_TYPE_REGION3:if (vaddr &0xfffffc0000000000ULL ) {
@@ -254,6 +275,10 @@ static int mmu_translate_asc(CPUS390XState *env, target_ulong vaddr,trigger_page_fault (env, vaddr,PGM_TRANS_SPEC , asc, rw);return -1 ; } +if ((vaddr >>40 &3 ) > (asce & _ASCE_TABLE_LENGTH)) { +trigger_page_fault (env, vaddr,PGM_REG_THIRD_TRANS , asc, rw); +return -1 ; + }break ;case _ASCE_TYPE_SEGMENT:if (vaddr &0xffffffff80000000ULL ) {
@@ -262,6 +287,10 @@ static int mmu_translate_asc(CPUS390XState *env, target_ulong vaddr,trigger_page_fault (env, vaddr,PGM_TRANS_SPEC , asc, rw);return -1 ; } +if ((vaddr >>29 &3 ) > (asce & _ASCE_TABLE_LENGTH)) { +trigger_page_fault (env, vaddr,PGM_SEGMENT_TRANS , asc, rw); +return -1 ; + }break ; }
Signature · 1 line
2.1.4
PATCH 5/25 s390x/mmu: Skip exceptions properly when translating addresses for debug
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
When a fault occurs during the MMU lookup in s390_cpu_get_phys_page_debug(), the trigger_page_fault() function writes the translation exception code into the lowcore - something you would not expect during a memory access by the debugger. Ease this problem by adding an additional parameter to mmu_translate() which can be used to specify whether a program check and the translation exception code should be injected or not.
--- target-s390x/cpu.h | 2 +- target-s390x/helper.c | 8 ++--- target-s390x/mem_helper.c | 12 ++++---- target-s390x/mmu_helper.c | 77 ++++++++++++++++++++++++++++++----------------- 4 files changed, 59 insertions(+), 40 deletions(-)
target-s390x/cpu.h +1 -1
@@ -885,7 +885,7 @@ struct sysib_322 {void load_psw (CPUS390XState *env,uint64_t mask,uint64_t addr);int mmu_translate (CPUS390XState *env,target_ulong vaddr,int rw,uint64_t asc, -target_ulong *raddr,int *flags); +target_ulong *raddr,int *flags,bool exc);int sclp_service_call (CPUS390XState *env,uint64_t sccb,uint32_t code);uint32_t calc_cc (CPUS390XState *env,uint32_t cc_op,uint64_t src,uint64_t dst,uint64_t vr);
target-s390x/helper.c +3 -5
@@ -127,7 +127,7 @@ int s390_cpu_handle_mmu_fault(CPUState *cs, vaddr orig_vaddr, vaddr &=0x7fffffff ; } -if (mmu_translate (env, vaddr, rw, asc, &raddr, &prot)) { +if (mmu_translate (env, vaddr, rw, asc, &raddr, &prot, true)) {/* Translation ended in exception */ return 1 ; }
@@ -154,8 +154,7 @@ hwaddr s390_cpu_get_phys_page_debug(CPUState *cs, vaddr vaddr)S390CPU *cpu =S390_CPU (cs);CPUS390XState *env = &cpu->env;target_ulong raddr; -int prot =PAGE_READ |PAGE_WRITE |PAGE_EXEC ; -int old_exc = cs->exception_index; +int prot;uint64_t asc = env->psw.mask &PSW_MASK_ASC ;/* 31-Bit mode */
@@ -163,8 +162,7 @@ hwaddr s390_cpu_get_phys_page_debug(CPUState *cs, vaddr vaddr) vaddr &=0x7fffffff ; } -mmu_translate (env, vaddr,2 , asc, &raddr, &prot); - cs->exception_index = old_exc; +mmu_translate (env, vaddr,2 , asc, &raddr, &prot, false);return raddr; }
target-s390x/mem_helper.c +6 -6
@@ -65,7 +65,7 @@ static void mvc_fast_memset(CPUS390XState *env, uint32_t l, uint64_t dest,uint64_t asc = env->psw.mask &PSW_MASK_ASC ;int flags; -if (mmu_translate (env, dest,1 , asc, &dest_phys, &flags)) { +if (mmu_translate (env, dest,1 , asc, &dest_phys, &flags, true)) {cpu_stb_data (env, dest, byte);cpu_abort (CPU (cpu),"should never reach here" ); }
@@ -90,13 +90,13 @@ static void mvc_fast_memmove(CPUS390XState *env, uint32_t l, uint64_t dest,uint64_t asc = env->psw.mask &PSW_MASK_ASC ;int flags; -if (mmu_translate (env, dest,1 , asc, &dest_phys, &flags)) { +if (mmu_translate (env, dest,1 , asc, &dest_phys, &flags, true)) {cpu_stb_data (env, dest,0 );cpu_abort (CPU (cpu),"should never reach here" ); } dest_phys |= dest & ~TARGET_PAGE_MASK ; -if (mmu_translate (env, src,0 , asc, &src_phys, &flags)) { +if (mmu_translate (env, src,0 , asc, &src_phys, &flags, true)) {cpu_ldub_data (env, src);cpu_abort (CPU (cpu),"should never reach here" ); }
@@ -967,12 +967,12 @@ static uint32_t mvc_asc(CPUS390XState *env, int64_t l, uint64_t a1, cc =3 ; } -if (mmu_translate (env, a1 &TARGET_PAGE_MASK ,1 , mode1, &dest, &flags)) { +if (mmu_translate (env, a1,1 , mode1, &dest, &flags, true)) {cpu_loop_exit (CPU (s390_env_get_cpu (env))); } dest |= a1 & ~TARGET_PAGE_MASK ; -if (mmu_translate (env, a2 &TARGET_PAGE_MASK ,0 , mode2, &src, &flags)) { +if (mmu_translate (env, a2,0 , mode2, &src, &flags, true)) {cpu_loop_exit (CPU (s390_env_get_cpu (env))); } src |= a2 & ~TARGET_PAGE_MASK ;
@@ -1088,7 +1088,7 @@ uint64_t HELPER(lra)(CPUS390XState *env, uint64_t addr) } cs->exception_index = old_exc; -if (mmu_translate (env, addr,0 , asc, &ret, &flags)) { +if (mmu_translate (env, addr,0 , asc, &ret, &flags, true)) { cc =3 ; }if (cs->exception_index ==EXCP_PGM ) {
target-s390x/mmu_helper.c +49 -28
223 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH 6/25 s390x/mmu: Fix translation exception code in lowcore
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
The address space bits in the translation exception code were wrong. In fact, we can simply copy the bits from the PSW, so there's no need for the trans_bits() function anymore.
Additionally, we now also set the fetch/store bits in the translation exception code, so a guest can determine whether the exception occured during a write or during a read.
--- target-s390x/mmu_helper.c | 48 +++++++++++++++-------------------------------- 1 file changed, 15 insertions(+), 33 deletions(-)
target-s390x/mmu_helper.c +15 -33
@@ -42,45 +42,26 @@ do { } while (0)#endif -static int trans_bits (CPUS390XState *env,uint64_t mode) -{ -S390CPU *cpu =s390_env_get_cpu (env); -int bits =0 ; - -switch (mode) { -case PSW_ASC_PRIMARY : - bits =1 ; -break ; -case PSW_ASC_SECONDARY : - bits =2 ; -break ; -case PSW_ASC_HOME : - bits =3 ; -break ; -default : -cpu_abort (CPU (cpu),"unknown asc mode\n" ); -break ; - } - -return bits; -} +/* Fetch/store bits in the translation exception code: */ +#define FS_READ 0x800 +#define FS_WRITE 0x400static void trigger_prot_fault (CPUS390XState *env,target_ulong vaddr, -uint64_t mode,bool exc) +uint64_t asc,int rw,bool exc) {CPUState *cs =CPU (s390_env_get_cpu (env)); -int ilen =ILEN_LATER_INC ; -int bits =trans_bits (env, mode) |4 ; +uint64_t tec; -DPRINTF ("%s: vaddr=%016" PRIx64" bits=%d\n" , __func__, vaddr, bits); + tec = vaddr | (rw ==1 ?FS_WRITE :FS_READ ) |4 | asc >>46 ; + +DPRINTF ("%s: trans_exc_code=%016" PRIx64"\n" , __func__, tec);if (!exc) {return ; } -stq_phys (cs->as, - env->psa + offsetof(LowCore , trans_exc_code), vaddr | bits); -trigger_pgm_exception (env,PGM_PROTECTION , ilen); +stq_phys (cs->as, env->psa + offsetof(LowCore , trans_exc_code), tec); +trigger_pgm_exception (env,PGM_PROTECTION ,ILEN_LATER_INC ); } static void trigger_page_fault(CPUS390XState *env, target_ulong vaddr,
@@ -88,7 +69,9 @@ static void trigger_page_fault(CPUS390XState *env, target_ulong vaddr, {CPUState *cs =CPU (s390_env_get_cpu (env));int ilen =ILEN_LATER ; -int bits =trans_bits (env, asc); +uint64_t tec; + + tec = vaddr | (rw ==1 ?FS_WRITE :FS_READ ) | asc >>46 ;DPRINTF ("%s: vaddr=%016" PRIx64" bits=%d\n" , __func__, vaddr, bits);
@@ -101,8 +84,7 @@ static void trigger_page_fault(CPUS390XState *env, target_ulong vaddr, ilen =2 ; } -stq_phys (cs->as, - env->psa + offsetof(LowCore , trans_exc_code), vaddr | bits); +stq_phys (cs->as, env->psa + offsetof(LowCore , trans_exc_code), tec);trigger_pgm_exception (env, type, ilen); }
@@ -307,7 +289,7 @@ static int mmu_translate_asc(CPUS390XState *env, target_ulong vaddr, r =mmu_translate_region (env, vaddr, asc, asce, level, raddr, flags, rw, exc);if ((rw ==1 ) && !(*flags &PAGE_WRITE )) { -trigger_prot_fault (env, vaddr, asc, exc); +trigger_prot_fault (env, vaddr, asc, rw, exc);return -1 ; }
Signature · 1 line
2.1.4
PATCH 7/25 s390x/mmu: Fix exception types when checking the ASCEs
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
If an ASCE has illegal bits set, an ASCE-type exception should be generated instead of a translation specification exception.
--- target-s390x/mmu_helper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
target-s390x/mmu_helper.c +3 -3
@@ -252,7 +252,7 @@ static int mmu_translate_asc(CPUS390XState *env, target_ulong vaddr,if (vaddr &0xffe0000000000000ULL ) {DPRINTF ("%s: vaddr doesn't fit 0x%16" PRIx64" 0xffe0000000000000ULL\n" , __func__, vaddr); -trigger_page_fault (env, vaddr,PGM_TRANS_SPEC , asc, rw, exc); +trigger_page_fault (env, vaddr,PGM_ASCE_TYPE , asc, rw, exc);return -1 ; }if ((vaddr >>51 &3 ) > (asce & _ASCE_TABLE_LENGTH)) {
@@ -264,7 +264,7 @@ static int mmu_translate_asc(CPUS390XState *env, target_ulong vaddr,if (vaddr &0xfffffc0000000000ULL ) {DPRINTF ("%s: vaddr doesn't fit 0x%16" PRIx64" 0xfffffc0000000000ULL\n" , __func__, vaddr); -trigger_page_fault (env, vaddr,PGM_TRANS_SPEC , asc, rw, exc); +trigger_page_fault (env, vaddr,PGM_ASCE_TYPE , asc, rw, exc);return -1 ; }if ((vaddr >>40 &3 ) > (asce & _ASCE_TABLE_LENGTH)) {
@@ -276,7 +276,7 @@ static int mmu_translate_asc(CPUS390XState *env, target_ulong vaddr,if (vaddr &0xffffffff80000000ULL ) {DPRINTF ("%s: vaddr doesn't fit 0x%16" PRIx64" 0xffffffff80000000ULL\n" , __func__, vaddr); -trigger_page_fault (env, vaddr,PGM_TRANS_SPEC , asc, rw, exc); +trigger_page_fault (env, vaddr,PGM_ASCE_TYPE , asc, rw, exc);return -1 ; }if ((vaddr >>29 &3 ) > (asce & _ASCE_TABLE_LENGTH)) {
Signature · 1 line
2.1.4
PATCH 8/25 s390x/mmu: Fix the exception codes for illegal table entries
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
Each different level of region/segment table has a dedicated exception type for illegal entries.
--- target-s390x/mmu_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target-s390x/mmu_helper.c +1 -2
@@ -178,9 +178,8 @@ static int mmu_translate_region(CPUS390XState *env, target_ulong vaddr, __func__, origin, offs, new_entry);if ((new_entry & _REGION_ENTRY_INV) !=0 ) { -/* XXX different regions have different faults */ DPRINTF ("%s: invalid region\n" , __func__); -trigger_page_fault (env, vaddr,PGM_SEGMENT_TRANS , asc, rw, exc); +trigger_page_fault (env, vaddr, pchks[level /4 ], asc, rw, exc);return -1 ; }
Signature · 1 line
2.1.4
PATCH 9/25 s390x/mmu: Add support for read-only regions
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
If the "DAT-protection" bit is set in the region table entry and EDAT is enabled, only read accesses are allowed in the corresponding memory area.
--- target-s390x/cpu.h | 1 + target-s390x/mmu_helper.c | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-)
target-s390x/cpu.h +1 -0
@@ -837,6 +837,7 @@ struct sysib_322 {#define _ASCE_TABLE_LENGTH 0x03/* region table length */ #define _REGION_ENTRY_ORIGIN ~0xfffULL/* region/segment table origin */ +#define _REGION_ENTRY_RO 0x200/* region/segment protection bit */ #define _REGION_ENTRY_TF 0xc0/* region/segment table offset */ #define _REGION_ENTRY_INV 0x20/* invalid region table entry */ #define _REGION_ENTRY_TYPE_MASK 0x0c/* region/segment table type mask */
target-s390x/mmu_helper.c +4 -3
@@ -188,9 +188,6 @@ static int mmu_translate_region(CPUS390XState *env, target_ulong vaddr,return -1 ; } -/* XXX region protection flags */ -/* *flags &= ~PAGE_WRITE */ -if (level == _ASCE_TYPE_SEGMENT) {return mmu_translate_segment (env, vaddr, asc, new_entry, raddr, flags, rw, exc);
@@ -205,6 +202,10 @@ static int mmu_translate_region(CPUS390XState *env, target_ulong vaddr,return -1 ; } +if ((env->cregs[0 ] &CR0_EDAT ) && (new_entry & _REGION_ENTRY_RO)) { + *flags &= ~PAGE_WRITE ; + } +/* yet another region */ return mmu_translate_region (env, vaddr, asc, new_entry, level -4 , raddr, flags, rw, exc);
Signature · 1 line
2.1.4
PATCH 10/25 s390x/mmu: Renaming related to the ASCE confusion
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
An Address Space Control Element (ASCE) is only the very first unit of an s390 address translation (normally residing in one of the control registers). The entries in the page tables are called differently. So let's call the relevant variable pt_entry instead of asce in mmu_translate_pte() to avoid future confusion (thus there is no functional change in this patch, just renaming).
--- target-s390x/mmu_helper.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
target-s390x/mmu_helper.c +6 -6
@@ -104,22 +104,22 @@ static target_ulong mmu_real2abs(CPUS390XState *env, target_ulong raddr)/* Decode page table entry (normal 4KB page) */ static int mmu_translate_pte (CPUS390XState *env,target_ulong vaddr, -uint64_t asc,uint64_t asce, +uint64_t asc,uint64_t pt_entry,target_ulong *raddr,int *flags,int rw,bool exc) { -if (asce & _PAGE_INVALID) { -DPRINTF ("%s: PTE=0x%" PRIx64" invalid\n" , __func__, asce); +if (pt_entry & _PAGE_INVALID) { +DPRINTF ("%s: PTE=0x%" PRIx64" invalid\n" , __func__, pt_entry);trigger_page_fault (env, vaddr,PGM_PAGE_TRANS , asc, rw, exc);return -1 ; } -if (asce & _PAGE_RO) { +if (pt_entry & _PAGE_RO) { *flags &= ~PAGE_WRITE ; } - *raddr = asce & _ASCE_ORIGIN; + *raddr = pt_entry & _ASCE_ORIGIN; -PTE_DPRINTF ("%s: PTE=0x%" PRIx64"\n" , __func__, asce); +PTE_DPRINTF ("%s: PTE=0x%" PRIx64"\n" , __func__, pt_entry);return 0 ; }
Signature · 1 line
2.1.4
PATCH 11/25 s390x/mmu: Check bit 52 in page table entry
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
Bit 52 in a page table entry has always to be zero, or a translation specification exception is to be recognized.
--- target-s390x/cpu.h | 1 + target-s390x/mmu_helper.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)
target-s390x/cpu.h +1 -0
@@ -853,6 +853,7 @@ struct sysib_322 {#define _PAGE_RO 0x200/* HW read-only bit */ #define _PAGE_INVALID 0x400/* HW invalid bit */ +#define _PAGE_RES0 0x800/* bit must be zero */ #define SK_C (0x1 << 1)#define SK_R (0x1 << 2)
target-s390x/mmu_helper.c +4 -1
@@ -112,7 +112,10 @@ static int mmu_translate_pte(CPUS390XState *env, target_ulong vaddr,trigger_page_fault (env, vaddr,PGM_PAGE_TRANS , asc, rw, exc);return -1 ; } - +if (pt_entry & _PAGE_RES0) { +trigger_page_fault (env, vaddr,PGM_TRANS_SPEC , asc, rw, exc); +return -1 ; + }if (pt_entry & _PAGE_RO) { *flags &= ~PAGE_WRITE ; }
Signature · 1 line
2.1.4
PATCH 12/25 s390x/mmu: Clean up mmu_translate_asc()
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
We can get rid of the switch(asc) in mmu_translate_asc() by simply selecting the right control register ASCE in the mmu_translate() function already.
This patch is based on an original patch/idea by Ralf Hoppe.
--- target-s390x/mmu_helper.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-)
target-s390x/mmu_helper.c +15 -24
@@ -214,29 +214,13 @@ static int mmu_translate_region(CPUS390XState *env, target_ulong vaddr, raddr, flags, rw, exc); } -static int mmu_translate_asc (CPUS390XState *env,target_ulong vaddr, -uint64_t asc,target_ulong *raddr,int *flags, -int rw,bool exc) +static int mmu_translate_asce (CPUS390XState *env,target_ulong vaddr, +uint64_t asc,uint64_t asce,target_ulong *raddr, +int *flags,int rw,bool exc) { -uint64_t asce =0 ;int level;int r; -switch (asc) { -case PSW_ASC_PRIMARY : -PTE_DPRINTF ("%s: asc=primary\n" , __func__); - asce = env->cregs[1 ]; -break ; -case PSW_ASC_SECONDARY : -PTE_DPRINTF ("%s: asc=secondary\n" , __func__); - asce = env->cregs[7 ]; -break ; -case PSW_ASC_HOME : -PTE_DPRINTF ("%s: asc=home\n" , __func__); - asce = env->cregs[13 ]; -break ; - } -if (asce & _ASCE_REAL_SPACE) {/* direct mapping */ *raddr = vaddr;
@@ -326,21 +310,28 @@ int mmu_translate(CPUS390XState *env, target_ulong vaddr, int rw, uint64_t asc,switch (asc) {case PSW_ASC_PRIMARY : +PTE_DPRINTF ("%s: asc=primary\n" , __func__); + r =mmu_translate_asce (env, vaddr, asc, env->cregs[1 ], raddr, flags, + rw, exc); +break ;case PSW_ASC_HOME : - r =mmu_translate_asc (env, vaddr, asc, raddr, flags, rw, exc); +PTE_DPRINTF ("%s: asc=home\n" , __func__); + r =mmu_translate_asce (env, vaddr, asc, env->cregs[13 ], raddr, flags, + rw, exc);break ;case PSW_ASC_SECONDARY : +PTE_DPRINTF ("%s: asc=secondary\n" , __func__);/* * Instruction: Primary * Data: Secondary */ if (rw ==2 ) { - r =mmu_translate_asc (env, vaddr,PSW_ASC_PRIMARY , raddr, flags, - rw, exc); + r =mmu_translate_asce (env, vaddr,PSW_ASC_PRIMARY , env->cregs[1 ], + raddr, flags, rw, exc); *flags &= ~(PAGE_READ |PAGE_WRITE ); }else { - r =mmu_translate_asc (env, vaddr,PSW_ASC_SECONDARY , raddr, flags, - rw, exc); + r =mmu_translate_asce (env, vaddr,PSW_ASC_SECONDARY , env->cregs[7 ], + raddr, flags, rw, exc); *flags &= ~(PAGE_EXEC ); }break ;
Signature · 1 line
2.1.4
PATCH 13/25 s390x/kvm: Add function for injecting pgm access exceptions
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
Program access exceptions are defined to deliver a translation exception code in the low-core. Add a function trigger_access_exception() that generates the proper program interrupt on both KVM and non-KVM systems and switch the existing code to use it.
--- target-s390x/cpu.h | 5 +++++ target-s390x/kvm.c | 12 ++++++++++++ target-s390x/mmu_helper.c | 22 ++++++++++++++++------ 3 files changed, 33 insertions(+), 6 deletions(-)
target-s390x/cpu.h +5 -0
@@ -397,6 +397,7 @@ void kvm_s390_service_interrupt(uint32_t parm);void kvm_s390_vcpu_interrupt (S390CPU *cpu,struct kvm_s390_irq *irq);void kvm_s390_floating_interrupt (struct kvm_s390_irq *irq);int kvm_s390_inject_flic (struct kvm_s390_irq *irq); +void kvm_s390_access_exception (S390CPU *cpu,uint16_t code,uint64_t te_code);#else static inline void kvm_s390_virtio_irq (int config_change,uint64_t token) {
@@ -404,6 +405,10 @@ static inline void kvm_s390_virtio_irq(int config_change, uint64_t token)static inline void kvm_s390_service_interrupt (uint32_t parm) { } +static inline void kvm_s390_access_exception (S390CPU *cpu,uint16_t code, +uint64_t te_code) +{ +}#endif S390CPU *s390_cpu_addr2state (uint16_t cpu_addr);unsigned int s390_cpu_halt (S390CPU *cpu);
target-s390x/kvm.c +12 -0
@@ -756,6 +756,18 @@ static void enter_pgmcheck(S390CPU *cpu, uint16_t code)kvm_s390_vcpu_interrupt (cpu, &irq); } +void kvm_s390_access_exception (S390CPU *cpu,uint16_t code,uint64_t te_code) +{ +struct kvm_s390_irq irq = { + .type =KVM_S390_PROGRAM_INT , + .u.pgm.code = code, + .u.pgm.trans_exc_code = te_code, + .u.pgm.exc_access_id = te_code &3 , + }; + +kvm_s390_vcpu_interrupt (cpu, &irq); +} +static int kvm_sclp_service_call (S390CPU *cpu,struct kvm_run *run,uint16_t ipbh0) {
target-s390x/mmu_helper.c +16 -6
@@ -46,10 +46,23 @@#define FS_READ 0x800#define FS_WRITE 0x400 +static void trigger_access_exception (CPUS390XState *env,uint32_t type, +uint32_t ilen,uint64_t tec) +{ +S390CPU *cpu =s390_env_get_cpu (env); + +if (kvm_enabled ()) { +kvm_s390_access_exception (cpu, type, tec); + }else { +CPUState *cs =CPU (cpu); +stq_phys (cs->as, env->psa + offsetof(LowCore , trans_exc_code), tec); +trigger_pgm_exception (env, type, ilen); + } +} +static void trigger_prot_fault (CPUS390XState *env,target_ulong vaddr,uint64_t asc,int rw,bool exc) { -CPUState *cs =CPU (s390_env_get_cpu (env));uint64_t tec; tec = vaddr | (rw ==1 ?FS_WRITE :FS_READ ) |4 | asc >>46 ;
@@ -60,14 +73,12 @@ static void trigger_prot_fault(CPUS390XState *env, target_ulong vaddr,return ; } -stq_phys (cs->as, env->psa + offsetof(LowCore , trans_exc_code), tec); -trigger_pgm_exception (env,PGM_PROTECTION ,ILEN_LATER_INC ); +trigger_access_exception (env,PGM_PROTECTION ,ILEN_LATER_INC , tec); }static void trigger_page_fault (CPUS390XState *env,target_ulong vaddr,uint32_t type,uint64_t asc,int rw,bool exc) { -CPUState *cs =CPU (s390_env_get_cpu (env));int ilen =ILEN_LATER ;uint64_t tec;
@@ -84,8 +95,7 @@ static void trigger_page_fault(CPUS390XState *env, target_ulong vaddr, ilen =2 ; } -stq_phys (cs->as, env->psa + offsetof(LowCore , trans_exc_code), tec); -trigger_pgm_exception (env, type, ilen); +trigger_access_exception (env, type, ilen, tec); }/**
Signature · 1 line
2.1.4
PATCH 14/25 s390x/mmu: Add function for accessing guest memory
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
According to the POP specification, the parameter blocks of various functions like the IO instructions are accessed with logical addresses. Thus we need a function that can read or write a buffer from/to the guest's logical address space.
This patch now provides a function that can be used to access virtual guest memory by using the mmu_translate function of QEMU to convert the virtual addresses to physical.
--- target-s390x/cpu.h | 11 +++++ target-s390x/mmu_helper.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+)
target-s390x/cpu.h +11 -0
@@ -287,6 +287,7 @@ typedef struct CPUS390XState {#define FLAG_MASK_32 0x00001000/* Control register 0 bits */ +#define CR0_LOWPROT 0x0000000010000000ULL#define CR0_EDAT 0x0000000000800000ULLstatic inline int cpu_mmu_index (CPUS390XState *env)
@@ -897,6 +898,16 @@ int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code);uint32_t calc_cc (CPUS390XState *env,uint32_t cc_op,uint64_t src,uint64_t dst,uint64_t vr); +int s390_cpu_virt_mem_rw (S390CPU *cpu,vaddr laddr,void *hostbuf,int len, +bool is_write); + +#define s390_cpu_virt_mem_read (cpu, laddr, dest, len) \ + s390_cpu_virt_mem_rw(cpu, laddr, dest, len, false) +#define s390_cpu_virt_mem_write (cpu, laddr, dest, len) \ + s390_cpu_virt_mem_rw(cpu, laddr, dest, len, true) +#define s390_cpu_virt_mem_check_write (cpu, laddr, len) \ + s390_cpu_virt_mem_rw(cpu, laddr, NULL, len, true) +/* The value of the TOD clock for 1.1.1970. */ #define TOD_UNIX_EPOCH 0x7d91048bca000000ULL
target-s390x/mmu_helper.c +102 -0
111 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH 15/25 s390x/css: Make schib parameter of css_do_msch const
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
The schib parameter of css_do_msch() can be declared as const to make it clear that it does not get modified by this function.
--- hw/s390x/css.c | 2 +- target-s390x/cpu.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/s390x/css.c +1 -1
@@ -584,7 +584,7 @@ static void copy_schib_from_guest(SCHIB *dest, const SCHIB *src) } } -int css_do_msch (SubchDev *sch,SCHIB *orig_schib) +int css_do_msch (SubchDev *sch,const SCHIB *orig_schib) {SCSW *s = &sch->curr_status.scsw;PMCW *p = &sch->curr_status.pmcw;
target-s390x/cpu.h +1 -1
@@ -450,7 +450,7 @@ bool css_subch_visible(SubchDev *sch);void css_conditional_io_interrupt (SubchDev *sch);int css_do_stsch (SubchDev *sch,SCHIB *schib);bool css_schid_final (int m,uint8_t cssid,uint8_t ssid,uint16_t schid); -int css_do_msch (SubchDev *sch,SCHIB *schib); +int css_do_msch (SubchDev *sch,const SCHIB *schib);int css_do_xsch (SubchDev *sch);int css_do_csch (SubchDev *sch);int css_do_hsch (SubchDev *sch);
Signature · 1 line
2.1.4
PATCH 16/25 s390x/ioinst: Rework memory access in MSCH instruction
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
Change the handler for MSCH to use the new logical memory access functions.
--- target-s390x/ioinst.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
target-s390x/ioinst.c +7 -13
@@ -1,7 +1,7 @@/* * I/O instructions for S/390 * -* Copyright 2012 IBM Corp. +* Copyright 2012, 2015 IBM Corp. * Author(s): Cornelia Huck <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or (at
@@ -144,11 +144,10 @@ void ioinst_handle_msch(S390CPU *cpu, uint64_t reg1, uint32_t ipb) {int cssid, ssid, schid, m;SubchDev *sch; -SCHIB *schib; +SCHIB schib;uint64_t addr;int ret = -ENODEV ;int cc; -hwaddr len =sizeof (*schib);CPUS390XState *env = &cpu->env; addr =decode_basedisp_s (env, ipb);
@@ -156,20 +155,18 @@ void ioinst_handle_msch(S390CPU *cpu, uint64_t reg1, uint32_t ipb)program_interrupt (env,PGM_SPECIFICATION ,2 );return ; } - schib =s390_cpu_physical_memory_map (env, addr, &len,0 ); -if (!schib || len !=sizeof (*schib)) { -program_interrupt (env,PGM_ADDRESSING ,2 ); - goto out; +if (s390_cpu_virt_mem_read (cpu, addr, &schib,sizeof (schib))) { +return ; }if (ioinst_disassemble_sch_ident (reg1, &m, &cssid, &ssid, &schid) || - !ioinst_schib_valid (schib)) { + !ioinst_schib_valid (&schib)) {program_interrupt (env,PGM_OPERAND ,2 ); - goto out; +return ; }trace_ioinst_sch_id ("msch" , cssid, ssid, schid); sch =css_find_subch (m, cssid, ssid, schid);if (sch &&css_subch_visible (sch)) { - ret =css_do_msch (sch, schib); + ret =css_do_msch (sch, &schib); }switch (ret) {case -ENODEV :
@@ -186,9 +183,6 @@ void ioinst_handle_msch(S390CPU *cpu, uint64_t reg1, uint32_t ipb)break ; }setcc (cpu, cc); - -out: -s390_cpu_physical_memory_unmap (env, schib, len,0 ); }static void copy_orb_from_guest (ORB *dest,const ORB *src)
Signature · 1 line
2.1.4
PATCH 17/25 s390x/ioinst: Rework memory access in SSCH instruction
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
Change the handler for SSCH to use the new logical memory access functions.
--- target-s390x/ioinst.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
target-s390x/ioinst.c +5 -11
@@ -210,11 +210,10 @@ void ioinst_handle_ssch(S390CPU *cpu, uint64_t reg1, uint32_t ipb) {int cssid, ssid, schid, m;SubchDev *sch; -ORB *orig_orb, orb; +ORB orig_orb, orb;uint64_t addr;int ret = -ENODEV ;int cc; -hwaddr len =sizeof (*orig_orb);CPUS390XState *env = &cpu->env; addr =decode_basedisp_s (env, ipb);
@@ -222,16 +221,14 @@ void ioinst_handle_ssch(S390CPU *cpu, uint64_t reg1, uint32_t ipb)program_interrupt (env,PGM_SPECIFICATION ,2 );return ; } - orig_orb =s390_cpu_physical_memory_map (env, addr, &len,0 ); -if (!orig_orb || len !=sizeof (*orig_orb)) { -program_interrupt (env,PGM_ADDRESSING ,2 ); - goto out; +if (s390_cpu_virt_mem_read (cpu, addr, &orig_orb,sizeof (orb))) { +return ; } -copy_orb_from_guest (&orb, orig_orb); +copy_orb_from_guest (&orb, &orig_orb);if (ioinst_disassemble_sch_ident (reg1, &m, &cssid, &ssid, &schid) || !ioinst_orb_valid (&orb)) {program_interrupt (env,PGM_OPERAND ,2 ); - goto out; +return ; }trace_ioinst_sch_id ("ssch" , cssid, ssid, schid); sch =css_find_subch (m, cssid, ssid, schid);
@@ -253,9 +250,6 @@ void ioinst_handle_ssch(S390CPU *cpu, uint64_t reg1, uint32_t ipb)break ; }setcc (cpu, cc); - -out: -s390_cpu_physical_memory_unmap (env, orig_orb, len,0 ); }void ioinst_handle_stcrw (S390CPU *cpu,uint32_t ipb)
Signature · 1 line
2.1.4
PATCH 18/25 s390x/ioinst: Rework memory access in STSCH instruction
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
Change the handler for STSCH to use the new logical memory access functions.
--- target-s390x/ioinst.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-)
target-s390x/ioinst.c +22 -14
@@ -284,8 +284,7 @@ void ioinst_handle_stsch(S390CPU *cpu, uint64_t reg1, uint32_t ipb)SubchDev *sch;uint64_t addr;int cc; -SCHIB *schib; -hwaddr len =sizeof (*schib); +SCHIB schib;CPUS390XState *env = &cpu->env; addr =decode_basedisp_s (env, ipb);
@@ -293,21 +292,23 @@ void ioinst_handle_stsch(S390CPU *cpu, uint64_t reg1, uint32_t ipb)program_interrupt (env,PGM_SPECIFICATION ,2 );return ; } - schib =s390_cpu_physical_memory_map (env, addr, &len,1 ); -if (!schib || len !=sizeof (*schib)) { -program_interrupt (env,PGM_ADDRESSING ,2 ); - goto out; - }if (ioinst_disassemble_sch_ident (reg1, &m, &cssid, &ssid, &schid)) { -program_interrupt (env,PGM_OPERAND ,2 ); - goto out; +/* +* As operand exceptions have a lower priority than access exceptions, +* we check whether the memory area is writeable (injecting the +* access execption if it is not) first. +*/ +if (!s390_cpu_virt_mem_check_write (cpu, addr,sizeof (schib))) { +program_interrupt (env,PGM_OPERAND ,2 ); + } +return ; }trace_ioinst_sch_id ("stsch" , cssid, ssid, schid); sch =css_find_subch (m, cssid, ssid, schid);if (sch) {if (css_subch_visible (sch)) { -css_do_stsch (sch, schib); +css_do_stsch (sch, &schib); cc =0 ; }else {/* Indicate no more subchannels in this css/ss */
@@ -318,14 +319,21 @@ void ioinst_handle_stsch(S390CPU *cpu, uint64_t reg1, uint32_t ipb) cc =3 ;/* No more subchannels in this css/ss */ }else {/* Store an empty schib. */ -memset (schib,0 ,sizeof (*schib)); +memset (&schib,0 ,sizeof (schib)); cc =0 ; } } +if (cc !=3 ) { +if (s390_cpu_virt_mem_write (cpu, addr, &schib,sizeof (schib)) !=0 ) { +return ; + } + }else { +/* Access exceptions have a higher priority than cc3 */ +if (s390_cpu_virt_mem_check_write (cpu, addr,sizeof (schib)) !=0 ) { +return ; + } + }setcc (cpu, cc); - -out: -s390_cpu_physical_memory_unmap (env, schib, len,1 ); }int ioinst_handle_tsch (CPUS390XState *env,uint64_t reg1,uint32_t ipb)
Signature · 1 line
2.1.4
PATCH 19/25 s390x/ioinst: Set condition code in ioinst_handle_tsch() handler
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
Move the setting of the condition code from kvm.c into the handler function in ioinst.c itself, just like it has been done with the other handlers already (TSCH has just not been changed yet since it is called from a different dispatcher in kvm.c).
--- target-s390x/ioinst.c | 8 ++++---- target-s390x/ioinst.h | 2 +- target-s390x/kvm.c | 9 ++------- 3 files changed, 7 insertions(+), 12 deletions(-)
target-s390x/ioinst.c +4 -4
@@ -336,13 +336,13 @@ void ioinst_handle_stsch(S390CPU *cpu, uint64_t reg1, uint32_t ipb)setcc (cpu, cc); } -int ioinst_handle_tsch (CPUS390XState *env,uint64_t reg1,uint32_t ipb) +int ioinst_handle_tsch (S390CPU *cpu,uint64_t reg1,uint32_t ipb) { +CPUS390XState *env = &cpu->env;int cssid, ssid, schid, m;SubchDev *sch;IRB *irb;uint64_t addr; -int ret = -ENODEV ;int cc;hwaddr len =sizeof (*irb);
@@ -364,12 +364,12 @@ int ioinst_handle_tsch(CPUS390XState *env, uint64_t reg1, uint32_t ipb) } sch =css_find_subch (m, cssid, ssid, schid);if (sch &&css_subch_visible (sch)) { - ret =css_do_tsch (sch, irb); + cc =css_do_tsch (sch, irb);/* 0 - status pending, 1 - not status pending */ - cc = ret; }else { cc =3 ; } +setcc (cpu, cc); out:s390_cpu_physical_memory_unmap (env, irb,sizeof (*irb),1 );return cc;
target-s390x/ioinst.h +1 -1
@@ -234,7 +234,7 @@ void ioinst_handle_msch(S390CPU *cpu, uint64_t reg1, uint32_t ipb);void ioinst_handle_ssch (S390CPU *cpu,uint64_t reg1,uint32_t ipb);void ioinst_handle_stcrw (S390CPU *cpu,uint32_t ipb);void ioinst_handle_stsch (S390CPU *cpu,uint64_t reg1,uint32_t ipb); -int ioinst_handle_tsch (CPUS390XState *env,uint64_t reg1,uint32_t ipb); +int ioinst_handle_tsch (S390CPU *cpu,uint64_t reg1,uint32_t ipb);void ioinst_handle_chsc (S390CPU *cpu,uint32_t ipb);int ioinst_handle_tpi (CPUS390XState *env,uint32_t ipb); void ioinst_handle_schm(S390CPU *cpu, uint64_t reg1, uint64_t reg2,
target-s390x/kvm.c +2 -7
@@ -1337,19 +1337,14 @@ static int handle_intercept(S390CPU *cpu)static int handle_tsch (S390CPU *cpu) { -CPUS390XState *env = &cpu->env;CPUState *cs =CPU (cpu);struct kvm_run *run = cs->kvm_run;int ret;cpu_synchronize_state (cs); - ret =ioinst_handle_tsch (env, env->regs[1 ], run->s390_tsch.ipb); -if (ret >=0 ) { -/* Success; set condition code. */ -setcc (cpu, ret); - ret =0 ; - }else if (ret <-1 ) { + ret =ioinst_handle_tsch (cpu, cpu->env.regs[1 ], run->s390_tsch.ipb); +if (ret <0 ) {/* * Failure. * If an I/O interrupt had been dequeued, we have to reinject it.
Signature · 1 line
2.1.4
PATCH 20/25 s390x/ioinst: Rework memory access in TSCH instruction
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
Change the TSCH handler to use the new logical memory access functions. Since the channel should not be updated in case of a protection or access exception while writing to the guest memory, the css_do_tsch() has to be split up into two parts, one for retrieving the IRB and one for the update.
--- hw/s390x/css.c | 38 +++++++++++++++++++++++--------------- target-s390x/cpu.h | 3 ++- target-s390x/ioinst.c | 33 +++++++++++++++++++-------------- 3 files changed, 44 insertions(+), 30 deletions(-)
hw/s390x/css.c +23 -15
@@ -801,7 +801,8 @@ out:return ret; } -static void copy_irb_to_guest (IRB *dest,const IRB *src,PMCW *pmcw) +static void copy_irb_to_guest (IRB *dest,const IRB *src,PMCW *pmcw, +int *irb_len) {int i;uint16_t stctl = src->scsw.ctrl &SCSW_CTRL_MASK_STCTL ;
@@ -815,6 +816,8 @@ static void copy_irb_to_guest(IRB *dest, const IRB *src, PMCW *pmcw)for (i =0 ; i <ARRAY_SIZE (dest->ecw); i++) { dest->ecw[i] =cpu_to_be32 (src->ecw[i]); } + *irb_len =sizeof (*dest) -sizeof (dest->emw); +/* extended measurements enabled? */ if ((src->scsw.flags & SCSW_FLAGS_MASK_ESWF) || !(pmcw->flags & PMCW_FLAGS_MASK_TF) ||
@@ -832,26 +835,21 @@ static void copy_irb_to_guest(IRB *dest, const IRB *src, PMCW *pmcw) dest->emw[i] =cpu_to_be32 (src->emw[i]); } } + *irb_len =sizeof (*dest); } -int css_do_tsch (SubchDev *sch,IRB *target_irb) +int css_do_tsch_get_irb (SubchDev *sch,IRB *target_irb,int *irb_len) {SCSW *s = &sch->curr_status.scsw;PMCW *p = &sch->curr_status.pmcw;uint16_t stctl; -uint16_t fctl; -uint16_t actl;IRB irb; -int ret;if (!(p->flags & (PMCW_FLAGS_MASK_DNV |PMCW_FLAGS_MASK_ENA ))) { - ret =3 ; - goto out; +return 3 ; } stctl = s->ctrl &SCSW_CTRL_MASK_STCTL ; - fctl = s->ctrl &SCSW_CTRL_MASK_FCTL ; - actl = s->ctrl &SCSW_CTRL_MASK_ACTL ;/* Prepare the irb for the guest. */ memset (&irb,0 ,sizeof (IRB ));
@@ -876,7 +874,22 @@ int css_do_tsch(SubchDev *sch, IRB *target_irb) } }/* Store the irb to the guest. */ -copy_irb_to_guest (target_irb, &irb, p); +copy_irb_to_guest (target_irb, &irb, p, irb_len); + +return ((stctl &SCSW_STCTL_STATUS_PEND ) ==0 ); +} + +void css_do_tsch_update_subch (SubchDev *sch) +{ +SCSW *s = &sch->curr_status.scsw; +PMCW *p = &sch->curr_status.pmcw; +uint16_t stctl; +uint16_t fctl; +uint16_t actl; + + stctl = s->ctrl &SCSW_CTRL_MASK_STCTL ; + fctl = s->ctrl &SCSW_CTRL_MASK_FCTL ; + actl = s->ctrl &SCSW_CTRL_MASK_ACTL ;/* Clear conditions on subchannel, if applicable. */ if (stctl &SCSW_STCTL_STATUS_PEND ) {
@@ -913,11 +926,6 @@ int css_do_tsch(SubchDev *sch, IRB *target_irb)memset (sch->sense_data,0 ,sizeof (sch->sense_data)); } } - - ret = ((stctl &SCSW_STCTL_STATUS_PEND ) ==0 ); - -out: -return ret; }static void copy_crw_to_guest (CRW *dest,const CRW *src)
target-s390x/cpu.h +2 -1
@@ -455,7 +455,8 @@ int css_do_xsch(SubchDev *sch);int css_do_csch (SubchDev *sch);int css_do_hsch (SubchDev *sch);int css_do_ssch (SubchDev *sch,ORB *orb); -int css_do_tsch (SubchDev *sch,IRB *irb); +int css_do_tsch_get_irb (SubchDev *sch,IRB *irb,int *irb_len); +void css_do_tsch_update_subch (SubchDev *sch);int css_do_stcrw (CRW *crw);int css_do_tpi (IOIntCode *int_code,int lowcore); int css_collect_chp_desc(int m, uint8_t cssid, uint8_t f_chpid, uint8_t l_chpid,
target-s390x/ioinst.c +19 -14
@@ -341,10 +341,9 @@ int ioinst_handle_tsch(S390CPU *cpu, uint64_t reg1, uint32_t ipb)CPUS390XState *env = &cpu->env;int cssid, ssid, schid, m;SubchDev *sch; -IRB *irb; +IRB irb;uint64_t addr; -int cc; -hwaddr len =sizeof (*irb); +int cc, irb_len;if (ioinst_disassemble_sch_ident (reg1, &m, &cssid, &ssid, &schid)) {program_interrupt (env,PGM_OPERAND ,2 );
@@ -356,23 +355,29 @@ int ioinst_handle_tsch(S390CPU *cpu, uint64_t reg1, uint32_t ipb)program_interrupt (env,PGM_SPECIFICATION ,2 );return -EIO ; } - irb =s390_cpu_physical_memory_map (env, addr, &len,1 ); -if (!irb || len !=sizeof (*irb)) { -program_interrupt (env,PGM_ADDRESSING ,2 ); - cc = -EIO ; - goto out; - } + sch =css_find_subch (m, cssid, ssid, schid);if (sch &&css_subch_visible (sch)) { - cc =css_do_tsch (sch, irb); -/* 0 - status pending, 1 - not status pending */ + cc =css_do_tsch_get_irb (sch, &irb, &irb_len); }else { cc =3 ; } +/* 0 - status pending, 1 - not status pending, 3 - not operational */ +if (cc !=3 ) { +if (s390_cpu_virt_mem_write (cpu, addr, &irb, irb_len) !=0 ) { +return -EFAULT ; + } +css_do_tsch_update_subch (sch); + }else { + irb_len =sizeof (irb) -sizeof (irb.emw); +/* Access exceptions have a higher priority than cc3 */ +if (s390_cpu_virt_mem_check_write (cpu, addr, irb_len) !=0 ) { +return -EFAULT ; + } + } +setcc (cpu, cc); -out: -s390_cpu_physical_memory_unmap (env, irb,sizeof (*irb),1 ); -return cc; +return 0 ; } typedef struct ChscReq {
Signature · 1 line
2.1.4
PATCH 21/25 s390x/ioinst: Rework memory access in STCRW instruction
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
Change the handler for STCRW to use the new logical memory access functions. Since STCRW is suppressed on protection/access exceptions, we also have to make sure to re-queue the CRW in case it could not be written to the memory.
--- hw/s390x/css.c | 20 ++++++++++++++++++++ target-s390x/cpu.h | 1 + target-s390x/ioinst.c | 20 +++++++++----------- 3 files changed, 30 insertions(+), 11 deletions(-)
hw/s390x/css.c +20 -0
@@ -955,6 +955,26 @@ int css_do_stcrw(CRW *crw)return ret; } +static void copy_crw_from_guest (CRW *dest,const CRW *src) +{ + dest->flags =be16_to_cpu (src->flags); + dest->rsid =be16_to_cpu (src->rsid); +} + +void css_undo_stcrw (CRW *crw) +{ +CrwContainer *crw_cont; + + crw_cont =g_try_malloc0 (sizeof (CrwContainer)); +if (!crw_cont) { + channel_subsys->crws_lost = true; +return ; + } +copy_crw_from_guest (&crw_cont->crw, crw); + +QTAILQ_INSERT_HEAD (&channel_subsys->pending_crws, crw_cont, sibling); +} +int css_do_tpi (IOIntCode *int_code,int lowcore) {/* No pending interrupts for !KVM. */
target-s390x/cpu.h +1 -0
@@ -458,6 +458,7 @@ int css_do_ssch(SubchDev *sch, ORB *orb);int css_do_tsch_get_irb (SubchDev *sch,IRB *irb,int *irb_len);void css_do_tsch_update_subch (SubchDev *sch);int css_do_stcrw (CRW *crw); +void css_undo_stcrw (CRW *crw);int css_do_tpi (IOIntCode *int_code,int lowcore);int css_collect_chp_desc (int m,uint8_t cssid,uint8_t f_chpid,uint8_t l_chpid,int rfmt,void *buf);
target-s390x/ioinst.c +9 -11
@@ -254,10 +254,9 @@ void ioinst_handle_ssch(S390CPU *cpu, uint64_t reg1, uint32_t ipb)void ioinst_handle_stcrw (S390CPU *cpu,uint32_t ipb) { -CRW *crw; +CRW crw;uint64_t addr;int cc; -hwaddr len =sizeof (*crw);CPUS390XState *env = &cpu->env; addr =decode_basedisp_s (env, ipb);
@@ -265,17 +264,16 @@ void ioinst_handle_stcrw(S390CPU *cpu, uint32_t ipb)program_interrupt (env,PGM_SPECIFICATION ,2 );return ; } - crw =s390_cpu_physical_memory_map (env, addr, &len,1 ); -if (!crw || len !=sizeof (*crw)) { -program_interrupt (env,PGM_ADDRESSING ,2 ); - goto out; - } - cc =css_do_stcrw (crw); + + cc =css_do_stcrw (&crw);/* 0 - crw stored, 1 - zeroes stored */ -setcc (cpu, cc); -out: -s390_cpu_physical_memory_unmap (env, crw, len,1 ); +if (s390_cpu_virt_mem_write (cpu, addr, &crw,sizeof (crw)) ==0 ) { +setcc (cpu, cc); + }else if (cc ==0 ) { +/* Write failed: requeue CRW since STCRW is a suppressing instruction */ +css_undo_stcrw (&crw); + } }void ioinst_handle_stsch (S390CPU *cpu,uint64_t reg1,uint32_t ipb)
Signature · 1 line
2.1.4
PATCH 22/25 s390x/ioinst: Rework memory access in CHSC instruction
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
Change the CHSC handler to correctly use logical addresses, too.
--- target-s390x/ioinst.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
target-s390x/ioinst.c +13 -9
@@ -629,8 +629,8 @@ void ioinst_handle_chsc(S390CPU *cpu, uint32_t ipb)int reg;uint16_t len;uint16_t command; -hwaddr map_size =TARGET_PAGE_SIZE ;CPUS390XState *env = &cpu->env; +uint8_t buf[TARGET_PAGE_SIZE ];trace_ioinst ("chsc" ); reg = (ipb >>20 ) &0x00f ;
@@ -640,16 +640,20 @@ void ioinst_handle_chsc(S390CPU *cpu, uint32_t ipb)program_interrupt (env,PGM_SPECIFICATION ,2 );return ; } - req =s390_cpu_physical_memory_map (env, addr, &map_size,1 ); -if (!req || map_size !=TARGET_PAGE_SIZE ) { -program_interrupt (env,PGM_ADDRESSING ,2 ); - goto out; +/* +* Reading sizeof(ChscReq) bytes is currently enough for all of our +* present CHSC sub-handlers ... if we ever need more, we should take +* care of req->len here first. +*/ +if (s390_cpu_virt_mem_read (cpu, addr, buf,sizeof (ChscReq))) { +return ; } + req = (ChscReq *)buf; len =be16_to_cpu (req->len);/* Length field valid? */ if ((len <16 ) || (len >4088 ) || (len &7 )) {program_interrupt (env,PGM_OPERAND ,2 ); - goto out; +return ; }memset ((char *)req + len,0 ,TARGET_PAGE_SIZE - len); res = (void *)((char *)req + len);
@@ -673,9 +677,9 @@ void ioinst_handle_chsc(S390CPU *cpu, uint32_t ipb)break ; } -setcc (cpu,0 );/* Command execution complete */ -out: -s390_cpu_physical_memory_unmap (env, req, map_size,1 ); +if (!s390_cpu_virt_mem_write (cpu, addr + len, res,be16_to_cpu (res->len))) { +setcc (cpu,0 );/* Command execution complete */ + } }int ioinst_handle_tpi (CPUS390XState *env,uint32_t ipb)
Signature · 1 line
2.1.4
PATCH 23/25 s390x/ioinst: Rework memory access in TPI instruction
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
Change the handler for TPI to use the new logical memory access functions.
--- target-s390x/ioinst.c | 19 +++++++------------ target-s390x/ioinst.h | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-)
target-s390x/ioinst.c +7 -12
@@ -682,12 +682,13 @@ void ioinst_handle_chsc(S390CPU *cpu, uint32_t ipb) } } -int ioinst_handle_tpi (CPUS390XState *env,uint32_t ipb) +int ioinst_handle_tpi (S390CPU *cpu,uint32_t ipb) { +CPUS390XState *env = &cpu->env;uint64_t addr;int lowcore; -IOIntCode *int_code; -hwaddr len, orig_len; +IOIntCode int_code; +hwaddr len;int ret;trace_ioinst ("tpi" );
@@ -699,16 +700,10 @@ int ioinst_handle_tpi(CPUS390XState *env, uint32_t ipb) lowcore = addr ?0 :1 ; len = lowcore ?8 /* two words */ :12 /* three words */ ; - orig_len = len; - int_code =s390_cpu_physical_memory_map (env, addr, &len,1 ); -if (!int_code || (len != orig_len)) { -program_interrupt (env,PGM_ADDRESSING ,2 ); - ret = -EIO ; - goto out; + ret =css_do_tpi (&int_code, lowcore); +if (ret ==1 ) { +s390_cpu_virt_mem_write (cpu, lowcore ?184 : addr, &int_code, len); } - ret =css_do_tpi (int_code, lowcore); -out: -s390_cpu_physical_memory_unmap (env, int_code, len,1 );return ret; }
target-s390x/ioinst.h +1 -1
@@ -236,7 +236,7 @@ void ioinst_handle_stcrw(S390CPU *cpu, uint32_t ipb);void ioinst_handle_stsch (S390CPU *cpu,uint64_t reg1,uint32_t ipb);int ioinst_handle_tsch (S390CPU *cpu,uint64_t reg1,uint32_t ipb);void ioinst_handle_chsc (S390CPU *cpu,uint32_t ipb); -int ioinst_handle_tpi (CPUS390XState *env,uint32_t ipb); +int ioinst_handle_tpi (S390CPU *cpu,uint32_t ipb);void ioinst_handle_schm (S390CPU *cpu,uint64_t reg1,uint64_t reg2,uint32_t ipb);void ioinst_handle_rsch (S390CPU *cpu,uint64_t reg1);
Signature · 1 line
2.1.4
PATCH 24/25 s390x/pci: Rework memory access in zpci instruction
In reply to Jens FreimannFrom: Frank Blaschka <[email protected]>
Change zpci instructions to use the new logical memory access functions.
--- hw/s390x/s390-pci-inst.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-)
hw/s390x/s390-pci-inst.c +28 -9
@@ -155,7 +155,9 @@ int clp_service_call(S390CPU *cpu, uint8_t r2)return 0 ; } -cpu_physical_memory_read (env->regs[r2], buffer,sizeof (*reqh)); +if (s390_cpu_virt_mem_read (cpu, env->regs[r2], buffer,sizeof (*reqh))) { +return 0 ; + } reqh = (ClpReqHdr *)buffer; req_len =lduw_p (&reqh->len);if (req_len <16 || req_len >8184 || (req_len %8 !=0 )) {
@@ -163,7 +165,10 @@ int clp_service_call(S390CPU *cpu, uint8_t r2)return 0 ; } -cpu_physical_memory_read (env->regs[r2], buffer, req_len +sizeof (*resh)); +if (s390_cpu_virt_mem_read (cpu, env->regs[r2], buffer, + req_len +sizeof (*resh))) { +return 0 ; + } resh = (ClpRspHdr *)(buffer + req_len); res_len =lduw_p (&resh->len);if (res_len <8 || res_len >8176 || (res_len %8 !=0 )) {
@@ -175,7 +180,10 @@ int clp_service_call(S390CPU *cpu, uint8_t r2)return 0 ; } -cpu_physical_memory_read (env->regs[r2], buffer, req_len + res_len); +if (s390_cpu_virt_mem_read (cpu, env->regs[r2], buffer, + req_len + res_len)) { +return 0 ; + }if (req_len !=32 ) {stw_p (&resh->rsp,CLP_RC_LEN );
@@ -269,7 +277,10 @@ int clp_service_call(S390CPU *cpu, uint8_t r2) } out: -cpu_physical_memory_write (env->regs[r2], buffer, req_len + res_len); +if (s390_cpu_virt_mem_write (cpu, env->regs[r2], buffer, + req_len + res_len)) { +return 0 ; + }setcc (cpu, cc);return 0 ; }
@@ -539,10 +550,10 @@ int pcistb_service_call(S390CPU *cpu, uint8_t r1, uint8_t r3, uint64_t gaddr)S390PCIBusDevice *pbdev;MemoryRegion *mr;int i; -uint64_t val;uint32_t fh;uint8_t pcias;uint8_t len; +uint8_t buffer[128 ];if (env->psw.mask &PSW_MASK_PSTATE ) {program_interrupt (env,PGM_PRIVILEGED ,6 );
@@ -590,9 +601,12 @@ int pcistb_service_call(S390CPU *cpu, uint8_t r1, uint8_t r3, uint64_t gaddr)return 0 ; } +if (s390_cpu_virt_mem_read (cpu, gaddr, buffer, len)) { +return 0 ; + } +for (i =0 ; i < len /8 ; i++) { - val =ldq_phys (&address_space_memory, gaddr + i *8 ); -io_mem_write (mr, env->regs[r3] + i *8 , val,8 ); +io_mem_write (mr, env->regs[r3] + i *8 ,ldq_p (buffer + i *8 ),8 ); }setcc (cpu,ZPCI_PCI_LS_OK );
@@ -709,7 +723,9 @@ int mpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba)return 0 ; } -cpu_physical_memory_read (fiba, (uint8_t *)&fib,sizeof (fib)); +if (s390_cpu_virt_mem_read (cpu, fiba, (uint8_t *)&fib,sizeof (fib))) { +return 0 ; + }switch (oc) {case ZPCI_MOD_FC_REG_INT :
@@ -809,7 +825,10 @@ int stpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba) fib.fc |=0x10 ; } -cpu_physical_memory_write (fiba, (uint8_t *)&fib,sizeof (fib)); +if (s390_cpu_virt_mem_write (cpu, fiba, (uint8_t *)&fib,sizeof (fib))) { +return 0 ; + } +setcc (cpu, cc);return 0 ; }
Signature · 1 line
2.1.4
PATCH 25/25 s390x/helper: Remove s390_cpu_physical_memory_map
In reply to Jens FreimannFrom: Thomas Huth <[email protected]>
The function is now not used anymore, so it can be removed safely.
--- target-s390x/cpu.h | 4 ---- target-s390x/helper.c | 25 ------------------------- 2 files changed, 29 deletions(-)
target-s390x/cpu.h +0 -4
@@ -350,10 +350,6 @@ int s390_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int rw,#include "ioinst.h" #ifndef CONFIG_USER_ONLY -void *s390_cpu_physical_memory_map (CPUS390XState *env,hwaddr addr,hwaddr *len, -int is_write); -void s390_cpu_physical_memory_unmap (CPUS390XState *env,void *addr,hwaddr len, -int is_write);static inline hwaddr decode_basedisp_s (CPUS390XState *env,uint32_t ipb) {hwaddr addr =0 ;
target-s390x/helper.c +0 -25
@@ -229,31 +229,6 @@ static void cpu_unmap_lowcore(LowCore *lowcore)cpu_physical_memory_unmap (lowcore,sizeof (LowCore),1 ,sizeof (LowCore)); } -void *s390_cpu_physical_memory_map (CPUS390XState *env,hwaddr addr,hwaddr *len, -int is_write) -{ -hwaddr start = addr; - -/* Mind the prefix area. */ -if (addr <8192 ) { -/* Map the lowcore. */ - start += env->psa; - *len =MIN (*len,8192 - addr); - }else if ((addr >= env->psa) && (addr < env->psa +8192 )) { -/* Map the 0 page. */ - start -= env->psa; - *len =MIN (*len,8192 - start); - } - -return cpu_physical_memory_map (start, len, is_write); -} - -void s390_cpu_physical_memory_unmap (CPUS390XState *env,void *addr,hwaddr len, -int is_write) -{ -cpu_physical_memory_unmap (addr, len, is_write, len); -} -static void do_svc_interrupt (CPUS390XState *env) {uint64_t mask, addr;
Signature · 1 line
2.1.4
Christian Borntraeger
AppliedAm 12.02.2015 um 18:09 schrieb Jens Freimann:
Quoted 35 lines
Cornelia, Alex, Christian,
this patches are a rework of guest memory access to allow access to guest logical address space.
Frank Blaschka (1):
s390x/pci: Rework memory access in zpci instructionThomas Huth (24):
s390x/mmu: Movemmu_translate()and friends to separate file s390x/mmu: Fix the check for the real-space designation bit s390x/mmu: Fix the handling of the table levels s390x/mmu: Check table length and offset fields s390x/mmu: Skip exceptions properly when translating addresses for
debug
s390x/mmu: Fix translation exception code in lowcore s390x/mmu: Fix exception types when checking the ASCEs s390x/mmu: Fix the exception codes for illegal table entries s390x/mmu: Add support for read-only regions
s390x/mmu: Renaming related to the ASCE confusion s390x/mmu: Check bit 52 in page table entry
s390x/mmu: Clean upmmu_translate_asc()
s390x/kvm: Add function for injecting pgm access exceptions s390x/mmu: Add function for accessing guest memory s390x/css: Make schib parameter ofcss_do_mschconst s390x/ioinst: Rework memory access in MSCH instruction s390x/ioinst: Rework memory access in SSCH instruction s390x/ioinst: Rework memory access in STSCH instruction s390x/ioinst: Set condition code inioinst_handle_tsch()handler s390x/ioinst: Rework memory access in TSCH instruction s390x/ioinst: Rework memory access in STCRW instruction s390x/ioinst: Rework memory access in CHSC instruction s390x/ioinst: Rework memory access in TPI instruction s390x/helper: Removes390_cpu_physical_memory_map
Quoted 13 lines
hw/s390x/css.c | 60 ++++-- hw/s390x/s390-pci-inst.c | 37 +++- target-s390x/Makefile.objs | 2 +- target-s390x/cpu.h | 32 ++- target-s390x/helper.c | 356 +--------------------------------- target-s390x/ioinst.c | 172 ++++++++--------- target-s390x/ioinst.h | 4 +- target-s390x/kvm.c | 21 +- target-s390x/mem_helper.c | 12 +- target-s390x/mmu_helper.c | 472 +++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 681 insertions(+), 487 deletions(-) create mode 100644 target-s390x/mmu_helper.c
Applied to s390-next.
Thanks