Skip to content

Commit 64c3431

Browse files
svens-s390hcahca
authored andcommitted
s390/entry: compare gmap asce to determine guest/host fault
With the current implementation, there are some cornercases where a host fault would be treated as a guest fault, for example when the sie instruction causes a program check. Therefore store the gmap asce in ptregs, and use that to compare the primary asce from the fault instead of matching instruction addresses. Suggested-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Sven Schnelle <svens@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent 29e5bc0 commit 64c3431

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

arch/s390/include/asm/ptrace.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
#define PIF_SYSCALL 0 /* inside a system call */
1515
#define PIF_EXECVE_PGSTE_RESTART 1 /* restart execve for PGSTE binaries */
1616
#define PIF_SYSCALL_RET_SET 2 /* return value was set via ptrace */
17-
#define PIF_GUEST_FAULT 3 /* indicates program check in sie64a */
1817
#define PIF_FTRACE_FULL_REGS 4 /* all register contents valid (ftrace) */
1918

2019
#define _PIF_SYSCALL BIT(PIF_SYSCALL)
2120
#define _PIF_EXECVE_PGSTE_RESTART BIT(PIF_EXECVE_PGSTE_RESTART)
2221
#define _PIF_SYSCALL_RET_SET BIT(PIF_SYSCALL_RET_SET)
23-
#define _PIF_GUEST_FAULT BIT(PIF_GUEST_FAULT)
2422
#define _PIF_FTRACE_FULL_REGS BIT(PIF_FTRACE_FULL_REGS)
2523

2624
#define PSW32_MASK_PER _AC(0x40000000, UL)

arch/s390/kernel/entry.S

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ _LPP_OFFSET = __LC_LPP
119119
.endm
120120

121121
#if IS_ENABLED(CONFIG_KVM)
122-
.macro SIEEXIT
123-
lg %r9,__SF_SIE_CONTROL(%r15) # get control block pointer
122+
.macro SIEEXIT sie_control
123+
lg %r9,\sie_control # get control block pointer
124124
ni __SIE_PROG0C+3(%r9),0xfe # no longer in SIE
125125
lctlg %c1,%c1,__LC_KERNEL_ASCE # load primary asce
126126
ni __LC_CPU_FLAGS+7,255-_CIF_SIE
@@ -316,21 +316,13 @@ SYM_CODE_START(pgm_check_handler)
316316
stpt __LC_SYS_ENTER_TIMER
317317
BPOFF
318318
stmg %r8,%r15,__LC_SAVE_AREA_SYNC
319-
lghi %r10,0
319+
lgr %r10,%r15
320320
lmg %r8,%r9,__LC_PGM_OLD_PSW
321321
tmhh %r8,0x0001 # coming from user space?
322322
jno .Lpgm_skip_asce
323323
lctlg %c1,%c1,__LC_KERNEL_ASCE
324324
j 3f # -> fault in user space
325325
.Lpgm_skip_asce:
326-
#if IS_ENABLED(CONFIG_KVM)
327-
# cleanup critical section for program checks in __sie64a
328-
TSTMSK __LC_CPU_FLAGS,_CIF_SIE
329-
jz 1f
330-
BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
331-
SIEEXIT
332-
lghi %r10,_PIF_GUEST_FAULT
333-
#endif
334326
1: tmhh %r8,0x4000 # PER bit set in old PSW ?
335327
jnz 2f # -> enabled, can't be a double fault
336328
tm __LC_PGM_ILC+3,0x80 # check for per exception
@@ -341,13 +333,20 @@ SYM_CODE_START(pgm_check_handler)
341333
CHECK_VMAP_STACK __LC_SAVE_AREA_SYNC,4f
342334
3: lg %r15,__LC_KERNEL_STACK
343335
4: la %r11,STACK_FRAME_OVERHEAD(%r15)
344-
stg %r10,__PT_FLAGS(%r11)
336+
xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
345337
xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
346338
stmg %r0,%r7,__PT_R0(%r11)
347339
mvc __PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
348340
mvc __PT_LAST_BREAK(8,%r11),__LC_PGM_LAST_BREAK
349-
stmg %r8,%r9,__PT_PSW(%r11)
350-
341+
stctg %c1,%c1,__PT_CR1(%r11)
342+
#if IS_ENABLED(CONFIG_KVM)
343+
lg %r12,__LC_GMAP
344+
clc __GMAP_ASCE(8,%r12), __PT_CR1(%r11)
345+
jne 5f
346+
BPENTER __SF_SIE_FLAGS(%r10),_TIF_ISOLATE_BP_GUEST
347+
SIEEXIT __SF_SIE_CONTROL(%r10)
348+
#endif
349+
5: stmg %r8,%r9,__PT_PSW(%r11)
351350
# clear user controlled registers to prevent speculative use
352351
xgr %r0,%r0
353352
xgr %r1,%r1
@@ -399,7 +398,7 @@ SYM_CODE_START(\name)
399398
TSTMSK __LC_CPU_FLAGS,_CIF_SIE
400399
jz 0f
401400
BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
402-
SIEEXIT
401+
SIEEXIT __SF_SIE_CONTROL(%r15)
403402
#endif
404403
0: CHECK_STACK __LC_SAVE_AREA_ASYNC
405404
aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
@@ -507,7 +506,7 @@ SYM_CODE_START(mcck_int_handler)
507506
clgrjhe %r9,%r14, 4f
508507
oi __LC_CPU_FLAGS+7, _CIF_MCCK_GUEST
509508
4: BPENTER __SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
510-
SIEEXIT
509+
SIEEXIT __SF_SIE_CONTROL(%r15)
511510
#endif
512511
.Lmcck_user:
513512
lg %r15,__LC_MCCK_STACK

arch/s390/mm/fault.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ early_initcall(fault_init);
6767
static enum fault_type get_fault_type(struct pt_regs *regs)
6868
{
6969
union teid teid = { .val = regs->int_parm_long };
70+
struct gmap *gmap;
7071

7172
if (likely(teid.as == PSW_BITS_AS_PRIMARY)) {
7273
if (user_mode(regs))
7374
return USER_FAULT;
7475
if (!IS_ENABLED(CONFIG_PGSTE))
7576
return KERNEL_FAULT;
76-
if (test_pt_regs_flag(regs, PIF_GUEST_FAULT))
77+
gmap = (struct gmap *)S390_lowcore.gmap;
78+
if (regs->cr1 == gmap->asce)
7779
return GMAP_FAULT;
7880
return KERNEL_FAULT;
7981
}

0 commit comments

Comments
 (0)