]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/x86_64/ia32/syscall32.c
Linux-2.6.12-rc2
[mirror_ubuntu-artful-kernel.git] / arch / x86_64 / ia32 / syscall32.c
1 /* Copyright 2002,2003 Andi Kleen, SuSE Labs */
2
3 /* vsyscall handling for 32bit processes. Map a stub page into it
4 on demand because 32bit cannot reach the kernel's fixmaps */
5
6 #include <linux/mm.h>
7 #include <linux/string.h>
8 #include <linux/kernel.h>
9 #include <linux/gfp.h>
10 #include <linux/init.h>
11 #include <linux/stringify.h>
12 #include <asm/proto.h>
13 #include <asm/tlbflush.h>
14 #include <asm/ia32_unistd.h>
15
16 /* 32bit VDSOs mapped into user space. */
17 asm(".section \".init.data\",\"aw\"\n"
18 "syscall32_syscall:\n"
19 ".incbin \"arch/x86_64/ia32/vsyscall-syscall.so\"\n"
20 "syscall32_syscall_end:\n"
21 "syscall32_sysenter:\n"
22 ".incbin \"arch/x86_64/ia32/vsyscall-sysenter.so\"\n"
23 "syscall32_sysenter_end:\n"
24 ".previous");
25
26 extern unsigned char syscall32_syscall[], syscall32_syscall_end[];
27 extern unsigned char syscall32_sysenter[], syscall32_sysenter_end[];
28 extern int sysctl_vsyscall32;
29
30 char *syscall32_page;
31 static int use_sysenter = -1;
32
33 /*
34 * Map the 32bit vsyscall page on demand.
35 *
36 * RED-PEN: This knows too much about high level VM.
37 *
38 * Alternative would be to generate a vma with appropriate backing options
39 * and let it be handled by generic VM.
40 */
41 int __map_syscall32(struct mm_struct *mm, unsigned long address)
42 {
43 pgd_t *pgd;
44 pud_t *pud;
45 pte_t *pte;
46 pmd_t *pmd;
47 int err = -ENOMEM;
48
49 spin_lock(&mm->page_table_lock);
50 pgd = pgd_offset(mm, address);
51 pud = pud_alloc(mm, pgd, address);
52 if (pud) {
53 pmd = pmd_alloc(mm, pud, address);
54 if (pmd && (pte = pte_alloc_map(mm, pmd, address)) != NULL) {
55 if (pte_none(*pte)) {
56 set_pte(pte,
57 mk_pte(virt_to_page(syscall32_page),
58 PAGE_KERNEL_VSYSCALL32));
59 }
60 /* Flush only the local CPU. Other CPUs taking a fault
61 will just end up here again
62 This probably not needed and just paranoia. */
63 __flush_tlb_one(address);
64 err = 0;
65 }
66 }
67 spin_unlock(&mm->page_table_lock);
68 return err;
69 }
70
71 int map_syscall32(struct mm_struct *mm, unsigned long address)
72 {
73 int err;
74 down_read(&mm->mmap_sem);
75 err = __map_syscall32(mm, address);
76 up_read(&mm->mmap_sem);
77 return err;
78 }
79
80 static int __init init_syscall32(void)
81 {
82 syscall32_page = (void *)get_zeroed_page(GFP_KERNEL);
83 if (!syscall32_page)
84 panic("Cannot allocate syscall32 page");
85 SetPageReserved(virt_to_page(syscall32_page));
86 if (use_sysenter > 0) {
87 memcpy(syscall32_page, syscall32_sysenter,
88 syscall32_sysenter_end - syscall32_sysenter);
89 } else {
90 memcpy(syscall32_page, syscall32_syscall,
91 syscall32_syscall_end - syscall32_syscall);
92 }
93 return 0;
94 }
95
96 __initcall(init_syscall32);
97
98 /* May not be __init: called during resume */
99 void syscall32_cpu_init(void)
100 {
101 if (use_sysenter < 0)
102 use_sysenter = (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL);
103
104 /* Load these always in case some future AMD CPU supports
105 SYSENTER from compat mode too. */
106 checking_wrmsrl(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
107 checking_wrmsrl(MSR_IA32_SYSENTER_ESP, 0ULL);
108 checking_wrmsrl(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target);
109
110 wrmsrl(MSR_CSTAR, ia32_cstar_target);
111 }