WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 6/7] xen/debugfs: Add 'p2m' file for printing out the

To: linux-kernel@xxxxxxxxxxxxxxx, Jeremy Fitzhardinge <jeremy@xxxxxxxx>, hpa@xxxxxxxxx, Ian Campbell <Ian.Campbell@xxxxxxxxxx>
Subject: [Xen-devel] [PATCH 6/7] xen/debugfs: Add 'p2m' file for printing out the P2M layout.
From: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
Date: Mon, 10 Jan 2011 12:17:38 -0500
Cc: Konrad Rzeszutek Wilk <konrad@xxxxxxxxxx>, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx, Jan Beulich <JBeulich@xxxxxxxxxx>, Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Delivery-date: Mon, 10 Jan 2011 09:26:54 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1294679859-30029-1-git-send-email-konrad.wilk@xxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <1294679859-30029-1-git-send-email-konrad.wilk@xxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
We walk over the whole P2M tree and construct a simplified view of
which PFN regions belong to what level and what type they are.

Only enabled if CONFIG_XEN_DEBUG_FS is set.

[v2: UNKN->UNKNOWN, use uninitialized_var]
Reviewed-by: Ian Campbell <Ian.Campbell@xxxxxxxxxxxxx>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
---
 arch/x86/xen/mmu.c |   86 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 86 insertions(+), 0 deletions(-)

diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
index 0cce0c2..6164323 100644
--- a/arch/x86/xen/mmu.c
+++ b/arch/x86/xen/mmu.c
@@ -46,6 +46,7 @@
 #include <linux/module.h>
 #include <linux/gfp.h>
 #include <linux/memblock.h>
+#include <linux/seq_file.h>
 
 #include <asm/pgtable.h>
 #include <asm/tlbflush.h>
@@ -2833,6 +2834,90 @@ EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
 
 #ifdef CONFIG_XEN_DEBUG_FS
 
+static int p2m_dump_show(struct seq_file *m, void *v)
+{
+       static const char * const level_name[] = { "top", "middle",
+                                               "entry", "abnormal" };
+       static const char * const type_name[] = { "identity", "missing",
+                                               "pfn", "abnormal"};
+#define TYPE_IDENTITY 0
+#define TYPE_MISSING 1
+#define TYPE_PFN 2
+#define TYPE_UNKNOWN 3
+       unsigned long pfn, prev_pfn_type = 0, prev_pfn_level = 0;
+       unsigned int uninitialized_var(prev_level);
+       unsigned int uninitialized_var(prev_type);
+
+       if (!p2m_top)
+               return 0;
+
+       for (pfn = 0; pfn < MAX_DOMAIN_PAGES; pfn++) {
+               unsigned topidx = p2m_top_index(pfn);
+               unsigned mididx = p2m_mid_index(pfn);
+               unsigned idx = p2m_index(pfn);
+               unsigned lvl, type;
+
+               lvl = 4;
+               type = TYPE_UNKNOWN;
+               if (p2m_top[topidx] == p2m_mid_missing) {
+                       lvl = 0; type = TYPE_MISSING;
+               } else if (p2m_top[topidx][mididx] == p2m_identity) {
+                       lvl = 1; type = TYPE_IDENTITY;
+               } else if (p2m_top[topidx][mididx][idx] == pfn) {
+                       lvl = 2; type = TYPE_PFN;
+               } else if (p2m_top[topidx][mididx][idx] == IDENTITY_FRAME(pfn)) 
{
+                       lvl = 2; type = TYPE_IDENTITY;
+               } else if (p2m_top[topidx][mididx][idx] != pfn) {
+                       lvl = 2; type = TYPE_PFN;
+               } else if (p2m_top[topidx] == NULL) {
+                       lvl = 0; type = TYPE_UNKNOWN;
+               } else if (p2m_top[topidx][mididx] == NULL) {
+                       lvl = 1; type = TYPE_UNKNOWN;
+               } else if (p2m_top[topidx][mididx][idx] == 0) {
+                       lvl = 2; type = TYPE_UNKNOWN;
+               } else if (p2m_top[topidx][mididx] == p2m_missing) {
+                       lvl = 1; type = TYPE_MISSING;
+               } else if (p2m_top[topidx][mididx][idx] == INVALID_P2M_ENTRY) {
+                       lvl = 2; type = TYPE_MISSING;
+               } else if (p2m_top[topidx][mididx][idx] != pfn) {
+                       lvl = 2; type = TYPE_PFN;
+               }
+               if (pfn == 0) {
+                       prev_level = lvl;
+                       prev_type = type;
+               }
+               if (pfn == MAX_DOMAIN_PAGES-1) {
+                       lvl = 3;
+                       type = TYPE_UNKNOWN;
+               }
+               if (prev_type != type) {
+                       seq_printf(m, " [0x%lx->0x%lx] %s\n",
+                               prev_pfn_type, pfn, type_name[prev_type]);
+                       prev_pfn_type = pfn;
+                       prev_type = type;
+               }
+               if (prev_level != lvl) {
+                       seq_printf(m, " [0x%lx->0x%lx] level %s\n",
+                               prev_pfn_level, pfn, level_name[prev_level]);
+                       prev_pfn_level = pfn;
+                       prev_level = lvl;
+               }
+       }
+       return 0;
+}
+
+static int p2m_dump_open(struct inode *inode, struct file *filp)
+{
+       return single_open(filp, p2m_dump_show, NULL);
+}
+
+static const struct file_operations p2m_dump_fops = {
+       .open           = p2m_dump_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
 static struct dentry *d_mmu_debug;
 
 static int __init xen_mmu_debugfs(void)
@@ -2888,6 +2973,7 @@ static int __init xen_mmu_debugfs(void)
        debugfs_create_u32("prot_commit_batched", 0444, d_mmu_debug,
                           &mmu_stats.prot_commit_batched);
 
+       debugfs_create_file("p2m", 0600, d_mmu_debug, NULL, &p2m_dump_fops);
        return 0;
 }
 fs_initcall(xen_mmu_debugfs);
-- 
1.7.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel