This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / arch / i386 / kernel / sysenter.c
1 /*
2  * linux/arch/i386/kernel/sysenter.c
3  *
4  * (C) Copyright 2002 Linus Torvalds
5  *
6  * This file contains the needed initializations to support sysenter.
7  */
8
9 #include <linux/init.h>
10 #include <linux/smp.h>
11 #include <linux/thread_info.h>
12 #include <linux/sched.h>
13 #include <linux/gfp.h>
14 #include <linux/string.h>
15 #include <linux/elf.h>
16 #include <linux/mman.h>
17
18 #include <asm/cpufeature.h>
19 #include <asm/msr.h>
20 #include <asm/pgtable.h>
21 #include <asm/unistd.h>
22 #include <linux/highmem.h>
23
24 extern asmlinkage void sysenter_entry(void);
25
26 void enable_sep_cpu(void *info)
27 {
28         int cpu = get_cpu();
29 #ifdef CONFIG_X86_HIGH_ENTRY
30         struct tss_struct *tss = (struct tss_struct *) __fix_to_virt(FIX_TSS_0) + cpu;
31 #else
32         struct tss_struct *tss = init_tss + cpu;
33 #endif
34
35         tss->ss1 = __KERNEL_CS;
36         tss->esp1 = sizeof(struct tss_struct) + (unsigned long) tss;
37         wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0);
38         wrmsr(MSR_IA32_SYSENTER_ESP, tss->esp1, 0);
39         wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long) sysenter_entry, 0);
40         put_cpu();      
41 }
42
43 /*
44  * These symbols are defined by vsyscall.o to mark the bounds
45  * of the ELF DSO images included therein.
46  */
47 extern const char vsyscall_int80_start, vsyscall_int80_end;
48 extern const char vsyscall_sysenter_start, vsyscall_sysenter_end;
49
50 struct page *sysenter_page;
51
52 static int __init sysenter_setup(void)
53 {
54         unsigned long page = get_zeroed_page(GFP_ATOMIC);
55
56         __set_fixmap(FIX_VSYSCALL, __pa(page), PAGE_KERNEL_RO);
57         sysenter_page = virt_to_page(page);
58
59         if (!boot_cpu_has(X86_FEATURE_SEP)) {
60                 memcpy((void *) page,
61                        &vsyscall_int80_start,
62                        &vsyscall_int80_end - &vsyscall_int80_start);
63                 return 0;
64         }
65
66         memcpy((void *) page,
67                &vsyscall_sysenter_start,
68                &vsyscall_sysenter_end - &vsyscall_sysenter_start);
69
70         on_each_cpu(enable_sep_cpu, NULL, 1, 1);
71
72         return 0;
73 }
74
75 __initcall(sysenter_setup);
76
77 extern void SYSENTER_RETURN_OFFSET;
78
79 unsigned int vdso_enabled = 1;
80
81 void map_vsyscall(void)
82 {
83         struct thread_info *ti = current_thread_info();
84         struct vm_area_struct *vma;
85         unsigned long addr;
86
87         if (unlikely(!vdso_enabled)) {
88                 current->mm->context.vdso = NULL;
89                 return;
90         }
91
92         /*
93          * Map the vDSO (it will be randomized):
94          */
95         down_write(&current->mm->mmap_sem);
96         addr = do_mmap(NULL, 0, 4096, PROT_READ | PROT_EXEC, MAP_PRIVATE, 0);
97         current->mm->context.vdso = (void *)addr;
98         ti->sysenter_return = (void *)addr + (long)&SYSENTER_RETURN_OFFSET;
99         if (addr != -1) {
100                 vma = find_vma(current->mm, addr);
101                 if (vma) {
102                         pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
103                         get_page(sysenter_page);
104                         install_page(current->mm, vma, addr,
105                                         sysenter_page, vma->vm_page_prot);
106                         
107                 }
108         }
109         up_write(&current->mm->mmap_sem);
110 }
111
112 static int __init vdso_setup(char *str)
113 {
114         vdso_enabled = simple_strtoul(str, NULL, 0);
115         return 1;
116 }
117 __setup("vdso=", vdso_setup);
118