Skip to contentSkip to conversation

s390: Remove PIF_GUEST_FAULT and add PER trap flag

PATCH Applied Sven Schnelle 3 participants 5 messages Jul 9 – Jul 10

Subsystems (2)
lore
Share & tools
lore

Sven Schnelle

author reviewer
#0 lore raw

cover s390: Remove PIF_GUEST_FAULT and add PER trap flag

While looking at the syscall code I noticed that entry.S still sets PIF_GUEST_FAULT in ptregs even though it's only used in __do_pgm_check(). Remove that and pass it directly to __do_pgm_check(). Heiko suggested to also add a define for the per trap flag in system_call().

Sven Schnelle (2):
s390/traps: Remove PIF_GUEST_FAULT
s390/syscalls: Use define instead of '1' to indicate PER trap

 arch/s390/include/asm/ptrace.h |  4 +---
 arch/s390/kernel/entry.S       |  9 +++++----
 arch/s390/kernel/entry.h       | 10 ++++++++--
 arch/s390/kernel/syscall.c     |  4 ++--
 arch/s390/kernel/traps.c       |  4 ++--
 5 files changed, 18 insertions(+), 13 deletions(-)

--
2.53.0

author reviewer
#1 lore raw

PATCH 1/2 s390/traps: Remove PIF_GUEST_FAULT

PIF_GUEST_FAULT is only used to pass information whether a fault was caused when executing SIE or when executing host code. Instead of using ptregs for this, just pass the flag directly as argument to __do_pgm_check(). This also saves the time required to read the flag from ptregs, although this likely isn't much as it is already in the data cache.

---
 arch/s390/include/asm/ptrace.h | 4 +---
 arch/s390/kernel/entry.S       | 7 ++++---
 arch/s390/kernel/entry.h       | 7 ++++++-
 arch/s390/kernel/traps.c       | 4 ++--
 4 files changed, 13 insertions(+), 9 deletions(-)
arch/s390/include/asm/ptrace.h +1 -3
index 495e310c3d6d..6411e3584283 100644
@@ -16,13 +16,11 @@
 #define PIF_SYSCALL			0	/* inside a system call */
 #define PIF_PSW_ADDR_ADJUSTED		1	/* psw address has been adjusted */
 #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_FTRACE_FULL_REGS		3	/* all register contents valid (ftrace) */
 
 #define _PIF_SYSCALL			BIT(PIF_SYSCALL)
 #define _PIF_ADDR_PSW_ADJUSTED		BIT(PIF_PSW_ADDR_ADJUSTED)
 #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/entry.S +4 -3
index 79a45efae23d..d70eef7a0b29 100644
@@ -31,6 +31,7 @@
 #include <asm/nospec-insn.h>
 #include <asm/lowcore.h>
 #include <asm/machine.h>
+#include "entry.h"
 
 _LPP_OFFSET	= __LC_LPP
 
@@ -321,7 +322,7 @@ SYM_CODE_START(pgm_check_handler)
 	jz	1f
 	BPENTER	__SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
 	SIEEXIT __SF_SIE_CONTROL(%r15),%r13
-	lghi	%r10,_PIF_GUEST_FAULT
+	lghi	%r10,PGM_FLAG_GUEST_FAULT
 #endif
 1:	tmhh	%r8,0x4000		# PER bit set in old PSW ?
 	jnz	2f			# -> enabled, can't be a double fault
@@ -332,7 +333,7 @@ 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)
-	stg	%r10,__PT_FLAGS(%r11)
+	xc	__PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
 	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
 	stmg	%r0,%r7,__PT_R0(%r11)
 	mvc	__PT_R8(64,%r11),__LC_SAVE_AREA(%r13)
@@ -341,13 +342,13 @@ SYM_CODE_START(pgm_check_handler)
 	# clear user controlled registers to prevent speculative use
 	xgr	%r0,%r0
 	xgr	%r1,%r1
