Skip to content

Commit a50b56f

Browse files
hcahcagregkh
authored andcommitted
s390/mem_detect: fix tprot() program check new psw handling
[ Upstream commit da90575 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 7e1e023 commit a50b56f

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
@@ -115,24 +115,30 @@ static int diag260(void)
115115

116116
static int tprot(unsigned long addr)
117117
{
118-
unsigned long pgm_addr;
118+
unsigned long reg1, reg2;
119119
int rc = -EFAULT;
120-
psw_t old = S390_lowcore.program_new_psw;
120+
psw_t old;
121121

122-
S390_lowcore.program_new_psw.mask = __extract_psw();
123122
asm volatile(
124-
" larl %[pgm_addr],1f\n"
125-
" stg %[pgm_addr],%[psw_pgm_addr]\n"
123+
" mvc 0(16,%[psw_old]),0(%[psw_pgm])\n"
124+
" epsw %[reg1],%[reg2]\n"
125+
" st %[reg1],0(%[psw_pgm])\n"
126+
" st %[reg2],4(%[psw_pgm])\n"
127+
" larl %[reg1],1f\n"
128+
" stg %[reg1],8(%[psw_pgm])\n"
126129
" tprot 0(%[addr]),0\n"
127130
" ipm %[rc]\n"
128131
" srl %[rc],28\n"
129-
"1:\n"
130-
: [pgm_addr] "=&d"(pgm_addr),
131-
[psw_pgm_addr] "=Q"(S390_lowcore.program_new_psw.addr),
132-
[rc] "+&d"(rc)
133-
: [addr] "a"(addr)
132+
"1: mvc 0(16,%[psw_pgm]),0(%[psw_old])\n"
133+
: [reg1] "=&d" (reg1),
134+
[reg2] "=&a" (reg2),
135+
[rc] "+&d" (rc),
136+
"=Q" (S390_lowcore.program_new_psw.addr),
137+
"=Q" (old)
138+
: [psw_old] "a" (&old),
139+
[psw_pgm] "a" (&S390_lowcore.program_new_psw),
140+
[addr] "a" (addr)
134141
: "cc", "memory");
135-
S390_lowcore.program_new_psw = old;
136142
return rc;
137143
}
138144

0 commit comments

Comments
 (0)