Skip to content

Commit ca241c7

Browse files
Glauber de Oliveira CostaIngo Molnar
authored andcommitted
x86: unify tss_struct
Although slighly different, the tss_struct is very similar in x86_64 and i386. The really different part, which matchs the hardware vision of it, is now called x86_hw_tss, and each of the architectures provides yours. It's then used as a field in the outter tss_struct. Signed-off-by: Glauber de Oliveira Costa <gcosta@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 0ccb8ac commit ca241c7

File tree

9 files changed

+85
-103
lines changed

9 files changed

+85
-103
lines changed

arch/x86/kernel/asm-offsets_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int main(void)
110110
ENTRY(cr8);
111111
BLANK();
112112
#undef ENTRY
113-
DEFINE(TSS_ist, offsetof(struct tss_struct, ist));
113+
DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist));
114114
BLANK();
115115
DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
116116
BLANK();

arch/x86/kernel/doublefault_32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void doublefault_fn(void)
3333
printk(KERN_EMERG "double fault, tss at %08lx\n", tss);
3434

3535
if (ptr_ok(tss)) {
36-
struct i386_hw_tss *t = (struct i386_hw_tss *)tss;
36+
struct x86_hw_tss *t = (struct x86_hw_tss *)tss;
3737

3838
printk(KERN_EMERG "eip = %08lx, esp = %08lx\n",
3939
t->ip, t->sp);

arch/x86/kernel/process_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
639639
/*
640640
* Reload esp0, LDT and the page table pointer:
641641
*/
642-
tss->sp0 = next->sp0;
642+
tss->x86_tss.sp0 = next->sp0;
643643

644644
/*
645645
* Switch DS and ES.

arch/x86/kernel/setup64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ void __cpuinit cpu_init (void)
258258
v, cpu);
259259
}
260260
estacks += PAGE_SIZE << order[v];
261-
orig_ist->ist[v] = t->ist[v] = (unsigned long)estacks;
261+
orig_ist->ist[v] = t->x86_tss.ist[v] = (unsigned long)estacks;
262262
}
263263

264-
t->io_bitmap_base = offsetof(struct tss_struct, io_bitmap);
264+
t->x86_tss.io_bitmap_base = offsetof(struct tss_struct, io_bitmap);
265265
/*
266266
* <= is required because the CPU will access up to
267267
* 8 bits beyond the end of the IO permission bitmap.

arch/x86/kernel/smpboot_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ static int __cpuinit do_boot_cpu(int cpu, int apicid)
614614
start_rip = setup_trampoline();
615615

616616
init_rsp = c_idle.idle->thread.sp;
617-
per_cpu(init_tss,cpu).sp0 = init_rsp;
617+
per_cpu(init_tss, cpu).x86_tss.sp0 = init_rsp;
618618
initial_code = start_secondary;
619619
clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
620620

include/asm-x86/lguest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct lguest_ro_state
5151
/* Fields which are used when guest is running. */
5252
struct desc_ptr guest_idt_desc;
5353
struct desc_ptr guest_gdt_desc;
54-
struct i386_hw_tss guest_tss;
54+
struct x86_hw_tss guest_tss;
5555
struct desc_struct guest_idt[IDT_ENTRIES];
5656
struct desc_struct guest_gdt[GDT_ENTRIES];
5757
};

include/asm-x86/processor.h

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ struct task_struct;
88
struct mm_struct;
99

1010
#include <asm/page.h>
11+
#include <asm/percpu.h>
1112
#include <asm/system.h>
1213

