From: Rusty Russell <rusty@rustcorp.com.au>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>, Andi Kleen <andi@firstfloor.org>,
lkml - Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH 4/4] i386 GDT cleanups: cleanup GDT Access
Date: Wed, 21 Mar 2007 17:53:36 +1100 [thread overview]
Message-ID: <1174460016.11680.156.camel@localhost.localdomain> (raw)
In-Reply-To: <1174459014.11680.153.camel@localhost.localdomain>
Now we have an explicit per-cpu GDT variable, we don't need to keep
the descriptors around to use them to find the GDT: expose cpu_gdt
directly.
We could go further and make load_gdt() pack the descriptor for us, or
even assume it means "load the current cpu's GDT" which is what it
always does.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
arch/i386/kernel/cpu/common.c | 4 +---
arch/i386/kernel/efi.c | 18 +++++++++---------
arch/i386/kernel/entry.S | 3 +--
arch/i386/kernel/smpboot.c | 12 ++++++------
arch/i386/kernel/traps.c | 4 +---
include/asm-i386/desc.h | 15 ++++++---------
6 files changed, 24 insertions(+), 32 deletions(-)
diff -r 0714eeaace72 arch/i386/kernel/cpu/common.c
--- a/arch/i386/kernel/cpu/common.c Wed Mar 21 15:55:51 2007 +1100
+++ b/arch/i386/kernel/cpu/common.c Wed Mar 21 16:02:02 2007 +1100
@@ -22,9 +22,6 @@
#include "cpu.h"
-DEFINE_PER_CPU(struct Xgt_desc_struct, cpu_gdt_descr);
-EXPORT_PER_CPU_SYMBOL(cpu_gdt_descr);
-
DEFINE_PER_CPU(struct desc_struct, cpu_gdt[GDT_ENTRIES]) = {
[GDT_ENTRY_KERNEL_CS] = { 0x0000ffff, 0x00cf9a00 },
[GDT_ENTRY_KERNEL_DS] = { 0x0000ffff, 0x00cf9200 },
@@ -52,6 +49,7 @@ DEFINE_PER_CPU(struct desc_struct, cpu_g
[GDT_ENTRY_ESPFIX_SS] = { 0x00000000, 0x00c09200 },
[GDT_ENTRY_PDA] = { 0x00000000, 0x00c09200 }, /* set in setup_pda */
};
+EXPORT_PER_CPU_SYMBOL_GPL(cpu_gdt);
DEFINE_PER_CPU(struct i386_pda, _cpu_pda);
EXPORT_PER_CPU_SYMBOL(_cpu_pda);
diff -r 0714eeaace72 arch/i386/kernel/efi.c
--- a/arch/i386/kernel/efi.c Wed Mar 21 15:55:51 2007 +1100
+++ b/arch/i386/kernel/efi.c Wed Mar 21 15:56:22 2007 +1100
@@ -69,12 +69,10 @@ static void efi_call_phys_prelog(void) _
{
unsigned long cr4;
unsigned long temp;
- struct Xgt_desc_struct *cpu_gdt_descr;
+ struct Xgt_desc_struct gdt_descr;
spin_lock(&efi_rt_lock);
local_irq_save(efi_rt_eflags);
-
- cpu_gdt_descr = &per_cpu(cpu_gdt_descr, 0);
/*
* If I don't have PSE, I should just duplicate two entries in page
@@ -105,17 +103,19 @@ static void efi_call_phys_prelog(void) _
*/
local_flush_tlb();
- cpu_gdt_descr->address = __pa(cpu_gdt_descr->address);
- load_gdt(cpu_gdt_descr);
+ gdt_descr.address = __pa(get_cpu_gdt_table(0));
+ gdt_descr.size = GDT_SIZE - 1;
+ load_gdt(&gdt_descr);
}
static void efi_call_phys_epilog(void) __releases(efi_rt_lock)
{
unsigned long cr4;
- struct Xgt_desc_struct *cpu_gdt_descr = &per_cpu(cpu_gdt_descr, 0);
-
- cpu_gdt_descr->address = (unsigned long)__va(cpu_gdt_descr->address);
- load_gdt(cpu_gdt_descr);
+ struct Xgt_desc_struct gdt_descr;
+
+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
+ gdt_descr.size = GDT_SIZE - 1;
+ load_gdt(&gdt_descr);
cr4 = read_cr4();
diff -r 0714eeaace72 arch/i386/kernel/entry.S
--- a/arch/i386/kernel/entry.S Wed Mar 21 15:55:51 2007 +1100
+++ b/arch/i386/kernel/entry.S Wed Mar 21 16:02:02 2007 +1100
@@ -558,8 +558,7 @@ END(syscall_badsys)
#define FIXUP_ESPFIX_STACK \
/* since we are on a wrong stack, we cant make it a C code :( */ \
movl %fs:PDA_cpu, %ebx; \
- PER_CPU(cpu_gdt_descr, %ebx); \
- movl GDS_address(%ebx), %ebx; \
+ PER_CPU(cpu_gdt, %ebx); \
GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
addl %esp, %eax; \
pushl $__KERNEL_DS; \
diff -r 0714eeaace72 arch/i386/kernel/smpboot.c
--- a/arch/i386/kernel/smpboot.c Wed Mar 21 15:55:51 2007 +1100
+++ b/arch/i386/kernel/smpboot.c Wed Mar 21 16:02:02 2007 +1100
@@ -786,12 +786,8 @@ static inline struct task_struct * alloc
secondary which will soon come up. */
static __cpuinit void init_gdt(int cpu, struct task_struct *idle)
{
- struct Xgt_desc_struct *cpu_gdt_descr = &per_cpu(cpu_gdt_descr, cpu);
- struct desc_struct *gdt = per_cpu(cpu_gdt, cpu);
+ struct desc_struct *gdt = get_cpu_gdt_table(cpu);
struct i386_pda *pda = &per_cpu(_cpu_pda, cpu);
-
- cpu_gdt_descr->address = (unsigned long)gdt;
- cpu_gdt_descr->size = GDT_SIZE - 1;
pack_descriptor((u32 *)&gdt[GDT_ENTRY_PDA].a,
(u32 *)&gdt[GDT_ENTRY_PDA].b,
@@ -1187,7 +1183,11 @@ void __init smp_prepare_cpus(unsigned in
* it's on the real one. */
static inline void switch_to_new_gdt(void)
{
- load_gdt(&per_cpu(cpu_gdt_descr, smp_processor_id()));
+ struct Xgt_desc_struct gdt_descr;
+
+ gdt_descr.address = (long)get_cpu_gdt_table(smp_processor_id());
+ gdt_descr.size = GDT_SIZE - 1;
+ load_gdt(&gdt_descr);
asm volatile ("mov %0, %%fs" : : "r" (__KERNEL_PDA) : "memory");
}
diff -r 0714eeaace72 arch/i386/kernel/traps.c
--- a/arch/i386/kernel/traps.c Wed Mar 21 15:55:51 2007 +1100
+++ b/arch/i386/kernel/traps.c Wed Mar 21 16:02:02 2007 +1100
@@ -1037,9 +1037,7 @@ fastcall unsigned long patch_espfix_desc
fastcall unsigned long patch_espfix_desc(unsigned long uesp,
unsigned long kesp)
{
- int cpu = smp_processor_id();
- struct Xgt_desc_struct *cpu_gdt_descr = &per_cpu(cpu_gdt_descr, cpu);
- struct desc_struct *gdt = (struct desc_struct *)cpu_gdt_descr->address;
+ struct desc_struct *gdt = __get_cpu_var(cpu_gdt);
unsigned long base = (kesp - uesp) & -THREAD_SIZE;
unsigned long new_kesp = kesp - base;
unsigned long lim_pages = (new_kesp | (THREAD_SIZE - 1)) >> PAGE_SHIFT;
diff -r 0714eeaace72 arch/i386/lguest/core.c
--- a/arch/i386/lguest/core.c Wed Mar 21 15:55:51 2007 +1100
+++ b/arch/i386/lguest/core.c Wed Mar 21 16:11:14 2007 +1100
@@ -96,7 +96,8 @@ static __init int map_hypervisor(void)
struct lguest_ro_state *state = &pages->state;
/* These fields are static: rest done in copy_in_guest_info */
- state->host_gdt_desc = per_cpu(cpu_gdt_descr, i);
+ state->host_gdt_desc.size = GDT_SIZE-1;
+ state->host_gdt_desc.address = (long)get_cpu_gdt_table(i);
store_idt(&state->host_idt_desc);
state->guest_idt_desc.size = sizeof(state->guest_idt)-1;
state->guest_idt_desc.address = (long)&state->guest_idt;
diff -r 0714eeaace72 arch/i386/lguest/lguest.c
--- a/arch/i386/lguest/lguest.c Wed Mar 21 15:55:51 2007 +1100
+++ b/arch/i386/lguest/lguest.c Wed Mar 21 16:03:12 2007 +1100
@@ -451,6 +451,7 @@ static void lguest_power_off(void)
/* From head.S */
extern void setup_pda(void);
+extern struct Xgt_desc_struct early_gdt_descr;
static __attribute_used__ __init void lguest_init(void)
{
diff -r 0714eeaace72 include/asm-i386/desc.h
--- a/include/asm-i386/desc.h Wed Mar 21 15:55:51 2007 +1100
+++ b/include/asm-i386/desc.h Wed Mar 21 16:02:02 2007 +1100
@@ -18,16 +18,13 @@ struct Xgt_desc_struct {
unsigned short pad;
} __attribute__ ((packed));
+DECLARE_PER_CPU(struct desc_struct, cpu_gdt[GDT_ENTRIES]);
+static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
+{
+ return per_cpu(cpu_gdt, cpu);
+}
+
extern struct Xgt_desc_struct idt_descr;
-DECLARE_PER_CPU(struct Xgt_desc_struct, cpu_gdt_descr);
-DECLARE_PER_CPU(struct desc_struct, cpu_gdt[GDT_ENTRIES]);
-extern struct Xgt_desc_struct early_gdt_descr;
-
-static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
-{
- return (struct desc_struct *)per_cpu(cpu_gdt_descr, cpu).address;
-}
-
extern struct desc_struct idt_table[];
extern void set_intr_gate(unsigned int irq, void * addr);
next prev parent reply other threads:[~2007-03-21 6:53 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-21 6:10 [PATCH] Allow per-cpu variables to be page-aligned Rusty Russell
2007-03-21 6:30 ` [PATCH 0/4] i386 GDT cleanups Rusty Russell
2007-03-21 6:32 ` [PATCH 1/4] i386 GDT cleanups: Use per-cpu variables for GDT, PDA Rusty Russell
2007-03-21 6:35 ` [PATCH 2/4] i386 GDT cleanups: Use per-cpu GDT immediately upon boot Rusty Russell
2007-03-21 6:36 ` [PATCH 3/4] i386 GDT cleanups: clean up cpu_init() Rusty Russell
2007-03-21 6:53 ` Rusty Russell [this message]
2007-03-21 9:31 ` [PATCH 2/4] i386 GDT cleanups: Use per-cpu GDT immediately upon boot Eric W. Biederman
2007-03-21 11:55 ` Rusty Russell
2007-03-21 16:51 ` Eric W. Biederman
2007-03-21 23:58 ` Rusty Russell
2007-03-22 8:10 ` Sébastien Dugué
2007-03-22 9:24 ` Rusty Russell
2007-03-22 15:59 ` [PATCH] i386 GDT cleanups: Rename boot_gdt_table to boot_gdt Sébastien Dugué
2007-03-23 7:19 ` Rusty Russell
2007-03-23 14:15 ` Andi Kleen
2007-03-21 9:21 ` [PATCH] Allow per-cpu variables to be page-aligned Eric W. Biederman
2007-03-21 11:44 ` Rusty Russell
2007-03-21 16:49 ` Eric W. Biederman
2007-03-22 0:09 ` Rusty Russell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1174460016.11680.156.camel@localhost.localdomain \
--to=rusty@rustcorp.com.au \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome