Thanks Dave. The kretprobe worked for me.<div><div><br></div><div>Dheeraj<br><br><div class="gmail_quote">On Thu, Dec 4, 2008 at 8:14 PM, Dave Anderson <span dir="ltr"><<a href="mailto:anderson@redhat.com">anderson@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="Wj3C7c"><br>
----- "Dheeraj Sangamkar" <<a href="mailto:dheerajrs@gmail.com">dheerajrs@gmail.com</a>> wrote:<br>
<br>
> On the same machine, I am unable to live-debug the running kernel.<br>
> Here is the error I get. Please let me know if there is something I<br>
> can do to get crash working.<br>
><br>
> /dheeraj/crash/crash-4.0-7.4 # crash -d 255<br>
> /boot/System.map-2.6.27.4-2-default<br>
> /root/dheeraj/linux-2.6.27.4-2.1/vmlinux<br>
><br>
> crash 4.0-7.4<br>
> Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Red Hat, Inc.<br>
> Copyright (C) 2004, 2005, 2006 IBM Corporation<br>
> Copyright (C) 1999-2006 Hewlett-Packard Co<br>
> Copyright (C) 2005, 2006 Fujitsu Limited<br>
> Copyright (C) 2006, 2007 VA Linux Systems Japan K.K.<br>
> Copyright (C) 2005 NEC Corporation<br>
> Copyright (C) 1999, 2002, 2007 Silicon Graphics, Inc.<br>
> Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc.<br>
> This program is free software, covered by the GNU General Public<br>
> License,<br>
> and you are welcome to change it and/or distribute copies of it under<br>
> certain conditions. Enter "help copying" to see the conditions.<br>
> This program has absolutely no warranty. Enter "help warranty" for<br>
> details.<br>
><br>
> crash: diskdump / compressed kdump: dump does not have panic dump<br>
> header<br>
> get_live_memory_source: /dev/mem<br>
> crash: pv_init_ops exists: ARCH_PVOPS<br>
> _text: ffffffff80200000 Kernel code: 200000 -> phys_base: 0<br>
><br>
> gdb /root/dheeraj/linux-2.6.27.4-2.1/vmlinux<br>
> GNU gdb 6.1<br>
> Copyright 2004 Free Software Foundation, Inc.<br>
> GDB is free software, covered by the GNU General Public License, and<br>
> you are<br>
> welcome to change it and/or distribute copies of it under certain<br>
> conditions.<br>
> Type "show copying" to see the conditions.<br>
> There is absolutely no warranty for GDB. Type "show warranty" for<br>
> details.<br>
> This GDB was configured as "x86_64-unknown-linux-gnu"...<br>
> GETBUF(248 -> 0)<br>
> GETBUF(1500 -> 1)<br>
><br>
> FREEBUF(1)<br>
> FREEBUF(0)<br>
> <readmem: ffffffff804be660, KVADDR, "kernel_config_data", 32768,<br>
> (ROE), 1ae5040><br>
> /dev/mem: Operation not permitted<br>
> crash: read(/dev/mem, 4be660, 2464): 4294967295 (ffffffff)<br>
> crash: read error: kernel virtual address: ffffffff804be660 type:<br>
> "kernel_config_data"<br>
> WARNING: cannot read kernel_config_data<br>
> GETBUF(248 -> 0)<br>
> FREEBUF(0)<br>
> GETBUF(16 -> 0)<br>
> <readmem: ffffffff80a14800, KVADDR, "cpu_possible_map", 16, (ROE),<br>
> a49160><br>
> /dev/mem: Operation not permitted<br>
> crash: read(/dev/mem, a14800, 16): 4294967295 (ffffffff)<br>
> crash: read error: kernel virtual address: ffffffff80a14800 type:<br>
> "cpu_possible_map"<br>
> WARNING: cannot read cpu_possible_map<br>
> <readmem: ffffffff80872710, KVADDR, "cpu_present_map", 16, (ROE),<br>
> a49160><br>
> /dev/mem: Operation not permitted<br>
> crash: read(/dev/mem, 872710, 16): 4294967295 (ffffffff)<br>
> crash: read error: kernel virtual address: ffffffff80872710 type:<br>
> "cpu_present_map"<br>
> WARNING: cannot read cpu_present_map<br>
> <readmem: ffffffff80846c90, KVADDR, "cpu_online_map", 16, (ROE),<br>
> a49160><br>
> /dev/mem: Operation not permitted<br>
> crash: read(/dev/mem, 846c90, 16): 4294967295 (ffffffff)<br>
> crash: read error: kernel virtual address: ffffffff80846c90 type:<br>
> "cpu_online_map"<br>
> WARNING: cannot read cpu_online_map<br>
> FREEBUF(0)<br>
> <readmem: ffffffff80a74400, KVADDR, "xtime", 16, (FOE), a0d2f0><br>
> /dev/mem: Operation not permitted<br>
> crash: read(/dev/mem, a74400, 16): 4294967295 (ffffffff)<br>
> crash: read error: kernel virtual address: ffffffff80a74400 type:<br>
> "xtime"<br>
<br>
</div></div>Live system analysis is impossible if /dev/mem won't allow you<br>
to read physical memory.  Each read attempt above results in an<br>
"Operation not permitted" (EPERM) error.<br>
<br>
They fail because of a pain-in-the-ass CONFIG_STRICT_DEVMEM configuration<br>
option that was recently added to upstream kernels.  When the crash<br>
utility makes a read() from /dev/mem, it ends up in the kernel's<br>
drivers/char/mem.c driver, and proceeds like so:<br>
<br>
  read_mem()<br>
    range_is_allowed()<br>
      devmem_is_allowed()<br>
