[PATCH 14/16] makes special fields be per-vcpu

2008-01-07 Thread Glauber de Oliveira Costa
lguest struct have room for some fields, namely, cr2, ts, esp1
and ss1, that are not really guest-wide, but rather, vcpu-wide.

This patch puts it in the vcpu struct

Signed-off-by: Glauber de Oliveira Costa <[EMAIL PROTECTED]>
---
 drivers/lguest/hypercalls.c   |   10 +-
 drivers/lguest/interrupts_and_traps.c |   24 +---
 drivers/lguest/lg.h   |   18 ++
 drivers/lguest/page_tables.c  |   11 ++-
 drivers/lguest/x86/core.c |   10 --
 5 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/drivers/lguest/hypercalls.c b/drivers/lguest/hypercalls.c
index edc8cb4..4a4133b 100644
--- a/drivers/lguest/hypercalls.c
+++ b/drivers/lguest/hypercalls.c
@@ -58,7 +58,7 @@ static void do_hcall(struct lg_vcpu *vcpu, struct hcall_args 
*args)
/* FLUSH_TLB comes in two flavors, depending on the
 * argument: */
if (args->arg1)
-   guest_pagetable_clear_all(lg);
+   guest_pagetable_clear_all(vcpu);
else
guest_pagetable_flush_user(lg);
break;
@@ -66,10 +66,10 @@ static void do_hcall(struct lg_vcpu *vcpu, struct 
hcall_args *args)
/* All these calls simply pass the arguments through to the right
 * routines. */
case LHCALL_NEW_PGTABLE:
-   guest_new_pagetable(lg, args->arg1);
+   guest_new_pagetable(vcpu, args->arg1);
break;
case LHCALL_SET_STACK:
-   guest_set_stack(lg, args->arg1, args->arg2, args->arg3);
+   guest_set_stack(vcpu, args->arg1, args->arg2, args->arg3);
break;
case LHCALL_SET_PTE:
guest_set_pte(lg, args->arg1, args->arg2, __pte(args->arg3));
@@ -82,7 +82,7 @@ static void do_hcall(struct lg_vcpu *vcpu, struct hcall_args 
*args)
break;
case LHCALL_TS:
/* This sets the TS flag, as we saw used in run_guest(). */
-   lg->ts = args->arg1;
+   vcpu->ts = args->arg1;
break;
case LHCALL_HALT:
/* Similarly, this sets the halted flag for run_guest(). */
@@ -189,7 +189,7 @@ static void initialize(struct lg_vcpu *vcpu)
 * first write to a Guest page.  This may have caused a copy-on-write
 * fault, but the old page might be (read-only) in the Guest
 * pagetable. */
-   guest_pagetable_clear_all(lg);
+   guest_pagetable_clear_all(vcpu);
 }
 
 /*H:100
diff --git a/drivers/lguest/interrupts_and_traps.c 
b/drivers/lguest/interrupts_and_traps.c
index c1ca198..745f3ae 100644
--- a/drivers/lguest/interrupts_and_traps.c
+++ b/drivers/lguest/interrupts_and_traps.c
@@ -74,8 +74,8 @@ static void set_guest_interrupt(struct lg_vcpu *vcpu, u32 lo, 
u32 hi,
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;
-   ss = lg->ss1;
+   virtstack = vcpu->esp1;
+   ss = vcpu->ss1;
 
origstack = gstack = guest_pa(lg, virtstack);
/* We push the old stack segment and pointer onto the new
@@ -313,10 +313,11 @@ static int direct_trap(unsigned int num)
  * the Guest.
  *
  * Which is deeply unfair, because (literally!) it wasn't the Guests' fault. */
-void pin_stack_pages(struct lguest *lg)
+void pin_stack_pages(struct lg_vcpu *vcpu)
 {
unsigned int i;
 
+   struct lguest *lg = vcpu->lg;
/* Depending on the CONFIG_4KSTACKS option, the Guest can have one or
 * two pages of stack space. */
for (i = 0; i < lg->stack_pages; i++)
@@ -324,7 +325,7 @@ void pin_stack_pages(struct lguest *lg)
 * start of the page after the kernel stack.  Subtract one to
 * get back onto the first stack page, and keep subtracting to
 * get to the rest of the stack pages. */
-   pin_page(lg, lg->esp1 - 1 - i * PAGE_SIZE);
+   pin_page(lg, vcpu->esp1 - 1 - i * PAGE_SIZE);
 }
 
 /* Direct traps also mean that we need to know whenever the Guest wants to use
@@ -335,21 +336,22 @@ void pin_stack_pages(struct lguest *lg)
  *
  * In Linux each process has its own kernel stack, so this happens a lot: we
  * change stacks on each context switch. */
