ia64/xen-unstable

changeset 4251:c54f46498d74

bitkeeper revision 1.1253 (423f5bfeAsGuNeyQOV86d_mRSzPc5A)

Removed duplicate file from bk tree.

Signed-off-by: michael.fetterman@cl.cam.ac.uk
author mafetter@fleming.research
date Mon Mar 21 23:42:54 2005 +0000 (2005-03-21)
parents dcf6c3ab8a7b
children 3cd8c263b94e
files .rootkeys ~/audit.c
line diff
     1.1 --- a/.rootkeys	Mon Mar 21 17:36:01 2005 +0000
     1.2 +++ b/.rootkeys	Mon Mar 21 23:42:54 2005 +0000
     1.3 @@ -1239,4 +1239,3 @@ 3eb3c87fPL2T_zBb0bHlbZY-ACEKRw xen/tools
     1.4  3eb3c87fmKYTC5GCh_rydFakZp9ayw xen/tools/figlet/README
     1.5  3eb3c87fdQKQ5OBGbM-KjZfi9Us4ng xen/tools/figlet/figlet.c
     1.6  3eb3c87fS7DNbg0i6yhFs28UIqAK5g xen/tools/figlet/xen.flf
     1.7 -42386d3bKw0QftYe-cDL6_4WiATRTw ~/audit.c
     2.1 --- a/~/audit.c	Mon Mar 21 17:36:01 2005 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,817 +0,0 @@
     2.4 -/******************************************************************************
     2.5 - * arch/x86/audit.c
     2.6 - * 
     2.7 - * Copyright (c) 2002-2005 K A Fraser
     2.8 - * Copyright (c) 2004 Christian Limpach
     2.9 - * Copyright (c) 2005 Michael A Fetterman
    2.10 - * 
    2.11 - * This program is free software; you can redistribute it and/or modify
    2.12 - * it under the terms of the GNU General Public License as published by
    2.13 - * the Free Software Foundation; either version 2 of the License, or
    2.14 - * (at your option) any later version.
    2.15 - * 
    2.16 - * This program is distributed in the hope that it will be useful,
    2.17 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.19 - * GNU General Public License for more details.
    2.20 - * 
    2.21 - * You should have received a copy of the GNU General Public License
    2.22 - * along with this program; if not, write to the Free Software
    2.23 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.24 - */
    2.25 -
    2.26 -#include <xen/config.h>
    2.27 -#include <xen/init.h>
    2.28 -#include <xen/kernel.h>
    2.29 -#include <xen/lib.h>
    2.30 -#include <xen/mm.h>
    2.31 -//#include <xen/sched.h>
    2.32 -//#include <xen/errno.h>
    2.33 -#include <xen/perfc.h>
    2.34 -//#include <xen/irq.h>
    2.35 -//#include <xen/softirq.h>
    2.36 -#include <asm/shadow.h>
    2.37 -#include <asm/page.h>
    2.38 -#include <asm/flushtlb.h>
    2.39 -//#include <asm/io.h>
    2.40 -//#include <asm/uaccess.h>
    2.41 -//#include <asm/domain_page.h>
    2.42 -//#include <asm/ldt.h>
    2.43 -
    2.44 -// XXX SMP bug -- these should not be statics...
    2.45 -//
    2.46 -static int ttot=0, ctot=0, io_mappings=0, lowmem_mappings=0;
    2.47 -static int l1, l2, oos_count, page_count;
    2.48 -
    2.49 -#define FILE_AND_LINE 1
    2.50 -
    2.51 -#if FILE_AND_LINE
    2.52 -#define adjust(_p, _a) _adjust((_p), (_a), __FILE__, __LINE__)
    2.53 -#define ADJUST_EXTRA_ARGS ,const char *file, int line
    2.54 -#define APRINTK(_f, _a...) printk(_f " %s:%d\n", ## _a, file, line)
    2.55 -#else
    2.56 -#define adjust _adjust
    2.57 -#define ADJUST_EXTRA_ARGS
    2.58 -#define APRINTK(_f, _a...) printk(_f "\n", ##_a)
    2.59 -#endif
    2.60 -
    2.61 -int audit_adjust_pgtables(struct domain *d, int dir, int noisy)
    2.62 -{
    2.63 -    int errors = 0;
    2.64 -    int shadow_enabled = shadow_mode_enabled(d) ? 1 : 0;
    2.65 -
    2.66 -    void _adjust(struct pfn_info *page, int adjtype ADJUST_EXTRA_ARGS)
    2.67 -    {
    2.68 -        if ( adjtype )
    2.69 -        {
    2.70 -            // adjust the type count
    2.71 -            //
    2.72 -            int tcount = page->u.inuse.type_info & PGT_count_mask;
    2.73 -            tcount += dir;
    2.74 -            ttot++;
    2.75 -
    2.76 -            if ( page_get_owner(page) == NULL )
    2.77 -            {
    2.78 -                APRINTK("adjust(mfn=%p, dir=%d, adjtype=%d) owner=NULL",
    2.79 -                        page_to_pfn(page), dir, adjtype, file, line);
    2.80 -                errors++;
    2.81 -            }
    2.82 -
    2.83 -            if ( tcount < 0 )
    2.84 -            {
    2.85 -                APRINTK("Audit %d: type count went below zero mfn=%x t=%x ot=%x",
    2.86 -                        d->id, page-frame_table,
    2.87 -                        page->u.inuse.type_info,
    2.88 -                        page->tlbflush_timestamp);
    2.89 -                errors++;
    2.90 -            }
    2.91 -            else if ( (tcount & ~PGT_count_mask) != 0 )
    2.92 -            {
    2.93 -                APRINTK("Audit %d: type count overflowed mfn=%x t=%x ot=%x",
    2.94 -                        d->id, page-frame_table,
    2.95 -                        page->u.inuse.type_info,
    2.96 -                        page->tlbflush_timestamp);
    2.97 -                errors++;
    2.98 -            }
    2.99 -            else
   2.100 -                page->u.inuse.type_info += dir;
   2.101 -        }
   2.102 -
   2.103 -        // adjust the general count
   2.104 -        //
   2.105 -        int count = page->count_info & PGC_count_mask;
   2.106 -        count += dir;
   2.107 -        ctot++;
   2.108 -
   2.109 -        if ( count < 0 )
   2.110 -        {
   2.111 -            APRINTK("Audit %d: general count went below zero pfn=%x t=%x ot=%x",
   2.112 -                    d->id, page-frame_table,
   2.113 -                    page->u.inuse.type_info,
   2.114 -                    page->tlbflush_timestamp);
   2.115 -            errors++;
   2.116 -        }
   2.117 -        else if ( (count & ~PGT_count_mask) != 0 )
   2.118 -        {
   2.119 -            APRINTK("Audit %d: general count overflowed pfn=%x t=%x ot=%x",
   2.120 -                    d->id, page-frame_table,
   2.121 -                    page->u.inuse.type_info,
   2.122 -                    page->tlbflush_timestamp);
   2.123 -            errors++;
   2.124 -        }
   2.125 -        else
   2.126 -            page->count_info += dir;
   2.127 -    }
   2.128 -
   2.129 -    void adjust_l2_page(unsigned long mfn, int adjtype)
   2.130 -    {
   2.131 -        unsigned long *pt = map_domain_mem(mfn << PAGE_SHIFT);
   2.132 -        int i, limit;
   2.133 -
   2.134 -        if ( shadow_mode_external(d) )
   2.135 -            limit = L2_PAGETABLE_ENTRIES;
   2.136 -        else
   2.137 -            limit = DOMAIN_ENTRIES_PER_L2_PAGETABLE;
   2.138 -
   2.139 -        for ( i = 0; i < limit; i++ )
   2.140 -        {
   2.141 -            if ( pt[i] & _PAGE_PRESENT )
   2.142 -            {
   2.143 -                unsigned long l1mfn = pt[i] >> PAGE_SHIFT;
   2.144 -                struct pfn_info *l1page = pfn_to_page(l1mfn);
   2.145 -
   2.146 -                if ( noisy )
   2.147 -                {
   2.148 -                    if ( shadow_enabled )
   2.149 -                    {
   2.150 -                        if ( page_get_owner(l1page) != NULL )
   2.151 -                        {
   2.152 -                            printk("L2: Bizarre shadow L1 page mfn=%p "
   2.153 -                                   "belonging to a domain %p (id=%d)\n",
   2.154 -                                   l1mfn,
   2.155 -                                   page_get_owner(l1page),
   2.156 -                                   page_get_owner(l1page)->id);
   2.157 -                            errors++;
   2.158 -                            continue;
   2.159 -                        }
   2.160 -                    }
   2.161 -                    else
   2.162 -                    {
   2.163 -                        if ( page_get_owner(l1page) != d )
   2.164 -                        {
   2.165 -                            printk("L2: Skip bizarre L1 page mfn=%p "
   2.166 -                                   "belonging to other dom %p (id=%d)\n",
   2.167 -                                   l1mfn,
   2.168 -                                   page_get_owner(l1page),
   2.169 -                                   page_get_owner(l1page)->id);
   2.170 -                            errors++;
   2.171 -                            continue;
   2.172 -                        }
   2.173 -
   2.174 -                        u32 page_type = l1page->u.inuse.type_info & PGT_type_mask;
   2.175 -
   2.176 -                        if ( page_type == PGT_l2_page_table )
   2.177 -                        {
   2.178 -                            printk("Audit %d: [%x] Found %s Linear PT "
   2.179 -                                   "t=%x mfn=%p\n",
   2.180 -                                   d->id, i, (l1mfn==mfn) ? "Self" : "Other",
   2.181 -                                   l1page->u.inuse.type_info, l1mfn);
   2.182 -                        }
   2.183 -                        else if ( page_type != PGT_l1_page_table )
   2.184 -                        {
   2.185 -                            printk("Audit %d: [L2 mfn=%p i=%x] "
   2.186 -                                   "Expected L1 t=%x mfn=%p\n",
   2.187 -                                   d->id, mfn, i,
   2.188 -                                   l1page->u.inuse.type_info, l1mfn);
   2.189 -                            errors++;
   2.190 -                        }
   2.191 -                    }
   2.192 -                }
   2.193 -
   2.194 -                adjust(l1page, adjtype);
   2.195 -            }
   2.196 -        }
   2.197 -
   2.198 -        unmap_domain_mem(pt);
   2.199 -    }
   2.200 -
   2.201 -    void adjust_l1_page(unsigned long l1mfn)
   2.202 -    {
   2.203 -        unsigned long *pt = map_domain_mem(l1mfn << PAGE_SHIFT);
   2.204 -        int i;
   2.205 -
   2.206 -        for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ )
   2.207 -        {
   2.208 -            if ( pt[i] & _PAGE_PRESENT )
   2.209 -            {
   2.210 -                unsigned long gmfn = pt[i] >> PAGE_SHIFT;
   2.211 -                struct pfn_info *gpage = pfn_to_page(gmfn);
   2.212 -
   2.213 -                if ( gmfn < 0x100 )
   2.214 -                {
   2.215 -                    lowmem_mappings++;
   2.216 -                    continue;
   2.217 -                }
   2.218 -
   2.219 -                if ( gmfn > max_page )
   2.220 -                {
   2.221 -                    io_mappings++;
   2.222 -                    continue;
   2.223 -                }
   2.224 -
   2.225 -                if ( noisy )
   2.226 -                {
   2.227 -                    if ( pt[i] & _PAGE_RW )
   2.228 -                    {
   2.229 -                        // If it's not a writable page, complain.
   2.230 -                        //
   2.231 -                        if ( !((gpage->u.inuse.type_info & PGT_type_mask) ==
   2.232 -                               PGT_writable_page) )
   2.233 -                        {
   2.234 -                            printk("Audit %d: [l1mfn=%p, i=%x] Illegal RW "
   2.235 -                                   "t=%x mfn=%p\n",
   2.236 -                                   d->id, l1mfn, i,
   2.237 -                                   gpage->u.inuse.type_info, gmfn);
   2.238 -                            errors++;
   2.239 -                        }
   2.240 -
   2.241 -                        if ( shadow_enabled &&
   2.242 -                             page_is_page_table(gpage) &&
   2.243 -                             ! page_out_of_sync(gpage) )
   2.244 -                        {
   2.245 -                            printk("Audit %d: [l1mfn=%p, i=%x] Illegal RW of "
   2.246 -                                   "page table gmfn=%p\n",
   2.247 -                                   d->id, l1mfn, i, gmfn);
   2.248 -                            errors++;
   2.249 -                        }
   2.250 -                    }
   2.251 -
   2.252 -                    if ( page_get_owner(gpage) != d )
   2.253 -                    {
   2.254 -                        printk("Audit %d: [l1mfn=%p,i=%x] Skip foreign page "
   2.255 -                               "dom=%p (id=%d) mfn=%p c=%08x t=%08x\n",
   2.256 -                               d->id, l1mfn, i,
   2.257 -                               page_get_owner(gpage),
   2.258 -                               page_get_owner(gpage)->id,
   2.259 -                               gmfn,
   2.260 -                               gpage->count_info,
   2.261 -                               gpage->u.inuse.type_info);
   2.262 -                        continue;
   2.263 -                    }
   2.264 -                }
   2.265 -
   2.266 -                adjust(gpage, (pt[i] & _PAGE_RW) ? 1 : 0);
   2.267 -            }
   2.268 -        }
   2.269 -
   2.270 -        unmap_domain_mem(pt);
   2.271 -    }
   2.272 -
   2.273 -    void adjust_shadow_tables()
   2.274 -    {
   2.275 -        struct shadow_status *a;
   2.276 -        unsigned long smfn, gmfn;
   2.277 -        struct pfn_info *page;
   2.278 -        int i;
   2.279 -
   2.280 -        for ( i = 0; i < shadow_ht_buckets; i++ )
   2.281 -        {
   2.282 -            a = &d->arch.shadow_ht[i];
   2.283 -            while ( a && a->gpfn_and_flags )
   2.284 -            {
   2.285 -                gmfn = __gpfn_to_mfn(d, a->gpfn_and_flags & PGT_mfn_mask);
   2.286 -                smfn = a->smfn;
   2.287 -                page = &frame_table[smfn];
   2.288 -
   2.289 -                adjust(pfn_to_page(gmfn), 0);
   2.290 -
   2.291 -                switch ( a->gpfn_and_flags & PGT_type_mask ) {
   2.292 -                case PGT_snapshot:
   2.293 -                    break;
   2.294 -                case PGT_l1_shadow:
   2.295 -                case PGT_hl2_shadow:
   2.296 -                    adjust_l1_page(smfn);
   2.297 -                    if ( page->u.inuse.type_info & PGT_pinned )
   2.298 -                        adjust(page, 0);
   2.299 -                    break;
   2.300 -                case PGT_l2_shadow:
   2.301 -                    adjust_l2_page(smfn, 0);
   2.302 -                    if ( page->u.inuse.type_info & PGT_pinned )
   2.303 -                        adjust(page, 0);
   2.304 -                    break;
   2.305 -                default:
   2.306 -                    BUG();
   2.307 -                    break;
   2.308 -                }
   2.309 -
   2.310 -                a = a->next;
   2.311 -            }
   2.312 -        }
   2.313 -    }
   2.314 -
   2.315 -    void adjust_oos_list()
   2.316 -    {
   2.317 -        struct out_of_sync_entry *oos;
   2.318 -
   2.319 -        if ( (oos = d->arch.out_of_sync) )
   2.320 -            ASSERT(shadow_enabled);
   2.321 -
   2.322 -        while ( oos )
   2.323 -        {
   2.324 -            adjust(pfn_to_page(oos->gmfn), 0);
   2.325 -
   2.326 -            // Only use entries that have low bits clear...
   2.327 -            //
   2.328 -            if ( !(oos->writable_pl1e & (sizeof(l1_pgentry_t)-1)) )
   2.329 -                adjust(pfn_to_page(oos->writable_pl1e >> PAGE_SHIFT), 0);
   2.330 -
   2.331 -            oos = oos->next;
   2.332 -            oos_count++;
   2.333 -        }
   2.334 -    }
   2.335 -
   2.336 -    void adjust_for_pgtbase()
   2.337 -    {
   2.338 -        struct exec_domain *ed;
   2.339 -
   2.340 -        for_each_exec_domain(d, ed)
   2.341 -            {
   2.342 -                if ( !shadow_enabled )
   2.343 -                {
   2.344 -                    if ( pagetable_val(ed->arch.guest_table) )
   2.345 -                        adjust(&frame_table[pagetable_val(ed->arch.guest_table)
   2.346 -                                            >> PAGE_SHIFT], 1);
   2.347 -                }
   2.348 -                else
   2.349 -                {
   2.350 -                    if ( pagetable_val(ed->arch.guest_table) )
   2.351 -                        adjust(&frame_table[pagetable_val(ed->arch.guest_table)
   2.352 -                                            >> PAGE_SHIFT], 0);
   2.353 -                    if ( pagetable_val(ed->arch.shadow_table) )
   2.354 -                        adjust(&frame_table[pagetable_val(ed->arch.shadow_table)
   2.355 -                                            >> PAGE_SHIFT], 0);
   2.356 -                }
   2.357 -            }
   2.358 -    }
   2.359 -
   2.360 -    void adjust_guest_pages()
   2.361 -    {
   2.362 -        struct list_head *list_ent = d->page_list.next;
   2.363 -        struct pfn_info *page;
   2.364 -        unsigned long mfn;
   2.365 -
   2.366 -        while ( list_ent != &d->page_list )
   2.367 -        {
   2.368 -            u32 page_type;
   2.369 -
   2.370 -            page = list_entry(list_ent, struct pfn_info, list);
   2.371 -            mfn = page_to_pfn(page);
   2.372 -            page_type = page->u.inuse.type_info & PGT_type_mask;
   2.373 -
   2.374 -            if ( page_get_owner(page) != d )
   2.375 -                BUG();
   2.376 -
   2.377 -            page_count++;
   2.378 -
   2.379 -            switch ( page_type )
   2.380 -            {
   2.381 -            case PGT_l2_page_table:
   2.382 -                l2++;
   2.383 -
   2.384 -                if ( noisy )
   2.385 -                {
   2.386 -                    if ( shadow_enabled )
   2.387 -                    {
   2.388 -                        printk("Audit %d: found an L2 guest page "
   2.389 -                               "mfn=%p t=%08x c=%08x while in shadow mode\n",
   2.390 -                               mfn, page->u.inuse.type_info, page->count_info);
   2.391 -                        errors++;
   2.392 -                    }
   2.393 -
   2.394 -                    if ( (page->u.inuse.type_info & PGT_validated) !=
   2.395 -                         PGT_validated )
   2.396 -                    {
   2.397 -                        printk("Audit %d: L2 mfn=%p not validated %p\n",
   2.398 -                               d->id, mfn, page->u.inuse.type_info);
   2.399 -                        errors++;
   2.400 -                    }
   2.401 -
   2.402 -                    if ( (page->u.inuse.type_info & PGT_pinned) != PGT_pinned )
   2.403 -                    {
   2.404 -                        printk("Audit %d: L2 mfn=%p not pinned t=%p\n",
   2.405 -                               d->id, mfn, page->u.inuse.type_info);
   2.406 -                        errors++;
   2.407 -                    }
   2.408 -                }
   2.409 -
   2.410 -                if ( page->u.inuse.type_info & PGT_pinned )
   2.411 -                    adjust(page, 1);
   2.412 -
   2.413 -                if ( page->u.inuse.type_info & PGT_validated )
   2.414 -                    adjust_l2_page(mfn, 1);
   2.415 -
   2.416 -                break;
   2.417 -
   2.418 -            case PGT_l1_page_table:
   2.419 -                l1++;
   2.420 -
   2.421 -                if ( noisy )
   2.422 -                {
   2.423 -                    if ( shadow_enabled )
   2.424 -                    {
   2.425 -                        printk("found an L1 guest page mfn=%p t=%08x c=%08x while in shadow mode\n",
   2.426 -                               mfn, page->u.inuse.type_info, page->count_info);
   2.427 -                        errors++;
   2.428 -                    }
   2.429 -
   2.430 -                    if ( (page->u.inuse.type_info & PGT_validated) != PGT_validated )
   2.431 -                    {
   2.432 -                        printk("Audit %d: L1 not validated mfn=%p t=%p\n",
   2.433 -                               d->id, mfn, page->u.inuse.type_info);
   2.434 -                        errors++;
   2.435 -                    }
   2.436 -
   2.437 -                    if ( (page->u.inuse.type_info & PGT_pinned) != PGT_pinned )
   2.438 -                    {
   2.439 -                        if ( !VM_ASSIST(d, VMASST_TYPE_writable_pagetables) )
   2.440 -                        {
   2.441 -                            printk("Audit %d: L1 mfn=%p not pinned t=%p\n",
   2.442 -                                   d->id, mfn, page->u.inuse.type_info);
   2.443 -                            errors++;
   2.444 -                        }
   2.445 -                    }
   2.446 -                }
   2.447 -                
   2.448 -                if ( page->u.inuse.type_info & PGT_pinned )
   2.449 -                    adjust(page, 1);
   2.450 -
   2.451 -                if ( page->u.inuse.type_info & PGT_validated )
   2.452 -                    adjust_l1_page(mfn);
   2.453 -
   2.454 -                break;
   2.455 -
   2.456 -            case PGT_gdt_page:
   2.457 -                ASSERT( !page_out_of_sync(page) );
   2.458 -                adjust(page, 1);
   2.459 -                break;
   2.460 -
   2.461 -            case PGT_ldt_page:
   2.462 -                ASSERT( !page_out_of_sync(page) );
   2.463 -                adjust(page, 1);
   2.464 -                break;
   2.465 -
   2.466 -            case PGT_writable_page:
   2.467 -                if ( shadow_enabled )
   2.468 -                {
   2.469 -                    // In shadow mode, writable pages can get pinned by
   2.470 -                    // paravirtualized guests that think they are pinning
   2.471 -                    // their L1s and/or L2s.
   2.472 -                    //
   2.473 -                    if ( page->u.inuse.type_info & PGT_pinned )
   2.474 -                        adjust(page, 1);
   2.475 -                }
   2.476 -            }
   2.477 -
   2.478 -            list_ent = page->list.next;
   2.479 -        }
   2.480 -    }
   2.481 -
   2.482 -    adjust_for_pgtbase();
   2.483 -
   2.484 -    adjust_guest_pages();
   2.485 -
   2.486 -    if ( shadow_enabled )
   2.487 -    {
   2.488 -        adjust_oos_list();
   2.489 -        adjust_shadow_tables();
   2.490 -    }
   2.491 -
   2.492 -    return errors;
   2.493 -}
   2.494 -
   2.495 -
   2.496 -#ifndef NDEBUG
   2.497 -
   2.498 -void _audit_domain(struct domain *d, int flags, const char *file, int line)
   2.499 -{
   2.500 -    void scan_for_pfn_in_mfn(struct domain *d, unsigned long xmfn,
   2.501 -                             unsigned long mfn)
   2.502 -    {
   2.503 -        struct pfn_info *page = &frame_table[mfn];
   2.504 -        unsigned long *pt = map_domain_mem(mfn);
   2.505 -        int i;
   2.506 -
   2.507 -        for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ )
   2.508 -        {
   2.509 -            if ( (pt[i] & _PAGE_PRESENT) && ((pt[i] >> PAGE_SHIFT) == xmfn) )
   2.510 -                printk("     found dom=%d mfn=%p t=%x c=%x pt[i=%x]=%p\n",
   2.511 -                       d->id, mfn, page->u.inuse.type_info,
   2.512 -                       page->count_info, i, pt[i]);
   2.513 -        }
   2.514 -
   2.515 -        unmap_domain_mem(pt);           
   2.516 -    }
   2.517 -
   2.518 -    void scan_for_pfn(struct domain *d, unsigned long xmfn)
   2.519 -    {
   2.520 -        if ( !shadow_mode_enabled(d) )
   2.521 -        {
   2.522 -            struct list_head *list_ent = d->page_list.next;
   2.523 -            struct pfn_info *page;
   2.524 -
   2.525 -            while ( list_ent != &d->page_list )
   2.526 -            {
   2.527 -                page = list_entry(list_ent, struct pfn_info, list);
   2.528 -
   2.529 -                switch ( page->u.inuse.type_info & PGT_type_mask )
   2.530 -                {
   2.531 -                case PGT_l1_page_table:
   2.532 -                case PGT_l2_page_table:
   2.533 -                    scan_for_pfn_in_mfn(d, xmfn, page_to_pfn(page));
   2.534 -                    break;
   2.535 -                default:
   2.536 -                    break;
   2.537 -                }
   2.538 -
   2.539 -                list_ent = page->list.next;
   2.540 -            }
   2.541 -        }
   2.542 -        else
   2.543 -        {
   2.544 -            struct shadow_status *a;
   2.545 -            int i;
   2.546 -            
   2.547 -            for ( i = 0; i < shadow_ht_buckets; i++ )
   2.548 -            {
   2.549 -                a = &d->arch.shadow_ht[i];
   2.550 -                while ( a && a->gpfn_and_flags )
   2.551 -                {
   2.552 -                    switch ( a->gpfn_and_flags & PGT_type_mask )
   2.553 -                    {
   2.554 -                    case PGT_l1_shadow:
   2.555 -                    case PGT_l2_shadow:
   2.556 -                    case PGT_hl2_shadow:
   2.557 -                        scan_for_pfn_in_mfn(d, xmfn, a->smfn);
   2.558 -                        break;
   2.559 -                    case PGT_snapshot:
   2.560 -                        break;
   2.561 -                    default:
   2.562 -                        BUG();
   2.563 -                        break;
   2.564 -                    }
   2.565 -                    a = a->next;
   2.566 -                }
   2.567 -            }
   2.568 -        }
   2.569 -    }
   2.570 -
   2.571 -    void scan_for_pfn_remote(unsigned long xmfn)
   2.572 -    {
   2.573 -        struct domain *e;
   2.574 -        for_each_domain ( e )
   2.575 -            scan_for_pfn( e, xmfn );
   2.576 -    } 
   2.577 -
   2.578 -    unsigned long mfn;
   2.579 -    struct list_head *list_ent;
   2.580 -    struct pfn_info *page;
   2.581 -    int errors = 0;
   2.582 -
   2.583 -    if ( d != current->domain )
   2.584 -        domain_pause(d);
   2.585 -    synchronise_pagetables(~0UL);
   2.586 -
   2.587 -    // Maybe we should just be using BIGLOCK?
   2.588 -    //
   2.589 -    if ( !(flags & AUDIT_ALREADY_LOCKED) )
   2.590 -        shadow_lock(d);
   2.591 -
   2.592 -    spin_lock(&d->page_alloc_lock);
   2.593 -
   2.594 -    /* PHASE 0 */
   2.595 -
   2.596 -    list_ent = d->page_list.next;
   2.597 -    while ( list_ent != &d->page_list )
   2.598 -    {
   2.599 -        u32 page_type;
   2.600 -
   2.601 -        page = list_entry(list_ent, struct pfn_info, list);
   2.602 -        mfn = page_to_pfn(page);
   2.603 -        page_type = page->u.inuse.type_info & PGT_type_mask;
   2.604 -
   2.605 -        if ( page_get_owner(page) != d )
   2.606 -            BUG();
   2.607 -
   2.608 -        if ( (page->u.inuse.type_info & PGT_count_mask) >
   2.609 -             (page->count_info & PGC_count_mask) )
   2.610 -        {
   2.611 -            printk("taf(%08x) > caf(%08x) mfn=%p\n",
   2.612 -                   page->u.inuse.type_info, page->count_info, mfn);
   2.613 -            errors++;
   2.614 -        }
   2.615 -
   2.616 -        if ( shadow_mode_enabled(d) &&
   2.617 -             (page_type == PGT_writable_page) &&
   2.618 -             !(page->u.inuse.type_info & PGT_validated) )
   2.619 -        {
   2.620 -            printk("shadow mode writable page not validated mfn=%p t=%08x c=%08x\n",
   2.621 -                   mfn, page->u.inuse.type_info, page->count_info);
   2.622 -            errors++;
   2.623 -        }
   2.624 - 
   2.625 -#if 0   /* SYSV shared memory pages plus writeable files. */
   2.626 -        if ( page_type == PGT_writable_page && 
   2.627 -             (page->u.inuse.type_info & PGT_count_mask) > 1 )
   2.628 -        {
   2.629 -            printk("writeable page with type count >1: mfn=%lx t=%x c=%x\n",
   2.630 -                  mfn,
   2.631 -                  page->u.inuse.type_info,
   2.632 -                  page->count_info );
   2.633 -            errors++;
   2.634 -            scan_for_pfn_remote(mfn);
   2.635 -        }
   2.636 -#endif
   2.637 -
   2.638 -        if ( page_type == PGT_none && 
   2.639 -             (page->u.inuse.type_info & PGT_count_mask) > 0 )
   2.640 -        {
   2.641 -            printk("normal page with type count >0: mfn=%lx t=%x c=%x\n",
   2.642 -                  mfn,
   2.643 -                  page->u.inuse.type_info,
   2.644 -                  page->count_info );
   2.645 -            errors++;
   2.646 -        }
   2.647 -
   2.648 -        if ( page_out_of_sync(page) )
   2.649 -        {
   2.650 -            if ( !page_is_page_table(page) )
   2.651 -            {
   2.652 -                printk("out of sync page mfn=%p is not a page table\n", mfn);
   2.653 -                errors++;
   2.654 -            }
   2.655 -            unsigned long pfn = __mfn_to_gpfn(d, mfn);
   2.656 -            if ( !__shadow_status(d, pfn, PGT_snapshot) )
   2.657 -            {
   2.658 -                printk("out of sync page mfn=%p doesn't have a snapshot\n");
   2.659 -                errors++;
   2.660 -            }
   2.661 -            if ( page_type != PGT_writable_page )
   2.662 -            {
   2.663 -                printk("out of sync page mfn=%p has strange type t=%08x c=%08x\n",
   2.664 -                       mfn, page->u.inuse.type_info, page->count_info);
   2.665 -                errors++;
   2.666 -            }
   2.667 -        }
   2.668 -
   2.669 -        /* Use tlbflush_timestamp to store original type_info. */
   2.670 -        page->tlbflush_timestamp = page->u.inuse.type_info;
   2.671 -
   2.672 -        list_ent = page->list.next;
   2.673 -    }
   2.674 -
   2.675 -    /* PHASE 1 */
   2.676 -    io_mappings = lowmem_mappings = 0;
   2.677 -
   2.678 -    errors += audit_adjust_pgtables(d, -1, 1);
   2.679 -
   2.680 -    if ( !(flags & AUDIT_QUIET) &&
   2.681 -         ((io_mappings > 0) || (lowmem_mappings > 0)) )
   2.682 -        printk("Audit %d: Found %d lowmem mappings and %d io mappings\n",
   2.683 -               d->id, lowmem_mappings, io_mappings);
   2.684 -
   2.685 -    /* PHASE 2 */
   2.686 -
   2.687 -    list_ent = d->page_list.next;
   2.688 -    while ( list_ent != &d->page_list )
   2.689 -    {
   2.690 -        page = list_entry(list_ent, struct pfn_info, list);
   2.691 -        mfn = page_to_pfn(page);
   2.692 -
   2.693 -        switch ( page->u.inuse.type_info & PGT_type_mask)
   2.694 -        {
   2.695 -        case PGT_l1_page_table:
   2.696 -        case PGT_l2_page_table:
   2.697 -            if ( (page->u.inuse.type_info & PGT_count_mask) != 0 )
   2.698 -            {
   2.699 -                printk("Audit %d: type count!=0 t=%x ot=%x c=%x mfn=%lx\n",
   2.700 -                       d->id, page->u.inuse.type_info, 
   2.701 -                       page->tlbflush_timestamp,
   2.702 -                       page->count_info, mfn);
   2.703 -                errors++;
   2.704 -                scan_for_pfn_remote(mfn);
   2.705 -            }
   2.706 -            break;
   2.707 -        case PGT_none:
   2.708 -        case PGT_writable_page:
   2.709 -        case PGT_gdt_page:
   2.710 -        case PGT_ldt_page:
   2.711 -            if ( (page->u.inuse.type_info & PGT_count_mask) != 0 )
   2.712 -            {
   2.713 -                printk("Audit %d: type count!=0 t=%x ot=%x c=%x mfn=%lx\n",
   2.714 -                       d->id, page->u.inuse.type_info, 
   2.715 -                       page->tlbflush_timestamp,
   2.716 -                       page->count_info, mfn);
   2.717 -                errors++;
   2.718 -            }
   2.719 -            break;
   2.720 -        default:
   2.721 -            BUG(); // XXX fix me...
   2.722 -        }
   2.723 -        
   2.724 -        if ( (page->count_info & PGC_count_mask) != 1 )
   2.725 -        {
   2.726 -            printk("Audit %d: gen count!=1 (c=%x) t=%x ot=%x mfn=%lx\n",
   2.727 -                   d->id,
   2.728 -                   page->count_info,
   2.729 -                   page->u.inuse.type_info, 
   2.730 -                   page->tlbflush_timestamp, mfn );
   2.731 -            errors++;
   2.732 -            scan_for_pfn_remote(mfn);
   2.733 -        }
   2.734 -
   2.735 -        list_ent = page->list.next;
   2.736 -    }
   2.737 -
   2.738 -    if ( shadow_mode_enabled(d) )
   2.739 -    {
   2.740 -        struct shadow_status *a;
   2.741 -        struct pfn_info *page;
   2.742 -        u32 page_type;
   2.743 -        int i;
   2.744 -
   2.745 -        for ( i = 0; i < shadow_ht_buckets; i++ )
   2.746 -        {
   2.747 -            a = &d->arch.shadow_ht[i];
   2.748 -            while ( a && a->gpfn_and_flags )
   2.749 -            {
   2.750 -                page = pfn_to_page(a->smfn);
   2.751 -                page_type = a->gpfn_and_flags & PGT_type_mask;
   2.752 -
   2.753 -                switch ( page_type ) {
   2.754 -                case PGT_snapshot:
   2.755 -                    // XXX -- what should we check here?
   2.756 -                    break;
   2.757 -                case PGT_l1_shadow:
   2.758 -                case PGT_l2_shadow:
   2.759 -                    if ( ((page->u.inuse.type_info & PGT_type_mask) != page_type ) ||
   2.760 -                         (page->count_info != 0) )
   2.761 -                    {
   2.762 -                        printk("Audit %d: shadow page counts wrong mfn=%p t=%x c=%x\n",
   2.763 -                               d->id, page_to_pfn(page),
   2.764 -                               page->u.inuse.type_info,
   2.765 -                               page->count_info);
   2.766 -                        errors++;
   2.767 -                    }
   2.768 -                    break;
   2.769 -
   2.770 -                case PGT_hl2_shadow: // haven't thought about this case yet.
   2.771 -                default:
   2.772 -                    BUG();
   2.773 -                    break;
   2.774 -                }
   2.775 -
   2.776 -                a = a->next;
   2.777 -            }
   2.778 -        }
   2.779 -    }
   2.780 -
   2.781 -    /* PHASE 3 */
   2.782 -    ctot = ttot = page_count = l1 = l2 = oos_count = 0;
   2.783 -
   2.784 -    audit_adjust_pgtables(d, 1, 0);
   2.785 -
   2.786 -#if 0
   2.787 -    // This covers our sins of trashing the tlbflush_timestamps...
   2.788 -    //
   2.789 -    local_flush_tlb();
   2.790 -#endif
   2.791 -
   2.792 -    spin_unlock(&d->page_alloc_lock);
   2.793 -
   2.794 -    if ( !(flags & AUDIT_QUIET) )
   2.795 -        printk("Audit dom%d (%s:%d) Done. "
   2.796 -               "pages=%d oos=%d l1=%d l2=%d ctot=%d ttot=%d\n",
   2.797 -               d->id, file, line, page_count, oos_count, l1, l2, ctot, ttot );
   2.798 -
   2.799 -    if ( !(flags & AUDIT_ALREADY_LOCKED) )
   2.800 -        shadow_unlock(d);
   2.801 -
   2.802 -    if ( d != current->domain )
   2.803 -        domain_unpause(d);
   2.804 -
   2.805 -    if ( errors && !(flags & AUDIT_ERRORS_OK) )
   2.806 -        BUG();
   2.807 -}
   2.808 -
   2.809 -void audit_domains(void)
   2.810 -{
   2.811 -    struct domain *d;
   2.812 -    for_each_domain ( d )
   2.813 -        audit_domain(d);
   2.814 -}
   2.815 -
   2.816 -void audit_domains_key(unsigned char key)
   2.817 -{
   2.818 -    audit_domains();
   2.819 -}
   2.820 -#endif