Skip to contentSkip to conversation

favourite vfs globals

DISCUSSION Pat LaVarre 1 participant 5 messages Nov 28, 2003

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Which vfs globals are the most fun, in lk like 2.6.0-test11?

Pat LaVarre

P.S. I ask because:

Quoted 8 lines
From: http://marc.theaimsgroup.com/?l=linux-fsdevel&m=107004461717172
Subject:  Re: zeroes read back more often than appended
Date:     2003-11-28 18:29:39

CONFIG_DEBUG_KERNEL=y
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_SLAB=y
CONFIG_MAGIC_SYSRQ=y

gdb vmlinux /proc/kcore

indeed does let me print globals that make some kind of sense. Specifically on my own in stunning ignorance, I notice Six things:

1) ? suggests help.

2) help suggests info variables.

3) info variables takes minutes to complete, but writes its list out thru tee if first you thought to tee your sudo'ed gdb.

4) info variables vfs completes much more quickly.

5) print xtime returns the same result til you quit and re-enter gdb, also that result appears in between what date +'%s %N' prints before and after, suggesting that this approach to gdb takes a blurry snapshot of kernel memory and then walks us thru a stale copy of all the bits.

6) Substituting /dev/kmem for /proc/kcore prints zero for xtime, suggesting sym table addresses somehow not sync'ed with physical memory in that abuse.

#1 lore raw
Quoted 1 line

Which vfs globals are the most fun, in lk like 2.6.0-test11?

That question I can't yet answer, but:

Quoted 3 lines

gdb vmlinux /proc/kcore
... this approach to gdb takes a blurry snapshot of kernel memory and then walks us thru a stale copy of all the bits.

Also I suppose we can't see the global variables of modules this way, except when the modules share those variables with non-module code i.e. code linked into the kernel before boot. I'm guessing wildly from experiences like the following.

(gdb) info variables scsi_comm
All variables matching regular expression "scsi_comm":

File drivers/block/scsi_ioctl.c:
const unsigned char scsi_command_size[8];
static const char __kstrtab_scsi_command_size[18];
static const struct kernel_symbol __ksymtab_scsi_command_size; (gdb) #
(gdb) print /x scsi_command_size
$2 = {0x6, 0xa, 0xa, 0xc, 0x10, 0xc, 0xa, 0xa}
(gdb) #
(gdb) file /lib/modules/2.6.0-11.udf/kernel/drivers/scsi/scsi_mod.ko
warning: core file may not match specified executable file. Load new symbol table from "/lib/modules/2.6.0-11.udf/kernel/drivers/scsi/scsi_mod.ko"? (y or n) y

Reading symbols from /lib/modules/2.6.0-11.udf/kernel/drivers/scsi/scsi_mod.ko...done. (gdb) #
(gdb) info variables xtime
...
(gdb) print xtime
Address of symbol "xtime" is unknown.
(gdb) #
(gdb) info variables scsi_command_size
...
(gdb) print scsi_command_size
Address of symbol "scsi_command_size" is unknown.
(gdb) #

#2 lore raw
Quoted 1 line
Quoted 1 line

Which vfs globals are the most fun, in lk like 2.6.0-test11?

"That question I can't yet answer, but":

Quoted 7 lines
Quoted 3 lines

gdb vmlinux /proc/kcore
... this approach to gdb takes a blurry snapshot of kernel memory and then walks us thru a stale copy of all the bits.

... we ... see the global variables of modules this way, ... when the modules share those variables with non-module code i.e. code linked into the kernel before boot.

I see directly adding a global to a module does not work:

MODPOST
*** Warning: "hello_gdb" [fs/udf/udf.ko] undefined!

Ouch.

I'll go ask the kernelnewbies list to comment.

Pat LaVarre

drivers/block/ll_rw_blk.c +3 -0
diff -Nur linux-2.6.0-test11/drivers/block/ll_rw_blk.c linux/drivers/block/ll_rw_blk.c
@@ -2445,6 +2445,9 @@
 	}
 }
 
