Rusty Russell | f938d2c | 2007-07-26 10:41:02 -0700 | [diff] [blame] | 1 | /*P:500 Just as userspace programs request kernel operations through a system |
| 2 | * call, the Guest requests Host operations through a "hypercall". You might |
| 3 | * notice this nomenclature doesn't really follow any logic, but the name has |
| 4 | * been around for long enough that we're stuck with it. As you'd expect, this |
| 5 | * code is basically a one big switch statement. :*/ |
| 6 | |
| 7 | /* Copyright (C) 2006 Rusty Russell IBM Corporation |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 2 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program; if not, write to the Free Software |
| 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | */ |
| 23 | #include <linux/uaccess.h> |
| 24 | #include <linux/syscalls.h> |
| 25 | #include <linux/mm.h> |
Glauber de Oliveira Costa | ca94f2b | 2008-01-18 23:59:07 -0200 | [diff] [blame] | 26 | #include <linux/ktime.h> |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 27 | #include <asm/page.h> |
| 28 | #include <asm/pgtable.h> |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 29 | #include "lg.h" |
| 30 | |
Jes Sorensen | b410e7b | 2007-10-22 11:03:31 +1000 | [diff] [blame] | 31 | /*H:120 This is the core hypercall routine: where the Guest gets what it wants. |
Rusty Russell | a6bd8e1 | 2008-03-28 11:05:53 -0500 | [diff] [blame] | 32 | * Or gets killed. Or, in the case of LHCALL_SHUTDOWN, both. */ |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 33 | static void do_hcall(struct lg_cpu *cpu, struct hcall_args *args) |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 34 | { |
Jes Sorensen | b410e7b | 2007-10-22 11:03:31 +1000 | [diff] [blame] | 35 | switch (args->arg0) { |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 36 | case LHCALL_FLUSH_ASYNC: |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 37 | /* This call does nothing, except by breaking out of the Guest |
| 38 | * it makes us process all the asynchronous hypercalls. */ |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 39 | break; |
Rusty Russell | a32a8813 | 2009-06-12 22:27:02 -0600 | [diff] [blame] | 40 | case LHCALL_SEND_INTERRUPTS: |
| 41 | /* This call does nothing too, but by breaking out of the Guest |
| 42 | * it makes us process any pending interrupts. */ |
| 43 | break; |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 44 | case LHCALL_LGUEST_INIT: |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 45 | /* You can't get here unless you're already initialized. Don't |
| 46 | * do that. */ |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 47 | kill_guest(cpu, "already have lguest_data"); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 48 | break; |
Balaji Rao | ec04b13 | 2007-12-28 14:26:24 +0530 | [diff] [blame] | 49 | case LHCALL_SHUTDOWN: { |
| 50 | /* Shutdown is such a trivial hypercall that we do it in four |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 51 | * lines right here. */ |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 52 | char msg[128]; |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 53 | /* If the lgread fails, it will call kill_guest() itself; the |
| 54 | * kill_guest() with the message will be ignored. */ |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 55 | __lgread(cpu, msg, args->arg1, sizeof(msg)); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 56 | msg[sizeof(msg)-1] = '\0'; |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 57 | kill_guest(cpu, "CRASH: %s", msg); |
Balaji Rao | ec04b13 | 2007-12-28 14:26:24 +0530 | [diff] [blame] | 58 | if (args->arg2 == LGUEST_SHUTDOWN_RESTART) |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 59 | cpu->lg->dead = ERR_PTR(-ERESTART); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 60 | break; |
| 61 | } |
| 62 | case LHCALL_FLUSH_TLB: |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 63 | /* FLUSH_TLB comes in two flavors, depending on the |
| 64 | * argument: */ |
Jes Sorensen | b410e7b | 2007-10-22 11:03:31 +1000 | [diff] [blame] | 65 | if (args->arg1) |
Glauber de Oliveira Costa | 4665ac8 | 2008-01-07 11:05:35 -0200 | [diff] [blame] | 66 | guest_pagetable_clear_all(cpu); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 67 | else |
Glauber de Oliveira Costa | 1713608 | 2008-01-07 11:05:37 -0200 | [diff] [blame] | 68 | guest_pagetable_flush_user(cpu); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 69 | break; |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 70 | |
| 71 | /* All these calls simply pass the arguments through to the right |
| 72 | * routines. */ |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 73 | case LHCALL_NEW_PGTABLE: |
Glauber de Oliveira Costa | 4665ac8 | 2008-01-07 11:05:35 -0200 | [diff] [blame] | 74 | guest_new_pagetable(cpu, args->arg1); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 75 | break; |
| 76 | case LHCALL_SET_STACK: |
Glauber de Oliveira Costa | 4665ac8 | 2008-01-07 11:05:35 -0200 | [diff] [blame] | 77 | guest_set_stack(cpu, args->arg1, args->arg2, args->arg3); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 78 | break; |
| 79 | case LHCALL_SET_PTE: |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 80 | guest_set_pte(cpu, args->arg1, args->arg2, __pte(args->arg3)); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 81 | break; |
Matias Zabaljauregui | ebe0ba8 | 2009-05-30 15:48:08 -0300 | [diff] [blame^] | 82 | case LHCALL_SET_PGD: |
| 83 | guest_set_pgd(cpu->lg, args->arg1, args->arg2); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 84 | break; |
| 85 | case LHCALL_SET_CLOCKEVENT: |
Glauber de Oliveira Costa | ad8d8f3 | 2008-01-07 11:05:28 -0200 | [diff] [blame] | 86 | guest_set_clockevent(cpu, args->arg1); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 87 | break; |
| 88 | case LHCALL_TS: |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 89 | /* This sets the TS flag, as we saw used in run_guest(). */ |
Glauber de Oliveira Costa | 4665ac8 | 2008-01-07 11:05:35 -0200 | [diff] [blame] | 90 | cpu->ts = args->arg1; |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 91 | break; |
| 92 | case LHCALL_HALT: |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 93 | /* Similarly, this sets the halted flag for run_guest(). */ |
Glauber de Oliveira Costa | 66686c2 | 2008-01-07 11:05:34 -0200 | [diff] [blame] | 94 | cpu->halted = 1; |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 95 | break; |
Rusty Russell | 1504527 | 2007-10-22 11:24:10 +1000 | [diff] [blame] | 96 | case LHCALL_NOTIFY: |
Glauber de Oliveira Costa | 5e232f4 | 2008-01-07 11:05:36 -0200 | [diff] [blame] | 97 | cpu->pending_notify = args->arg1; |
Rusty Russell | 1504527 | 2007-10-22 11:24:10 +1000 | [diff] [blame] | 98 | break; |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 99 | default: |
Rusty Russell | e1e7296 | 2007-10-25 15:02:50 +1000 | [diff] [blame] | 100 | /* It should be an architecture-specific hypercall. */ |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 101 | if (lguest_arch_do_hcall(cpu, args)) |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 102 | kill_guest(cpu, "Bad hypercall %li\n", args->arg0); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 103 | } |
| 104 | } |
Jes Sorensen | b410e7b | 2007-10-22 11:03:31 +1000 | [diff] [blame] | 105 | /*:*/ |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 106 | |
Jes Sorensen | b410e7b | 2007-10-22 11:03:31 +1000 | [diff] [blame] | 107 | /*H:124 Asynchronous hypercalls are easy: we just look in the array in the |
| 108 | * Guest's "struct lguest_data" to see if any new ones are marked "ready". |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 109 | * |
| 110 | * We are careful to do these in order: obviously we respect the order the |
| 111 | * Guest put them in the ring, but we also promise the Guest that they will |
| 112 | * happen before any normal hypercall (which is why we check this before |
| 113 | * checking for a normal hcall). */ |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 114 | static void do_async_hcalls(struct lg_cpu *cpu) |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 115 | { |
| 116 | unsigned int i; |
| 117 | u8 st[LHCALL_RING_SIZE]; |
| 118 | |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 119 | /* For simplicity, we copy the entire call status array in at once. */ |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 120 | if (copy_from_user(&st, &cpu->lg->lguest_data->hcall_status, sizeof(st))) |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 121 | return; |
| 122 | |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 123 | /* We process "struct lguest_data"s hcalls[] ring once. */ |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 124 | for (i = 0; i < ARRAY_SIZE(st); i++) { |
Jes Sorensen | b410e7b | 2007-10-22 11:03:31 +1000 | [diff] [blame] | 125 | struct hcall_args args; |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 126 | /* We remember where we were up to from last time. This makes |
| 127 | * sure that the hypercalls are done in the order the Guest |
| 128 | * places them in the ring. */ |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 129 | unsigned int n = cpu->next_hcall; |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 130 | |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 131 | /* 0xFF means there's no call here (yet). */ |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 132 | if (st[n] == 0xFF) |
| 133 | break; |
| 134 | |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 135 | /* OK, we have hypercall. Increment the "next_hcall" cursor, |
| 136 | * and wrap back to 0 if we reach the end. */ |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 137 | if (++cpu->next_hcall == LHCALL_RING_SIZE) |
| 138 | cpu->next_hcall = 0; |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 139 | |
Jes Sorensen | b410e7b | 2007-10-22 11:03:31 +1000 | [diff] [blame] | 140 | /* Copy the hypercall arguments into a local copy of |
| 141 | * the hcall_args struct. */ |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 142 | if (copy_from_user(&args, &cpu->lg->lguest_data->hcalls[n], |
Jes Sorensen | b410e7b | 2007-10-22 11:03:31 +1000 | [diff] [blame] | 143 | sizeof(struct hcall_args))) { |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 144 | kill_guest(cpu, "Fetching async hypercalls"); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 145 | break; |
| 146 | } |
| 147 | |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 148 | /* Do the hypercall, same as a normal one. */ |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 149 | do_hcall(cpu, &args); |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 150 | |
| 151 | /* Mark the hypercall done. */ |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 152 | if (put_user(0xFF, &cpu->lg->lguest_data->hcall_status[n])) { |
| 153 | kill_guest(cpu, "Writing result for async hypercall"); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 154 | break; |
| 155 | } |
| 156 | |
Rusty Russell | 1504527 | 2007-10-22 11:24:10 +1000 | [diff] [blame] | 157 | /* Stop doing hypercalls if they want to notify the Launcher: |
| 158 | * it needs to service this first. */ |
Glauber de Oliveira Costa | 5e232f4 | 2008-01-07 11:05:36 -0200 | [diff] [blame] | 159 | if (cpu->pending_notify) |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 160 | break; |
| 161 | } |
| 162 | } |
| 163 | |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 164 | /* Last of all, we look at what happens first of all. The very first time the |
| 165 | * Guest makes a hypercall, we end up here to set things up: */ |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 166 | static void initialize(struct lg_cpu *cpu) |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 167 | { |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 168 | /* You can't do anything until you're initialized. The Guest knows the |
| 169 | * rules, so we're unforgiving here. */ |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 170 | if (cpu->hcall->arg0 != LHCALL_LGUEST_INIT) { |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 171 | kill_guest(cpu, "hypercall %li before INIT", cpu->hcall->arg0); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 172 | return; |
| 173 | } |
| 174 | |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 175 | if (lguest_arch_init_hypercalls(cpu)) |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 176 | kill_guest(cpu, "bad guest page %p", cpu->lg->lguest_data); |
Rusty Russell | 3c6b5bf | 2007-10-22 11:03:26 +1000 | [diff] [blame] | 177 | |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 178 | /* The Guest tells us where we're not to deliver interrupts by putting |
| 179 | * the range of addresses into "struct lguest_data". */ |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 180 | if (get_user(cpu->lg->noirq_start, &cpu->lg->lguest_data->noirq_start) |
| 181 | || get_user(cpu->lg->noirq_end, &cpu->lg->lguest_data->noirq_end)) |
| 182 | kill_guest(cpu, "bad guest page %p", cpu->lg->lguest_data); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 183 | |
Rusty Russell | e1e7296 | 2007-10-25 15:02:50 +1000 | [diff] [blame] | 184 | /* We write the current time into the Guest's data page once so it can |
| 185 | * set its clock. */ |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 186 | write_timestamp(cpu); |
Rusty Russell | 6c8dca5 | 2007-07-27 13:42:52 +1000 | [diff] [blame] | 187 | |
Rusty Russell | 47436aa | 2007-10-22 11:03:36 +1000 | [diff] [blame] | 188 | /* page_tables.c will also do some setup. */ |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 189 | page_table_guest_data_init(cpu); |
Rusty Russell | 47436aa | 2007-10-22 11:03:36 +1000 | [diff] [blame] | 190 | |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 191 | /* This is the one case where the above accesses might have been the |
| 192 | * first write to a Guest page. This may have caused a copy-on-write |
Rusty Russell | e1e7296 | 2007-10-25 15:02:50 +1000 | [diff] [blame] | 193 | * fault, but the old page might be (read-only) in the Guest |
| 194 | * pagetable. */ |
Glauber de Oliveira Costa | 4665ac8 | 2008-01-07 11:05:35 -0200 | [diff] [blame] | 195 | guest_pagetable_clear_all(cpu); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 196 | } |
Rusty Russell | a6bd8e1 | 2008-03-28 11:05:53 -0500 | [diff] [blame] | 197 | /*:*/ |
| 198 | |
| 199 | /*M:013 If a Guest reads from a page (so creates a mapping) that it has never |
| 200 | * written to, and then the Launcher writes to it (ie. the output of a virtual |
| 201 | * device), the Guest will still see the old page. In practice, this never |
| 202 | * happens: why would the Guest read a page which it has never written to? But |
| 203 | * a similar scenario might one day bite us, so it's worth mentioning. :*/ |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 204 | |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 205 | /*H:100 |
| 206 | * Hypercalls |
| 207 | * |
| 208 | * Remember from the Guest, hypercalls come in two flavors: normal and |
| 209 | * asynchronous. This file handles both of types. |
| 210 | */ |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 211 | void do_hypercalls(struct lg_cpu *cpu) |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 212 | { |
Rusty Russell | cc6d4fb | 2007-10-22 11:03:30 +1000 | [diff] [blame] | 213 | /* Not initialized yet? This hypercall must do it. */ |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 214 | if (unlikely(!cpu->lg->lguest_data)) { |
Rusty Russell | cc6d4fb | 2007-10-22 11:03:30 +1000 | [diff] [blame] | 215 | /* Set up the "struct lguest_data" */ |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 216 | initialize(cpu); |
Rusty Russell | cc6d4fb | 2007-10-22 11:03:30 +1000 | [diff] [blame] | 217 | /* Hcall is done. */ |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 218 | cpu->hcall = NULL; |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 219 | return; |
| 220 | } |
| 221 | |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 222 | /* The Guest has initialized. |
| 223 | * |
| 224 | * Look in the hypercall ring for the async hypercalls: */ |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 225 | do_async_hcalls(cpu); |
Rusty Russell | bff672e | 2007-07-26 10:41:04 -0700 | [diff] [blame] | 226 | |
| 227 | /* If we stopped reading the hypercall ring because the Guest did a |
Rusty Russell | 1504527 | 2007-10-22 11:24:10 +1000 | [diff] [blame] | 228 | * NOTIFY to the Launcher, we want to return now. Otherwise we do |
Rusty Russell | cc6d4fb | 2007-10-22 11:03:30 +1000 | [diff] [blame] | 229 | * the hypercall. */ |
Glauber de Oliveira Costa | 5e232f4 | 2008-01-07 11:05:36 -0200 | [diff] [blame] | 230 | if (!cpu->pending_notify) { |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 231 | do_hcall(cpu, cpu->hcall); |
Rusty Russell | cc6d4fb | 2007-10-22 11:03:30 +1000 | [diff] [blame] | 232 | /* Tricky point: we reset the hcall pointer to mark the |
| 233 | * hypercall as "done". We use the hcall pointer rather than |
| 234 | * the trap number to indicate a hypercall is pending. |
| 235 | * Normally it doesn't matter: the Guest will run again and |
| 236 | * update the trap number before we come back here. |
| 237 | * |
Rusty Russell | e1e7296 | 2007-10-25 15:02:50 +1000 | [diff] [blame] | 238 | * However, if we are signalled or the Guest sends I/O to the |
Rusty Russell | cc6d4fb | 2007-10-22 11:03:30 +1000 | [diff] [blame] | 239 | * Launcher, the run_guest() loop will exit without running the |
| 240 | * Guest. When it comes back it would try to re-run the |
Rusty Russell | a6bd8e1 | 2008-03-28 11:05:53 -0500 | [diff] [blame] | 241 | * hypercall. Finding that bug sucked. */ |
Glauber de Oliveira Costa | 73044f0 | 2008-01-07 11:05:27 -0200 | [diff] [blame] | 242 | cpu->hcall = NULL; |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 243 | } |
| 244 | } |
Rusty Russell | 6c8dca5 | 2007-07-27 13:42:52 +1000 | [diff] [blame] | 245 | |
| 246 | /* This routine supplies the Guest with time: it's used for wallclock time at |
| 247 | * initial boot and as a rough time source if the TSC isn't available. */ |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 248 | void write_timestamp(struct lg_cpu *cpu) |
Rusty Russell | 6c8dca5 | 2007-07-27 13:42:52 +1000 | [diff] [blame] | 249 | { |
| 250 | struct timespec now; |
| 251 | ktime_get_real_ts(&now); |
Glauber de Oliveira Costa | 382ac6b | 2008-01-17 19:19:42 -0200 | [diff] [blame] | 252 | if (copy_to_user(&cpu->lg->lguest_data->time, |
| 253 | &now, sizeof(struct timespec))) |
| 254 | kill_guest(cpu, "Writing timestamp"); |
Rusty Russell | 6c8dca5 | 2007-07-27 13:42:52 +1000 | [diff] [blame] | 255 | } |