[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6d10d7e4-8af4-5398-7c08-8d111d1179ee@gnuweeb.org>
Date: Sat, 8 Jan 2022 07:34:42 +0700
From: Ammar Faizi <ammarfaizi2@...weeb.org>
To: Andy Lutomirski <luto@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
"H. Peter Anvin" <hpa@...or.com>
Cc: x86-ml <x86@...nel.org>, lkml <linux-kernel@...r.kernel.org>,
GNU/Weeb Mailing List <gwml@...weeb.org>,
Michael Matz <matz@...e.de>, "H.J. Lu" <hjl.tools@...il.com>,
Willy Tarreau <w@....eu>
Subject: Re: [PATCH v1 2/3] x86/entry/64: Add info about registers on exit
On 1/8/22 7:03 AM, Andy Lutomirski wrote:
> On 1/7/22 15:52, Ammar Faizi wrote:
>> There was a controversial discussion about the wording in the System
>> V ABI document regarding what registers the kernel is allowed to
>> clobber when the userspace executes syscall.
>>
>> The resolution of the discussion was reviewing the clobber list in
>> the glibc source. For a historical reason in the glibc source, the
>> kernel must restore all registers before returning to the userspace
>> (except for rax, rcx and r11).
>>
>> Link: https://lore.kernel.org/lkml/alpine.LSU.2.20.2110131601000.26294@wotan.suse.de/
>> Link: https://gitlab.com/x86-psABIs/x86-64-ABI/-/merge_requests/25
>>
>> This adds info about registers on exit.
>>
>> Cc: Andy Lutomirski <luto@...nel.org>
>> Cc: Thomas Gleixner <tglx@...utronix.de>
>> Cc: Ingo Molnar <mingo@...hat.com>
>> Cc: Borislav Petkov <bp@...en8.de>
>> Cc: Dave Hansen <dave.hansen@...ux.intel.com>
>> Cc: "H. Peter Anvin" <hpa@...or.com>
>> Cc: Michael Matz <matz@...e.de>
>> Cc: "H.J. Lu" <hjl.tools@...il.com>
>> Cc: Willy Tarreau <w@....eu>
>> Cc: x86-ml <x86@...nel.org>
>> Cc: lkml <linux-kernel@...r.kernel.org>
>> Cc: GNU/Weeb Mailing List <gwml@...weeb.org>
>> Signed-off-by: Ammar Faizi <ammarfaizi2@...weeb.org>
>> ---
[...]
>> diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
>> index e432dd075291..1111fff2e05f 100644
>> --- a/arch/x86/entry/entry_64.S
>> +++ b/arch/x86/entry/entry_64.S
>> @@ -79,6 +79,19 @@
>> *
>> * Only called from user space.
>> *
>> + * Registers on exit:
>> + * rax syscall return value
>> + * rcx return address
>> + * r11 rflags
>> + *
>> + * For a historical reason in the glibc source, the kernel must restore all
>> + * registers except the rax (syscall return value) before returning to the
>> + * userspace.
>> + *
>> + * In other words, with respect to the userspace, when the kernel returns
>> + * to the userspace, only 3 registers are clobbered, they are rax, rcx,
>> + * and r11.
>> + *
>
> I would say this much more concisely:
>
> The Linux kernel preserves all registers (even C callee-clobbered
> registers) except for rax, rcx and r11 across system calls, and
> existing user code relies on this behavior.
Agree, I will take that as Suggested-by in the v2.
--
Ammar Faizi
Download attachment "OpenPGP_signature" of type "application/pgp-signature" (496 bytes)
Powered by blists - more mailing lists