aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/lguest/interrupts_and_traps.c
diff options
context:
space:
mode:
authorGlauber de Oliveira Costa <gcosta@redhat.com>2008-01-17 16:19:42 -0500
committerRusty Russell <rusty@rustcorp.com.au>2008-01-30 06:50:18 -0500
commit382ac6b3fbc0ea6a5697fc6caaf7e7de12fa8b96 (patch)
treebdda012251f29775b2e1201f3b2b3e38c4680f42 /drivers/lguest/interrupts_and_traps.c
parent934faab464c6a26ed1a226b6cf7111b35405dde1 (diff)
lguest: get rid of lg variable assignments
We can save some lines of code by getting rid of *lg = cpu... lines of code spread everywhere by now. Signed-off-by: Glauber de Oliveira Costa <gcosta@redhat.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/lguest/interrupts_and_traps.c')
-rw-r--r--drivers/lguest/interrupts_and_traps.c54
1 files changed, 26 insertions, 28 deletions
diff --git a/drivers/lguest/interrupts_and_traps.c b/drivers/lguest/interrupts_and_traps.c
index 9ac7455ec7fb..32e97c1858e5 100644
--- a/drivers/lguest/interrupts_and_traps.c
+++ b/drivers/lguest/interrupts_and_traps.c
@@ -41,11 +41,11 @@ static int idt_present(u32 lo, u32 hi)
41 41
42/* We need a helper to "push" a value onto the Guest's stack, since that's a 42/* We need a helper to "push" a value onto the Guest's stack, since that's a
43 * big part of what delivering an interrupt does. */ 43 * big part of what delivering an interrupt does. */
44static void push_guest_stack(struct lguest *lg, unsigned long *gstack, u32 val) 44static void push_guest_stack(struct lg_cpu *cpu, unsigned long *gstack, u32 val)
45{ 45{
46 /* Stack grows upwards: move stack then write value. */ 46 /* Stack grows upwards: move stack then write value. */
47 *gstack -= 4; 47 *gstack -= 4;
48 lgwrite(lg, *gstack, u32, val); 48 lgwrite(cpu, *gstack, u32, val);
49} 49}
50 50
51/*H:210 The set_guest_interrupt() routine actually delivers the interrupt or 51/*H:210 The set_guest_interrupt() routine actually delivers the interrupt or
@@ -65,7 +65,6 @@ static void set_guest_interrupt(struct lg_cpu *cpu, u32 lo, u32 hi, int has_err)
65 unsigned long gstack, origstack; 65 unsigned long gstack, origstack;
66 u32 eflags, ss, irq_enable; 66 u32 eflags, ss, irq_enable;
67 unsigned long virtstack; 67 unsigned long virtstack;
68 struct lguest *lg = cpu->lg;
69 68
70 /* There are two cases for interrupts: one where the Guest is already 69 /* There are two cases for interrupts: one where the Guest is already
71 * in the kernel, and a more complex one where the Guest is in 70 * in the kernel, and a more complex one where the Guest is in
@@ -81,8 +80,8 @@ static void set_guest_interrupt(struct lg_cpu *cpu, u32 lo, u32 hi, int has_err)
81 * stack: when the Guest does an "iret" back from the interrupt 80 * stack: when the Guest does an "iret" back from the interrupt
82 * handler the CPU will notice they're dropping privilege 81 * handler the CPU will notice they're dropping privilege
83 * levels and expect these here. */ 82 * levels and expect these here. */
84 push_guest_stack(lg, &gstack, cpu->regs->ss); 83 push_guest_stack(cpu, &gstack, cpu->regs->ss);
85 push_guest_stack(lg, &gstack, cpu->regs->esp); 84 push_guest_stack(cpu, &gstack, cpu->regs->esp);
86 } else { 85 } else {
87 /* We're staying on the same Guest (kernel) stack. */ 86 /* We're staying on the same Guest (kernel) stack. */
88 virtstack = cpu->regs->esp; 87 virtstack = cpu->regs->esp;
@@ -96,20 +95,20 @@ static void set_guest_interrupt(struct lg_cpu *cpu, u32 lo, u32 hi, int has_err)
96 * Guest's "irq_enabled" field into the eflags word: we saw the Guest 95 * Guest's "irq_enabled" field into the eflags word: we saw the Guest
97 * copy it back in "lguest_iret". */ 96 * copy it back in "lguest_iret". */
98 eflags = cpu->regs->eflags; 97 eflags = cpu->regs->eflags;
99 if (get_user(irq_enable, &lg->lguest_data->irq_enabled) == 0 98 if (get_user(irq_enable, &cpu->lg->lguest_data->irq_enabled) == 0
100 && !(irq_enable & X86_EFLAGS_IF)) 99 && !(irq_enable & X86_EFLAGS_IF))
101 eflags &= ~X86_EFLAGS_IF; 100 eflags &= ~X86_EFLAGS_IF;
102 101
103 /* An interrupt is expected to push three things on the stack: the old 102 /* An interrupt is expected to push three things on the stack: the old
104 * "eflags" word, the old code segment, and the old instruction 103 * "eflags" word, the old code segment, and the old instruction
105 * pointer. */ 104 * pointer. */
106 push_guest_stack(lg, &gstack, eflags); 105 push_guest_stack(cpu, &gstack, eflags);
107 push_guest_stack(lg, &gstack, cpu->regs->cs); 106 push_guest_stack(cpu, &gstack, cpu->regs->cs);
108 push_guest_stack(lg, &gstack, cpu->regs->eip); 107 push_guest_stack(cpu, &gstack, cpu->regs->eip);
109 108
110 /* For the six traps which supply an error code, we push that, too. */ 109 /* For the six traps which supply an error code, we push that, too. */
111 if (has_err) 110 if (has_err)
112 push_guest_stack(lg, &gstack, cpu->regs->errcode); 111 push_guest_stack(cpu, &gstack, cpu->regs->errcode);
113 112
114 /* Now we've pushed all the old state, we change the stack, the code 113 /* Now we've pushed all the old state, we change the stack, the code
115 * segment and the address to execute. */ 114 * segment and the address to execute. */
@@ -121,8 +120,8 @@ static void set_guest_interrupt(struct lg_cpu *cpu, u32 lo, u32 hi, int has_err)
121 /* There are two kinds of interrupt handlers: 0xE is an "interrupt 120 /* There are two kinds of interrupt handlers: 0xE is an "interrupt
122 * gate" which expects interrupts to be disabled on entry. */ 121 * gate" which expects interrupts to be disabled on entry. */
123 if (idt_type(lo, hi) == 0xE) 122 if (idt_type(lo, hi) == 0xE)
124 if (put_user(0, &lg->lguest_data->irq_enabled)) 123 if (put_user(0, &cpu->lg->lguest_data->irq_enabled))
125 kill_guest(lg, "Disabling interrupts"); 124 kill_guest(cpu, "Disabling interrupts");
126} 125}
127 126
128/*H:205 127/*H:205
@@ -133,17 +132,16 @@ static void set_guest_interrupt(struct lg_cpu *cpu, u32 lo, u32 hi, int has_err)
133void maybe_do_interrupt(struct lg_cpu *cpu) 132void maybe_do_interrupt(struct lg_cpu *cpu)
134{ 133{
135 unsigned int irq; 134 unsigned int irq;
136 struct lguest *lg = cpu->lg;
137 DECLARE_BITMAP(blk, LGUEST_IRQS); 135 DECLARE_BITMAP(blk, LGUEST_IRQS);
138 struct desc_struct *idt; 136 struct desc_struct *idt;
139 137
140 /* If the Guest hasn't even initialized yet, we can do nothing. */ 138 /* If the Guest hasn't even initialized yet, we can do nothing. */
141 if (!lg->lguest_data) 139 if (!cpu->lg->lguest_data)
142 return; 140 return;
143 141
144 /* Take our "irqs_pending" array and remove any interrupts the Guest 142 /* Take our "irqs_pending" array and remove any interrupts the Guest
145 * wants blocked: the result ends up in "blk". */ 143 * wants blocked: the result ends up in "blk". */
146 if (copy_from_user(&blk, lg->lguest_data->blocked_interrupts, 144 if (copy_from_user(&blk, cpu->lg->lguest_data->blocked_interrupts,
147 sizeof(blk))) 145 sizeof(blk)))
148 return; 146 return;
149 147
@@ -157,19 +155,20 @@ void maybe_do_interrupt(struct lg_cpu *cpu)
157 155
158 /* They may be in the middle of an iret, where they asked us never to 156 /* They may be in the middle of an iret, where they asked us never to
159 * deliver interrupts. */ 157 * deliver interrupts. */
160 if (cpu->regs->eip >= lg->noirq_start && cpu->regs->eip < lg->noirq_end) 158 if (cpu->regs->eip >= cpu->lg->noirq_start &&
159 (cpu->regs->eip < cpu->lg->noirq_end))
161 return; 160 return;
162 161
163 /* If they're halted, interrupts restart them. */ 162 /* If they're halted, interrupts restart them. */
164 if (cpu->halted) { 163 if (cpu->halted) {
165 /* Re-enable interrupts. */ 164 /* Re-enable interrupts. */
166 if (put_user(X86_EFLAGS_IF, &lg->lguest_data->irq_enabled)) 165 if (put_user(X86_EFLAGS_IF, &cpu->lg->lguest_data->irq_enabled))
167 kill_guest(lg, "Re-enabling interrupts"); 166 kill_guest(cpu, "Re-enabling interrupts");
168 cpu->halted = 0; 167 cpu->halted = 0;
169 } else { 168 } else {
170 /* Otherwise we check if they have interrupts disabled. */ 169 /* Otherwise we check if they have interrupts disabled. */
171 u32 irq_enabled; 170 u32 irq_enabled;
172 if (get_user(irq_enabled, &lg->lguest_data->irq_enabled)) 171 if (get_user(irq_enabled, &cpu->lg->lguest_data->irq_enabled))
173 irq_enabled = 0; 172 irq_enabled = 0;
174 if (!irq_enabled) 173 if (!irq_enabled)
175 return; 174 return;
@@ -194,7 +193,7 @@ void maybe_do_interrupt(struct lg_cpu *cpu)
194 * did this more often, but it can actually be quite slow: doing it 193 * did this more often, but it can actually be quite slow: doing it
195 * here is a compromise which means at least it gets updated every 194 * here is a compromise which means at least it gets updated every
196 * timer interrupt. */ 195 * timer interrupt. */
197 write_timestamp(lg); 196 write_timestamp(cpu);
198} 197}
199/*:*/ 198/*:*/
200 199
@@ -315,10 +314,9 @@ void pin_stack_pages(struct lg_cpu *cpu)
315{ 314{
316 unsigned int i; 315 unsigned int i;
317 316
318 struct lguest *lg = cpu->lg;
319 /* Depending on the CONFIG_4KSTACKS option, the Guest can have one or 317 /* Depending on the CONFIG_4KSTACKS option, the Guest can have one or
320 * two pages of stack space. */ 318 * two pages of stack space. */
321 for (i = 0; i < lg->stack_pages; i++) 319 for (i = 0; i < cpu->lg->stack_pages; i++)
322 /* The stack grows *upwards*, so the address we're given is the 320 /* The stack grows *upwards*, so the address we're given is the
323 * start of the page after the kernel stack. Subtract one to 321 * start of the page after the kernel stack. Subtract one to
324 * get back onto the first stack page, and keep subtracting to 322 * get back onto the first stack page, and keep subtracting to
@@ -339,10 +337,10 @@ void guest_set_stack(struct lg_cpu *cpu, u32 seg, u32 esp, unsigned int pages)
339 /* You are not allowed have a stack segment with privilege level 0: bad 337 /* You are not allowed have a stack segment with privilege level 0: bad
340 * Guest! */ 338 * Guest! */
341 if ((seg & 0x3) != GUEST_PL) 339 if ((seg & 0x3) != GUEST_PL)
342 kill_guest(cpu->lg, "bad stack segment %i", seg); 340 kill_guest(cpu, "bad stack segment %i", seg);
343 /* We only expect one or two stack pages. */ 341 /* We only expect one or two stack pages. */
344 if (pages > 2) 342 if (pages > 2)
345 kill_guest(cpu->lg, "bad stack pages %u", pages); 343 kill_guest(cpu, "bad stack pages %u", pages);
346 /* Save where the stack is, and how many pages */ 344 /* Save where the stack is, and how many pages */
347 cpu->ss1 = seg; 345 cpu->ss1 = seg;
348 cpu->esp1 = esp; 346 cpu->esp1 = esp;
@@ -356,7 +354,7 @@ void guest_set_stack(struct lg_cpu *cpu, u32 seg, u32 esp, unsigned int pages)
356 354
357/*H:235 This is the routine which actually checks the Guest's IDT entry and 355/*H:235 This is the routine which actually checks the Guest's IDT entry and
358 * transfers it into the entry in "struct lguest": */ 356 * transfers it into the entry in "struct lguest": */
359static void set_trap(struct lguest *lg, struct desc_struct *trap, 357static void set_trap(struct lg_cpu *cpu, struct desc_struct *trap,
360 unsigned int num, u32 lo, u32 hi) 358 unsigned int num, u32 lo, u32 hi)
361{ 359{
362 u8 type = idt_type(lo, hi); 360 u8 type = idt_type(lo, hi);
@@ -369,7 +367,7 @@ static void set_trap(struct lguest *lg, struct desc_struct *trap,
369 367
370 /* We only support interrupt and trap gates. */ 368 /* We only support interrupt and trap gates. */
371 if (type != 0xE && type != 0xF) 369 if (type != 0xE && type != 0xF)
372 kill_guest(lg, "bad IDT type %i", type); 370 kill_guest(cpu, "bad IDT type %i", type);
373 371
374 /* We only copy the handler address, present bit, privilege level and 372 /* We only copy the handler address, present bit, privilege level and
375 * type. The privilege level controls where the trap can be triggered 373 * type. The privilege level controls where the trap can be triggered
@@ -399,9 +397,9 @@ void load_guest_idt_entry(struct lg_cpu *cpu, unsigned int num, u32 lo, u32 hi)
399 397
400 /* Check that the Guest doesn't try to step outside the bounds. */ 398 /* Check that the Guest doesn't try to step outside the bounds. */
401 if (num >= ARRAY_SIZE(cpu->arch.idt)) 399 if (num >= ARRAY_SIZE(cpu->arch.idt))
402 kill_guest(cpu->lg, "Setting idt entry %u", num); 400 kill_guest(cpu, "Setting idt entry %u", num);
403 else 401 else
404 set_trap(cpu->lg, &cpu->arch.idt[num], num, lo, hi); 402 set_trap(cpu, &cpu->arch.idt[num], num, lo, hi);
405} 403}
406 404
407/* The default entry for each interrupt points into the Switcher routines which 405/* The default entry for each interrupt points into the Switcher routines which