From: Ian Campbell Subject: Re: [PATCH 02/38] arm: handy function to print a walk of the hypervisor page tables Date: Thu, 7 Jun 2012 12:57:40 +0100 Message-ID: <1339070260.18523.14.camel@zakaz.uk.xensource.com> References: <1338565113.17466.141.camel@zakaz.uk.xensource.com> <1338565207-2888-1-git-send-email-ian.campbell@citrix.com> <1338565207-2888-2-git-send-email-ian.campbell@citrix.com> <20120607084517.GA70339@ocelot.phlegethon.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20120607084517.GA70339@ocelot.phlegethon.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Tim Deegan Cc: "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org On Thu, 2012-06-07 at 09:45 +0100, Tim Deegan wrote: > Hi, > > At 15:39 +0000 on 01 Jun (1338565171), Ian Campbell wrote: > > +void dump_pt_walk(uint32_t addr) > > +{ > > + paddr_t second_ma, third_ma; > > + lpae_t *first = NULL, *second = NULL, *third = NULL; > > + uint64_t httbr = READ_CP64(HTTBR); > > + > > + printk("Walking Hypervisor VA %#"PRIx32" via HTTBR %#"PRIx64"\n", > > + addr, httbr); > > + > > + BUG_ON( (lpae_t *)(unsigned long)(httbr - xen_phys_offset) != xen_pgtable ); > > + first = xen_pgtable; > > + printk("1ST[%#03"PRIx32"] = %p[%#03"PRIx32"] = %#llx = %#016llx\n", > > + first_table_offset(addr), > > + first, first_table_offset(addr), > > + virt_to_maddr(&first[first_table_offset(addr)]), > > + first[first_table_offset(addr)].bits); > > + > > + if ( !first[first_table_offset(addr)].pt.valid || > > + !first[first_table_offset(addr)].pt.table ) > > + goto done; > > This could probably be a for loop rather than open-coding three > almost-identical printks. The *_table_offsets macro names are different at each stage, I suppose I could open code the equivalent shifts, but I'd rather keep using the access macros. > > + > > + second_ma = (paddr_t)first[first_table_offset(addr)].pt.base << PAGE_SHIFT; > > + second = (lpae_t *)(unsigned long)(second_ma - xen_phys_offset); > > + printk("2ND[%#03"PRIx32"] = %p[%#03"PRIx32"] = %#llx = %#016llx\n", > > + second_table_offset(addr), > > + second, second_table_offset(addr), > > + virt_to_maddr(&second[second_table_offset(addr)]), > > + second[second_table_offset(addr)].bits); > > + if ( !second[second_table_offset(addr)].pt.valid || > > + !second[second_table_offset(addr)].pt.table ) > > + goto done; > > + > > + third_ma = (paddr_t)second[second_table_offset(addr)].pt.base << PAGE_SHIFT; > > + third = (lpae_t *)(unsigned long)(third_ma - xen_phys_offset); > > + printk("3RD[%#03"PRIx32"] = %p[%#03"PRIx32"] = %#llx = %#016llx\n", > > + third_table_offset(addr), > > + third, third_table_offset(addr), > > + virt_to_maddr(&third[third_table_offset(addr)]), > > + third[third_table_offset(addr)].bits); > > + if ( !third[third_table_offset(addr)].pt.valid || > > + !third[third_table_offset(addr)].pt.table ) > > + goto done; > > + > > +done: > > + return; > > Maybe use return above instead of goto? Yes, good idea. > > > +} > > + > > /* Map a 4k page in a fixmap entry */ > > void set_fixmap(unsigned map, unsigned long mfn, unsigned attributes) > > { > > @@ -173,8 +222,8 @@ void __init setup_pagetables(unsigned long boot_phys_offset) > > flush_xen_data_tlb_va(dest_va); > > > > /* Calculate virt-to-phys offset for the new location */ > > - phys_offset = xen_paddr - (unsigned long) _start; > > - > > + xen_phys_offset = phys_offset = xen_paddr - (unsigned long) _start; > > + > > Just make phys_offset file-scope static; no need to add a new variable > for this. Will do. > > > /* Copy */ > > memcpy((void *) dest_va, _start, _end - _start); > > > > diff --git a/xen/include/asm-arm/page.h b/xen/include/asm-arm/page.h > > index b6df64e..22c56b5 100644 > > --- a/xen/include/asm-arm/page.h > > +++ b/xen/include/asm-arm/page.h > > @@ -312,6 +312,8 @@ static inline uint64_t gva_to_ipa(uint32_t va) > > /* Bits in the PAR returned by va_to_par */ > > #define PAR_FAULT 0x1 > > > > +extern void dump_pt_walk(uint32_t addr); > > + > > Maybe a comment? Yes, good idea.