Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/mem_detect: fix tprot() program check new psw handling

The tprot() 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@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>

authored by

Heiko Carstens and committed by
Vasily Gorbik
da905757 1b2f281f

+17 -11
+17 -11
arch/s390/boot/mem_detect.c
··· 118 118 119 119 static int tprot(unsigned long addr) 120 120 { 121 - unsigned long pgm_addr; 121 + unsigned long reg1, reg2; 122 122 int rc = -EFAULT; 123 - psw_t old = S390_lowcore.program_new_psw; 123 + psw_t old; 124 124 125 - S390_lowcore.program_new_psw.mask = __extract_psw(); 126 125 asm volatile( 127 - " larl %[pgm_addr],1f\n" 128 - " stg %[pgm_addr],%[psw_pgm_addr]\n" 126 + " mvc 0(16,%[psw_old]),0(%[psw_pgm])\n" 127 + " epsw %[reg1],%[reg2]\n" 128 + " st %[reg1],0(%[psw_pgm])\n" 129 + " st %[reg2],4(%[psw_pgm])\n" 130 + " larl %[reg1],1f\n" 131 + " stg %[reg1],8(%[psw_pgm])\n" 129 132 " tprot 0(%[addr]),0\n" 130 133 " ipm %[rc]\n" 131 134 " srl %[rc],28\n" 132 - "1:\n" 133 - : [pgm_addr] "=&d"(pgm_addr), 134 - [psw_pgm_addr] "=Q"(S390_lowcore.program_new_psw.addr), 135 - [rc] "+&d"(rc) 136 - : [addr] "a"(addr) 135 + "1: mvc 0(16,%[psw_pgm]),0(%[psw_old])\n" 136 + : [reg1] "=&d" (reg1), 137 + [reg2] "=&a" (reg2), 138 + [rc] "+&d" (rc), 139 + "=Q" (S390_lowcore.program_new_psw.addr), 140 + "=Q" (old) 141 + : [psw_old] "a" (&old), 142 + [psw_pgm] "a" (&S390_lowcore.program_new_psw), 143 + [addr] "a" (addr) 137 144 : "cc", "memory"); 138 - S390_lowcore.program_new_psw = old; 139 145 return rc; 140 146 } 141 147