Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 79977
b: refs/heads/master
c: 881c297
h: refs/heads/master
i:
  79975: 88699d7
v: v3
  • Loading branch information
Glauber de Oliveira Costa authored and Ingo Molnar committed Jan 30, 2008
1 parent 64d415e commit 9551f65
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 107 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 59fbed775aa5a6f352bfbde6b40508b541086b7e
refs/heads/master: 881c2975d02b6575c417a6eee40868d60a9ecba9
65 changes: 64 additions & 1 deletion trunk/include/asm-x86/desc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef __ASSEMBLY__
#include <asm/desc_defs.h>
#include <asm/ldt.h>
#include <asm/mmu.h>

static inline void fill_ldt(struct desc_struct *desc, struct user_desc *info)
{
Expand All @@ -23,12 +24,74 @@ static inline void fill_ldt(struct desc_struct *desc, struct user_desc *info)
desc->base2 = (info->base_addr & 0xff000000) >> 24;
}

#endif
extern struct desc_ptr idt_descr;
extern gate_desc idt_table[];

#ifdef CONFIG_X86_32
# include "desc_32.h"
#else
# include "desc_64.h"
#endif

#define _LDT_empty(info) (\
(info)->base_addr == 0 && \
(info)->limit == 0 && \
(info)->contents == 0 && \
(info)->read_exec_only == 1 && \
(info)->seg_32bit == 0 && \
(info)->limit_in_pages == 0 && \
(info)->seg_not_present == 1 && \
(info)->useable == 0)

#ifdef CONFIG_X86_64
#define LDT_empty(info) (_LDT_empty(info) && ((info)->lm == 0))
#else
#define LDT_empty(info) (_LDT_empty(info))
#endif

static inline void clear_LDT(void)
{
set_ldt(NULL, 0);
}

/*
* load one particular LDT into the current CPU
*/
static inline void load_LDT_nolock(mm_context_t *pc)
{
set_ldt(pc->ldt, pc->size);
}

static inline void load_LDT(mm_context_t *pc)
{
preempt_disable();
load_LDT_nolock(pc);
preempt_enable();
}

#else
/*
* GET_DESC_BASE reads the descriptor base of the specified segment.
*
* Args:
* idx - descriptor index
* gdt - GDT pointer
* base - 32bit register to which the base will be written
* lo_w - lo word of the "base" register
* lo_b - lo byte of the "base" register
* hi_b - hi byte of the low word of the "base" register
*
* Example:
* GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah)
* Will read the base address of GDT_ENTRY_ESPFIX_SS and put it into %eax.
*/
#define GET_DESC_BASE(idx, gdt, base, lo_w, lo_b, hi_b) \
movb idx*8+4(gdt), lo_b; \
movb idx*8+7(gdt), hi_b; \
shll $16, base; \
movw idx*8+2(gdt), lo_w;


#endif /* __ASSEMBLY__ */

#endif
58 changes: 0 additions & 58 deletions trunk/include/asm-x86/desc_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <linux/smp.h>
#include <linux/percpu.h>

#include <asm/mmu.h>

struct gdt_page
{
struct desc_struct gdt[GDT_ENTRIES];
Expand All @@ -24,8 +22,6 @@ static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
return per_cpu(gdt_page, cpu).gdt;
}

extern struct desc_ptr idt_descr;
extern gate_desc idt_table[];
extern void set_intr_gate(unsigned int irq, void * addr);

