Skip to content

Commit 2a405f6

Browse files
hcahcaVasily Gorbik
authored andcommitted
s390/stackleak: provide fast __stackleak_poison() implementation
Provide an s390 specific __stackleak_poison() implementation which is faster than the generic variant. For the original implementation with an enforced 4kb stackframe for the getpid() system call the system call overhead increases by a factor of 3 if the stackleak feature is enabled. Using the s390 mvc based variant this is reduced to an increase of 25% instead. This is within the expected area, since the mvc based implementation is more or less a memset64() variant which comes with similar results. See commit 0b77d67 ("s390: implement memset16, memset32 & memset64"). Reviewed-by: Vasily Gorbik <[email protected]> Signed-off-by: Heiko Carstens <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vasily Gorbik <[email protected]>
1 parent 491a786 commit 2a405f6

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

arch/s390/include/asm/processor.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,41 @@ unsigned long vdso_size(void);
118118

119119
#define HAVE_ARCH_PICK_MMAP_LAYOUT
120120

121+
#define __stackleak_poison __stackleak_poison
122+
static __always_inline void __stackleak_poison(unsigned long erase_low,
123+
unsigned long erase_high,
124+
unsigned long poison)
125+
{
126+
unsigned long tmp, count;
127+
128+
count = erase_high - erase_low;
129+
if (!count)
130+
return;
131+
asm volatile(
132+
" cghi %[count],8\n"
133+
" je 2f\n"
134+
" aghi %[count],-(8+1)\n"
135+
" srlg %[tmp],%[count],8\n"
136+
" ltgr %[tmp],%[tmp]\n"
137+
" jz 1f\n"
138+
"0: stg %[poison],0(%[addr])\n"
139+
" mvc 8(256-8,%[addr]),0(%[addr])\n"
140+
" la %[addr],256(%[addr])\n"
141+
" brctg %[tmp],0b\n"
142+
"1: stg %[poison],0(%[addr])\n"
143+
" larl %[tmp],3f\n"
144+
" ex %[count],0(%[tmp])\n"
145+
" j 4f\n"
146+
"2: stg %[poison],0(%[addr])\n"
147+
" j 4f\n"
148+
"3: mvc 8(1,%[addr]),0(%[addr])\n"
149+
"4:\n"
150+
: [addr] "+&a" (erase_low), [count] "+&d" (count), [tmp] "=&a" (tmp)
151+
: [poison] "d" (poison)
152+
: "memory", "cc"
153+
);
154+
}
155+
121156
/*
122157
* Thread structure
123158
*/

0 commit comments

Comments
 (0)