Skip to content

Commit da90575

Browse files
hcahcaVasily Gorbik
authored andcommitted
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>
1 parent 1b2f281 commit da90575

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

‎arch/s390/boot/mem_detect.c‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,30 @@ static int diag260(void)
118118

119119
static int tprot(unsigned long addr)
120120
{
121-
unsigned long pgm_addr;
121+
unsigned long reg1, reg2;
122122
int rc = -EFAULT;
123-
psw_t old = S390_lowcore.program_new_psw;
123+
psw_t old;
124124

125-
S390_lowcore.program_new_psw.mask = __extract_psw();
126125
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"
129132
" tprot 0(%[addr]),0\n"
130133
" ipm %[rc]\n"
131134
" 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)
137144
: "cc", "memory");
138-
S390_lowcore.program_new_psw = old;
139145
return rc;
140146
}
141147

0 commit comments

Comments
 (0)