diff mbox series

[v11,35/37] x86/syscall: Split IDT syscall setup code into idt_syscall_init()

Message ID 20230923094212.26520-36-xin3.li@intel.com (mailing list archive)
State Superseded
Headers show
Series x86: enable FRED for x86-64 | expand

Commit Message

Li, Xin3 Sept. 23, 2023, 9:42 a.m. UTC
Because FRED uses the ring 3 FRED entrypoint for SYSCALL and SYSENTER and
ERETU is the only legit instruction to return to ring 3, there is NO need
to setup SYSCALL and SYSENTER MSRs for FRED, except the IA32_STAR MSR.

Split IDT syscall setup code into idt_syscall_init() to make it easy to
skip syscall setup code when FRED is enabled.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Shan Kang <shan.kang@intel.com>
Signed-off-by: Xin Li <xin3.li@intel.com>
---
 arch/x86/kernel/cpu/common.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Comments

H. Peter Anvin Sept. 25, 2023, 4:07 p.m. UTC | #1
On September 23, 2023 2:42:10 AM PDT, Xin Li <xin3.li@intel.com> wrote:
>Because FRED uses the ring 3 FRED entrypoint for SYSCALL and SYSENTER and
>ERETU is the only legit instruction to return to ring 3, there is NO need
>to setup SYSCALL and SYSENTER MSRs for FRED, except the IA32_STAR MSR.
>
>Split IDT syscall setup code into idt_syscall_init() to make it easy to
>skip syscall setup code when FRED is enabled.
>
>Suggested-by: Thomas Gleixner <tglx@linutronix.de>
>Tested-by: Shan Kang <shan.kang@intel.com>
>Signed-off-by: Xin Li <xin3.li@intel.com>
>---
> arch/x86/kernel/cpu/common.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
>diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
>index 20bbedbf6dcb..2ee4e7b597a3 100644
>--- a/arch/x86/kernel/cpu/common.c
>+++ b/arch/x86/kernel/cpu/common.c
>@@ -2071,10 +2071,8 @@ static void wrmsrl_cstar(unsigned long val)
> 		wrmsrl(MSR_CSTAR, val);
> }
> 
>-/* May not be marked __init: used by software suspend */
>-void syscall_init(void)
>+static inline void idt_syscall_init(void)
> {
>-	wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS);
> 	wrmsrl(MSR_LSTAR, (unsigned long)entry_SYSCALL_64);
> 
> 	if (ia32_enabled()) {
>@@ -2108,6 +2106,15 @@ void syscall_init(void)
> 	       X86_EFLAGS_AC|X86_EFLAGS_ID);
> }
> 
>+/* May not be marked __init: used by software suspend */
>+void syscall_init(void)
>+{
>+	/* The default user and kernel segments */
>+	wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS);
>+
>+	idt_syscall_init();
>+}
>+
> #else	/* CONFIG_X86_64 */
> 
> #ifdef CONFIG_STACKPROTECTOR

Am I missing something, or is this patch a noop?
Li, Xin3 Sept. 25, 2023, 5:56 p.m. UTC | #2
> >diff --git a/arch/x86/kernel/cpu/common.c
> >b/arch/x86/kernel/cpu/common.c index 20bbedbf6dcb..2ee4e7b597a3 100644
> >--- a/arch/x86/kernel/cpu/common.c
> >+++ b/arch/x86/kernel/cpu/common.c
> >@@ -2071,10 +2071,8 @@ static void wrmsrl_cstar(unsigned long val)
> > 		wrmsrl(MSR_CSTAR, val);
> > }
> >
> >-/* May not be marked __init: used by software suspend */ -void
> >syscall_init(void)
> >+static inline void idt_syscall_init(void)
> > {
> >-	wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS);
> > 	wrmsrl(MSR_LSTAR, (unsigned long)entry_SYSCALL_64);
> >
> > 	if (ia32_enabled()) {
> >@@ -2108,6 +2106,15 @@ void syscall_init(void)
> > 	       X86_EFLAGS_AC|X86_EFLAGS_ID);
> > }
> >
> >+/* May not be marked __init: used by software suspend */ void
> >+syscall_init(void) {
> >+	/* The default user and kernel segments */
> >+	wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS);
> >+
> >+	idt_syscall_init();
> >+}
> >+
> > #else	/* CONFIG_X86_64 */
> >
> > #ifdef CONFIG_STACKPROTECTOR
> 
> Am I missing something, or is this patch a noop?

