<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<tt>Magnus Damm wrote:</tt>
<blockquote TYPE=CITE><tt>On Tue, 2006-10-24 at 09:45 -0400, Dave Anderson
wrote:</tt>
<br><tt>> Magnus Damm wrote:</tt>
<br><tt>> > The idea is that the crash_notes contents in the Xen hypervisor</tt>
<br><tt>> space</tt>
<br><tt>> > contains registers indexed by physical cpu number.</tt>
<br><tt>> ></tt>
<br><tt>> > It is possible to locate the crashing physical cpu by looking
up a</tt>
<br><tt>> > global variable in hypervisor symbol, and from there it should
be</tt>
<br><tt>> > possible to backtrack and find the domain pseudo-phys to virt</tt>
<br><tt>> mapping</tt>
<br><tt>> > table. I say "should" because it is probably pretty hairy.</tt>
<br><tt>> ></tt>
<br><tt>></tt>
<br><tt>> Actually, given that the crash utility is only interested in
the</tt>
<br><tt>> specifics of the dom0 kernel, it has no interest in physical</tt>
<br><tt>> cpus.  If you're specifically interested in debugging a
crash</tt>
<br><tt>> that occurred while operating in the xen binary, you're going</tt>
<br><tt>> to want to use gdb on the vmcore file with xen-syms-xxx</tt>
<br><tt>> namelist file.  You can still run crash on the same vmcore
to</tt>
<br><tt>> find out what was going on in the dom0 kernel, but there's</tt>
<br><tt>> no awareness of the xen hypervisor underpinnings; you'll</tt>
<br><tt>> just get the state of the dom0 kernel at the time of the crash.</tt><tt></tt>
<p><tt>Exactly. But for gdb to work we need to provide crash notes to the
xen</tt>
<br><tt>vmcore file - and with physical cpu crash notes in this case. I
just</tt>
<br><tt>hacked up some code to do this and it seems like the default number
of</tt>
<br><tt>cpus in xen-unstable is set to 32. That's 32 crash notes.</tt>
<br><tt></tt> </blockquote>
<tt>That's fine -- the crash utility will ignore the registers in the</tt>
<br><tt>NT_PRSTATUS notes if it can determine that the vmcore is</tt>
<br><tt>a hypervisor/dom0/kdump-type dumpfile.  In my prototype, it</tt>
<br><tt>does just that when it sees the unique NT_XEN_DOM0_CR3 note.</tt>
<br><tt>(crash doesn't really need the NR_PRSTATUS register contents,</tt>
<br><tt>because it can find them elsewhere if need be.)</tt>
<blockquote TYPE=CITE><tt></tt> 
<br><tt>> But I would guess-timate that the majority of the crashes are</tt>
<br><tt>> going to have occurred in the dom0 kernel, and not while</tt>
<br><tt>> running in the hypervisor.</tt><tt></tt>
<p><tt>Yeah, given the number of lines of code...</tt><tt></tt>
<p><tt>> Now, given that that the crash_notes context contains registers</tt>
<br><tt>> that are indexed by the physical cpu number, well, that's not</tt>
<br><tt>> helpful to crash's needs with respect to dom0.  That's why
you</tt>
<br><tt>> guys must have created the additional NT_XEN_DOM0_CR3</tt>
<br><tt>> ELF note.</tt><tt></tt>
<p><tt>I'm note sure exactly why we created it - I thought it was because
you</tt>
<br><tt>wanted it - but I'm pretty sure Moriwaka-sans tool can locate things</tt>
<br><tt>without it.</tt>
<br><tt></tt> </blockquote>
<tt>That's exactly right -- I requested dom0's cr3 or pfn_to_mfn_list_list</tt>
<br><tt>value, and Moriwaka-san provided me with a prototype vmcore that</tt>
<br><tt>contained the NT_XEN_DOM0_CR3 ELF note.</tt><tt></tt>
<p><tt>I presume that the i386 vmcore he sent me was also usable with</tt>
<br><tt>gdb and xen-syms.  Here's what the header looks like:</tt><tt></tt>
<p><tt>$ readelf -a vmcore</tt>
<br><tt>ELF Header:</tt>
<br><tt>  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00
00 00 00</tt>
<br><tt>  Class:                            
ELF32</tt>
<br><tt>  Data:                             
2's complement, little endian</tt>
<br><tt>  Version:                          
1 (current)</tt>
<br><tt>  OS/ABI:                           
UNIX - System V</tt>
<br><tt>  ABI Version:                      
0</tt>
<br><tt>  Type:                             
CORE (Core file)</tt>
<br><tt>  Machine:                          
Intel 80386</tt>
<br><tt>  Version:                          
0x1</tt>
<br><tt>  Entry point address:              
0x0</tt>
<br><tt>  Start of program headers:         
52 (bytes into file)</tt>
<br><tt>  Start of section headers:         
0 (bytes into file)</tt>
<br><tt>  Flags:                            
0x0</tt>
<br><tt>  Size of this header:              
52 (bytes)</tt>
<br><tt>  Size of program headers:          
32 (bytes)</tt>
<br><tt>  Number of program headers:        
5</tt>
<br><tt>  Size of section headers:          
0 (bytes)</tt>
<br><tt>  Number of section headers:        
0</tt>
<br><tt>  Section header string table index: 0</tt><tt></tt>
<p><tt>There are no sections in this file.</tt><tt></tt>
<p><tt>Program Headers:</tt>
<br><tt>  Type          
Offset   VirtAddr   PhysAddr   FileSiz MemSiz 
Flg Align</tt>
<br><tt>  NOTE          
0x0000d4 0x00000000 0x00000000 0x00190 0x00190    
0</tt>
<br><tt>  LOAD          
0x000264 0xc0000000 0x00000000 0xa0000 0xa0000 RWE 0</tt>
<br><tt>  LOAD          
0x0a0264 0xc0100000 0x00100000 0x3f00000 0x3f00000 RWE 0</tt>
<br><tt>  LOAD          
0x3fa0264 0xc8000000 0x08000000 0x30000000 0x30000000 RWE 0</tt>
<br><tt>  LOAD          
0x33fa0264 0xffffffff 0x38000000 0x7ffb000 0x7ffb000 RWE 0</tt><tt></tt>
<p><tt>There is no dynamic segment in this file.</tt><tt></tt>
<p><tt>There are no relocations in this file.</tt><tt></tt>
<p><tt>There are no unwind sections in this file.</tt><tt></tt>
<p><tt>No version information found in this file.</tt><tt></tt>
<p><tt>Notes at offset 0x000000d4 with length 0x00000190:</tt>
<br><tt>  Owner         Data
size       Description</tt>
<br><tt>  CORE         
0x00000090      NT_PRSTATUS (prstatus structure)</tt>
<br><tt>  Xen Domanin-0 CR3            
0x00000004      Unknown note type: (0x10000001)</tt>
<br><tt>  CORE         
0x00000090      NT_PRSTATUS (prstatus structure)</tt>
<br><tt>  Xen Domanin-0 CR3            
0x00000004      Unknown note type: (0x10000001)</tt>
<br><tt>$</tt>
<br><tt></tt> 
<blockquote TYPE=CITE><tt></tt> 
<br><tt>> I guess I understand why you feel it's a burden to continue</tt>
<br><tt>> the maintenance of such a thing, but given that the panic can</tt>
<br><tt>> occur either while operating in the dom0 kernel or while in</tt>
<br><tt>> the xen hypervisor code, it makes perfect sense (to me) to</tt>
<br><tt>> make a minimal effort by including an indication of the dom0</tt>
<br><tt>> cr3 or dom0 pfn_to_mfn_frame_list_list value in the vmcore.</tt>
<br><tt>> Perhaps you consider it a case of the tail wagging the dog,</tt>
<br><tt>> but to me, it would be more a case of accomodating the needs</tt>
<br><tt>> of the consumer...   ;-)</tt>
<br><tt>></tt><tt></tt>
<p><tt>We should definately have something, we just need to figure out
what. =)</tt><tt></tt>
<p><tt>> ></tt>
<br><tt>> > Our internal interfaces are not particularly clean at the moment.
We</tt>
<br><tt>> > have code that keeps the crash_notes in the hypervisor, but
passes</tt>
<br><tt>> the</tt>
<br><tt>> > physical addresses (or machine addresses in xen lingo) for
the notes</tt>
<br><tt>> all</tt>
<br><tt>> > the way down to kexec-tools in dom0 user space. These addresses
are</tt>
<br><tt>> then</tt>
<br><tt>> > used to create the ELF headers. dom0 only knows about VCPU:s,
but</tt>
<br><tt>> > because we are creating a system-wide crash dump we want to
use</tt>
<br><tt>> physical</tt>
<br><tt>> > cpus. So down in user space we then need to create a mapping
between</tt>
<br><tt>> > physical cpu:s and VCPU:s. And can we be sure that dom0 has
all cpus</tt>
<br><tt>> > available as VCPU:s?</tt>
<br><tt>> ></tt>
<br><tt>></tt>
<br><tt>> I don't care about that.  All I need is a starting point
for</tt>
<br><tt>> translating dom0</tt>
<br><tt>> kernel virtual addresses.  And that is either a dom0 cr3
value or the</tt>
<br><tt>> domain's pfn_to_mfn_frame_list_list value.</tt><tt></tt>
<p><tt>I understand that. I'm sure we can figure out a good solution.</tt><tt></tt>
<p><tt>> ></tt>
<br><tt>> > > But again, there's no easy way for the crash utility to dig</tt>
<br><tt>> > > them out of a completely foreign binary's.</tt>
<br><tt>> ></tt>
<br><tt>> > No, but that's because your tool is missing knowledge about
the</tt>
<br><tt>> binary</tt>
<br><tt>> > right? =) Is there any easy way out... No! =) Or maybe there
is?</tt>
<br><tt>></tt>
<br><tt>> No!</tt>
<br><tt>></tt>
<br><tt>> ></tt>
<br><tt>> ></tt>
<br><tt>> > I hope we can find a good balance between your code and ours.
Maybe</tt>
<br><tt>> a</tt>
<br><tt>> > relatively fair balance could be that we provide per-physical
cpu</tt>
<br><tt>> > pointers to some virtual to physical mapping tables which should
be</tt>
<br><tt>> easy</tt>
<br><tt>> > to parse for your tool, but in return your tool doesn't depend
on</tt>
<br><tt>> > finding register information using the note program headers
in the</tt>
<br><tt>> ELF</tt>
<br><tt>> > header...</tt>
<br><tt>></tt>
<br><tt>> Now we're getting complex -- I'm pretty sure I don't know what</tt>
<br><tt>> you're talking about here...  Or how it can possibly lead
to a dom0</tt>
<br><tt>> cr3 or pfn_to_mfn_frame_list_list value?</tt><tt></tt>
<p><tt>Let's put it like this: Your tool, does it use xen-syms today? How</tt>
<br><tt>difficult would it be to use lookup a symbol in hypervisor space?
And</tt>
<br><tt>how do you feel about requiring xen-syms to be able to parse dom0?</tt>
<br><tt></tt> </blockquote>
<tt>Definitely not.  In the interest of simplicity, the idea is to
keep</tt>
<br><tt>things the way they have always been, i.e., "crash vmlinux vmcore",</tt>
<br><tt>and having to drag out the relevant xen-syms binary defeats that</tt>
<br><tt>concept.  And that's not to mention having to read it, figure
out</tt>
<br><tt>how to translate hypervisor virtual addresses, then navigate around</tt>
<br><tt>the vmcore to find the location of a symbol, having to deal with
the</tt>
<br><tt>following of data structures that may change over time -- to eventually</tt>
<br><tt>find what's needed...</tt>
<blockquote TYPE=CITE><tt></tt> 
<br><tt>I'm not talking about your tool walking arch-dependent cross linked
data</tt>
<br><tt>structures in the xen hypervisor, just basic symbol lookup.</tt>
<br><tt></tt> </blockquote>
<tt>But I'm not sure what good would that do?  The "domain_list" symbol</tt>
<br><tt>is only the beginning of the structure chain...</tt>
<blockquote TYPE=CITE><tt></tt> 
<br><tt>> > That's good, isn't it? If I've understood things right it's
possible</tt>
<br><tt>> to</tt>
<br><tt>> > locate the data you need using the domain list symbol?</tt>
<br><tt>></tt>
<br><tt>> Yeah...</tt>
<br><tt>></tt>
<br><tt>> To clarify,  it's possible for *you*, i.e., the kexec/kdump
code, to</tt>
<br><tt>> locate</tt>
<br><tt>> the data that way.  The crash utility, using the vmlinux/vmcore
file</tt>
<br><tt>> pair, doesn't know anything about what the "domain_list" is,
the</tt>
<br><tt>> structures that it uses/links-to.  And even if it did, it
wouldn't</tt>
<br><tt>> know</tt>
<br><tt>> how to find it in the vmcore file.</tt><tt></tt>
<p><tt>Hm...</tt><tt></tt>
<p><tt>> > Yeah, I agree that navigating around those structures seems
rather</tt>
<br><tt>> > painful. But OTOH, if you want to know things that only the</tt>
<br><tt>> internals</tt>
<br><tt>> > can tell you, you need to be able to parse them, right? But
maybe</tt>
<br><tt>> you</tt>
<br><tt>> > only want to cover the "simple" dom0 case. (Simple yeah right)</tt>
<br><tt>> ></tt>
<br><tt>></tt>
<br><tt>> That's right -- crash is *only* interested in the dom0 case;
again</tt>
<br><tt>> it's clueless about the hypervisor, and rightly so.</tt>
<br><tt>></tt>
<br><tt>> It's just such a unique case.  It's like trying to debug
"ls" using</tt>
<br><tt>> a "cat" binary, where the core file is usable for debugging either</tt>
<br><tt>> one.</tt><tt></tt>
<p><tt>I will continue working on cleaning up the code. Some of the changes</tt>
<br><tt>that have been made or are going to happen are:</tt><tt></tt>
<p><tt>- Separate dom0 notes from hypervisor notes.</tt></blockquote>
<tt>Looks like a reasonable spot to stuff cr3 (or pfn_to_mfn_frame_list_list)?</tt>
<br><tt>(i.e. stuffing the dom0 cr3 at the end of the dom0 NT_PRSTATUS</tt>
<br><tt>register dump(s), like your current patch talks about)</tt>
<blockquote TYPE=CITE><tt></tt> 
<br><tt>- Xen vmcore files should have per physical cpu hypervisor crash_notes.</tt>
<br><tt>- These hypervisor notes should be pointed out by the program header.</tt>
<br><tt>- Xen vmcore files should have the hypervisor in a PT_LOAD segment.</tt>
<br><tt>- Xen vmcore files should have PT_LOAD headers for RAM, but with
VA = 0.</tt></blockquote>
<tt>With respect to the PT_LOAD segments, the crash utility pretty much</tt>
<br><tt>ignores the p_vaddr values -- it's particularly interested in the</tt>
<br><tt>p_paddr values.  And once able to translate a unity-mapped
kernel</tt>
<br><tt>virtual address into a physical address, it can find that physical</tt>
<br><tt>address by checking the p_paddr/p_filesz values in each PT_LOAD</tt>
<br><tt>segment.  (Again -- that only works with xen kernels if the
pseudo</tt>
<br><tt>physical address can be translated into a machine address, and
then</tt>
<br><tt>a vmcore file location -- hence the pre-requisite requirement for</tt>
<br><tt>either the dom0 cr3 or pfn_to_mfn_list_list value.)</tt><tt></tt>
<p><tt>The one exception to "ignore-the-p_vaddr" rule is for the new</tt>
<br><tt>relocatable x86_64 kernels, where the PT_LOAD mapping for
the</tt>
<br><tt>kernel's __START_KERNEL_map region needs to be looked at in</tt>
<br><tt>order to figure out where the kernel was physically loaded,</tt>
<br><tt>because in relocatable kernels, unity-mapping can no longer be</tt>
<br><tt>done by simply stripping off the PAGE_OFFSET value.  Relocatable</tt>
<br><tt>kernels are being introduced so that there is no need for separate</tt>
<br><tt>"first-kernel" and the secondary kexec'd "kdump-kernel".</tt><tt></tt>
<p><tt>But AFAIK, the new kernel relocation scheme shouldn't infect xen</tt>
<br><tt>x86_64 kernels, so I don't believe that would ever be an issue.</tt>
<br><tt>In other words, xen kernels should remain unity-mapped in the</tt>
<br><tt>traditional manner, albeit with pseudo-physical addresses instead</tt>
<br><tt>of machine addresses.  Again, I *believe* that to be true,
since</tt>
<br><tt>there's no reason to relocate them.</tt>
<blockquote TYPE=CITE><tt></tt> 
<br><tt>- Xen vmcore files should provide crash with something like CR3.</tt></blockquote>
<tt>Or this would be good...   ;-)</tt>
<blockquote TYPE=CITE><tt></tt> 
<br><tt>- kexec-tools will be made xen aware.</tt><tt></tt>
<p><tt>I'm sorry if we've been going over and over about this, but I'm
a bit</tt>
<br><tt>confused by the current status, what we want to have and if that
is</tt>
<br><tt>going to work. The points above show the direction. Please shout
if you</tt>
<br><tt>think they sound bad.</tt></blockquote>
<tt>Nothing sounds bad to me!  What would be really helpful is if,</tt>
<br><tt>during your development, you could provide me with sample</tt>
<br><tt>vmlinux/vmcore pairs that I could work with?  Just so I don't</tt>
<br><tt>have to scramble at the end of it all, and only then find out</tt>
<br><tt>that there's a "gotcha" that we're not considering.</tt><tt></tt>
<p><tt>Thanks,</tt>
<br><tt>  Dave</tt>
<br><tt></tt> </html>