1314
/*
@@ -38,6 +39,82 @@ static inline void load_cr3(pgd_t *pgdir)
3839
write_cr3(__pa(pgdir));
3940
}
4041

42+
#ifdef CONFIG_X86_32
43+
/* This is the TSS defined by the hardware. */
44+
struct x86_hw_tss {
45+
unsigned short back_link, __blh;
46+
unsigned long sp0;
47+
unsigned short ss0, __ss0h;
48+
unsigned long sp1;
49+
unsigned short ss1, __ss1h; /* ss1 caches MSR_IA32_SYSENTER_CS */
50+
unsigned long sp2;
51+
unsigned short ss2, __ss2h;
52+
unsigned long __cr3;
53+
unsigned long ip;
54+
unsigned long flags;
55+
unsigned long ax, cx, dx, bx;
56+
unsigned long sp, bp, si, di;
57+
unsigned short es, __esh;
58+
unsigned short cs, __csh;
59+
unsigned short ss, __ssh;
60+
unsigned short ds, __dsh;
61+
unsigned short fs, __fsh;
62+
unsigned short gs, __gsh;
63+
unsigned short ldt, __ldth;
64+
unsigned short trace, io_bitmap_base;
65+
} __attribute__((packed));
66+
#else
67+
struct x86_hw_tss {
68+
u32 reserved1;
69+
u64 sp0;
70+
u64 sp1;
71+
u64 sp2;
72+
u64 reserved2;
73+
u64 ist[7];
74+
u32 reserved3;
75+
u32 reserved4;
76+
u16 reserved5;
77+
u16 io_bitmap_base;
78+
} __attribute__((packed)) ____cacheline_aligned;
79+
#endif
80+
81+
/*
82+
* Size of io_bitmap.
83+
*/
84+
#define IO_BITMAP_BITS 65536
85+
#define IO_BITMAP_BYTES (IO_BITMAP_BITS/8)
86+
#define IO_BITMAP_LONGS (IO_BITMAP_BYTES/sizeof(long))
87+
#define IO_BITMAP_OFFSET offsetof(struct tss_struct, io_bitmap)
88+
#define INVALID_IO_BITMAP_OFFSET 0x8000
89+
#define INVALID_IO_BITMAP_OFFSET_LAZY 0x9000
90+
91+
struct tss_struct {
92+
struct x86_hw_tss x86_tss;
93+
94+
/*
95+
* The extra 1 is there because the CPU will access an
96+
* additional byte beyond the end of the IO permission
97+
* bitmap. The extra byte must be all 1 bits, and must
98+
* be within the limit.
99+
*/
100+
unsigned long io_bitmap[IO_BITMAP_LONGS + 1];
101+
/*
102+
* Cache the current maximum and the last task that used the bitmap:
103+
*/
104+
unsigned long io_bitmap_max;
105+
struct thread_struct *io_bitmap_owner;
106+
/*
107+
* pads the TSS to be cacheline-aligned (size is 0x100)
108+
*/
109+
unsigned long __cacheline_filler[35];
110+
/*
111+
* .. and then another 0x100 bytes for emergency kernel stack
112+
*/
113+
unsigned long stack[64];
114+
} __attribute__((packed));
115+
116+
DECLARE_PER_CPU(struct tss_struct, init_tss);
117+
41118
#ifdef CONFIG_X86_32
42119
# include "processor_32.h"
43120
#else

