ia64/xen-unstable

changeset 8118:689315a7ff80

Tidy up audit code for PAE plus avoid its use during live migrate where
it is not strictly required.

Signed-off-by: Steven Hand <steven@xensource.com>
author smh22@firebug.cl.cam.ac.uk
date Tue Nov 29 15:54:44 2005 +0100 (2005-11-29)
parents 37b93f40eb0a
children 92469b92f768
files xen/arch/x86/audit.c xen/arch/x86/shadow_public.c
line diff
     1.1 --- a/xen/arch/x86/audit.c	Tue Nov 29 14:50:30 2005 +0100
     1.2 +++ b/xen/arch/x86/audit.c	Tue Nov 29 15:54:44 2005 +0100
     1.3 @@ -51,7 +51,30 @@ int audit_adjust_pgtables(struct domain 
     1.4      int errors = 0;
     1.5      int shadow_refcounts = !!shadow_mode_refcounts(d);
     1.6      int shadow_enabled = !!shadow_mode_enabled(d);
     1.7 -    int l2limit;
     1.8 +
     1.9 +    int l2limit( unsigned long mfn )
    1.10 +    {
    1.11 +
    1.12 +        if ( shadow_mode_external(d) )
    1.13 +            return L2_PAGETABLE_ENTRIES;
    1.14 +
    1.15 +#ifdef __i386__
    1.16 +#ifdef CONFIG_X86_PAE
    1.17 +        /* 32b PAE */
    1.18 +        if ( (( frame_table[mfn].u.inuse.type_info & PGT_va_mask ) 
    1.19 +	    >> PGT_va_shift) == 3 )
    1.20 +            return l2_table_offset(HYPERVISOR_VIRT_START); 
    1.21 +        else
    1.22 +            return L2_PAGETABLE_ENTRIES;
    1.23 +#else
    1.24 +        /* 32b non-PAE */
    1.25 +        return DOMAIN_ENTRIES_PER_L2_PAGETABLE;
    1.26 +#endif
    1.27 +#else
    1.28 +        /* 64b */
    1.29 +        return 0; /* XXX x86/64 XXX */
    1.30 +#endif
    1.31 +    }
    1.32  
    1.33      void _adjust(struct pfn_info *page, int adjtype ADJUST_EXTRA_ARGS)
    1.34      {
    1.35 @@ -121,15 +144,15 @@ int audit_adjust_pgtables(struct domain 
    1.36  
    1.37      void adjust_l2_page(unsigned long mfn, int shadow)
    1.38      {
    1.39 -        unsigned long *pt = map_domain_page(mfn);
    1.40 +        l2_pgentry_t *pt = map_domain_page(mfn);
    1.41          int i;
    1.42          u32 page_type;
    1.43  
    1.44 -        for ( i = 0; i < l2limit; i++ )
    1.45 +        for ( i = 0; i < l2limit(mfn); i++ )
    1.46          {
    1.47 -            if ( pt[i] & _PAGE_PRESENT )
    1.48 +            if ( l2e_get_flags(pt[i]) & _PAGE_PRESENT )
    1.49              {
    1.50 -                unsigned long l1mfn = pt[i] >> PAGE_SHIFT;
    1.51 +	        unsigned long l1mfn = l2e_get_pfn(pt[i]);
    1.52                  struct pfn_info *l1page = pfn_to_page(l1mfn);
    1.53  
    1.54                  if ( noisy )
    1.55 @@ -199,7 +222,7 @@ int audit_adjust_pgtables(struct domain 
    1.56          if ( shadow_mode_translate(d) && !shadow_mode_external(d) )
    1.57          {
    1.58              unsigned long hl2mfn =
    1.59 -                pt[l2_table_offset(LINEAR_PT_VIRT_START)] >> PAGE_SHIFT;
    1.60 +                l2e_get_pfn(pt[l2_table_offset(LINEAR_PT_VIRT_START)]);
    1.61              struct pfn_info *hl2page = pfn_to_page(hl2mfn);
    1.62              adjust(hl2page, 0);
    1.63          }
    1.64 @@ -209,14 +232,14 @@ int audit_adjust_pgtables(struct domain 
    1.65  
    1.66      void adjust_hl2_page(unsigned long hl2mfn)
    1.67      {
    1.68 -        unsigned long *pt = map_domain_page(hl2mfn);
    1.69 +        l2_pgentry_t *pt = map_domain_page(hl2mfn);
    1.70          int i;
    1.71  
    1.72 -        for ( i = 0; i < l2limit; i++ )
    1.73 +        for ( i = 0; i < l2limit(hl2mfn); i++ )
    1.74          {
    1.75 -            if ( pt[i] & _PAGE_PRESENT )
    1.76 +            if ( l2e_get_flags(pt[i]) & _PAGE_PRESENT )
    1.77              {
    1.78 -                unsigned long gmfn = pt[i] >> PAGE_SHIFT;
    1.79 +                unsigned long gmfn = l2e_get_pfn(pt[i]);
    1.80                  struct pfn_info *gpage = pfn_to_page(gmfn);
    1.81  
    1.82                  if ( gmfn < 0x100 )
    1.83 @@ -256,14 +279,14 @@ int audit_adjust_pgtables(struct domain 
    1.84  
    1.85      void adjust_l1_page(unsigned long l1mfn)
    1.86      {
    1.87 -        unsigned long *pt = map_domain_page(l1mfn);
    1.88 +        l1_pgentry_t *pt = map_domain_page(l1mfn);
    1.89          int i;
    1.90  
    1.91          for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ )
    1.92          {
    1.93 -            if ( pt[i] & _PAGE_PRESENT )
    1.94 +            if ( l1e_get_flags(pt[i]) & _PAGE_PRESENT )
    1.95              {
    1.96 -                unsigned long gmfn = pt[i] >> PAGE_SHIFT;
    1.97 +                unsigned long gmfn = l1e_get_pfn(pt[i]);
    1.98                  struct pfn_info *gpage = pfn_to_page(gmfn);
    1.99  
   1.100                  if ( gmfn < 0x100 )
   1.101 @@ -280,7 +303,7 @@ int audit_adjust_pgtables(struct domain 
   1.102  
   1.103                  if ( noisy )
   1.104                  {
   1.105 -                    if ( pt[i] & _PAGE_RW )
   1.106 +                    if ( l1e_get_flags(pt[i]) & _PAGE_RW )
   1.107                      {
   1.108                          // If it's not a writable page, complain.
   1.109                          //
   1.110 @@ -320,7 +343,7 @@ int audit_adjust_pgtables(struct domain 
   1.111                      }
   1.112                  }
   1.113  
   1.114 -                adjust(gpage, (pt[i] & _PAGE_RW) ? 1 : 0);
   1.115 +                adjust(gpage, (l1e_get_flags(pt[i]) & _PAGE_RW) ? 1 : 0);
   1.116              }
   1.117          }
   1.118  
   1.119 @@ -544,15 +567,6 @@ int audit_adjust_pgtables(struct domain 
   1.120          }
   1.121      }
   1.122  
   1.123 -#ifdef __i386__
   1.124 -    if ( shadow_mode_external(d) )
   1.125 -        l2limit = L2_PAGETABLE_ENTRIES;
   1.126 -    else
   1.127 -        l2limit = DOMAIN_ENTRIES_PER_L2_PAGETABLE;
   1.128 -#else
   1.129 -    l2limit = 0; /* XXX x86/64 XXX */
   1.130 -#endif
   1.131 -
   1.132      adjust_for_pgtbase();
   1.133  
   1.134      adjust_guest_pages();
   1.135 @@ -604,16 +618,17 @@ void _audit_domain(struct domain *d, int
   1.136                               unsigned long mfn)
   1.137      {
   1.138          struct pfn_info *page = &frame_table[mfn];
   1.139 -        unsigned long *pt = map_domain_page(mfn);
   1.140 +        l1_pgentry_t *pt = map_domain_page(mfn);
   1.141          int i;
   1.142  
   1.143          for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ )
   1.144          {
   1.145 -            if ( (pt[i] & _PAGE_PRESENT) && ((pt[i] >> PAGE_SHIFT) == xmfn) )
   1.146 +            if ( (l1e_get_flags(pt[i]) & _PAGE_PRESENT) && 
   1.147 +                 (l1e_get_pfn(pt[i]) == xmfn) )
   1.148                  printk("     found dom=%d mfn=%lx t=%" PRtype_info " c=%08x "
   1.149 -                       "pt[i=%x]=%lx\n",
   1.150 +                       "pt[i=%x]=%" PRIpte "\n",
   1.151                         d->domain_id, mfn, page->u.inuse.type_info,
   1.152 -                       page->count_info, i, pt[i]);
   1.153 +                       page->count_info, i, l1e_get_intpte(pt[i]));
   1.154          }
   1.155  
   1.156          unmap_domain_page(pt);           
     2.1 --- a/xen/arch/x86/shadow_public.c	Tue Nov 29 14:50:30 2005 +0100
     2.2 +++ b/xen/arch/x86/shadow_public.c	Tue Nov 29 15:54:44 2005 +0100
     2.3 @@ -1077,36 +1077,40 @@ int __shadow_mode_enable(struct domain *
     2.4      //
     2.5      free_shadow_pages(d);
     2.6  
     2.7 -    /*
     2.8 -     * Tear down its counts by disassembling its page-table-based ref counts.
     2.9 -     * Also remove CR3's gcount/tcount.
    2.10 -     * That leaves things like GDTs and LDTs and external refs in tact.
    2.11 -     *
    2.12 -     * Most pages will be writable tcount=0.
    2.13 -     * Some will still be L1 tcount=0 or L2 tcount=0.
    2.14 -     * Maybe some pages will be type none tcount=0.
    2.15 -     * Pages granted external writable refs (via grant tables?) will
    2.16 -     * still have a non-zero tcount.  That's OK.
    2.17 -     *
    2.18 -     * gcounts will generally be 1 for PGC_allocated.
    2.19 -     * GDTs and LDTs will have additional gcounts.
    2.20 -     * Any grant-table based refs will still be in the gcount.
    2.21 -     *
    2.22 -     * We attempt to grab writable refs to each page (thus setting its type).
    2.23 -     * Immediately put back those type refs.
    2.24 -     *
    2.25 -     * Assert that no pages are left with L1/L2/L3/L4 type.
    2.26 -     */
    2.27 -    audit_adjust_pgtables(d, -1, 1);
    2.28 -
    2.29      d->arch.shadow_mode = mode;
    2.30  
    2.31      if ( shadow_mode_refcounts(d) )
    2.32      {
    2.33 -        struct list_head *list_ent = d->page_list.next;
    2.34 -        while ( list_ent != &d->page_list )
    2.35 -        {
    2.36 -            struct pfn_info *page = list_entry(list_ent, struct pfn_info, list);
    2.37 +        struct list_head *list_ent; 
    2.38 +
    2.39 +        /*
    2.40 +         * Tear down its counts by disassembling its page-table-based refcounts
    2.41 +         * Also remove CR3's gcount/tcount.
    2.42 +         * That leaves things like GDTs and LDTs and external refs in tact.
    2.43 +         *
    2.44 +         * Most pages will be writable tcount=0.
    2.45 +         * Some will still be L1 tcount=0 or L2 tcount=0.
    2.46 +         * Maybe some pages will be type none tcount=0.
    2.47 +         * Pages granted external writable refs (via grant tables?) will
    2.48 +         * still have a non-zero tcount.  That's OK.
    2.49 +         *
    2.50 +         * gcounts will generally be 1 for PGC_allocated.
    2.51 +         * GDTs and LDTs will have additional gcounts.
    2.52 +         * Any grant-table based refs will still be in the gcount.
    2.53 +         *
    2.54 +         * We attempt to grab writable refs to each page thus setting its type
    2.55 +         * Immediately put back those type refs.
    2.56 +         *
    2.57 +         * Assert that no pages are left with L1/L2/L3/L4 type.
    2.58 +         */
    2.59 +        audit_adjust_pgtables(d, -1, 1);
    2.60 +
    2.61 +
    2.62 +        for (list_ent = d->page_list.next; list_ent != &d->page_list; 
    2.63 +             list_ent = page->list.next) {
    2.64 +            
    2.65 +            struct pfn_info *page = list_entry(list_ent, 
    2.66 +                                               struct pfn_info, list);
    2.67              if ( !get_page_type(page, PGT_writable_page) )
    2.68                  BUG();
    2.69              put_page_type(page);
    2.70 @@ -1114,14 +1118,14 @@ int __shadow_mode_enable(struct domain *
    2.71               * We use tlbflush_timestamp as back pointer to smfn, and need to
    2.72               * clean up it.
    2.73               */
    2.74 -            if ( shadow_mode_external(d) )
    2.75 +            if (shadow_mode_external(d))
    2.76                  page->tlbflush_timestamp = 0;
    2.77 -            list_ent = page->list.next;
    2.78          }
    2.79 +        
    2.80 +        audit_adjust_pgtables(d, 1, 1);
    2.81 +  
    2.82      }
    2.83  
    2.84 -    audit_adjust_pgtables(d, 1, 1);
    2.85 -
    2.86      return 0;
    2.87  
    2.88   nomem: