In Xen-4.0+, usage of a page must be determined from its PGC_xxx flags, which are stored in the highest bits of the _count field of struct page_info. Let's keep the original function for Xen3 only and add a new function for walking the pages under Xen4. This avoids adding many new conditionals to the inner loop and also makes the logic easier to follow for all Xen versions. Signed-off-by: Norbert Trapp Signed-off-by: Petr Tesarik --- makedumpfile.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- makedumpfile.h | 25 +++++++++++++ 2 files changed, 122 insertions(+), 6 deletions(-) --- a/makedumpfile.h +++ b/makedumpfile.h @@ -78,6 +78,31 @@ int get_mem_type(void); #define LSEEKED_PDATA (3) /* + * Xen page flags + */ +#define BITS_PER_BYTE (8) +#define BITS_PER_LONG (BITS_PER_BYTE * sizeof(long)) +#define PG_shift(idx) (BITS_PER_LONG - (idx)) +#define PG_mask(x, idx) (x ## UL << PG_shift(idx)) + /* Cleared when the owning guest 'frees' this page. */ +#define PGC_allocated PG_mask(1, 1) + /* Page is Xen heap? */ +#define PGC_xen_heap PG_mask(1, 2) + /* Page is broken? */ +#define PGC_broken PG_mask(1, 7) + /* Mutually-exclusive page states: { inuse, offlining, offlined, free }. */ +#define PGC_state PG_mask(3, 9) +#define PGC_state_inuse PG_mask(0, 9) +#define PGC_state_offlining PG_mask(1, 9) +#define PGC_state_offlined PG_mask(2, 9) +#define PGC_state_free PG_mask(3, 9) +#define page_state_is(ci, st) (((ci)&PGC_state) == PGC_state_##st) + + /* Count of references to this frame. */ +#define PGC_count_width PG_shift(9) +#define PGC_count_mask ((1UL<frame_table_vaddr + pfn * SIZE(page_info); + if (!readmem(VADDR_XEN, + page_info_addr + OFFSET(page_info.count_info), + &count_info, sizeof(count_info))) { + clear_bit_on_2nd_bitmap(pfn); + continue; /* page_info may not exist */ + } + + /* delete free and offlined pages + * Note: Broken pages also get offlined + */ + if (page_state_is(count_info, free) || + page_state_is(count_info, offlined)) { + clear_bit_on_2nd_bitmap(pfn); + continue; + } + + /* always keep Xen heap pages */ + if (count_info & PGC_xen_heap) + continue; + + /* delete pages not allocated to any domain */ + if (! (count_info & PGC_allocated)) { + clear_bit_on_2nd_bitmap(pfn); + continue; + } + + if (!readmem(VADDR_XEN, + page_info_addr + OFFSET(page_info._domain), + &_domain, sizeof(_domain))) { + ERRMSG("Can't get page_info._domain.\n"); + return FALSE; + } + + /* + * keep: + * - anonymous (_domain == 0), or + * - selected domain page + */ + if (_domain == 0) + continue; + if (is_select_domain(_domain)) + continue; + clear_bit_on_2nd_bitmap(pfn); + } + } + + return TRUE; +} + +int +exclude_xen_user_domain(void) +{ + struct timeval tv_start; + int ret; + + gettimeofday(&tv_start, NULL); + + if (info->xen_crash_info.com && + info->xen_crash_info.com->xen_major_version >= 4) + ret = exclude_xen4_user_domain(); + else + ret = exclude_xen3_user_domain(); + /* * print [100 %] */ - print_progress(PROGRESS_XEN_DOMAIN, num_pt_loads, num_pt_loads); + print_progress(PROGRESS_XEN_DOMAIN, 1, 1); print_execution_time(PROGRESS_XEN_DOMAIN, &tv_start); - return TRUE; + return ret; } int