aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/x86/include/asm/lguest_hcall.h1
-rw-r--r--arch/x86/lguest/boot.c21
-rw-r--r--arch/x86/lguest/i386_head.S2
-rw-r--r--drivers/lguest/core.c7
-rw-r--r--drivers/lguest/hypercalls.c4
-rw-r--r--drivers/lguest/interrupts_and_traps.c16
-rw-r--r--drivers/lguest/lg.h4
-rw-r--r--include/linux/lguest.h4
8 files changed, 43 insertions, 16 deletions
diff --git a/arch/x86/include/asm/lguest_hcall.h b/arch/x86/include/asm/lguest_hcall.h
index faae1996487b..f9a9f7811248 100644
--- a/arch/x86/include/asm/lguest_hcall.h
+++ b/arch/x86/include/asm/lguest_hcall.h
@@ -17,6 +17,7 @@
17#define LHCALL_LOAD_TLS 16 17#define LHCALL_LOAD_TLS 16
18#define LHCALL_NOTIFY 17 18#define LHCALL_NOTIFY 17
19#define LHCALL_LOAD_GDT_ENTRY 18 19#define LHCALL_LOAD_GDT_ENTRY 18
20#define LHCALL_SEND_INTERRUPTS 19
20 21
21#define LGUEST_TRAP_ENTRY 0x1F 22#define LGUEST_TRAP_ENTRY 0x1F
22 23
diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
index 2392a7a171c2..37b8c1d3e022 100644
--- a/arch/x86/lguest/boot.c
+++ b/arch/x86/lguest/boot.c
@@ -205,6 +205,12 @@ PV_CALLEE_SAVE_REGS_THUNK(save_fl);
205static void restore_fl(unsigned long flags) 205static void restore_fl(unsigned long flags)
206{ 206{
207 lguest_data.irq_enabled = flags; 207 lguest_data.irq_enabled = flags;
208 mb();
209 /* Null hcall forces interrupt delivery now, if irq_pending is
210 * set to X86_EFLAGS_IF (ie. an interrupt is pending, and flags
211 * enables interrupts. */
212 if (flags & lguest_data.irq_pending)
213 kvm_hypercall0(LHCALL_SEND_INTERRUPTS);
208} 214}
209PV_CALLEE_SAVE_REGS_THUNK(restore_fl); 215PV_CALLEE_SAVE_REGS_THUNK(restore_fl);
210 216
@@ -219,6 +225,11 @@ PV_CALLEE_SAVE_REGS_THUNK(irq_disable);
219static void irq_enable(void) 225static void irq_enable(void)
220{ 226{
221 lguest_data.irq_enabled = X86_EFLAGS_IF; 227 lguest_data.irq_enabled = X86_EFLAGS_IF;
228 mb();
229 /* Null hcall forces interrupt delivery now. */
230 if (lguest_data.irq_pending)
231 kvm_hypercall0(LHCALL_SEND_INTERRUPTS);
232
222} 233}
223PV_CALLEE_SAVE_REGS_THUNK(irq_enable); 234PV_CALLEE_SAVE_REGS_THUNK(irq_enable);
224 235
@@ -972,10 +983,10 @@ static void lguest_restart(char *reason)
972 * 983 *
973 * Our current solution is to allow the paravirt back end to optionally patch 984 * Our current solution is to allow the paravirt back end to optionally patch
974 * over the indirect calls to replace them with something more efficient. We 985 * over the indirect calls to replace them with something more efficient. We
975 * patch the four most commonly called functions: disable interrupts, enable 986 * patch two of the simplest of the most commonly called functions: disable
976 * interrupts, restore interrupts and save interrupts. We usually have 6 or 10 987 * interrupts and save interrupts. We usually have 6 or 10 bytes to patch
977 * bytes to patch into: the Guest versions of these operations are small enough 988 * into: the Guest versions of these operations are small enough that we can
978 * that we can fit comfortably. 989 * fit comfortably.
979 * 990 *
980 * First we need assembly templates of each of the patchable Guest operations, 991 * First we need assembly templates of each of the patchable Guest operations,
981 * and these are in i386_head.S. */ 992 * and these are in i386_head.S. */
@@ -986,8 +997,6 @@ static const struct lguest_insns
986 const char *start, *end; 997 const char *start, *end;
987} lguest_insns[] = { 998} lguest_insns[] = {
988 [PARAVIRT_PATCH(pv_irq_ops.irq_disable)] = { lgstart_cli, lgend_cli }, 999 [PARAVIRT_PATCH(pv_irq_ops.irq_disable)] = { lgstart_cli, lgend_cli },
989 [PARAVIRT_PATCH(pv_irq_ops.irq_enable)] = { lgstart_sti, lgend_sti },
990 [PARAVIRT_PATCH(pv_irq_ops.restore_fl)] = { lgstart_popf, lgend_popf },
991 [PARAVIRT_PATCH(pv_irq_ops.save_fl)] = { lgstart_pushf, lgend_pushf }, 1000 [PARAVIRT_PATCH(pv_irq_ops.save_fl)] = { lgstart_pushf, lgend_pushf },
992}; 1001};
993 1002
diff --git a/arch/x86/lguest/i386_head.S b/arch/x86/lguest/i386_head.S
index f79541989471..3e0c5545d59c 100644
--- a/arch/x86/lguest/i386_head.S
+++ b/arch/x86/lguest/i386_head.S
@@ -46,8 +46,6 @@ ENTRY(lguest_entry)
46 .globl lgstart_##name; .globl lgend_##name 46 .globl lgstart_##name; .globl lgend_##name
47 47
48LGUEST_PATCH(cli, movl $0, lguest_data+LGUEST_DATA_irq_enabled) 48LGUEST_PATCH(cli, movl $0, lguest_data+LGUEST_DATA_irq_enabled)
49LGUEST_PATCH(sti, movl $X86_EFLAGS_IF, lguest_data+LGUEST_DATA_irq_enabled)
50LGUEST_PATCH(popf, movl %eax, lguest_data+LGUEST_DATA_irq_enabled)
51LGUEST_PATCH(pushf, movl lguest_data+LGUEST_DATA_irq_enabled, %eax) 49LGUEST_PATCH(pushf, movl lguest_data+LGUEST_DATA_irq_enabled, %eax)
52/*:*/ 50/*:*/
53 51
diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
index 8ca1def5b142..03fbc88c0023 100644
--- a/drivers/lguest/core.c
+++ b/drivers/lguest/core.c
@@ -189,6 +189,7 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user)
189 /* We stop running once the Guest is dead. */ 189 /* We stop running once the Guest is dead. */
190 while (!cpu->lg->dead) { 190 while (!cpu->lg->dead) {
191 unsigned int irq; 191 unsigned int irq;
192 bool more;
192 193
193 /* First we run any hypercalls the Guest wants done. */ 194 /* First we run any hypercalls the Guest wants done. */
194 if (cpu->hcall) 195 if (cpu->hcall)
@@ -213,9 +214,9 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user)
213 /* Check if there are any interrupts which can be delivered now: 214 /* Check if there are any interrupts which can be delivered now:
214 * if so, this sets up the hander to be executed when we next 215 * if so, this sets up the hander to be executed when we next
215 * run the Guest. */ 216 * run the Guest. */
216 irq = interrupt_pending(cpu); 217 irq = interrupt_pending(cpu, &more);
217 if (irq < LGUEST_IRQS) 218 if (irq < LGUEST_IRQS)
218 try_deliver_interrupt(cpu, irq); 219 try_deliver_interrupt(cpu, irq, more);
219 220
220 /* All long-lived kernel loops need to check with this horrible 221 /* All long-lived kernel loops need to check with this horrible
221 * thing called the freezer. If the Host is trying to suspend, 222 * thing called the freezer. If the Host is trying to suspend,
@@ -233,7 +234,7 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user)
233 set_current_state(TASK_INTERRUPTIBLE); 234 set_current_state(TASK_INTERRUPTIBLE);
234 /* Just before we sleep, make sure nothing snuck in 235 /* Just before we sleep, make sure nothing snuck in
235 * which we should be doing. */ 236 * which we should be doing. */
236 if (interrupt_pending(cpu) < LGUEST_IRQS 237 if (interrupt_pending(cpu, &more) < LGUEST_IRQS
237 || cpu->break_out) 238 || cpu->break_out)
238 set_current_state(TASK_RUNNING); 239 set_current_state(TASK_RUNNING);
239 else 240 else
diff --git a/drivers/lguest/hypercalls.c b/drivers/lguest/hypercalls.c
index 54d66f05fefa..f252b71ae79e 100644
--- a/drivers/lguest/hypercalls.c
+++ b/drivers/lguest/hypercalls.c
@@ -37,6 +37,10 @@ static void do_hcall(struct lg_cpu *cpu, struct hcall_args *args)
37 /* This call does nothing, except by breaking out of the Guest 37 /* This call does nothing, except by breaking out of the Guest
38 * it makes us process all the asynchronous hypercalls. */ 38 * it makes us process all the asynchronous hypercalls. */
39 break; 39 break;
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;
40 case LHCALL_LGUEST_INIT: 44 case LHCALL_LGUEST_INIT:
41 /* You can't get here unless you're already initialized. Don't 45 /* You can't get here unless you're already initialized. Don't
42 * do that. */ 46 * do that. */
diff --git a/drivers/lguest/interrupts_and_traps.c b/drivers/lguest/interrupts_and_traps.c
index a8c966fee1e4..5a10754b4790 100644
--- a/drivers/lguest/interrupts_and_traps.c
+++ b/drivers/lguest/interrupts_and_traps.c
@@ -131,7 +131,7 @@ static void set_guest_interrupt(struct lg_cpu *cpu, u32 lo, u32 hi,
131 * interrupt_pending() returns the first pending interrupt which isn't blocked 131 * interrupt_pending() returns the first pending interrupt which isn't blocked
132 * by the Guest. It is called before every entry to the Guest, and just before 132 * by the Guest. It is called before every entry to the Guest, and just before
133 * we go to sleep when the Guest has halted itself. */ 133 * we go to sleep when the Guest has halted itself. */
134unsigned int interrupt_pending(struct lg_cpu *cpu) 134unsigned int interrupt_pending(struct lg_cpu *cpu, bool *more)
135{ 135{
136 unsigned int irq; 136 unsigned int irq;
137 DECLARE_BITMAP(blk, LGUEST_IRQS); 137 DECLARE_BITMAP(blk, LGUEST_IRQS);
@@ -149,13 +149,14 @@ unsigned int interrupt_pending(struct lg_cpu *cpu)
149 149
150 /* Find the first interrupt. */ 150 /* Find the first interrupt. */
151 irq = find_first_bit(blk, LGUEST_IRQS); 151 irq = find_first_bit(blk, LGUEST_IRQS);
152 *more = find_next_bit(blk, LGUEST_IRQS, irq+1);
152 153
153 return irq; 154 return irq;
154} 155}
155 156
156/* This actually diverts the Guest to running an interrupt handler, once an 157/* This actually diverts the Guest to running an interrupt handler, once an
157 * interrupt has been identified by interrupt_pending(). */ 158 * interrupt has been identified by interrupt_pending(). */
158void try_deliver_interrupt(struct lg_cpu *cpu, unsigned int irq) 159void try_deliver_interrupt(struct lg_cpu *cpu, unsigned int irq, bool more)
159{ 160{
160 struct desc_struct *idt; 161 struct desc_struct *idt;
161 162
@@ -178,8 +179,12 @@ void try_deliver_interrupt(struct lg_cpu *cpu, unsigned int irq)
178 u32 irq_enabled; 179 u32 irq_enabled;
179 if (get_user(irq_enabled, &cpu->lg->lguest_data->irq_enabled)) 180 if (get_user(irq_enabled, &cpu->lg->lguest_data->irq_enabled))
180 irq_enabled = 0; 181 irq_enabled = 0;
181 if (!irq_enabled) 182 if (!irq_enabled) {
183 /* Make sure they know an IRQ is pending. */
184 put_user(X86_EFLAGS_IF,
185 &cpu->lg->lguest_data->irq_pending);
182 return; 186 return;
187 }
183 } 188 }
184 189
185 /* Look at the IDT entry the Guest gave us for this interrupt. The 190 /* Look at the IDT entry the Guest gave us for this interrupt. The
@@ -202,6 +207,11 @@ void try_deliver_interrupt(struct lg_cpu *cpu, unsigned int irq)
202 * here is a compromise which means at least it gets updated every 207 * here is a compromise which means at least it gets updated every
203 * timer interrupt. */ 208 * timer interrupt. */
204 write_timestamp(cpu); 209 write_timestamp(cpu);
210
211 /* If there are no other interrupts we want to deliver, clear
212 * the pending flag. */
213 if (!more)
214 put_user(0, &cpu->lg->lguest_data->irq_pending);
205} 215}
206/*:*/ 216/*:*/
207 217
diff --git a/drivers/lguest/lg.h b/drivers/lguest/lg.h
index 6743cf147d97..573896533ac9 100644
--- a/drivers/lguest/lg.h
+++ b/drivers/lguest/lg.h
@@ -139,8 +139,8 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user);
139#define pgd_pfn(x) (pgd_val(x) >> PAGE_SHIFT) 139#define pgd_pfn(x) (pgd_val(x) >> PAGE_SHIFT)
140 140
141/* interrupts_and_traps.c: */ 141/* interrupts_and_traps.c: */
142unsigned int interrupt_pending(struct lg_cpu *cpu); 142unsigned int interrupt_pending(struct lg_cpu *cpu, bool *more);
143void try_deliver_interrupt(struct lg_cpu *cpu, unsigned int irq); 143void try_deliver_interrupt(struct lg_cpu *cpu, unsigned int irq, bool more);
144bool deliver_trap(struct lg_cpu *cpu, unsigned int num); 144bool deliver_trap(struct lg_cpu *cpu, unsigned int num);
145void load_guest_idt_entry(struct lg_cpu *cpu, unsigned int i, 145void load_guest_idt_entry(struct lg_cpu *cpu, unsigned int i,
146 u32 low, u32 hi); 146 u32 low, u32 hi);
diff --git a/include/linux/lguest.h b/include/linux/lguest.h
index 175e63f4a8c0..7bc1440fc473 100644
--- a/include/linux/lguest.h
+++ b/include/linux/lguest.h
@@ -30,6 +30,10 @@ struct lguest_data
30 /* Wallclock time set by the Host. */ 30 /* Wallclock time set by the Host. */
31 struct timespec time; 31 struct timespec time;
32 32
33 /* Interrupt pending set by the Host. The Guest should do a hypercall
34 * if it re-enables interrupts and sees this set (to X86_EFLAGS_IF). */
35 int irq_pending;
36
33 /* Async hypercall ring. Instead of directly making hypercalls, we can 37 /* Async hypercall ring. Instead of directly making hypercalls, we can
34 * place them in here for processing the next time the Host wants. 38 * place them in here for processing the next time the Host wants.
35 * This batching can be quite efficient. */ 39 * This batching can be quite efficient. */