linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 6/9] Ksplice: Add functions for walking kallsyms symbols
@ 2009-02-07 12:45 Rusty Russell
  2009-02-11 20:19 ` Jon Masters
  0 siblings, 1 reply; 5+ messages in thread
From: Rusty Russell @ 2009-02-07 12:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Jeff Arnold, Tim Abbott, Anders Kaseorg

From: Anders Kaseorg <andersk@mit.edu>

Impact: New API

kallsyms_lookup_name only returns the first match that it finds.  Ksplice
needs information about all symbols with a given name in order to correctly
resolve local symbols.

kallsyms_on_each_symbol provides a generic mechanism for iterating over the
kallsyms table.

Cc: Jeff Arnold <jbarnold@mit.edu>
Cc: Tim Abbott <tabbott@mit.edu>
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 include/linux/kallsyms.h |   13 +++++++++++++
 include/linux/module.h   |   12 ++++++++++++
 kernel/kallsyms.c        |   19 +++++++++++++++++++
 kernel/module.c          |   19 +++++++++++++++++++
 4 files changed, 63 insertions(+)

diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index f3fe343..37746b2 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -17,6 +17,11 @@
 /* Lookup the address for a symbol. Returns 0 if not found. */
 unsigned long kallsyms_lookup_name(const char *name);
 
+/* Call a function on each kallsyms symbol in the core kernel */
+int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
+				      unsigned long),
+			    void *data);
+
 extern int kallsyms_lookup_size_offset(unsigned long addr,
 				  unsigned long *symbolsize,
 				  unsigned long *offset);
@@ -43,6 +48,14 @@ static inline unsigned long kallsyms_lookup_name(const char *name)
 	return 0;
 }
 
+static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *,
+						    struct module *,
+						    unsigned long),
+					  void *data)
+{
+	return 0;
+}
+
 static inline int kallsyms_lookup_size_offset(unsigned long addr,
 					      unsigned long *symbolsize,
 					      unsigned long *offset)
diff --git a/include/linux/module.h b/include/linux/module.h
index 2268147..29972a2 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -378,6 +378,10 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
 /* Look for this name: can be of form module:name. */
 unsigned long module_kallsyms_lookup_name(const char *name);
 
+int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
+					     struct module *, unsigned long),
+				   void *data);
+
 extern void __module_put_and_exit(struct module *mod, long code)
 	__attribute__((noreturn));
 #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
@@ -546,6 +550,14 @@ static inline unsigned long module_kallsyms_lookup_name(const char *name)
 	return 0;
 }
 
+static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
+							   struct module *,
+							   unsigned long),
+						 void *data)
+{
+	return 0;
+}
+
 static inline int register_module_notifier(struct notifier_block * nb)
 {
 	/* no events will happen anyway, so this can always succeed */
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 7b8b0f2..374faf9 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -161,6 +161,25 @@ unsigned long kallsyms_lookup_name(const char *name)
 	return module_kallsyms_lookup_name(name);
 }
 
+int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
+				      unsigned long),
+			    void *data)
+{
+	char namebuf[KSYM_NAME_LEN];
+	unsigned long i;
+	unsigned int off;
+	int ret;
+
+	for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
+		off = kallsyms_expand_symbol(off, namebuf);
+		ret = fn(data, namebuf, NULL, kallsyms_addresses[i]);
+		if (ret != 0)
+			return ret;
+	}
+	return module_kallsyms_on_each_symbol(fn, data);
+}
+EXPORT_SYMBOL_GPL(kallsyms_on_each_symbol);
+
 static unsigned long get_symbol_pos(unsigned long addr,
 				    unsigned long *symbolsize,
 				    unsigned long *offset)
diff --git a/kernel/module.c b/kernel/module.c
index c3cf234..8839d40 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2554,6 +2554,25 @@ unsigned long module_kallsyms_lookup_name(const char *name)
 	preempt_enable();
 	return ret;
 }
+
+int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
+					     struct module *, unsigned long),
+				   void *data)
+{
+	struct module *mod;
+	unsigned int i;
+	int ret;
+
+	list_for_each_entry(mod, &modules, list) {
+		for (i = 0; i < mod->num_symtab; i++) {
+			ret = fn(data, mod->strtab + mod->symtab[i].st_name,
+				 mod, mod->symtab[i].st_value);
+			if (ret != 0)
+				return ret;
+		}
+	}
+	return 0;
+}
 #endif /* CONFIG_KALLSYMS */
 
 static char *module_flags(struct module *mod, char *buf)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 6/9] Ksplice: Add functions for walking kallsyms symbols
  2009-02-07 12:45 [PATCH 6/9] Ksplice: Add functions for walking kallsyms symbols Rusty Russell
@ 2009-02-11 20:19 ` Jon Masters
  2009-02-12  6:09   ` Tim Abbott
  0 siblings, 1 reply; 5+ messages in thread
From: Jon Masters @ 2009-02-11 20:19 UTC (permalink / raw)
  To: Rusty Russell; +Cc: linux-kernel, Jeff Arnold, Tim Abbott, Anders Kaseorg

Folks,

Please forgive me not tracking ksplice closely enough - I didn't think
it required these changes - is there some refactoring going on currently
or am I mistaken and these patches are now a necessary pre-req.?

Jon.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 6/9] Ksplice: Add functions for walking kallsyms symbols
  2009-02-11 20:19 ` Jon Masters