Yes, this is a noop, just a cleanup patch w/o functionality change.
H. Peter Anvin Sept. 25, 2023, 6:55 p.m. UTC | #3
On September 25, 2023 10:56:44 AM PDT, "Li, Xin3" <xin3.li@intel.com> wrote:
>> >diff --git a/arch/x86/kernel/cpu/common.c
>> >b/arch/x86/kernel/cpu/common.c index 20bbedbf6dcb..2ee4e7b597a3 100644
>> >--- a/arch/x86/kernel/cpu/common.c
>> >+++ b/arch/x86/kernel/cpu/common.c
>> >@@ -2071,10 +2071,8 @@ static void wrmsrl_cstar(unsigned long val)
>> > 		wrmsrl(MSR_CSTAR, val);
>> > }
>> >
>> >-/* May not be marked __init: used by software suspend */ -void
>> >syscall_init(void)
>> >+static inline void idt_syscall_init(void)
>> > {
>> >-	wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS);
>> > 	wrmsrl(MSR_LSTAR, (unsigned long)entry_SYSCALL_64);
>> >
>> > 	if (ia32_enabled()) {
>> >@@ -2108,6 +2106,15 @@ void syscall_init(void)
>> > 	       X86_EFLAGS_AC|X86_EFLAGS_ID);
>> > }
>> >
>> >+/* May not be marked __init: used by software suspend */ void
>> >+syscall_init(void) {
>> >+	/* The default user and kernel segments */
>> >+	wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS);
>> >+
>> >+	idt_syscall_init();
>> >+}
>> >+
>> > #else	/* CONFIG_X86_64 */
>> >
>> > #ifdef CONFIG_STACKPROTECTOR
>> 
>> Am I missing something, or is this patch a noop?
>
>Yes, this is a noop, just a cleanup patch w/o functionality change.
>
>

It just seems to be completely redundant. We can just drop it, no? If we aren't going to explicitly clobber the registers there is no harm in setting them up for IDT unconditionally.
Li, Xin3 Sept. 26, 2023, 6:58 a.m. UTC | #4
> >Yes, this is a noop, just a cleanup patch w/o functionality change.
> >
> It just seems to be completely redundant. We can just drop it, no? If we aren't going
> to explicitly clobber the registers there is no harm in setting them up for IDT
> unconditionally.

If no objection, I can make the change, i.e., unconditionally set these
MSRs up for IDT.
Thomas Gleixner Sept. 28, 2023, 6:01 p.m. UTC | #5
On Mon, Sep 25 2023 at 09:07, H. Peter Anvin wrote:
> On September 23, 2023 2:42:10 AM PDT, Xin Li <xin3.li@intel.com> wrote:
>>+/* May not be marked __init: used by software suspend */
>>+void syscall_init(void)
>>+{
>>+	/* The default user and kernel segments */
>>+	wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS);
>>+
>>+	idt_syscall_init();
>>+}
>>+
>> #else	/* CONFIG_X86_64 */
>> 
>> #ifdef CONFIG_STACKPROTECTOR
>
> Am I missing something, or is this patch a noop?

Yes. It's a noop at this point. Later on it gains a

     if (!fred)
        idt_syscall_init();

Sure we could do

     if (!fred) {
     	write_msr(foo...);
        ...
     }

too, but I prefer the separation. No strong opinion though.

Thanks,

        tglx
diff mbox series

Patch

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 20bbedbf6dcb..2ee4e7b597a3 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -2071,10 +2071,8 @@  static void wrmsrl_cstar(unsigned long val)
 		wrmsrl(MSR_CSTAR, val);
 }
 
-/* May not be marked __init: used by software suspend */
-void syscall_init(void)
+static inline void idt_syscall_init(void)
 {
-	wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS);
 	wrmsrl(MSR_LSTAR, (unsigned long)entry_SYSCALL_64);
 
 	if (ia32_enabled()) {
@@ -2108,6 +2106,15 @@  void syscall_init(void)
 	       X86_EFLAGS_AC|X86_EFLAGS_ID);
 }
 
+/* May not be marked __init: used by software suspend */
+void syscall_init(void)
+{
+	/* The default user and kernel segments */
+	wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS);
+
+	idt_syscall_init();
+}
+
 #else	/* CONFIG_X86_64 */
 
 #ifdef CONFIG_STACKPROTECTOR