lguest: makes special fields be per-vcpu
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 <gcosta@redhat.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Rusty Russell
parent
66686c2ab0
commit
4665ac8e28
@@ -60,7 +60,7 @@ static void do_hcall(struct lg_cpu *cpu, struct hcall_args *args)
|
|||||||
/* FLUSH_TLB comes in two flavors, depending on the
|
/* FLUSH_TLB comes in two flavors, depending on the
|
||||||
* argument: */
|
* argument: */
|
||||||
if (args->arg1)
|
if (args->arg1)
|
||||||
guest_pagetable_clear_all(lg);
|
guest_pagetable_clear_all(cpu);
|
||||||
else
|
else
|
||||||
guest_pagetable_flush_user(lg);
|
guest_pagetable_flush_user(lg);
|
||||||
break;
|
break;
|
||||||
@@ -68,10 +68,10 @@ static void do_hcall(struct lg_cpu *cpu, struct hcall_args *args)
|
|||||||
/* All these calls simply pass the arguments through to the right
|
/* All these calls simply pass the arguments through to the right
|
||||||
* routines. */
|
* routines. */
|
||||||
case LHCALL_NEW_PGTABLE:
|
case LHCALL_NEW_PGTABLE:
|
||||||
guest_new_pagetable(lg, args->arg1);
|
guest_new_pagetable(cpu, args->arg1);
|
||||||
break;
|
break;
|
||||||
case LHCALL_SET_STACK:
|
case LHCALL_SET_STACK:
|
||||||
guest_set_stack(lg, args->arg1, args->arg2, args->arg3);
|
guest_set_stack(cpu, args->arg1, args->arg2, args->arg3);
|
||||||
break;
|
break;
|
||||||
case LHCALL_SET_PTE:
|
case LHCALL_SET_PTE:
|
||||||
guest_set_pte(lg, args->arg1, args->arg2, __pte(args->arg3));
|
guest_set_pte(lg, args->arg1, args->arg2, __pte(args->arg3));
|
||||||
@@ -84,7 +84,7 @@ static void do_hcall(struct lg_cpu *cpu, struct hcall_args *args)
|
|||||||
break;
|
break;
|
||||||
case LHCALL_TS:
|
case LHCALL_TS:
|
||||||
/* This sets the TS flag, as we saw used in run_guest(). */
|
/* This sets the TS flag, as we saw used in run_guest(). */
|
||||||
lg->ts = args->arg1;
|
cpu->ts = args->arg1;
|
||||||
break;
|
break;
|
||||||
case LHCALL_HALT:
|
case LHCALL_HALT:
|
||||||
/* Similarly, this sets the halted flag for run_guest(). */
|
/* Similarly, this sets the halted flag for run_guest(). */
|
||||||
@@ -191,7 +191,7 @@ static void initialize(struct lg_cpu *cpu)
|
|||||||
* first write to a Guest page. This may have caused a copy-on-write
|
* 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
|
* fault, but the old page might be (read-only) in the Guest
|
||||||
* pagetable. */
|
* pagetable. */
|
||||||
guest_pagetable_clear_all(lg);
|
guest_pagetable_clear_all(cpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*H:100
|
/*H:100
|
||||||
|
@@ -73,8 +73,8 @@ static void set_guest_interrupt(struct lg_cpu *cpu, u32 lo, u32 hi, int has_err)
|
|||||||
if ((cpu->regs->ss&0x3) != GUEST_PL) {
|
if ((cpu->regs->ss&0x3) != GUEST_PL) {
|
||||||
/* The Guest told us their kernel stack with the SET_STACK
|
/* The Guest told us their kernel stack with the SET_STACK
|
||||||
* hypercall: both the virtual address and the segment */
|
* hypercall: both the virtual address and the segment */
|
||||||
virtstack = lg->esp1;
|
virtstack = cpu->esp1;
|
||||||
ss = lg->ss1;
|
ss = cpu->ss1;
|
||||||
|
|
||||||
origstack = gstack = guest_pa(lg, virtstack);
|
origstack = gstack = guest_pa(lg, virtstack);
|
||||||
/* We push the old stack segment and pointer onto the new
|
/* We push the old stack segment and pointer onto the new
|
||||||
@@ -311,10 +311,11 @@ static int direct_trap(unsigned int num)
|
|||||||
* the Guest.
|
* the Guest.
|
||||||
*
|
*
|
||||||
* Which is deeply unfair, because (literally!) it wasn't the Guests' fault. */
|
* 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_cpu *cpu)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
|
struct lguest *lg = cpu->lg;
|
||||||
/* Depending on the CONFIG_4KSTACKS option, the Guest can have one or
|
/* Depending on the CONFIG_4KSTACKS option, the Guest can have one or
|
||||||
* two pages of stack space. */
|
* two pages of stack space. */
|
||||||
for (i = 0; i < lg->stack_pages; i++)
|
for (i = 0; i < lg->stack_pages; i++)
|
||||||
@@ -322,7 +323,7 @@ void pin_stack_pages(struct lguest *lg)
|
|||||||
* start of the page after the kernel stack. Subtract one to
|
* start of the page after the kernel stack. Subtract one to
|
||||||
* get back onto the first stack page, and keep subtracting to
|
* get back onto the first stack page, and keep subtracting to
|
||||||
* get to the rest of the stack pages. */
|
* get to the rest of the stack pages. */
|
||||||
pin_page(lg, lg->esp1 - 1 - i * PAGE_SIZE);
|
pin_page(lg, cpu->esp1 - 1 - i * PAGE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Direct traps also mean that we need to know whenever the Guest wants to use
|
/* Direct traps also mean that we need to know whenever the Guest wants to use
|
||||||
@@ -333,21 +334,21 @@ void pin_stack_pages(struct lguest *lg)
|
|||||||
*
|
*
|
||||||
* In Linux each process has its own kernel stack, so this happens a lot: we
|
* In Linux each process has its own kernel stack, so this happens a lot: we
|
||||||
* change stacks on each context switch. */
|
* 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_cpu *cpu, u32 seg, u32 esp, unsigned int pages)
|
||||||
{
|
{
|
||||||
/* You are not allowed have a stack segment with privilege level 0: bad
|
/* You are not allowed have a stack segment with privilege level 0: bad
|
||||||
* Guest! */
|
* Guest! */
|
||||||
if ((seg & 0x3) != GUEST_PL)
|
if ((seg & 0x3) != GUEST_PL)
|
||||||
kill_guest(lg, "bad stack segment %i", seg);
|
kill_guest(cpu->lg, "bad stack segment %i", seg);
|
||||||
/* We only expect one or two stack pages. */
|
/* We only expect one or two stack pages. */
|
||||||
if (pages > 2)
|
if (pages > 2)
|
||||||
kill_guest(lg, "bad stack pages %u", pages);
|
kill_guest(cpu->lg, "bad stack pages %u", pages);
|
||||||
/* Save where the stack is, and how many pages */
|
/* Save where the stack is, and how many pages */
|
||||||
lg->ss1 = seg;
|
cpu->ss1 = seg;
|
||||||
lg->esp1 = esp;
|
cpu->esp1 = esp;
|
||||||
lg->stack_pages = pages;
|
cpu->lg->stack_pages = pages;
|
||||||
/* Make sure the new stack pages are mapped */
|
/* Make sure the new stack pages are mapped */
|
||||||
pin_stack_pages(lg);
|
pin_stack_pages(cpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* All this reference to mapping stacks leads us neatly into the other complex
|
/* All this reference to mapping stacks leads us neatly into the other complex
|
||||||
|
@@ -46,6 +46,11 @@ struct lg_cpu {
|
|||||||
struct task_struct *tsk;
|
struct task_struct *tsk;
|
||||||
struct mm_struct *mm; /* == tsk->mm, but that becomes NULL on exit */
|
struct mm_struct *mm; /* == tsk->mm, but that becomes NULL on exit */
|
||||||
|
|
||||||
|
u32 cr2;
|
||||||
|
int ts;
|
||||||
|
u32 esp1;
|
||||||
|
u8 ss1;
|
||||||
|
|
||||||
/* At end of a page shared mapped over lguest_pages in guest. */
|
/* At end of a page shared mapped over lguest_pages in guest. */
|
||||||
unsigned long regs_page;
|
unsigned long regs_page;
|
||||||
struct lguest_regs *regs;
|
struct lguest_regs *regs;
|
||||||
@@ -80,10 +85,6 @@ struct lguest
|
|||||||
* memory in the Launcher. */
|
* memory in the Launcher. */
|
||||||
void __user *mem_base;
|
void __user *mem_base;
|
||||||
unsigned long kernel_address;
|
unsigned long kernel_address;
|
||||||
u32 cr2;
|
|
||||||
int ts;
|
|
||||||
u32 esp1;
|
|
||||||
u8 ss1;
|
|
||||||
|
|
||||||
/* Bitmap of what has changed: see CHANGED_* above. */
|
/* Bitmap of what has changed: see CHANGED_* above. */
|
||||||
int changed;
|
int changed;
|
||||||
@@ -141,8 +142,8 @@ void maybe_do_interrupt(struct lg_cpu *cpu);
|
|||||||
int deliver_trap(struct lg_cpu *cpu, unsigned int num);
|
int deliver_trap(struct lg_cpu *cpu, unsigned int num);
|
||||||
void load_guest_idt_entry(struct lg_cpu *cpu, unsigned int i,
|
void load_guest_idt_entry(struct lg_cpu *cpu, unsigned int i,
|
||||||
u32 low, u32 hi);
|
u32 low, u32 hi);
|
||||||
void guest_set_stack(struct lguest *lg, u32 seg, u32 esp, unsigned int pages);
|
void guest_set_stack(struct lg_cpu *cpu, u32 seg, u32 esp, unsigned int pages);
|
||||||
void pin_stack_pages(struct lguest *lg);
|
void pin_stack_pages(struct lg_cpu *cpu);
|
||||||
void setup_default_idt_entries(struct lguest_ro_state *state,
|
void setup_default_idt_entries(struct lguest_ro_state *state,
|
||||||
const unsigned long *def);
|
const unsigned long *def);
|
||||||
void copy_traps(const struct lg_cpu *cpu, struct desc_struct *idt,
|
void copy_traps(const struct lg_cpu *cpu, struct desc_struct *idt,
|
||||||
@@ -164,9 +165,9 @@ void copy_gdt_tls(const struct lg_cpu *cpu, struct desc_struct *gdt);
|
|||||||
/* page_tables.c: */
|
/* page_tables.c: */
|
||||||
int init_guest_pagetable(struct lguest *lg, unsigned long pgtable);
|
int init_guest_pagetable(struct lguest *lg, unsigned long pgtable);
|
||||||
void free_guest_pagetable(struct lguest *lg);
|
void free_guest_pagetable(struct lguest *lg);
|
||||||
void guest_new_pagetable(struct lguest *lg, unsigned long pgtable);
|
void guest_new_pagetable(struct lg_cpu *cpu, unsigned long pgtable);
|
||||||
void guest_set_pmd(struct lguest *lg, unsigned long gpgdir, u32 i);
|
void guest_set_pmd(struct lguest *lg, unsigned long gpgdir, u32 i);
|
||||||
void guest_pagetable_clear_all(struct lguest *lg);
|
void guest_pagetable_clear_all(struct lg_cpu *cpu);
|
||||||
void guest_pagetable_flush_user(struct lguest *lg);
|
void guest_pagetable_flush_user(struct lguest *lg);
|
||||||
void guest_set_pte(struct lguest *lg, unsigned long gpgdir,
|
void guest_set_pte(struct lguest *lg, unsigned long gpgdir,
|
||||||
unsigned long vaddr, pte_t val);
|
unsigned long vaddr, pte_t val);
|
||||||
|
@@ -432,9 +432,10 @@ static unsigned int new_pgdir(struct lguest *lg,
|
|||||||
* Now we've seen all the page table setting and manipulation, let's see what
|
* Now we've seen all the page table setting and manipulation, let's see what
|
||||||
* what happens when the Guest changes page tables (ie. changes the top-level
|
* what happens when the Guest changes page tables (ie. changes the top-level
|
||||||
* pgdir). This occurs on almost every context switch. */
|
* pgdir). This occurs on almost every context switch. */
|
||||||
void guest_new_pagetable(struct lguest *lg, unsigned long pgtable)
|
void guest_new_pagetable(struct lg_cpu *cpu, unsigned long pgtable)
|
||||||
{
|
{
|
||||||
int newpgdir, repin = 0;
|
int newpgdir, repin = 0;
|
||||||
|
struct lguest *lg = cpu->lg;
|
||||||
|
|
||||||
/* Look to see if we have this one already. */
|
/* Look to see if we have this one already. */
|
||||||
newpgdir = find_pgdir(lg, pgtable);
|
newpgdir = find_pgdir(lg, pgtable);
|
||||||
@@ -446,7 +447,7 @@ void guest_new_pagetable(struct lguest *lg, unsigned long pgtable)
|
|||||||
lg->pgdidx = newpgdir;
|
lg->pgdidx = newpgdir;
|
||||||
/* If it was completely blank, we map in the Guest kernel stack */
|
/* If it was completely blank, we map in the Guest kernel stack */
|
||||||
if (repin)
|
if (repin)
|
||||||
pin_stack_pages(lg);
|
pin_stack_pages(cpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*H:470 Finally, a routine which throws away everything: all PGD entries in all
|
/*H:470 Finally, a routine which throws away everything: all PGD entries in all
|
||||||
@@ -468,11 +469,11 @@ static void release_all_pagetables(struct lguest *lg)
|
|||||||
* mapping. Since kernel mappings are in every page table, it's easiest to
|
* mapping. Since kernel mappings are in every page table, it's easiest to
|
||||||
* throw them all away. This traps the Guest in amber for a while as
|
* throw them all away. This traps the Guest in amber for a while as
|
||||||
* everything faults back in, but it's rare. */
|
* everything faults back in, but it's rare. */
|
||||||
void guest_pagetable_clear_all(struct lguest *lg)
|
void guest_pagetable_clear_all(struct lg_cpu *cpu)
|
||||||
{
|
{
|
||||||
release_all_pagetables(lg);
|
release_all_pagetables(cpu->lg);
|
||||||
/* We need the Guest kernel stack mapped again. */
|
/* We need the Guest kernel stack mapped again. */
|
||||||
pin_stack_pages(lg);
|
pin_stack_pages(cpu);
|
||||||
}
|
}
|
||||||
/*:*/
|
/*:*/
|
||||||
/*M:009 Since we throw away all mappings when a kernel mapping changes, our
|
/*M:009 Since we throw away all mappings when a kernel mapping changes, our
|
||||||
|
@@ -95,8 +95,8 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
|
|||||||
/* Set up the two "TSS" members which tell the CPU what stack to use
|
/* Set up the two "TSS" members which tell the CPU what stack to use
|
||||||
* for traps which do directly into the Guest (ie. traps at privilege
|
* for traps which do directly into the Guest (ie. traps at privilege
|
||||||
* level 1). */
|
* level 1). */
|
||||||
pages->state.guest_tss.esp1 = lg->esp1;
|
pages->state.guest_tss.esp1 = cpu->esp1;
|
||||||
pages->state.guest_tss.ss1 = lg->ss1;
|
pages->state.guest_tss.ss1 = cpu->ss1;
|
||||||
|
|
||||||
/* Copy direct-to-Guest trap entries. */
|
/* Copy direct-to-Guest trap entries. */
|
||||||
if (lg->changed & CHANGED_IDT)
|
if (lg->changed & CHANGED_IDT)
|
||||||
@@ -165,12 +165,10 @@ static void run_guest_once(struct lg_cpu *cpu, struct lguest_pages *pages)
|
|||||||
* are disabled: we own the CPU. */
|
* are disabled: we own the CPU. */
|
||||||
void lguest_arch_run_guest(struct lg_cpu *cpu)
|
void lguest_arch_run_guest(struct lg_cpu *cpu)
|
||||||
{
|
{
|
||||||
struct lguest *lg = cpu->lg;
|
|
||||||
|
|
||||||
/* Remember the awfully-named TS bit? If the Guest has asked to set it
|
/* Remember the awfully-named TS bit? If the Guest has asked to set it
|
||||||
* we set it now, so we can trap and pass that trap to the Guest if it
|
* we set it now, so we can trap and pass that trap to the Guest if it
|
||||||
* uses the FPU. */
|
* uses the FPU. */
|
||||||
if (lg->ts)
|
if (cpu->ts)
|
||||||
lguest_set_ts();
|
lguest_set_ts();
|
||||||
|
|
||||||
/* SYSENTER is an optimized way of doing system calls. We can't allow
|
/* SYSENTER is an optimized way of doing system calls. We can't allow
|
||||||
@@ -325,7 +323,7 @@ void lguest_arch_handle_trap(struct lg_cpu *cpu)
|
|||||||
/* If the Guest doesn't want to know, we already restored the
|
/* If the Guest doesn't want to know, we already restored the
|
||||||
* Floating Point Unit, so we just continue without telling
|
* Floating Point Unit, so we just continue without telling
|
||||||
* it. */
|
* it. */
|
||||||
if (!lg->ts)
|
if (!cpu->ts)
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 32 ... 255:
|
case 32 ... 255:
|
||||||
|
Reference in New Issue
Block a user