ia64/xen-unstable

changeset 9200:a4dc14edd56b

Clean up the interface for sharing xen-heap pages with guests.
Map trace buffer pages as DOMID_XEN pages.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Mar 09 00:45:40 2006 +0100 (2006-03-09)
parents 4af3f8bd7e0c
children 17e26f60e901
files tools/xenmon/xenbaked.c tools/xentrace/xentrace.c xen/arch/x86/domain.c xen/arch/x86/mm.c xen/arch/x86/x86_32/mm.c xen/arch/x86/x86_64/mm.c xen/common/trace.c xen/include/asm-ia64/mm.h xen/include/asm-x86/grant_table.h xen/include/asm-x86/mm.h
line diff
     1.1 --- a/tools/xenmon/xenbaked.c	Thu Mar 09 00:04:43 2006 +0100
     1.2 +++ b/tools/xenmon/xenbaked.c	Thu Mar 09 00:45:40 2006 +0100
     1.3 @@ -299,7 +299,7 @@ struct t_buf *map_tbufs(unsigned long tb
     1.4          exit(EXIT_FAILURE);
     1.5      }
     1.6  
     1.7 -    tbufs_mapped = xc_map_foreign_range(xc_handle, 0 /* Dom 0 ID */,
     1.8 +    tbufs_mapped = xc_map_foreign_range(xc_handle, DOMID_XEN,
     1.9                                          size * num, PROT_READ | PROT_WRITE,
    1.10                                          tbufs_mfn);
    1.11  
     2.1 --- a/tools/xentrace/xentrace.c	Thu Mar 09 00:04:43 2006 +0100
     2.2 +++ b/tools/xentrace/xentrace.c	Thu Mar 09 00:45:40 2006 +0100
     2.3 @@ -144,7 +144,7 @@ struct t_buf *map_tbufs(unsigned long tb
     2.4          exit(EXIT_FAILURE);
     2.5      }
     2.6  
     2.7 -    tbufs_mapped = xc_map_foreign_range(xc_handle, 0 /* Dom 0 ID */,
     2.8 +    tbufs_mapped = xc_map_foreign_range(xc_handle, DOMID_XEN,
     2.9                                          size * num, PROT_READ | PROT_WRITE,
    2.10                                          tbufs_mfn);
    2.11  
     3.1 --- a/xen/arch/x86/domain.c	Thu Mar 09 00:04:43 2006 +0100
     3.2 +++ b/xen/arch/x86/domain.c	Thu Mar 09 00:45:40 2006 +0100
     3.3 @@ -312,7 +312,8 @@ int arch_domain_create(struct domain *d)
     3.4              goto fail_nomem;
     3.5  
     3.6          memset(d->shared_info, 0, PAGE_SIZE);
     3.7 -        SHARE_PFN_WITH_DOMAIN(virt_to_page(d->shared_info), d);
     3.8 +        share_xen_page_with_guest(
     3.9 +            virt_to_page(d->shared_info), d, XENSHARE_writable);
    3.10      }
    3.11  
    3.12      return 0;
     4.1 --- a/xen/arch/x86/mm.c	Thu Mar 09 00:04:43 2006 +0100
     4.2 +++ b/xen/arch/x86/mm.c	Thu Mar 09 00:45:40 2006 +0100
     4.3 @@ -176,10 +176,9 @@ void __init init_frametable(void)
     4.4  
     4.5  void arch_init_memory(void)
     4.6  {
     4.7 -    extern void subarch_init_memory(struct domain *);
     4.8 +    extern void subarch_init_memory(void);
     4.9  
    4.10      unsigned long i, pfn, rstart_pfn, rend_pfn;
    4.11 -    struct page_info *page;
    4.12  
    4.13      memset(percpu_info, 0, sizeof(percpu_info));
    4.14  
    4.15 @@ -189,6 +188,7 @@ void arch_init_memory(void)
    4.16       * their domain field set to dom_xen.
    4.17       */
    4.18      dom_xen = alloc_domain();
    4.19 +    spin_lock_init(&dom_xen->page_alloc_lock);
    4.20      atomic_set(&dom_xen->refcnt, 1);
    4.21      dom_xen->domain_id = DOMID_XEN;
    4.22  
    4.23 @@ -198,17 +198,13 @@ void arch_init_memory(void)
    4.24       * array. Mappings occur at the priv of the caller.
    4.25       */
    4.26      dom_io = alloc_domain();
    4.27 +    spin_lock_init(&dom_io->page_alloc_lock);
    4.28      atomic_set(&dom_io->refcnt, 1);
    4.29      dom_io->domain_id = DOMID_IO;
    4.30  
    4.31      /* First 1MB of RAM is historically marked as I/O. */
    4.32      for ( i = 0; i < 0x100; i++ )
    4.33 -    {
    4.34 -        page = mfn_to_page(i);
    4.35 -        page->count_info        = PGC_allocated | 1;
    4.36 -        page->u.inuse.type_info = PGT_writable_page | PGT_validated | 1;
    4.37 -        page_set_owner(page, dom_io);
    4.38 -    }
    4.39 +        share_xen_page_with_guest(mfn_to_page(i), dom_io, XENSHARE_writable);
    4.40   
    4.41      /* Any areas not specified as RAM by the e820 map are considered I/O. */
    4.42      for ( i = 0, pfn = 0; i < e820.nr_map; i++ )
    4.43 @@ -221,17 +217,45 @@ void arch_init_memory(void)
    4.44          for ( ; pfn < rstart_pfn; pfn++ )
    4.45          {
    4.46              BUG_ON(!mfn_valid(pfn));
    4.47 -            page = mfn_to_page(pfn);
    4.48 -            page->count_info        = PGC_allocated | 1;
    4.49 -            page->u.inuse.type_info = PGT_writable_page | PGT_validated | 1;
    4.50 -            page_set_owner(page, dom_io);
    4.51 +            share_xen_page_with_guest(
    4.52 +                mfn_to_page(pfn), dom_io, XENSHARE_writable);
    4.53          }
    4.54          /* Skip the RAM region. */
    4.55          pfn = rend_pfn;
    4.56      }
    4.57      BUG_ON(pfn != max_page);
    4.58  
    4.59 -    subarch_init_memory(dom_xen);
    4.60 +    subarch_init_memory();
    4.61 +}
    4.62 +
    4.63 +void share_xen_page_with_guest(
    4.64 +    struct page_info *page, struct domain *d, int readonly)
    4.65 +{
    4.66 +    if ( page_get_owner(page) == d )
    4.67 +        return;
    4.68 +
    4.69 +    spin_lock(&d->page_alloc_lock);
    4.70 +
    4.71 +    /* The incremented type count pins as writable or read-only. */
    4.72 +    page->u.inuse.type_info  = (readonly ? PGT_none : PGT_writable_page);
    4.73 +    page->u.inuse.type_info |= PGT_validated | 1;
    4.74 +
    4.75 +    page_set_owner(page, d);
    4.76 +    wmb(); /* install valid domain ptr before updating refcnt. */
    4.77 +    ASSERT(page->count_info == 0);
    4.78 +    page->count_info |= PGC_allocated | 1;
    4.79 +
    4.80 +    if ( unlikely(d->xenheap_pages++ == 0) )
    4.81 +        get_knownalive_domain(d);
    4.82 +    list_add_tail(&page->list, &d->xenpage_list);
    4.83 +
    4.84 +    spin_unlock(&d->page_alloc_lock);
    4.85 +}
    4.86 +
    4.87 +void share_xen_page_with_privileged_guests(
    4.88 +    struct page_info *page, int readonly)
    4.89 +{
    4.90 +    share_xen_page_with_guest(page, dom_xen, readonly);
    4.91  }
    4.92  
    4.93  void write_ptbase(struct vcpu *v)
     5.1 --- a/xen/arch/x86/x86_32/mm.c	Thu Mar 09 00:04:43 2006 +0100
     5.2 +++ b/xen/arch/x86/x86_32/mm.c	Thu Mar 09 00:45:40 2006 +0100
     5.3 @@ -144,7 +144,7 @@ void __init zap_low_mappings(l2_pgentry_
     5.4      flush_tlb_all_pge();
     5.5  }
     5.6  
     5.7 -void subarch_init_memory(struct domain *dom_xen)
     5.8 +void subarch_init_memory(void)
     5.9  {
    5.10      unsigned long m2p_start_mfn;
    5.11      unsigned int i, j;
    5.12 @@ -175,10 +175,7 @@ void subarch_init_memory(struct domain *
    5.13          for ( j = 0; j < L2_PAGETABLE_ENTRIES; j++ )
    5.14          {
    5.15              struct page_info *page = mfn_to_page(m2p_start_mfn + j);
    5.16 -            page->count_info = PGC_allocated | 1;
    5.17 -            /* Ensure it's only mapped read-only by domains. */
    5.18 -            page->u.inuse.type_info = PGT_gdt_page | 1;
    5.19 -            page_set_owner(page, dom_xen);
    5.20 +            share_xen_page_with_privileged_guests(page, XENSHARE_readonly);
    5.21          }
    5.22      }
    5.23  
     6.1 --- a/xen/arch/x86/x86_64/mm.c	Thu Mar 09 00:04:43 2006 +0100
     6.2 +++ b/xen/arch/x86/x86_64/mm.c	Thu Mar 09 00:45:40 2006 +0100
     6.3 @@ -134,7 +134,7 @@ void __init zap_low_mappings(void)
     6.4      flush_tlb_all_pge();
     6.5  }
     6.6  
     6.7 -void subarch_init_memory(struct domain *dom_xen)
     6.8 +void subarch_init_memory(void)
     6.9  {
    6.10      unsigned long i, v, m2p_start_mfn;
    6.11      l3_pgentry_t l3e;
    6.12 @@ -174,11 +174,7 @@ void subarch_init_memory(struct domain *
    6.13          for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ )
    6.14          {
    6.15              struct page_info *page = mfn_to_page(m2p_start_mfn + i);
    6.16 -            page->count_info = PGC_allocated | 1;
    6.17 -            /* gdt to make sure it's only mapped read-only by non-privileged
    6.18 -               domains. */
    6.19 -            page->u.inuse.type_info = PGT_gdt_page | 1;
    6.20 -            page_set_owner(page, dom_xen);
    6.21 +            share_xen_page_with_privileged_guests(page, XENSHARE_readonly);
    6.22          }
    6.23      }
    6.24  }
     7.1 --- a/xen/common/trace.c	Thu Mar 09 00:04:43 2006 +0100
     7.2 +++ b/xen/common/trace.c	Thu Mar 09 00:45:40 2006 +0100
     7.3 @@ -83,8 +83,9 @@ static int alloc_trace_bufs(void)
     7.4  
     7.5      /* Share pages so that xentrace can map them. */
     7.6      for ( i = 0; i < nr_pages; i++ )
     7.7 -        SHARE_PFN_WITH_DOMAIN(virt_to_page(rawbuf + i * PAGE_SIZE), dom0);
     7.8 -    
     7.9 +        share_xen_page_with_privileged_guests(
    7.10 +            virt_to_page(rawbuf) + i, XENSHARE_writable);
    7.11 +
    7.12      for_each_online_cpu ( i )
    7.13      {
    7.14          buf = t_bufs[i] = (struct t_buf *)&rawbuf[i*opt_tbuf_size*PAGE_SIZE];
     8.1 --- a/xen/include/asm-ia64/mm.h	Thu Mar 09 00:04:43 2006 +0100
     8.2 +++ b/xen/include/asm-ia64/mm.h	Thu Mar 09 00:45:40 2006 +0100
     8.3 @@ -118,7 +118,8 @@ static inline u32 pickle_domptr(struct d
     8.4  #define page_set_owner(_p, _d)	((_p)->u.inuse._domain = pickle_domptr(_d))
     8.5  
     8.6  /* Dummy now */
     8.7 -#define SHARE_PFN_WITH_DOMAIN(_pfn, _dom) do { } while (0)
     8.8 +#define share_xen_page_with_guest(p, d, r) do { } while (0)
     8.9 +#define share_xen_page_with_privileged_guests(p, r) do { } while (0)
    8.10  
    8.11  extern struct page_info *frame_table;
    8.12  extern unsigned long frame_table_size;
     9.1 --- a/xen/include/asm-x86/grant_table.h	Thu Mar 09 00:04:43 2006 +0100
     9.2 +++ b/xen/include/asm-x86/grant_table.h	Thu Mar 09 00:45:40 2006 +0100
     9.3 @@ -23,8 +23,9 @@ int steal_page_for_grant_transfer(
     9.4  
     9.5  #define gnttab_create_shared_page(d, t, i)                               \
     9.6      do {                                                                 \
     9.7 -        SHARE_PFN_WITH_DOMAIN(                                           \
     9.8 -            virt_to_page((char *)(t)->shared + ((i) * PAGE_SIZE)), (d)); \
     9.9 +        share_xen_page_with_guest(                                       \
    9.10 +            virt_to_page((char *)(t)->shared + ((i) * PAGE_SIZE)),       \
    9.11 +            (d), XENSHARE_writable);                                     \
    9.12          set_gpfn_from_mfn(                                               \
    9.13              (virt_to_maddr((t)->shared) >> PAGE_SHIFT) + (i),            \
    9.14              INVALID_M2P_ENTRY);                                          \
    10.1 --- a/xen/include/asm-x86/mm.h	Thu Mar 09 00:04:43 2006 +0100
    10.2 +++ b/xen/include/asm-x86/mm.h	Thu Mar 09 00:45:40 2006 +0100
    10.3 @@ -138,21 +138,12 @@ static inline u32 pickle_domptr(struct d
    10.4  #define page_get_owner(_p)    (unpickle_domptr((_p)->u.inuse._domain))
    10.5  #define page_set_owner(_p,_d) ((_p)->u.inuse._domain = pickle_domptr(_d))
    10.6  
    10.7 -#define SHARE_PFN_WITH_DOMAIN(_pfn, _dom)                                   \
    10.8 -    do {                                                                    \
    10.9 -        page_set_owner((_pfn), (_dom));                                     \
   10.10 -        /* The incremented type count is intended to pin to 'writable'. */  \
   10.11 -        (_pfn)->u.inuse.type_info = PGT_writable_page | PGT_validated | 1;  \
   10.12 -        wmb(); /* install valid domain ptr before updating refcnt. */       \
   10.13 -        spin_lock(&(_dom)->page_alloc_lock);                                \
   10.14 -        /* _dom holds an allocation reference */                            \
   10.15 -        ASSERT((_pfn)->count_info == 0);                                    \
   10.16 -        (_pfn)->count_info |= PGC_allocated | 1;                            \
   10.17 -        if ( unlikely((_dom)->xenheap_pages++ == 0) )                       \
   10.18 -            get_knownalive_domain(_dom);                                    \
   10.19 -        list_add_tail(&(_pfn)->list, &(_dom)->xenpage_list);                \
   10.20 -        spin_unlock(&(_dom)->page_alloc_lock);                              \
   10.21 -    } while ( 0 )
   10.22 +#define XENSHARE_writable 0
   10.23 +#define XENSHARE_readonly 1
   10.24 +extern void share_xen_page_with_guest(
   10.25 +    struct page_info *page, struct domain *d, int readonly);
   10.26 +extern void share_xen_page_with_privileged_guests(
   10.27 +    struct page_info *page, int readonly);
   10.28  
   10.29  extern struct page_info *frame_table;
   10.30  extern unsigned long max_page;