static inline void pack_descriptor(struct desc_struct *desc,
Expand Down Expand Up @@ -172,36 +168,6 @@ static inline void __set_tss_desc(unsigned int cpu, unsigned int entry, const vo

#define set_tss_desc(cpu,addr) __set_tss_desc(cpu, GDT_ENTRY_TSS, addr)

#define LDT_empty(info) (\
(info)->base_addr == 0 && \
(info)->limit == 0 && \
(info)->contents == 0 && \
(info)->read_exec_only == 1 && \
(info)->seg_32bit == 0 && \
(info)->limit_in_pages == 0 && \
(info)->seg_not_present == 1 && \
(info)->useable == 0 )

static inline void clear_LDT(void)
{
set_ldt(NULL, 0);
}

/*
* load one particular LDT into the current CPU
*/
static inline void load_LDT_nolock(mm_context_t *pc)
{
set_ldt(pc->ldt, pc->size);
}

static inline void load_LDT(mm_context_t *pc)
{
preempt_disable();
load_LDT_nolock(pc);
preempt_enable();
}

static inline unsigned long get_desc_base(unsigned long *desc)
{
unsigned long base;
Expand All @@ -210,30 +176,6 @@ static inline unsigned long get_desc_base(unsigned long *desc)
(desc[1] & 0xff000000);
return base;
}

#else /* __ASSEMBLY__ */

/*
* GET_DESC_BASE reads the descriptor base of the specified segment.
*
* Args:
* idx - descriptor index
* gdt - GDT pointer
* base - 32bit register to which the base will be written
* lo_w - lo word of the "base" register
* lo_b - lo byte of the "base" register
* hi_b - hi byte of the low word of the "base" register
*
* Example:
* GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah)
* Will read the base address of GDT_ENTRY_ESPFIX_SS and put it into %eax.
*/
#define GET_DESC_BASE(idx, gdt, base, lo_w, lo_b, hi_b) \
movb idx*8+4(gdt), lo_b; \
movb idx*8+7(gdt), hi_b; \
shll $16, base; \
movw idx*8+2(gdt), lo_w;

#endif /* !__ASSEMBLY__ */

#endif
55 changes: 10 additions & 45 deletions trunk/include/asm-x86/desc_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@

#include <linux/string.h>
#include <linux/smp.h>
#include <asm/desc_defs.h>

#include <asm/segment.h>
#include <asm/mmu.h>

extern struct desc_struct cpu_gdt_table[GDT_ENTRIES];

#define load_TR_desc() asm volatile("ltr %w0"::"r" (GDT_ENTRY_TSS*8))
#define load_LDT_desc() asm volatile("lldt %w0"::"r" (GDT_ENTRY_LDT*8))
#define clear_LDT() asm volatile("lldt %w0"::"r" (0))

static inline unsigned long __store_tr(void)
{
Expand All @@ -30,7 +27,6 @@ static inline unsigned long __store_tr(void)

#define store_tr(tr) (tr) = __store_tr()

extern gate_desc idt_table[];
extern struct desc_ptr cpu_gdt_descr[];

static inline void write_ldt_entry(struct desc_struct *ldt,
Expand Down Expand Up @@ -138,22 +134,18 @@ static inline void set_tss_desc(unsigned cpu, void *addr)
IO_BITMAP_OFFSET + IO_BITMAP_BYTES + sizeof(unsigned long) - 1);
}

static inline void set_ldt_desc(unsigned cpu, void *addr, int size)
static inline void set_ldt(void *addr, int entries)
{
set_tssldt_descriptor(&get_cpu_gdt_table(cpu)[GDT_ENTRY_LDT],
(unsigned long)addr, DESC_LDT, size * 8 - 1);
}
if (likely(entries == 0))
__asm__ __volatile__("lldt %w0"::"q" (0));
else {
unsigned cpu = smp_processor_id();

#define LDT_empty(info) (\
(info)->base_addr == 0 && \
(info)->limit == 0 && \
(info)->contents == 0 && \
(info)->read_exec_only == 1 && \
(info)->seg_32bit == 0 && \
(info)->limit_in_pages == 0 && \
(info)->seg_not_present == 1 && \
(info)->useable == 0 && \
(info)->lm == 0)
set_tssldt_descriptor(&get_cpu_gdt_table(cpu)[GDT_ENTRY_LDT],
(unsigned long)addr, DESC_LDT, entries * 8 - 1);
__asm__ __volatile__("lldt %w0"::"q" (GDT_ENTRY_LDT*8));
}
}

static inline void load_TLS(struct thread_struct *t, unsigned int cpu)
{
Expand All @@ -164,32 +156,6 @@ static inline void load_TLS(struct thread_struct *t, unsigned int cpu)
gdt[i] = t->tls_array[i];
}

/*
* load one particular LDT into the current CPU
*/
static inline void load_LDT_nolock(mm_context_t *pc, int cpu)
{
int count = pc->size;

if (likely(!count)) {
clear_LDT();
return;
}

set_ldt_desc(cpu, pc->ldt, count);
load_LDT_desc();
}

static inline void load_LDT(mm_context_t *pc)
{
int cpu = get_cpu();

load_LDT_nolock(pc, cpu);
put_cpu();
}

extern struct desc_ptr idt_descr;

static inline unsigned long get_desc_base(const void *ptr)
{
const u32 *desc = ptr;
Expand All @@ -199,7 +165,6 @@ static inline unsigned long get_desc_base(const void *ptr)
(desc[1] & 0xff000000);
return base;
}

#endif /* !__ASSEMBLY__ */

#endif
4 changes: 2 additions & 2 deletions trunk/include/asm-x86/mmu_context_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
load_cr3(next->pgd);

if (unlikely(next->context.ldt != prev->context.ldt))
load_LDT_nolock(&next->context, cpu);
load_LDT_nolock(&next->context);
}
#ifdef CONFIG_SMP
else {
Expand All @@ -56,7 +56,7 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
* to make sure to use no freed page tables.
*/
load_cr3(next->pgd);
load_LDT_nolock(&next->context, cpu);
load_LDT_nolock(&next->context);
}
}
#endif
Expand Down

0 comments on commit 9551f65

Please sign in to comment.