aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/mm/fault_64.c
diff options
context:
space:
mode:
authorHarvey Harrison <harvey.harrison@gmail.com>2008-01-30 07:32:35 -0500
committerIngo Molnar <mingo@elte.hu>2008-01-30 07:32:35 -0500
commit1dc85be087d6645575847dc23c37147a2352312b (patch)
treef5bd8543789decca03c7d8a152fc2427af71c975 /arch/x86/mm/fault_64.c
parentb6795e65f158d12d3124379fc50ec156ae60f888 (diff)
x86: begin fault_{32|64}.c unification
Move X86_32 only get_segment_eip to X86_64 Move X86_64 only is_errata93 to X86_32 Change X86_32 loop in is_prefetch to highlight the differences between them. Fold the logic from __is_prefetch in as well on X86_32. Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/x86/mm/fault_64.c')
-rw-r--r--arch/x86/mm/fault_64.c124
1 files changed, 117 insertions, 7 deletions
diff --git a/arch/x86/mm/fault_64.c b/arch/x86/mm/fault_64.c
index 7e98a7691283..0d3d5979ce2c 100644
--- a/arch/x86/mm/fault_64.c
+++ b/arch/x86/mm/fault_64.c
@@ -64,32 +64,136 @@ static inline int notify_page_fault(struct pt_regs *regs)
64#endif 64#endif
65} 65}
66 66
67/* Sometimes the CPU reports invalid exceptions on prefetch. 67#ifdef CONFIG_X86_32
68 Check that here and ignore. 68/*
69 Opcode checker based on code by Richard Brunner */ 69 * Return EIP plus the CS segment base. The segment limit is also
70static noinline int is_prefetch(struct pt_regs *regs, unsigned long addr, 70 * adjusted, clamped to the kernel/user address space (whichever is
71 unsigned long error_code) 71 * appropriate), and returned in *eip_limit.
72 *
73 * The segment is checked, because it might have been changed by another
74 * task between the original faulting instruction and here.
75 *
76 * If CS is no longer a valid code segment, or if EIP is beyond the
77 * limit, or if it is a kernel address when CS is not a kernel segment,
78 * then the returned value will be greater than *eip_limit.
79 *
80 * This is slow, but is very rarely executed.
81 */
82static inline unsigned long get_segment_eip(struct pt_regs *regs,
83 unsigned long *eip_limit)
84{
85 unsigned long ip = regs->ip;
86 unsigned seg = regs->cs & 0xffff;
87 u32 seg_ar, seg_limit, base, *desc;
88
89 /* Unlikely, but must come before segment checks. */
90 if (unlikely(regs->flags & VM_MASK)) {
91 base = seg << 4;
92 *eip_limit = base + 0xffff;
93 return base + (ip & 0xffff);
94 }
95
96 /* The standard kernel/user address space limit. */
97 *eip_limit = user_mode(regs) ? USER_DS.seg : KERNEL_DS.seg;
98
99 /* By far the most common cases. */
100 if (likely(SEGMENT_IS_FLAT_CODE(seg)))
101 return ip;
102
103 /* Check the segment exists, is within the current LDT/GDT size,
104 that kernel/user (ring 0..3) has the appropriate privilege,
105 that it's a code segment, and get the limit. */
106 __asm__("larl %3,%0; lsll %3,%1"
107 : "=&r" (seg_ar), "=r" (seg_limit) : "0" (0), "rm" (seg));
108 if ((~seg_ar & 0x9800) || ip > seg_limit) {
109 *eip_limit = 0;
110 return 1; /* So that returned ip > *eip_limit. */
111 }
112
113 /* Get the GDT/LDT descriptor base.
114 When you look for races in this code remember that
115 LDT and other horrors are only used in user space. */
116 if (seg & (1<<2)) {
117 /* Must lock the LDT while reading it. */
118 mutex_lock(&current->mm->context.lock);
119 desc = current->mm->context.ldt;
120 desc = (void *)desc + (seg & ~7);
121 } else {
122 /* Must disable preemption while reading the GDT. */
123 desc = (u32 *)get_cpu_gdt_table(get_cpu());
124 desc = (void *)desc + (seg & ~7);
125 }
126
127 /* Decode the code segment base from the descriptor */
128 base = get_desc_base((struct desc_struct *)desc);
129
130 if (seg & (1<<2))
131 mutex_unlock(&current->mm->context.lock);
132 else
133 put_cpu();
134
135 /* Adjust EIP and segment limit, and clamp at the kernel limit.
136 It's legitimate for segments to wrap at 0xffffffff. */
137 seg_limit += base;
138 if (seg_limit < *eip_limit && seg_limit >= base)
139 *eip_limit = seg_limit;
140 return ip + base;
141}
142#endif
143
144/*
145 * X86_32
146 * Sometimes AMD Athlon/Opteron CPUs report invalid exceptions on prefetch.
147 * Check that here and ignore it.
148 *
149 * X86_64
150 * Sometimes the CPU reports invalid exceptions on prefetch.
151 * Check that here and ignore it.
152 *
153 * Opcode checker based on code by Richard Brunner
154 */
155static int is_prefetch(struct pt_regs *regs, unsigned long addr,
156 unsigned long error_code)
72{ 157{
73 unsigned char *instr; 158 unsigned char *instr;
74 int scan_more = 1; 159 int scan_more = 1;
75 int prefetch = 0; 160 int prefetch = 0;
76 unsigned char *max_instr; 161 unsigned char *max_instr;
77 162
163#ifdef CONFIG_X86_32
164 unsigned long limit;
165 if (unlikely(boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
166 boot_cpu_data.x86 >= 6)) {
167 /* Catch an obscure case of prefetch inside an NX page. */
168 if (nx_enabled && (error_code & PF_INSTR))
169 return 0;
170 } else {
171 return 0;
172 }
173 instr = (unsigned char *)get_segment_eip(regs, &limit);
174#else
78 /* If it was a exec fault ignore */ 175 /* If it was a exec fault ignore */
79 if (error_code & PF_INSTR) 176 if (error_code & PF_INSTR)
80 return 0; 177 return 0;
81
82 instr = (unsigned char __user *)convert_rip_to_linear(current, regs); 178 instr = (unsigned char __user *)convert_rip_to_linear(current, regs);
179#endif
180
83 max_instr = instr + 15; 181 max_instr = instr + 15;
84 182
183#ifdef CONFIG_X86_64
85 if (user_mode(regs) && instr >= (unsigned char *)TASK_SIZE) 184 if (user_mode(regs) && instr >= (unsigned char *)TASK_SIZE)
86 return 0; 185 return 0;
186#endif
87 187
88 while (scan_more && instr < max_instr) { 188 while (scan_more && instr < max_instr) {
89 unsigned char opcode; 189 unsigned char opcode;
90 unsigned char instr_hi; 190 unsigned char instr_hi;
91 unsigned char instr_lo; 191 unsigned char instr_lo;
92 192
193#ifdef CONFIG_X86_32
194 if (instr > (unsigned char *)limit)
195 break;
196#endif
93 if (probe_kernel_address(instr, opcode)) 197 if (probe_kernel_address(instr, opcode))
94 break; 198 break;
95 199
@@ -125,12 +229,16 @@ static noinline int is_prefetch(struct pt_regs *regs, unsigned long addr,
125 scan_more = (instr_lo & 0xC) == 0x4; 229 scan_more = (instr_lo & 0xC) == 0x4;
126 break; 230 break;
127 case 0xF0: 231 case 0xF0:
128 /* 0xF0, 0xF2, and 0xF3 are valid prefixes in all modes. */ 232 /* 0xF0, 0xF2, 0xF3 are valid prefixes in all modes. */
129 scan_more = !instr_lo || (instr_lo>>1) == 1; 233 scan_more = !instr_lo || (instr_lo>>1) == 1;
130 break; 234 break;
131 case 0x00: 235 case 0x00:
132 /* Prefetch instruction is 0x0F0D or 0x0F18 */ 236 /* Prefetch instruction is 0x0F0D or 0x0F18 */
133 scan_more = 0; 237 scan_more = 0;
238#ifdef CONFIG_X86_32
239 if (instr > (unsigned char *)limit)
240 break;
241#endif
134 if (probe_kernel_address(instr, opcode)) 242 if (probe_kernel_address(instr, opcode))
135 break; 243 break;
136 prefetch = (instr_lo == 0xF) && 244 prefetch = (instr_lo == 0xF) &&
@@ -185,6 +293,7 @@ bad:
185 printk("BAD\n"); 293 printk("BAD\n");
186} 294}
187 295
296#ifdef CONFIG_X86_64
188static const char errata93_warning[] = 297static const char errata93_warning[] =
189KERN_ERR "******* Your BIOS seems to not contain a fix for K8 errata #93\n" 298KERN_ERR "******* Your BIOS seems to not contain a fix for K8 errata #93\n"
190KERN_ERR "******* Working around it, but it may cause SEGVs or burn power.\n" 299KERN_ERR "******* Working around it, but it may cause SEGVs or burn power.\n"
@@ -218,6 +327,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
218 } 327 }
219 return 0; 328 return 0;
220} 329}
330#endif
221 331
222static noinline void pgtable_bad(unsigned long address, struct pt_regs *regs, 332static noinline void pgtable_bad(unsigned long address, struct pt_regs *regs,
223 unsigned long error_code) 333 unsigned long error_code)