From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Subject: [PATCH RFC 44/44] misc debugging
Date: Thu, 4 Jan 2018 20:22:09 +0000 [thread overview]
Message-ID: <1515097329-31902-45-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1515097329-31902-1-git-send-email-andrew.cooper3@citrix.com>
Keyhandlers for the following:
'1' - Walk idle_pg_table[]
'2' - Walk each percpu_mappings
'3' - Dump PT shadow stats
---
xen/arch/x86/hvm/save.c | 4 -
xen/arch/x86/mm/p2m-ept.c | 5 +-
xen/arch/x86/pv/pt-shadow.c | 19 ++++
xen/arch/x86/traps.c | 199 +++++++++++++++++++++++++++++++++++++
xen/arch/x86/x86_64/mm.c | 6 ++
xen/include/asm-x86/pv/pt-shadow.h | 17 ++++
6 files changed, 244 insertions(+), 6 deletions(-)
diff --git a/xen/arch/x86/hvm/save.c b/xen/arch/x86/hvm/save.c
index 8984a23..fbdae05 100644
--- a/xen/arch/x86/hvm/save.c
+++ b/xen/arch/x86/hvm/save.c
@@ -223,8 +223,6 @@ int hvm_save(struct domain *d, hvm_domain_context_t *h)
handler = hvm_sr_handlers[i].save;
if ( handler != NULL )
{
- printk(XENLOG_G_INFO "HVM%d save: %s\n",
- d->domain_id, hvm_sr_handlers[i].name);
if ( handler(d, h) != 0 )
{
printk(XENLOG_G_ERR
@@ -297,8 +295,6 @@ int hvm_load(struct domain *d, hvm_domain_context_t *h)
}
/* Load the entry */
- printk(XENLOG_G_INFO "HVM%d restore: %s %"PRIu16"\n", d->domain_id,
- hvm_sr_handlers[desc->typecode].name, desc->instance);
if ( handler(d, h) != 0 )
{
printk(XENLOG_G_ERR "HVM%d restore: failed to load entry %u/%u\n",
diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c
index b4996ce..4167d29 100644
--- a/xen/arch/x86/mm/p2m-ept.c
+++ b/xen/arch/x86/mm/p2m-ept.c
@@ -1285,7 +1285,7 @@ void ept_p2m_uninit(struct p2m_domain *p2m)
free_cpumask_var(ept->invalidate);
}
-static const char *memory_type_to_str(unsigned int x)
+const char *memory_type_to_str(unsigned int x)
{
static const char memory_types[8][3] = {
[MTRR_TYPE_UNCACHABLE] = "UC",
@@ -1293,7 +1293,8 @@ static const char *memory_type_to_str(unsigned int x)
[MTRR_TYPE_WRTHROUGH] = "WT",
[MTRR_TYPE_WRPROT] = "WP",
[MTRR_TYPE_WRBACK] = "WB",
- [MTRR_NUM_TYPES] = "??"
+ [PAT_TYPE_UC_MINUS] = "U-",
+ /* [MTRR_NUM_TYPES] = "??", */
};
ASSERT(x < ARRAY_SIZE(memory_types));
diff --git a/xen/arch/x86/pv/pt-shadow.c b/xen/arch/x86/pv/pt-shadow.c
index d550ae1..f4c522f 100644
--- a/xen/arch/x86/pv/pt-shadow.c
+++ b/xen/arch/x86/pv/pt-shadow.c
@@ -28,6 +28,8 @@
#undef page_to_mfn
#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
+struct ptstats ptstats;
+
/*
* To use percpu linear ranges, we require that no two pcpus have %cr3
* pointing at the same L4 pagetable at the same time.
@@ -224,7 +226,10 @@ unsigned long pt_maybe_shadow(struct vcpu *v)
/* No shadowing necessary? Run on the intended pagetable. */
if ( !pt_need_shadow(v->domain) )
+ {
+ ptstat(&ptstats.sync_none);
return new_cr3;
+ }
ptsh->domain = v->domain;
@@ -259,6 +264,11 @@ unsigned long pt_maybe_shadow(struct vcpu *v)
}
}
local_irq_restore(flags);
+
+ if ( cache_idx )
+ ptstat(&ptstats.sync_shuffle);
+ else
+ ptstat(&ptstats.sync_noshuffle);
}
else
{
@@ -293,6 +303,7 @@ unsigned long pt_maybe_shadow(struct vcpu *v)
sizeof(*l4t) * (L4_PAGETABLE_ENTRIES - (slot + 1)));
unmap_domain_page(vcpu_l4t);
+ ptstat(&ptstats.sync_full);
}
ASSERT(ptsh->cache[0].cr3_mfn == (new_cr3 >> PAGE_SHIFT));
@@ -320,13 +331,19 @@ static void _pt_shadow_ipi(void *arg)
/* No longer shadowing state from this domain? Nothing to do. */
if ( info->d != ptsh->domain )
+ {
+ ptstat(&ptstats.ipi_dom_miss);
return;
+ }
ent = pt_cache_lookup(ptsh, page_to_maddr(info->pg));
/* Not shadowing this frame? Nothing to do. */
if ( ent == NULL )
+ {
+ ptstat(&ptstats.ipi_cache_miss);
return;
+ }
switch ( info->op )
{
@@ -340,6 +357,7 @@ static void _pt_shadow_ipi(void *arg)
l4t[info->slot] = vcpu_l4t[info->slot];
unmap_domain_page(vcpu_l4t);
+ ptstat(&ptstats.ipi_write);
break;
case PTSH_IPI_INVLPG:
@@ -357,6 +375,7 @@ static void _pt_shadow_ipi(void *arg)
case 2: ptsh->cache[2] = ptsh->cache[3];
case 3: ptsh->cache[3] = (pt_cache_entry_t){ shadow_idx };
}
+ ptstat(&ptstats.ipi_invlpg);
break;
default:
diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
index 6b02a5f..095bf97 100644
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -955,6 +955,7 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf,
break;
res->b = flsl(get_upper_mfn_bound()) + PAGE_SHIFT;
+ res->c = v->vcpu_id;
break;
default:
@@ -2074,6 +2075,204 @@ void asm_domain_crash_synchronous(unsigned long addr)
__domain_crash_synchronous();
}
+#include <xen/keyhandler.h>
+#include <asm/pv/pt-shadow.h>
+
+const char *memory_type_to_str(unsigned int x);
+static void decode_intpte(unsigned int level, unsigned int slot, intpte_t pte)
+{
+ unsigned int pat_idx = ((pte >> 3) & 3) |
+ ((pte >> ((level > 1 && (pte & _PAGE_PSE)) ? 10 : 5)) & 4);
+
+ unsigned int mem_type = (host_pat >> (pat_idx << 3)) & 0xff;
+
+ printk("%*sL%u[%03u] %"PRIpte" %*s%s %s%s%s%s%s%s\n",
+ (4 - level) * 2, "",
+ level, slot, pte,
+ (level - 1) * 2, "",
+
+ memory_type_to_str(mem_type),
+
+ pte & 0x8000000000000000ULL ? " Nx" : "",
+ pte & _PAGE_GLOBAL ? " G" : "",
+ (level > 1 && pte & _PAGE_PSE) ? " +" : "",
+ pte & _PAGE_USER ? " U" : "",
+ pte & _PAGE_RW ? " W" : "",
+ pte & _PAGE_PRESENT ? " P" : "");
+}
+
+static bool is_poison(intpte_t pte)
+{
+ return (pte & ~0xfff0000) == 0x800f868600000063;
+}
+
+static void dump_l3t(l3_pgentry_t *l3t, bool decend)
+{
+ unsigned int l3i, l2i, l1i;
+ l2_pgentry_t *l2;
+ l1_pgentry_t *l1;
+
+ for ( l3i = 0; l3i < 512; ++l3i )
+ {
+ if ( !(l3t[l3i].l3 & _PAGE_PRESENT) )
+ continue;
+
+ decode_intpte(3, l3i, l3t[l3i].l3);
+
+ if ( is_poison(l3t[l3i].l3) )
+ continue;
+
+ if ( l3t[l3i].l3 & _PAGE_PSE )
+ continue;
+
+ if ( !decend )
+ continue;
+
+ l2 = l3e_to_l2e(l3t[l3i]);
+ for ( l2i = 0; l2i < 512; ++l2i )
+ {
+ if ( !(l2[l2i].l2 & _PAGE_PRESENT) )
+ continue;
+
+ decode_intpte(2, l2i, l2[l2i].l2);
+
+ if ( is_poison(l2[l2i].l2) )
+ continue;
+
+ if ( l2[l2i].l2 & _PAGE_PSE )
+ continue;
+
+ l1 = l2e_to_l1e(l2[l2i]);
+ for ( l1i = 0; l1i < 512; ++l1i )
+ {
+ if ( !(l1[l1i].l1 & _PAGE_PRESENT) )
+ continue;
+
+ decode_intpte(1, l1i, l1[l1i].l1);
+ }
+
+ process_pending_softirqs();
+ }
+
+ process_pending_softirqs();
+ }
+
+}
+
+static void dump_l4t(l4_pgentry_t *l4t, bool decend)
+{
+ unsigned int l4i;
+
+ for ( l4i = 0; l4i < 512; ++l4i )
+ {
+ if ( !(l4t[l4i].l4 & _PAGE_PRESENT) )
+ continue;
+
+ decode_intpte(4, l4i, l4t[l4i].l4);
+
+ if ( is_poison(l4t[l4i].l4) )
+ continue;
+
+ if ( decend &&
+ l4i != l4_table_offset(LINEAR_PT_VIRT_START) &&
+ l4i != l4_table_offset(SH_LINEAR_PT_VIRT_START) )
+ dump_l3t(l4e_to_l3e(l4t[l4i]), true);
+ }
+}
+
+static void do_extreme_debug(unsigned char key)
+{
+ unsigned int cpu;
+
+ printk("'%c' pressed -> Extreme debugging in progress...\n", key);
+
+ watchdog_disable();
+ console_start_log_everything();
+
+ switch ( key )
+ {
+ case '1':
+ dump_l4t(idle_pg_table, true);
+ break;
+
+ case '2':
+ printk("idle_pg_table[]\n");
+ dump_l4t(idle_pg_table, false);
+
+ for_each_online_cpu ( cpu )
+ {
+ paddr_t l4 = per_cpu(percpu_idle_pt, cpu);
+ l4_pgentry_t mappings = per_cpu(percpu_mappings, cpu);
+ l4_pgentry_t *l4t;
+ l3_pgentry_t *l3t;
+
+ printk("CPU #%u per-pcpu l4 %"PRIpaddr", mappings %"PRIpte"\n",
+ cpu, l4, mappings.l4);
+
+ if ( !l4 )
+ {
+ printk(" BAD l4\n");
+ continue;
+ }
+ if ( !mappings.l4 )
+ {
+ printk(" Bad mappings\n");
+ continue;
+ }
+
+ printk("Dumping L4:\n");
+ l4t = map_domain_page(_mfn(paddr_to_pfn(l4)));
+ dump_l4t(l4t, false);
+ unmap_domain_page(l4t);
+
+ printk("Dumping L3:\n");
+ l3t = map_domain_page(l4e_get_mfn(mappings));
+ dump_l3t(l3t, true);
+ unmap_domain_page(l3t);
+ }
+ break;
+
+ case '3':
+ printk("pt_shadow() stats:\n"
+ " sync_none: %20lu\n"
+ " sync_noshuffle: %20lu\n"
+ " sync_shuffle: %20lu\n"
+ " sync_full: %20lu\n"
+ " ipi_dom_miss: %20lu\n"
+ " ipi_cache_miss: %20lu\n"
+ " ipi_ipi_write: %20lu\n"
+ " ipi_ipi_invlpg: %20lu\n",
+ ptstats.sync_none, ptstats.sync_noshuffle,
+ ptstats.sync_shuffle, ptstats.sync_full,
+ ptstats.ipi_dom_miss, ptstats.ipi_cache_miss,
+ ptstats.ipi_write, ptstats.ipi_invlpg);
+ break;
+ }
+
+ console_end_log_everything();
+ watchdog_enable();
+}
+
+static struct timer stats;
+static void stats_fn(void *unused)
+{
+ do_extreme_debug('3');
+ set_timer(&stats, NOW() + SECONDS(10));
+}
+
+static int __init extreme_debug_keyhandler_init(void)
+{
+ register_keyhandler('1', &do_extreme_debug, "Extreme debugging 1", 0);
+ register_keyhandler('2', &do_extreme_debug, "Extreme debugging 2", 0);
+ register_keyhandler('3', &do_extreme_debug, "Extreme debugging 3", 0);
+
+ init_timer(&stats, stats_fn, NULL, 0);
+ /* set_timer(&stats, NOW() + SECONDS(10)); */
+
+ return 0;
+}
+__initcall(extreme_debug_keyhandler_init);
+
/*
* Local variables:
* mode: C
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index aae721b..a3e81ac 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -874,6 +874,12 @@ void __init subarch_init_memory(void)
}
}
+ /* Poison specific entries. */
+ idle_pg_table[271].l4 = 0x800f868602710063;
+ idle_pg_table[272].l4 = 0x800f868602720063;
+ idle_pg_table[510].l4 = 0x800f868605100063;
+ idle_pg_table[511].l4 = 0x800f868605110063;
+
/* Create an L3 table for the MMCFG region, or remap it NX. */
pl4e = &idle_pg_table[l4_table_offset(PCI_MCFG_VIRT_START)];
if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) )
diff --git a/xen/include/asm-x86/pv/pt-shadow.h b/xen/include/asm-x86/pv/pt-shadow.h
index d5576f4..399ebeb 100644
--- a/xen/include/asm-x86/pv/pt-shadow.h
+++ b/xen/include/asm-x86/pv/pt-shadow.h
@@ -23,6 +23,23 @@
#include <xen/sched.h>
+extern struct ptstats {
+ unsigned long sync_none;
+ unsigned long sync_noshuffle;
+ unsigned long sync_shuffle;
+ unsigned long sync_full;
+
+ unsigned long ipi_dom_miss;
+ unsigned long ipi_cache_miss;
+ unsigned long ipi_write;
+ unsigned long ipi_invlpg;
+} ptstats;
+
+static inline void ptstat(unsigned long *stat)
+{
+ asm volatile ("lock; add $1, %0" : "+m" (*stat));
+}
+
#ifdef CONFIG_PV
/*
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-01-04 20:22 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-04 20:21 [PATCH FAIRLY-RFC 00/44] x86: Prerequisite work for a Xen KAISER solution Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 01/44] passthrough/vtd: Don't DMA to the stack in queue_invalidate_wait() Andrew Cooper
2018-01-05 9:21 ` Jan Beulich
2018-01-05 9:33 ` Andrew Cooper
2018-01-16 6:41 ` Tian, Kevin
2018-01-04 20:21 ` [PATCH RFC 02/44] x86/idt: Factor out enabling and disabling of ISTs Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 03/44] x86/pv: Rename invalidate_shadow_ldt() to pv_destroy_ldt() Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 04/44] x86/boot: Introduce cpu_smpboot_bsp() to dynamically allocate BSP state Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 05/44] x86/boot: Move arch_init_memory() earlier in the boot sequence Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 06/44] x86/boot: Allocate percpu pagetables for the idle vcpus Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 07/44] x86/boot: Use " Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 08/44] x86/pv: Avoid an opencoded mov to %cr3 in toggle_guest_mode() Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 09/44] x86/mm: Track the current %cr3 in a per_cpu variable Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 10/44] x86/pt-shadow: Initial infrastructure for L4 PV pagetable shadowing Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 11/44] x86/pt-shadow: Always set _PAGE_ACCESSED on L4e updates Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 12/44] x86/fixmap: Temporarily add a percpu fixmap range Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 13/44] x86/pt-shadow: Shadow L4 tables from 64bit PV guests Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 14/44] x86/mm: Added safety checks that pagetables aren't shared Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 15/44] x86: Rearrange the virtual layout to introduce a PERCPU linear slot Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 16/44] xen/ipi: Introduce arch_ipi_param_ok() to check IPI parameters Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 17/44] x86/smp: Infrastructure for allocating and freeing percpu pagetables Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 18/44] x86/mm: Maintain the correct percpu mappings on context switch Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 19/44] x86/boot: Defer TSS/IST setup until later during boot on the BSP Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 20/44] x86/smp: Allocate a percpu linear range for the IDT Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 21/44] x86/smp: Switch to using the percpu IDT mappings Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 22/44] x86/mm: Track whether the current cr3 has a short or extended directmap Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 23/44] x86/smp: Allocate percpu resources for map_domain_page() to use Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 24/44] x86/mapcache: Reimplement map_domain_page() from scratch Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 25/44] x86/fixmap: Drop percpu fixmap range Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 26/44] x86/pt-shadow: Maintain a small cache of shadowed frames Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 27/44] x86/smp: Allocate a percpu linear range for the compat translation area Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 28/44] x86/xlat: Use the percpu " Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 29/44] x86/smp: Allocate percpu resources for the GDT and LDT Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 30/44] x86/pv: Break handle_ldt_mapping_fault() out of handle_gdt_ldt_mapping_fault() Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 31/44] x86/pv: Drop support for paging out the LDT Andrew Cooper
2018-01-24 11:04 ` Jan Beulich
2018-01-04 20:21 ` [PATCH RFC 32/44] x86: Always reload the LDT on vcpu context switch Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 33/44] x86/smp: Use the percpu GDT/LDT mappings Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 34/44] x86: Drop the PERDOMAIN mappings Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 35/44] x86/smp: Allocate the stack in the percpu range Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 36/44] x86/monitor: Capture Xen's intent to use monitor at boot time Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 37/44] x86/misc: Move some IPI parameters off the stack Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 38/44] x86/mca: Move __HYPERVISOR_mca " Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 39/44] x86/smp: Introduce get_smp_ipi_buf() and take more " Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 40/44] x86/boot: Switch the APs to the percpu pagetables before entering C Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 41/44] x86/smp: Switch to using the percpu stacks Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 42/44] x86/smp: Allocate a percpu linear range for the TSS Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 43/44] x86/smp: Use the percpu TSS mapping Andrew Cooper
2018-01-04 20:22 ` Andrew Cooper [this message]
2018-01-05 7:48 ` [PATCH FAIRLY-RFC 00/44] x86: Prerequisite work for a Xen KAISER solution Juergen Gross
2018-01-05 9:26 ` Andrew Cooper
2018-01-05 9:39 ` Juergen Gross
2018-01-05 9:56 ` Andrew Cooper
2018-01-05 14:11 ` George Dunlap
2018-01-05 14:17 ` Juergen Gross
2018-01-05 14:21 ` George Dunlap
2018-01-05 14:28 ` Jan Beulich
2018-01-05 14:27 ` Jan Beulich
2018-01-05 14:35 ` Andrew Cooper
2018-01-08 11:41 ` George Dunlap
2018-01-09 23:14 ` Stefano Stabellini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1515097329-31902-45-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).