Commit 3c1a3bce authored by Heiko Carstens's avatar Heiko Carstens Committed by Martin Schwidefsky

s390/maccess: improve s390_kernel_write()

Use the sturg instruction instead of the stura instruction. This allows to
modify up to eight bytes in a row instead of only four.

For function tracer enabling and disabling this reduces the time needed to
modify the text sections by 50%, since for each mcount call site six bytes
need to be changed.

Also remove the EXTABLE entries, since calls to this function are not
supposed to fail.
Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent 8a5d8473
/* /*
* Access kernel memory without faulting -- s390 specific implementation. * Access kernel memory without faulting -- s390 specific implementation.
* *
* Copyright IBM Corp. 2009 * Copyright IBM Corp. 2009, 2015
* *
* Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>, * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>,
* *
...@@ -18,28 +18,25 @@ ...@@ -18,28 +18,25 @@
static notrace long s390_kernel_write_odd(void *dst, const void *src, size_t size) static notrace long s390_kernel_write_odd(void *dst, const void *src, size_t size)
{ {
unsigned long count, aligned; unsigned long aligned, offset, count;
int offset, mask; char tmp[8];
int rc = -EFAULT;
aligned = (unsigned long) dst & ~3UL; aligned = (unsigned long) dst & ~7UL;
offset = (unsigned long) dst & 3; offset = (unsigned long) dst & 7UL;
count = min_t(unsigned long, 4 - offset, size); size = min(8UL - offset, size);
mask = (0xf << (4 - count)) & 0xf; count = size - 1;
mask >>= offset;
asm volatile( asm volatile(
" bras 1,0f\n" " bras 1,0f\n"
" icm 0,0,0(%3)\n" " mvc 0(1,%4),0(%5)\n"
"0: l 0,0(%1)\n" "0: mvc 0(8,%3),0(%0)\n"
" lra %1,0(%1)\n" " ex %1,0(1)\n"
"1: ex %2,0(1)\n" " lg %1,0(%3)\n"
"2: stura 0,%1\n" " lra %0,0(%0)\n"
" la %0,0\n" " sturg %1,%0\n"
"3:\n" : "+&a" (aligned), "+&a" (count), "=m" (tmp)
EX_TABLE(0b,3b) EX_TABLE(1b,3b) EX_TABLE(2b,3b) : "a" (&tmp), "a" (&tmp[offset]), "a" (src)
: "+d" (rc), "+a" (aligned) : "cc", "memory", "1");
: "a" (mask), "a" (src) : "cc", "memory", "0", "1"); return size;
return rc ? rc : count;
} }
/* /*
...@@ -50,8 +47,8 @@ static notrace long s390_kernel_write_odd(void *dst, const void *src, size_t siz ...@@ -50,8 +47,8 @@ static notrace long s390_kernel_write_odd(void *dst, const void *src, size_t siz
* *
* This function writes to kernel memory bypassing DAT and possible page table * This function writes to kernel memory bypassing DAT and possible page table
* write protection. It writes to the destination using the sturg instruction. * write protection. It writes to the destination using the sturg instruction.
* Therefore we have a read-modify-write sequence: the function reads four * Therefore we have a read-modify-write sequence: the function reads eight
* bytes from destination at a four byte boundary, modifies the bytes * bytes from destination at an eight byte boundary, modifies the bytes
* requested and writes the result back in a loop. * requested and writes the result back in a loop.
* *
* Note: this means that this function may not be called concurrently on * Note: this means that this function may not be called concurrently on
...@@ -60,12 +57,10 @@ static notrace long s390_kernel_write_odd(void *dst, const void *src, size_t siz ...@@ -60,12 +57,10 @@ static notrace long s390_kernel_write_odd(void *dst, const void *src, size_t siz
*/ */
void notrace s390_kernel_write(void *dst, const void *src, size_t size) void notrace s390_kernel_write(void *dst, const void *src, size_t size)
{ {
long copied = 0; long copied;
while (size) { while (size) {
copied = s390_kernel_write_odd(dst, src, size); copied = s390_kernel_write_odd(dst, src, size);
if (copied < 0)
break;
dst += copied; dst += copied;
src += copied; src += copied;
size -= copied; size -= copied;
......
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