aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/sys-i386/bugs.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/sys-i386/bugs.c')
-rw-r--r--arch/um/sys-i386/bugs.c201
1 files changed, 39 insertions, 162 deletions
diff --git a/arch/um/sys-i386/bugs.c b/arch/um/sys-i386/bugs.c
index 806895d73bcc..a74442d13762 100644
--- a/arch/um/sys-i386/bugs.c
+++ b/arch/um/sys-i386/bugs.c
@@ -3,171 +3,47 @@
3 * Licensed under the GPL 3 * Licensed under the GPL
4 */ 4 */
5 5
6#include <errno.h>
7#include <signal.h> 6#include <signal.h>
8#include <string.h>
9#include "kern_constants.h" 7#include "kern_constants.h"
10#include "os.h" 8#include "kern_util.h"
9#include "longjmp.h"
11#include "task.h" 10#include "task.h"
12#include "user.h" 11#include "user.h"
13 12#include "sysdep/ptrace.h"
14#define MAXTOKEN 64
15 13
16/* Set during early boot */ 14/* Set during early boot */
17int host_has_cmov = 1; 15int host_has_cmov = 1;
18int host_has_xmm = 0; 16static jmp_buf cmov_test_return;
19 17
20static char token(int fd, char *buf, int len, char stop) 18static void cmov_sigill_test_handler(int sig)
21{ 19{
22 int n; 20 host_has_cmov = 0;
23 char *ptr, *end, c; 21 longjmp(cmov_test_return, 1);
24
25 ptr = buf;
26 end = &buf[len];
27 do {
28 n = os_read_file(fd, ptr, sizeof(*ptr));
29 c = *ptr++;
30 if (n != sizeof(*ptr)) {
31 if (n == 0)
32 return 0;
33 printk(UM_KERN_ERR "Reading /proc/cpuinfo failed, "
34 "err = %d\n", -n);
35 if (n < 0)
36 return n;
37 else return -EIO;
38 }
39 } while ((c != '\n') && (c != stop) && (ptr < end));
40
41 if (ptr == end) {
42 printk(UM_KERN_ERR "Failed to find '%c' in /proc/cpuinfo\n",
43 stop);
44 return -1;
45 }
46 *(ptr - 1) = '\0';
47 return c;
48}
49
50static int find_cpuinfo_line(int fd, char *key, char *scratch, int len)
51{
52 int n;
53 char c;
54
55 scratch[len - 1] = '\0';
56 while (1) {
57 c = token(fd, scratch, len - 1, ':');
58 if (c <= 0)
59 return 0;
60 else if (c != ':') {
61 printk(UM_KERN_ERR "Failed to find ':' in "
62 "/proc/cpuinfo\n");
63 return 0;
64 }
65
66 if (!strncmp(scratch, key, strlen(key)))
67 return 1;
68
69 do {
70 n = os_read_file(fd, &c, sizeof(c));
71 if (n != sizeof(c)) {
72 printk(UM_KERN_ERR "Failed to find newline in "
73 "/proc/cpuinfo, err = %d\n", -n);
74 return 0;
75 }
76 } while (c != '\n');
77 }
78 return 0;
79} 22}
80 23
81static int check_cpu_flag(char *feature, int *have_it) 24void arch_check_bugs(void)
82{
83 char buf[MAXTOKEN], c;
84 int fd, len = ARRAY_SIZE(buf);
85
86 printk(UM_KERN_INFO "Checking for host processor %s support...",
87 feature);
88 fd = os_open_file("/proc/cpuinfo", of_read(OPENFLAGS()), 0);
89 if (fd < 0) {
90 printk(UM_KERN_ERR "Couldn't open /proc/cpuinfo, err = %d\n",
91 -fd);
92 return 0;
93 }
94
95 *have_it = 0;
96 if (!find_cpuinfo_line(fd, "flags", buf, ARRAY_SIZE(buf)))
97 goto out;
98
99 c = token(fd, buf, len - 1, ' ');
100 if (c < 0)
101 goto out;
102 else if (c != ' ') {
103 printk(UM_KERN_ERR "Failed to find ' ' in /proc/cpuinfo\n");
104 goto out;
105 }
106
107 while (1) {
108 c = token(fd, buf, len - 1, ' ');
109 if (c < 0)
110 goto out;
111 else if (c == '\n')
112 break;
113
114 if (!strcmp(buf, feature)) {
115 *have_it = 1;
116 goto out;
117 }
118 }
119 out:
120 if (*have_it == 0)
121 printk("No\n");
122 else if (*have_it == 1)
123 printk("Yes\n");
124 os_close_file(fd);
125 return 1;
126}
127
128#if 0 /*
129 * This doesn't work in tt mode, plus it's causing compilation problems
130 * for some people.
131 */
132static void disable_lcall(void)
133{ 25{
134 struct modify_ldt_ldt_s ldt; 26 struct sigaction old, new;
135 int err;
136 27
137 bzero(&ldt, sizeof(ldt)); 28 printk(UM_KERN_INFO "Checking for host processor cmov support...");
138 ldt.entry_number = 7; 29 new.sa_handler = cmov_sigill_test_handler;
139 ldt.base_addr = 0;
140 ldt.limit = 0;
141 err = modify_ldt(1, &ldt, sizeof(ldt));
142 if (err)
143 printk(UM_KERN_ERR "Failed to disable lcall7 - errno = %d\n",
144 errno);
145}
146#endif
147 30
148void arch_init_thread(void) 31 /* Make sure that SIGILL is enabled after the handler longjmps back */
149{ 32 new.sa_flags = SA_NODEFER;
150#if 0 33 sigemptyset(&new.sa_mask);
151 disable_lcall(); 34 sigaction(SIGILL, &new, &old);
152#endif
153}
154 35
155void arch_check_bugs(void) 36 if (setjmp(cmov_test_return) == 0) {
156{ 37 unsigned long foo = 0;
157 int have_it; 38 __asm__ __volatile__("cmovz %0, %1" : "=r" (foo) : "0" (foo));
39 printk(UM_KERN_CONT "Yes\n");
40 } else
41 printk(UM_KERN_CONT "No\n");
158 42
159 if (os_access("/proc/cpuinfo", OS_ACC_R_OK) < 0) { 43 sigaction(SIGILL, &old, &new);
160 printk(UM_KERN_ERR "/proc/cpuinfo not available - skipping CPU "
161 "capability checks\n");
162 return;
163 }
164 if (check_cpu_flag("cmov", &have_it))
165 host_has_cmov = have_it;
166 if (check_cpu_flag("xmm", &have_it))
167 host_has_xmm = have_it;
168} 44}
169 45
170int arch_handle_signal(int sig, struct uml_pt_regs *regs) 46void arch_examine_signal(int sig, struct uml_pt_regs *regs)
171{ 47{
172 unsigned char tmp[2]; 48 unsigned char tmp[2];
173 49
@@ -176,24 +52,25 @@ int arch_handle_signal(int sig, struct uml_pt_regs *regs)
176 * SIGILL in init. 52 * SIGILL in init.
177 */ 53 */
178 if ((sig != SIGILL) || (TASK_PID(get_current()) != 1)) 54 if ((sig != SIGILL) || (TASK_PID(get_current()) != 1))
179 return 0; 55 return;
56
57 if (copy_from_user_proc(tmp, (void *) UPT_IP(regs), 2)) {
58 printk(UM_KERN_ERR "SIGILL in init, could not read "
59 "instructions!\n");
60 return;
61 }
180 62
181 if (copy_from_user_proc(tmp, (void *) UPT_IP(regs), 2))
182 panic("SIGILL in init, could not read instructions!\n");
183 if ((tmp[0] != 0x0f) || ((tmp[1] & 0xf0) != 0x40)) 63 if ((tmp[0] != 0x0f) || ((tmp[1] & 0xf0) != 0x40))
184 return 0; 64 return;
185 65
186 if (host_has_cmov == 0) 66 if (host_has_cmov == 0)
187 panic("SIGILL caused by cmov, which this processor doesn't " 67 printk(UM_KERN_ERR "SIGILL caused by cmov, which this "
188 "implement, boot a filesystem compiled for older " 68 "processor doesn't implement. Boot a filesystem "
189 "processors"); 69 "compiled for older processors");
190 else if (host_has_cmov == 1) 70 else if (host_has_cmov == 1)
191 panic("SIGILL caused by cmov, which this processor claims to " 71 printk(UM_KERN_ERR "SIGILL caused by cmov, which this "
192 "implement"); 72 "processor claims to implement");
193 else if (host_has_cmov == -1) 73 else
194 panic("SIGILL caused by cmov, couldn't tell if this processor " 74 printk(UM_KERN_ERR "Bad value for host_has_cmov (%d)",
195 "implements it, boot a filesystem compiled for older " 75 host_has_cmov);
196 "processors");
197 else panic("Bad value for host_has_cmov (%d)", host_has_cmov);
198 return 0;
199} 76}