Thanks a million Dave,<br>I will try using the kprobes approach.<br><br>Dheeraj<br><br><div class="gmail_quote">On Fri, Mar 7, 2008 at 1:33 AM, Dave Anderson <<a href="mailto:anderson@redhat.com">anderson@redhat.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
As it turns out, another way to work around the /dev/mem restriction<br>
is with kprobes.<br>
<br>
The devmem_is_allowed() function looks like this, and for<br>
the purposes of using it by the crash utility, we'd like it<br>
to return 1 always:<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>
I took the sample kretprobes.c file from Documentation/kprobes.txt<br>
and set a kretprobe in devmem_is_allowed() that forces a return<br>
value of 1:<br>
<br>
   static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs)<br>
   {<br>
           regs->eax = 1;<br>
           return 0;<br>
   }<br>
<br>
<br>
Here's the "kretprobes.c" module I used:<br>
<br>
   #include <linux/kernel.h><br>
   #include <linux/module.h><br>
   #include <linux/kprobes.h><br>
<br>
   static const char *probed_func = "devmem_is_allowed";<br>
<br>
   /* Return-probe handler: force return value to be 1. */<br>
   static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs)<br>
   {<br>
        regs->eax = 1;<br>
        return 0;<br>
   }<br>
<br>
   static struct kretprobe my_kretprobe = {<br>
        .handler = ret_handler,<br>
        /* Probe up to 20 instances concurrently. */<br>
        .maxactive = 20<br>
   };<br>
<br>
   static int __init kretprobe_init(void)<br>
   {<br>
        int ret;<br>
        my_kretprobe.kp.symbol_name = (char *)probed_func;<br>
<br>
        if ((ret = register_kretprobe(&my_kretprobe)) < 0) {<br>
                printk("register_kretprobe failed, returned %d\n", ret);<br>
                return -1;<br>
        }<br>
        printk("Planted return probe at %p\n", my_kretprobe.kp.addr);<br>
<br>
        return 0;<br>
   }<br>
<br>
   static void __exit kretprobe_exit(void)<br>
   {<br>
        unregister_kretprobe(&my_kretprobe);<br>
        printk("kretprobe unregistered\n");<br>
        /* nmissed > 0 suggests that maxactive was set too low. */<br>
        printk("Missed probing %d instances of %s\n",<br>
                my_kretprobe.nmissed, probed_func);<br>
   }<br>
<br>
   module_init(kretprobe_init)<br>
   module_exit(kretprobe_exit)<br>
   MODULE_LICENSE("GPL");<br>
<br>
And then build it with the supplied Makefile snippet:<br>
<br>
obj-m := kretprobes.o<br>
KDIR := /lib/modules/$(shell uname -r)/build<br>
PWD := $(shell pwd)<br>
default:<br>
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules<br>
clean:<br>
        rm -f *.mod.c *.ko *.o<br>
<br>
Load the module, and then while it's running, "crash /dev/mem" will<br>
override its  default usage of "/dev/crash" and just work.<br>
<br>
This was on a RHEL5 kernel, but it should work for RHEL4 as well:<br>
<br>
   $ crash /dev/mem<br>
<br>
   crash 4.0-6.1<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 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 details.<br>
<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 you are<br>
   welcome to change it and/or distribute copies of it under certain conditions.<br>
   Type "show copying" to see the conditions.<br>
   There is absolutely no warranty for GDB.  Type "show warranty" for details.<br>
   This GDB was configured as "i686-pc-linux-gnu"...<br>
<br>
         KERNEL: /usr/lib/debug/lib/modules/2.6.18-53.el5/vmlinux<br>
       DUMPFILE: /dev/mem<br>
           CPUS: 2<br>
           DATE: Thu Mar  6 14:43:06 2008<br>
         UPTIME: 23 days, 04:50:13<br>
   LOAD AVERAGE: 0.14, 0.20, 0.20<br>
          TASKS: 175<br>
       NODENAME: <a href="http://crash.boston.redhat.com" target="_blank">crash.boston.redhat.com</a><br>
        RELEASE: 2.6.18-53.el5<br>
        VERSION: #1 SMP Wed Oct 10 16:34:02 EDT 2007<br>
        MACHINE: i686  (1993 Mhz)<br>
         MEMORY: 511.5 MB<br>
            PID: 15518<br>
        COMMAND: "crash"<br>
           TASK: cb0ffaa0  [THREAD_INFO: d976c000]<br>
            CPU: 0<br>
          STATE: TASK_RUNNING (ACTIVE)<br>
<br>
   crash> p panic_on_oops<br>
   panic_on_oops = $2 = 1<br>
   crash> wr panic_on_oops 2<br>
   crash> p panic_on_oops<br>
   panic_on_oops = $3 = 2<br>
   crash><br>
<br>
Dave<br>
<font color="#888888"><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>
</font></blockquote></div><br>