-	xgr	%r3,%r3
 	xgr	%r4,%r4
 	xgr	%r5,%r5
 	xgr	%r6,%r6
 	xgr	%r7,%r7
 	xgr	%r12,%r12
 	lgr	%r2,%r11
+	lgr	%r3,%r10
 	brasl	%r14,__do_pgm_check
 	tmhh	%r8,0x0001		# returning to user space?
 	jno	.Lpgm_exit_kernel
arch/s390/kernel/entry.h +6 -1
index fb67b4abe68c..d18a9a63f6b8 100644
@@ -2,6 +2,10 @@
 #ifndef _ENTRY_H
 #define _ENTRY_H
 
+#define PGM_FLAG_GUEST_FAULT	1
+
+#ifndef __ASSEMBLER__
+
 #include <linux/percpu.h>
 #include <linux/types.h>
 #include <linux/signal.h>
@@ -21,7 +25,7 @@ void early_pgm_check_handler(void);
 
 struct task_struct *__switch_to_asm(struct task_struct *prev, struct task_struct *next);
 void __ret_from_fork(struct task_struct *prev, struct pt_regs *regs);
-void __do_pgm_check(struct pt_regs *regs);
+void __do_pgm_check(struct pt_regs *regs, unsigned long flags);
 void __do_syscall(struct pt_regs *regs, int per_trap);
 void __do_early_pgm_check(struct pt_regs *regs);
 
@@ -70,4 +74,5 @@ extern struct exception_table_entry _stop_amode31_ex_table[];
 #define __amode31_ref __section(".amode31.refs")
 extern long _start_amode31_refs[], _end_amode31_refs[];
 
+#endif /* __ASSEMBLER__ */
 #endif /* _ENTRY_H */
arch/s390/kernel/traps.c +2 -2
index 564403496a7c..a5c259dd4295 100644
@@ -327,7 +327,7 @@ void __init trap_init(void)
 
 static void (*pgm_check_table[128])(struct pt_regs *regs);
 
-void noinstr __do_pgm_check(struct pt_regs *regs)
+void noinstr __do_pgm_check(struct pt_regs *regs, unsigned long flags)
 {
 	struct lowcore *lc = get_lowcore();
 	bool percpu_needs_fixup;
@@ -346,7 +346,7 @@ void noinstr __do_pgm_check(struct pt_regs *regs)
 	 * 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)) {
+	if (flags & PGM_FLAG_GUEST_FAULT) {
 		current->thread.gmap_teid.val = regs->int_parm_long;
 		current->thread.gmap_int_code = regs->int_code & 0xffff;
 		return;
Signature · 1 line
2.53.0
author reviewer
#2 lore raw

PATCH 2/2 s390/syscalls: Use define instead of '1' to indicate PER trap

In reply to Sven Schnelle

Make the code a bit easier to read by defining SYSCALL_PER_TRAP instead of passing '1' to __do_syscall().

---
 arch/s390/kernel/entry.S   | 2 +-
 arch/s390/kernel/entry.h   | 3 ++-
 arch/s390/kernel/syscall.c | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)
arch/s390/kernel/entry.S +1 -1
index d70eef7a0b29..10dd9bbdf985 100644
@@ -368,7 +368,7 @@ SYM_CODE_START(pgm_check_handler)
 	mvc	__LC_RETURN_PSW(8,%r13),__LC_SVC_NEW_PSW(%r13)
 	larl	%r14,.Lsysc_per
 	stg	%r14,__LC_RETURN_PSW+8(%r13)
-	lghi	%r14,1
+	lghi	%r14,SYSCALL_FLAG_PER_TRAP
 	LBEAR	__LC_PGM_LAST_BREAK(%r13)
 	LPSWEY	__LC_RETURN_PSW,__LC_RETURN_LPSWE # branch to .Lsysc_per
 SYM_CODE_END(pgm_check_handler)
arch/s390/kernel/entry.h +2 -1
index d18a9a63f6b8..dc84ab497251 100644
@@ -3,6 +3,7 @@
 #define _ENTRY_H
 
 #define PGM_FLAG_GUEST_FAULT	1
+#define SYSCALL_FLAG_PER_TRAP	1
 
 #ifndef __ASSEMBLER__
 
@@ -26,7 +27,7 @@ void early_pgm_check_handler(void);
 struct task_struct *__switch_to_asm(struct task_struct *prev, struct task_struct *next);
 void __ret_from_fork(struct task_struct *prev, struct pt_regs *regs);
 void __do_pgm_check(struct pt_regs *regs, unsigned long flags);
-void __do_syscall(struct pt_regs *regs, int per_trap);
+void __do_syscall(struct pt_regs *regs, unsigned long flags);
 void __do_early_pgm_check(struct pt_regs *regs);
 
 void do_protection_exception(struct pt_regs *regs);
arch/s390/kernel/syscall.c +2 -2
index 75d5a3cab14e..b6c643756a7c 100644
@@ -93,7 +93,7 @@ SYSCALL_DEFINE0(ni_syscall)
 	return -ENOSYS;
 }
 
