Commit da905757 authored by Heiko Carstens's avatar Heiko Carstens Committed by Vasily Gorbik

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: default avatarHeiko Carstens <hca@linux.ibm.com>
Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
parent 1b2f281f
...@@ -118,24 +118,30 @@ static int diag260(void) ...@@ -118,24 +118,30 @@ static int diag260(void)
static int tprot(unsigned long addr) static int tprot(unsigned long addr)
{ {
unsigned long pgm_addr; unsigned long reg1, reg2;
int rc = -EFAULT; int rc = -EFAULT;
psw_t old = S390_lowcore.program_new_psw; psw_t old;
S390_lowcore.program_new_psw.mask = __extract_psw();
asm volatile( asm volatile(
" larl %[pgm_addr],1f\n" " mvc 0(16,%[psw_old]),0(%[psw_pgm])\n"
" stg %[pgm_addr],%[psw_pgm_addr]\n" " epsw %[reg1],%[reg2]\n"
" st %[reg1],0(%[psw_pgm])\n"
" st %[reg2],4(%[psw_pgm])\n"
" larl %[reg1],1f\n"
" stg %[reg1],8(%[psw_pgm])\n"
" tprot 0(%[addr]),0\n" " tprot 0(%[addr]),0\n"
" ipm %[rc]\n" " ipm %[rc]\n"
" srl %[rc],28\n" " srl %[rc],28\n"
"1:\n" "1: mvc 0(16,%[psw_pgm]),0(%[psw_old])\n"
: [pgm_addr] "=&d"(pgm_addr), : [reg1] "=&d" (reg1),
[psw_pgm_addr] "=Q"(S390_lowcore.program_new_psw.addr), [reg2] "=&a" (reg2),
[rc] "+&d"(rc) [rc] "+&d" (rc),
: [addr] "a"(addr) "=Q" (S390_lowcore.program_new_psw.addr),
"=Q" (old)
: [psw_old] "a" (&old),
[psw_pgm] "a" (&S390_lowcore.program_new_psw),
[addr] "a" (addr)
: "cc", "memory"); : "cc", "memory");
S390_lowcore.program_new_psw = old;
return rc; return rc;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment