Xen-paravirt: Xen guest implementation for paravirt_ops interface
Subsystems (14)
cover Xen-paravirt: Xen guest implementation for paravirt_ops interface
Hi Andi,
This patch series implements the Linux Xen guest in terms of the paravirt-ops interface. The features in implemented this patch series are:
* domU only
* UP only (most code is SMP-safe, but there's no way to create a new vcpu)
* writable pagetables, with late pinning/early unpinning
(no shadow pagetable support)
* supports both PAE and non-PAE modes
* xen console
* virtual block device (blockfront)
* virtual network device (netfront)
The patch series is in two parts:
1-12: cleanups to the core kernel, either to fix outright problems,
or to add appropriate hooks for Xen
13-21: the Xen guest implementation itself
I've tried to make each patch as self-explanatory as possible. The series is based on git changeset ec2f9d1331f658433411c58077871e1eef4ee1b4 + x86_64-2.6.20-git8-070213-1.patch.
Changes since the previous posting:
- rebased
- addressed review comments:
- deal with missing vga hardware better
- deal with Andi's comments
- clean up header file placement
- update netfront, and move it into drivers/net
I looked at linking in xen-head.S rather than including it into xen-head.S, but it seems to provoke linker bugs, so I've left it as-is for now.
Thanks,
J
PATCH 1/21 Xen-paravirt: Fix typo in sync_constant_test_bit()s name.
===================================================================
include/asm-i386/sync_bitops.h +1 -1
@@ -130,7 +130,7 @@ static inline int sync_test_and_change_breturn oldbit; } -static __always_inline int sync_const_test_bit(int nr, const volatile unsigned long *addr) +static __always_inline int sync_constant_test_bit(int nr, const volatile unsigned long *addr) {return ((1UL << (nr &31 )) & (((const volatile unsigned int *)addr)[nr >>5 ])) !=0 ;
PATCH 2/21 Xen-paravirt: ignore vgacon if hardware not present
In reply to Jeremy Fitzhardinge===================================================================
drivers/video/console/vgacon.c +2 -1
@@ -372,7 +372,8 @@ static const char *vgacon_startup(void) }/* VGA16 modes are not handled by VGACON */ - if ((ORIG_VIDEO_MODE == 0x0D) || /* 320x200/4 */ + if ((ORIG_VIDEO_MODE == 0x00) || /* SCREEN_INFO not initialized */ + (ORIG_VIDEO_MODE == 0x0D) || /* 320x200/4 */ (ORIG_VIDEO_MODE == 0x0E) || /* 640x200/4 */ (ORIG_VIDEO_MODE == 0x10) || /* 640x350/4 */ (ORIG_VIDEO_MODE == 0x12) || /* 640x480/4 */
PATCH 3/21 Xen-paravirt: Add pagetable accessors to pack and unpack pagetable entries
In reply to Jeremy FitzhardingeAdd a set of accessors to pack, unpack and modify page table entries (at all levels). This allows a paravirt implementation to control the contents of pgd/pmd/pte entries. For example, Xen uses this to convert the (pseudo-)physical address into a machine address when populating a pagetable entry, and converting back to pphys address when an entry is read.
--
arch/i386/kernel/paravirt.c | 113 ++++++++++++++++++++++++++++++++---- arch/i386/kernel/vmlinux.lds.S | 3 include/asm-i386/page.h | 18 ++++- include/asm-i386/paravirt.h | 68 +++++++++++++++++++++ include/asm-i386/pgtable-2level.h | 5 - include/asm-i386/pgtable-3level.h | 27 ++++---- 6 files changed, 199 insertions(+), 35 deletions(-)
===================================================================
arch/i386/kernel/paravirt.c +104 -12
@@ -34,7 +34,7 @@#include <asm/tlbflush.h> /* nop stub */ -static void native_nop (void ) +void native_nop (void ) { }
@@ -400,38 +400,76 @@ static void native_flush_tlb_single(u32 }#ifndef CONFIG_X86_PAE -static void native_set_pte (pte_t *ptep,pte_t pteval) +void native_set_pte (pte_t *ptep,pte_t pteval) { *ptep = pteval; } -static void native_set_pte_at (struct mm_struct *mm,u32 addr,pte_t *ptep,pte_t pteval) +void native_set_pte_at (struct mm_struct *mm,u32 addr, +pte_t *ptep,pte_t pteval) { *ptep = pteval; } -static void native_set_pmd (pmd_t *pmdp,pmd_t pmdval) +void native_set_pmd (pmd_t *pmdp,pmd_t pmdval) { *pmdp = pmdval; } +unsigned long native_pte_val (pte_t pte) +{ +return pte.pte_low; +} + +unsigned long native_pmd_val (pmd_t pmd) +{ +BUG (); +return 0 ; +} + +unsigned long native_pgd_val (pgd_t pgd) +{ +return pgd.pgd; +} + +pte_t native_make_pte (unsigned long pte) +{ +return (pte_t ){ pte }; +} + +pmd_t native_make_pmd (unsigned long pmd) +{ +BUG (); +} + +pgd_t native_make_pgd (unsigned long pgd) +{ +return (pgd_t ){ pgd }; +} + +pte_t native_ptep_get_and_clear (pte_t *ptep) +{ +return __pte (xchg (&(ptep)->pte_low,0 )); +} +#else /* CONFIG_X86_PAE */ -static void native_set_pte (pte_t *ptep,pte_t pte) +void native_set_pte (pte_t *ptep,pte_t pte) { ptep->pte_high = pte.pte_high;smp_wmb (); ptep->pte_low = pte.pte_low; } -static void native_set_pte_at (struct mm_struct *mm,u32 addr,pte_t *ptep,pte_t pte) +void native_set_pte_at (struct mm_struct *mm,u32 addr,pte_t *ptep,pte_t pte) { ptep->pte_high = pte.pte_high;smp_wmb (); ptep->pte_low = pte.pte_low; } -static void native_set_pte_present (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pte) +void native_set_pte_present (struct mm_struct *mm,u32 addr, +pte_t *ptep,pte_t pte) { ptep->pte_low =0 ;smp_wmb ();
@@ -440,35 +478,78 @@ static void native_set_pte_present(struc ptep->pte_low = pte.pte_low; } -static void native_set_pte_atomic (pte_t *ptep,pte_t pteval) +void native_set_pte_atomic (pte_t *ptep,pte_t pteval) {set_64bit ((unsigned long long *)ptep,pte_val (pteval)); } -static void native_set_pmd (pmd_t *pmdp,pmd_t pmdval) +void native_set_pmd (pmd_t *pmdp,pmd_t pmdval) {set_64bit ((unsigned long long *)pmdp,pmd_val (pmdval)); } -static void native_set_pud (pud_t *pudp,pud_t pudval) +void native_set_pud (pud_t *pudp,pud_t pudval) { *pudp = pudval; } -static void native_pte_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep) +void native_pte_clear (struct mm_struct *mm,u32 addr,pte_t *ptep) { ptep->pte_low =0 ;smp_wmb (); ptep->pte_high =0 ; } -static void native_pmd_clear (pmd_t *pmd) +void native_pmd_clear (pmd_t *pmd) {u32 *tmp = (u32 *)pmd; *tmp =0 ;smp_wmb (); *(tmp +1 ) =0 ; } + +unsigned long long native_pte_val (pte_t pte) +{ +return pte.pte_low | ((unsigned long long )pte.pte_high <<32 ); +} + +unsigned long long native_pmd_val (pmd_t pmd) +{ +return pmd.pmd; +} + +unsigned long long native_pgd_val (pgd_t pgd) +{ +return pgd.pgd; +} + +pte_t native_make_pte (unsigned long long pte) +{ +return (pte_t ){ pte }; +} + +pmd_t native_make_pmd (unsigned long long pmd) +{ +return (pmd_t ){ pmd }; +} + +pgd_t native_make_pgd (unsigned long long pgd) +{ +return (pgd_t ){ pgd }; +} + +pte_t native_ptep_get_and_clear (pte_t *ptep) +{ +pte_t res; + +/* xchg acts as a barrier before the setting of the high bits */ + res.pte_low =xchg (&ptep->pte_low,0 ); + res.pte_high = ptep->pte_high; + ptep->pte_high =0 ; + +return res; +} +#endif /* CONFIG_X86_PAE */ /* These are in entry.S */
@@ -561,6 +642,9 @@ struct paravirt_ops paravirt_ops = { .set_pmd = native_set_pmd, .pte_update = (void *)native_nop, .pte_update_defer = (void *)native_nop, + + .ptep_get_and_clear = native_ptep_get_and_clear, + #ifdef CONFIG_X86_PAE .set_pte_atomic = native_set_pte_atomic, .set_pte_present = native_set_pte_present,
@@ -569,6 +653,14 @@ struct paravirt_ops paravirt_ops = { .pmd_clear = native_pmd_clear, #endif + .pte_val = native_pte_val, + .pmd_val = native_pmd_val, + .pgd_val = native_pgd_val, + + .make_pte = native_make_pte, + .make_pmd = native_make_pmd, + .make_pgd = native_make_pgd, + .irq_enable_sysexit = native_irq_enable_sysexit, .iret = native_iret,
===================================================================
arch/i386/kernel/vmlinux.lds.S +3 -0
@@ -21,6 +21,9 @@ #include <asm/page.h> #include <asm/cache.h> #include <asm/boot.h> + +#undef ENTRY +#undef ALIGN OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") OUTPUT_ARCH(i386)
===================================================================
include/asm-i386/page.h +14 -4
@@ -11,7 +11,6 @@#ifdef __KERNEL__#ifndef __ASSEMBLY__ -#ifdef CONFIG_X86_USE_3DNOW
@@ -48,9 +47,11 @@ typedef struct { unsigned long long pmd;typedef struct {unsigned long long pmd; }pmd_t ;typedef struct {unsigned long long pgd; }pgd_t ;typedef struct {unsigned long long pgprot; }pgprot_t ; +#ifndef CONFIG_PARAVIRT #define pmd_val (x) ((x).pmd)#define pte_val (x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))#define __pmd (x) ((pmd_t) { (x) } ) +#endif /* CONFIG_PARAVIRT */ #define HPAGE_SHIFT 21#include <asm-generic/pgtable-nopud.h> #else
@@ -58,7 +59,9 @@ typedef struct { unsigned long pgd; } pgtypedef struct {unsigned long pgd; }pgd_t ;typedef struct {unsigned long pgprot; }pgprot_t ;#define boot_pte_t pte_t/* or would you rather have a typedef */ +#ifndef CONFIG_PARAVIRT #define pte_val (x) ((x).pte_low) +#endif #define HPAGE_SHIFT 22#include <asm-generic/pgtable-nopmd.h> #endif
@@ -71,12 +74,14 @@ typedef struct { unsigned long pgprot; }#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA #endif +#define pgprot_val (x) ((x).pgprot) +#define __pgprot (x) ((pgprot_t) { (x) } ) + +#ifndef CONFIG_PARAVIRT #define pgd_val (x) ((x).pgd) -#define pgprot_val (x) ((x).pgprot) -#define __pte (x) ((pte_t) { (x) } )#define __pgd (x) ((pgd_t) { (x) } ) -#define __pgprot (x) ((pgprot_t) { (x) } ) +#endif #endif /* !__ASSEMBLY__ */
@@ -143,6 +148,11 @@ extern int page_is_ram(unsigned long pag#include <asm-generic/memory_model.h> #include <asm-generic/page.h> +#ifdef CONFIG_PARAVIRT +/* After pte_t, etc, have been defined */ +#include <asm/paravirt.h> +#endif +#ifndef CONFIG_COMPAT_VDSO #define __HAVE_ARCH_GATE_AREA 1#endif
===================================================================
include/asm-i386/paravirt.h +66 -2
108 lines not on this page · raw message
===================================================================
include/asm-i386/pgtable-2level.h +2 -3
@@ -15,6 +15,7 @@#define set_pte (pteptr, pteval) (*(pteptr) = pteval)#define set_pte_at (mm,addr,ptep,pteval) set_pte(ptep,pteval)#define set_pmd (pmdptr, pmdval) (*(pmdptr) = (pmdval)) +#define raw_ptep_get_and_clear (xp) __pte(xchg(&(xp)->pte_low, 0))#endif #define set_pte_atomic (pteptr, pteval) set_pte(pteptr,pteval)
@@ -23,11 +24,9 @@#define pte_clear (mm,addr,xp) do { set_pte_at(mm, addr, xp, __pte(0)); } while (0)#define pmd_clear (xp) do { set_pmd(xp, __pmd(0)); } while (0) -#define raw_ptep_get_and_clear (xp) __pte(xchg(&(xp)->pte_low, 0)) -#define pte_page (x) pfn_to_page(pte_pfn(x))#define pte_none (x) (!(x).pte_low) -#define pte_pfn (x) ((unsigned long)(((x).pte_low >> PAGE_SHIFT))) +#define pte_pfn (x) (pte_val(x) >> PAGE_SHIFT)#define pfn_pte (pfn, prot) __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))#define pfn_pmd (pfn, prot) __pmd(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
===================================================================
include/asm-i386/pgtable-3level.h +13 -14
@@ -98,6 +98,18 @@ static inline void pmd_clear(pmd_t *pmd)smp_wmb (); *(tmp + 1) = 0; } + +static inline pte_t raw_ptep_get_and_clear (pte_t *ptep) +{ +pte_t res; + +/* xchg acts as a barrier before the setting of the high bits */ + res.pte_low =xchg (&ptep->pte_low,0 ); + res.pte_high = ptep->pte_high; + ptep->pte_high =0 ; + +return res; +}#endif /*
@@ -119,18 +131,6 @@ static inline void pud_clear (pud_t * pu#define pmd_offset (pud, address) ((pmd_t *) pud_page(*(pud)) + \ pmd_index(address)) -static inline pte_t raw_ptep_get_and_clear (pte_t *ptep) -{ -pte_t res; - -/* xchg acts as a barrier before the setting of the high bits */ - res.pte_low =xchg (&ptep->pte_low,0 ); - res.pte_high = ptep->pte_high; - ptep->pte_high =0 ; - -return res; -} -#define __HAVE_ARCH_PTE_SAMEstatic inline int pte_same (pte_t a,pte_t b) {
@@ -146,8 +146,7 @@ static inline int pte_none(pte_t pte)static inline unsigned long pte_pfn (pte_t pte) { -return (pte.pte_low >>PAGE_SHIFT ) | - (pte.pte_high << (32 -PAGE_SHIFT )); +return pte_val (pte) >>PAGE_SHIFT ; }extern unsigned long long __supported_pte_mask;
PATCH 4/21 Xen-paravirt: ===================================================================
In reply to Jeremy Fitzhardinge-static void vmi_set_pte_present(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) +static void vmi_set_pte_present(struct mm_struct *mm, u32 addr, pte_t *ptep, pte_t pte)
{
vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE); vmi_ops.set_pte(pte, ptep, vmi_flags_addr_defer(mm, addr, VMI_PAGE_PT, 1));
@@ -492,7 +492,7 @@ static void vmi_set_pud(pud_t *pudp, pud
vmi_ops.set_pte(pte, (pte_t *)pudp, VMI_PAGE_PDP);
}
-static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) +static void vmi_pte_clear(struct mm_struct *mm, u32 addr, pte_t *ptep)
{
const pte_t pte = { 0 };
vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE);
Re: [patch 04/21] Xen-paravirt: ===================================================================
Subject? description?
Review
Quoted 2 lines · Jeremy Fitzhardinge
(quoted diff) +1
-1-static void vmi_set_pte_present(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) +static void vmi_set_pte_present(struct mm_struct *mm, u32 addr, pte_t *ptep, pte_t pte)
And what good is that change anyways? unsigned long is the usual style for addresses.
-Andi
Re: [patch 04/21] Xen-paravirt: ===================================================================
Quoted 11 lines · Andi Kleen
Subject? description?
Review
Quoted 3 lines · Jeremy Fitzhardinge
(quoted diff) +1
-1-static void vmi_set_pte_present(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) +static void vmi_set_pte_present(struct mm_struct *mm, u32 addr, pte_t *ptep, pte_t pte)And what good is that change anyways? unsigned long is the usual style for addresses.
There was a fair amount of inconsistency. In this case, u32 was being used for existing functions dealing with addresses, and I propagated it through. I can switch it all back to unsigned long if you'd prefer.
J
PATCH 5/21 Xen-paravirt: paravirt_ops: hooks to set up initial pagetable
In reply to Jeremy FitzhardingeThis patch introduces paravirt_ops hooks to control how the kernel's initial pagetable is set up.
In the case of a native boot, the very early bootstrap code creates a simple non-PAE pagetable to map the kernel and physical memory. When the VM subsystem is initialized, it creates a proper pagetable which respects the PAE mode, large pages, etc.
When booting under a hypervisor, there are many possibilities for what paging environment the hypervisor establishes for the guest kernel, so the constructon of the kernel's pagetable depends on the hypervisor.
In the case of Xen, the hypervisor boots the kernel with a fully constructed pagetable, which is already using PAE if necessary. Also, Xen requires particular care when constructing pagetables to make sure all pagetables are always mapped read-only.
In order to make this easier, kernel's initial pagetable construction has been changed to only allocate and initialize a pagetable page if there's no page already present in the pagetable. This allows the Xen paravirt backend to make a copy of the hypervisor-provided pagetable, allowing the kernel to establish any more mappings it needs while keeping the existing ones.
A slightly subtle point which is worth highlighting here is that Xen requires all kernel mappings to share the same pte_t pages between all pagetables, so that updating a kernel page's mapping in one pagetable is reflected in all other pagetables. This makes it possible to allocate a page and attach it to a pagetable without having to explicitly enumerate that page's mapping in all pagetables.
--
arch/i386/kernel/paravirt.c | 40 ++++++++++++++++++ arch/i386/mm/init.c | 89 +++++++++++++++++++++++++----------------- include/asm-i386/paravirt.h | 54 +++++++++++++++++++++++++ include/asm-i386/pgtable.h | 3 + 4 files changed, 150 insertions(+), 36 deletions(-)
===================================================================
arch/i386/kernel/paravirt.c +40 -0
@@ -379,6 +379,43 @@ static void native_io_delay(void) { asmvolatile ("outb %al,$0x80" ); } + +void native_pagetable_setup_start (pgd_t *base) +{ +#ifdef CONFIG_X86_PAE +int i; + +/* +* Init entries of the first-level page table to the +* zero page, if they haven't already been set up. +* +* In a normal native boot, we'll be running on a +* pagetable rooted in swapper_pg_dir, but not in PAE +* mode, so this will end up clobbering the mappings +* for the lower 24Mbytes of the address space, +* without affecting the kernel address space. +*/ +for (i =0 ; i <USER_PTRS_PER_PGD ; i++) +set_pgd (&base[i], +__pgd (__pa (empty_zero_page) | _PAGE_PRESENT)); +memset (&base[USER_PTRS_PER_PGD ],0 ,sizeof (pgd_t)); +#endif +} + +void native_pagetable_setup_done (pgd_t *base) +{ +#ifdef CONFIG_X86_PAE +/* +* Add low memory identity-mappings - SMP needs it when +* starting up on an AP from real-mode. In the non-PAE +* case we already have these mappings through head.S. +* All user-space mappings are explicitly cleared after +* SMP startup. +*/ +set_pgd (&base[0 ], base[USER_PTRS_PER_PGD ]); +#endif +} +static void native_flush_tlb (void ) {
@@ -627,6 +664,9 @@ struct paravirt_ops paravirt_ops = {#endif .set_lazy_mode = (void *)native_nop, + .pagetable_setup_start = native_pagetable_setup_start, + .pagetable_setup_done = native_pagetable_setup_done, + .flush_tlb_user = native_flush_tlb, .flush_tlb_kernel = native_flush_tlb_global, .flush_tlb_single = native_flush_tlb_single,
===================================================================
arch/i386/mm/init.c +53 -36
150 lines not on this page · raw message
===================================================================
include/asm-i386/paravirt.h +54 -0
77 lines not on this page · raw message
===================================================================
include/asm-i386/pgtable.h +3 -0
@@ -15,7 +15,10 @@#include <asm/processor.h> #include <asm/fixmap.h> #include <linux/threads.h> + +#ifdef CONFIG_PARAVIRT /* guarded to prevent cyclic dependency */ #include <asm/paravirt.h> +#endif #ifndef _I386_BITOPS_H#include <asm/bitops.h>
PATCH 6/21 Xen-paravirt: paravirt_ops: allocate a fixmap slot
In reply to Jeremy FitzhardingeAllocate a fixmap slot for use by a paravirt_ops implementation. Xen uses this to map the hypervisor's shared info page, which doesn't have a pseudo-physical page number, and therefore can't be mapped ordinarily.
--
include/asm-i386/fixmap.h | 3 +++ 1 file changed, 3 insertions(+)
===================================================================
include/asm-i386/fixmap.h +3 -0
@@ -86,6 +86,9 @@ enum fixed_addresses {#ifdef CONFIG_PCI_MMCONFIG FIX_PCIE_MCFG,#endif +#ifdef CONFIG_PARAVIRT + FIX_PARAVIRT, +#endif __end_of_permanent_fixed_addresses,/* temporary boot-time mappings, used before ioremap() is functional */ #define NR_FIX_BTMAPS 16
PATCH 7/21 Xen-paravirt: remove ctor for pgd cache
In reply to Jeremy FitzhardingeRemove the ctor for the pgd cache. There's no point in having the cache machinery do this via an indirect call when all pgd are freed in the one place anyway.
===================================================================
arch/i386/mm/init.c +3 -5
@@ -739,11 +739,9 @@ void __init pgtable_cache_init(void)panic ("pgtable_cache_init(): cannot create pmd cache" ); } pgd_cache =kmem_cache_create ("pgd" , -PTRS_PER_PGD *sizeof (pgd_t), -PTRS_PER_PGD *sizeof (pgd_t), -0 , - pgd_ctor, -PTRS_PER_PMD ==1 ? pgd_dtor :NULL ); +PTRS_PER_PGD *sizeof (pgd_t), +PTRS_PER_PGD *sizeof (pgd_t), +0 ,NULL ,NULL );if (!pgd_cache)panic ("pgtable_cache_init(): Cannot create pgd cache" ); }
===================================================================
arch/i386/mm/pgtable.c +11 -4
@@ -236,7 +236,7 @@ static inline void pgd_list_del(pgd_t *pset_page_private (next, (unsigned long )pprev); } -void pgd_ctor (void *pgd,struct kmem_cache *cache,unsigned long unused) +static void pgd_ctor (pgd_t *pgd) {unsigned long flags;
@@ -245,7 +245,7 @@ void pgd_ctor(void *pgd, struct kmem_cacspin_lock_irqsave (&pgd_lock, flags); } -clone_pgd_range ((pgd_t *)pgd +USER_PTRS_PER_PGD , +clone_pgd_range (pgd +USER_PTRS_PER_PGD , swapper_pg_dir +USER_PTRS_PER_PGD ,KERNEL_PGD_PTRS );
@@ -261,10 +261,12 @@ void pgd_ctor(void *pgd, struct kmem_cacspin_unlock_irqrestore (&pgd_lock, flags); } -/* never called when PTRS_PER_PMD > 1 */ -void pgd_dtor (void *pgd,struct kmem_cache *cache,unsigned long unused) +static void pgd_dtor (pgd_t *pgd) {unsigned long flags;/* can be called from interrupt context */ + +if (PTRS_PER_PMD ==1 ) +return ;paravirt_release_pd (__pa (pgd) >>PAGE_SHIFT );spin_lock_irqsave (&pgd_lock, flags);
@@ -276,6 +278,9 @@ pgd_t *pgd_alloc(struct mm_struct *mm) {int i;pgd_t *pgd =kmem_cache_alloc (pgd_cache,GFP_KERNEL ); + +if (pgd) +pgd_ctor (pgd);if (PTRS_PER_PMD ==1 || !pgd)return pgd;
@@ -296,6 +301,7 @@ out_oom:paravirt_release_pd (__pa (pmd) >>PAGE_SHIFT );kmem_cache_free (pmd_cache, pmd); } +pgd_dtor (pgd);kmem_cache_free (pgd_cache, pgd);return NULL ; }
@@ -313,5 +319,6 @@ void pgd_free(pgd_t *pgd)kmem_cache_free (pmd_cache, pmd); }/* in the non-PAE case, free_pgtables() clears user pgd entries */ +pgd_dtor (pgd);kmem_cache_free (pgd_cache, pgd); }
===================================================================
include/asm-i386/pgtable.h +0 -2
@@ -41,8 +41,6 @@ extern struct page *pgd_list;extern struct page *pgd_list;void pmd_ctor (void *,struct kmem_cache *,unsigned long ); -void pgd_ctor (void *,struct kmem_cache *,unsigned long ); -void pgd_dtor (void *,struct kmem_cache *,unsigned long );void pgtable_cache_init (void );void paging_init (void );
Re: [patch 07/21] Xen-paravirt: remove ctor for pgd cache
Quoted 6 lines · Jeremy Fitzhardinge
Remove the ctor for the pgd cache. There's no point in having the cache machinery do this via an indirect call when all pgd are freed in the one place anyway.
Signed-off-by Jeremy Fitzhardinge <[email protected]>
This does introduce a bug for us, but that is trivially fixed, and I would like to inspect final merged code to make sure bugfix is proper.
Zach
Re: [patch 07/21] Xen-paravirt: remove ctor for pgd cache
In reply to Jeremy FitzhardingeQuoted 3 lines · Jeremy Fitzhardinge
Remove the ctor for the pgd cache. There's no point in having the cache machinery do this via an indirect call when all pgd are freed in the one place anyway.
The reason we have slab constructors and destructors is to _avoid_ reinitializing every time we allocate an object. AFAICT your changing the code now to do _more_ work than before, so is there some other reason why you want to do this than avoiding an indirect call?
Re: [patch 07/21] Xen-paravirt: remove ctor for pgd cache
Quoted 11 lines · Pekka Enberg
Quoted 3 lines · Jeremy Fitzhardinge
Remove the ctor for the pgd cache. There's no point in having the cache machinery do this via an indirect call when all pgd are freed in the one place anyway.
The reason we have slab constructors and destructors is to _avoid_ reinitializing every time we allocate an object. AFAICT your changing the code now to do _more_ work than before, so is there some other reason why you want to do this than avoiding an indirect call?
Sometimes it is better for the caches to initialise an object immediately, but in this case I think it is better to use the slab ctor because it is very unlikely to use many cachelines immediately anyway.
It would be nice to put the "why" in the changelogs, rather than "what". Not everyone wants to go through the whole patchset to decipher why Xen possibly needs something.
Signature · 2 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Re: [patch 07/21] Xen-paravirt: remove ctor for pgd cache
Quoted 13 lines · Nick Piggin
Quoted 11 lines · Pekka Enberg
Quoted 3 lines · Jeremy Fitzhardinge
Remove the ctor for the pgd cache. There's no point in having the cache machinery do this via an indirect call when all pgd are freed in the one place anyway.
The reason we have slab constructors and destructors is to _avoid_ reinitializing every time we allocate an object. AFAICT your changing the code now to do _more_ work than before, so is there some other reason why you want to do this than avoiding an indirect call?
Quoted 8 lines
Sometimes it is better for the caches to initialise an object immediately, but in this case I think it is better to use the slab ctor because it is very unlikely to use many cachelines immediately anyway.
It would be nice to put the "why" in the changelogs, rather than "what". Not everyone wants to go through the whole patchset to decipher why Xen possibly needs something.
Hm, I think I was mislead by looking at kmem_cache_alloc in slob.c rather than the one that's actually used in slab.c. There's no particular Xen reason for this patch, so I can drop it.
J
Re: [patch 07/21] Xen-paravirt: remove ctor for pgd cache
In reply to Jeremy FitzhardingeQuoted 3 lines · Jeremy Fitzhardinge
Remove the ctor for the pgd cache. There's no point in having the cache machinery do this via an indirect call when all pgd are freed in the one place anyway.
Great. We finally get rid of this evil .....
On second throughts:
Are you sure that you understand what you are modifying? The ctor is not called when you allocate an object but when the slab allocates it. Freeing an object does not make the slab free it. It will hold it for the next kmalloc. So you may just have reduced performance somewhat by addiung additional ctor processing and possibly disturbed the preservation of cache hot pgds.
Re: [patch 07/21] Xen-paravirt: remove ctor for pgd cache
Quoted 10 lines · Christoph Lameter
Quoted 4 lines · Jeremy Fitzhardinge
Remove the ctor for the pgd cache. There's no point in having the cache machinery do this via an indirect call when all pgd are freed in the one place anyway.
Great. We finally get rid of this evil .....
Quoted 8 lines
On second throughts:
Are you sure that you understand what you are modifying? The ctor is not called when you allocate an object but when the slab allocates it. Freeing an object does not make the slab free it. It will hold it for the next kmalloc. So you may just have reduced performance somewhat by addiung additional ctor processing and possibly disturbed the preservation of cache hot pgds.
It's true I wrote this patch as a result of accidentally reading slob.c rather than slab.c, which was mostly as a result of hopeful thinking (I knew that there has been discussion about removing all the slab cache stuff, and I assumed that it had already happened). As a result I'm withdrawing this patch for now, but with any luck it will be useful at some point.
J
PATCH 8/21 Xen-paravirt: Allow paravirt backend to choose kernel PMD sharing
In reply to Jeremy FitzhardingeXen does not allow guests to have the kernel pmd shared between page tables, so parameterize pgtable.c to allow both modes of operation.
--
arch/i386/kernel/paravirt.c | 1 arch/i386/mm/fault.c | 6 +-- arch/i386/mm/pageattr.c | 2 - arch/i386/mm/pgtable.c | 61 +++++++++++++++++++------------ include/asm-i386/page.h | 7 ++- include/asm-i386/paravirt.h | 1 include/asm-i386/pgtable-2level-defs.h | 2 + include/asm-i386/pgtable-2level.h | 2 - include/asm-i386/pgtable-3level-defs.h | 6 +++ include/asm-i386/pgtable-3level.h | 16 ++------ include/asm-i386/pgtable.h | 7 +++ 11 files changed, 68 insertions(+), 43 deletions(-)
===================================================================
arch/i386/kernel/paravirt.c +1 -0
@@ -572,6 +572,7 @@ struct paravirt_ops paravirt_ops = { .name = "bare hardware", .paravirt_enabled = 0, .kernel_rpl = 0, + .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */ .patch = native_patch, .banner = default_banner,
===================================================================
arch/i386/mm/fault.c +3 -3
@@ -616,8 +616,7 @@ do_sigbus:force_sig_info_fault (SIGBUS ,BUS_ADRERR , address, tsk); } -#ifndef CONFIG_X86_PAE -void vmalloc_sync_all (void ) +void _vmalloc_sync_all (void ) {/* * Note that races in the updates of insync and start aren't
@@ -628,6 +627,8 @@ void vmalloc_sync_all(void) static DECLARE_BITMAP(insync, PTRS_PER_PGD);static unsigned long start =TASK_SIZE ;unsigned long address; + +BUG_ON (SHARED_KERNEL_PMD );BUILD_BUG_ON (TASK_SIZE & ~PGDIR_MASK );for (address = start; address >=TASK_SIZE ; address +=PGDIR_SIZE ) {
@@ -651,4 +652,3 @@ void vmalloc_sync_all(void) start = address +PGDIR_SIZE ; } } -#endif
===================================================================
arch/i386/mm/pageattr.c +1 -1
@@ -91,7 +91,7 @@ static void set_pmd_pte(pte_t *kpte, unsunsigned long flags;set_pte_atomic (kpte, pte);/* change init_mm */ -if (PTRS_PER_PMD >1 ) +if (SHARED_KERNEL_PMD )return ;spin_lock_irqsave (&pgd_lock, flags);
===================================================================
arch/i386/mm/pgtable.c +39 -22
96 lines not on this page · raw message
===================================================================
include/asm-i386/page.h +4 -3
@@ -50,21 +50,23 @@ typedef struct { unsigned long long pgpr#ifndef CONFIG_PARAVIRT #define pmd_val (x) ((x).pmd)#define pte_val (x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32)) +#define __pte (x) ((pte_t) { .pte_low = (x), .pte_high = ((x) >> 32) } )#define __pmd (x) ((pmd_t) { (x) } )#endif /* CONFIG_PARAVIRT */ #define HPAGE_SHIFT 21#include <asm-generic/pgtable-nopud.h> -#else +#else /* !CONFIG_X86_PAE */ typedef struct {unsigned long pte_low; }pte_t ;typedef struct {unsigned long pgd; }pgd_t ;typedef struct {unsigned long pgprot; }pgprot_t ;#define boot_pte_t pte_t/* or would you rather have a typedef */ #ifndef CONFIG_PARAVIRT +#define __pte (x) ((pte_t) { (x) })#define pte_val (x) ((x).pte_low)#endif #define HPAGE_SHIFT 22#include <asm-generic/pgtable-nopmd.h> -#endif +#endif /* CONFIG_X86_PAE */ #define PTE_MASK PAGE_MASK#ifdef CONFIG_HUGETLB_PAGE
@@ -79,7 +81,6 @@ typedef struct { unsigned long pgprot; }#ifndef CONFIG_PARAVIRT #define pgd_val (x) ((x).pgd) -#define __pte (x) ((pte_t) { (x) } )#define __pgd (x) ((pgd_t) { (x) } )#endif
===================================================================
include/asm-i386/paravirt.h +1 -0
@@ -34,6 +34,7 @@ struct paravirt_opsstruct paravirt_ops {unsigned int kernel_rpl; +int shared_kernel_pmd;int paravirt_enabled;const char *name;
===================================================================
include/asm-i386/pgtable-2level-defs.h +2 -0
@@ -1,5 +1,7 @@#ifndef _I386_PGTABLE_2LEVEL_DEFS_H#define _I386_PGTABLE_2LEVEL_DEFS_H + +#define SHARED_KERNEL_PMD 0/* * traditional i386 two-level paging structure:
===================================================================
include/asm-i386/pgtable-2level.h +0 -2
@@ -66,6 +66,4 @@ static inline int pte_exec_kernel(pte_t#define __pte_to_swp_entry (pte) ((swp_entry_t) { (pte).pte_low })#define __swp_entry_to_pte (x) ((pte_t) { (x).val }) -void vmalloc_sync_all (void ); -#endif /* _I386_PGTABLE_2LEVEL_H */
===================================================================
include/asm-i386/pgtable-3level-defs.h +6 -0
@@ -1,5 +1,11 @@#ifndef _I386_PGTABLE_3LEVEL_DEFS_H#define _I386_PGTABLE_3LEVEL_DEFS_H + +#ifdef CONFIG_PARAVIRT +#define SHARED_KERNEL_PMD (paravirt_ops.shared_kernel_pmd) +#else +#define SHARED_KERNEL_PMD 1 +#endif /* * PGDIR_SHIFT determines what a top-level page table entry can map
===================================================================
include/asm-i386/pgtable-3level.h +4 -12
@@ -153,20 +153,14 @@ extern unsigned long long __supported_ptstatic inline pte_t pfn_pte (unsigned long page_nr,pgprot_t pgprot) { -pte_t pte; - - pte.pte_high = (page_nr >> (32 -PAGE_SHIFT )) | \ - (pgprot_val (pgprot) >>32 ); - pte.pte_high &= (__supported_pte_mask >>32 ); - pte.pte_low = ((page_nr <<PAGE_SHIFT ) |pgprot_val (pgprot)) & \ - __supported_pte_mask; -return pte; +return __pte ((((unsigned long long )page_nr <<PAGE_SHIFT ) | +pgprot_val (pgprot)) & __supported_pte_mask); }static inline pmd_t pfn_pmd (unsigned long page_nr,pgprot_t pgprot) { -return __pmd ((((unsigned long long )page_nr <<PAGE_SHIFT ) | \ -pgprot_val (pgprot)) & __supported_pte_mask); +return __pmd ((((unsigned long long )page_nr <<PAGE_SHIFT ) | +pgprot_val (pgprot)) & __supported_pte_mask); }/*
@@ -186,6 +180,4 @@ static inline pmd_t pfn_pmd(unsigned lon#define __pmd_free_tlb (tlb, x) do { } while (0) -#define vmalloc_sync_all () ((void)0) -#endif /* _I386_PGTABLE_3LEVEL_H */
===================================================================
include/asm-i386/pgtable.h +7 -0
@@ -239,6 +239,13 @@ static inline pte_t pte_mkwrite(pte_t ptstatic inline pte_t pte_mkwrite (pte_t pte) { (pte).pte_low |= _PAGE_RW;return pte; }static inline pte_t pte_mkhuge (pte_t pte) { (pte).pte_low |= _PAGE_PSE;return pte; } +extern void _vmalloc_sync_all (void ); +static inline void vmalloc_sync_all (void ) +{ +if (!SHARED_KERNEL_PMD ) +_vmalloc_sync_all (); +} +#ifdef CONFIG_X86_PAE # include <asm/pgtable-3level.h> #else
PATCH 9/21 Xen-paravirt: Allow paravirt backend to select PGD allocation alignment
In reply to Jeremy FitzhardingeXen requires pgds to be page-aligned, so make this a parameter which can be set in the paravirt_ops structure.
--
arch/i386/kernel/paravirt.c | 1 + arch/i386/mm/init.c | 2 +- include/asm-i386/paravirt.h | 5 ++++- include/asm-i386/pgtable.h | 6 ++++++ 4 files changed, 12 insertions(+), 2 deletions(-)
===================================================================
arch/i386/kernel/paravirt.c +1 -0
@@ -573,6 +573,7 @@ struct paravirt_ops paravirt_ops = { .paravirt_enabled = 0, .kernel_rpl = 0, .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */ + .pgd_alignment = sizeof(pgd_t) * PTRS_PER_PGD, .patch = native_patch, .banner = default_banner,
===================================================================
arch/i386/mm/init.c +1 -1
@@ -745,7 +745,7 @@ void __init pgtable_cache_init(void) } pgd_cache =kmem_cache_create ("pgd" ,PTRS_PER_PGD *sizeof (pgd_t), -PTRS_PER_PGD *sizeof (pgd_t), +PGD_ALIGNMENT ,0 ,NULL ,NULL );if (!pgd_cache)panic ("pgtable_cache_init(): Cannot create pgd cache" );
===================================================================
include/asm-i386/paravirt.h +4 -1
@@ -33,9 +33,12 @@ struct mm_struct;struct mm_struct ;struct paravirt_ops { +int paravirt_enabled;unsigned int kernel_rpl; +int shared_kernel_pmd; -int paravirt_enabled; +int pgd_alignment; +const char *name;/*
===================================================================
include/asm-i386/pgtable.h +6 -0
@@ -270,6 +270,12 @@ static inline void vmalloc_sync_all(void#define pte_update_defer (mm, addr, ptep) do { } while (0)#endif +#ifdef CONFIG_PARAVIRT +#define PGD_ALIGNMENT (paravirt_ops.pgd_alignment) +#else +#define PGD_ALIGNMENT (sizeof(pgd_t) * PTRS_PER_PGD) +#endif +/* * We only update the dirty/accessed state if we set * the dirty bit by hand in the kernel, since the hardware
PATCH 10/21 Xen-paravirt: add hooks to intercept mm creation and destruction
In reply to Jeremy FitzhardingeAdd hooks to allow a paravirt implementation to track the lifetime of an mm.
--
arch/i386/kernel/paravirt.c | 4 ++++ include/asm-i386/mmu_context.h | 8 ++++++-- include/asm-i386/paravirt.h | 38 ++++++++++++++++++++++++++++++++++++++ kernel/fork.c | 3 +++ mm/mmap.c | 4 ++++ 5 files changed, 55 insertions(+), 2 deletions(-)
===================================================================
arch/i386/kernel/paravirt.c +4 -0
@@ -706,6 +706,10 @@ struct paravirt_ops paravirt_ops = { .irq_enable_sysexit = native_irq_enable_sysexit, .iret = native_iret, + .dup_mmap = (void *)native_nop, + .exit_mmap = (void *)native_nop, + .activate_mm = (void *)native_nop, + .startup_ipi_hook = (void *)native_nop, };
===================================================================
include/asm-i386/mmu_context.h +6 -2
@@ -5,6 +5,7 @@#include <asm/atomic.h> #include <asm/pgalloc.h> #include <asm/tlbflush.h> +#include <asm/paravirt.h> /* * Used for LDT copy/destruction.
@@ -65,7 +66,10 @@ static inline void switch_mm(struct mm_s#define deactivate_mm (tsk, mm) \ asm("movl %0,%%gs": :"r" (0)); -#define activate_mm (prev, next) \ - switch_mm((prev),(next),NULL) +#define activate_mm (prev, next) \ + do { \ + arch_activate_mm(prev, next); \ + switch_mm((prev),(next),NULL); \ + } while(0);#endif
===================================================================
include/asm-i386/paravirt.h +39 -0
@@ -126,6 +126,12 @@ struct paravirt_opsvoid (*io_delay)(void );void (*const_udelay)(unsigned long loops); + void (fastcall *activate_mm)(struct mm_struct *prev, +struct mm_struct *next); + void (fastcall *dup_mmap)(struct mm_struct *oldmm, +struct mm_struct *mm); + void (fastcall *exit_mmap)(struct mm_struct *mm); +#ifdef CONFIG_X86_LOCAL_APIC void (*apic_write)(unsigned long reg,unsigned long v);void (*apic_write_atomic)(unsigned long reg,unsigned long v);
@@ -429,6 +435,24 @@ static inline void startup_ipi_hook(int }#endif +#define __HAVE_ARCH_MM_LIFETIME +static inline void arch_activate_mm (struct mm_struct *prev, +struct mm_struct *next) +{ + paravirt_ops.activate_mm (prev, next); +} + +static inline void arch_dup_mmap (struct mm_struct *oldmm, +struct mm_struct *mm) +{ + paravirt_ops.dup_mmap (oldmm, mm); +} + +static inline void arch_exit_mmap (struct mm_struct *mm) +{ + paravirt_ops.exit_mmap (mm); +} +#define __flush_tlb () paravirt_ops.flush_tlb_user()#define __flush_tlb_global () paravirt_ops.flush_tlb_kernel()#define __flush_tlb_single (addr) paravirt_ops.flush_tlb_single(addr)
@@ -673,5 +697,20 @@ static inline void paravirt_pagetable_seset_pgd (&base[0 ], base[USER_PTRS_PER_PGD ]);#endif } + +static inline void paravirt_activate_mm (struct mm_struct *prev, +struct mm_struct *next) +{ +} + +static inline void paravirt_dup_mmap (struct mm_struct *oldmm, +struct mm_struct *mm) +{ +} + +static inline void paravirt_exit_mmap (struct mm_struct *mm) +{ +} +#endif /* CONFIG_PARAVIRT */ #endif /* __ASM_PARAVIRT_H */
===================================================================
include/linux/sched.h +6 -0
@@ -374,6 +374,12 @@ struct mm_struct {rwlock_t ioctx_list_lock;struct kioctx *ioctx_list; }; + +#ifndef __HAVE_ARCH_MM_LIFETIME +#define arch_activate_mm (prev, next) do {} while(0) +#define arch_dup_mmap (oldmm, mm) do {} while(0) +#define arch_exit_mmap (mm) do {} while(0) +#endif struct sighand_struct {atomic_t count;
===================================================================
kernel/fork.c +1 -0
@@ -286,6 +286,7 @@ static inline int dup_mmap(struct mm_strif (retval) goto out; } +arch_dup_mmap (oldmm, mm); retval =0 ; out:up_write (&mm->mmap_sem);
===================================================================
mm/mmap.c +2 -0
@@ -1976,6 +1976,8 @@ void exit_mmap(struct mm_struct *mm)struct vm_area_struct *vma = mm->mmap;unsigned long nr_accounted =0 ;unsigned long end; + +arch_exit_mmap (mm);lru_add_drain ();flush_cache_mm (mm);
Andrew Morton
maintainerRe: [patch 10/21] Xen-paravirt: add hooks to intercept mm creation and destruction
Quoted 6 lines · On Thu, 15 Feb 2007 18:24:59 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
Add hooks to allow a paravirt implementation to track the lifetime of an mm.
arch/i386/kernel/paravirt.c struct paravirt_ops paravirt_ops = { · line 714
Quoted 9 lines
arch/i386/kernel/paravirt.c +4
-0@@ -706,6 +706,10 @@ struct paravirt_ops paravirt_ops = { .irq_enable_sysexit = native_irq_enable_sysexit, .iret = native_iret, + .dup_mmap = (void *)native_nop, + .exit_mmap = (void *)native_nop, + .activate_mm = (void *)native_nop, + .startup_ipi_hook = (void *)native_nop, };
eww. I suppose there's a good reason for the casting.
Quoted 12 lines
===================================================================
include/asm-i386/mmu_context.h +1
-0@@ -5,6 +5,7 @@#include <asm/atomic.h> #include <asm/pgalloc.h> #include <asm/tlbflush.h> +#include <asm/paravirt.h> /* * Used for LDT copy/destruction.
include/asm-i386/mmu_context.h static inline void switch_mm(struct mm_s · line 73
Quoted 10 lines
include/asm-i386/mmu_context.h +5
-2@@ -65,7 +66,10 @@ static inline void switch_mm(struct mm_s#define deactivate_mm (tsk, mm) \ asm("movl %0,%%gs": :"r" (0)); -#define activate_mm (prev, next) \ - switch_mm((prev),(next),NULL) +#define activate_mm (prev, next) \ + do { \ + arch_activate_mm(prev, next); \ + switch_mm((prev),(next),NULL); \ + } while(0);
It seems strange to call out to arch_foo() from within an arch header file. I mean, we implicity know we're i386.
Maybe it's just poorly named.
include/asm-i386/mmu_context.h static inline void switch_mm(struct mm_s
Quoted 13 lines
include/asm-i386/mmu_context.h +13
-0+static inline void paravirt_activate_mm (struct mm_struct *prev, +struct mm_struct *next) +{ +} + +static inline void paravirt_dup_mmap (struct mm_struct *oldmm, +struct mm_struct *mm) +{ +} + +static inline void paravirt_exit_mmap (struct mm_struct *mm) +{ +}
These functions are unreferenced in this patchset.
Quoted 6 lines
#endif /*
CONFIG_PARAVIRT*/
#endif /*__ASM_PARAVIRT_H*/
===================================================================
include/linux/sched.h struct mm_struct { · line 382
Quoted 9 lines
include/linux/sched.h +6
-0@@ -374,6 +374,12 @@ struct mm_struct {rwlock_t ioctx_list_lock;struct kioctx *ioctx_list; }; + +#ifndef __HAVE_ARCH_MM_LIFETIME +#define arch_activate_mm (prev, next) do {} while(0) +#define arch_dup_mmap (oldmm, mm) do {} while(0) +#define arch_exit_mmap (mm) do {} while(0) +#endif
Can we lose __HAVE_ARCH_MM_LIFETIME? Just define these (preferably in C, not in cpp) in the appropriate include/asm-foo/ files?
Quoted 17 lines
include/linux/sched.h +0
-0struct sighand_struct {atomic_t count;===================================================================
kernel/fork.c +1
-0@@ -286,6 +286,7 @@ static inline int dup_mmap(struct mm_strif (retval) goto out; } +arch_dup_mmap (oldmm, mm); retval =0 ; out:up_write (&mm->mmap_sem);===================================================================
mm/mmap.c void exit_mmap(struct mm_struct *mm) · line 1983
Quoted 8 lines
mm/mmap.c +2
-0@@ -1976,6 +1976,8 @@ void exit_mmap(struct mm_struct *mm)struct vm_area_struct *vma = mm->mmap;unsigned long nr_accounted =0 ;unsigned long end; + +arch_exit_mmap (mm);lru_add_drain ();flush_cache_mm (mm);
Perhaps some commentary telling the arch maintainer what these hooks he's being offered are for?
Re: [patch 10/21] Xen-paravirt: add hooks to intercept mm creation and destruction
Quoted 12 lines · Andrew Morton
Quoted 9 lines · On Thu, 15 Feb 2007 18:24:59 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
Add hooks to allow a paravirt implementation to track the lifetime of an mm.
arch/i386/kernel/paravirt.c +0
-0@@ -706,6 +706,10 @@ struct paravirt_ops paravirt_ops = { .irq_enable_sysexit = native_irq_enable_sysexit, .iret = native_iret,
Quoted 10 lines
arch/i386/kernel/paravirt.c struct paravirt_ops paravirt_ops = { · line 715
Quoted 7 lines
arch/i386/kernel/paravirt.c +4
-0+ .dup_mmap = (void *)native_nop, + .exit_mmap = (void *)native_nop, + .activate_mm = (void *)native_nop, + .startup_ipi_hook = (void *)native_nop, };eww. I suppose there's a good reason for the casting.
Yeah, it's a bit ugly. The alternative is to have a separate correctly-typed nop function for each operation. But that's even more typing.
Quoted 5 lines
It seems strange to call out to
arch_foo()from within an arch header file. I mean, we implicity know we're i386.Maybe it's just poorly named.
The other two are arch_* and are called from common code. arch_activate_mm() is either empty or a call to paravirt_ops.activate_mm. I could name it paravirt_activate_mm (as it was in earlier versions of this patch), but then it would be inconsistent with the other functions. I thought the consistency was more important, because these calls need to be properly matched.
Quoted 8 lines
Quoted 8 lines
arch/i386/kernel/paravirt.c +8
-0+static inline void paravirt_activate_mm (struct mm_struct *prev, +struct mm_struct *next) +{ +} + +static inline void paravirt_dup_mmap (struct mm_struct *oldmm, +struct mm_struct *mm) +{
Quoted 9 lines
arch/i386/kernel/paravirt.c
Quoted 6 lines
arch/i386/kernel/paravirt.c +5
-0+} + +static inline void paravirt_exit_mmap (struct mm_struct *mm) +{ +}These functions are unreferenced in this patchset.
OK, I'll drop them.
Quoted 11 lines
Quoted 11 lines
#endif /*
CONFIG_PARAVIRT*/
#endif /*__ASM_PARAVIRT_H*/
===================================================================include/linux/sched.h +2
-0@@ -374,6 +374,12 @@ struct mm_struct {rwlock_t ioctx_list_lock;struct kioctx *ioctx_list; }; + +#ifndef __HAVE_ARCH_MM_LIFETIME
Quoted 9 lines
include/linux/sched.h struct mm_struct { · line 383
Quoted 5 lines
include/linux/sched.h +4
-0+#define arch_activate_mm (prev, next) do {} while(0) +#define arch_dup_mmap (oldmm, mm) do {} while(0) +#define arch_exit_mmap (mm) do {} while(0) +#endif Can we lose
__HAVE_ARCH_MM_LIFETIME? Just define these (preferably in C, not in cpp) in the appropriateinclude/asm-foo/files?
I guess, if you want. For everything except i386 (and x86_64 in the not too distant future) they'll be noops. But for consistency, I/we would have to put the appropriate arch_activate_mm() into each arch's activate_mm(); I seem to remember some were not as straightforward as i386.
Quoted 23 lines
Quoted 23 lines
include/linux/sched.h +0
-0struct sighand_struct {atomic_t count;===================================================================
kernel/fork.c +1
-0@@ -286,6 +286,7 @@ static inline int dup_mmap(struct mm_strif (retval) goto out; } +arch_dup_mmap (oldmm, mm); retval =0 ; out:up_write (&mm->mmap_sem);===================================================================
mm/mmap.c +2
-0@@ -1976,6 +1976,8 @@ void exit_mmap(struct mm_struct *mm)struct vm_area_struct *vma = mm->mmap;unsigned long nr_accounted =0 ;unsigned long end; + +arch_exit_mmap (mm);
Quoted 7 lines
mm/mmap.c void exit_mmap(struct mm_struct *mm) · line 1983
Quoted 3 lines
mm/mmap.c +0
-0lru_add_drain ();flush_cache_mm (mm);Perhaps some commentary telling the arch maintainer what these hooks he's being offered are for?
OK.
J
Re: [patch 10/21] Xen-paravirt: add hooks to intercept mm creation and destruction
In reply to Jeremy FitzhardingeHi!
include/asm-i386/paravirt.h struct paravirt_ops · line 134
Quoted 10 lines
include/asm-i386/paravirt.h +6
-0@@ -126,6 +126,12 @@ struct paravirt_opsvoid (*io_delay)(void );void (*const_udelay)(unsigned long loops); + void (fastcall *activate_mm)(struct mm_struct *prev, +struct mm_struct *next); + void (fastcall *dup_mmap)(struct mm_struct *oldmm, +struct mm_struct *mm); + void (fastcall *exit_mmap)(struct mm_struct *mm); +
Why the fastcall stuff? Why is io_delay different from activate_mm in this regard?
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [patch 10/21] Xen-paravirt: add hooks to intercept mm creation and destruction
Quoted 7 lines · Pavel Machek
Hi!
Quoted 4 lines
include/asm-i386/paravirt.h +0
-0@@ -126,6 +126,12 @@ struct paravirt_opsvoid (*io_delay)(void );void (*const_udelay)(unsigned long loops);
Quoted 11 lines
include/asm-i386/paravirt.h struct paravirt_ops
Quoted 7 lines
include/asm-i386/paravirt.h +6
-0+ void (fastcall *activate_mm)(struct mm_struct *prev, +struct mm_struct *next); + void (fastcall *dup_mmap)(struct mm_struct *oldmm, +struct mm_struct *mm); + void (fastcall *exit_mmap)(struct mm_struct *mm); +Why the fastcall stuff? Why is
io_delaydifferent fromactivate_mmin this regard?
That's crud; I forgot to remove it. Everything is effectively fastcall now that -mregparm=3 is always on.
J
Re: [patch 10/21] Xen-paravirt: add hooks to intercept mm creation and destruction
In reply to Pavel MachekQuoted 7 lines · Pavel Machek
Hi!
Quoted 4 lines
include/asm-i386/paravirt.h +0
-0@@ -126,6 +126,12 @@ struct paravirt_opsvoid (*io_delay)(void );void (*const_udelay)(unsigned long loops);
Quoted 11 lines
include/asm-i386/paravirt.h struct paravirt_ops
Quoted 7 lines
include/asm-i386/paravirt.h +6
-0+ void (fastcall *activate_mm)(struct mm_struct *prev, +struct mm_struct *next); + void (fastcall *dup_mmap)(struct mm_struct *oldmm, +struct mm_struct *mm); + void (fastcall *exit_mmap)(struct mm_struct *mm); +Why the fastcall stuff? Why is
io_delaydifferent fromactivate_mmin this regard?
Actually, I did remove it. I think you're looking at an old patch.
J
PATCH 11/21 Xen-paravirt: Add apply_to_page_range() which applies a function to a pte range.
In reply to Jeremy FitzhardingeAdd a new mm function apply_to_page_range() which applies a given function to every pte in a given virtual address range in a given mm structure. This is a generic alternative to cut-and-pasting the Linux idiomatic pagetable walking code in every place that a sequence of PTEs must be accessed.
Although this interface is intended to be useful in a wide range of situations, it is currently used specifically by several Xen subsystems, for example: to ensure that pagetables have been allocated for a virtual address range, and to construct batched special pagetable update requests to map I/O memory (in ioremap()).
--- include/linux/mm.h | 5 ++ mm/memory.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+)
===================================================================
include/linux/mm.h +5 -0
@@ -1130,6 +1130,11 @@ struct page *follow_page(struct vm_area_unsigned long __follow_page (void *vaddr); +typedef int (*pte_fn_t )(pte_t *pte,struct page *pmd_page,unsigned long addr, +void *data); +extern int apply_to_page_range (struct mm_struct *mm,unsigned long address, +unsigned long size,pte_fn_t fn,void *data); +#ifdef CONFIG_PROC_FS void vm_stat_account (struct mm_struct *,unsigned long ,struct file *,long );#else
===================================================================
mm/memory.c +94 -0
100 lines not on this page · raw message
Andrew Morton
maintainerRe: [patch 11/21] Xen-paravirt: Add apply_to_page_range() which applies a function to a pte range.
Quoted 11 lines · On Thu, 15 Feb 2007 18:25:00 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
Add a new mm function
apply_to_page_range()which applies a given function to every pte in a given virtual address range in a given mm structure. This is a generic alternative to cut-and-pasting the Linux idiomatic pagetable walking code in every place that a sequence of PTEs must be accessed.Although this interface is intended to be useful in a wide range of situations, it is currently used specifically by several Xen subsystems, for example: to ensure that pagetables have been allocated for a virtual address range, and to construct batched special pagetable update requests to map I/O memory (in
ioremap()).
There was some discussion about this sort of thing last week. The consensus was that it's better to run the callback against a whole pmd's worth of ptes, mainly to amortise the callback's cost (a lot).
It was implemented in ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.20/2.6.20-mm1/broken-out/smaps-extract-pmd-walker-from-smaps-code.patch
Re: [patch 11/21] Xen-paravirt: Add apply_to_page_range() which applies a function to a pte range.
Quoted 10 lines · Andrew Morton
Quoted 1 line · On Thu, 15 Feb 2007 18:25:00 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
Add a new mm function apply_to_page_range()[...]
There was some discussion about this sort of thing last week. The consensus was that it's better to run the callback against a whole pmd's worth of ptes, mainly to amortise the callback's cost (a lot).
It was implemented in ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.20/2.6.20-mm1/broken-out/smaps-extract-pmd-walker-from-smaps-code.patch
Yes I was looking at that and wondering what the upshot would be. I'll have a closer look, but it seems like it should be usable.
J
Andrew Morton
maintainerRe: [patch 11/21] Xen-paravirt: Add apply_to_page_range() which applies a function to a pte range.
Quoted 9 lines · On Thu, 15 Feb 2007 23:06:45 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
Quoted 8 lines · Andrew Morton
Quoted 1 line · On Thu, 15 Feb 2007 18:25:00 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
Add a new mm function apply_to_page_range()[...]
There was some discussion about this sort of thing last week. The consensus was that it's better to run the callback against a whole pmd's worth of ptes, mainly to amortise the callback's cost (a lot).
Quoted 5 lines
Quoted 2 lines
It was implemented in ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.20/2.6.20-mm1/broken-out/smaps-extract-pmd-walker-from-smaps-code.patch
Yes I was looking at that and wondering what the upshot would be. I'll have a closer look, but it seems like it should be usable.
It's a question of who-merges-first. I wasn't planning on merging the smaps stuff into 2.6.21.
Perhaps the best approach is to proceed as-is and clean things up once it's all merged.
I guess your pte-at-a-time walker could be quite simply implemented underneath the smaps pmd-at-a-time walker.
Re: [patch 11/21] Xen-paravirt: Add apply_to_page_range() which applies a function to a pte range.
Quoted 3 lines · Andrew Morton
I guess your pte-at-a-time walker could be quite simply implemented underneath the smaps pmd-at-a-time walker.
Yes, converting should be pretty simple. There aren't many users in Xen, but they are moderately performance critical (fork, exec and exit), so using batching would be good.
J
Re: [patch 11/21] Xen-paravirt: Add apply_to_page_range() which applies a function to a pte range.
In reply to Andrew MortonQuoted 16 lines · Andrew Morton
Quoted 11 lines · On Thu, 15 Feb 2007 18:25:00 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
Add a new mm function
apply_to_page_range()which applies a given function to every pte in a given virtual address range in a given mm structure. This is a generic alternative to cut-and-pasting the Linux idiomatic pagetable walking code in every place that a sequence of PTEs must be accessed.Although this interface is intended to be useful in a wide range of situations, it is currently used specifically by several Xen subsystems, for example: to ensure that pagetables have been allocated for a virtual address range, and to construct batched special pagetable update requests to map I/O memory (in
ioremap()).
Quoted 6 lines
There was some discussion about this sort of thing last week. The consensus was that it's better to run the callback against a whole pmd's worth of ptes, mainly to amortise the callback's cost (a lot).
It was implemented in ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.20/2.6.20-mm1/broken-out/smaps-extract-pmd-walker-from-smaps-code.patch
Speaking of that patch, I missed the discussion, but I'd hope it doesn't go upstream in its current form.
We now have one way of walking range of ptes. The code may be duplicated a few times, but it is simple, we know how it works, and it is easy to get right because everyone does the same thing.
We used to have about a dozen slightly different ways of doing this until Hugh spent the effort to standardise it all. Isn't it nice?
If we want an ever-so-slightly lower performing interface for those paths that don't care to count every cycle -- which I think is a fine idea BTW -- it should be implemented in mm/memory.c and it should use our standard form of pagetable walking.
Signature · 8 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 12/21 Xen-paravirt: Allocate and free vmalloc areas
In reply to Jeremy FitzhardingeAllocate/destroy a 'vmalloc' VM area: alloc_vm_area and free_vm_area The alloc function ensures that page tables are constructed for the region of kernel virtual address space and mapped into init_mm.
Lock an area so that PTEs are accessible in the current address space:lock_vm_area and unlock_vm_area. The lock function prevents context switches to a lazy mm that doesn't have the area mapped into its page tables. It also ensures that the page tables are mapped into the current mm by causing the page fault handler to copy the page directory pointers from init_mm into the current mm.
These functions are not particularly Xen-specific, so they're put into mm/vmalloc.c.
--
include/linux/vmalloc.h | 8 +++++ mm/vmalloc.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+)
===================================================================
include/linux/vmalloc.h +8 -0
@@ -68,6 +68,14 @@ extern int map_vm_area(struct vm_struct struct page ***pages);extern void unmap_vm_area (struct vm_struct *area); +/* Allocate/destroy a 'vmalloc' VM area. */ +extern struct vm_struct *alloc_vm_area (unsigned long size); +extern void free_vm_area (struct vm_struct *area); + +/* Lock an area so that PTEs are accessible in the current address space. */ +extern void lock_vm_area (struct vm_struct *area); +extern void unlock_vm_area (struct vm_struct *area); +/* * Internals. Dont't use.. */
===================================================================
mm/vmalloc.c +62 -0
65 lines not on this page · raw message
Andrew Morton
maintainerRe: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
Quoted 9 lines · On Thu, 15 Feb 2007 18:25:01 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
mm/vmalloc.c +9
-0+void lock_vm_area (struct vm_struct *area) +{ +unsigned long i; +char c; + +/* +* Prevent context switch to a lazy mm that doesn't have this area +* mapped into its page tables. +*/
mm/vmalloc.c out_einval_locked: · line 805
Quoted 10 lines
mm/vmalloc.c +10
-0+preempt_disable (); + +/* +* Ensure that the page tables are mapped into the current mm. The +* page-fault path will copy the page directory pointers from init_mm. +*/ +for (i =0 ; i < area->size; i +=PAGE_SIZE ) + (void )__get_user (c, (char __user *)area->addr + i); +} +EXPORT_SYMBOL_GPL (lock_vm_area);
This won't work when CONFIG_PREEMPT=y. The pagefault handler will see in_atomic() and will scram.
(pet-peeve-from-someone-who-remembers-fortran: the reader expects the variable `i' to be signed. signed int really)
Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
Quoted 3 lines · Andrew Morton
This won't work when
CONFIG_PREEMPT=y. The pagefault handler will seein_atomic()and will scram.
Is there some other way to get the pagetable populated for the address range?
J
Andrew Morton
maintainerRe: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
Quoted 8 lines · On Thu, 15 Feb 2007 23:08:02 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
Quoted 3 lines · Andrew Morton
This won't work when
CONFIG_PREEMPT=y. The pagefault handler will seein_atomic()and will scram.Is there some other way to get the pagetable populated for the address range?
If you really need to run atomically, that gets ugly. Even of one were to run handle_mm_fault() by hand, it still needs to allocate memory.
Two ugly options might be:
a) touch all the pages, then go atomic, then touch them all again. If one of them faults (ie: you raced with swapout) then go back and try again. Obviously susceptible to livelocking.
b) Do get_user_pages() against all the pages, then go atomic, then do put_page() against them all. Of course, they can immediately get swapped out.
But that function's already racy against swapout and I guess it works OK. I don't have clue what it is actually trying to do, so I'm guessing madly here.
Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
Quoted 23 lines · Andrew Morton
Quoted 10 lines · On Thu, 15 Feb 2007 23:08:02 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
Quoted 4 lines · Andrew Morton
This won't work when
CONFIG_PREEMPT=y. The pagefault handler will seein_atomic()and will scram.Is there some other way to get the pagetable populated for the address range?
If you really need to run atomically, that gets ugly. Even of one were to run
handle_mm_fault()by hand, it still needs to allocate memory.Two ugly options might be:
a) touch all the pages, then go atomic, then touch them all again. If one of them faults (ie: you raced with swapout) then go back and try again. Obviously susceptible to livelocking.
Quoted 8 lines
b) Do
get_user_pages()against all the pages, then go atomic, then doput_page()against them all. Of course, they can immediately get swapped out.But that function's already racy against swapout and I guess it works OK. I don't have clue what it is actually trying to do, so I'm guessing madly here.
It's for populating the pagetable in a vmalloc area. There's magic in the fault handler to synchronize the vmalloc mappings between different process's kernel mappings, so if the mapping isn't currently present, it will fault and create the appropriate mapping. It's not operating on swappable user memory, so swapping isn't an issue; but if the fault handler exits immediately with preempt disabled, then there's a problem.
(Even though we don't support preempt, I've been generally coding in a preempt-safe way, just so that the code looks "normal". And maybe we will support preempt at some point.)
J
Andrew Morton
maintainerRe: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
Quoted 18 lines · On Thu, 15 Feb 2007 23:30:57 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
Quoted 9 lines
If you really need to run atomically, that gets ugly. Even of one were to run
handle_mm_fault()by hand, it still needs to allocate memory.Two ugly options might be:
a) touch all the pages, then go atomic, then touch them all again. If one of them faults (ie: you raced with swapout) then go back and try again. Obviously susceptible to livelocking.
Quoted 8 lines
b) Do
get_user_pages()against all the pages, then go atomic, then doput_page()against them all. Of course, they can immediately get swapped out.But that function's already racy against swapout and I guess it works OK. I don't have clue what it is actually trying to do, so I'm guessing madly here.
Quoted 7 lines
It's for populating the pagetable in a vmalloc area. There's magic in the fault handler to synchronize the vmalloc mappings between different process's kernel mappings, so if the mapping isn't currently present, it will fault and create the appropriate mapping. It's not operating on swappable user memory, so swapping isn't an issue; but if the fault handler exits immediately with preempt disabled, then there's a problem.
oh, I see. The vmalloc fault can run atomically. In fact it can run at hard iRQ. So no probs (apart from the fact that it required an email dialogue to work this out rather than reading the code, but I do go on).
Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
In reply to Jeremy FitzhardingeQuoted 1 line
It's for populating the pagetable in a vmalloc area. There's magic in
If the lazy setup doesn't work for you you can always call vmalloc_sync() early.
-Andi
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
Quoted 4 lines · Andi Kleen
Quoted 1 line
It's for populating the pagetable in a vmalloc area. There's magic in
If the lazy setup doesn't work for you you can always call
vmalloc_sync()early.
vmalloc_sync_all()? That's a great idea. We can put that in alloc_vm_area() and kill {lock,unlock}_vm_area() which is a nice interface simplification.
Thanks!
Keir
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
Quoted 9 lines · Keir Fraser
Quoted 4 lines · Andi Kleen
Quoted 1 line
It's for populating the pagetable in a vmalloc area. There's magic in
If the lazy setup doesn't work for you you can always call
vmalloc_sync()early.
vmalloc_sync_all()?
Yes.
Credit goes to Jan for writing it originally.
-Andi
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
In reply to Andi KleenQuoted 4 lines · Andi Kleen
Quoted 1 line
It's for populating the pagetable in a vmalloc area. There's magic in
If the lazy setup doesn't work for you you can always call
vmalloc_sync()early.
vmalloc_sync_all()? That's a great idea. We can put that in alloc_vm_area() and kill {lock,unlock}_vm_area() which is a nice interface simplification.
Thanks!
Keir
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
In reply to Andi KleenQuoted 4 lines · Andi Kleen
Quoted 1 line
It's for populating the pagetable in a vmalloc area. There's magic in
If the lazy setup doesn't work for you you can always call
vmalloc_sync()early.
vmalloc_sync_all()? That's a great idea. We can put that in alloc_vm_area() and kill {lock,unlock}_vm_area() which is a nice interface simplification.
Thanks!
Keir
Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
In reply to Andi KleenQuoted 6 lines · Andi Kleen
Quoted 2 lines
It's for populating the pagetable in a vmalloc area. There's magic in
If the lazy setup doesn't work for you you can always call
vmalloc_sync()early.
Yes, that would work. Unfortunately that's i386 arch-specific, whereas the rest of this code is generic. I guess I could just move it all to arch/i386/mm.
J
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
Quoted 3 lines · Jeremy Fitzhardinge
Yes, that would work. Unfortunately that's i386 arch-specific, whereas the rest of this code is generic. I guess I could just move it all to
arch/i386/mm.
This whole thing isn't an issue on ia64 (they no-op lock_vm_area) and powerpc doesn't use any of the Xen driver code at this time. vmalloc_sync_all is supported by both i386 and x86_64, so we can make the call conditional on CONFIG_X86 so that ia64 will continue to build. This is what I've done in xen-unstable.
-- Keir
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
Quoted 11 lines · Keir Fraser
Quoted 3 lines · Jeremy Fitzhardinge
Yes, that would work. Unfortunately that's i386 arch-specific, whereas the rest of this code is generic. I guess I could just move it all to
arch/i386/mm.This whole thing isn't an issue on ia64 (they no-op
lock_vm_area) and powerpc doesn't use any of the Xen driver code at this time.vmalloc_sync_allis supported by both i386 andx86_64, so we can make the call conditional onCONFIG_X86so that ia64 will continue to build. This is what I've done in xen-unstable.
In fact that file is only built for i386 and x86_64, so there really is no problem with using vmalloc_sync_all() directly and without ifdef.
-- Keir
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
Quoted 18 lines · Keir Fraser
Quoted 7 lines · Keir Fraser
Quoted 4 lines · Jeremy Fitzhardinge
Yes, that would work. Unfortunately that's i386 arch-specific, whereas the rest of this code is generic. I guess I could just move it all to
arch/i386/mm.Quoted 6 lines
This whole thing isn't an issue on ia64 (they no-op
lock_vm_area) and powerpc doesn't use any of the Xen driver code at this time.vmalloc_sync_allis supported by both i386 andx86_64, so we can make the call conditional onCONFIG_X86so that ia64 will continue to build. This is what I've done in xen-unstable.
Quoted 3 lines
In fact that file is only built for i386 and
x86_64, so there really is no problem with usingvmalloc_sync_all()directly and without ifdef.
I had moved it to mm/vmalloc.c in response to previous review comments (namely, its not Xen specific, so it shouldn't live in the Xen part of the tree).
J
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
Quoted 7 lines · Jeremy Fitzhardinge
In fact that file is only built for i386 and
x86_64, so there really is noQuoted 2 lines
problem with using
vmalloc_sync_all()directly and without ifdef.I had moved it to
mm/vmalloc.cin response to previous review comments (namely, its not Xen specific, so it shouldn't live in the Xen part of the tree).
Then the call will have to be CONFIG_X86. I hadn't realised powerpc were also using lock_vm_area. However I suspect that the x86 issue that those functions were written doesn't even exist on powerpc, or any other non-x86 architecture.
I guess we should change the name of alloc_vm_area, by the way. Perhaps alloc_vm_area_sync() or similar, to give some hint of what it's doing and how it differs from other vmalloc-area functions?
-- Keir
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
Quoted 8 lines · Keir Fraser
Quoted 3 lines
I had moved it to
mm/vmalloc.cin response to previous review comments (namely, its not Xen specific, so it shouldn't live in the Xen part of the tree).Then the call will have to be
CONFIG_X86. I hadn't realised powerpc were also usinglock_vm_area. However I suspect that the x86 issue that those functions were written doesn't even exist on powerpc, or any other non-x86 architecture.
Hmmm... Actually looks like a bunch of architectures do lazy sync of the vmalloc area, although neither ia64 nor powerpc does so. However, all current users of the alloc_vm_area() function would be okay since none of the other lazy-syncing architectures are supported by Xen.
-- Keir
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
Quoted 5 lines · Keir Fraser
Hmmm... Actually looks like a bunch of architectures do lazy sync of the vmalloc area, although neither ia64 nor powerpc does so. However, all current users of the
alloc_vm_area()function would be okay since none of the other lazy-syncing architectures are supported by Xen.
Well, assuming that alloc_vm_area() has some non-Xen use, the right thing is for archs to export vmalloc_sync_all(), and just use that from common code.
J
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
Quoted 10 lines · Jeremy Fitzhardinge
Quoted 5 lines · Keir Fraser
Hmmm... Actually looks like a bunch of architectures do lazy sync of the vmalloc area, although neither ia64 nor powerpc does so. However, all current users of the
alloc_vm_area()function would be okay since none of the other lazy-syncing architectures are supported by Xen.Well, assuming that
alloc_vm_area()has some non-Xen use, the right thing is for archs to exportvmalloc_sync_all(), and just use that from common code.
It has no other users right now and get_vm_area_sync() would be a better-named and more generically useful function than alloc_vm_area(). But yes, to be done properly it does require vmalloc_sync_all() to be defined by all architectures (even if that's BUG() and implement-properly-on-demand).
get_vm_area_sync(), partnered with existing remove_vm_area(), just seems much smaller and neater than adding four new functions with a more complex
usage: alloc_vm_area, {lock,unlock}_vm_area, and free_vm_area. Maybe keeping free_vm_area() too makes sense as its interface is more neatly symmetrical to that of get_vm_area().
-- Keir
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
Quoted 2 lines · Keir Fraser
It has no other users right now and
get_vm_area_sync()would be a better-named and more generically useful function thanalloc_vm_area().
I'm thinking "reserve" might be a better term; "get" generally has the suggestion of a refcount.
Quoted 5 lines
get_vm_area_sync(), partnered with existingremove_vm_area(), just seems much smaller and neater than adding four new functions with a more complex
usage:alloc_vm_area, {lock,unlock}_vm_area, andfree_vm_area. Maybe keepingfree_vm_area()too makes sense as its interface is more neatly symmetrical to that ofget_vm_area().
I've already killed the lock/unlock functions. I'll come up with something for the get/allocate/reserve and free functions.
J
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
In reply to Jeremy FitzhardingeQuoted 7 lines · Jeremy Fitzhardinge
In fact that file is only built for i386 and
x86_64, so there really is noQuoted 2 lines
problem with using
vmalloc_sync_all()directly and without ifdef.I had moved it to
mm/vmalloc.cin response to previous review comments (namely, its not Xen specific, so it shouldn't live in the Xen part of the tree).
Then the call will have to be CONFIG_X86. I hadn't realised powerpc were also using lock_vm_area. However I suspect that the x86 issue that those functions were written doesn't even exist on powerpc, or any other non-x86 architecture.
I guess we should change the name of alloc_vm_area, by the way. Perhaps alloc_vm_area_sync() or similar, to give some hint of what it's doing and how it differs from other vmalloc-area functions?
-- Keir
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
In reply to Jeremy FitzhardingeQuoted 7 lines · Jeremy Fitzhardinge
In fact that file is only built for i386 and
x86_64, so there really is noQuoted 2 lines
problem with using
vmalloc_sync_all()directly and without ifdef.I had moved it to
mm/vmalloc.cin response to previous review comments (namely, its not Xen specific, so it shouldn't live in the Xen part of the tree).
Then the call will have to be CONFIG_X86. I hadn't realised powerpc were also using lock_vm_area. However I suspect that the x86 issue that those functions were written doesn't even exist on powerpc, or any other non-x86 architecture.
I guess we should change the name of alloc_vm_area, by the way. Perhaps alloc_vm_area_sync() or similar, to give some hint of what it's doing and how it differs from other vmalloc-area functions?
-- Keir
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
In reply to Keir FraserQuoted 11 lines · Keir Fraser
Quoted 3 lines · Jeremy Fitzhardinge
Yes, that would work. Unfortunately that's i386 arch-specific, whereas the rest of this code is generic. I guess I could just move it all to
arch/i386/mm.This whole thing isn't an issue on ia64 (they no-op
lock_vm_area) and powerpc doesn't use any of the Xen driver code at this time.vmalloc_sync_allis supported by both i386 andx86_64, so we can make the call conditional onCONFIG_X86so that ia64 will continue to build. This is what I've done in xen-unstable.
In fact that file is only built for i386 and x86_64, so there really is no problem with using vmalloc_sync_all() directly and without ifdef.
-- Keir
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
In reply to Keir FraserQuoted 11 lines · Keir Fraser
Quoted 3 lines · Jeremy Fitzhardinge
Yes, that would work. Unfortunately that's i386 arch-specific, whereas the rest of this code is generic. I guess I could just move it all to
arch/i386/mm.This whole thing isn't an issue on ia64 (they no-op
lock_vm_area) and powerpc doesn't use any of the Xen driver code at this time.vmalloc_sync_allis supported by both i386 andx86_64, so we can make the call conditional onCONFIG_X86so that ia64 will continue to build. This is what I've done in xen-unstable.
In fact that file is only built for i386 and x86_64, so there really is no problem with using vmalloc_sync_all() directly and without ifdef.
-- Keir
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
In reply to Keir FraserQuoted 10 lines · Keir Fraser
Quoted 3 lines · Jeremy Fitzhardinge
Yes, that would work. Unfortunately that's i386 arch-specific, whereas the rest of this code is generic. I guess I could just move it all to
arch/i386/mm.This whole thing isn't an issue on ia64 (they no-op
lock_vm_area) and powerpc doesn't use any of the Xen driver code at this time.
Not sure what you mean? PowerPC uses pretty much all of the Xen driver
code: event channels, blkfront/back, netfront/back, console, etc.
Signature · 2 lines
Hollis Blanchard IBM Linux Technology Center
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
In reply to Jeremy FitzhardingeQuoted 3 lines · Jeremy Fitzhardinge
Yes, that would work. Unfortunately that's i386 arch-specific, whereas the rest of this code is generic. I guess I could just move it all to
arch/i386/mm.
This whole thing isn't an issue on ia64 (they no-op lock_vm_area) and powerpc doesn't use any of the Xen driver code at this time. vmalloc_sync_all is supported by both i386 and x86_64, so we can make the call conditional on CONFIG_X86 so that ia64 will continue to build. This is what I've done in xen-unstable.
-- Keir
Re: [Xen-devel] Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
In reply to Jeremy FitzhardingeQuoted 3 lines · Jeremy Fitzhardinge
Yes, that would work. Unfortunately that's i386 arch-specific, whereas the rest of this code is generic. I guess I could just move it all to
arch/i386/mm.
This whole thing isn't an issue on ia64 (they no-op lock_vm_area) and powerpc doesn't use any of the Xen driver code at this time. vmalloc_sync_all is supported by both i386 and x86_64, so we can make the call conditional on CONFIG_X86 so that ia64 will continue to build. This is what I've done in xen-unstable.
-- Keir
Re: [patch 12/21] Xen-paravirt: Allocate and free vmalloc areas
In reply to Andrew MortonQuoted 23 lines · Andrew Morton
Quoted 9 lines · On Thu, 15 Feb 2007 23:08:02 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
Quoted 3 lines · Andrew Morton
This won't work when
CONFIG_PREEMPT=y. The pagefault handler will seein_atomic()and will scram.Is there some other way to get the pagetable populated for the address range?
If you really need to run atomically, that gets ugly. Even of one were to run
handle_mm_fault()by hand, it still needs to allocate memory.Two ugly options might be:
a) touch all the pages, then go atomic, then touch them all again. If one of them faults (ie: you raced with swapout) then go back and try again. Obviously susceptible to livelocking.
Quoted 6 lines
b) Do
get_user_pages()against all the pages, then go atomic, then doput_page()against them all. Of course, they can immediately get swapped out.But that function's already racy against swapout and I guess it works OK. I don't have clue what it is actually trying to do, so I'm guessing madly here.
Well its only operating on kernel pages, and against a vmalloc region. So it would be immune to any sort of unmapping or swapout.
Andrew's option a) should work. What's this for, and how is it not Xen specific if nothing else in the tree needs such a weird hack?
Signature · 2 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
PATCH 13/21 Xen-paravirt: Add nosegneg capability to the vsyscall page notes
In reply to Jeremy FitzhardingeAdd the "nosegneg" fake capabilty to the vsyscall page notes. This is used by the runtime linker to select a glibc version which then disables negative-offset accesses to the thread-local segment via %gs. These accesses require emulation in Xen (because segments are truncated to protect the hypervisor address space) and avoiding them provides a measurable performance boost.
--- arch/i386/kernel/vsyscall-note.S | 28 +++++++++++++++++++++++++++++ 1 files changed, 28 insertions(+)
===================================================================
arch/i386/kernel/vsyscall-note.S +28 -0
@@ -23,3 +24,31 @@ 3: .balign 4; /* pad out section */ ASM_ELF_NOTE_BEGIN(".note.kernel-version", "a", UTS_SYSNAME, 0) .long LINUX_VERSION_CODE ASM_ELF_NOTE_END + +#ifdef CONFIG_XEN +/* + * Add a special note telling glibc's dynamic linker a fake hardware + * flavor that it will use to choose the search path for libraries in the + * same way it uses real hardware capabilities like "mmx". + * We supply "nosegneg" as the fake capability, to indicate that we + * do not like negative offsets in instructions using segment overrides, + * since we implement those inefficiently. This makes it possible to + * install libraries optimized to avoid those access patterns in someplace + * like /lib/i686/tls/nosegneg. Note that an /etc/ld.so.conf.d/file + * corresponding to the bits here is needed to make ldconfig work right. + * It should contain: + * hwcap 0 nosegneg + * to match the mapping of bit to name that we give here. + */ +#define NOTE_KERNELCAP_BEGIN(ncaps, mask) \ + ASM_ELF_NOTE_BEGIN(".note.kernelcap", "a", "GNU", 2) \ + .long ncaps, mask +#define NOTE_KERNELCAP(bit, name) \ + .byte bit; .asciz name +#define NOTE_KERNELCAP_END ASM_ELF_NOTE_END + +NOTE_KERNELCAP_BEGIN(1, 1) +NOTE_KERNELCAP(1, "nosegneg") +NOTE_KERNELCAP_END +#endif +
Re: [patch 13/21] Xen-paravirt: Add nosegneg capability to the vsyscall page notes
Quoted 11 lines · Jeremy Fitzhardinge
Add the "nosegneg" fake capabilty to the vsyscall page notes. This is used by the runtime linker to select a glibc version which then disables negative-offset accesses to the thread-local segment via %gs. These accesses require emulation in Xen (because segments are truncated to protect the hypervisor address space) and avoiding them provides a measurable performance boost.
Signed-off-by Ian Pratt <[email protected]>Signed-off-by Christian Limpach <[email protected]>Signed-off-by Chris Wright <[email protected]>
We would like to see this by dynamic, but that is much more difficult to achieve, and seeing your recent linker issues, I don't think this should gate merging this code. The performance loss for us I believe to be negligible, and the fix is quite a bit more complicated than something achievable in the .21 timeframe.
Zach
PATCH 14/21 Xen-paravirt: Add XEN config options and disable unsupported config options.
In reply to Jeremy FitzhardingeThe XEN config option enables the Xen paravirt_ops interface, which is installed when the kernel finds itself running under Xen. (By some as-yet fully defined mechanism, implemented in a future patch.)
Xen is no longer a sub-architecture, so the X86_XEN subarch config option has gone.
The disabled config options are:
- PREEMPT: Xen doesn't support it
- HZ: set to 100Hz for now, to cut down on VCPU context switch rate. This will be adapted to use tickless later.
- kexec: not yet supported
--- arch/i386/Kconfig | 7 +++++-- arch/i386/Kconfig.debug | 1 + arch/i386/xen/Kconfig | 10 ++++++++++ kernel/Kconfig.hz | 4 ++-- kernel/Kconfig.preempt | 1 + 5 files changed, 19 insertions(+), 4 deletions(-)
===================================================================
arch/i386/Kconfig +5 -2
@@ -192,6 +192,8 @@ config PARAVIRT under a hypervisor, improving performance significantly. However, when run without a hypervisor the kernel is theoretically slower. If in doubt, say N. + +source "arch/i386/xen/Kconfig" config ACPI_SRAT bool
@@ -298,12 +300,12 @@ config X86_UP_IOAPIC config X86_LOCAL_APIC bool - depends on X86_UP_APIC || ((X86_VISWS || SMP) && !X86_VOYAGER) || X86_GENERICARCH + depends on X86_UP_APIC || (((X86_VISWS || SMP) && !X86_VOYAGER) || X86_GENERICARCH) default y config X86_IO_APIC bool - depends on X86_UP_IOAPIC || (SMP && !(X86_VISWS || X86_VOYAGER)) || X86_GENERICARCH + depends on X86_UP_IOAPIC || ((SMP && !(X86_VISWS || X86_VOYAGER)) || X86_GENERICARCH) default y config X86_VISWS_APIC
@@ -743,6 +745,7 @@ source kernel/Kconfig.hz config KEXEC bool "kexec system call" + depends on !XEN help kexec is a system call that implements the ability to shutdown your current kernel, and to start another kernel. It is like a reboot
===================================================================
arch/i386/Kconfig.debug +1 -0
@@ -79,6 +79,7 @@ config DOUBLEFAULT config DOUBLEFAULT default y bool "Enable doublefault exception handler" if EMBEDDED + depends on !XEN help This option allows trapping of rare doublefault exceptions that would otherwise cause a system to silently reboot. Disabling this
===================================================================
arch/i386/xen/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +# +# This Kconfig describes xen options +# + +config XEN + bool "Enable support for Xen hypervisor" + depends PARAVIRT + default y + help + This is the Linux Xen port.
===================================================================
kernel/Kconfig.hz +2 -2
@@ -3,7 +3,7 @@ # choice - prompt "Timer frequency" + prompt "Timer frequency" if !XEN default HZ_250 help Allows the configuration of the timer frequency. It is customary
@@ -49,7 +49,7 @@ endchoice config HZ int - default 100 if HZ_100 + default 100 if HZ_100 || XEN default 250 if HZ_250 default 300 if HZ_300 default 1000 if HZ_1000
===================================================================
kernel/Kconfig.preempt +1 -0
@@ -35,6 +35,7 @@ config PREEMPT_VOLUNTARY config PREEMPT bool "Preemptible Kernel (Low-Latency Desktop)" + depends on !XEN help This option reduces the latency of the kernel by making all kernel code (that is not executing in a critical section)
Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
Quoted 57 lines · Jeremy Fitzhardinge
The XEN config option enables the Xen
paravirt_opsinterface, which is installed when the kernel finds itself running under Xen. (By some as-yet fully defined mechanism, implemented in a future patch.)Xen is no longer a sub-architecture, so the
X86_XENsubarch config option has gone.The disabled config options are:
- PREEMPT: Xen doesn't support it
- HZ: set to 100Hz for now, to cut down on VCPU context switch rate. This will be adapted to use tickless later.
- kexec: not yet supportedconfig KEXEC
kernel/Kconfig.hz +10
-2bool "kexec system call" + depends on !XEN help kexec is a system call that implements the ability to shutdown your current kernel, and to start another kernel. It is like a reboot config DOUBLEFAULT default y bool "Enable doublefault exception handler" if EMBEDDED + depends on !XEN help This option allows trapping of rare doublefault exceptions that would otherwise cause a system to silently reboot. Disabling this +config XEN + bool "Enable support for Xen hypervisor" + depends PARAVIRT + default y + help + This is the Linux Xen port. choice - prompt "Timer frequency" + prompt "Timer frequency" if !XEN default HZ_250 help Allows the configuration of the timer frequency. It is customary@@ -49,7 +49,7 @@ endchoice config HZ int - default 100 if HZ_100 + default 100 if HZ_100 || XEN default 250 if HZ_250 default 300 if HZ_300 default 1000 if HZ_1000config PREEMPT
kernel/Kconfig.preempt config PREEMPT_VOLUNTARY · line 41
Quoted 5 lines
kernel/Kconfig.preempt +1
-0bool "Preemptible Kernel (Low-Latency Desktop)" + depends on !XEN help This option reduces the latency of the kernel by making all kernel code (that is not executing in a critical section)
I hate to sound like a broken record, but this really isn't the right way to do this. If you are going to inhibit config settings when Xen support is compiled, then it should be:
config XEN
depends on !KEXEC && !DOUBLEFAULT && HZ_100 && !PREEMPT
I'm really not trying to make things more difficult for you or for Xen users.
One of the primary goals of paravirt-ops is to allow the same kernel binary to bind to multiple hypervisor interfaces (and native), at runtime. So, we should assume that kernels which are built with CONFIG_PARAVIRT will also enable all the paravirt-ops backends; and this is a good thing.
But, the problem is, then, when someone enables paravirt (and all the backends, including Xen), you are silently forcing all these options off. Compiling in paravirt support should not change force you into using some set of config option; when a paravirt-ops kernel is run on native, it should be as fully featured as a non-paravirtops kernel.
So, this should really be solved (in order of preference) by:
1) Complete the xen paravirt-ops backend so it can handle these "incompatible" options. I realize this is just a matter of time (at least for most of them, what is your plan for PREEMPT?).
2) Disable the option at runtime only if the kernel is booted on Xen. When the kernel is booted on native, lhype, paravirt kvm, vmware, etc it should be not be inhibited. This may not be feasible for all of these options, but as Zach pointed out, is easy enough for DOUBLEFAULT. Maybe it can be done for KEXEC? And HZ is easy to allow too, even though Xen will still give interrupts at 100hz -- we do this when you boot on VMI. PREEMPT is probably the only real compile time incompatible options
with Xen. You just simply have to change the loop decrementors in your timer interrupt.
You basically chose #2 for SMP: while your backend doesn't support it yet, it's not harmful to have the config option enabled; you just don't allow a second vcpu to startup when running on Xen.
3) Use the config XEN line I suggest above. The net effect is the same as your proposed change (it prevents users from compiling the incompatible options together), but at least the user understands what is going on, instead of options just silently changing on them.
Dan
Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
Quoted 3 lines · Dan Hecht
1) Complete the xen paravirt-ops backend so it can handle these "incompatible" options. I realize this is just a matter of time (at least for most of them, what is your plan for PREEMPT?).
Hope it will go away? There's some relatively deep reason to do with migration which makes preempt very difficult to support, but I've forgotten the details. I've been wondering if there's some way to make it runtime selectable without massive performance cost.
Quoted 10 lines
2) Disable the option at runtime only if the kernel is booted on Xen. When the kernel is booted on native, lhype, paravirt kvm, vmware, etc it should be not be inhibited. This may not be feasible for all of these options, but as Zach pointed out, is easy enough for DOUBLEFAULT. Maybe it can be done for KEXEC? And HZ is easy to allow too, even though Xen will still give interrupts at 100hz -- we do this when you boot on VMI. PREEMPT is probably the only real compile time incompatible options with Xen. You just simply have to change the loop decrementors in your timer interrupt.
Quoted 3 lines
You basically chose #2 for SMP: while your backend doesn't support it yet, it's not harmful to have the config option enabled; you just don't allow a second vcpu to startup when running on Xen.
Yes, this has been my preferred approach. So for each of the restrictions:
PREEMPT - hard, will try to do something at runtime
HZ - I'm assuming dynticks will appear in the short term, and this will become moot
KEXEC - there's been some work on making KEXEC and Xen play nicely together; I was waiting to see if that matures, and/or make it runtime switchable in the meantime
DOUBLEFAULT - not really an issue; guests won't get them under Xen (I think) and we can ignore setting the gate pretty easily
J
Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
Quoted 2 lines · Jeremy Fitzhardinge
HZ - I'm assuming dynticks will appear in the short term, and this will become moot
Doesn't Xen send any non-blocked domain a 100hz alarm implicitly, without anyway for the guest to disable it? I guess you'll have to break kernel/hypervisor compatibility if you want dynticks?
Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
Quoted 7 lines · Dan Hecht
Quoted 2 lines · Jeremy Fitzhardinge
HZ - I'm assuming dynticks will appear in the short term, and this will become moot
Doesn't Xen send any non-blocked domain a 100hz alarm implicitly, without anyway for the guest to disable it? I guess you'll have to break kernel/hypervisor compatibility if you want dynticks?
The timer VIRQ will generate events at a fixed 100Hz (which can be masked, like any other event), but you can also ask for a timer event at a particular time. We do this already for tickless idle.
J
Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
Quoted 8 lines · Jeremy Fitzhardinge
Quoted 6 lines · Dan Hecht
Quoted 2 lines · Jeremy Fitzhardinge
HZ - I'm assuming dynticks will appear in the short term, and this will become moot
Doesn't Xen send any non-blocked domain a 100hz alarm implicitly, without anyway for the guest to disable it? I guess you'll have to break kernel/hypervisor compatibility if you want dynticks?
Quoted 6 lines
The timer VIRQ will generate events at a fixed 100Hz (which can be masked, like any other event), but you can also ask for a timer event at a particular time. We do this already for tickless idle.
J
Hmm? I thought the periodic timer and one-shot timer both generate the same VIRQ. So, how can you mask one without masking the other?
The tickless idle works since the block hypercall disables the periodic timer. But for dynticks (aka NO_HZ), you'll need to mask the periodic timer (even for a running vcpu), while keeping the one-shot timer unmasked. I don't think Xen provides an interface to do that.
Dan
Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
Quoted 7 lines · Dan Hecht
Hmm? I thought the periodic timer and one-shot timer both generate the same VIRQ. So, how can you mask one without masking the other?
The tickless idle works since the block hypercall disables the periodic timer. But for dynticks (aka
NO_HZ), you'll need to mask the periodic timer (even for a running vcpu), while keeping the one-shot timer unmasked. I don't think Xen provides an interface to do that.
There's no interface for this right now, but we can easily add one in a backward compatible way. This also will not prevent a dyntick kernel from running on an older Xen -- the guest will then receive to many timer interrupts, but that should only be a performance concern fixable by upgrading the hypervisor component of the system.
-- Keir
Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
In reply to Dan HechtQuoted 7 lines · Dan Hecht
Hmm? I thought the periodic timer and one-shot timer both generate the same VIRQ. So, how can you mask one without masking the other?
The tickless idle works since the block hypercall disables the periodic timer. But for dynticks (aka
NO_HZ), you'll need to mask the periodic timer (even for a running vcpu), while keeping the one-shot timer unmasked. I don't think Xen provides an interface to do that.
There's no interface for this right now, but we can easily add one in a backward compatible way. This also will not prevent a dyntick kernel from running on an older Xen -- the guest will then receive to many timer interrupts, but that should only be a performance concern fixable by upgrading the hypervisor component of the system.
-- Keir
Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
In reply to Dan HechtQuoted 7 lines · Dan Hecht
Hmm? I thought the periodic timer and one-shot timer both generate the same VIRQ. So, how can you mask one without masking the other?
The tickless idle works since the block hypercall disables the periodic timer. But for dynticks (aka
NO_HZ), you'll need to mask the periodic timer (even for a running vcpu), while keeping the one-shot timer unmasked. I don't think Xen provides an interface to do that.
There's no interface for this right now, but we can easily add one in a backward compatible way. This also will not prevent a dyntick kernel from running on an older Xen -- the guest will then receive to many timer interrupts, but that should only be a performance concern fixable by upgrading the hypervisor component of the system.
-- Keir
Andrew Morton
maintainerRe: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
In reply to Dan HechtQuoted 7 lines · On Thu, 15 Feb 2007 22:14:45 -0800 Dan Hecht <[email protected]> wrote:
kernel/Kconfig.preempt config PREEMPT_VOLUNTARY · line 41
Quoted 7 lines
config PREEMPT
kernel/Kconfig.preempt +1
-0bool "Preemptible Kernel (Low-Latency Desktop)" + depends on !XEN help This option reduces the latency of the kernel by making all kernel code (that is not executing in a critical section)
Oh, so that's why it doesn't break when CONFIG_PREEMPT=y. In which case that preempt_disable() I spotted is wrong-and-unneeded.
Why doesn't Xen work with preemption??
Quoted 7 lines
I hate to sound like a broken record, but this really isn't the right way to do this. If you are going to inhibit config settings when Xen support is compiled, then it should be:
config XEN
depends on !KEXEC && !DOUBLEFAULT && HZ_100 && !PREEMPT
Agree.
Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
Quoted 15 lines · Andrew Morton
Quoted 8 lines · On Thu, 15 Feb 2007 22:14:45 -0800 Dan Hecht <[email protected]> wrote:
kernel/Kconfig.preempt config PREEMPT_VOLUNTARY · line 41
Quoted 8 lines
config PREEMPT
kernel/Kconfig.preempt +1
-0bool "Preemptible Kernel (Low-Latency Desktop)" + depends on !XEN help This option reduces the latency of the kernel by making all kernel code (that is not executing in a critical section)Oh, so that's why it doesn't break when
CONFIG_PREEMPT=y. In which case thatpreempt_disable()I spotted is wrong-and-unneeded.
Quoted 2 lines
Why doesn't Xen work with preemption??
I've forgotten the details. Ian? Keir? Steven? Maybe it can be done.
J
Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
Quoted 6 lines · Jeremy Fitzhardinge
Quoted 4 lines
Oh, so that's why it doesn't break when
CONFIG_PREEMPT=y. In which case thatpreempt_disable()I spotted is wrong-and-unneeded.Why doesn't Xen work with preemption??
I've forgotten the details. Ian? Keir? Steven? Maybe it can be done.
It breaks guest save/restore for us currently because threads can be sleeping with machine addresses in local storage (registers, stack). There are a few ways to achieve an acceptable solution:
1. Put processes in the freezer when we suspend. This should avoid any
thread being in a critical section with machine addresses in its hand. We haven't yet investigated the performance impact of freezing processes, particularly on the downtime of live relocation.
2. Allow CONFIG_PREEMPT to be compiled in, but disable it at runtime. We
could do this by, for example, reserving a bit in preempt_count() so that most preemption checks do not touch any more cache lines. I guess it would need a bit of fixing up (e.g., so that in_atomic() would not be always asserted). Even better for us would be to allow switching between involuntary and voluntary preemption at runtime. It looks as though the hook points for these two techniques are not usually compiled in at the same time, however.
-- Keir
Re: [Xen-devel] Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
Quoted 20 lines · Keir Fraser
Quoted 7 lines · Jeremy Fitzhardinge
Quoted 5 lines
Oh, so that's why it doesn't break when
CONFIG_PREEMPT=y. In which case thatpreempt_disable()I spotted is wrong-and-unneeded.Why doesn't Xen work with preemption??
I've forgotten the details. Ian? Keir? Steven? Maybe it can be done.
It breaks guest save/restore for us currently because threads can be sleeping with machine addresses in local storage (registers, stack). There are a few ways to achieve an acceptable solution:
1. Put processes in the freezer when we suspend. This should avoid any
thread being in a critical section with machine addresses in its hand. We haven't yet investigated the performance impact of freezing processes, particularly on the downtime of live relocation.
Quoted 10 lines
2. Allow
CONFIG_PREEMPTto be compiled in, but disable it at runtime. We
could do this by, for example, reserving a bit inpreempt_count()so that most preemption checks do not touch any more cache lines. I guess it would need a bit of fixing up (e.g., so thatin_atomic()would not be always asserted). Even better for us would be to allow switching between involuntary and voluntary preemption at runtime. It looks as though the hook points for these two techniques are not usually compiled in at the same time, however.
Doesn't stop_machine_run already take care of getting you out of all kernel threads? So you can only be sleeping, not preempted, in which case, this might not be an issue?
Zach
Re: [Xen-devel] Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
Quoted 3 lines · Zachary Amsden
Doesn't
stop_machine_runalready take care of getting you out of all kernel threads? So you can only be sleeping, not preempted, in which case, this might not be an issue?
It ensures that no (non-stopmachine) threads are running on any of the other CPUs, but it doesn't guarantee that all threads are at any form of quiescent point. They can certainly have private references to machine addresses.
Otherwise, what would be the point of the process freezer? :-)
-- Keir
Re: [Xen-devel] Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
Quoted 8 lines · Keir Fraser
Quoted 4 lines · Zachary Amsden
Doesn't
stop_machine_runalready take care of getting you out of all kernel threads? So you can only be sleeping, not preempted, in which case, this might not be an issue?
Quoted 6 lines
It ensures that no (non-stopmachine) threads are running on any of the other CPUs, but it doesn't guarantee that all threads are at any form of quiescent point. They can certainly have private references to machine addresses.
Otherwise, what would be the point of the process freezer? :-)
Yeah, I was over-hoping on that one. At least thought it was worth suggesting as a starting point. I had similar issues considering loading VMI as a module at runtime.
Zach
Re: [Xen-devel] Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
In reply to Zachary AmsdenQuoted 3 lines · Zachary Amsden
Doesn't
stop_machine_runalready take care of getting you out of all kernel threads? So you can only be sleeping, not preempted, in which case, this might not be an issue?
No, stop_machine only protects against preempt-disabled regions.
I thought about making that particularly hammer bigger, but noone had needed it yet. It would simply require a runtime way of disabling further preemption and flushing preempted threads (AFAICT there can be no deadlock issues with this).
Rusty.
Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
In reply to Jeremy FitzhardingeQuoted 13 lines · Jeremy Fitzhardinge
The XEN config option enables the Xen
paravirt_opsinterface, which is installed when the kernel finds itself running under Xen. (By some as-yet fully defined mechanism, implemented in a future patch.)Xen is no longer a sub-architecture, so the
X86_XENsubarch config option has gone.The disabled config options are:
- PREEMPT: Xen doesn't support it
- HZ: set to 100Hz for now, to cut down on VCPU context switch rate. This will be adapted to use tickless later.
- kexec: not yet supported
Quoted 5 lines
Signed-off-by Jeremy Fitzhardinge <[email protected]>Signed-off-by Ian Pratt <[email protected]>Signed-off-by Christian Limpach <[email protected]>Signed-off-by Chris Wright <[email protected]>
We do support different HZ values, although 100HZ is actually preferable for us, so I don't object to that. PREEMPT is supported by us, but not as tested as I would like, so I also don't object to dropping it for generic paravirt guests - Rusty - Avi any objections to dropping preempt in terms of lguest/KVM paravirtualization?
Paravirt-ops definitely needs a hook for kexec, although we should not disable kexec for the natively booted paravirt-ops. Eric - is there a way to disable it at runtime?
We do support the doublefault task gate, and it would be good to keep it, but I can't complain so much if it is gone from generic paravirt kernels for now, because it is non-essential, and generally fatal anyway. We do need it for native boots of paravirt-ops kernels, however, so turning off the config option still needs to be revisited.
Zach
Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
Quoted 11 lines · Zachary Amsden
We do support different HZ values, although 100HZ is actually preferable for us, so I don't object to that. PREEMPT is supported by us, but not as tested as I would like, so I also don't object to dropping it for generic paravirt guests - Rusty - Avi any objections to dropping preempt in terms of lguest/KVM paravirtualization?
Paravirt-ops definitely needs a hook for kexec, although we should not disable kexec for the natively booted paravirt-ops. Eric - is there a way to disable it at runtime?
Quoted 5 lines
We do support the doublefault task gate, and it would be good to keep it, but I can't complain so much if it is gone from generic paravirt kernels for now, because it is non-essential, and generally fatal anyway. We do need it for native boots of paravirt-ops kernels, however, so turning off the config option still needs to be revisited
Have machine_kexec_prepare fail.
I think your machine description or paravirt_ops or whatever it is needs to hook both machine_kexec_prepare and machine_kexec.
I know there actually has been some work to get kexec actually working under Xen but I don't know where that has gone.
Eric
Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
Quoted 2 lines · Eric W. Biederman
I know there actually has been some work to get kexec actually working under Xen but I don't know where that has gone.
kexec/kdump works with Xen 3.0.4 but it's a dom0 only thing so it doesn't appear in this patchset.
Ian.
Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
Quoted 6 lines · Ian Campbell
Quoted 2 lines · Eric W. Biederman
I know there actually has been some work to get kexec actually working under Xen but I don't know where that has gone.
kexec/kdump works with Xen 3.0.4 but it's a dom0 only thing so it doesn't appear in this patchset.
Ok but we still need to get the failure to user space for domU instead of trying what works on real hardware and failing.
Eric
Zachary Amsden
Acked-byRe: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
Quoted 8 lines · Eric W. Biederman
Quoted 5 lines · Ian Campbell
Quoted 3 lines · Eric W. Biederman
I know there actually has been some work to get kexec actually working under Xen but I don't know where that has gone.
Quoted 8 lines
Quoted 3 lines
kexec/kdump works with Xen 3.0.4 but it's a dom0 only thing so it doesn't appear in this patchset.
Ok but we still need to get the failure to user space for domU instead of trying what works on real hardware and failing.
Eric
Re: [Xen-devel] Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
In reply to Eric W. BiedermanQuoted 7 lines · Eric W. Biederman
Have
machine_kexec_preparefail.I think your machine description or
paravirt_opsor whatever it is needs to hook bothmachine_kexec_prepareandmachine_kexec.I know there actually has been some work to get kexec actually working under Xen but I don't know where that has gone.
Works, modulo bugs. Shouldn't be hard to get work on top of paravirt_ops. The current 2.6.18 code uses function pointers already because the dom0 code looks very different from domU code. It is one of the items on my todo list. I'll probably look into it once I'm done with the earlyprintk and console mess ...
cheers,
Gerd
Signature · 1 line
Gerd Hoffmann <[email protected]>
Re: [patch 14/21] Xen-paravirt: Add XEN config options and disable unsupported config options.
In reply to Zachary AmsdenQuoted 14 lines · Zachary Amsden
Quoted 13 lines · Jeremy Fitzhardinge
The XEN config option enables the Xen
paravirt_opsinterface, which is installed when the kernel finds itself running under Xen. (By some as-yet fully defined mechanism, implemented in a future patch.)Xen is no longer a sub-architecture, so the
X86_XENsubarch config option has gone.The disabled config options are:
- PREEMPT: Xen doesn't support it
- HZ: set to 100Hz for now, to cut down on VCPU context switch rate. This will be adapted to use tickless later.
- kexec: not yet supported
Quoted 7 lines
Quoted 5 lines
Signed-off-by Jeremy Fitzhardinge <[email protected]>Signed-off-by Ian Pratt <[email protected]>Signed-off-by Christian Limpach <[email protected]>Signed-off-by Chris Wright <[email protected]>We do support different HZ values, although 100HZ is actually preferable for us, so I don't object to that.
Ditto for kvm.
Quoted 1 line
PREEMPT is supported by us, but not as tested as I would like, so I also don't object to dropping it for generic paravirt guests - Rusty - Avi any objections to dropping preempt in terms of lguest/KVM paravirtualization?
I don't have any objections myself, but Ingo (who has done the bulk of the kvm paravirt work; cc'ed) uses PREEMPT_RT, so he will certainly object.
Quoted 2 lines
Paravirt-ops definitely needs a hook for kexec, although we should not disable kexec for the natively booted paravirt-ops. Eric - is there a way to disable it at runtime?
kvm paravirt should work correctly with kexec.
Quoted 2 lines
We do support the doublefault task gate, and it would be good to keep it, but I can't complain so much if it is gone from generic paravirt kernels for now, because it is non-essential, and generally fatal anyway. We do need it for native boots of paravirt-ops kernels, however, so turning off the config option still needs to be revisited.
kvm doesn't support task gates (a task switch will immediately kill the guest).
Signature · 1 line
error compiling committee.c: too many arguments to function
PATCH 15/21 Xen-paravirt: Add Xen interface header files
In reply to Jeremy FitzhardingeAdd Xen interface header files. These are taken fairly directly from the Xen tree and hence the style is not entirely in accordance with Linux guidelines. There is a tension between fitting with Linux coding rules and ease of maintenance.
Define macros and inline functions for doing hypercalls into the hypervisor.
--
include/asm-i386/hypercall.h | 416 +++++++++++++++++++++++++++++ include/asm-i386/hypervisor.h | 72 +++++ include/xen/interface/arch-x86_32.h | 187 +++++++++++++ include/xen/interface/elfnote.h | 133 +++++++++ include/xen/interface/event_channel.h | 195 ++++++++++++++ include/xen/interface/features.h | 43 +++ include/xen/interface/grant_table.h | 301 +++++++++++++++++++++ include/xen/interface/io/blkif.h | 96 ++++++ include/xen/interface/io/console.h | 23 + include/xen/interface/io/netif.h | 152 ++++++++++ include/xen/interface/io/ring.h | 260 ++++++++++++++++++ include/xen/interface/io/xenbus.h | 42 +++ include/xen/interface/io/xs_wire.h | 87 ++++++ include/xen/interface/memory.h | 145 ++++++++++ include/xen/interface/physdev.h | 61 ++++ include/xen/interface/sched.h | 77 +++++ include/xen/interface/vcpu.h | 109 +++++++ include/xen/interface/version.h | 60 ++++ include/xen/interface/xen.h | 445 ++++++++++++++++++++++++++++++++ 19 files changed, 2904 insertions(+)
===================================================================
include/asm-i386/xen/hypercall.h new file +413 -0
@@ -0,0 +1,413 @@ +/****************************************************************************** +* hypercall.h +* +* Linux-specific hypervisor handling. +* +* Copyright (c) 2002-2004, K A Fraser +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License version 2 +* as published by the Free Software Foundation; or, when distributed +* separately from the Linux kernel or incorporated into other +* software packages, subject to the following license: +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this source file (the "Software"), to deal in the Software without +* restriction, including without limitation the rights to use, copy, modify, +* merge, publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +* IN THE SOFTWARE. +*/ + +#ifndef __HYPERCALL_H__ +#define __HYPERCALL_H__ + +#include <linux/errno.h> +#include <linux/string.h> + +#include <xen/interface/xen.h> +#include <xen/interface/sched.h> +#include <xen/interface/physdev.h> + +extern struct {char _entry[32 ]; } hypercall_page[]; + +#define _hypercall0 (type, name) \ +({ \ + long __res; \ + asm volatile ( \ + "call %[call]" \ + : "=a" (__res) \ + : [call] "m" (hypercall_page[__HYPERVISOR_##name]) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall1 (type, name, a1) \ +({ \ + long __res, __ign1; \ + asm volatile ( \ + "call %[call]" \ + : "=a" (__res), "=b" (__ign1) \ + : "1" ((long)(a1)), \ + [call] "m" (hypercall_page[__HYPERVISOR_##name]) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall2 (type, name, a1, a2) \ +({ \ + long __res, __ign1, __ign2; \ + asm volatile ( \ + "call %[call]" \ + : "=a" (__res), "=b" (__ign1), "=c" (__ign2) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + [call] "m" (hypercall_page[__HYPERVISOR_##name]) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall3 (type, name, a1, a2, a3) \ +({ \ + long __res, __ign1, __ign2, __ign3; \ + asm volatile ( \ + "call %[call]" \ + : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ + "=d" (__ign3) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)), \ + [call] "m" (hypercall_page[__HYPERVISOR_##name]) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall4 (type, name, a1, a2, a3, a4) \ +({ \ + long __res, __ign1, __ign2, __ign3, __ign4; \ + asm volatile ( \ + "call %[call]" \ + : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ + "=d" (__ign3), "=S" (__ign4) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)), "4" ((long)(a4)), \ + [call] "m" (hypercall_page[__HYPERVISOR_##name]) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall5 (type, name, a1, a2, a3, a4, a5) \ +({ \ + long __res, __ign1, __ign2, __ign3, __ign4, __ign5; \ + asm volatile ( \ + "call %[call]" \ + : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ + "=d" (__ign3), "=S" (__ign4), "=D" (__ign5) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)), "4" ((long)(a4)), \ + "5" ((long)(a5)), \ + [call] "m" (hypercall_page[__HYPERVISOR_##name]) \ + : "memory" ); \ + (type)__res; \ +}) + +static inline int +HYPERVISOR_set_trap_table ( +struct trap_info *table) +{ +return _hypercall1 (int, set_trap_table, table); +} + +static inline int +HYPERVISOR_mmu_update ( +struct mmu_update *req,int count,int *success_count,domid_t domid) +{ +return _hypercall4 (int, mmu_update, req, count, success_count, domid); +} + +static inline int +HYPERVISOR_mmuext_op ( +struct mmuext_op *op,int count,int *success_count,domid_t domid) +{ +return _hypercall4 (int, mmuext_op, op, count, success_count, domid); +} + +static inline int +HYPERVISOR_set_gdt ( +unsigned long *frame_list,int entries) +{ +return _hypercall2 (int, set_gdt, frame_list, entries); +} + +static inline int +HYPERVISOR_stack_switch ( +unsigned long ss,unsigned long esp) +{ +return _hypercall2 (int, stack_switch, ss, esp); +} + +static inline int +HYPERVISOR_set_callbacks ( +unsigned long event_selector,unsigned long event_address, +unsigned long failsafe_selector,unsigned long failsafe_address) +{ +return _hypercall4 (int, set_callbacks, + event_selector, event_address, + failsafe_selector, failsafe_address); +} + +static inline int +HYPERVISOR_fpu_taskswitch ( +int set) +{ +return _hypercall1 (int, fpu_taskswitch, set); +} + +static inline int +HYPERVISOR_sched_op ( +int cmd,unsigned long arg) +{ +return _hypercall2 (int, sched_op, cmd, arg); +} + +static inline long +HYPERVISOR_set_timer_op ( +u64 timeout) +{ +unsigned long timeout_hi = (unsigned long )(timeout>>32 ); +unsigned long timeout_lo = (unsigned long )timeout; +return _hypercall2 (long, set_timer_op, timeout_lo, timeout_hi); +} + +static inline int +HYPERVISOR_set_debugreg ( +int reg,unsigned long value) +{ +return _hypercall2 (int, set_debugreg, reg, value); +} + +static inline unsigned long +HYPERVISOR_get_debugreg ( +int reg) +{ + return _hypercall1(unsigned long, get_debugreg, reg); +} + +static inline int +HYPERVISOR_update_descriptor ( +u64 ma,u64 desc) +{ +return _hypercall4 (int, update_descriptor, ma, ma>>32 , desc, desc>>32 ); +} + +static inline int +HYPERVISOR_memory_op ( +unsigned int cmd,void *arg) +{ +return _hypercall2 (int, memory_op, cmd, arg); +} + +static inline int +HYPERVISOR_multicall ( +void *call_list,int nr_calls) +{ +return _hypercall2 (int, multicall, call_list, nr_calls); +} + +static inline int +HYPERVISOR_update_va_mapping ( +unsigned long va,pte_t new_val,unsigned long flags) +{ +unsigned long pte_hi =0 ; +#ifdef CONFIG_X86_PAE + pte_hi = new_val.pte_high; +#endif +return _hypercall4 (int, update_va_mapping, va, + new_val.pte_low, pte_hi, flags); +} + +static inline int +HYPERVISOR_event_channel_op ( +int cmd,void *arg) +{ +int rc =_hypercall2 (int, event_channel_op, cmd, arg); +if (unlikely (rc == -ENOSYS )) { +struct evtchn_op op; + op.cmd = cmd; +memcpy (&op.u, arg,sizeof (op.u)); + rc =_hypercall1 (int, event_channel_op_compat, &op); +memcpy (arg, &op.u,sizeof (op.u)); + } +return rc; +} + +static inline int +HYPERVISOR_xen_version ( +int cmd,void *arg) +{ +return _hypercall2 (int, xen_version, cmd, arg); +} + +static inline int +HYPERVISOR_console_io ( +int cmd,int count,char *str) +{ +return _hypercall3 (int, console_io, cmd, count, str); +} + +static inline int +HYPERVISOR_physdev_op (int cmd,void *arg) +{ +int rc =_hypercall2 (int, physdev_op, cmd, arg); +if (unlikely (rc == -ENOSYS )) { +struct physdev_op op; + op.cmd = cmd; +memcpy (&op.u, arg,sizeof (op.u)); + rc =_hypercall1 (int, physdev_op_compat, &op); +memcpy (arg, &op.u,sizeof (op.u)); + } +return rc; +} + +static inline int +HYPERVISOR_grant_table_op ( +unsigned int cmd,void *uop,unsigned int count) +{ +return _hypercall3 (int, grant_table_op, cmd, uop, count); +} + +static inline int +HYPERVISOR_update_va_mapping_otherdomain ( +unsigned long va,pte_t new_val,unsigned long flags,domid_t domid) +{ +unsigned long pte_hi =0 ; +#ifdef CONFIG_X86_PAE + pte_hi = new_val.pte_high; +#endif +return _hypercall5 (int, update_va_mapping_otherdomain, va, + new_val.pte_low, pte_hi, flags, domid); +} + +static inline int +HYPERVISOR_vm_assist ( +unsigned int cmd,unsigned int type) +{ +return _hypercall2 (int, vm_assist, cmd, type); +} + +static inline int +HYPERVISOR_vcpu_op ( +int cmd,int vcpuid,void *extra_args) +{ +return _hypercall3 (int, vcpu_op, cmd, vcpuid, extra_args); +} + +static inline int +HYPERVISOR_suspend ( +unsigned long srec) +{ +return _hypercall3 (int, sched_op, SCHEDOP_shutdown, + SHUTDOWN_suspend, srec); +} + +static inline int +HYPERVISOR_nmi_op ( +unsigned long op, +unsigned long arg) +{ +return _hypercall2 (int, nmi_op, op, arg); +} + +static inline void +MULTI_update_va_mapping (struct multicall_entry *mcl,unsigned long va, +pte_t new_val,unsigned long flags) +{ + mcl->op = __HYPERVISOR_update_va_mapping; + mcl->args[0 ] = va; +#ifdef CONFIG_X86_PAE + mcl->args[1 ] = new_val.pte_low; + mcl->args[2 ] = new_val.pte_high; +#else + mcl->args[1 ] = new_val.pte_low; + mcl->args[2 ] =0 ; +#endif + mcl->args[3 ] = flags; +} + +static inline void +MULTI_grant_table_op (struct multicall_entry *mcl,unsigned int cmd, +void *uop,unsigned int count) +{ + mcl->op = __HYPERVISOR_grant_table_op; + mcl->args[0 ] = cmd; + mcl->args[1 ] = (unsigned long )uop; + mcl->args[2 ] = count; +} + +static inline void +MULTI_update_va_mapping_otherdomain (struct multicall_entry *mcl,unsigned long va, +pte_t new_val,unsigned long flags,domid_t domid) +{ + mcl->op = __HYPERVISOR_update_va_mapping_otherdomain; + mcl->args[0 ] = va; +#ifdef CONFIG_X86_PAE + mcl->args[1 ] = new_val.pte_low; + mcl->args[2 ] = new_val.pte_high; +#else + mcl->args[1 ] = new_val.pte_low; + mcl->args[2 ] =0 ; +#endif + mcl->args[3 ] = flags; + mcl->args[4 ] = domid; +} + +static inline void +MULTI_update_descriptor (struct multicall_entry *mcl,u64 maddr, +struct desc_struct desc) +{ + mcl->op = __HYPERVISOR_update_descriptor; + mcl->args[0 ] = maddr; + mcl->args[1 ] = maddr >>32 ; + mcl->args[2 ] = desc.a; + mcl->args[3 ] = desc.b; +} + +static inline void +MULTI_memory_op (struct multicall_entry *mcl,unsigned int cmd,void *arg) +{ + mcl->op = __HYPERVISOR_memory_op; + mcl->args[0 ] = cmd; + mcl->args[1 ] = (unsigned long )arg; +} + +static inline void +MULTI_mmu_update (struct multicall_entry *mcl,struct mmu_update *req, +int count,int *success_count,domid_t domid) +{ + mcl->op = __HYPERVISOR_mmu_update; + mcl->args[0 ] = (unsigned long )req; + mcl->args[1 ] = count; + mcl->args[2 ] = (unsigned long )success_count; + mcl->args[3 ] = domid; +} + +static inline void +MULTI_mmuext_op (struct multicall_entry *mcl,struct mmuext_op *op,int count, +int *success_count,domid_t domid) +{ + mcl->op = __HYPERVISOR_mmuext_op; + mcl->args[0 ] = (unsigned long )op; + mcl->args[1 ] = count; + mcl->args[2 ] = (unsigned long )success_count; + mcl->args[3 ] = domid; +} +#endif /* __HYPERCALL_H__ */
===================================================================
include/asm-i386/xen/hypervisor.h new file +72 -0
72 lines not on this page · raw message
===================================================================
include/asm-i386/xen/interface.h new file +187 -0
187 lines not on this page · raw message
===================================================================
include/xen/interface/elfnote.h new file +133 -0
133 lines not on this page · raw message
===================================================================
include/xen/interface/event_channel.h new file +195 -0
195 lines not on this page · raw message
===================================================================
include/xen/interface/features.h new file +43 -0
43 lines not on this page · raw message
===================================================================
include/xen/interface/grant_table.h new file +301 -0
301 lines not on this page · raw message
===================================================================
include/xen/interface/io/blkif.h new file +96 -0
96 lines not on this page · raw message
===================================================================
include/xen/interface/io/console.h new file +23 -0
@@ -0,0 +1,23 @@ +/****************************************************************************** +* console.h +* +* Console I/O interface for Xen guest OSes. +* +* Copyright (c) 2005, Keir Fraser +*/ + +#ifndef __XEN_PUBLIC_IO_CONSOLE_H__ +#define __XEN_PUBLIC_IO_CONSOLE_H__ + +typedef uint32_t XENCONS_RING_IDX ; + +#define MASK_XENCONS_IDX (idx, ring) ((idx) & (sizeof(ring)-1)) + +struct xencons_interface { +char in[1024 ]; +char out[2048 ]; +XENCONS_RING_IDX in_cons, in_prod; +XENCONS_RING_IDX out_cons, out_prod; +}; + +#endif /* __XEN_PUBLIC_IO_CONSOLE_H__ */
===================================================================
include/xen/interface/io/netif.h new file +152 -0
152 lines not on this page · raw message
===================================================================
include/xen/interface/io/ring.h new file +260 -0
260 lines not on this page · raw message
===================================================================
include/xen/interface/io/xenbus.h new file +42 -0
42 lines not on this page · raw message
===================================================================
include/xen/interface/io/xs_wire.h new file +87 -0
87 lines not on this page · raw message
===================================================================
include/xen/interface/memory.h new file +145 -0
145 lines not on this page · raw message
===================================================================
include/xen/interface/physdev.h new file +61 -0
61 lines not on this page · raw message
===================================================================
include/xen/interface/sched.h new file +77 -0
77 lines not on this page · raw message
===================================================================
include/xen/interface/vcpu.h new file +109 -0
109 lines not on this page · raw message
===================================================================
include/xen/interface/version.h new file +60 -0
60 lines not on this page · raw message
===================================================================
include/xen/interface/xen.h new file +445 -0
445 lines not on this page · raw message
PATCH 16/21 Xen-paravirt: Core Xen implementation
In reply to Jeremy FitzhardingeThis adds a second entry point to head.S, which is jumped to when booted by Xen. This allows startup under Xen to be easily detected.
Because Xen starts the kernel in a fairly sane state, very little setup is needed here; it just needs to jump into xen_start_kernel to init the paravirt_ops structure, and then jump into start_kernel proper.
This also makes a few small adjustments to the gdt tables to make them properly suited to Xen.
This patch also contains an initial set of paravirt ops for Xen, mostly ones which can just be implemented with the generic native_* version. At boot time, the global paravirt_ops structure is populated with the Xen pointers in xen_start_kernel, which then jumps to the standard start_kernel.
Also implements Xen pagetable handling, including the machinery to implement direct pagetables. This means that pte update operations are intercepted so that pseudo-physical addresses can be converted to machine addresses. It also implements late pinning/early unpinning so that pagetables are initialized while they're normal read-write memory as much as possible, yet pinned to make cr3 reloads as efficient as possible.
Xen implements interrupts in terms of event channels. This patch maps an event through an event channel to an irq, and then feeds it through the normal interrupt path, via a Xen irq_chip implementation.
Context switches are optimised with the use of multicalls, so that the multiple hypercalls needed to perform the switch can be implemented with a single hypercall. In order to simplify the source changes, this is done via a generic multicall batching mechanism, which can be used to batch arbitrary series of hypercalls into a multicall.
Time is implemented by using a clocksource which is driven from the hypervisor's nanosecond timebase. Xen implements time by extrapolating from known timestamps using the tsc; the hypervisor is responsible for making sure that the tsc is constant rate and synchronized between vcpus.
--- arch/i386/Makefile | 3 arch/i386/kernel/cpu/common.c | 3 arch/i386/kernel/entry.S | 79 +++ arch/i386/kernel/head.S | 13 arch/i386/kernel/paravirt.c | 48 +- arch/i386/kernel/vmlinux.lds.S | 1 arch/i386/mm/pgtable.c | 1 arch/i386/xen/Makefile | 2 arch/i386/xen/enlighten.c | 801 ++++++++++++++++++++++++++++++++++++++ arch/i386/xen/events.c | 480 ++++++++++++++++++++++ arch/i386/xen/features.c | 29 + arch/i386/xen/mmu.c | 419 +++++++++++++++++++ arch/i386/xen/mmu.h | 51 ++ arch/i386/xen/multicalls.c | 62 ++ arch/i386/xen/multicalls.h | 13 arch/i386/xen/setup.c | 95 ++++ arch/i386/xen/time.c | 452 +++++++++++++++++++++ arch/i386/xen/xen-head.S | 30 + arch/i386/xen/xen-ops.h | 20 include/asm-i386/irq.h | 1 include/asm-i386/paravirt.h | 42 + include/asm-i386/pda.h | 12 include/asm-i386/xen/hypercall.h | 18 include/xen/events.h | 28 + include/xen/features.h | 26 + include/xen/page.h | 175 ++++++++ 26 files changed, 2878 insertions(+), 26 deletions(-)
===================================================================
arch/i386/Makefile +3 -0
@@ -93,6 +93,9 @@ mcore-$(CONFIG_X86_ES7000) := mach-defau mcore-$(CONFIG_X86_ES7000) := mach-default core-$(CONFIG_X86_ES7000) := arch/i386/mach-es7000/ +# Xen paravirtualization support +core-$(CONFIG_XEN) += arch/i386/xen/ + # default subarch .h files mflags-y += -Iinclude/asm-i386/mach-default
===================================================================
arch/i386/kernel/cpu/common.c +3 -0
@@ -19,6 +19,7 @@#include <mach_apic.h> #endif #include <asm/pda.h> +#include <asm/paravirt.h> #include "cpu.h"
@@ -707,6 +708,8 @@ __cpuinit int init_gdt(int cpu, struct t pda->cpu_number = cpu; pda->pcurrent = idle; +paravirt_init_pda (pda, cpu); +return 1 ; }
===================================================================
arch/i386/kernel/entry.S +79 -0
85 lines not on this page · raw message
===================================================================
arch/i386/kernel/head.S +11 -2
@@ -535,6 +535,10 @@ unhandled_paravirt: ud2 #endif +#ifdef CONFIG_XEN +#include "../xen/xen-head.S" +#endif + /* * Real beginning of normal "text" segment */
@@ -544,8 +548,9 @@ ENTRY(_stext) /* * BSS section */ -.section ".bss.page_aligned","w" +.section ".bss.page_aligned","wa" ENTRY(swapper_pg_dir) + .align PAGE_SIZE_asm .fill 1024,4,0 ENTRY(empty_zero_page) .fill 4096,1,0
@@ -614,7 +619,8 @@ ENTRY(boot_gdt_table) /* * The Global Descriptor Table contains 28 quadwords, per-CPU. */ - .align L1_CACHE_BYTES + .section ".data.page_aligned" + .align PAGE_SIZE_asm ENTRY(cpu_gdt_table) .quad 0x0000000000000000 /* NULL descriptor */ .quad 0x0000000000000000 /* 0x0b reserved */
@@ -663,3 +669,6 @@ ENTRY(cpu_gdt_table) .quad 0x0000000000000000 /* 0xf0 - unused */ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */ + /* Be sure this is zeroed to avoid false validations in Xen */ + .fill PAGE_SIZE_asm / 8 - GDT_ENTRIES,8,0 + .previous
===================================================================
arch/i386/kernel/paravirt.c +24 -24
162 lines not on this page · raw message
===================================================================
arch/i386/kernel/vmlinux.lds.S +1 -0
@@ -93,6 +93,7 @@ SECTIONS . = ALIGN(4096); .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) { + *(.data.page_aligned) *(.data.idt) }
===================================================================
arch/i386/mm/pgtable.c +1 -0
@@ -267,6 +267,7 @@ static void pgd_ctor(pgd_t *pgd) swapper_pg_dir +USER_PTRS_PER_PGD , KERNEL_PGD_PTRS); }else { +memset (pgd,0 ,USER_PTRS_PER_PGD *sizeof (pgd_t));spin_lock_irqsave (&pgd_lock, flags);pgd_list_add (pgd);spin_unlock_irqrestore (&pgd_lock, flags);
===================================================================
arch/i386/xen/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +obj-y := enlighten.o setup.o events.o time.o \ + features.o mmu.o multicalls.o
===================================================================
arch/i386/xen/enlighten.c new file +801 -0
801 lines not on this page · raw message
===================================================================
arch/i386/xen/events.c new file +480 -0
480 lines not on this page · raw message
===================================================================
arch/i386/xen/features.c new file +29 -0
@@ -0,0 +1,29 @@ +/****************************************************************************** +* features.c +* +* Xen feature flags. +* +* Copyright (c) 2006, Ian Campbell, XenSource Inc. +*/ +#include <linux/types.h> +#include <linux/cache.h> +#include <linux/module.h> +#include <asm/xen/hypervisor.h> +#include <xen/features.h> + +u8 xen_features[XENFEAT_NR_SUBMAPS *32 ]__read_mostly ; +EXPORT_SYMBOL_GPL (xen_features); + +void xen_setup_features (void ) +{ +struct xen_feature_info fi; +int i, j; + +for (i =0 ; i <XENFEAT_NR_SUBMAPS ; i++) { + fi.submap_idx = i; +if (HYPERVISOR_xen_version (XENVER_get_features, &fi) <0 ) +break ; +for (j=0 ; j<32 ; j++) + xen_features[i*32 +j] = !!(fi.submap &1 <<j); + } +}
===================================================================
arch/i386/xen/mmu.c new file +419 -0
419 lines not on this page · raw message
===================================================================
arch/i386/xen/mmu.h new file +51 -0
51 lines not on this page · raw message
===================================================================
arch/i386/xen/multicalls.c new file +62 -0
62 lines not on this page · raw message
===================================================================
arch/i386/xen/multicalls.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef _XEN_MULTICALLS_H +#define _XEN_MULTICALLS_H + +struct multicall_space +{ +struct multicall_entry *mc; +void *args; +}; + +struct multicall_space xen_mc_entry (size_t args); +int xen_mc_flush (void ); + +#endif /* _XEN_MULTICALLS_H */
===================================================================
arch/i386/xen/setup.c new file +95 -0
95 lines not on this page · raw message
===================================================================
arch/i386/xen/time.c new file +452 -0
452 lines not on this page · raw message
===================================================================
arch/i386/xen/xen-head.S new file +30 -0
@@ -0,0 +1,30 @@ +/* Xen-specific pieces of head.S, intended to be included in the right + place in head.S */ + +#include <linux/elfnote.h> +#include <asm/boot.h> +#include <xen/interface/elfnote.h> + +ENTRY(startup_xen) + movl %esi,xen_start_info + jmp startup_paravirt + +.pushsection ".bss.page_aligned" +ENTRY(hypercall_page) + .align PAGE_SIZE_asm + .skip 0x1000 +.popsection + + ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS, .asciz, "linux") + ELFNOTE(Xen, XEN_ELFNOTE_GUEST_VERSION, .asciz, "2.6") + ELFNOTE(Xen, XEN_ELFNOTE_XEN_VERSION, .asciz, "xen-3.0") + ELFNOTE(Xen, XEN_ELFNOTE_VIRT_BASE, .long, __PAGE_OFFSET) + ELFNOTE(Xen, XEN_ELFNOTE_ENTRY, .long, startup_xen) + ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, .long, hypercall_page) + ELFNOTE(Xen, XEN_ELFNOTE_FEATURES, .asciz, "!writable_page_tables|pae_pgdir_above_4gb") +#ifdef CONFIG_X86_PAE + ELFNOTE(Xen, XEN_ELFNOTE_PAE_MODE, .asciz, "yes") +#else + ELFNOTE(Xen, XEN_ELFNOTE_PAE_MODE, .asciz, "no") +#endif + ELFNOTE(Xen, XEN_ELFNOTE_LOADER, .asciz, "generic")
===================================================================
arch/i386/xen/xen-ops.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef XEN_OPS_H +#define XEN_OPS_H + +#include <linux/init.h> + +extern struct start_info *xen_start_info; +extern struct shared_info *HYPERVISOR_shared_info; + +char *__init xen_memory_setup (void ); +void __init xen_arch_setup (void ); +void __init xen_init_IRQ (void ); + +void __init xen_time_init (void ); +unsigned long xen_get_wallclock (void ); +int xen_set_wallclock (unsigned long time); + +void stop_hz_timer (void ); +void start_hz_timer (void ); + +#endif /* XEN_OPS_H */
===================================================================
include/asm-i386/irq.h +1 -0
@@ -43,6 +43,7 @@ extern void fixup_irqs(cpumask_t map);extern void fixup_irqs (cpumask_t map);#endif +fastcall unsigned int do_IRQ(struct pt_regs *regs);void init_IRQ (void );void __init native_init_IRQ (void );
===================================================================
include/asm-i386/paravirt.h +42 -0
71 lines not on this page · raw message
===================================================================
include/asm-i386/pda.h +12 -0
@@ -16,8 +16,20 @@ struct i386_pdaint cpu_number;struct task_struct *pcurrent;/* current process */ struct pt_regs *irq_regs; + +#ifdef CONFIG_PARAVIRT +union { +#ifdef CONFIG_XEN +struct { +struct vcpu_info *vcpu; +unsigned long cr3; + } xen; +#endif /* CONFIG_XEN */ + }; +#endif /* CONFIG_PARAVIRT */ }; +extern struct i386_pda boot_pda;extern struct i386_pda *_cpu_pda[];#define cpu_pda (i) (_cpu_pda[i])
===================================================================
include/asm-i386/xen/hypercall.h +18 -0
@@ -410,4 +410,22 @@ MULTI_mmuext_op(struct multicall_entry * mcl->args[2 ] = (unsigned long )success_count; mcl->args[3] = domid; } + +static inline void +MULTI_set_gdt (struct multicall_entry *mcl,unsigned long *frames,int entries) +{ + mcl->op = __HYPERVISOR_set_gdt; + mcl->args[0 ] = (unsigned long )frames; + mcl->args[1 ] = entries; +} + +static inline void +MULTI_stack_switch (struct multicall_entry *mcl, +unsigned long ss,unsigned long esp) +{ + mcl->op = __HYPERVISOR_stack_switch; + mcl->args[0 ] = ss; + mcl->args[1 ] = esp; +} +#endif /* __HYPERCALL_H__ */
===================================================================
include/xen/events.h new file +28 -0
@@ -0,0 +1,28 @@ +#ifndef _XEN_EVENTS_H +#define _XEN_EVENTS_H + +#include <linux/irq.h> + +int bind_evtchn_to_irqhandler (unsigned int evtchn, +irqreturn_t (*handler)(int ,void *), +unsigned long irqflags,const char *devname, +void *dev_id); +int bind_virq_to_irqhandler (unsigned int virq,unsigned int cpu, +irqreturn_t (*handler)(int ,void *), +unsigned long irqflags,const char *devname,void *dev_id); + +/* +* Common unbind function for all event sources. Takes IRQ to unbind from. +* Automatically closes the underlying event channel (even for bindings +* made with bind_evtchn_to_irqhandler()). +*/ +void unbind_from_irqhandler (unsigned int irq,void *dev_id); + +static inline void notify_remote_via_evtchn (int port) +{ +struct evtchn_send send = { .port = port }; + (void )HYPERVISOR_event_channel_op (EVTCHNOP_send, &send); +} + +extern void notify_remote_via_irq (int irq); +#endif /* _XEN_EVENTS_H */
===================================================================
include/xen/features.h new file +26 -0
@@ -0,0 +1,26 @@ +/****************************************************************************** +* features.h +* +* Query the features reported by Xen. +* +* Copyright (c) 2006, Ian Campbell +*/ + +#ifndef __XEN_FEATURES_H__ +#define __XEN_FEATURES_H__ + +#include <xen/interface/features.h> + +void xen_setup_features (void ); + +extern u8 xen_features[XENFEAT_NR_SUBMAPS *32 ]; + +static inline int xen_feature (int flag) +{ +switch (flag) { + } + +return xen_features[flag]; +} + +#endif /* __ASM_XEN_FEATURES_H__ */
===================================================================
include/xen/page.h new file +175 -0
52 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
PATCH 17/21 Xen-paravirt: Add the Xen virtual console driver.
In reply to Jeremy FitzhardingeThis provides a bootstrap and ongoing emergency console which is intended to be available from very early during boot and at all times thereafter, in contrast with alternatives such as UDP-based syslogd, or logging in via ssh. The protocol is based on a simple shared-memory ring buffer.
--- arch/i386/kernel/early_printk.c | 2 drivers/Makefile | 3 drivers/xen/Makefile | 1 drivers/xen/console/Makefile | 2 drivers/xen/console/console.c | 585 +++++++++++++++++++++++++++++++++++ drivers/xen/console/xencons_ring.c | 144 ++++++++ include/xen/xencons.h | 14 init/main.c | 2 8 files changed, 753 insertions(+)
===================================================================
arch/i386/kernel/early_printk.c +2 -0
@@ -1,2 +1,4 @@ +#ifndef CONFIG_XEN #include "../../x86_64/kernel/early_printk.c" +#endif
===================================================================
drivers/Makefile +3 -0
@@ -14,6 +14,9 @@ obj-$(CONFIG_ACPI) += acpi/ # was used and do nothing if so obj-$(CONFIG_PNP) += pnp/ obj-$(CONFIG_ARM_AMBA) += amba/ + +# Xen is the default console when running as a guest +obj-$(CONFIG_XEN) += xen/ # char/ comes before serial/ etc so that the VT console is the boot-time # default.
===================================================================
drivers/xen/Makefile new file +1 -0
@@ -0,0 +1,1 @@ +obj-y += console/
===================================================================
drivers/xen/console/Makefile new file +2 -0
@@ -0,0 +1,2 @@ + +obj-y := console.o xencons_ring.o
===================================================================
drivers/xen/console/console.c new file +585 -0
585 lines not on this page · raw message
===================================================================
drivers/xen/console/xencons_ring.c new file +144 -0
144 lines not on this page · raw message
===================================================================
include/xen/xencons.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef __ASM_XENCONS_H__ +#define __ASM_XENCONS_H__ + +void xencons_force_flush (void ); +void xencons_resume (void ); + +/* Interrupt work hooks. Receive data, or kick data out. */ +void xencons_rx (char *buf,unsigned len); +void xencons_tx (void ); + +int xencons_ring_init (void ); +int xencons_ring_send (const char *data,unsigned len); + +#endif /* __ASM_XENCONS_H__ */
===================================================================
init/main.c +2 -0
@@ -495,6 +495,8 @@ asmlinkage void __init start_kernel(voidunwind_init ();lockdep_init (); +//setup_early_printk(NULL); +local_irq_disable ();early_boot_irqs_off ();early_init_irq_lock_class ();
Andrew Morton
maintainerRe: [patch 17/21] Xen-paravirt: Add the Xen virtual console driver.
Quoted 9 lines · On Thu, 15 Feb 2007 18:25:06 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
===================================================================
arch/i386/kernel/early_printk.c +2
-0@@ -1,2 +1,4 @@ +#ifndef CONFIG_XEN #include "../../x86_64/kernel/early_printk.c" +#endif ===================================================================
This can be done in Kconfig: disable CONFIG_EARLY_PRINTK if CONFIG_XEN.
PATCH 18/21 Xen-paravirt: Add Xen grant table support
In reply to Jeremy FitzhardingeAdd Xen 'grant table' driver which allows granting of access to selected local memory pages by other virtual machines and, symmetrically, the mapping of remote memory pages which other virtual machines have granted access to.
This driver is a prerequisite for many of the Xen virtual device drivers, which grant the 'device driver domain' restricted and temporary access to only those memory pages that are currently involved in I/O operations.
--- drivers/xen/Makefile | 1 drivers/xen/core/Makefile | 1 drivers/xen/core/grant_table.c | 446 +++++++++++++++++++++++++++++++++++++++ include/xen/grant_table.h | 107 +++++++++ 4 files changed, 555 insertions(+)
===================================================================
drivers/xen/Makefile +1 -0
@@ -1,1 +1,2 @@ obj-y += console/ +obj-y += core/ obj-y += console/
===================================================================
drivers/xen/core/Makefile new file +1 -0
@@ -0,0 +1,1 @@ +obj-y += grant_table.o
===================================================================
drivers/xen/core/grant_table.c new file +446 -0
446 lines not on this page · raw message
===================================================================
include/xen/grant_table.h new file +107 -0
107 lines not on this page · raw message
Andrew Morton
maintainerRe: [patch 18/21] Xen-paravirt: Add Xen grant table support
Quoted 6 lines · On Thu, 15 Feb 2007 18:25:07 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
drivers/xen/core/grant_table.c new file +6
-0+int gnttab_grant_foreign_access (domid_t domid,unsigned long frame, +int readonly) +{ +int ref; + +if (unlikely ((ref =get_free_entry ()) ==-1 ))
drivers/xen/core/grant_table.c line 141
Quoted 10 lines
drivers/xen/core/grant_table.c new file +10
-0+return -ENOSPC ; + + shared[ref].frame = frame; + shared[ref].domid = domid; +wmb (); + shared[ref].flags = GTF_permit_access | (readonly ? GTF_readonly :0 ); + +return ref; +} +EXPORT_SYMBOL_GPL (gnttab_grant_foreign_access);
We have lots of open-coded mysteriously unexplained barriers in here.
I assume they're not smp_wmb() because this could be a !SMP guest talking to an SMP host?
Re: [patch 18/21] Xen-paravirt: Add Xen grant table support
Quoted 23 lines · Andrew Morton
Quoted 7 lines · On Thu, 15 Feb 2007 18:25:07 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
drivers/xen/core/grant_table.c new file +6
-0+int gnttab_grant_foreign_access (domid_t domid,unsigned long frame, +int readonly) +{ +int ref; + +if (unlikely ((ref =get_free_entry ()) ==-1 ))drivers/xen/core/grant_table.c line 141
Quoted 10 lines
drivers/xen/core/grant_table.c new file +10
-0+return -ENOSPC ; + + shared[ref].frame = frame; + shared[ref].domid = domid; +wmb (); + shared[ref].flags = GTF_permit_access | (readonly ? GTF_readonly :0 ); + +return ref; +} +EXPORT_SYMBOL_GPL (gnttab_grant_foreign_access);We have lots of open-coded mysteriously unexplained barriers in here.
Quoted 3 lines
I assume they're not
smp_wmb()because this could be a !SMP guest talking to an SMP host?
Yeah. The grant tables refer to pages which are shared with other domains, so they could be running on other cpus even if this domain is UP. There's a lockless protocol going on here, but I'll need to look it up and sprinkle some comments.
J
PATCH 19/21 Xen-paravirt: Add the Xenbus sysfs and virtual device hotplug driver.
In reply to Jeremy FitzhardingeThis communicates with the machine control software via a registry residing in a controlling virtual machine. This allows dynamic creation, destruction and modification of virtual device configurations (network devices, block devices and CPUS, to name some examples).
--- arch/i386/xen/Kconfig | 5 drivers/xen/Makefile | 1 drivers/xen/xenbus/Makefile | 9 drivers/xen/xenbus/xenbus_client.c | 566 +++++++++++++++++ drivers/xen/xenbus/xenbus_comms.c | 218 ++++++ drivers/xen/xenbus/xenbus_comms.h | 44 + drivers/xen/xenbus/xenbus_probe.c | 891 ++++++++++++++++++++++++++++ drivers/xen/xenbus/xenbus_probe.h | 72 ++ drivers/xen/xenbus/xenbus_probe_backend.c | 269 ++++++++ drivers/xen/xenbus/xenbus_xs.c | 840 ++++++++++++++++++++++++++ include/asm-i386/hypervisor.h | 1 include/xen/xenbus.h | 208 ++++++ 12 files changed, 3124 insertions(+)
===================================================================
arch/i386/xen/Kconfig +5 -0
@@ -8,3 +8,8 @@ config XEN default y help This is the Linux Xen port. + +config XEN_BACKEND + bool + depends XEN + default n
===================================================================
drivers/xen/Makefile +1 -0
@@ -1,2 +1,3 @@ obj-y += core/ obj-y += core/ obj-y += console/ +obj-y += xenbus/
===================================================================
drivers/xen/xenbus/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +obj-y += xenbus.o + +xenbus-objs = +xenbus-objs += xenbus_client.o +xenbus-objs += xenbus_comms.o +xenbus-objs += xenbus_xs.o +xenbus-objs += xenbus_probe.o + +obj-$(CONFIG_XEN_BACKEND) += xenbus_probe_backend.o
===================================================================
drivers/xen/xenbus/xenbus_client.c new file +566 -0
566 lines not on this page · raw message
===================================================================
drivers/xen/xenbus/xenbus_comms.c new file +218 -0
218 lines not on this page · raw message
===================================================================
drivers/xen/xenbus/xenbus_comms.h new file +44 -0
44 lines not on this page · raw message
===================================================================
drivers/xen/xenbus/xenbus_probe.c new file +891 -0
891 lines not on this page · raw message
===================================================================
drivers/xen/xenbus/xenbus_probe.h new file +72 -0
72 lines not on this page · raw message
===================================================================
drivers/xen/xenbus/xenbus_probe_backend.c new file +269 -0
269 lines not on this page · raw message
===================================================================
drivers/xen/xenbus/xenbus_xs.c new file +840 -0
840 lines not on this page · raw message
===================================================================
include/asm-i386/xen/hypervisor.h +1 -0
@@ -42,6 +42,7 @@#include <asm/ptrace.h> #include <asm/page.h> +#include <asm/desc.h> #if defined(__i386__)# ifdef CONFIG_X86_PAE # include <asm-generic/pgtable-nopud.h>
===================================================================
include/xen/xenbus.h new file +208 -0
73 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
PATCH 20/21 Xen-paravirt: Add Xen virtual block device driver.
In reply to Jeremy FitzhardingeThe block device frontend driver allows the kernel to access block devices exported exported by a virtual machine containing a physical block device driver.
--- drivers/block/Kconfig | 1 drivers/block/Makefile | 1 drivers/block/xen/Kconfig | 14 drivers/block/xen/Makefile | 5 drivers/block/xen/blkfront.c | 844 +++++++++++++++++++++++++++++++++++++++++ drivers/block/xen/block.h | 135 ++++++ drivers/block/xen/vbd.c | 230 +++++++++++ include/linux/major.h | 2 8 files changed, 1232 insertions(+)
===================================================================
drivers/block/Kconfig +1 -0
@@ -461,6 +461,7 @@ config CDROM_PKTCDVD_WCACHE don't do deferred write error handling yet. source "drivers/s390/block/Kconfig" +source "drivers/block/xen/Kconfig" config ATA_OVER_ETH tristate "ATA over Ethernet support"
===================================================================
drivers/block/Makefile +1 -0
@@ -29,3 +29,4 @@ obj-$(CONFIG_BLK_DEV_SX8) += sx8.o obj-$(CONFIG_BLK_DEV_SX8) += sx8.o obj-$(CONFIG_BLK_DEV_UB) += ub.o +obj-$(CONFIG_XEN) += xen/
===================================================================
drivers/block/xen/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +menu "Xen block device drivers" + depends on XEN + +config XEN_BLKDEV_FRONTEND + tristate "Block device frontend driver" + depends on XEN + default y + help + The block device frontend driver allows the kernel to access block + devices exported from a device driver virtual machine. Unless you + are building a dedicated device driver virtual machine, then you + almost certainly want to say Y here. + +endmenu
===================================================================
drivers/block/xen/Makefile new file +5 -0
@@ -0,0 +1,5 @@ + +obj-$(CONFIG_XEN_BLKDEV_FRONTEND) := xenblk.o + +xenblk-objs := blkfront.o vbd.o +
===================================================================
drivers/block/xen/blkfront.c new file +844 -0
844 lines not on this page · raw message
===================================================================
drivers/block/xen/block.h new file +135 -0
135 lines not on this page · raw message
===================================================================
drivers/block/xen/vbd.c new file +230 -0
230 lines not on this page · raw message
===================================================================
include/linux/major.h +2 -0
@@ -156,6 +156,8 @@#define VXSPEC_MAJOR 200/* VERITAS volume config driver */ #define VXDMP_MAJOR 201/* VERITAS volume multipath driver */ +#define XENVBD_MAJOR 202/* Xen virtual block device */ +#define MSR_MAJOR 202#define CPUID_MAJOR 203
PATCH 21/21 Xen-paravirt: Add the Xen virtual network device driver.
In reply to Jeremy FitzhardingeThe network device frontend driver allows the kernel to access network devices exported exported by a virtual machine containing a physical network device driver.
--- drivers/net/Kconfig | 12 drivers/net/Makefile | 2 drivers/net/xen-netfront.c | 2066 ++++++++++++++++++++++++++++++++++++++++++++ include/xen/events.h | 2 4 files changed, 2082 insertions(+)
===================================================================
drivers/net/Kconfig +12 -0
@@ -2525,6 +2525,18 @@ source "drivers/atm/Kconfig" source "drivers/s390/net/Kconfig" +config XEN_NETDEV_FRONTEND + tristate "Xen network device frontend driver" + depends on XEN + default y + help + The network device frontend driver allows the kernel to + access network devices exported exported by a virtual + machine containing a physical network device driver. The + frontend driver is intended for unprivileged guest domains; + if you are compiling a kernel for a Xen guest, you almost + certainly want to enable this. + config ISERIES_VETH tristate "iSeries Virtual Ethernet driver support" depends on PPC_ISERIES
===================================================================
drivers/net/Makefile +2 -0
@@ -218,3 +218,5 @@ obj-$(CONFIG_FS_ENET) += fs_enet/ obj-$(CONFIG_FS_ENET) += fs_enet/ obj-$(CONFIG_NETXEN_NIC) += netxen/ + +obj-$(CONFIG_XEN_NETDEV_FRONTEND) += xen-netfront.o
===================================================================
drivers/net/xen-netfront.c new file +2066 -0
2,066 lines not on this page · raw message
===================================================================
include/xen/events.h +2 -0
@@ -2,6 +2,8 @@#define _XEN_EVENTS_H#include <linux/irq.h> +#include <xen/interface/event_channel.h> +#include <asm/xen/hypercall.h> int bind_evtchn_to_irqhandler(unsigned int evtchn, irqreturn_t (*handler)(int, void *),
Andrew Morton
maintainerQuoted 2 lines · On Thu, 15 Feb 2007 18:24:49 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
This patch series implements the Linux Xen guest in terms of the paravirt-ops interface.
The whole patchset exports 67 symbols to modules. How come?
Are they all needed?
Quoted 10 lines · Andrew Morton
Quoted 3 lines · On Thu, 15 Feb 2007 18:24:49 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
This patch series implements the Linux Xen guest in terms of the paravirt-ops interface.
The whole patchset exports 67 symbols to modules. How come?
Are they all needed?
Yep, pretty much. They're all generally to do with Xen's virtual device model, and are needed by modular frontend/backed drivers. This series only includes the basic block and network frontend devices, but there are more waiting in the wings.
The breakdown, roughly, is:
* event channel management
* pseudophysical <-> machine addresses
* grant-table management
* xenbus, which includes
o which has a filesystem-like namespace
o the means to monitor changes in objects in the namespace
o shared resource management
o suspend/resume
J
Quoted 2 lines · Jeremy Fitzhardinge
This patch series implements the Linux Xen guest in terms of the paravirt-ops interface. The features in implemented this patch series
I am thoroughly confused. Maybe that is because I have not been following this issue closely but it seems that you are using the paravirt interface as an API for Xen code in the guest? I thought the idea of paravirt was to have an API that is generic? This patchset seems to be mostly realizing Xen specific functionality? How does the code here interact with KVM, VMWare and other hypervisors?
Quoted 9 lines · Christoph Lameter
Quoted 3 lines · Jeremy Fitzhardinge
This patch series implements the Linux Xen guest in terms of the paravirt-ops interface. The features in implemented this patch series
I am thoroughly confused. Maybe that is because I have not been following this issue closely but it seems that you are using the paravirt interface as an API for Xen code in the guest? I thought the idea of paravirt was to have an API that is generic? This patchset seems to be mostly realizing Xen specific functionality? How does the code here interact with KVM, VMWare and other hypervisors?
For the most part, it doesn't disturb VMware or KVM. Xen does need some additional functionality in paravirt-ops because they took a different design choice - direct page tables instead of shadow page tables. This is where all the requirements for the new Xen paravirt-ops hooks come from.
Zach
Quoted 4 lines · Zachary Amsden
For the most part, it doesn't disturb VMware or KVM. Xen does need some additional functionality in paravirt-ops because they took a different design choice - direct page tables instead of shadow page tables. This is where all the requirements for the new Xen paravirt-ops hooks come from.
It still seems to be implemented for Xen and not to support a variety of page table methods in paravirt ops.
Quoted 11 lines · Christoph Lameter
Quoted 5 lines · Zachary Amsden
For the most part, it doesn't disturb VMware or KVM. Xen does need some additional functionality in paravirt-ops because they took a different design choice - direct page tables instead of shadow page tables. This is where all the requirements for the new Xen paravirt-ops hooks come from.
It still seems to be implemented for Xen and not to support a variety of page table methods in paravirt ops.
Yes, but that is just because the Xen hooks happens to be near the last part of the merge. VMI required some special hooks, as do both Xen and lhype (I think ... Rusty can correct me if lhype's puppy's have precluded the addition of new hooks). Xen page table handling is very different, mostly it is trap and emulate so writable page tables can work, which means they don't always issue hypercalls for PTE updates, although they do have that option, should the hypervisor MMU model change, or performance concerns prompt a different model (or perhaps, migration?)
Zach
Quoted 8 lines · Zachary Amsden
Yes, but that is just because the Xen hooks happens to be near the last part of the merge. VMI required some special hooks, as do both Xen and lhype (I think ... Rusty can correct me if lhype's puppy's have precluded the addition of new hooks). Xen page table handling is very different, mostly it is trap and emulate so writable page tables can work, which means they don't always issue hypercalls for PTE updates, although they do have that option, should the hypervisor MMU model change, or performance concerns prompt a different model (or perhaps, migration?)
Well looks like there are still some major design issues to be ironed out. What is proposed here is to make paravirt_ops a fake generic API and then tunnel through it to vendor specific kernel mods.
Quoted 13 lines · Christoph Lameter
Quoted 9 lines · Zachary Amsden
Yes, but that is just because the Xen hooks happens to be near the last part of the merge. VMI required some special hooks, as do both Xen and lhype (I think ... Rusty can correct me if lhype's puppy's have precluded the addition of new hooks). Xen page table handling is very different, mostly it is trap and emulate so writable page tables can work, which means they don't always issue hypercalls for PTE updates, although they do have that option, should the hypervisor MMU model change, or performance concerns prompt a different model (or perhaps, migration?)
Quoted 2 lines
Well looks like there are still some major design issues to be ironed out. What is proposed here is to make
paravirt_opsa fake generic API and then tunnel through it to vendor specific kernel mods.
No, there are two radically different approaches represented in one API. Shadow page tables and direct page tables require different abstractions to make them work. The API is not fake. It accommodates both approaches, and the Xen changes here are pretty much required to make direct page tables work. The shadow side of the equation is not vendor specific, in fact, it is used by lhype to make PTE update hypercalls. But only one vendor chose direct page tables, so it appears vendor specific, when in fact it is just specific to that design choice.
Adding XenBus hooks to paravirt-ops, for instance, would be vendor specific and useless to anyone else. But that is not the approach which has been taken here.
Zach
Quoted 11 lines · Christoph Lameter
Quoted 8 lines · Zachary Amsden
Yes, but that is just because the Xen hooks happens to be near the last part of the merge. VMI required some special hooks, as do both Xen and lhype (I think ... Rusty can correct me if lhype's puppy's have precluded the addition of new hooks). Xen page table handling is very different, mostly it is trap and emulate so writable page tables can work, which means they don't always issue hypercalls for PTE updates, although they do have that option, should the hypervisor MMU model change, or performance concerns prompt a different model (or perhaps, migration?)
Quoted 3 lines
Well looks like there are still some major design issues to be ironed out. What is proposed here is to make
paravirt_opsa fake generic API and then tunnel through it to vendor specific kernel mods.
That was always its intention. It's not a direct interface to a hypervisor, but an somewhat abstracted interface to a "hypervisor driver"
But you're right that there are currently still quite a lot of hooks being added. I plan to be much more strict on that in the future.
-Andi
Quoted 2 lines · Andi Kleen
That was always its intention. It's not a direct interface to a hypervisor, but an somewhat abstracted interface to a "hypervisor driver"
I thought that hypervisor driver was some binary blob that can be directly accessed via paravirt_ops?
Quoted 2 lines
But you're right that there are currently still quite a lot of hooks being added. I plan to be much more strict on that in the future.
And it seems that the hooks are not generic but bound to a particular hypervisor. Should the Xen specific stuff not be in the binary blob?
Quoted 10 lines · Christoph Lameter
Quoted 3 lines · Andi Kleen
That was always its intention. It's not a direct interface to a hypervisor, but an somewhat abstracted interface to a "hypervisor driver"
I thought that hypervisor driver was some binary blob that can be directly accessed via
paravirt_ops?
There are no more binary blobs being used by paravirt-ops hypervisors. I prefer the term "open hypercode layer".
Quoted 6 lines
Quoted 3 lines
But you're right that there are currently still quite a lot of hooks being added. I plan to be much more strict on that in the future.
And it seems that the hooks are not generic but bound to a particular hypervisor. Should the Xen specific stuff not be in the binary blob?
Xen doesn't use a hypercode layer, and there is no way to do what they need to do without hooks in the kernel.
Zach
Quoted 2 lines · Christoph Lameter
And it seems that the hooks are not generic but bound to a particular hypervisor. Should the Xen specific stuff not be in the binary blob?
Xen has no "binary blob". It needs guests to cooperate with it by making hypercalls; all that code is in the Xen implementation of the paravirt_ops interface, which is just ordinary code which lives in the kernel sources.
J
Quoted 8 lines · Zachary Amsden
Quoted 2 lines · Christoph Lameter
It still seems to be implemented for Xen and not to support a variety of page table methods in paravirt ops.
Yes, but that is just because the Xen hooks happens to be near the last part of the merge. VMI required some special hooks, as do both Xen and lhype (I think ... Rusty can correct me if lhype's puppy's have precluded the addition of new hooks).
lguest was supposed to be a demonstration of paravirt_ops, so it shouldn't have added any. But note that I did change some other things, such as the esp0 initialization for the swapper.
Puppies are still alive and well. Although Andi not pushing into 2.6.21 (yet?) made puppies sad 8(
Quoted 6 lines
Xen page table handling is very
different, mostly it is trap and emulate so writable page tables can work, which means they don't always issue hypercalls for PTE updates, although they do have that option, should the hypervisor MMU model change, or performance concerns prompt a different model (or perhaps, migration?)
Yes, Xen really like their direct pagetable stuff. I'm a traditionalist, myself, but it did require some expansion of paravirt_ops.
KVM might well want more, although from here it's more likely we'll move some of the hooks up the stack a little IMHO.
Cheers,
Rusty.
Quoted 6 lines · Christoph Lameter
I am thoroughly confused. Maybe that is because I have not been following this issue closely but it seems that you are using the paravirt interface as an API for Xen code in the guest? I thought the idea of paravirt was to have an API that is generic? This patchset seems to be mostly realizing Xen specific functionality? How does the code here interact with KVM, VMWare and other hypervisors?
There are two things in this patch series: generic kernel changes, and the core bits of Xen itself.
The earlier part of the patch contains changes to the core kernel which are needed for Xen, but are generally harmless to non-paravirt use, or
to being virtualized under other hypervisors. In some cases these are
plain bugfixes (like dealing with absent vga hardware), or things which have become parameterised (like the pgd alignment, or whether we share the kernel pmd in PAE mode).
But there are also extensions to the paravirt_ops interface. The largest of these is adding the appropriate hooks for non-shadowed-pagetable hypervisors. While Xen is the only example of this at the moment, its not a Xen-specific set of hooks. It allows a hypervisor backend to have detailed control over what actually gets put into pagetables; in Xen's case this means we can convert the kernel's pseudo-physical addresses into machine addresses, but you could imagine a hypervisor maintaining some other structure in parallel with the pagetable or something like that. An analogy would be extending the IO DMA interfaces to account for an IOMMU, even if only one hardware platform actually has an IOMMU.
The latter part of the series is basically pure Xen-specifc stuff, which is almost entirely restricted to Xen-specific parts of the tree. This code introduces a number of new Xen-specific interfaces, but they're completely distinct from paravirt_ops.
J
Quoted 11 lines · Christoph Lameter
Quoted 2 lines · Jeremy Fitzhardinge
This patch series implements the Linux Xen guest in terms of the paravirt-ops interface. The features in implemented this patch series
I am thoroughly confused. Maybe that is because I have not been following this issue closely but it seems that you are using the paravirt interface as an API for Xen code in the guest? I thought the idea of paravirt was to have an API that is generic? This patchset seems to be mostly realizing Xen specific functionality? How does the code here interact with KVM, VMWare and other hypervisors?
It doesn't. Paravirt_ops provides the hooks. KVM, lguest, VMI and Xen all need to implement what they want on top of them.
Hope that clarifies,
Rusty.