lguest: PAE support
Subsystems (3)
PATCH 1/1 lguest: PAE support
Hi, this version requires that host and guest have the same PAE status. NX cap is not offered to the guest, yet.
Thanks,
Matias
Lguest PAE support
--- Documentation/lguest/lguest.txt | 1 - arch/x86/include/asm/lguest.h | 7 +- arch/x86/include/asm/lguest_hcall.h | 3 +- arch/x86/lguest/Kconfig | 1 - arch/x86/lguest/boot.c | 79 +++++++- drivers/lguest/Kconfig | 2 +- drivers/lguest/hypercalls.c | 10 + drivers/lguest/lg.h | 5 + drivers/lguest/page_tables.c | 356 +++++++++++++++++++++++++++++++---- 9 files changed, 410 insertions(+), 54 deletions(-)
Documentation/lguest/lguest.txt +0 -1
@@ -37,7 +37,6 @@ Running Lguest: "Paravirtualized guest support" = Y "Lguest guest support" = Y "High Memory Support" = off/4GB - "PAE (Physical Address Extension) Support" = N "Alignment value to which kernel should be aligned" = 0x100000 (CONFIG_PARAVIRT=y, CONFIG_LGUEST_GUEST=y, CONFIG_HIGHMEM64G=n and CONFIG_PHYSICAL_ALIGN=0x100000)
arch/x86/include/asm/lguest.h +6 -1
@@ -17,8 +17,13 @@/* Pages for switcher itself, then two pages per cpu */ #define TOTAL_SWITCHER_PAGES (SHARED_SWITCHER_PAGES + 2 * nr_cpu_ids) -/* We map at -4M for ease of mapping into the guest (one PTE page). */ +/* We map at -4M (-2M when PAE is activated) for ease of mapping +* into the guest (one PTE page). */ +#ifdef CONFIG_X86_PAE +#define SWITCHER_ADDR 0xFFE00000 +#else #define SWITCHER_ADDR 0xFFC00000 +#endif /* Found in switcher.S */ extern unsigned long default_idt_entries[];
arch/x86/include/asm/lguest_hcall.h +2 -1
@@ -12,6 +12,7 @@#define LHCALL_TS 8#define LHCALL_SET_CLOCKEVENT 9#define LHCALL_HALT 10 +#define LHCALL_SET_PMD 13#define LHCALL_SET_PTE 14#define LHCALL_SET_PGD 15#define LHCALL_LOAD_TLS 16
@@ -32,7 +33,7 @@* operations? There are two ways: the direct way is to make a "hypercall", * to make requests of the Host Itself. * -* We use the KVM hypercall mechanism. Eighteen hypercalls are +* We use the KVM hypercall mechanism. Sixteen hypercalls are * available: the hypercall number is put in the %eax register, and the * arguments (when required) are placed in %ebx, %ecx, %edx and %esi. * If a return value makes sense, it's returned in %eax.
arch/x86/lguest/Kconfig +0 -1
@@ -2,7 +2,6 @@ config LGUEST_GUEST bool "Lguest guest support" select PARAVIRT depends on X86_32 - depends on !X86_PAE select VIRTIO select VIRTIO_RING select VIRTIO_CONSOLE
arch/x86/lguest/boot.c +70 -9
144 lines not on this page · raw message
drivers/lguest/Kconfig +1 -1
@@ -1,6 +1,6 @@ config LGUEST tristate "Linux hypervisor example code" - depends on X86_32 && EXPERIMENTAL && !X86_PAE && FUTEX + depends on X86_32 && EXPERIMENTAL && FUTEX select HVC_DRIVER ---help--- This is a very simple module which allows you to run
drivers/lguest/hypercalls.c +10 -0
@@ -73,11 +73,21 @@ static void do_hcall(struct lg_cpu *cpu, struct hcall_args *args)guest_set_stack (cpu, args->arg1, args->arg2, args->arg3);break ;case LHCALL_SET_PTE : +#ifdef CONFIG_X86_PAE +guest_set_pte (cpu, args->arg1, args->arg2, +__pte (args->arg3 | (u64 )args->arg4 <<32 )); +#else guest_set_pte (cpu, args->arg1, args->arg2,__pte (args->arg3)); +#endif break ;case LHCALL_SET_PGD :guest_set_pgd (cpu->lg, args->arg1, args->arg2);break ; +#ifdef CONFIG_X86_PAE +case LHCALL_SET_PMD : +guest_set_pmd (cpu->lg, args->arg1, args->arg2); +break ; +#endif case LHCALL_SET_CLOCKEVENT :guest_set_clockevent (cpu, args->arg1);break ;
drivers/lguest/lg.h +5 -0
@@ -137,6 +137,8 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user);* in the kernel. */ #define pgd_flags (x) (pgd_val(x) & ~PAGE_MASK)#define pgd_pfn (x) (pgd_val(x) >> PAGE_SHIFT) +#define pmd_flags (x) (pmd_val(x) & ~PAGE_MASK) +#define pmd_pfn (x) (pmd_val(x) >> PAGE_SHIFT)/* interrupts_and_traps.c: */ void maybe_do_interrupt (struct lg_cpu *cpu);
@@ -169,6 +171,9 @@ int init_guest_pagetable(struct lguest *lg);void free_guest_pagetable (struct lguest *lg);void guest_new_pagetable (struct lg_cpu *cpu,unsigned long pgtable);void guest_set_pgd (struct lguest *lg,unsigned long gpgdir,u32 i); +#ifdef CONFIG_X86_PAE +void guest_set_pmd (struct lguest *lg,unsigned long gpgdir,u32 i); +#endif void guest_pagetable_clear_all (struct lg_cpu *cpu);void guest_pagetable_flush_user (struct lg_cpu *cpu); void guest_set_pte(struct lg_cpu *cpu, unsigned long gpgdir,
drivers/lguest/page_tables.c +316 -40
575 lines not on this page · raw message
Signature · 1 line
1.6.0.4
Rusty Russell
AppliedQuoted 2 lines · Matias Zabaljauregui
Hi, this version requires that host and guest have the same PAE status. NX cap is not offered to the guest, yet.
Thanks, applied!
I extracted the following parts for moving into your previous "native ops" patch:
arch/x86/lguest/boot.c +4 -4
@@ -519,7 +519,7 @@ static void lguest_pte_update(struct mm_static void lguest_set_pte_at (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pteval) { - *ptep = pteval; +native_set_pte (ptep, pteval);lguest_pte_update (mm, addr, ptep); }
@@ -528,9 +528,9 @@ static void lguest_set_pte_at(struct mm_* changed. */ static void lguest_set_pmd (pmd_t *pmdp,pmd_t pmdval) { - *pmdp = pmdval; +native_set_pmd (pmdp, pmdval);lazy_hcall2 (LHCALL_SET_PMD ,__pa (pmdp) &PAGE_MASK , - (__pa (pmdp) & (PAGE_SIZE -1 )) /4 ); + (__pa (pmdp) & (PAGE_SIZE -1 )) /sizeof (pmd_t)); }/* There are a couple of legacy places where the kernel sets a PTE, but we
@@ -544,7 +544,7 @@ static void lguest_set_pmd(pmd_t *pmdp,* which brings boot back to 0.25 seconds. */ static void lguest_set_pte (pte_t *ptep,pte_t pteval) { - *ptep = pteval; +native_set_pte (ptep, pteval);if (cr3_changed)lazy_hcall1 (LHCALL_FLUSH_TLB ,1 ); }
drivers/lguest/page_tables.c +3 -2
@@ -726,8 +726,9 @@ void map_switcher_in_guest(struct lg_cpu* page is already mapped there, we don't have to copy them out * again. */ pfn =__pa (cpu->regs_page) >>PAGE_SHIFT ; - regs_pte =pfn_pte (pfn,__pgprot (__PAGE_KERNEL)); - switcher_pte_page[(unsigned long )pages/PAGE_SIZE %PTRS_PER_PTE ] = regs_pte; +native_set_pte (®s_pte,pfn_pte (pfn,PAGE_KERNEL )); +native_set_pte (&switcher_pte_page[pte_index ((unsigned long )pages)], + regs_pte); }/*:*/
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 8 lines · Rusty Russell
Quoted 2 lines · Matias Zabaljauregui
Hi, this version requires that host and guest have the same PAE status. NX cap is not offered to the guest, yet.
Thanks, applied!
I extracted the following parts for moving into your previous "native ops" patch:
great, thank you (forgive my laziness)
Quoted 49 lines
arch/x86/lguest/boot.c +4
-4@@ -519,7 +519,7 @@ static void lguest_pte_update(struct mm_static void lguest_set_pte_at (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pteval) { - *ptep = pteval; +native_set_pte (ptep, pteval);lguest_pte_update (mm, addr, ptep); }@@ -528,9 +528,9 @@ static void lguest_set_pte_at(struct mm_* changed. */ static void lguest_set_pmd (pmd_t *pmdp,pmd_t pmdval) { - *pmdp = pmdval; +native_set_pmd (pmdp, pmdval);lazy_hcall2 (LHCALL_SET_PMD ,__pa (pmdp) &PAGE_MASK , - (__pa (pmdp) & (PAGE_SIZE -1 )) /4 ); + (__pa (pmdp) & (PAGE_SIZE -1 )) /sizeof (pmd_t)); }/* There are a couple of legacy places where the kernel sets a PTE, but we @@ -544,7 +544,7 @@ static void lguest_set_pmd(pmd_t *pmdp,* which brings boot back to 0.25 seconds. */ static void lguest_set_pte (pte_t *ptep,pte_t pteval) { - *ptep = pteval; +native_set_pte (ptep, pteval);if (cr3_changed)lazy_hcall1 (LHCALL_FLUSH_TLB ,1 ); }drivers/lguest/page_tables.c +3
-2@@ -726,8 +726,9 @@ void map_switcher_in_guest(struct lg_cpu* page is already mapped there, we don't have to copy them out * again. */ pfn =__pa (cpu->regs_page) >>PAGE_SHIFT ; - regs_pte =pfn_pte (pfn,__pgprot (__PAGE_KERNEL)); - switcher_pte_page[(unsigned long )pages/PAGE_SIZE %PTRS_PER_PTE ] = regs_pte; +native_set_pte (®s_pte,pfn_pte (pfn,PAGE_KERNEL )); +native_set_pte (&switcher_pte_page[pte_index ((unsigned long )pages)], + regs_pte); }/*:*/
A message that is not in the archive (sent off-list or not yet received): 1244397067.21275.33.camel@zetabook
Debugged why guest was crashing immediately with unhandled page fault, also fixed a potential future problem. Please review.
lguest: PAE fixes
1) j wasn't initialized in setup_pagetables, so they weren't set up for me causing immediate guest crashes.
2) gpte_addr should not re-read the pmd from the Guest. Especially not BUG_ON() based on the value. If we ever supported SMP guests, they could trigger that. And the Launcher could also trigger it (tho currently root-only).
drivers/lguest/page_tables.c +21 -17
@@ -154,26 +154,25 @@ static unsigned long gpmd_addr(pgd_t gpgBUG_ON (!(pgd_flags (gpgd) & _PAGE_PRESENT)); return gpage + pmd_index(vaddr) * sizeof(pmd_t); } -#endif static unsigned long gpte_addr (struct lg_cpu *cpu, +pmd_t gpmd,unsigned long vaddr) +{ +unsigned long gpage =pmd_pfn (gpmd) <<PAGE_SHIFT ; + +BUG_ON (!(pmd_flags (gpmd) & _PAGE_PRESENT)); +return gpage +pte_index (vaddr) *sizeof (pte_t); +} +#else +static unsigned long gpte_addr (struct lg_cpu *cpu,pgd_t gpgd,unsigned long vaddr) { -#ifdef CONFIG_X86_PAE -pmd_t gpmd; -#endif -unsigned long gpage; +unsigned long gpage =pgd_pfn (gpgd) <<PAGE_SHIFT ;BUG_ON (!(pgd_flags (gpgd) & _PAGE_PRESENT)); -#ifdef CONFIG_X86_PAE - gpmd =lgread (cpu,gpmd_addr (gpgd, vaddr), pmd_t); - gpage =pmd_pfn (gpmd) <<PAGE_SHIFT ; -BUG_ON (!(pmd_flags (gpmd) & _PAGE_PRESENT)); -#else - gpage =pgd_pfn (gpgd) <<PAGE_SHIFT ; -#endif return gpage +pte_index (vaddr) *sizeof (pte_t); } +#endif /*:*/ /*M:014 get_pfn is slow: we could probably try to grab batches of pages here as
@@ -339,10 +338,15 @@ bool demand_page(struct lg_cpu *cpu, uns* number in the shadow PMD is the page we just allocated. */ native_set_pmd(spmd, __pmd(__pa(ptepage) | pmd_flags(gpmd))); } -#endif + +/* OK, now we look at the lower level in the Guest page table: keep its +* address, because we might update it later. */ + gpte_ptr =gpte_addr (cpu, gpmd, vaddr); +#else /* OK, now we look at the lower level in the Guest page table: keep its * address, because we might update it later. */ gpte_ptr =gpte_addr (cpu, gpgd, vaddr); +#endif gpte =lgread (cpu, gpte_ptr, pte_t);/* If this page isn't in the Guest page tables, we can't page it in. */
@@ -522,7 +526,6 @@ unsigned long guest_pa(struct lg_cpu *cp {pgd_t gpgd;pte_t gpte; -#ifdef CONFIG_X86_PAE pmd_t gpmd;#endif
@@ -534,13 +537,14 @@ unsigned long guest_pa(struct lg_cpu *cpreturn -1UL ; } - gpte =lgread (cpu,gpte_addr (cpu, gpgd, vaddr), pte_t);#ifdef CONFIG_X86_PAE gpmd =lgread (cpu,gpmd_addr (gpgd, vaddr), pmd_t);if (!(pmd_flags (gpmd) & _PAGE_PRESENT))kill_guest (cpu,"Bad address %#lx" , vaddr); + gpte =lgread (cpu,gpte_addr (cpu, gpmd, vaddr), pte_t); +#else + gpte =lgread (cpu,gpte_addr (cpu, gpgd, vaddr), pte_t);#endif - gpte =lgread (cpu,gpte_addr (cpu, gpgd, vaddr), pte_t);if (!(pte_flags (gpte) & _PAGE_PRESENT))kill_guest (cpu,"Bad address %#lx" , vaddr);
@@ -847,7 +851,7 @@ static unsigned long setup_pagetables(st/* The top level points to the linear page table pages above. * We setup the identity and linear mappings here. */ #ifdef CONFIG_X86_PAE -for (i =0 , j; i < mapped_pages && j <PTRS_PER_PMD ; +for (i = j =0 ; i < mapped_pages && j <PTRS_PER_PMD ; i +=PTRS_PER_PTE , j++) {native_set_pmd (&pmd,__pmd (((unsigned long )(linear + i) - mem_base) | _PAGE_PRESENT | _PAGE_RW | _PAGE_USER));
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 7 lines · Rusty Russell
Debugged why guest was crashing immediately with unhandled page fault, also fixed a potential future problem. Please review.
lguest: PAE fixes
1) j wasn't initialized in
setup_pagetables, so they weren't set up for me causing immediate guest crashes.
Oops, don't understand how it worked on my test boxes all these days.
Quoted 6 lines
2)
gpte_addrshould not re-read the pmd from the Guest. Especially notBUG_ON()based on the value. If we ever supported SMP guests, they could trigger that. And the Launcher could also trigger it (tho currently root-only).
thanks for fixing this as well.
Matias
Quoted 95 lines
Signed-off-by Rusty Russell <[email protected]>drivers/lguest/page_tables.c +21
-17@@ -154,26 +154,25 @@ static unsigned long gpmd_addr(pgd_t gpgBUG_ON (!(pgd_flags (gpgd) & _PAGE_PRESENT)); return gpage + pmd_index(vaddr) * sizeof(pmd_t); } -#endif static unsigned long gpte_addr (struct lg_cpu *cpu, +pmd_t gpmd,unsigned long vaddr) +{ +unsigned long gpage =pmd_pfn (gpmd) <<PAGE_SHIFT ; + +BUG_ON (!(pmd_flags (gpmd) & _PAGE_PRESENT)); +return gpage +pte_index (vaddr) *sizeof (pte_t); +} +#else +static unsigned long gpte_addr (struct lg_cpu *cpu,pgd_t gpgd,unsigned long vaddr) { -#ifdef CONFIG_X86_PAE -pmd_t gpmd; -#endif -unsigned long gpage; +unsigned long gpage =pgd_pfn (gpgd) <<PAGE_SHIFT ;BUG_ON (!(pgd_flags (gpgd) & _PAGE_PRESENT)); -#ifdef CONFIG_X86_PAE - gpmd =lgread (cpu,gpmd_addr (gpgd, vaddr), pmd_t); - gpage =pmd_pfn (gpmd) <<PAGE_SHIFT ; -BUG_ON (!(pmd_flags (gpmd) & _PAGE_PRESENT)); -#else - gpage =pgd_pfn (gpgd) <<PAGE_SHIFT ; -#endif return gpage +pte_index (vaddr) *sizeof (pte_t); } +#endif /*:*/ /*M:014 get_pfn is slow: we could probably try to grab batches of pages here as @@ -339,10 +338,15 @@ bool demand_page(struct lg_cpu *cpu, uns* number in the shadow PMD is the page we just allocated. */ native_set_pmd(spmd, __pmd(__pa(ptepage) | pmd_flags(gpmd))); } -#endif + +/* OK, now we look at the lower level in the Guest page table: keep its +* address, because we might update it later. */ + gpte_ptr =gpte_addr (cpu, gpmd, vaddr); +#else /* OK, now we look at the lower level in the Guest page table: keep its * address, because we might update it later. */ gpte_ptr =gpte_addr (cpu, gpgd, vaddr); +#endif gpte =lgread (cpu, gpte_ptr, pte_t);/* If this page isn't in the Guest page tables, we can't page it in. */ @@ -522,7 +526,6 @@ unsigned long guest_pa(struct lg_cpu *cp {pgd_t gpgd;pte_t gpte; -#ifdef CONFIG_X86_PAE pmd_t gpmd;#endif @@ -534,13 +537,14 @@ unsigned long guest_pa(struct lg_cpu *cpreturn -1UL ; } - gpte =lgread (cpu,gpte_addr (cpu, gpgd, vaddr), pte_t);#ifdef CONFIG_X86_PAE gpmd =lgread (cpu,gpmd_addr (gpgd, vaddr), pmd_t);if (!(pmd_flags (gpmd) & _PAGE_PRESENT))kill_guest (cpu,"Bad address %#lx" , vaddr); + gpte =lgread (cpu,gpte_addr (cpu, gpmd, vaddr), pte_t); +#else + gpte =lgread (cpu,gpte_addr (cpu, gpgd, vaddr), pte_t);#endif - gpte =lgread (cpu,gpte_addr (cpu, gpgd, vaddr), pte_t);if (!(pte_flags (gpte) & _PAGE_PRESENT))kill_guest (cpu,"Bad address %#lx" , vaddr);@@ -847,7 +851,7 @@ static unsigned long setup_pagetables(st/* The top level points to the linear page table pages above. * We setup the identity and linear mappings here. */ #ifdef CONFIG_X86_PAE -for (i =0 , j; i < mapped_pages && j <PTRS_PER_PMD ; +for (i = j =0 ; i < mapped_pages && j <PTRS_PER_PMD ; i +=PTRS_PER_PTE , j++) {native_set_pmd (&pmd,__pmd (((unsigned long )(linear + i) - mem_base) | _PAGE_PRESENT | _PAGE_RW | _PAGE_USER));