All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Smith <dsmith@redhat.com>
To: "Randy.Dunlap" <rdunlap@xenotime.net>
Cc: linux-kernel@vger.kernel.org, rusty@rustcorp.com.au,
	prasanna@in.ibm.com, ananth@in.ibm.com,
	anil.s.keshavamurthy@intel.com, davem@davemloft.net
Subject: Re: [PATCH] module interface improvement for kprobes
Date: Fri, 04 Aug 2006 14:51:01 -0500	[thread overview]
Message-ID: <1154721061.15967.31.camel@dhcp-2.hsv.redhat.com> (raw)
In-Reply-To: <20060804090018.0bd4020d.rdunlap@xenotime.net>

Randy,

Thanks for looking at this.  I implemented your suggestions and also
changed EXPORT_SYMBOL to EXPORT_SYMBOL_GPL.

On Fri, 2006-08-04 at 09:00 -0700, Randy.Dunlap wrote:
> On Fri, 04 Aug 2006 10:17:32 -0500 David Smith wrote:
> 
> > When inserting a kprobes probe into a loadable module, there isn't a way
> > for the kprobes module to get a module reference (in order to find the
> > base address of the module among perhaps other things).
> > 
> > A kprobes probe needs the base address of the module in order to
> > "relocate" the addresses of probe points (since the load address of the
> > module can change from run to run of the kprobe).
> > 
> > I've added a new function, module_get_byname(), that looks up a module
> > by name and returns the module reference.  Note that module_get_byname()
> > also increments the module reference count.  It does this so that the
> > module won't be unloaded between the time that module_get_byname() is
> > called and register_kprobe() is called.

...

Signed off by David Smith <dsmith@redhat.com>

----
diff --git a/include/linux/module.h b/include/linux/module.h
index 0dfb794..9953a38 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -374,6 +374,8 @@ extern void __module_put_and_exit(struct
 	__attribute__((noreturn));
 #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE,
code);
 
+int module_get_byname(const char *mod_name, struct module **mod);
+
 #ifdef CONFIG_MODULE_UNLOAD
 unsigned int module_refcount(struct module *mod);
 void __symbol_put(const char *symbol);
@@ -549,6 +551,11 @@ static inline int is_exported(const char
 	return 0;
 }
 
+static inline int module_get_byname(const char *mod_name, struct module
**mod)
+{
+	return 1;
+}
+
 static inline int register_module_notifier(struct notifier_block * nb)
 {
 	/* no events will happen anyway, so this can always succeed */
diff --git a/kernel/module.c b/kernel/module.c
index 2a19cd4..473cc0b 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -291,7 +291,27 @@ static struct module *find_module(const 
 	}
 	return NULL;
 }
+  
+int module_get_byname(const char *mod_name, struct module **mod)
+{
+	*mod = NULL;
 
+	/* We must hold module_mutex before calling find_module(). */
+	if (mutex_lock_interruptible(&module_mutex) != 0)
+		return -EINTR;
+
+	*mod = find_module(mod_name);
+	mutex_unlock(&module_mutex);
+	if (*mod) {
+		if (!strong_try_module_get(*mod)) {
+			*mod = NULL;
+			return -EINVAL;
+		}
+	}
+	return 0;
+}
+EXPORT_SYMBOL_GPL(module_get_byname);
+ 
 #ifdef CONFIG_SMP
 /* Number of blocks used and allocated. */
 static unsigned int pcpu_num_used, pcpu_num_allocated;



  reply	other threads:[~2006-08-04 19:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-04 15:17 [PATCH] module interface improvement for kprobes David Smith
2006-08-04 15:57 ` Christoph Hellwig
2006-08-04 18:30   ` David Smith
2006-08-05 11:35     ` Christoph Hellwig
2006-08-05 21:10       ` Frank Ch. Eigler
2006-08-07  4:52   ` Ananth N Mavinakayanahalli
2006-08-07  5:05     ` Ananth N Mavinakayanahalli
2006-08-08 15:39     ` David Smith
2006-08-04 16:00 ` Randy.Dunlap
2006-08-04 19:51   ` David Smith [this message]
2006-08-05  2:28 ` Rusty Russell
  -- strict thread matches above, loose matches on Subject: below --
2006-08-04 23:00 Chuck Ebbert

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=1154721061.15967.31.camel@dhcp-2.hsv.redhat.com \
    --to=dsmith@redhat.com \
    --cc=ananth@in.ibm.com \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=prasanna@in.ibm.com \
    --cc=rdunlap@xenotime.net \
    --cc=rusty@rustcorp.com.au \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.