mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Arnold <jbarnold@MIT.EDU>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org,
	Denys Vlasenko <vda.linux@googlemail.com>,
	Tim Abbott <tabbott@MIT.EDU>, Anders Kaseorg <andersk@MIT.EDU>,
	Waseem Daher <wdaher@MIT.EDU>,
	Nikanth Karthikesan <knikanth@suse.de>
Subject: [PATCH 3/7] Ksplice: Make find_symbol return a struct kernel_symbol
Date: Fri,  5 Dec 2008 19:03:56 -0500	[thread overview]
Message-ID: <1228521840-3886-4-git-send-email-jbarnold@mit.edu> (raw)
In-Reply-To: <1228521840-3886-3-git-send-email-jbarnold@mit.edu>

From: Tim Abbott <tabbott@mit.edu>

Ksplice needs access to the kernel_symbol structure in order to support
modifications to the exported symbol table.

Signed-off-by: Tim Abbott <tabbott@mit.edu>
---
 kernel/module.c |   80 ++++++++++++++++++++++++++----------------------------
 1 files changed, 39 insertions(+), 41 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index 5275d86..0d361f0 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -282,7 +282,7 @@ struct find_symbol_arg {
 	/* Output */
 	struct module *owner;
 	const unsigned long *crc;
-	unsigned long value;
+	const struct kernel_symbol *sym;
 };
 
 static bool find_symbol_in_section(const struct symsearch *syms,
@@ -323,17 +323,17 @@ static bool find_symbol_in_section(const struct symsearch *syms,
 
 	fsa->owner = owner;
 	fsa->crc = symversion(syms->crcs, symnum);
-	fsa->value = syms->start[symnum].value;
+	fsa->sym = &syms->start[symnum];
 	return true;
 }
 
-/* Find a symbol, return value, (optional) crc and (optional) module
- * which owns it */
-static unsigned long find_symbol(const char *name,
-				 struct module **owner,
-				 const unsigned long **crc,
-				 bool gplok,
-				 bool warn)
+/* Find a symbol and return it, along with, (optional) crc and
+ * (optional) module which owns it */
+static const struct kernel_symbol *find_symbol(const char *name,
+					       struct module **owner,
+					       const unsigned long **crc,
+					       bool gplok,
+					       bool warn)
 {
 	struct find_symbol_arg fsa;
 
@@ -346,11 +346,11 @@ static unsigned long find_symbol(const char *name,
 			*owner = fsa.owner;
 		if (crc)
 			*crc = fsa.crc;
-		return fsa.value;
+		return fsa.sym;
 	}
 
 	DEBUGP("Failed to find symbol %s\n", name);
-	return -ENOENT;
+	return NULL;
 }
 
 /* Search for module by name: must hold module_mutex. */
@@ -848,7 +848,7 @@ void __symbol_put(const char *symbol)
 	struct module *owner;
 
 	preempt_disable();
-	if (IS_ERR_VALUE(find_symbol(symbol, &owner, NULL, true, false)))
+	if (find_symbol(symbol, &owner, NULL, true, false) == NULL)
 		BUG();
 	module_put(owner);
 	preempt_enable();
@@ -1011,7 +1011,7 @@ static inline int check_modstruct_version(Elf_Shdr *sechdrs,
 {
 	const unsigned long *crc;
 
-	if (IS_ERR_VALUE(find_symbol("struct_module", NULL, &crc, true, false)))
+	if (find_symbol("struct_module", NULL, &crc, true, false) == NULL)
 		BUG();
 	return check_version(sechdrs, versindex, "struct_module", mod, crc);
 }
@@ -1052,25 +1052,23 @@ static inline int same_magic(const char *amagic, const char *bmagic,
 
 /* Resolve a symbol for this module.  I.e. if we find one, record usage.
    Must be holding module_mutex. */
-static unsigned long resolve_symbol(Elf_Shdr *sechdrs,
-				    unsigned int versindex,
-				    const char *name,
-				    struct module *mod)
+static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs,
+						  unsigned int versindex,
+						  const char *name,
+						  struct module *mod)
 {
 	struct module *owner;
-	unsigned long ret;
+	const struct kernel_symbol *sym;
 	const unsigned long *crc;
 
-	ret = find_symbol(name, &owner, &crc,
+	sym = find_symbol(name, &owner, &crc,
 			  !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true);
-	if (!IS_ERR_VALUE(ret)) {
-		/* use_module can fail due to OOM,
-		   or module initialization or unloading */
-		if (!check_version(sechdrs, versindex, name, mod, crc) ||
-		    !use_module(mod, owner))
-			ret = -EINVAL;
-	}
-	return ret;
+	/* use_module can fail due to OOM,
+	   or module initialization or unloading */
+	if (!check_version(sechdrs, versindex, name, mod, crc) ||
+	    !use_module(mod, owner))
+		sym = NULL;
+	return sym;
 }
 
 /*
@@ -1466,17 +1464,15 @@ static void free_module(struct module *mod)
 void *__symbol_get(const char *symbol)
 {
 	struct module *owner;
-	unsigned long value;
+	const struct kernel_symbol *sym;
 
 	preempt_disable();
-	value = find_symbol(symbol, &owner, NULL, true, true);
-	if (IS_ERR_VALUE(value))
-		value = 0;
-	else if (strong_try_module_get(owner))
-		value = 0;
+	sym = find_symbol(symbol, &owner, NULL, true, true);
+	if (sym != NULL && strong_try_module_get(owner))
+		sym = NULL;
 	preempt_enable();
 
-	return (void *)value;
+	return sym == NULL ? (void *)0 : (void *)sym->value;
 }
 EXPORT_SYMBOL_GPL(__symbol_get);
 
@@ -1504,8 +1500,8 @@ static int verify_export_symbols(struct module *mod)
 
 	for (i = 0; i < ARRAY_SIZE(arr); i++) {
 		for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) {
-			if (!IS_ERR_VALUE(find_symbol(s->name, &owner,
-						      NULL, true, false))) {
+			if (find_symbol(s->name, &owner, NULL, true, false)
+			    != NULL) {
 				printk(KERN_ERR
 				       "%s: exports duplicate symbol %s"
 				       " (owned by %s)\n",
@@ -1529,6 +1525,7 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
 	unsigned long secbase;
 	unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
 	int ret = 0;
+	const struct kernel_symbol *ksym;
 
 	for (i = 1; i < n; i++) {
 		switch (sym[i].st_shndx) {
@@ -1548,13 +1545,14 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
 			break;
 
 		case SHN_UNDEF:
-			sym[i].st_value
-			  = resolve_symbol(sechdrs, versindex,
-					   strtab + sym[i].st_name, mod);
-
+			ksym = resolve_symbol(sechdrs, versindex,
+					      strtab + sym[i].st_name, mod);
 			/* Ok if resolved.  */
-			if (!IS_ERR_VALUE(sym[i].st_value))
+			if (ksym != NULL) {
+				sym[i].st_value = ksym->value;
 				break;
+			}
+
 			/* Ok if weak.  */
 			if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK)
 				break;
-- 
1.5.6.3


  reply	other threads:[~2008-12-06  0:06 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-06  0:03 [PATCH 0/7] Ksplice: Rebootless kernel updates Jeff Arnold
2008-12-06  0:03 ` [PATCH 1/7] Make section names compatible with -ffunction-sections -fdata-sections Jeff Arnold
2008-12-06  0:03   ` [PATCH 2/7] x86: Add an option to compile " Jeff Arnold
2008-12-06  0:03     ` Jeff Arnold [this message]
2008-12-06  0:03       ` [PATCH 4/7] Ksplice: Add module_data_address (the analogue of module_text_address) Jeff Arnold
2008-12-06  0:03         ` [PATCH 5/7] Ksplice: Add functions for walking kallsyms symbols Jeff Arnold
2008-12-06  0:03           ` [PATCH 6/7] Ksplice: Export symbols needed for Ksplice Jeff Arnold
2008-12-06  0:04             ` [PATCH 7/7] Ksplice: Support updating x86-32 and x86-64 Jeff Arnold
2008-12-17  5:41               ` Theodore Tso
2008-12-18  2:09                 ` Tim Abbott
2009-02-07  2:36               ` Rusty Russell
2009-02-10  1:01                 ` Tim Abbott
2009-02-04 11:35             ` [PATCH 6/7] Ksplice: Export symbols needed for Ksplice Rusty Russell
2009-02-13  1:46               ` Tim Abbott
2009-02-16  7:11                 ` Rusty Russell
2009-02-04 11:30           ` [PATCH 5/7] Ksplice: Add functions for walking kallsyms symbols Rusty Russell
2009-02-04 21:31             ` Anders Kaseorg
2009-02-04 11:21         ` [PATCH 4/7] Ksplice: Add module_data_address (the analogue of module_text_address) Rusty Russell
2009-02-04 20:48           ` Anders Kaseorg
2009-02-07 12:45             ` Rusty Russell
2009-02-04  9:26       ` [PATCH 3/7] Ksplice: Make find_symbol return a struct kernel_symbol Rusty Russell
2009-02-04  8:38     ` [PATCH 2/7] x86: Add an option to compile with -ffunction-sections -fdata-sections Rusty Russell
2009-02-04 10:26       ` Anders Kaseorg
2009-02-04 10:58         ` Rusty Russell
2009-02-04 20:50           ` Anders Kaseorg
2008-12-06  8:46   ` [PATCH 1/7] Make section names compatible " Andi Kleen
2008-12-31 19:18     ` Tim Abbott
2008-12-31 19:52       ` Andi Kleen
2008-12-31 21:59         ` Tim Abbott
2009-01-01 16:32           ` Andrew Morton
2009-01-04 19:20             ` Tim Abbott
2009-01-12 21:51               ` Andrew Morton
2009-01-12 22:11                 ` Andi Kleen
2009-02-04  8:15   ` Rusty Russell
2009-02-05  1:11     ` Anders Kaseorg
2009-02-05  2:00       ` Anders Kaseorg
2008-12-17  2:48 ` [PATCH 0/7] Ksplice: Rebootless kernel updates Tim Abbott
2008-12-17  3:07   ` Andrew Morton
2008-12-17  3:53     ` Dave Jones
2008-12-17 17:19       ` Jeff Arnold
2008-12-17  5:05     ` Tim Abbott
2008-12-17 12:09       ` Ben Collins
2008-12-17 12:06     ` Ben Collins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1228521840-3886-4-git-send-email-jbarnold@mit.edu \
    --to=jbarnold@mit.edu \
    --cc=akpm@linux-foundation.org \
    --cc=andersk@MIT.EDU \
    --cc=knikanth@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tabbott@MIT.EDU \
    --cc=vda.linux@googlemail.com \
    --cc=wdaher@MIT.EDU \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome