[PATCH 11/16] make registers per-vcpu

2008-01-07 Thread Glauber de Oliveira Costa
This is the most obvious per-vcpu field: registers.

So this patch moves it from struct lguest to struct vcpu,
and patch the places in which they are used, accordingly

Signed-off-by: Glauber de Oliveira Costa <[EMAIL PROTECTED]>
---
 drivers/lguest/interrupts_and_traps.c |   29 ---
 drivers/lguest/lg.h   |9 ---
 drivers/lguest/lguest_user.c  |   36 +++---
 drivers/lguest/page_tables.c  |4 ++-
 drivers/lguest/x86/core.c |   39 +
 5 files changed, 61 insertions(+), 56 deletions(-)

diff --git a/drivers/lguest/interrupts_and_traps.c 
b/drivers/lguest/interrupts_and_traps.c
index d28671b..4cc7404 100644
--- a/drivers/lguest/interrupts_and_traps.c
+++ b/drivers/lguest/interrupts_and_traps.c
@@ -71,7 +71,7 @@ static void set_guest_interrupt(struct lg_vcpu *vcpu, u32 lo, 
u32 hi,
/* There are two cases for interrupts: one where the Guest is already
 * in the kernel, and a more complex one where the Guest is in
 * userspace.  We check the privilege level to find out. */
-   if ((lg->regs->ss&0x3) != GUEST_PL) {
+   if ((vcpu->regs->ss&0x3) != GUEST_PL) {
/* The Guest told us their kernel stack with the SET_STACK
 * hypercall: both the virtual address and the segment */
virtstack = lg->esp1;
@@ -82,12 +82,12 @@ static void set_guest_interrupt(struct lg_vcpu *vcpu, u32 
lo, u32 hi,
 * stack: when the Guest does an "iret" back from the interrupt
 * handler the CPU will notice they're dropping privilege
 * levels and expect these here. */
-   push_guest_stack(lg, &gstack, lg->regs->ss);
-   push_guest_stack(lg, &gstack, lg->regs->esp);
+   push_guest_stack(lg, &gstack, vcpu->regs->ss);
+   push_guest_stack(lg, &gstack, vcpu->regs->esp);
} else {
/* We're staying on the same Guest (kernel) stack. */
-   virtstack = lg->regs->esp;
-   ss = lg->regs->ss;
+   virtstack = vcpu->regs->esp;
+   ss = vcpu->regs->ss;
 
origstack = gstack = guest_pa(lg, virtstack);
}
@@ -96,7 +96,7 @@ static void set_guest_interrupt(struct lg_vcpu *vcpu, u32 lo, 
u32 hi,
 * the "Interrupt Flag" bit is always set.  We copy that bit from the
 * Guest's "irq_enabled" field into the eflags word: we saw the Guest
 * copy it back in "lguest_iret". */
-   eflags = lg->regs->eflags;
+   eflags = vcpu->regs->eflags;
if (get_user(irq_enable, &lg->lguest_data->irq_enabled) == 0
&& !(irq_enable & X86_EFLAGS_IF))
eflags &= ~X86_EFLAGS_IF;
@@ -105,19 +105,19 @@ static void set_guest_interrupt(struct lg_vcpu *vcpu, u32 
lo, u32 hi,
 * "eflags" word, the old code segment, and the old instruction
 * pointer. */
push_guest_stack(lg, &gstack, eflags);
-   push_guest_stack(lg, &gstack, lg->regs->cs);
-   push_guest_stack(lg, &gstack, lg->regs->eip);
+   push_guest_stack(lg, &gstack, vcpu->regs->cs);
+   push_guest_stack(lg, &gstack, vcpu->regs->eip);
 
/* For the six traps which supply an error code, we push that, too. */
if (has_err)
-   push_guest_stack(lg, &gstack, lg->regs->errcode);
+   push_guest_stack(lg, &gstack, vcpu->regs->errcode);
 
/* Now we've pushed all the old state, we change the stack, the code
 * segment and the address to execute. */
-   lg->regs->ss = ss;
-   lg->regs->esp = virtstack + (gstack - origstack);
-   lg->regs->cs = (__KERNEL_CS|GUEST_PL);
-   lg->regs->eip = idt_address(lo, hi);
+   vcpu->regs->ss = ss;
+   vcpu->regs->esp = virtstack + (gstack - origstack);
+   vcpu->regs->cs = (__KERNEL_CS|GUEST_PL);
+   vcpu->regs->eip = idt_address(lo, hi);
 
/* There are two kinds of interrupt handlers: 0xE is an "interrupt
 * gate" which expects interrupts to be disabled on entry. */
@@ -158,7 +158,8 @@ void maybe_do_interrupt(struct lg_vcpu *vcpu)
 
/* They may be in the middle of an iret, where they asked us never to
 * deliver interrupts. */
-   if (lg->regs->eip >= lg->noirq_start && lg->regs->eip < lg->noirq_end)
+   if ((vcpu->regs->eip >= lg->noirq_start) &&
+   (vcpu->regs->eip < lg->noirq_end))
return;
 
/* If they're halted, interrupts restart them. */
diff --git a/drivers/lguest/lg.h b/drivers/lguest/lg.h
index f871737..d8429a0 100644
--- a/drivers/lguest/lg.h
+++ b/drivers/lguest/lg.h
@@ -44,6 +44,10 @@ struct lg_vcpu {
int vcpu_id;
struct lguest *lg;
 
+   /* At end of a page shared mapped over lguest_pages in guest.  */
+   unsigned long regs_page;
+   struct lguest_regs *regs;
+
/* If a hypercall was asked for, this points to the ar

[PATCH 11/16] make registers per-vcpu

2007-12-20 Thread Glauber de Oliveira Costa
This is the most obvious per-vcpu field: registers.

So this patch moves it from struct lguest to struct vcpu,
and patch the places in which they are used, accordingly

Signed-off-by: Glauber de Oliveira Costa <[EMAIL PROTECTED]>
---
 drivers/lguest/interrupts_and_traps.c |   29 ---
 drivers/lguest/lg.h   |9 ---
 drivers/lguest/lguest_user.c  |   36 +++---
 drivers/lguest/page_tables.c  |4 ++-
 drivers/lguest/x86/core.c |   39 +
 5 files changed, 61 insertions(+), 56 deletions(-)

diff --git a/drivers/lguest/interrupts_and_traps.c 
b/drivers/lguest/interrupts_and_traps.c
index db440cb..1ceff5f 100644
--- a/drivers/lguest/interrupts_and_traps.c
+++ b/drivers/lguest/interrupts_and_traps.c
@@ -71,7 +71,7 @@ static void set_guest_interrupt(struct lguest_vcpu *vcpu, u32 
lo, u32 hi,
/* There are two cases for interrupts: one where the Guest is already
 * in the kernel, and a more complex one where the Guest is in
 * userspace.  We check the privilege level to find out. */
-   if ((lg->regs->ss&0x3) != GUEST_PL) {
+   if ((vcpu->regs->ss&0x3) != GUEST_PL) {
/* The Guest told us their kernel stack with the SET_STACK
 * hypercall: both the virtual address and the segment */
virtstack = lg->esp1;
@@ -82,12 +82,12 @@ static void set_guest_interrupt(struct lguest_vcpu *vcpu, 
u32 lo, u32 hi,
 * stack: when the Guest does an "iret" back from the interrupt
 * handler the CPU will notice they're dropping privilege
 * levels and expect these here. */
-   push_guest_stack(lg, &gstack, lg->regs->ss);
-   push_guest_stack(lg, &gstack, lg->regs->esp);
+   push_guest_stack(lg, &gstack, vcpu->regs->ss);
+   push_guest_stack(lg, &gstack, vcpu->regs->esp);
} else {
/* We're staying on the same Guest (kernel) stack. */
-   virtstack = lg->regs->esp;
-   ss = lg->regs->ss;
+   virtstack = vcpu->regs->esp;
+   ss = vcpu->regs->ss;
 
origstack = gstack = guest_pa(lg, virtstack);
}
@@ -96,7 +96,7 @@ static void set_guest_interrupt(struct lguest_vcpu *vcpu, u32 
lo, u32 hi,
 * the "Interrupt Flag" bit is always set.  We copy that bit from the
 * Guest's "irq_enabled" field into the eflags word: we saw the Guest
 * copy it back in "lguest_iret". */
-   eflags = lg->regs->eflags;
+   eflags = vcpu->regs->eflags;
if (get_user(irq_enable, &lg->lguest_data->irq_enabled) == 0
&& !(irq_enable & X86_EFLAGS_IF))
eflags &= ~X86_EFLAGS_IF;
@@ -105,19 +105,19 @@ static void set_guest_interrupt(struct lguest_vcpu *vcpu, 
u32 lo, u32 hi,
 * "eflags" word, the old code segment, and the old instruction
 * pointer. */
push_guest_stack(lg, &gstack, eflags);
-   push_guest_stack(lg, &gstack, lg->regs->cs);
-   push_guest_stack(lg, &gstack, lg->regs->eip);
+   push_guest_stack(lg, &gstack, vcpu->regs->cs);
+   push_guest_stack(lg, &gstack, vcpu->regs->eip);
 
/* For the six traps which supply an error code, we push that, too. */
if (has_err)
-   push_guest_stack(lg, &gstack, lg->regs->errcode);
+   push_guest_stack(lg, &gstack, vcpu->regs->errcode);
 
/* Now we've pushed all the old state, we change the stack, the code
 * segment and the address to execute. */
-   lg->regs->ss = ss;
-   lg->regs->esp = virtstack + (gstack - origstack);
-   lg->regs->cs = (__KERNEL_CS|GUEST_PL);
-   lg->regs->eip = idt_address(lo, hi);
+   vcpu->regs->ss = ss;
+   vcpu->regs->esp = virtstack + (gstack - origstack);
+   vcpu->regs->cs = (__KERNEL_CS|GUEST_PL);
+   vcpu->regs->eip = idt_address(lo, hi);
 
/* There are two kinds of interrupt handlers: 0xE is an "interrupt
 * gate" which expects interrupts to be disabled on entry. */
@@ -158,7 +158,8 @@ void maybe_do_interrupt(struct lguest_vcpu *vcpu)
 
/* They may be in the middle of an iret, where they asked us never to
 * deliver interrupts. */
-   if (lg->regs->eip >= lg->noirq_start && lg->regs->eip < lg->noirq_end)
+   if ((vcpu->regs->eip >= lg->noirq_start) &&
+   (vcpu->regs->eip < lg->noirq_end))
return;
 
/* If they're halted, interrupts restart them. */
diff --git a/drivers/lguest/lg.h b/drivers/lguest/lg.h
index f6e9020..d05fe38 100644
--- a/drivers/lguest/lg.h
+++ b/drivers/lguest/lg.h
@@ -44,6 +44,10 @@ struct lguest_vcpu {
int vcpu_id;
struct lguest *lg;
 
+   /* At end of a page shared mapped over lguest_pages in guest.  */
+   unsigned long regs_page;
+   struct lguest_regs *regs;
+
/* If a hypercall was asked fo