<br>
Here is the call in read_mem() that returns the EPERM:<br>
<br>
                if (!range_is_allowed(p >> PAGE_SHIFT, count))<br>
                        return -EPERM;<br>
<br>
Here are the two versions of range_is_allowed() in drivers/char/mem.c,<br>
which depend upon CONFIG_STRICT_DEVMEM:<br>
<br>
  #ifdef CONFIG_STRICT_DEVMEM<br>
  static inline int range_is_allowed(unsigned long pfn, unsigned long size)<br>
  {<br>
          u64 from = ((u64)pfn) << PAGE_SHIFT;<br>
          u64 to = from + size;<br>
          u64 cursor = from;<br>
<br>
          while (cursor < to) {<br>
                  if (!devmem_is_allowed(pfn)) {<br>
                          printk(KERN_INFO<br>
                  "Program %s tried to access /dev/mem between %Lx->%Lx.\n",<br>
                                  current->comm, from, to);<br>
                          return 0;<br>
                  }<br>
                  cursor += PAGE_SIZE;<br>
                  pfn++;<br>
          }<br>
          return 1;<br>
  }<br>
  #else<br>
  static inline int range_is_allowed(unsigned long pfn, unsigned long size)<br>
  {<br>
          return 1;<br>
  }<br>
  #endif<br>
<br>
And the call to devmem_is_allowed() above ends up here, where only the<br>
first 256 pages (1MB) of physical memory is accessible:<br>
<br>
  int devmem_is_allowed(unsigned long pagenr)<br>
  {<br>
          if (pagenr <= 256)<br>
                  return 1;<br>
          if (!page_is_ram(pagenr))<br>
                  return 1;<br>
          return 0;<br>
  }<br>
<br>
So that makes /dev/mem useless for the crash utility...<br>
<br>
Bernhard Walle made a valiant attempt to make this a run-time configurable<br>
rather than a compile-time config option,<br>
<br>
  <a href="http://lkml.org/lkml/2008/11/16/117" target="_blank">http://lkml.org/lkml/2008/11/16/117</a><br>
<br>
But the LKML thread went off into the weeds arguing whether the CONFIG_STRICT_DEVMEM<br>
imposition itself should be ripped out, rather than putting lipstick on a pig.<br>
And so it got nowhere...<br>
<br>
This same 256-page restriction has been in place in RHEL4 and RHEL5 kernels<br>
as well, because the same guy who managed to push it upstream formerly worked<br>
at Red Hat, and convinced the powers-that-be here that /dev/mem was a security<br>
hole.  As a result, I had to write a whole new physical memory-access device<br>
driver (/dev/crash) that is a read-only "misc" driver that the crash utility<br>
automatically loads when run on a live system.  But it's only available in<br>
the Red Hat RHEL4 and RHEL5 distribution, although it can be ported easily<br>
enough.<br>
<br>
So you've got 3 options:<br>
<br>
 1. Rebuild your kernel with CONFIG_STRICT_DEVMEM turned off.<br>
<br>
 2. Port the RHEL /dev/crash driver to your kernel.  I did suggest that<br>
    in another crash-utility thread here:<br>
<br>
      <a href="https://www.redhat.com/archives/crash-utility/2008-October/msg00057.html" target="_blank">https://www.redhat.com/archives/crash-utility/2008-October/msg00057.html</a><br>
<br>
 3. Write a kprobe module that forces devmem_is_allowed() to return 1 always:<br>
<br>
      <a href="http://www.redhat.com/archives/crash-utility/2008-March/msg00036.html" target="_blank">http://www.redhat.com/archives/crash-utility/2008-March/msg00036.html</a><br>
<br>
If you've got the power, obviously #1 is the best option.  But if you cannot<br>
change kernels, probably the kprobe option #3 is easier than porting the RHEL<br>
/dev/crash driver.  Check Documentation/kprobes.txt file and the samples/kprobes<br>
directory in your kernel build tree, and then use the RHEL kprobe example<br>
I put in the thread referenced in #3 above.  If that won't work (and I don't<br>
know why it wouldn't), then you can always port the RHEL /dev/crash driver<br>
that's attached to the thread reference in #2 above.<br>
<div><div></div><div class="Wj3C7c"><br>
Dave<br>
<br>
--<br>
Crash-utility mailing list<br>
<a href="mailto:Crash-utility@redhat.com">Crash-utility@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/crash-utility" target="_blank">https://www.redhat.com/mailman/listinfo/crash-utility</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Simplicity of character is the natural result of profound thought.<br>
</div></div>