[v7,23/33] x86/fred: let ret_from_fork() jmp to fred_exit_user when FRED is enabled

Message ID 20230404102716.1795-24-xin3.li@intel.com
State New
Headers
Series x86: enable FRED for x86-64 |

Commit Message

Li, Xin3 April 4, 2023, 10:27 a.m. UTC
  From: "H. Peter Anvin (Intel)" <hpa@zytor.com>

Let ret_from_fork() jmp to fred_exit_user when FRED is enabled,
otherwise the existing IDT code is chosen.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Tested-by: Shan Kang <shan.kang@intel.com>
Signed-off-by: Xin Li <xin3.li@intel.com>
---
 arch/x86/entry/entry_64.S | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

Dave Hansen April 10, 2023, 6:16 p.m. UTC | #1
On 4/4/23 03:27, Xin Li wrote:
> --- a/arch/x86/entry/entry_64.S
> +++ b/arch/x86/entry/entry_64.S
> @@ -299,7 +299,12 @@ SYM_CODE_START_NOALIGN(ret_from_fork)
>  	UNWIND_HINT_REGS
>  	movq	%rsp, %rdi
>  	call	syscall_exit_to_user_mode	/* returns with IRQs disabled */
> +#ifdef CONFIG_X86_FRED
> +	ALTERNATIVE "jmp swapgs_restore_regs_and_return_to_usermode", \
> +		    "jmp fred_exit_user", X86_FEATURE_FRED
> +#else
>  	jmp	swapgs_restore_regs_and_return_to_usermode
> +#endif

Does the #ifdef really buy us anything here?

I guess it might save a *TINY* amount of time at alternative processing
time.  But that doesn't really seem worth it.
  
Li, Xin3 April 10, 2023, 6:31 p.m. UTC | #2
> On 4/4/23 03:27, Xin Li wrote:
> > --- a/arch/x86/entry/entry_64.S
> > +++ b/arch/x86/entry/entry_64.S
> > @@ -299,7 +299,12 @@ SYM_CODE_START_NOALIGN(ret_from_fork)
> >  	UNWIND_HINT_REGS
> >  	movq	%rsp, %rdi
> >  	call	syscall_exit_to_user_mode	/* returns with IRQs disabled */
> > +#ifdef CONFIG_X86_FRED
> > +	ALTERNATIVE "jmp swapgs_restore_regs_and_return_to_usermode", \
> > +		    "jmp fred_exit_user", X86_FEATURE_FRED #else
> >  	jmp	swapgs_restore_regs_and_return_to_usermode
> > +#endif
> 
> Does the #ifdef really buy us anything here?
> 
> I guess it might save a *TINY* amount of time at alternative processing time.  But
> that doesn't really seem worth it.

You have kept saying not to use #ifdef if possible, and I tried to get if of them.

Somehow I ended up with overlooking this _unnecessary_ change, will remove.

Thanks!
  Xin
  
Li, Xin3 April 10, 2023, 7:25 p.m. UTC | #3
> -----Original Message-----
> From: Li, Xin3 <xin3.li@intel.com>
> Sent: Monday, April 10, 2023 11:32 AM
> To: Hansen, Dave <dave.hansen@intel.com>; linux-kernel@vger.kernel.org;
> x86@kernel.org; kvm@vger.kernel.org
> Cc: tglx@linutronix.de; mingo@redhat.com; bp@alien8.de;
> dave.hansen@linux.intel.com; hpa@zytor.com; peterz@infradead.org;
> andrew.cooper3@citrix.com; Christopherson,, Sean <seanjc@google.com>;
> pbonzini@redhat.com; Shankar, Ravi V <ravi.v.shankar@intel.com>;
> jiangshanlai@gmail.com; Kang, Shan <shan.kang@intel.com>
> Subject: RE: [PATCH v7 23/33] x86/fred: let ret_from_fork() jmp to fred_exit_user
> when FRED is enabled
> 
> > On 4/4/23 03:27, Xin Li wrote:
> > > --- a/arch/x86/entry/entry_64.S
> > > +++ b/arch/x86/entry/entry_64.S
> > > @@ -299,7 +299,12 @@ SYM_CODE_START_NOALIGN(ret_from_fork)
> > >  	UNWIND_HINT_REGS
> > >  	movq	%rsp, %rdi
> > >  	call	syscall_exit_to_user_mode	/* returns with IRQs disabled */
> > > +#ifdef CONFIG_X86_FRED
> > > +	ALTERNATIVE "jmp swapgs_restore_regs_and_return_to_usermode", \
> > > +		    "jmp fred_exit_user", X86_FEATURE_FRED #else
> > >  	jmp	swapgs_restore_regs_and_return_to_usermode
> > > +#endif
> >
> > Does the #ifdef really buy us anything here?
> >
> > I guess it might save a *TINY* amount of time at alternative
> > processing time.  But that doesn't really seem worth it.
> 
> You have kept saying not to use #ifdef if possible, and I tried to get if of them.
> 
> Somehow I ended up with overlooking this _unnecessary_ change, will remove.

Actually I didn't overlook it, the reason I keep the #ifdef is the symbol
"fred_exit_user" is missing otherwise, which is defined only if we have
CONFIG_X86_FRED.

Thanks!
  Xin
  

Patch

diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index eccc3431e515..5b595a9b2ffb 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -299,7 +299,12 @@  SYM_CODE_START_NOALIGN(ret_from_fork)
 	UNWIND_HINT_REGS
 	movq	%rsp, %rdi
 	call	syscall_exit_to_user_mode	/* returns with IRQs disabled */
+#ifdef CONFIG_X86_FRED
+	ALTERNATIVE "jmp swapgs_restore_regs_and_return_to_usermode", \
+		    "jmp fred_exit_user", X86_FEATURE_FRED
+#else
 	jmp	swapgs_restore_regs_and_return_to_usermode
+#endif
 
 1:
 	/* kernel thread */