-void noinstr __do_syscall(struct pt_regs *regs, int per_trap)
+void noinstr __do_syscall(struct pt_regs *regs, unsigned long flags)
 {
 	unsigned long nr;
 
@@ -106,7 +106,7 @@ void noinstr __do_syscall(struct pt_regs *regs, int per_trap)
 		current->thread.last_break = regs->last_break;
 	local_irq_enable();
 	regs->orig_gpr2 = regs->gprs[2];
-	if (unlikely(per_trap))
+	if (unlikely(flags & SYSCALL_FLAG_PER_TRAP))
 		set_thread_flag(TIF_PER_TRAP);
 	regs->flags = 0;
 	set_pt_regs_flag(regs, PIF_SYSCALL);
Signature · 1 line
2.53.0
maintainer Reviewed-by on the v1 series
#3 lore raw
In reply to Sven Schnelle
Quoted 9 lines · Sven Schnelle

While looking at the syscall code I noticed that entry.S still sets PIF_GUEST_FAULT in ptregs even though it's only used in __do_pgm_check(). Remove that and pass it directly to __do_pgm_check(). Heiko suggested to also add a define for the per trap flag in system_call().

Sven Schnelle (2):
s390/traps: Remove PIF_GUEST_FAULT
s390/syscalls: Use define instead of '1' to indicate PER trap

Quoted 6 lines
 arch/s390/include/asm/ptrace.h |  4 +---
 arch/s390/kernel/entry.S       |  9 +++++----
 arch/s390/kernel/entry.h       | 10 ++++++++--
 arch/s390/kernel/syscall.c     |  4 ++--
 arch/s390/kernel/traps.c       |  4 ++--
 5 files changed, 18 insertions(+), 13 deletions(-)
maintainer Applied
#4 lore raw
In reply to Sven Schnelle
Quoted 9 lines · Sven Schnelle

While looking at the syscall code I noticed that entry.S still sets PIF_GUEST_FAULT in ptregs even though it's only used in __do_pgm_check(). Remove that and pass it directly to __do_pgm_check(). Heiko suggested to also add a define for the per trap flag in system_call().

Sven Schnelle (2):
s390/traps: Remove PIF_GUEST_FAULT
s390/syscalls: Use define instead of '1' to indicate PER trap

Quoted 6 lines
 arch/s390/include/asm/ptrace.h |  4 +---
 arch/s390/kernel/entry.S       |  9 +++++----
 arch/s390/kernel/entry.h       | 10 ++++++++--
 arch/s390/kernel/syscall.c     |  4 ++--
 arch/s390/kernel/traps.c       |  4 ++--
 5 files changed, 18 insertions(+), 13 deletions(-)

Applied, thank you!