History

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 0b77d6701cf8 ("s390: implement memset16, memset32 & memset64").

Heiko Carstens committed 3 years ago

Commit 2a405f61 parent 491a7861 file · +35 −0Browse files

Unified · Split

arch/s390/include/asm/processor.h+35−0
@@ -118,6 +118,41 @@ unsigned long vdso_size(void); · 117 unmodified lines
118 118
119#define HAVE_ARCH_PICK_MMAP_LAYOUT119#define HAVE_ARCH_PICK_MMAP_LAYOUT
120 120
121#define __stackleak_poison __stackleak_poison
122static __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
121/*156/*
122 * Thread structure157 * Thread structure
123 */158 */