x86/asm/entry/32, selftests: Add 'test_syscall_vdso' test
PATCH RESEND v4 1/1 x86/asm/entry/32, selftests: Add 'test_syscall_vdso' test
This new test checks that all x86 registers are preserved across 32-bit syscalls. It tests syscalls through VDSO (if available) and through INT 0x80, normally and under ptrace.
If kernel is a 64-bit one, high registers (r8..r15) are poisoned before the syscall is called and are checked afterwards.
They must be either preserved, or cleared to zero (but r11 is special); r12..15 must be preserved for INT 0x80.
EFLAGS is checked for changes too, but change there is not considered to be a bug (paravirt kernels do not preserve arithmetic flags).
Run-tested on 64-bit kernel:
$ ./test_syscall_vdso_32 [RUN] Executing 6-argument 32-bit syscall via VDSO [OK] Arguments are preserved across syscall [NOTE] R11 has changed:0000000000200ed7 - assuming clobbered by SYSRET insn [OK] R8..R15 did not leak kernel data [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscall [OK] R8..R15 did not leak kernel data [RUN] Running tests under ptrace [RUN] Executing 6-argument 32-bit syscall via VDSO [OK] Arguments are preserved across syscall [OK] R8..R15 did not leak kernel data [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscall [OK] R8..R15 did not leak kernel data
On 32-bit paravirt kernel:
$ ./test_syscall_vdso_32 [NOTE] Not a 64-bit kernel, won't test R8..R15 leaks [RUN] Executing 6-argument 32-bit syscall via VDSO [WARN] Flags before=0000000000200ed7 id 0 00 o d i s z 0 a 0 p 1 c [WARN] Flags after=0000000000200246 id 0 00 i z 0 0 p 1 [WARN] Flags change=0000000000000c91 0 00 o d s 0 a 0 0 c [OK] Arguments are preserved across syscall [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscall [RUN] Running tests under ptrace [RUN] Executing 6-argument 32-bit syscall via VDSO [OK] Arguments are preserved across syscall [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscall
---
Changes in v2:
does not fail if VDSO can't be found;
tests INT 80 syscall method;
tests syscalls under ptrace;
switched to /* */ comments
Changes in v3:
added checking for r8..r15 info leaks
Changes in v4:
re-added Makefile change
tools/testing/selftests/x86/Makefile | 2 +- tools/testing/selftests/x86/test_syscall_vdso.c | 401 ++++++++++++++++++++++++ tools/testing/selftests/x86/thunks_32.S | 55 ++++ 3 files changed, 457 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/x86/test_syscall_vdso.c create mode 100644 tools/testing/selftests/x86/thunks_32.S
tools/testing/selftests/x86/Makefile +2 -1
@@ -5,7 +5,7 @@ include ../lib.mk .PHONY: all all_32 all_64 warn_32bit_failure clean TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs ldt_gdt syscall_nt -TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn +TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn test_syscall_vdso TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
@@ -60,3 +60,4 @@ endif # Some tests have additional dependencies. sysret_ss_attrs_64: thunks.S +test_syscall_vdso_32: thunks_32.S
tools/testing/selftests/x86/test_syscall_vdso.c new file +401 -0
401 lines not on this page · raw message
tools/testing/selftests/x86/thunks_32.S new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
1.8.1.4
Quoted 49 lines · Denys Vlasenko
This new test checks that all x86 registers are preserved across 32-bit syscalls. It tests syscalls through VDSO (if available) and through INT
0x80, normally and under ptrace.If kernel is a 64-bit one, high registers (r8..r15) are poisoned before the syscall is called and are checked afterwards.
They must be either preserved, or cleared to zero (but r11 is special); r12..15 must be preserved for INT
0x80.EFLAGS is checked for changes too, but change there is not considered to be a bug (paravirt kernels do not preserve arithmetic flags).
Run-tested on 64-bit kernel:
$ ./test_syscall_vdso_32 [RUN] Executing 6-argument 32-bit syscall via VDSO [OK] Arguments are preserved across syscall [NOTE] R11 has changed:0000000000200ed7 - assuming clobbered by SYSRET insn [OK] R8..R15 did not leak kernel data [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscall [OK] R8..R15 did not leak kernel data [RUN] Running tests under ptrace [RUN] Executing 6-argument 32-bit syscall via VDSO [OK] Arguments are preserved across syscall [OK] R8..R15 did not leak kernel data [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscall [OK] R8..R15 did not leak kernel dataOn 32-bit paravirt kernel:
$ ./test_syscall_vdso_32 [NOTE] Not a 64-bit kernel, won't test R8..R15 leaks [RUN] Executing 6-argument 32-bit syscall via VDSO [WARN] Flags before=0000000000200ed7 id 0 00 o d i s z 0 a 0 p 1 c [WARN] Flags after=0000000000200246 id 0 00 i z 0 0 p 1 [WARN] Flags change=0000000000000c91 0 00 o d s 0 a 0 0 c [OK] Arguments are preserved across syscall [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscall [RUN] Running tests under ptrace [RUN] Executing 6-argument 32-bit syscall via VDSO [OK] Arguments are preserved across syscall [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscall
Quoted 14 lines
Signed-off-by Denys Vlasenko <[email protected]>CC Linus Torvalds <[email protected]>CC Steven Rostedt <[email protected]>CC Ingo Molnar <[email protected]>CC Borislav Petkov <[email protected]>CC "H. Peter Anvin" <[email protected]>CC Andy Lutomirski <[email protected]>CC Oleg Nesterov <[email protected]>CC Frederic Weisbecker <[email protected]>CC Alexei Starovoitov <[email protected]>CC Will Drewry <[email protected]>CC Kees Cook <[email protected]>
with minor caveats below, none of which are show-stoppers...
tools/testing/selftests/x86/test_syscall_vdso.c line 161
Quoted 12 lines
tools/testing/selftests/x86/test_syscall_vdso.c new file +12
-0+/* INT80 syscall entrypoint can be used by +* 64-bit programs too, unlike SYSCALL/SYSENTER. +* Therefore it must preserve R12+ +* (they are callee-saved registers in 64-bit C ABI). +* +* This was probably historically not intended, +* but R8..11 are clobbered (cleared to 0). +* IOW: they are the only registers which aren't +* preserved across INT80 syscall. +*/ +if (*r64 ==0 && num <=11 ) +continue ;
Ugh. I'll change my big entry patchset to preserve these and maybe to preserve all of the 64-bit regs.
tools/testing/selftests/x86/test_syscall_vdso.c line 389
Quoted 13 lines
tools/testing/selftests/x86/test_syscall_vdso.c new file +13
-0+int main (int argc,char **argv,char **envp) +{ +int exitcode =0 ; +int cs; + + asm("\n" +" movl %%cs, %%eax\n" + :"=a" (cs) + ); + kernel_is_64bit = (cs ==0x23 ); +if (!kernel_is_64bit) +printf ("[NOTE]\tNot a 64-bit kernel, won't test R8..R15 leaks\n" ); +
Does this work on Xen? IIRC Xen is quite likely to land you in a funny Xen-specific CS.
If you want to be fancier, you could borrow cs_bitness from sigreturn.c.
tools/testing/selftests/x86/thunks_32.S
Quoted 17 lines
tools/testing/selftests/x86/test_syscall_vdso.c new file +12
-0+/* This only works for non-static builds: +* syscall_addr = dlsym(dlopen("linux-gate.so.1", RTLD_NOW), "__kernel_vsyscall"); +*/ + syscall_addr =get_syscall (envp); + + exitcode +=run_syscall_twice (); +ptrace_me (); + exitcode +=run_syscall_twice (); + + return exitcode; +} +#endif tools/testing/selftests/x86/thunks_32.S new file +0
-0
As a followup, we should rename thunks.S to thunks_64.S or just merge both of them into one file.
--Andy
Quoted 82 lines · Andy Lutomirski
Quoted 49 lines · Denys Vlasenko
This new test checks that all x86 registers are preserved across 32-bit syscalls. It tests syscalls through VDSO (if available) and through INT
0x80, normally and under ptrace.If kernel is a 64-bit one, high registers (r8..r15) are poisoned before the syscall is called and are checked afterwards.
They must be either preserved, or cleared to zero (but r11 is special); r12..15 must be preserved for INT
0x80.EFLAGS is checked for changes too, but change there is not considered to be a bug (paravirt kernels do not preserve arithmetic flags).
Run-tested on 64-bit kernel:
$ ./test_syscall_vdso_32 [RUN] Executing 6-argument 32-bit syscall via VDSO [OK] Arguments are preserved across syscall [NOTE] R11 has changed:0000000000200ed7 - assuming clobbered by SYSRET insn [OK] R8..R15 did not leak kernel data [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscall [OK] R8..R15 did not leak kernel data [RUN] Running tests under ptrace [RUN] Executing 6-argument 32-bit syscall via VDSO [OK] Arguments are preserved across syscall [OK] R8..R15 did not leak kernel data [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscall [OK] R8..R15 did not leak kernel dataOn 32-bit paravirt kernel:
$ ./test_syscall_vdso_32 [NOTE] Not a 64-bit kernel, won't test R8..R15 leaks [RUN] Executing 6-argument 32-bit syscall via VDSO [WARN] Flags before=0000000000200ed7 id 0 00 o d i s z 0 a 0 p 1 c [WARN] Flags after=0000000000200246 id 0 00 i z 0 0 p 1 [WARN] Flags change=0000000000000c91 0 00 o d s 0 a 0 0 c [OK] Arguments are preserved across syscall [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscall [RUN] Running tests under ptrace [RUN] Executing 6-argument 32-bit syscall via VDSO [OK] Arguments are preserved across syscall [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscallQuoted 14 lines
Signed-off-by Denys Vlasenko <[email protected]>CC Linus Torvalds <[email protected]>CC Steven Rostedt <[email protected]>CC Ingo Molnar <[email protected]>CC Borislav Petkov <[email protected]>CC "H. Peter Anvin" <[email protected]>CC Andy Lutomirski <[email protected]>CC Oleg Nesterov <[email protected]>CC Frederic Weisbecker <[email protected]>CC Alexei Starovoitov <[email protected]>CC Will Drewry <[email protected]>CC Kees Cook <[email protected]>Acked-by Andy Lutomirski <[email protected]>with minor caveats below, none of which are show-stoppers...
tools/testing/selftests/x86/test_syscall_vdso.c line 161
Quoted 12 lines
tools/testing/selftests/x86/test_syscall_vdso.c new file +12
-0+/* INT80 syscall entrypoint can be used by +* 64-bit programs too, unlike SYSCALL/SYSENTER. +* Therefore it must preserve R12+ +* (they are callee-saved registers in 64-bit C ABI). +* +* This was probably historically not intended, +* but R8..11 are clobbered (cleared to 0). +* IOW: they are the only registers which aren't +* preserved across INT80 syscall. +*/ +if (*r64 ==0 && num <=11 ) +continue ;
Quoted 2 lines
Ugh. I'll change my big entry patchset to preserve these and maybe to preserve all of the 64-bit regs.
If you do that, this won't change the ABI: we don't _promise_ to save them. If we accidentally do, that means nothing.
If you do that, the test won't fail. The code above does not require regs to be 0 - there is further code which also allow them to be unchanged.
(I'm not very comfortable about additional six push/pops which are necessary for this to happen. I'm surprised maintainers tentatively agreed to that -
I was grilled and asked to prove with measurements
that *one* additional push+pop wasn't adding significant overhead).
Quoted 93 lines · Denys Vlasenko
Quoted 82 lines · Andy Lutomirski
Quoted 49 lines · Denys Vlasenko
This new test checks that all x86 registers are preserved across 32-bit syscalls. It tests syscalls through VDSO (if available) and through INT
0x80, normally and under ptrace.If kernel is a 64-bit one, high registers (r8..r15) are poisoned before the syscall is called and are checked afterwards.
They must be either preserved, or cleared to zero (but r11 is special); r12..15 must be preserved for INT
0x80.EFLAGS is checked for changes too, but change there is not considered to be a bug (paravirt kernels do not preserve arithmetic flags).
Run-tested on 64-bit kernel:
$ ./test_syscall_vdso_32 [RUN] Executing 6-argument 32-bit syscall via VDSO [OK] Arguments are preserved across syscall [NOTE] R11 has changed:0000000000200ed7 - assuming clobbered by SYSRET insn [OK] R8..R15 did not leak kernel data [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscall [OK] R8..R15 did not leak kernel data [RUN] Running tests under ptrace [RUN] Executing 6-argument 32-bit syscall via VDSO [OK] Arguments are preserved across syscall [OK] R8..R15 did not leak kernel data [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscall [OK] R8..R15 did not leak kernel dataOn 32-bit paravirt kernel:
$ ./test_syscall_vdso_32 [NOTE] Not a 64-bit kernel, won't test R8..R15 leaks [RUN] Executing 6-argument 32-bit syscall via VDSO [WARN] Flags before=0000000000200ed7 id 0 00 o d i s z 0 a 0 p 1 c [WARN] Flags after=0000000000200246 id 0 00 i z 0 0 p 1 [WARN] Flags change=0000000000000c91 0 00 o d s 0 a 0 0 c [OK] Arguments are preserved across syscall [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscall [RUN] Running tests under ptrace [RUN] Executing 6-argument 32-bit syscall via VDSO [OK] Arguments are preserved across syscall [RUN] Executing 6-argument 32-bit syscall via INT 80 [OK] Arguments are preserved across syscallQuoted 14 lines
Signed-off-by Denys Vlasenko <[email protected]>CC Linus Torvalds <[email protected]>CC Steven Rostedt <[email protected]>CC Ingo Molnar <[email protected]>CC Borislav Petkov <[email protected]>CC "H. Peter Anvin" <[email protected]>CC Andy Lutomirski <[email protected]>CC Oleg Nesterov <[email protected]>CC Frederic Weisbecker <[email protected]>CC Alexei Starovoitov <[email protected]>CC Will Drewry <[email protected]>CC Kees Cook <[email protected]>Acked-by Andy Lutomirski <[email protected]>with minor caveats below, none of which are show-stoppers...
tools/testing/selftests/x86/test_syscall_vdso.c line 161
Quoted 12 lines
tools/testing/selftests/x86/test_syscall_vdso.c new file +12
-0+/* INT80 syscall entrypoint can be used by +* 64-bit programs too, unlike SYSCALL/SYSENTER. +* Therefore it must preserve R12+ +* (they are callee-saved registers in 64-bit C ABI). +* +* This was probably historically not intended, +* but R8..11 are clobbered (cleared to 0). +* IOW: they are the only registers which aren't +* preserved across INT80 syscall. +*/ +if (*r64 ==0 && num <=11 ) +continue ;Quoted 2 lines
Ugh. I'll change my big entry patchset to preserve these and maybe to preserve all of the 64-bit regs.
If you do that, this won't change the ABI: we don't _promise_ to save them. If we accidentally do, that means nothing.
If you do that, the test won't fail. The code above does not require regs to be 0 - there is further code which also allow them to be unchanged.
Quoted 5 lines
(I'm not very comfortable about additional six push/pops which are necessary for this to happen. I'm surprised maintainers tentatively agreed to that -
I was grilled and asked to prove with measurements
that *one* additional push+pop wasn't adding significant overhead).
I suspect that I need to make the series faster.
Also, int $0x80 isn't a fast path for any legitimate use case except Debian, and I would argue that Debian is just buggy.
--Andy
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Quoted 10 lines · Andy Lutomirski
Quoted 5 lines
(I'm not very comfortable about additional six push/pops which are necessary for this to happen. I'm surprised maintainers tentatively agreed to that -
I was grilled and asked to prove with measurements
that *one* additional push+pop wasn't adding significant overhead).I suspect that I need to make the series faster.
Also, int $0x80 isn't a fast path for any legitimate use case except Debian, and I would argue that Debian is just buggy.
So buggy in the sense of not making use of faster syscalls, right? It won't break in any visible way, correct?
So if this heavy int80 syscall use happens even with the latest version of Debian as well then it would be nice to figure out what's wrong there, and provide an optimization patch to their libc guys or so - to make sure we fully understand the problem.
Thanks,
Ingo
Quoted 10 lines · Ingo Molnar
Quoted 6 lines · Andy Lutomirski
Quoted 5 lines
(I'm not very comfortable about additional six push/pops which are necessary for this to happen. I'm surprised maintainers tentatively agreed to that -
I was grilled and asked to prove with measurements
that *one* additional push+pop wasn't adding significant overhead).
Quoted 7 lines
Quoted 4 lines
I suspect that I need to make the series faster.
Also, int $0x80 isn't a fast path for any legitimate use case except Debian, and I would argue that Debian is just buggy.
So buggy in the sense of not making use of faster syscalls, right? It won't break in any visible way, correct?
Correct. The only visible breakage I know of is that my unwind selftest fails if compiled by a Debian toolchain, and I'll fix that in v2.
Quoted 5 lines
So if this heavy int80 syscall use happens even with the latest version of Debian as well then it would be nice to figure out what's wrong there, and provide an optimization patch to their libc guys or so - to make sure we fully understand the problem.
I looked for a bit and drew a blank, but I know I'm bad at understanding Debian packaging and even worse at understanding the mess that is glibc's pile of multiply compiled files. I'll file a bug or something.
--Andy
Quoted 13 lines · Denys Vlasenko
Quoted 13 lines
Quoted 12 lines
tools/testing/selftests/x86/test_syscall_vdso.c new file +12
-0+/* INT80 syscall entrypoint can be used by +* 64-bit programs too, unlike SYSCALL/SYSENTER. +* Therefore it must preserve R12+ +* (they are callee-saved registers in 64-bit C ABI). +* +* This was probably historically not intended, +* but R8..11 are clobbered (cleared to 0). +* IOW: they are the only registers which aren't +* preserved across INT80 syscall. +*/ +if (*r64 ==0 && num <=11 ) +continue ;
Quoted 5 lines
Quoted 2 lines
Ugh. I'll change my big entry patchset to preserve these and maybe to preserve all of the 64-bit regs.
If you do that, this won't change the ABI: we don't _promise_ to save them. If we accidentally do, that means nothing.
Argh, that's dangerous nonsense! You _still_ don't seem to understand what the Linux ABI means and how to change code that implements it...
Let me try one more time, and please make the mental effort to understand and internalize it, because I'm not going to apply any more ABI affecting patches from you if you don't...
When you read 'ABI' you always need to write it out mentally:
_Application_ Binary Interface
Do you see the word 'kernel developer' in that phrase? I don't, and this really
matters: what an ABI is does not depend on what the kernel developers think or thought it means. Our state of mind, our design preferences, our documentation and our intentions are absolutely irrelevant.
What an ABI is purely depends on is whether applications break or change behavior as a result of us changing it.
What an ABI depends on is how applications (pretty much any real application or library, no matter how rare) learned to use the kernel's previous implementation of the ABI, in released kernels - in every tiny detail of that ABI.
If _any_ application/library functionally relied on saving registers in this place
- even if that behavior was 'accidental' from the kernel developer's POV, and if the app would break or misbehave if we changed that detail, then that's an 'accidental ABI', which is an ABI just as much!!!
This is why we preserve old quirks and this is why we try to be 110% careful around ABIs, especially low level ones that expose a big set of hardware registers that applications could rely on in unexpected ways.
Not because we couldn't "fix" them, but because an ABI is a long term contract: we promise absolutely no breakage to applications, no matter what.
Mistaken ABIs, unintended ABIs, deterministically quirky ABIs that apps/libs learned to rely on, even if the ABI usage in the app itself is just a bug or is otherwise unintended, has _exactly_ the same ABI strength as our sys_close() ABI.
There are some very, very rare expections, but none of them apply here:
- If an ABI component behaved non-deterministically (relying on random stack content for example) then we cannot always fully preserve it when fixing it - but we'll generally gravitate towards trying to fix it while preserving existing apps.
- Sometimes, 1 out of 100,000 kernel bugs, preserving an old, rare ABI would mean introducing or allowing a serious security hole. There's been less than 3 such cases in all of the 500,000+ commits in the Linux kernel that I'm aware of, so this is not a case you need to even know about.
- Testcases whose only purpose is to bake in every single silly detail from an exposed ABI generally don't count. Only if a real app/lib that people use is affected counts. (There are exceptions even to this exception: if the ABI change that breaks a test-case is obviously gratuitous then the ABI counts:
because reasonably there _might_ be apps out there that rely on the reasonable old behavior, they just haven't been reported yet.) Obviously an ABI test-case failing is a red flag, and by default we should assume we messed up and need to unbreak the ABI - unless we are absolutely convinced it's OK. And even if we think it's absolutely OK it takes just a single regression report of an application breaking to revert an ABI change - no questions asked.
Quoted 4 lines
(I'm not very comfortable about additional six push/pops which are necessary for this to happen. I'm surprised maintainers tentatively agreed to that - I was grilled and asked to prove with measurements that *one* additional push+pop wasn't adding significant overhead).
Yeah, so here's our thinking: the code is still not as maintainable as we wish it to be, so we are willing to temporarily accept those pop/pushes to help along the C conversion effort, to make the code (much!) more maintainable.
Other changes still have to be justified on an instruction granular manner.
Thanks,
Ingo
Quoted 17 lines · Ingo Molnar
Quoted 13 lines · Denys Vlasenko
Quoted 13 lines
Quoted 12 lines
tools/testing/selftests/x86/test_syscall_vdso.c new file +12
-0+/* INT80 syscall entrypoint can be used by +* 64-bit programs too, unlike SYSCALL/SYSENTER. +* Therefore it must preserve R12+ +* (they are callee-saved registers in 64-bit C ABI). +* +* This was probably historically not intended, +* but R8..11 are clobbered (cleared to 0). +* IOW: they are the only registers which aren't +* preserved across INT80 syscall. +*/ +if (*r64 ==0 && num <=11 ) +continue ;
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Ugh. I'll change my big entry patchset to preserve these and maybe to preserve all of the 64-bit regs.
If you do that, this won't change the ABI: we don't _promise_ to save them. If we accidentally do, that means nothing.
Argh, that's dangerous nonsense! You _still_ don't seem to understand what the Linux ABI means and how to change code that implements it...
I think Denys might be taking about R8-R11 here. If we change them from clobbered to saved, that's probably fine. Certainly I have to save R12-R15 -- my v1 is just buggy there. I was too deep in __kernel_vsyscall when I wrote that code, and I wasn't thinking about the raw int $0x80 entry variant.
I'd be rather surprised if anything broke if we started preserving R8-R11 instead of zeroing them.
--Andy
Quoted 27 lines · Andy Lutomirski
Quoted 17 lines · Ingo Molnar
Quoted 13 lines · Denys Vlasenko
Quoted 13 lines
Quoted 12 lines
tools/testing/selftests/x86/test_syscall_vdso.c new file +12
-0+/* INT80 syscall entrypoint can be used by +* 64-bit programs too, unlike SYSCALL/SYSENTER. +* Therefore it must preserve R12+ +* (they are callee-saved registers in 64-bit C ABI). +* +* This was probably historically not intended, +* but R8..11 are clobbered (cleared to 0). +* IOW: they are the only registers which aren't +* preserved across INT80 syscall. +*/ +if (*r64 ==0 && num <=11 ) +continue ;Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Ugh. I'll change my big entry patchset to preserve these and maybe to preserve all of the 64-bit regs.
If you do that, this won't change the ABI: we don't _promise_ to save them. If we accidentally do, that means nothing.
Argh, that's dangerous nonsense! You _still_ don't seem to understand what the Linux ABI means and how to change code that implements it...
Quoted 8 lines
I think Denys might be taking about R8-R11 here. If we change them from clobbered to saved, that's probably fine. Certainly I have to save R12-R15 -- my v1 is just buggy there. I was too deep in
__kernel_vsyscallwhen I wrote that code, and I wasn't thinking about the raw int $0x80 entry variant.I'd be rather surprised if anything broke if we started preserving R8-R11 instead of zeroing them.
Well, read the statement:
" If you do that, this won't change the ABI: we don't _promise_
to save them. If we accidentally do, that means nothing. "
of _course_ it means everything: if we preserve R8-R11 and any app learns to rely on it, it becomes an ABI.
What we 'promise' with our implementation and what our intentions are are entirely irrelevant, they simply don't matter to ABI compatibility: it's only what apps do with our released kernels that matters, in 99.998% of the cases..
And I'd really like that thinking to permeate everyone's mind who is regularly changing this type of code ...
Thanks,
Ingo
Quoted 40 lines · Ingo Molnar
Quoted 27 lines · Andy Lutomirski
Quoted 17 lines · Ingo Molnar
Quoted 13 lines · Denys Vlasenko
Quoted 13 lines
Quoted 12 lines
tools/testing/selftests/x86/test_syscall_vdso.c new file +12
-0+/* INT80 syscall entrypoint can be used by +* 64-bit programs too, unlike SYSCALL/SYSENTER. +* Therefore it must preserve R12+ +* (they are callee-saved registers in 64-bit C ABI). +* +* This was probably historically not intended, +* but R8..11 are clobbered (cleared to 0). +* IOW: they are the only registers which aren't +* preserved across INT80 syscall. +*/ +if (*r64 ==0 && num <=11 ) +continue ;Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Ugh. I'll change my big entry patchset to preserve these and maybe to preserve all of the 64-bit regs.
If you do that, this won't change the ABI: we don't _promise_ to save them. If we accidentally do, that means nothing.
Argh, that's dangerous nonsense! You _still_ don't seem to understand what the Linux ABI means and how to change code that implements it...
Quoted 8 lines
I think Denys might be taking about R8-R11 here. If we change them from clobbered to saved, that's probably fine. Certainly I have to save R12-R15 -- my v1 is just buggy there. I was too deep in
__kernel_vsyscallwhen I wrote that code, and I wasn't thinking about the raw int $0x80 entry variant.I'd be rather surprised if anything broke if we started preserving R8-R11 instead of zeroing them.
Quoted 7 lines
Well, read the statement:
" If you do that, this won't change the ABI: we don't _promise_
to save them. If we accidentally do, that means nothing. "of _course_ it means everything: if we preserve R8-R11 and any app learns to rely on it, it becomes an ABI.
Right, it changes the ABI in a way that we can't undo, but it probably doesn't break the old ABI.
Certainly for v2, I'll try to preserve the old behavior exactly. If we change it later to preserve all high regs, that'll be a separate patch.
--Andy
Quoted 43 lines · Andy Lutomirski
Quoted 42 lines · Ingo Molnar
Quoted 27 lines · Andy Lutomirski
Quoted 17 lines · Ingo Molnar
Quoted 13 lines · Denys Vlasenko
Quoted 13 lines
Quoted 12 lines
(quoted diff) +12
-0+ /* INT80 syscall entrypoint can be used by + * 64-bit programs too, unlike SYSCALL/SYSENTER. + * Therefore it must preserve R12+ + * (they are callee-saved registers in 64-bit C ABI). + * + * This was probably historically not intended, + * but R8..11 are clobbered (cleared to 0). + * IOW: they are the only registers which aren't + * preserved across INT80 syscall. + */ + if (*r64 == 0 && num <= 11) + continue;Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Ugh. I'll change my big entry patchset to preserve these and maybe to preserve all of the 64-bit regs.
If you do that, this won't change the ABI: we don't _promise_ to save them. If we accidentally do, that means nothing.
Argh, that's dangerous nonsense! You _still_ don't seem to understand what the Linux ABI means and how to change code that implements it...
Quoted 8 lines
I think Denys might be taking about R8-R11 here. If we change them from clobbered to saved, that's probably fine. Certainly I have to save R12-R15 -- my v1 is just buggy there. I was too deep in
__kernel_vsyscallwhen I wrote that code, and I wasn't thinking about the raw int $0x80 entry variant.I'd be rather surprised if anything broke if we started preserving R8-R11 instead of zeroing them.
Well, read the statement:
Quoted 8 lines
Quoted 5 lines
" If you do that, this won't change the ABI: we don't _promise_
to save them. If we accidentally do, that means nothing. "of _course_ it means everything: if we preserve R8-R11 and any app learns to rely on it, it becomes an ABI.
Right, it changes the ABI in a way that we can't undo, but it probably doesn't break the old ABI.
it's unknown: user-space code might have (unknowingly) started relying on the zeroing behavior. If that happened (and let's hope it didn't - but there's no guarantee), then the zeroing behavior is an ABI too.
Quoted 3 lines
Certainly for v2, I'll try to preserve the old behavior exactly. If we change it later to preserve all high regs, that'll be a separate patch.
Yeah, cleanly separating ABI-invariant patches from ABI-impacting ones (no matter how innocious the effect on the ABI looks) is a must.
Thanks,
Ingo
Quoted 6 lines · Denys Vlasenko
tools/testing/selftests/x86/Makefile | 2 +- tools/testing/selftests/x86/test_syscall_vdso.c | 401 ++++++++++++++++++++++++ tools/testing/selftests/x86/thunks_32.S | 55 ++++ 3 files changed, 457 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/x86/test_syscall_vdso.c create mode 100644 tools/testing/selftests/x86/thunks_32.S
So I wanted to apply this testcase (testcases are great!), but there's a build warning:
test_syscall_vdso.c: In function ‘print_flags’:
test_syscall_vdso.c:239:4: warning: format not a string literal and no format arguments [-Wformat-security]
printf(bitstr[(r >> bit) & 1]);
^That's with GCC 4.9.2.
Thanks,
Ingo