aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/lguest/core.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-01-30 17:35:32 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2008-01-30 17:35:32 -0500
commitd145c7253c8cb2ed8a75a8839621b0bb8f778820 (patch)
treefac21920d149a2cddfdfbde65066ff98935a9c57 /drivers/lguest/core.c
parent44c3b59102e3ecc7a01e9811862633e670595e51 (diff)
parent84f12e39c856a8b1ab407f8216ecebaf4204b94d (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus
* git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus: (27 commits) lguest: use __PAGE_KERNEL instead of _PAGE_KERNEL lguest: Use explicit includes rateher than indirect lguest: get rid of lg variable assignments lguest: change gpte_addr header lguest: move changed bitmap to lg_cpu lguest: move last_pages to lg_cpu lguest: change last_guest to last_cpu lguest: change spte_addr header lguest: per-vcpu lguest pgdir management lguest: make pending notifications per-vcpu lguest: makes special fields be per-vcpu lguest: per-vcpu lguest task management lguest: replace lguest_arch with lg_cpu_arch. lguest: make registers per-vcpu lguest: make emulate_insn receive a vcpu struct. lguest: map_switcher_in_guest() per-vcpu lguest: per-vcpu interrupt processing. lguest: per-vcpu lguest timers lguest: make hypercalls use the vcpu struct lguest: make write() operation smp aware ... Manual conflict resolved (maybe even correctly, who knows) in drivers/lguest/x86/core.c
Diffstat (limited to 'drivers/lguest/core.c')
-rw-r--r--drivers/lguest/core.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
index cb4c67025d52..7743d73768df 100644
--- a/drivers/lguest/core.c
+++ b/drivers/lguest/core.c
@@ -151,43 +151,43 @@ int lguest_address_ok(const struct lguest *lg,
151/* This routine copies memory from the Guest. Here we can see how useful the 151/* This routine copies memory from the Guest. Here we can see how useful the
152 * kill_lguest() routine we met in the Launcher can be: we return a random 152 * kill_lguest() routine we met in the Launcher can be: we return a random
153 * value (all zeroes) instead of needing to return an error. */ 153 * value (all zeroes) instead of needing to return an error. */
154void __lgread(struct lguest *lg, void *b, unsigned long addr, unsigned bytes) 154void __lgread(struct lg_cpu *cpu, void *b, unsigned long addr, unsigned bytes)
155{ 155{
156 if (!lguest_address_ok(lg, addr, bytes) 156 if (!lguest_address_ok(cpu->lg, addr, bytes)
157 || copy_from_user(b, lg->mem_base + addr, bytes) != 0) { 157 || copy_from_user(b, cpu->lg->mem_base + addr, bytes) != 0) {
158 /* copy_from_user should do this, but as we rely on it... */ 158 /* copy_from_user should do this, but as we rely on it... */
159 memset(b, 0, bytes); 159 memset(b, 0, bytes);
160 kill_guest(lg, "bad read address %#lx len %u", addr, bytes); 160 kill_guest(cpu, "bad read address %#lx len %u", addr, bytes);
161 } 161 }
162} 162}
163 163
164/* This is the write (copy into guest) version. */ 164/* This is the write (copy into guest) version. */
165void __lgwrite(struct lguest *lg, unsigned long addr, const void *b, 165void __lgwrite(struct lg_cpu *cpu, unsigned long addr, const void *b,
166 unsigned bytes) 166 unsigned bytes)
167{ 167{
168 if (!lguest_address_ok(lg, addr, bytes) 168 if (!lguest_address_ok(cpu->lg, addr, bytes)
169 || copy_to_user(lg->mem_base + addr, b, bytes) != 0) 169 || copy_to_user(cpu->lg->mem_base + addr, b, bytes) != 0)
170 kill_guest(lg, "bad write address %#lx len %u", addr, bytes); 170 kill_guest(cpu, "bad write address %#lx len %u", addr, bytes);
171} 171}
172/*:*/ 172/*:*/
173 173
174/*H:030 Let's jump straight to the the main loop which runs the Guest. 174/*H:030 Let's jump straight to the the main loop which runs the Guest.
175 * Remember, this is called by the Launcher reading /dev/lguest, and we keep 175 * Remember, this is called by the Launcher reading /dev/lguest, and we keep
176 * going around and around until something interesting happens. */ 176 * going around and around until something interesting happens. */
177int run_guest(struct lguest *lg, unsigned long __user *user) 177int run_guest(struct lg_cpu *cpu, unsigned long __user *user)
178{ 178{
179 /* We stop running once the Guest is dead. */ 179 /* We stop running once the Guest is dead. */
180 while (!lg->dead) { 180 while (!cpu->lg->dead) {
181 /* First we run any hypercalls the Guest wants done. */ 181 /* First we run any hypercalls the Guest wants done. */
182 if (lg->hcall) 182 if (cpu->hcall)
183 do_hypercalls(lg); 183 do_hypercalls(cpu);
184 184
185 /* It's possible the Guest did a NOTIFY hypercall to the 185 /* It's possible the Guest did a NOTIFY hypercall to the
186 * Launcher, in which case we return from the read() now. */ 186 * Launcher, in which case we return from the read() now. */
187 if (lg->pending_notify) { 187 if (cpu->pending_notify) {
188 if (put_user(lg->pending_notify, user)) 188 if (put_user(cpu->pending_notify, user))
189 return -EFAULT; 189 return -EFAULT;
190 return sizeof(lg->pending_notify); 190 return sizeof(cpu->pending_notify);
191 } 191 }
192 192
193 /* Check for signals */ 193 /* Check for signals */
@@ -195,13 +195,13 @@ int run_guest(struct lguest *lg, unsigned long __user *user)
195 return -ERESTARTSYS; 195 return -ERESTARTSYS;
196 196
197 /* If Waker set break_out, return to Launcher. */ 197 /* If Waker set break_out, return to Launcher. */
198 if (lg->break_out) 198 if (cpu->break_out)
199 return -EAGAIN; 199 return -EAGAIN;
200 200
201 /* Check if there are any interrupts which can be delivered 201 /* Check if there are any interrupts which can be delivered
202 * now: if so, this sets up the hander to be executed when we 202 * now: if so, this sets up the hander to be executed when we
203 * next run the Guest. */ 203 * next run the Guest. */
204 maybe_do_interrupt(lg); 204 maybe_do_interrupt(cpu);
205 205
206 /* All long-lived kernel loops need to check with this horrible 206 /* All long-lived kernel loops need to check with this horrible
207 * thing called the freezer. If the Host is trying to suspend, 207 * thing called the freezer. If the Host is trying to suspend,
@@ -210,12 +210,12 @@ int run_guest(struct lguest *lg, unsigned long __user *user)
210 210
211 /* Just make absolutely sure the Guest is still alive. One of 211 /* Just make absolutely sure the Guest is still alive. One of
212 * those hypercalls could have been fatal, for example. */ 212 * those hypercalls could have been fatal, for example. */
213 if (lg->dead) 213 if (cpu->lg->dead)
214 break; 214 break;
215 215
216 /* If the Guest asked to be stopped, we sleep. The Guest's 216 /* If the Guest asked to be stopped, we sleep. The Guest's
217 * clock timer or LHCALL_BREAK from the Waker will wake us. */ 217 * clock timer or LHCALL_BREAK from the Waker will wake us. */
218 if (lg->halted) { 218 if (cpu->halted) {
219 set_current_state(TASK_INTERRUPTIBLE); 219 set_current_state(TASK_INTERRUPTIBLE);
220 schedule(); 220 schedule();
221 continue; 221 continue;
@@ -226,15 +226,17 @@ int run_guest(struct lguest *lg, unsigned long __user *user)
226 local_irq_disable(); 226 local_irq_disable();
227 227
228 /* Actually run the Guest until something happens. */ 228 /* Actually run the Guest until something happens. */
229 lguest_arch_run_guest(lg); 229 lguest_arch_run_guest(cpu);
230 230
231 /* Now we're ready to be interrupted or moved to other CPUs */ 231 /* Now we're ready to be interrupted or moved to other CPUs */
232 local_irq_enable(); 232 local_irq_enable();
233 233
234 /* Now we deal with whatever happened to the Guest. */ 234 /* Now we deal with whatever happened to the Guest. */
235 lguest_arch_handle_trap(lg); 235 lguest_arch_handle_trap(cpu);
236 } 236 }
237 237
238 if (cpu->lg->dead == ERR_PTR(-ERESTART))
239 return -ERESTART;
238 /* The Guest is dead => "No such file or directory" */ 240 /* The Guest is dead => "No such file or directory" */
239 return -ENOENT; 241 return -ENOENT;
240} 242}
@@ -253,7 +255,7 @@ static int __init init(void)
253 255
254 /* Lguest can't run under Xen, VMI or itself. It does Tricky Stuff. */ 256 /* Lguest can't run under Xen, VMI or itself. It does Tricky Stuff. */
255 if (paravirt_enabled()) { 257 if (paravirt_enabled()) {
256 printk("lguest is afraid of %s\n", pv_info.name); 258 printk("lguest is afraid of being a guest\n");
257 return -EPERM; 259 return -EPERM;
258 } 260 }
259 261