@ 2009-02-12  6:09   ` Tim Abbott
  2009-02-12  6:37     ` Jon Masters
  0 siblings, 1 reply; 5+ messages in thread
From: Tim Abbott @ 2009-02-12  6:09 UTC (permalink / raw)
  To: Jon Masters; +Cc: Rusty Russell, linux-kernel, Jeff Arnold, Anders Kaseorg

On Wed, 11 Feb 2009, Jon Masters wrote:

> Folks,
> 
> Please forgive me not tracking ksplice closely enough - I didn't think
> it required these changes - is there some refactoring going on currently
> or am I mistaken and these patches are now a necessary pre-req.?

Hi Jon,

There are two different versions of the Ksplice kernel module, a 
"standalone" version that works with an unmodified kernel, and the version 
that we've proposed for mainline merge.

One difference between the two versions is that the standalone version has 
implementations of functions such as kallsyms_on_each_symbol in the 
Ksplice core module (i.e. the module containing ksplice.c).

Normally, one would not be able to implement kallsyms_on_each_symbol in a 
module, because it would not have access to necessary symbols such as 
kallsyms_num_syms (an unexported global symbol).  The standalone version 
of Ksplice resolves these symbols through a bootstrapping process.

This bootstrapping technique doesn't make any sense for a Ksplice in 
mainline; these prerequisite patches put functions such as 
kallsyms_on_each_symbol where they belong.

	-Tim Abbott



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 6/9] Ksplice: Add functions for walking kallsyms symbols
  2009-02-12  6:09   ` Tim Abbott
@ 2009-02-12  6:37     ` Jon Masters
  2009-02-13  4:27       ` Tim Abbott
  0 siblings, 1 reply; 5+ messages in thread
From: Jon Masters @ 2009-02-12  6:37 UTC (permalink / raw)
  To: Tim Abbott; +Cc: Rusty Russell, linux-kernel, Jeff Arnold, Anders Kaseorg

On Thu, 2009-02-12 at 01:09 -0500, Tim Abbott wrote:

> There are two different versions of the Ksplice kernel module, a 
> "standalone" version that works with an unmodified kernel, and the version 
> that we've proposed for mainline merge.

Ah thanks, I didn't realize you were proposing for mainline merge -
awesome. That would really be a useful merge...how close do you think
that is?

Jon.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 6/9] Ksplice: Add functions for walking kallsyms symbols
  2009-02-12  6:37     ` Jon Masters
@ 2009-02-13  4:27       ` Tim Abbott
  0 siblings, 0 replies; 5+ messages in thread
From: Tim Abbott @ 2009-02-13  4:27 UTC (permalink / raw)
  To: Jon Masters; +Cc: Rusty Russell, linux-kernel, Jeff Arnold, Anders Kaseorg

On Thu, 12 Feb 2009, Jon Masters wrote:

> Ah thanks, I didn't realize you were proposing for mainline merge -
> awesome. That would really be a useful merge...how close do you think
> that is?

I don't know when it will be merged, but I can comment on the status of 
our patches.

Ksplice has essentially two prerequisite changes:

- Changes to the module subsystem.  Rusty Russell included versions of 
those patches in a recent patch series for the module system targeted at 
2.6.30.

- Support for building the Linux kernel with -ffunction-sections 
-fdata-sections.  Linus was asked about a week ago whether he would take 
the patch, but he has not responded yet.

As for the Ksplice core, Rusty Russell has started reading the code and 
has requested some changes to it to assist further review.  We hope to 
send a new patch series with those changes made next week.

	-Tim Abbott

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-02-13  4:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-07 12:45 [PATCH 6/9] Ksplice: Add functions for walking kallsyms symbols Rusty Russell
2009-02-11 20:19 ` Jon Masters
2009-02-12  6:09   ` Tim Abbott
2009-02-12  6:37     ` Jon Masters
2009-02-13  4:27       ` Tim Abbott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).