s390/kvm: Handle guest-related program interrupts in KVM
Subsystems (5)
Claudio Imbrenda
maintainerv3 cover s390/kvm: Handle guest-related program interrupts in KVM
This patchseries moves the handling of host program interrupts that happen while a KVM guest is running into KVM itself.
All program interrupts that happen in the host while a KVM guest is running are due to DAT exceptions. It is cleaner and more maintainable to have KVM handle those.
As a side effect, some more cleanups is also possible.
Moreover, this series serves as a foundation for an upcoming series that will further move as much s390 KVM memory managament as possible into KVM itself, and away from the rest of the kernel.
Version 1 and 2 of this series were sent privately, which is also where the various reviews and acks come from.
Claudio Imbrenda (8):
s390/entry: Remove __GMAP_ASCE and use _PIF_GUEST_FAULT again s390/kvm: Remove kvm_arch_fault_in_page() s390/mm/gmap: Refactor gmap_fault() and add support for pfault s390/mm/gmap: Fix __gmap_fault() return code s390/mm/fault: Handle guest-related program interrupts in KVM s390/kvm: Stop using gmap_{en,dis}able() s390/mm/gmap: Remove gmap_{en,dis}able()
s390: Remove gmap pointer from lowcore
Heiko Carstens (3):
s390/mm: Simplify get_fault_type() s390/mm: Get rid of fault type switch statements s390/mm: Convert to LOCK_MM_AND_FIND_VMA
arch/s390/Kconfig | 1 + arch/s390/include/asm/gmap.h | 3 - arch/s390/include/asm/kvm_host.h | 3 + arch/s390/include/asm/lowcore.h | 3 +- arch/s390/include/asm/processor.h | 5 +- arch/s390/include/asm/ptrace.h | 2 + arch/s390/kernel/asm-offsets.c | 3 - arch/s390/kernel/entry.S | 44 ++----- arch/s390/kernel/traps.c | 23 +++- arch/s390/kvm/intercept.c | 4 +- arch/s390/kvm/kvm-s390.c | 139 ++++++++++++++------- arch/s390/kvm/kvm-s390.h | 8 +- arch/s390/kvm/vsie.c | 17 ++- arch/s390/mm/fault.c | 195 +++++------------------------- arch/s390/mm/gmap.c | 151 +++++++++++++++-------- 15 files changed, 278 insertions(+), 323 deletions(-)
Signature · 1 line
2.47.0
Claudio Imbrenda
maintainerPATCH v3 1/11 s390/entry: Remove __GMAP_ASCE and use _PIF_GUEST_FAULT again
Now that the guest ASCE is passed as a parameter to __sie64a(), _PIF_GUEST_FAULT can be used again to determine whether the fault was a guest or host fault.
Since the guest ASCE will not be taken from the gmap pointer in lowcore anymore, __GMAP_ASCE can be removed. For the same reason the guest ASCE needs now to be saved into the cr1 save area unconditionally.
--- arch/s390/include/asm/ptrace.h | 2 ++ arch/s390/kernel/asm-offsets.c | 2 -- arch/s390/kernel/entry.S | 26 ++++++++++++++------------ arch/s390/mm/fault.c | 6 ++---- 4 files changed, 18 insertions(+), 18 deletions(-)
arch/s390/include/asm/ptrace.h +2 -0
@@ -14,11 +14,13 @@#define PIF_SYSCALL 0/* inside a system call */ #define PIF_EXECVE_PGSTE_RESTART 1/* restart execve for PGSTE binaries */ #define PIF_SYSCALL_RET_SET 2/* return value was set via ptrace */ +#define PIF_GUEST_FAULT 3/* indicates program check in sie64a */ #define PIF_FTRACE_FULL_REGS 4/* all register contents valid (ftrace) */ #define _PIF_SYSCALL BIT(PIF_SYSCALL)#define _PIF_EXECVE_PGSTE_RESTART BIT(PIF_EXECVE_PGSTE_RESTART)#define _PIF_SYSCALL_RET_SET BIT(PIF_SYSCALL_RET_SET) +#define _PIF_GUEST_FAULT BIT(PIF_GUEST_FAULT)#define _PIF_FTRACE_FULL_REGS BIT(PIF_FTRACE_FULL_REGS)#define PSW32_MASK_PER _AC(0x40000000, UL)
arch/s390/kernel/asm-offsets.c +0 -2
@@ -13,7 +13,6 @@#include <linux/purgatory.h> #include <linux/pgtable.h> #include <linux/ftrace.h> -#include <asm/gmap.h> #include <asm/stacktrace.h> int main (void )
@@ -161,7 +160,6 @@ int main(void)OFFSET (__LC_PGM_TDB, lowcore, pgm_tdb);BLANK ();/* gmap/sie offsets */ -OFFSET (__GMAP_ASCE, gmap, asce);OFFSET (__SIE_PROG0C, kvm_s390_sie_block, prog0c);OFFSET (__SIE_PROG20, kvm_s390_sie_block, prog20);/* kexec_sha_region */
arch/s390/kernel/entry.S +14 -12
@@ -327,13 +327,23 @@ SYM_CODE_START(pgm_check_handler) GET_LC %r13 stpt __LC_SYS_ENTER_TIMER(%r13) BPOFF - lgr %r10,%r15 lmg %r8,%r9,__LC_PGM_OLD_PSW(%r13) + xgr %r10,%r10 + xgr %r12,%r12 tmhh %r8,0x0001 # coming from user space? jno .Lpgm_skip_asce lctlg %c1,%c1,__LC_KERNEL_ASCE(%r13) j 3f # -> fault in user space .Lpgm_skip_asce: +#if IS_ENABLED(CONFIG_KVM) + lg %r11,__LC_CURRENT(%r13) + tm __TI_sie(%r11),0xff + jz 1f + BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST + SIEEXIT __SF_SIE_CONTROL(%r15),%r13 + lg %r12,__SF_SIE_GUEST_ASCE(%r15) + lghi %r10,_PIF_GUEST_FAULT +#endif 1: tmhh %r8,0x4000 # PER bit set in old PSW ? jnz 2f # -> enabled, can't be a double fault tm __LC_PGM_ILC+3(%r13),0x80 # check for per exception
@@ -344,21 +354,13 @@ SYM_CODE_START(pgm_check_handler) CHECK_VMAP_STACK __LC_SAVE_AREA,%r13,4f 3: lg %r15,__LC_KERNEL_STACK(%r13) 4: la %r11,STACK_FRAME_OVERHEAD(%r15) - xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11) + stg %r10,__PT_FLAGS(%r11) + stg %r12,__PT_CR1(%r11) xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15) stmg %r0,%r7,__PT_R0(%r11) mvc __PT_R8(64,%r11),__LC_SAVE_AREA(%r13) mvc __PT_LAST_BREAK(8,%r11),__LC_PGM_LAST_BREAK(%r13) - stctg %c1,%c1,__PT_CR1(%r11) -#if IS_ENABLED(CONFIG_KVM) - ltg %r12,__LC_GMAP(%r13) - jz 5f - clc __GMAP_ASCE(8,%r12), __PT_CR1(%r11) - jne 5f - BPENTER __SF_SIE_FLAGS(%r10),_TIF_ISOLATE_BP_GUEST - SIEEXIT __SF_SIE_CONTROL(%r10),%r13 -#endif -5: stmg %r8,%r9,__PT_PSW(%r11) + stmg %r8,%r9,__PT_PSW(%r11) # clear user controlled registers to prevent speculative use xgr %r0,%r0 xgr %r1,%r1
arch/s390/mm/fault.c +2 -4
@@ -68,15 +68,13 @@ early_initcall(fault_init);static enum fault_type get_fault_type (struct pt_regs *regs) {union teid teid = { .val = regs->int_parm_long }; -struct gmap *gmap;if (likely (teid.as ==PSW_BITS_AS_PRIMARY )) {if (user_mode (regs))return USER_FAULT ;if (!IS_ENABLED (CONFIG_PGSTE ))return KERNEL_FAULT ; - gmap = (struct gmap *)get_lowcore ()->gmap; -if (gmap && gmap->asce == regs->cr1) +if (test_pt_regs_flag (regs,PIF_GUEST_FAULT ))return GMAP_FAULT ;return KERNEL_FAULT ; }
@@ -187,7 +185,7 @@ static void dump_fault_info(struct pt_regs *regs)pr_cont ("user " );break ;case GMAP_FAULT : - asce = ((struct gmap *)get_lowcore ()->gmap)->asce; + asce = regs->cr1;pr_cont ("gmap " );break ;case KERNEL_FAULT :
Signature · 1 line
2.47.0
Claudio Imbrenda
maintainerPATCH v3 2/11 s390/kvm: Remove kvm_arch_fault_in_page()
In reply to Claudio Imbrendakvm_arch_fault_in_page() is a useless wrapper around gmap_fault(); just use gmap_fault() directly instead.
--- arch/s390/kvm/intercept.c | 4 ++-- arch/s390/kvm/kvm-s390.c | 18 +----------------- arch/s390/kvm/kvm-s390.h | 1 - 3 files changed, 3 insertions(+), 20 deletions(-)
arch/s390/kvm/intercept.c +2 -2
@@ -367,7 +367,7 @@ static int handle_mvpg_pei(struct kvm_vcpu *vcpu) reg2, &srcaddr, GACC_FETCH, 0);if (rc)return kvm_s390_inject_prog_cond (vcpu, rc); - rc =kvm_arch_fault_in_page (vcpu, srcaddr,0 ); + rc =gmap_fault (vcpu->arch.gmap, srcaddr,0 );if (rc !=0 )return rc;
@@ -376,7 +376,7 @@ static int handle_mvpg_pei(struct kvm_vcpu *vcpu) reg1, &dstaddr, GACC_STORE, 0);if (rc)return kvm_s390_inject_prog_cond (vcpu, rc); - rc =kvm_arch_fault_in_page (vcpu, dstaddr,1 ); + rc =gmap_fault (vcpu->arch.gmap, dstaddr,FAULT_FLAG_WRITE );if (rc !=0 )return rc;
arch/s390/kvm/kvm-s390.c +1 -17
@@ -4579,22 +4579,6 @@ int kvm_s390_try_set_tod_clock(struct kvm *kvm, const struct kvm_s390_vm_tod_cloreturn 1 ; } -/** -* kvm_arch_fault_in_page - fault-in guest page if necessary -* @vcpu: The corresponding virtual cpu -* @gpa: Guest physical address -* @writable: Whether the page should be writable or not -* -* Make sure that a guest page has been faulted-in on the host. -* -* Return: Zero on success, negative error code otherwise. -*/ -long kvm_arch_fault_in_page (struct kvm_vcpu *vcpu,gpa_t gpa,int writable) -{ -return gmap_fault (vcpu->arch.gmap, gpa, - writable ?FAULT_FLAG_WRITE :0 ); -} -static void __kvm_inject_pfault_token (struct kvm_vcpu *vcpu,bool start_token,unsigned long token) {
@@ -4797,7 +4781,7 @@ static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)if (kvm_arch_setup_async_pf (vcpu))return 0 ; vcpu->stat.pfault_sync++; -return kvm_arch_fault_in_page (vcpu, current->thread.gmap_addr,1 ); +return gmap_fault (vcpu->arch.gmap, current->thread.gmap_addr,FAULT_FLAG_WRITE ); }return vcpu_post_run_fault_in_sie (vcpu); }
arch/s390/kvm/kvm-s390.h +0 -1
@@ -394,7 +394,6 @@ int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu);/* implemented in kvm-s390.c */ int kvm_s390_try_set_tod_clock (struct kvm *kvm,const struct kvm_s390_vm_tod_clock *gtod); -long kvm_arch_fault_in_page (struct kvm_vcpu *vcpu,gpa_t gpa,int writable);int kvm_s390_store_status_unloaded (struct kvm_vcpu *vcpu,unsigned long addr);int kvm_s390_vcpu_store_status (struct kvm_vcpu *vcpu,unsigned long addr);int kvm_s390_vcpu_start (struct kvm_vcpu *vcpu);
Signature · 1 line
2.47.0
Claudio Imbrenda
maintainerPATCH v3 3/11 s390/mm/gmap: Refactor gmap_fault() and add support for pfault
In reply to Claudio ImbrendaWhen specifying FAULT_FLAG_RETRY_NOWAIT as flag for gmap_fault(), the gmap fault will be processed only if it can be resolved quickly and without sleeping. This will be needed for pfault.
Refactor gmap_fault() to improve readability.
--- arch/s390/mm/gmap.c | 119 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 100 insertions(+), 19 deletions(-)
arch/s390/mm/gmap.c +100 -19
@@ -637,44 +637,125 @@ int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr) }/** -* gmap_fault - resolve a fault on a guest address +* fixup_user_fault_nowait - manually resolve a user page fault without waiting +* @mm: mm_struct of target mm +* @address: user address +* @fault_flags:flags to pass down to handle_mm_fault() +* @unlocked: did we unlock the mmap_lock while retrying +* +* This function behaves similarly to fixup_user_fault(), but it guarantees +* that the fault will be resolved without waiting. The function might drop +* and re-acquire the mm lock, in which case @unlocked will be set to true. +* +* The guarantee is that the fault is handled without waiting, but the +* function itself might sleep, due to the lock. +* +* Context: Needs to be called with mm->mmap_lock held in read mode, and will +* return with the lock held in read mode; @unlocked will indicate whether +* the lock has been dropped and re-acquired. This is the same behaviour as +* fixup_user_fault(). +* +* Return: 0 on success, -EAGAIN if the fault cannot be resolved without +* waiting, -EFAULT if the fault cannot be resolved, -ENOMEM if out of +* memory. +*/ +static int fixup_user_fault_nowait (struct mm_struct *mm,unsigned long address, +unsigned int fault_flags,bool *unlocked) +{ +struct vm_area_struct *vma; +unsigned int test_flags; +vm_fault_t fault; +int rc; + + fault_flags |=FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_RETRY_NOWAIT ; + test_flags = fault_flags &FAULT_FLAG_WRITE ?VM_WRITE :VM_READ ; + + vma =find_vma (mm, address); +if (unlikely (!vma || address < vma->vm_start)) +return -EFAULT ; +if (unlikely (!(vma->vm_flags & test_flags))) +return -EFAULT ; + + fault =handle_mm_fault (vma, address, fault_flags,NULL ); +/* the mm lock has been dropped, take it again */ +if (fault &VM_FAULT_COMPLETED ) { + *unlocked = true; +mmap_read_lock (mm); +return 0 ; + } +/* the mm lock has not been dropped */ +if (fault &VM_FAULT_ERROR ) { + rc =vm_fault_to_errno (fault,0 ); +BUG_ON (!rc); +return rc; + } +/* the mm lock has not been dropped because of FAULT_FLAG_RETRY_NOWAIT */ +if (fault &VM_FAULT_RETRY ) +return -EAGAIN ; +/* nothing needed to be done and the mm lock has not been dropped */ +return 0 ; +} + +/** +* __gmap_fault - resolve a fault on a guest address * @gmap: pointer to guest mapping meta data structure * @gaddr: guest address * @fault_flags: flags to pass down to handle_mm_fault() * -* Returns 0 on success, -ENOMEM for out of memory conditions, and -EFAULT -* if the vm address is already mapped to a different guest segment. +* Context: Needs to be called with mm->mmap_lock held in read mode. Might +* drop and re-acquire the lock. Will always return with the lock held. */ -int gmap_fault (struct gmap *gmap,unsigned long gaddr, -unsigned int fault_flags) +static int __gmap_fault (struct gmap *gmap,unsigned long gaddr,unsigned int fault_flags) {unsigned long vmaddr; -int rc;bool unlocked; - -mmap_read_lock (gmap->mm); +int rc =0 ; retry: unlocked = false; + vmaddr =__gmap_translate (gmap, gaddr); -if (IS_ERR_VALUE (vmaddr)) { - rc = vmaddr; - goto out_up; - } -if (fixup_user_fault (gmap->mm, vmaddr, fault_flags, - &unlocked)) { - rc = -EFAULT ; - goto out_up; +if (IS_ERR_VALUE (vmaddr)) +return vmaddr; + +if (fault_flags &FAULT_FLAG_RETRY_NOWAIT ) { + rc =fixup_user_fault_nowait (gmap->mm, vmaddr, fault_flags, &unlocked); +if (rc) +return rc; + }else if (fixup_user_fault (gmap->mm, vmaddr, fault_flags, &unlocked)) { +return -EFAULT ; }/* * In the case that fixup_user_fault unlocked the mmap_lock during -* faultin redo __gmap_translate to not race with a map/unmap_segment. +* fault-in, redo __gmap_translate() to avoid racing with a +* map/unmap_segment. +* In particular, __gmap_translate(), fixup_user_fault{,_nowait}(), +* and __gmap_link() must all be called atomically in one go; if the +* lock had been dropped in between, a retry is needed. */ if (unlocked) goto retry; - rc =__gmap_link (gmap, gaddr, vmaddr); -out_up: +return __gmap_link (gmap, gaddr, vmaddr); +} + +/** +* gmap_fault - resolve a fault on a guest address +* @gmap: pointer to guest mapping meta data structure +* @gaddr: guest address +* @fault_flags: flags to pass down to handle_mm_fault() +* +* Returns 0 on success, -ENOMEM for out of memory conditions, -EFAULT if the +* vm address is already mapped to a different guest segment, and -EAGAIN if +* FAULT_FLAG_RETRY_NOWAIT was specified and the fault could not be processed +* immediately. +*/ +int gmap_fault (struct gmap *gmap,unsigned long gaddr,unsigned int fault_flags) +{ +int rc; + +mmap_read_lock (gmap->mm); + rc =__gmap_fault (gmap, gaddr, fault_flags);mmap_read_unlock (gmap->mm);return rc; }
Signature · 1 line
2.47.0
Re: [PATCH v3 03/11] s390/mm/gmap: Refactor gmap_fault() and add support for pfault
Quoted 11 lines · Claudio Imbrenda
When specifying
FAULT_FLAG_RETRY_NOWAITas flag forgmap_fault(), the gmap fault will be processed only if it can be resolved quickly and without sleeping. This will be needed for pfault.Refactor
gmap_fault()to improve readability.Signed-off-by Claudio Imbrenda <[email protected]>--- arch/s390/mm/gmap.c | 119 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 100 insertions(+), 19 deletions(-)
...
arch/s390/mm/gmap.c int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr) · line 670
Quoted 9 lines
arch/s390/mm/gmap.c +9
-0+static int fixup_user_fault_nowait (struct mm_struct *mm,unsigned long address, +unsigned int fault_flags,bool *unlocked) +{ +struct vm_area_struct *vma; +unsigned int test_flags; +vm_fault_t fault; +int rc; + + fault_flags |=FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_RETRY_NOWAIT ;
^^^^^^^^^^^^^^^^^^^^^^^
This is not necessary, because of
arch/s390/mm/gmap.c int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr) · line 722
Quoted 2 lines
arch/s390/mm/gmap.c +2
-0+if (fault_flags &FAULT_FLAG_RETRY_NOWAIT ) { + rc =fixup_user_fault_nowait (gmap->mm, vmaddr, fault_flags, &unlocked);
this.
In any case:
Claudio Imbrenda
maintainerPATCH v3 4/11 s390/mm/gmap: Fix __gmap_fault() return code
In reply to Claudio ImbrendaErrors in fixup_user_fault() were masked and -EFAULT was returned for any error, including out of memory.
Fix this by returning the correct error code. This means that in many cases the error code will be propagated all the way to userspace.
--- arch/s390/mm/gmap.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
arch/s390/mm/gmap.c +5 -6
@@ -718,13 +718,12 @@ static int __gmap_fault(struct gmap *gmap, unsigned long gaddr, unsigned int fauif (IS_ERR_VALUE (vmaddr))return vmaddr; -if (fault_flags &FAULT_FLAG_RETRY_NOWAIT ) { +if (fault_flags &FAULT_FLAG_RETRY_NOWAIT ) rc =fixup_user_fault_nowait (gmap->mm, vmaddr, fault_flags, &unlocked); -if (rc) -return rc; - }else if (fixup_user_fault (gmap->mm, vmaddr, fault_flags, &unlocked)) { -return -EFAULT ; - } +else + rc =fixup_user_fault (gmap->mm, vmaddr, fault_flags, &unlocked); +if (rc) +return rc;/* * In the case that fixup_user_fault unlocked the mmap_lock during * fault-in, redo __gmap_translate() to avoid racing with a
Signature · 1 line
2.47.0
Claudio Imbrenda
maintainerPATCH v3 5/11 s390/mm/fault: Handle guest-related program interrupts in KVM
In reply to Claudio ImbrendaAny program interrupt that happens in the host during the execution of a KVM guest will now short circuit the fault handler and return to KVM immediately. Guest fault handling (including pfault) will happen entirely inside KVM.
When sie64a() returns zero, current->thread.gmap_int_code will contain the program interrupt number that caused the exit, or zero if the exit was not caused by a host program interrupt.
KVM will now take care of handling all guest faults in vcpu_post_run().
Since gmap faults will not be visible by the rest of the kernel, remove GMAP_FAULT, the linux fault handlers for secure execution faults, the exception table entries for the sie instruction, the nop padding after the sie instruction, and all other references to guest faults from the s390 code.
--- arch/s390/include/asm/kvm_host.h | 3 + arch/s390/include/asm/processor.h | 5 +- arch/s390/kernel/entry.S | 22 ------ arch/s390/kernel/traps.c | 23 ++++-- arch/s390/kvm/kvm-s390.c | 116 ++++++++++++++++++++++++------ arch/s390/kvm/kvm-s390.h | 7 ++ arch/s390/kvm/vsie.c | 13 ++-- arch/s390/mm/fault.c | 99 +------------------------ 8 files changed, 132 insertions(+), 156 deletions(-)
arch/s390/include/asm/kvm_host.h +3 -0
@@ -527,6 +527,9 @@ struct kvm_vcpu_stat {#define PGM_REGION_FIRST_TRANS 0x39#define PGM_REGION_SECOND_TRANS 0x3a#define PGM_REGION_THIRD_TRANS 0x3b +#define PGM_SECURE_STORAGE_ACCESS 0x3d +#define PGM_NON_SECURE_STORAGE_ACCESS 0x3e +#define PGM_SECURE_STORAGE_VIOLATION 0x3f#define PGM_MONITOR 0x40#define PGM_PER 0x80#define PGM_CRYPTO_OPERATION 0x119
arch/s390/include/asm/processor.h +2 -3
@@ -39,6 +39,7 @@#include <asm/runtime_instr.h> #include <asm/irqflags.h> #include <asm/alternative.h> +#include <asm/fault.h> struct pcpu {unsigned long ec_mask;/* bit mask for ec_xxx functions */
@@ -187,10 +188,8 @@ struct thread_struct {unsigned long hardirq_timer;/* task cputime in hardirq context */ unsigned long softirq_timer;/* task cputime in softirq context */ const sys_call_ptr_t *sys_call_table;/* system call table address */ -unsigned long gmap_addr;/* address of last gmap fault. */ -unsigned int gmap_write_flag;/* gmap fault write indication */ +union teid gmap_teid;/* address and flags of last gmap fault */ unsigned int gmap_int_code;/* int code of last gmap fault */ -unsigned int gmap_pfault;/* signal of a pending guest pfault */ int ufpu_flags;/* user fpu flags */ int kfpu_flags;/* kernel fpu flags */
arch/s390/kernel/entry.S +0 -22
@@ -222,17 +222,6 @@ SYM_FUNC_START(__sie64a) lctlg %c1,%c1,__LC_KERNEL_ASCE(%r14) # load primary asce lg %r14,__LC_CURRENT(%r14) mvi __TI_sie(%r14),0 -# some program checks are suppressing. C code (e.g. do_protection_exception) -# will rewind the PSW by the ILC, which is often 4 bytes in case of SIE. There -# are some corner cases (e.g. runtime instrumentation) where ILC is unpredictable. -# Other instructions between __sie64a and .Lsie_done should not cause program -# interrupts. So lets use 3 nops as a landing pad for all possible rewinds. -.Lrewind_pad6: - nopr 7 -.Lrewind_pad4: - nopr 7 -.Lrewind_pad2: - nopr 7 SYM_INNER_LABEL(sie_exit, SYM_L_GLOBAL) lg %r14,__SF_SIE_SAVEAREA(%r15) # load guest register save area stmg %r0,%r13,0(%r14) # save guest gprs 0-13
@@ -244,15 +233,6 @@ SYM_INNER_LABEL(sie_exit, SYM_L_GLOBAL) lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers lg %r2,__SF_SIE_REASON(%r15) # return exit reason code BR_EX %r14 -.Lsie_fault: - lghi %r14,-EFAULT - stg %r14,__SF_SIE_REASON(%r15) # set exit reason code - j sie_exit - - EX_TABLE(.Lrewind_pad6,.Lsie_fault) - EX_TABLE(.Lrewind_pad4,.Lsie_fault) - EX_TABLE(.Lrewind_pad2,.Lsie_fault) - EX_TABLE(sie_exit,.Lsie_fault) SYM_FUNC_END(__sie64a) EXPORT_SYMBOL(__sie64a) EXPORT_SYMBOL(sie_exit)
@@ -341,7 +321,6 @@ SYM_CODE_START(pgm_check_handler) jz 1f BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST SIEEXIT __SF_SIE_CONTROL(%r15),%r13 - lg %r12,__SF_SIE_GUEST_ASCE(%r15) lghi %r10,_PIF_GUEST_FAULT #endif 1: tmhh %r8,0x4000 # PER bit set in old PSW ?
@@ -355,7 +334,6 @@ SYM_CODE_START(pgm_check_handler) 3: lg %r15,__LC_KERNEL_STACK(%r13) 4: la %r11,STACK_FRAME_OVERHEAD(%r15) stg %r10,__PT_FLAGS(%r11) - stg %r12,__PT_CR1(%r11) xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15) stmg %r0,%r7,__PT_R0(%r11) mvc __PT_R8(64,%r11),__LC_SAVE_AREA(%r13)
arch/s390/kernel/traps.c +18 -5
@@ -31,6 +31,7 @@#include <asm/asm-extable.h> #include <asm/vtime.h> #include <asm/fpu.h> +#include <asm/fault.h> #include "entry.h" static inline void __user *get_trap_ip (struct pt_regs *regs)
@@ -317,9 +318,23 @@ void noinstr __do_pgm_check(struct pt_regs *regs)struct lowcore *lc =get_lowcore ();irqentry_state_t state;unsigned int trapnr; +union teid teid = { .val = lc->trans_exc_code }; regs->int_code = lc->pgm_int_code; - regs->int_parm_long = lc->trans_exc_code; + regs->int_parm_long = teid.val; + +/* +* In case of a guest fault, short-circuit the fault handler and return. +* This way the sie64a() function will return 0; fault address and +* other relevant bits are saved in current->thread.gmap_teid, and +* the fault number in current->thread.gmap_int_code. KVM will be +* able to use this information to handle the fault. +*/ +if (test_pt_regs_flag (regs,PIF_GUEST_FAULT ) && (teid.as ==PSW_BITS_AS_PRIMARY )) { + current->thread.gmap_teid.val = regs->int_parm_long; + current->thread.gmap_int_code = regs->int_code &0xffff ; +return ; + } state =irqentry_enter (regs);
@@ -408,8 +423,8 @@ static void (*pgm_check_table[128])(struct pt_regs *regs) = { [0x3b] = do_dat_exception, [0x3c] = default_trap_handler, [0x3d] = do_secure_storage_access, - [0x3e] = do_non_secure_storage_access, - [0x3f] = do_secure_storage_violation, + [0x3e] = default_trap_handler, + [0x3f] = default_trap_handler, [0x40] = monitor_event_exception, [0x41 ... 0x7f] = default_trap_handler, };
@@ -420,5 +435,3 @@ static void (*pgm_check_table[128])(struct pt_regs *regs) = { __stringify(default_trap_handler))COND_TRAP (do_secure_storage_access); -COND_TRAP (do_non_secure_storage_access); -COND_TRAP (do_secure_storage_violation);
arch/s390/kvm/kvm-s390.c +94 -22
160 lines not on this page · raw message
arch/s390/kvm/kvm-s390.h +7 -0
@@ -528,6 +528,13 @@ static inline int kvm_s390_use_sca_entries(void)void kvm_s390_reinject_machine_check (struct kvm_vcpu *vcpu,struct mcck_volatile_info *mcck_info); +static inline bool kvm_s390_cur_gmap_fault_is_write (void ) +{ +if (current->thread.gmap_int_code ==PGM_PROTECTION ) +return true; +return test_facility (75 ) && (current->thread.gmap_teid.fsi ==TEID_FSI_STORE ); +} +/** * kvm_s390_vcpu_crypto_reset_all *
arch/s390/kvm/vsie.c +7 -6
@@ -925,16 +925,16 @@ static int handle_fault(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)if (current->thread.gmap_int_code ==PGM_PROTECTION )/* we can directly forward all protection exceptions */ return inject_fault (vcpu,PGM_PROTECTION , - current->thread.gmap_addr,1 ); + current->thread.gmap_teid.addr *PAGE_SIZE ,1 ); rc =kvm_s390_shadow_fault (vcpu, vsie_page->gmap, - current->thread.gmap_addr,NULL ); + current->thread.gmap_teid.addr *PAGE_SIZE ,NULL );if (rc >0 ) { rc =inject_fault (vcpu, rc, - current->thread.gmap_addr, - current->thread.gmap_write_flag); + current->thread.gmap_teid.addr *PAGE_SIZE , +kvm_s390_cur_gmap_fault_is_write ());if (rc >=0 ) - vsie_page->fault_addr = current->thread.gmap_addr; + vsie_page->fault_addr = current->thread.gmap_teid.addr *PAGE_SIZE ; }return rc; }
@@ -1148,6 +1148,7 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)* also kick the vSIE. */ vcpu->arch.sie_block->prog0c |=PROG_IN_SIE ; + current->thread.gmap_int_code =0 ;barrier ();if (!kvm_s390_vcpu_sie_inhibited (vcpu)) rc =sie64a (scb_s, vcpu->run->s.regs.gprs,gmap_get_enabled ()->asce);
@@ -1172,7 +1173,7 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)if (rc >0 ) rc =0 ;/* we could still have an icpt */ -else if (rc == -EFAULT ) +else if (current->thread.gmap_int_code)return handle_fault (vcpu, vsie_page);switch (scb_s->icptcode) {
arch/s390/mm/fault.c +1 -98
172 lines not on this page · raw message
Signature · 1 line
2.47.0
Heiko Carstens
maintainerRe: [PATCH v3 05/11] s390/mm/fault: Handle guest-related program interrupts in KVM
Quoted 16 lines · Claudio Imbrenda
Any program interrupt that happens in the host during the execution of a KVM guest will now short circuit the fault handler and return to KVM immediately. Guest fault handling (including pfault) will happen entirely inside KVM.
When
sie64a()returns zero,current->thread.gmap_int_codewill contain the program interrupt number that caused the exit, or zero if the exit was not caused by a host program interrupt.KVM will now take care of handling all guest faults in
vcpu_post_run().Since gmap faults will not be visible by the rest of the kernel, remove
GMAP_FAULT, the linux fault handlers for secure execution faults, the exception table entries for the sie instruction, the nop padding after the sie instruction, and all other references to guest faults from the s390 code.
...
Quoted 1 line
arch/s390/kernel/traps.c +0
-0
...
Quoted 12 lines
arch/s390/kernel/traps.c +5
-1@@ -317,9 +318,23 @@ void noinstr __do_pgm_check(struct pt_regs *regs)struct lowcore *lc =get_lowcore ();irqentry_state_t state;unsigned int trapnr; +union teid teid = { .val = lc->trans_exc_code }; regs->int_code = lc->pgm_int_code; - regs->int_parm_long = lc->trans_exc_code; + regs->int_parm_long = teid.val; + +/* +* In case of a guest fault, short-circuit the fault handler and return.
arch/s390/kernel/traps.c void noinstr __do_pgm_check(struct pt_regs *regs) · line 337
Quoted 10 lines
arch/s390/kernel/traps.c +10
-0+* This way the sie64a() function will return 0; fault address and +* other relevant bits are saved in current->thread.gmap_teid, and +* the fault number in current->thread.gmap_int_code. KVM will be +* able to use this information to handle the fault. +*/ +if (test_pt_regs_flag (regs,PIF_GUEST_FAULT ) && (teid.as ==PSW_BITS_AS_PRIMARY )) { + current->thread.gmap_teid.val = regs->int_parm_long; + current->thread.gmap_int_code = regs->int_code &0xffff ; +return ; + }
This check looks suboptimal to me for two reasons:
- if PIF_GUEST_FAULT is set it should never happen that the normal exception handling code is executed; it is clearly a bug if that would happen, and with the above check this may or may not be recognized with a kernel crash, if I'm not mistaken.
- __do_pgm_check() is executed for all program interruptions. This includes those interruptions which do not write a teid. Therefore the above check may do something unexpected depending on what teid a previous program interruption wrote. I think the teid.as check should be moved to kvm as well, and only be done for those cases where it is known that the teid contains a valid value.
Claudio Imbrenda
maintainerRe: [PATCH v3 05/11] s390/mm/fault: Handle guest-related program interrupts in KVM
Quoted 52 lines · On Wed, 16 Oct 2024 12:05:14 +0200 Heiko Carstens <[email protected]> wrote:
Quoted 16 lines · Claudio Imbrenda
Any program interrupt that happens in the host during the execution of a KVM guest will now short circuit the fault handler and return to KVM immediately. Guest fault handling (including pfault) will happen entirely inside KVM.
When
sie64a()returns zero,current->thread.gmap_int_codewill contain the program interrupt number that caused the exit, or zero if the exit was not caused by a host program interrupt.KVM will now take care of handling all guest faults in
vcpu_post_run().Since gmap faults will not be visible by the rest of the kernel, remove
GMAP_FAULT, the linux fault handlers for secure execution faults, the exception table entries for the sie instruction, the nop padding after the sie instruction, and all other references to guest faults from the s390 code....
Quoted 1 line
arch/s390/kernel/traps.c +0
-0...
Quoted 12 lines
arch/s390/kernel/traps.c +5
-1@@ -317,9 +318,23 @@ void noinstr __do_pgm_check(struct pt_regs *regs)struct lowcore *lc =get_lowcore ();irqentry_state_t state;unsigned int trapnr; +union teid teid = { .val = lc->trans_exc_code }; regs->int_code = lc->pgm_int_code; - regs->int_parm_long = lc->trans_exc_code; + regs->int_parm_long = teid.val; + +/* +* In case of a guest fault, short-circuit the fault handler and return. arch/s390/kernel/traps.c void noinstr __do_pgm_check(struct pt_regs *regs) · line 337
Quoted 10 lines
arch/s390/kernel/traps.c +10
-0+* This way the sie64a() function will return 0; fault address and +* other relevant bits are saved in current->thread.gmap_teid, and +* the fault number in current->thread.gmap_int_code. KVM will be +* able to use this information to handle the fault. +*/ +if (test_pt_regs_flag (regs,PIF_GUEST_FAULT ) && (teid.as ==PSW_BITS_AS_PRIMARY )) { + current->thread.gmap_teid.val = regs->int_parm_long; + current->thread.gmap_int_code = regs->int_code &0xffff ; +return ; + }This check looks suboptimal to me for two reasons:
- if
PIF_GUEST_FAULTis set it should never happen that the normal exception handling code is executed; it is clearly a bug if that would happen, and with the above check this may or may not be recognized with a kernel crash, if I'm not mistaken.
Quoted 6 lines
-
__do_pgm_check()is executed for all program interruptions. This includes those interruptions which do not write a teid. Therefore the above check may do something unexpected depending on what teid a previous program interruption wrote. I think the teid.as check should be moved to kvm as well, and only be done for those cases where it is known that the teid contains a valid value.
makes sense
I'll move the checks into the kvm part of the code, and trigger a KVM_BUG if things are wrong
Claudio Imbrenda
maintainerPATCH v3 6/11 s390/kvm: Stop using gmap_{en,dis}able()
In reply to Claudio ImbrendaStop using gmap_enable(), gmap_disable(), gmap_get_enabled().
The correct guest ASCE is passed as a parameter of sie64a(), there is no need to save the current gmap in lowcore.
--- arch/s390/kvm/kvm-s390.c | 7 +------ arch/s390/kvm/vsie.c | 4 +--- 2 files changed, 2 insertions(+), 9 deletions(-)
arch/s390/kvm/kvm-s390.c +1 -6
@@ -3719,7 +3719,6 @@ __u64 kvm_s390_get_cpu_timer(struct kvm_vcpu *vcpu)void kvm_arch_vcpu_load (struct kvm_vcpu *vcpu,int cpu) { -gmap_enable (vcpu->arch.enabled_gmap);kvm_s390_set_cpuflags (vcpu,CPUSTAT_RUNNING );if (vcpu->arch.cputm_enabled && !is_vcpu_idle (vcpu))__start_cpu_timer_accounting (vcpu);
@@ -3732,8 +3731,6 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)if (vcpu->arch.cputm_enabled && !is_vcpu_idle (vcpu))__stop_cpu_timer_accounting (vcpu);kvm_s390_clear_cpuflags (vcpu,CPUSTAT_RUNNING ); - vcpu->arch.enabled_gmap =gmap_get_enabled (); -gmap_disable (vcpu->arch.enabled_gmap); }
@@ -3751,8 +3748,6 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu) }if (test_kvm_facility (vcpu->kvm,74 ) || vcpu->kvm->arch.user_instr0) vcpu->arch.sie_block->ictl |=ICTL_OPEREXC ; -/* make vcpu_load load the right gmap on the first trigger */ - vcpu->arch.enabled_gmap = vcpu->arch.gmap; }static bool kvm_has_pckmo_subfunc (struct kvm *kvm,unsigned long nr)
@@ -4891,7 +4886,7 @@ static int __vcpu_run(struct kvm_vcpu *vcpu) } exit_reason =sie64a (vcpu->arch.sie_block, vcpu->run->s.regs.gprs, -gmap_get_enabled ()->asce); + vcpu->arch.gmap->asce);if (kvm_s390_pv_cpu_is_protected (vcpu)) { memcpy(vcpu->run->s.regs.gprs, sie_page->pv_grregs,
arch/s390/kvm/vsie.c +1 -3
@@ -1151,7 +1151,7 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) current->thread.gmap_int_code =0 ;barrier ();if (!kvm_s390_vcpu_sie_inhibited (vcpu)) - rc =sie64a (scb_s, vcpu->run->s.regs.gprs,gmap_get_enabled ()->asce); + rc =sie64a (scb_s, vcpu->run->s.regs.gprs, vsie_page->gmap->asce);barrier (); vcpu->arch.sie_block->prog0c &= ~PROG_IN_SIE ;
@@ -1296,10 +1296,8 @@ static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)if (!rc) rc =map_prefix (vcpu, vsie_page);if (!rc) { -gmap_enable (vsie_page->gmap);update_intervention_requests (vsie_page); rc =do_vsie_run (vcpu, vsie_page); -gmap_enable (vcpu->arch.gmap); }atomic_andnot (PROG_BLOCK_SIE , &scb_s->prog20);
Signature · 1 line
2.47.0
Re: [PATCH v3 06/11] s390/kvm: Stop using gmap_{en,dis}able()
Quoted 25 lines · Claudio Imbrenda
Stop using
gmap_enable(),gmap_disable(),gmap_get_enabled().The correct guest ASCE is passed as a parameter of
sie64a(), there is no need to save the current gmap in lowcore.Signed-off-by Claudio Imbrenda <[email protected]>Acked-by Steffen Eiden <[email protected]>--- arch/s390/kvm/kvm-s390.c | 7 +------ arch/s390/kvm/vsie.c | 4 +--- 2 files changed, 2 insertions(+), 9 deletions(-)arch/s390/kvm/kvm-s390.c +0
-1@@ -3719,7 +3719,6 @@ __u64 kvm_s390_get_cpu_timer(struct kvm_vcpu *vcpu)void kvm_arch_vcpu_load (struct kvm_vcpu *vcpu,int cpu) { -gmap_enable (vcpu->arch.enabled_gmap);kvm_s390_set_cpuflags (vcpu,CPUSTAT_RUNNING );if (vcpu->arch.cputm_enabled && !is_vcpu_idle (vcpu))__start_cpu_timer_accounting (vcpu);
arch/s390/kvm/kvm-s390.c void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) · line 3736
Quoted 5 lines
arch/s390/kvm/kvm-s390.c +0
-2@@ -3732,8 +3731,6 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)if (vcpu->arch.cputm_enabled && !is_vcpu_idle (vcpu))__stop_cpu_timer_accounting (vcpu);kvm_s390_clear_cpuflags (vcpu,CPUSTAT_RUNNING ); - vcpu->arch.enabled_gmap =gmap_get_enabled (); -gmap_disable (vcpu->arch.enabled_gmap);
I guess you want to get rid of enabled_gmap as well, since it becomes unused with this patch:
arch/s390/include/asm/kvm_host.h +0 -2
@@ -750,8 +750,6 @@ struct kvm_vcpu_arch {struct hrtimer ckc_timer;struct kvm_s390_pgm_info pgm;struct gmap *gmap; -/* backup location for the currently enabled gmap when scheduled out */ -struct gmap *enabled_gmap;struct kvm_guestdbg_info_arch guestdbg;unsigned long pfault_token;unsigned long pfault_select;
Claudio Imbrenda
maintainerRe: [PATCH v3 06/11] s390/kvm: Stop using gmap_{en,dis}able()
Quoted 21 lines · On Mon, 21 Oct 2024 11:50:06 +0200 Heiko Carstens <[email protected]> wrote:
Quoted 20 lines · Claudio Imbrenda
Stop using
gmap_enable(),gmap_disable(),gmap_get_enabled().The correct guest ASCE is passed as a parameter of
sie64a(), there is no need to save the current gmap in lowcore.Signed-off-by Claudio Imbrenda <[email protected]>Acked-by Steffen Eiden <[email protected]>--- arch/s390/kvm/kvm-s390.c | 7 +------ arch/s390/kvm/vsie.c | 4 +--- 2 files changed, 2 insertions(+), 9 deletions(-)arch/s390/kvm/kvm-s390.c +0
-0@@ -3719,7 +3719,6 @@ __u64 kvm_s390_get_cpu_timer(struct kvm_vcpu *vcpu)void kvm_arch_vcpu_load (struct kvm_vcpu *vcpu,int cpu) {
Quoted 13 lines
arch/s390/kvm/kvm-s390.c void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) · line 3736
Quoted 10 lines
arch/s390/kvm/kvm-s390.c +0
-3-gmap_enable (vcpu->arch.enabled_gmap);kvm_s390_set_cpuflags (vcpu,CPUSTAT_RUNNING );if (vcpu->arch.cputm_enabled && !is_vcpu_idle (vcpu))__start_cpu_timer_accounting (vcpu);@@ -3732,8 +3731,6 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)if (vcpu->arch.cputm_enabled && !is_vcpu_idle (vcpu))__stop_cpu_timer_accounting (vcpu);kvm_s390_clear_cpuflags (vcpu,CPUSTAT_RUNNING ); - vcpu->arch.enabled_gmap =gmap_get_enabled (); -gmap_disable (vcpu->arch.enabled_gmap);I guess you want to get rid of
enabled_gmapas well, since it becomes unused with this patch:
oh yeah, I had missed that.
I guess it can go in the next patch, where things are removed
Quoted 16 lines
arch/s390/include/asm/kvm_host.h +0
-2@@ -750,8 +750,6 @@ struct kvm_vcpu_arch {struct hrtimer ckc_timer;struct kvm_s390_pgm_info pgm;struct gmap *gmap; -/* backup location for the currently enabled gmap when scheduled out */ -struct gmap *enabled_gmap;struct kvm_guestdbg_info_arch guestdbg;unsigned long pfault_token;unsigned long pfault_select;Reviewed-by Heiko Carstens <[email protected]>
Claudio Imbrenda
maintainerPATCH v3 7/11 s390/mm/gmap: Remove gmap_{en,dis}able()
In reply to Claudio ImbrendaRemove gmap_enable(), gmap_disable(), and gmap_get_enabled() since they do not have any users anymore.
--- arch/s390/include/asm/gmap.h | 3 --- arch/s390/mm/gmap.c | 31 ------------------------------- 2 files changed, 34 deletions(-)
arch/s390/include/asm/gmap.h +0 -3
@@ -107,9 +107,6 @@ void gmap_remove(struct gmap *gmap);struct gmap *gmap_get (struct gmap *gmap);void gmap_put (struct gmap *gmap); -void gmap_enable (struct gmap *gmap); -void gmap_disable (struct gmap *gmap); -struct gmap *gmap_get_enabled (void );int gmap_map_segment (struct gmap *gmap,unsigned long from,unsigned long to,unsigned long len);int gmap_unmap_segment (struct gmap *gmap,unsigned long to,unsigned long len);
arch/s390/mm/gmap.c +0 -31
@@ -281,37 +281,6 @@ void gmap_remove(struct gmap *gmap) }EXPORT_SYMBOL_GPL (gmap_remove); -/** -* gmap_enable - switch primary space to the guest address space -* @gmap: pointer to the guest address space structure -*/ -void gmap_enable (struct gmap *gmap) -{ -get_lowcore ()->gmap = (unsigned long )gmap; -} -EXPORT_SYMBOL_GPL (gmap_enable); - -/** -* gmap_disable - switch back to the standard primary address space -* @gmap: pointer to the guest address space structure -*/ -void gmap_disable (struct gmap *gmap) -{ -get_lowcore ()->gmap =0UL ; -} -EXPORT_SYMBOL_GPL (gmap_disable); - -/** -* gmap_get_enabled - get a pointer to the currently enabled gmap -* -* Returns a pointer to the currently enabled gmap. 0 if none is enabled. -*/ -struct gmap *gmap_get_enabled (void ) -{ -return (struct gmap *)get_lowcore ()->gmap; -} -EXPORT_SYMBOL_GPL (gmap_get_enabled); -/* * gmap_alloc_table is assumed to be called with mmap_lock held */
Signature · 1 line
2.47.0
Re: [PATCH v3 07/11] s390/mm/gmap: Remove gmap_{en,dis}able()
Quoted 9 lines · Claudio Imbrenda
Remove
gmap_enable(),gmap_disable(), andgmap_get_enabled()since they do not have any users anymore.Suggested-by Heiko Carstens <[email protected]>Signed-off-by Claudio Imbrenda <[email protected]>--- arch/s390/include/asm/gmap.h | 3 --- arch/s390/mm/gmap.c | 31 ------------------------------- 2 files changed, 34 deletions(-)
Claudio Imbrenda
maintainerPATCH v3 8/11 s390: Remove gmap pointer from lowcore
In reply to Claudio ImbrendaRemove the gmap pointer from lowcore, since it is not used anymore.
--- arch/s390/include/asm/lowcore.h | 3 +-- arch/s390/kernel/asm-offsets.c | 1 - 2 files changed, 1 insertion(+), 3 deletions(-)
arch/s390/include/asm/lowcore.h +1 -2
@@ -165,8 +165,7 @@ struct lowcore {__u64 percpu_offset;/* 0x03b8 */ __u8 pad_0x03c0[0x03c8 -0x03c0 ];/* 0x03c0 */ __u64 machine_flags;/* 0x03c8 */ -__u64 gmap;/* 0x03d0 */ -__u8 pad_0x03d8[0x0400 -0x03d8 ];/* 0x03d8 */ +__u8 pad_0x03d0[0x0400 -0x03d0 ];/* 0x03d0 */ __u32 return_lpswe;/* 0x0400 */ __u32 return_mcck_lpswe;/* 0x0404 */
arch/s390/kernel/asm-offsets.c +0 -1
@@ -137,7 +137,6 @@ int main(void)OFFSET (__LC_USER_ASCE, lowcore, user_asce);OFFSET (__LC_LPP, lowcore, lpp);OFFSET (__LC_CURRENT_PID, lowcore, current_pid); -OFFSET (__LC_GMAP, lowcore, gmap);OFFSET (__LC_LAST_BREAK, lowcore, last_break);/* software defined ABI-relevant lowcore locations 0xe00 - 0xe20 */ OFFSET (__LC_DUMP_REIPL, lowcore, ipib);
Signature · 1 line
2.47.0
Re: [PATCH v3 08/11] s390: Remove gmap pointer from lowcore
Quoted 8 lines · Claudio Imbrenda
Remove the gmap pointer from lowcore, since it is not used anymore.
Signed-off-by Claudio Imbrenda <[email protected]>Reviewed-by Steffen Eiden <[email protected]>--- arch/s390/include/asm/lowcore.h | 3 +-- arch/s390/kernel/asm-offsets.c | 1 - 2 files changed, 1 insertion(+), 3 deletions(-)
Claudio Imbrenda
maintainerPATCH v3 9/11 s390/mm: Simplify get_fault_type()
In reply to Claudio ImbrendaFrom: Heiko Carstens <[email protected]>
With the gmap code gone get_fault_type() can be simplified:
- every fault with user_mode(regs) == true must be a fault in user address space
- every fault with user_mode(regs) == false is only a fault in user address space if the used address space is the secondary address space
- every other fault is within the kernel address space
--- arch/s390/mm/fault.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
arch/s390/mm/fault.c +2 -9
@@ -68,17 +68,10 @@ static enum fault_type get_fault_type(struct pt_regs *regs) {union teid teid = { .val = regs->int_parm_long }; -if (likely (teid.as ==PSW_BITS_AS_PRIMARY )) { -if (user_mode (regs)) -return USER_FAULT ; -return KERNEL_FAULT ; - } -if (teid.as ==PSW_BITS_AS_SECONDARY ) +if (user_mode (regs))return USER_FAULT ; -/* Access register mode, not used in the kernel */ -if (teid.as ==PSW_BITS_AS_ACCREG ) +if (teid.as ==PSW_BITS_AS_SECONDARY )return USER_FAULT ; -/* Home space -> access via kernel ASCE */ return KERNEL_FAULT ; }
Signature · 1 line
2.47.0
Claudio Imbrenda
maintainerPATCH v3 10/11 s390/mm: Get rid of fault type switch statements
In reply to Claudio ImbrendaFrom: Heiko Carstens <[email protected]>
With GMAP_FAULT fault type gone, there are only KERNEL_FAULT and USER_FAULT fault types left. Therefore there is no need for any fault type switch statements left.
Rename get_fault_type() into is_kernel_fault() and let it return a boolean value. Change all switch statements to if statements. This removes quite a bit of code.
--- arch/s390/mm/fault.c | 70 ++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 48 deletions(-)
arch/s390/mm/fault.c +22 -48
@@ -46,11 +46,6 @@#include <asm/uv.h> #include "../kernel/entry.h" -enum fault_type { -KERNEL_FAULT , -USER_FAULT , -}; -static DEFINE_STATIC_KEY_FALSE (have_store_indication);static int __init fault_init (void )
@@ -64,15 +59,15 @@ early_initcall(fault_init);/* * Find out which address space caused the exception. */ -static enum fault_type get_fault_type (struct pt_regs *regs) +static bool is_kernel_fault (struct pt_regs *regs) {union teid teid = { .val = regs->int_parm_long };if (user_mode (regs)) -return USER_FAULT ; +return false;if (teid.as ==PSW_BITS_AS_SECONDARY ) -return USER_FAULT ; -return KERNEL_FAULT ; +return false; +return true; }static unsigned long get_fault_address (struct pt_regs *regs)
@@ -167,17 +162,12 @@ static void dump_fault_info(struct pt_regs *regs)break ; }pr_cont ("mode while using " ); -switch (get_fault_type (regs)) { -case USER_FAULT : - asce =get_lowcore ()->user_asce.val; -pr_cont ("user " ); -break ; -case KERNEL_FAULT : +if (is_kernel_fault (regs)) { asce =get_lowcore ()->kernel_asce.val;pr_cont ("kernel " ); -break ; -default : -unreachable (); + }else { + asce =get_lowcore ()->user_asce.val; +pr_cont ("user " ); }pr_cont ("ASCE.\n" );dump_pagetable (asce,get_fault_address (regs));
@@ -212,7 +202,6 @@ static void do_sigsegv(struct pt_regs *regs, int si_code)static void handle_fault_error_nolock (struct pt_regs *regs,int si_code) { -enum fault_type fault_type;unsigned long address;bool is_write;
@@ -223,17 +212,15 @@ static void handle_fault_error_nolock(struct pt_regs *regs, int si_code) }if (fixup_exception (regs))return ; - fault_type =get_fault_type (regs); -if (fault_type ==KERNEL_FAULT ) { +if (is_kernel_fault (regs)) { address =get_fault_address (regs); is_write =fault_is_write (regs);if (kfence_handle_page_fault (address, is_write, regs))return ; - } -if (fault_type ==KERNEL_FAULT )pr_alert ("Unable to handle kernel pointer dereference in virtual kernel address space\n" ); -else + }else {pr_alert ("Unable to handle kernel paging request in virtual user address space\n" ); + }dump_fault_info (regs);die (regs,"Oops" ); }
@@ -267,7 +254,6 @@ static void do_exception(struct pt_regs *regs, int access)struct vm_area_struct *vma;unsigned long address;struct mm_struct *mm; -enum fault_type type;unsigned int flags;vm_fault_t fault;bool is_write;
@@ -282,15 +268,8 @@ static void do_exception(struct pt_regs *regs, int access) mm = current->mm; address =get_fault_address (regs); is_write =fault_is_write (regs); - type =get_fault_type (regs); -switch (type) { -case KERNEL_FAULT : +if (is_kernel_fault (regs) ||faulthandler_disabled () || !mm)return handle_fault_error_nolock (regs,0 ); -case USER_FAULT : -if (faulthandler_disabled () || !mm) -return handle_fault_error_nolock (regs,0 ); -break ; - }perf_sw_event (PERF_COUNT_SW_PAGE_FAULTS ,1 , regs, address); flags =FAULT_FLAG_DEFAULT ;if (user_mode (regs))
@@ -460,8 +439,15 @@ void do_secure_storage_access(struct pt_regs *regs)*/ panic ("Unexpected PGM 0x3d with TEID bit 61=0" ); } -switch (get_fault_type (regs)) { -case USER_FAULT : +if (is_kernel_fault (regs)) { + folio =phys_to_folio (addr); +if (unlikely (!folio_try_get (folio))) +return ; + rc =arch_make_folio_accessible (folio); +folio_put (folio); +if (rc) +BUG (); + }else { mm = current->mm;mmap_read_lock (mm); vma =find_vma (mm, addr);
@@ -470,7 +456,7 @@ void do_secure_storage_access(struct pt_regs *regs) folio =folio_walk_start (&fw, vma, addr,0 );if (!folio) {mmap_read_unlock (mm); -break ; +return ; }/* arch_make_folio_accessible() needs a raised refcount. */ folio_get (folio);
@@ -480,18 +466,6 @@ void do_secure_storage_access(struct pt_regs *regs)if (rc)send_sig (SIGSEGV , current,0 );mmap_read_unlock (mm); -break ; -case KERNEL_FAULT : - folio =phys_to_folio (addr); -if (unlikely (!folio_try_get (folio))) -break ; - rc =arch_make_folio_accessible (folio); -folio_put (folio); -if (rc) -BUG (); -break ; -default : -unreachable (); } }NOKPROBE_SYMBOL (do_secure_storage_access);
Signature · 1 line
2.47.0
Claudio Imbrenda
maintainerPATCH v3 11/11 s390/mm: Convert to LOCK_MM_AND_FIND_VMA
In reply to Claudio ImbrendaFrom: Heiko Carstens <[email protected]>
With the gmap code gone s390 can be easily converted to LOCK_MM_AND_FIND_VMA like it has been done for most other architectures.
--- arch/s390/Kconfig | 1 + arch/s390/mm/fault.c | 13 ++----------- 2 files changed, 3 insertions(+), 11 deletions(-)
arch/s390/Kconfig +1 -0
@@ -224,6 +224,7 @@ config S390 select HAVE_VIRT_CPU_ACCOUNTING_IDLE select IOMMU_HELPER if PCI select IOMMU_SUPPORT if PCI + select LOCK_MM_AND_FIND_VMA select MMU_GATHER_MERGE_VMAS select MMU_GATHER_NO_GATHER select MMU_GATHER_RCU_TABLE_FREE
arch/s390/mm/fault.c +2 -11
@@ -308,18 +308,10 @@ static void do_exception(struct pt_regs *regs, int access)return ; } lock_mmap: -mmap_read_lock (mm); retry: - vma =find_vma (mm, address); + vma =lock_mm_and_find_vma (mm, address, regs);if (!vma) -return handle_fault_error (regs,SEGV_MAPERR ); -if (unlikely (vma->vm_start > address)) { -if (!(vma->vm_flags &VM_GROWSDOWN )) -return handle_fault_error (regs,SEGV_MAPERR ); - vma =expand_stack (mm, address); -if (!vma) -return handle_fault_error_nolock (regs,SEGV_MAPERR ); - } +return handle_fault_error_nolock (regs,SEGV_MAPERR );if (unlikely (!(vma->vm_flags & access)))return handle_fault_error (regs,SEGV_ACCERR ); fault =handle_mm_fault (vma, address, flags, regs);
@@ -337,7 +329,6 @@ static void do_exception(struct pt_regs *regs, int access) }if (fault &VM_FAULT_RETRY ) { flags |=FAULT_FLAG_TRIED ; -mmap_read_lock (mm); goto retry; }mmap_read_unlock (mm);
Signature · 1 line
2.47.0