include/asm-x86/processor_32.h

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ struct cpuinfo_x86 {
8181
extern struct cpuinfo_x86 boot_cpu_data;
8282
extern struct cpuinfo_x86 new_cpu_data;
8383
extern struct tss_struct doublefault_tss;
84-
DECLARE_PER_CPU(struct tss_struct, init_tss);
8584

8685
#ifdef CONFIG_SMP
8786
DECLARE_PER_CPU(struct cpuinfo_x86, cpu_info);
@@ -123,16 +122,6 @@ extern unsigned int mca_pentium_flag;
123122
#define TASK_SIZE (PAGE_OFFSET)
124123

125124

126-
/*
127-
* Size of io_bitmap.
128-
*/
129-
#define IO_BITMAP_BITS 65536
130-
#define IO_BITMAP_BYTES (IO_BITMAP_BITS/8)
131-
#define IO_BITMAP_LONGS (IO_BITMAP_BYTES/sizeof(long))
132-
#define IO_BITMAP_OFFSET offsetof(struct tss_struct,io_bitmap)
133-
#define INVALID_IO_BITMAP_OFFSET 0x8000
134-
#define INVALID_IO_BITMAP_OFFSET_LAZY 0x9000
135-
136125
struct i387_fsave_struct {
137126
long cwd;
138127
long swd;
@@ -185,57 +174,6 @@ typedef struct {
185174
unsigned long seg;
186175
} mm_segment_t;
187176

188-
struct thread_struct;
189-
190-
/* This is the TSS defined by the hardware. */
191-
struct i386_hw_tss {
192-
unsigned short back_link,__blh;
193-
unsigned long sp0;
194-
unsigned short ss0,__ss0h;
195-
unsigned long sp1;
196-
unsigned short ss1,__ss1h; /* ss1 is used to cache MSR_IA32_SYSENTER_CS */
197-
unsigned long sp2;
198-
unsigned short ss2,__ss2h;
199-
unsigned long __cr3;
200-
unsigned long ip;
201-
unsigned long flags;
202-
unsigned long ax, cx, dx, bx;
203-
unsigned long sp, bp, si, di;
204-
unsigned short es, __esh;
205-
unsigned short cs, __csh;
206-
unsigned short ss, __ssh;
207-
unsigned short ds, __dsh;
208-
unsigned short fs, __fsh;
209-
unsigned short gs, __gsh;
210-
unsigned short ldt, __ldth;
211-
unsigned short trace, io_bitmap_base;
212-
} __attribute__((packed));
213-
214-
struct tss_struct {
215-
struct i386_hw_tss x86_tss;
216-
217-
/*
218-
* The extra 1 is there because the CPU will access an
219-
* additional byte beyond the end of the IO permission
220-
* bitmap. The extra byte must be all 1 bits, and must
221-
* be within the limit.
222-
*/
223-
unsigned long io_bitmap[IO_BITMAP_LONGS + 1];
224-
/*
225-
* Cache the current maximum and the last task that used the bitmap:
226-
*/
227-
unsigned long io_bitmap_max;
228-
struct thread_struct *io_bitmap_owner;
229-
/*
230-
* pads the TSS to be cacheline-aligned (size is 0x100)
231-
*/
232-
unsigned long __cacheline_filler[35];
233-
/*
234-
* .. and then another 0x100 bytes for emergency kernel stack
235-
*/
236-
unsigned long stack[64];
237-
} __attribute__((packed));
238-
239177
#define ARCH_MIN_TASKALIGN 16
240178

241179
struct thread_struct {

include/asm-x86/processor_64.h

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,6 @@ extern void identify_cpu(struct cpuinfo_x86 *);
9191
#define TASK_SIZE (test_thread_flag(TIF_IA32) ? IA32_PAGE_OFFSET : TASK_SIZE64)
9292
#define TASK_SIZE_OF(child) ((test_tsk_thread_flag(child, TIF_IA32)) ? IA32_PAGE_OFFSET : TASK_SIZE64)
9393

94-
/*
95-
* Size of io_bitmap.
96-
*/
97-
#define IO_BITMAP_BITS 65536
98-
#define IO_BITMAP_BYTES (IO_BITMAP_BITS/8)
99-
#define IO_BITMAP_LONGS (IO_BITMAP_BYTES/sizeof(long))
100-
#define IO_BITMAP_OFFSET offsetof(struct tss_struct,io_bitmap)
101-
#define INVALID_IO_BITMAP_OFFSET 0x8000
10294

10395
struct i387_fxsave_struct {
10496
u16 cwd;
@@ -118,32 +110,7 @@ union i387_union {
118110
struct i387_fxsave_struct fxsave;
119111
};
120112

121-
struct tss_struct {
122-
u32 reserved1;
123-
u64 sp0;
124-
u64 sp1;
125-
u64 sp2;
126-
u64 reserved2;
127-
u64 ist[7];
128-
u32 reserved3;
129-
u32 reserved4;
130-
u16 reserved5;
131-
u16 io_bitmap_base;
132-
/*
133-
* The extra 1 is there because the CPU will access an
134-
* additional byte beyond the end of the IO permission
135-
* bitmap. The extra byte must be all 1 bits, and must
136-
* be within the limit. Thus we have:
137-
*
138-
* 128 bytes, the bitmap itself, for ports 0..0x3ff
139-
* 8 bytes, for an extra "long" of ~0UL
140-
*/
141-
unsigned long io_bitmap[IO_BITMAP_LONGS + 1];
142-
} __attribute__((packed)) ____cacheline_aligned;
143-
144-
145113
extern struct cpuinfo_x86 boot_cpu_data;
146-
DECLARE_PER_CPU(struct tss_struct,init_tss);
147114
/* Save the original ist values for checking stack pointers during debugging */
148115
struct orig_ist {
149116
unsigned long ist[7];
@@ -195,7 +162,7 @@ struct thread_struct {
195162
}
196163

197164
#define INIT_TSS { \
198-
.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
165+
.x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
199166
}
200167

201168
#define INIT_MMAP \

0 commit comments

Comments
 (0)