-void guest_set_stack(struct lguest *lg, u32 seg, u32 esp, unsigned int pages)
+void guest_set_stack(struct lg_vcpu *vcpu, u32 seg, u32 esp,
+unsigned int pages)
 {
/* You are not allowed have a stack segment with privilege level 0: bad
 * Guest! */
if ((seg & 0x3) != GUEST_PL)
-   kill_guest(lg, "bad stack segment %i", seg);
+   kill_guest(vcpu->lg, "bad stack segment %i", seg);
/* We only expect one

[PATCH 14/16] makes special fields be per-vcpu

2007-12-20 Thread Glauber de Oliveira Costa
lguest struct have room for some fields, namely, cr2, ts, esp1
and ss1, that are not really guest-wide, but rather, vcpu-wide.

This patch puts it in the vcpu struct

Signed-off-by: Glauber de Oliveira Costa <[EMAIL PROTECTED]>
---
 drivers/lguest/hypercalls.c   |   10 +-
 drivers/lguest/interrupts_and_traps.c |   24 +---
 drivers/lguest/lg.h   |   18 ++
 drivers/lguest/page_tables.c  |   11 ++-
 drivers/lguest/x86/core.c |   10 --
 5 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/drivers/lguest/hypercalls.c b/drivers/lguest/hypercalls.c
index 41ea2e2..c6b87ef 100644
--- a/drivers/lguest/hypercalls.c
+++ b/drivers/lguest/hypercalls.c
@@ -58,7 +58,7 @@ static void do_hcall(struct lguest_vcpu *vcpu, struct 
hcall_args *args)
/* FLUSH_TLB comes in two flavors, depending on the
 * argument: */
if (args->arg1)
-   guest_pagetable_clear_all(lg);
+   guest_pagetable_clear_all(vcpu);
else
guest_pagetable_flush_user(lg);
break;
@@ -66,10 +66,10 @@ static void do_hcall(struct lguest_vcpu *vcpu, struct 
hcall_args *args)
/* All these calls simply pass the arguments through to the right
 * routines. */
case LHCALL_NEW_PGTABLE:
-   guest_new_pagetable(lg, args->arg1);
+   guest_new_pagetable(vcpu, args->arg1);
break;
case LHCALL_SET_STACK:
-   guest_set_stack(lg, args->arg1, args->arg2, args->arg3);
+   guest_set_stack(vcpu, args->arg1, args->arg2, args->arg3);
break;
case LHCALL_SET_PTE:
guest_set_pte(lg, args->arg1, args->arg2, __pte(args->arg3));
@@ -82,7 +82,7 @@ static void do_hcall(struct lguest_vcpu *vcpu, struct 
hcall_args *args)
break;
case LHCALL_TS:
/* This sets the TS flag, as we saw used in run_guest(). */
-   lg->ts = args->arg1;
+   vcpu->ts = args->arg1;
break;
case LHCALL_HALT:
/* Similarly, this sets the halted flag for run_guest(). */
@@ -189,7 +189,7 @@ static void initialize(struct lguest_vcpu *vcpu)
 * first write to a Guest page.  This may have caused a copy-on-write
 * fault, but the old page might be (read-only) in the Guest
 * pagetable. */
-   guest_pagetable_clear_all(lg);
+   guest_pagetable_clear_all(vcpu);
 }
 
 /*H:100
diff --git a/drivers/lguest/interrupts_and_traps.c 
b/drivers/lguest/interrupts_and_traps.c
index 10c9aea..78f6210 100644
--- a/drivers/lguest/interrupts_and_traps.c
+++ b/drivers/lguest/interrupts_and_traps.c
@@ -74,8 +74,8 @@ static void set_guest_interrupt(struct lguest_vcpu *vcpu, u32 
lo, u32 hi,
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;
-   ss = lg->ss1;
+   virtstack = vcpu->esp1;
+   ss = vcpu->ss1;
 
origstack = gstack = guest_pa(lg, virtstack);
/* We push the old stack segment and pointer onto the new
@@ -313,10 +313,11 @@ static int direct_trap(unsigned int num)
  * the Guest.
  *
  * Which is deeply unfair, because (literally!) it wasn't the Guests' fault. */
-void pin_stack_pages(struct lguest *lg)
+void pin_stack_pages(struct lguest_vcpu *vcpu)
 {
unsigned int i;
 
+   struct lguest *lg = vcpu->lg;
/* Depending on the CONFIG_4KSTACKS option, the Guest can have one or
 * two pages of stack space. */
for (i = 0; i < lg->stack_pages; i++)
@@ -324,7 +325,7 @@ void pin_stack_pages(struct lguest *lg)
 * start of the page after the kernel stack.  Subtract one to
 * get back onto the first stack page, and keep subtracting to
 * get to the rest of the stack pages. */
-   pin_page(lg, lg->esp1 - 1 - i * PAGE_SIZE);
+   pin_page(lg, vcpu->esp1 - 1 - i * PAGE_SIZE);
 }
 
 /* Direct traps also mean that we need to know whenever the Guest wants to use
@@ -335,21 +336,22 @@ void pin_stack_pages(struct lguest *lg)
  *
  * In Linux each process has its own kernel stack, so this happens a lot: we
  * change stacks on each context switch. */
-void guest_set_stack(struct lguest *lg, u32 seg, u32 esp, unsigned int pages)
+void guest_set_stack(struct lguest_vcpu *vcpu, u32 seg, u32 esp,
+unsigned int pages)
 {
/* You are not allowed have a stack segment with privilege level 0: bad
 * Guest! */
if ((seg & 0x3) != GUEST_PL)
-   kill_guest(lg, "bad stack segment %i", seg);
+   kill_guest(vcpu->lg, "bad stack segment %i", seg);