[PATCH 5.12 107/292] s390/ipl_parm: fix program check new psw handling

From: Greg Kroah-Hartman
Date: Mon Jul 19 2021 - 14:01:59 EST


From: Heiko Carstens <hca@xxxxxxxxxxxxx>

[ Upstream commit 88c2510cecb7e2b518e3c4fdf3cf0e13ebe9377c ]

The __diag308() inline asm temporarily changes the program check new
psw to redirect a potential program check on the diag instruction.
Restoring of the program check new psw is done in C code behind the
inline asm.

This can be problematic, especially if the function is inlined, since
the compiler can reorder instructions in such a way that a different
instruction, which may result in a program check, might be executed
before the program check new psw has been restored.

To avoid such a scenario move restoring into the inline asm. For
consistency reasons move also saving of the original program check new
psw into the inline asm.

Signed-off-by: Heiko Carstens <hca@xxxxxxxxxxxxx>
Signed-off-by: Vasily Gorbik <gor@xxxxxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
arch/s390/boot/ipl_parm.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/arch/s390/boot/ipl_parm.c b/arch/s390/boot/ipl_parm.c
index d372a45fe10e..dd92092e3eec 100644
--- a/arch/s390/boot/ipl_parm.c
+++ b/arch/s390/boot/ipl_parm.c
@@ -28,22 +28,25 @@ static inline int __diag308(unsigned long subcode, void *addr)
register unsigned long _addr asm("0") = (unsigned long)addr;
register unsigned long _rc asm("1") = 0;
unsigned long reg1, reg2;
- psw_t old = S390_lowcore.program_new_psw;
+ psw_t old;

asm volatile(
+ " mvc 0(16,%[psw_old]),0(%[psw_pgm])\n"
" epsw %0,%1\n"
- " st %0,%[psw_pgm]\n"
- " st %1,%[psw_pgm]+4\n"
+ " st %0,0(%[psw_pgm])\n"
+ " st %1,4(%[psw_pgm])\n"
" larl %0,1f\n"
- " stg %0,%[psw_pgm]+8\n"
+ " stg %0,8(%[psw_pgm])\n"
" diag %[addr],%[subcode],0x308\n"
- "1: nopr %%r7\n"
+ "1: mvc 0(16,%[psw_pgm]),0(%[psw_old])\n"
: "=&d" (reg1), "=&a" (reg2),
- [psw_pgm] "=Q" (S390_lowcore.program_new_psw),
+ "+Q" (S390_lowcore.program_new_psw),
+ "=Q" (old),
[addr] "+d" (_addr), "+d" (_rc)
- : [subcode] "d" (subcode)
+ : [subcode] "d" (subcode),
+ [psw_old] "a" (&old),
+ [psw_pgm] "a" (&S390_lowcore.program_new_psw)
: "cc", "memory");
- S390_lowcore.program_new_psw = old;
return _rc;
}

--
2.30.2