From: "H. Peter Anvin (Intel)" <hpa@zytor.com>
<asm/cpufeature.h> depends on <asm/special_insns.h>, so in order to be
able to use alternatives in native_load_gs_index(), factor it out into
a separate header file.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Signed-off-by: Xin Li <xin3.li@intel.com>
---
arch/x86/ia32/ia32_signal.c | 1 +
arch/x86/include/asm/gsseg.h | 32 ++++++++++++++++++++++++++++
arch/x86/include/asm/mmu_context.h | 1 +
arch/x86/include/asm/special_insns.h | 17 ---------------
arch/x86/kernel/paravirt.c | 1 +
arch/x86/kernel/tls.c | 1 +
6 files changed, 36 insertions(+), 17 deletions(-)
create mode 100644 arch/x86/include/asm/gsseg.h
diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
index c9c3859322fa..14c739303099 100644
--- a/arch/x86/ia32/ia32_signal.c
+++ b/arch/x86/ia32/ia32_signal.c
@@ -34,6 +34,7 @@
#include <asm/sigframe.h>
#include <asm/sighandling.h>
#include <asm/smap.h>
+#include <asm/gsseg.h>
static inline void reload_segments(struct sigcontext_32 *sc)
{
diff --git a/arch/x86/include/asm/gsseg.h b/arch/x86/include/asm/gsseg.h
new file mode 100644
index 000000000000..5e3b56a17098
--- /dev/null
+++ b/arch/x86/include/asm/gsseg.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _ASM_X86_GSSEG_H
+#define _ASM_X86_GSSEG_H
+
+#include <linux/types.h>
+#include <asm/processor.h>
+
+#ifdef CONFIG_X86_64
+
+extern asmlinkage void asm_load_gs_index(u16 selector);
+
+static inline void native_load_gs_index(unsigned int selector)
+{
+ asm_load_gs_index(selector);
+}
+
+#endif /* CONFIG_X86_64 */
+
+#ifndef CONFIG_PARAVIRT_XXL
+
+static inline void load_gs_index(unsigned int selector)
+{
+#ifdef CONFIG_X86_64
+ native_load_gs_index(selector);
+#else
+ loadsegment(gs, selector);
+#endif
+}
+
+#endif /* CONFIG_PARAVIRT_XXL */
+
+#endif /* _ASM_X86_GSSEG_H */
diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
index b8d40ddeab00..e01aa74a6de7 100644
--- a/arch/x86/include/asm/mmu_context.h
+++ b/arch/x86/include/asm/mmu_context.h
@@ -12,6 +12,7 @@
#include <asm/tlbflush.h>
#include <asm/paravirt.h>
#include <asm/debugreg.h>
+#include <asm/gsseg.h>
extern atomic64_t last_mm_ctx_id;
diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h
index 6de00dec6564..cfd9499b617c 100644
--- a/arch/x86/include/asm/special_insns.h
+++ b/arch/x86/include/asm/special_insns.h
@@ -120,13 +120,6 @@ static inline void native_wbinvd(void)
asm volatile("wbinvd": : :"memory");
}
-extern asmlinkage void asm_load_gs_index(u16 selector);
-
-static inline void native_load_gs_index(unsigned int selector)
-{
- asm_load_gs_index(selector);
-}
-
static inline unsigned long __read_cr4(void)
{
return native_read_cr4();
@@ -180,16 +173,6 @@ static inline void wbinvd(void)
native_wbinvd();
}
-
-static inline void load_gs_index(unsigned int selector)
-{
-#ifdef CONFIG_X86_64
- native_load_gs_index(selector);
-#else
- loadsegment(gs, selector);
-#endif
-}
-
#endif /* CONFIG_PARAVIRT_XXL */
static inline void clflush(volatile void *__p)
diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
index 7ca2d46c08cc..00f6a92551d2 100644
--- a/arch/x86/kernel/paravirt.c
+++ b/arch/x86/kernel/paravirt.c
@@ -32,6 +32,7 @@
#include <asm/special_insns.h>
#include <asm/tlb.h>
#include <asm/io_bitmap.h>
+#include <asm/gsseg.h>
/*
* nop stub, which must not clobber anything *including the stack* to
diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
index 3c883e064242..3ffbab0081f4 100644
--- a/arch/x86/kernel/tls.c
+++ b/arch/x86/kernel/tls.c
@@ -12,6 +12,7 @@
#include <asm/ldt.h>
#include <asm/processor.h>
#include <asm/proto.h>
+#include <asm/gsseg.h>
#include "tls.h"
--
2.34.1
On Thu, Oct 6, 2022 at 12:13 PM Xin Li <xin3.li@intel.com> wrote: > > From: "H. Peter Anvin (Intel)" <hpa@zytor.com> > > <asm/cpufeature.h> depends on <asm/special_insns.h>, so in order to be > able to use alternatives in native_load_gs_index(), factor it out into > a separate header file. > > Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> > Signed-off-by: Xin Li <xin3.li@intel.com> This could be moved into <asm/segment.h> instead of creating a new header file. -- Brian Gerst
On October 7, 2022 8:40:41 AM PDT, Brian Gerst <brgerst@gmail.com> wrote: >On Thu, Oct 6, 2022 at 12:13 PM Xin Li <xin3.li@intel.com> wrote: >> >> From: "H. Peter Anvin (Intel)" <hpa@zytor.com> >> >> <asm/cpufeature.h> depends on <asm/special_insns.h>, so in order to be >> able to use alternatives in native_load_gs_index(), factor it out into >> a separate header file. >> >> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> >> Signed-off-by: Xin Li <xin3.li@intel.com> > >This could be moved into <asm/segment.h> instead of creating a new header file. > >-- >Brian Gerst At least at the time I wrote the code, it could not, without creating yet another circular header file dependency.
> On October 7, 2022 8:40:41 AM PDT, Brian Gerst <brgerst@gmail.com> wrote: > >On Thu, Oct 6, 2022 at 12:13 PM Xin Li <xin3.li@intel.com> wrote: > >> > >> From: "H. Peter Anvin (Intel)" <hpa@zytor.com> > >> > >> <asm/cpufeature.h> depends on <asm/special_insns.h>, so in order to > >> be able to use alternatives in native_load_gs_index(), factor it out > >> into a separate header file. > >> > >> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> > >> Signed-off-by: Xin Li <xin3.li@intel.com> > > > >This could be moved into <asm/segment.h> instead of creating a new header > file. Good suggestion. However I still prefer to keep GS segment in its own header file, 1) it's a special segment for x86_64 kernel, and it's more readable to keep it separated. 2) segment.h is included in too many files, but gsseg.h only 4 files. We avoid header pollution. Maybe we should even factor GS segment out of segment.h for x86_64. Xin > > > >-- > >Brian Gerst > > At least at the time I wrote the code, it could not, without creating yet another > circular header file dependency.
© 2016 - 2025 Red Hat, Inc.