[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6F6D3FEC-9AF1-40E1-A7C2-394D21C40114@zytor.com>
Date: Tue, 02 Nov 2021 12:22:50 +0100
From: "H. Peter Anvin" <hpa@...or.com>
To: Borislav Petkov <bp@...en8.de>,
Lai Jiangshan <laijs@...ux.alibaba.com>
CC: Lai Jiangshan <jiangshanlai@...il.com>,
linux-kernel@...r.kernel.org, x86@...nel.org,
Jan Beulich <jbeulich@...e.com>,
Thomas Gleixner <tglx@...utronix.de>,
Juergen Gross <jgross@...e.com>,
xen-devel@...ts.xenproject.org, Andy Lutomirski <luto@...nel.org>,
Ingo Molnar <mingo@...hat.com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Boris Ostrovsky <boris.ostrovsky@...cle.com>,
Stefano Stabellini <sstabellini@...nel.org>
Subject: Re: [PATCH V4 04/50] x86/xen: Add xenpv_restore_regs_and_return_to_usermode()
On November 2, 2021 10:49:44 AM GMT+01:00, Borislav Petkov <bp@...en8.de> wrote:
>On Tue, Nov 02, 2021 at 05:19:46PM +0800, Lai Jiangshan wrote:
>> It will add a 5-byte NOP at the beginning of the native
>> swapgs_restore_regs_and_return_to_usermode.
>
>So?
>
It would be interesting to have an "override function with jmp" alternatives macro. It doesn't require any changes to the alternatives mechanism proper (but possibly to objtool): it would just insert an alternatives entry without adding any code including nops to the main path. It would of course only be applicable to a jmp, so a syntax like OVERRIDE_JMP feature, target rather than open-coding the instruction would probably be a good idea.
That would reduce the trade-off to zero.
>> I avoided adding unneeded code in the native code even if it is NOPs
>> and avoided melting xenpv-one into the native one which will reduce
>> the code readability.
>
>How does this reduce code readability?!
>
>diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
>index e38a4cf795d9..bf1de54a1fca 100644
>--- a/arch/x86/entry/entry_64.S
>+++ b/arch/x86/entry/entry_64.S
>@@ -567,6 +567,10 @@ __irqentry_text_end:
>
> SYM_CODE_START_LOCAL(common_interrupt_return)
> SYM_INNER_LABEL(swapgs_restore_regs_and_return_to_usermode, SYM_L_GLOBAL)
>+
>+ ALTERNATIVE "", "jmp xenpv_restore_regs_and_return_to_usermode", \
>+ X86_FEATURE_XENPV
>+
> #ifdef CONFIG_DEBUG_ENTRY
> /* Assert that pt_regs indicates user mode. */
> testb $3, CS(%rsp)
>
>> I will follow your preference since a 5-byte NOP is so negligible in the slow
>> path with an iret instruction.
>
>Yes, we do already gazillion things on those entry and exit paths.
>
>> Or other option that adds macros to wrap the ALTERNATIVE.
>> RESTORE_REGS_AND_RETURN_TO_USERMODE and
>> COND_RESTORE_REGS_AND_RETURN_TO_USERMODE (test %eax before jmp in native case)
>
>No, the main goal is to keep the asm code as readable and as simple as
>possible.
>
>If macros or whatever need to be added, there better be a good reason
>for them. Saving a NOP is not one of them.
>
>Thx.
>
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Powered by blists - more mailing lists