+extern int hello_gdb;
+int hello_gdb = 'P';
+
 static int __end_that_request_first(struct request *req, int uptodate,
 				    int nr_bytes)
 {
fs/udf/super.c +5 -0
diff -Nur linux-2.6.0-test11/fs/udf/super.c linux/fs/udf/super.c
@@ -189,10 +189,15 @@
 	struct nls_table *nls_map;
 };
 
+extern int hello_gdb;
+
 static int __init init_udf_fs(void)
 {
 	int err;
 	printk(KERN_NOTICE "udf: registering filesystem\n");
+	printk(KERN_NOTICE "udf: before incrementing hello_gdb\n");
+	++hello_gdb;
+	printk(KERN_NOTICE "udf: after incrementing hello_gdb\n");
 	err = init_inodecache();
 	if (err)
 		goto out1;
#3 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line

Which vfs globals are the most fun, in lk like 2.6.0-test11?

"That question I can't yet answer, but":

Quoted 11 lines
Quoted 2 lines
Quoted 1 line

... we ... see the global variables of modules ...

... when the modules share those variables with non-module code

...
I see directly adding a global to a module does not work:

MODPOST
*** Warning: "hello_gdb" [fs/udf/udf.ko] undefined!

Ouch.

I'll go ask the kernelnewbies list to comment.

Ouch, I speak and only then do I remember finally now where I saw this working before. Not in drivers/usb/storage but rather in scsi/ e.g.

http://lxr.linux.no/ident?v=2.6.0-test7;i=scsi_command_size

yields:

http://lxr.linux.no/source/drivers/block/scsi_ioctl.c?v=2.6.0-test7#L530

i.e. the use of such std. C extensions as:

EXPORT_SYMBOL(scsi_command_size);

Pat LaVarre

#4 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Which vfs globals are the most fun, in lk like 2.6.0-test11?

"That question I can't yet answer, but":

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line

... we ... see the global variables of modules ...

... when the modules share those variables with non-module code

Success! Thanks again for the hints.

(gdb) print /x udf_gdb
$1 = 0xcafefacf
(gdb) #
(gdb) print udf_gdb_fstype
$3 = (struct file_system_type *) 0xdf9639c0
(gdb) #
(gdb) print *udf_gdb_fstype
$4 = {name = 0xdf95fc65 "udf", fs_flags = 1, get_sb = 0xdf9592d4,
kill_sb = 0xc0153d9c <kill_block_super>, owner = 0xdf963e80, next = 0x0, fs_supers = {next = 0xd5fa7d5c, prev = 0xd5fa7d5c}}
(gdb)

fs/udf/super.c +9 -0
diff -Nur linux-2.6.0-test11/fs/udf/super.c linux/fs/udf/super.c
@@ -189,10 +189,19 @@
 	struct nls_table *nls_map;
 };
 
+extern int udf_gdb;
+extern struct file_system_type * udf_gdb_fstype;
+
 static int __init init_udf_fs(void)
 {
 	int err;
 	printk(KERN_NOTICE "udf: registering filesystem\n");
+
+	printk(KERN_NOTICE "udf: before incrementing hello_gdb\n");
+	udf_gdb_fstype = &udf_fstype;
+	++udf_gdb;
+	printk(KERN_NOTICE "udf: after incrementing hello_gdb\n");
+
 	err = init_inodecache();
 	if (err)
 		goto out1;

diff -Nur linux-2.6.0-test11/drivers/block/scsi_ioctl.c linux/drivers/block/scsi_ioctl.c

drivers/block/ll_rw_blk.c +5 -0
diff -Nur linux-2.6.0-test11/drivers/block/ll_rw_blk.c linux/drivers/block/ll_rw_blk.c
@@ -2445,6 +2445,11 @@
 	}
 }
 
+int udf_gdb = 0xCAFEFACE;
+struct file_system_type * udf_gdb_fstype;
+EXPORT_SYMBOL(udf_gdb);
+EXPORT_SYMBOL(udf_gdb_fstype);
+
 static int __end_that_request_first(struct request *req, int uptodate,
 				    int nr_bytes)
 {