From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: akpm@linux-foundation.org, Ingo Molnar <mingo@elte.hu>,
linux-kernel@vger.kernel.org, laijs@cn.fujitsu.com,
dipankar@in.ibm.com, josh@joshtriplett.org, dvhltc@us.ibm.com,
niv@us.ibm.com, tglx@linutronix.de, peterz@infradead.org,
rostedt@goodmis.org, Valdis.Kletnieks@vt.edu,
dhowells@redhat.com, eric.dumazet@gmail.com, adobriyan@gmail.com
Subject: [RFC patch] extable and module add object is static
Date: Sat, 27 Mar 2010 20:02:34 -0400 [thread overview]
Message-ID: <20100328000234.GA4924@Krystal> (raw)
In-Reply-To: <20100327234314.GL2343@linux.vnet.ibm.com>
* Paul E. McKenney (paulmck@linux.vnet.ibm.com) wrote:
> On Sat, Mar 27, 2010 at 07:20:24PM -0400, Mathieu Desnoyers wrote:
[...]
> > Something close to "object_is_static()" would be "kernel_text_address()", but it
> > only considers the text section addresses. I'd need something that would be
> > broader than that, containing all core kernel and module bss and data sections.
> >
> > Still looking...
>
> I was actually feeling pretty good about remembering object_is_on_stack()
> and finding it again. ;-)
>
> I am not seeing anything the identifies data or bss, and in any case,
> other situations such as per-CPU, __read_mostly, and who knows what all
> else would also need to be handled. So in the short term, my guess would
> be that it would be best to provide the three functions (possibly renaming
> them as noted above), but to leave the responsibility for figuring out
> which to invoke with the caller. Always happy to be proven wrong, of
> course!
>
> Thanx, Paul
I think I found a neat way to do object_is_static(), which is all we need here.
Can you have a look at the following patch ? If you think it's right, I'll add
it to the patchset for the next submission.
extable and module add object is static
Adds an API to extable.c to check if an object is statically defined. This
permits, along with object_is_on_stack(), to figure out is an object is either
statically defined (object_is_static()) or allocated on the stack
(object_is_on_stack()).
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
CC: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
CC: David S. Miller <davem@davemloft.net>
CC: akpm@linux-foundation.org
CC: mingo@elte.hu
CC: laijs@cn.fujitsu.com
CC: dipankar@in.ibm.com
CC: josh@joshtriplett.org
CC: dvhltc@us.ibm.com
CC: niv@us.ibm.com
CC: tglx@linutronix.de
CC: peterz@infradead.org
CC: rostedt@goodmis.org
CC: Valdis.Kletnieks@vt.edu
CC: dhowells@redhat.com
CC: eric.dumazet@gmail.com
CC: Alexey Dobriyan <adobriyan@gmail.com>
---
include/linux/kernel.h | 2 +
kernel/extable.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+)
Index: linux.trees.git/include/linux/kernel.h
===================================================================
--- linux.trees.git.orig/include/linux/kernel.h 2010-03-27 19:27:02.000000000 -0400
+++ linux.trees.git/include/linux/kernel.h 2010-03-27 19:28:02.000000000 -0400
@@ -218,6 +218,8 @@ extern int __kernel_text_address(unsigne
extern int kernel_text_address(unsigned long addr);
extern int func_ptr_is_kernel_text(void *ptr);
+extern int object_is_static(void *obj);
+
struct pid;
extern struct pid *session_of_pgrp(struct pid *pgrp);
Index: linux.trees.git/kernel/extable.c
===================================================================
--- linux.trees.git.orig/kernel/extable.c 2010-03-27 19:28:06.000000000 -0400
+++ linux.trees.git/kernel/extable.c 2010-03-27 19:54:40.000000000 -0400
@@ -60,6 +60,14 @@ static inline int init_kernel_text(unsig
return 0;
}
+static inline int init_kernel_text_or_data(unsigned long addr)
+{
+ if (addr >= (unsigned long)__init_begin &&
+ addr <= (unsigned long)__init_end)
+ return 1;
+ return 0;
+}
+
int core_kernel_text(unsigned long addr)
{
if (addr >= (unsigned long)_stext &&
@@ -113,3 +121,47 @@ int func_ptr_is_kernel_text(void *ptr)
return 1;
return is_module_text_address(addr);
}
+
+/*
+ * Taking the safe approach to refer to each section individually rather than
+ * just taking a range between _stext and _end, just in case an architecture
+ * would decide to override the standard linker scripts and put a section
+ * outside of this range.
+ *
+ * Should be kept in sync with linux/section.h and asm-generic/vmlinux.lds.h.
+ */
+static int core_object_is_static(void *obj)
+{
+ unsigned long addr = (unsigned long) obj;
+
+ if (addr >= (unsigned long)_sdata &&
+ addr <= (unsigned long)_edata)
+ return 1;
+ if (addr >= (unsigned long)__bss_start &&
+ addr <= (unsigned long)__bss_stop)
+ return 1;
+ if (addr >= (unsigned long)__per_cpu_start &&
+ addr <= (unsigned long)__per_cpu_end)
+ return 1;
+ if (addr >= (unsigned long)__start_rodata &&
+ addr <= (unsigned long)__end_rodata)
+ return 1;
+ if (system_state == SYSTEM_BOOTING &&
+ init_kernel_text_or_data(addr))
+ return 1;
+ if (core_kernel_text(addr))
+ return 1;
+ return 0;
+}
+
+/*
+ * object_is_static - returns true is an object is statically defined
+ */
+int object_is_static(void *obj)
+{
+ if (core_object_is_static(obj))
+ return 1;
+ if (is_module_address((unsigned long) obj))
+ return 1;
+ return 0;
+}
--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
next prev parent reply other threads:[~2010-03-28 0:02 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-27 15:32 [patch 0/6] rcu head debugobjects Mathieu Desnoyers
2010-03-27 15:32 ` [patch 1/6] commit 501fdb3aeeb2444f86d289a4a044cf7c8fbc17df Author: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> Date: Sat Mar 27 10:52:11 2010 -0400 Mathieu Desnoyers
2010-03-27 15:32 ` [patch 2/6] commit afd066d60b77e28651bb8323fc8cfcedacc5cbf8 Author: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> Date: Sat Mar 27 10:53:30 " Mathieu Desnoyers
2010-03-27 15:32 ` [patch 3/6] commit 418b6f2c2ddba7c91d1186b68618092910260c32 Author: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> Date: Sat Mar 27 11:05:38 " Mathieu Desnoyers
2010-03-27 15:32 ` [patch 4/6] Debugobjects transition check Mathieu Desnoyers
2010-03-27 15:32 ` [patch 5/6] tree/tiny rcu: Add debug RCU head objects (v4) Mathieu Desnoyers
2010-03-27 15:32 ` [patch 6/6] kernel call_rcu usage: initialize rcu_head structures (v2) Mathieu Desnoyers
2010-03-27 15:40 ` [patch 0/6] rcu head debugobjects David Miller
2010-03-27 22:46 ` Paul E. McKenney
2010-03-27 23:14 ` Mathieu Desnoyers
2010-03-27 23:20 ` Mathieu Desnoyers
2010-03-27 23:43 ` Paul E. McKenney
2010-03-28 0:02 ` Mathieu Desnoyers [this message]
2010-03-28 0:25 ` [RFC patch] extable and module add object is static Paul E. McKenney
2010-03-29 1:39 ` Lai Jiangshan
2010-03-29 3:18 ` Mathieu Desnoyers
2010-03-29 8:53 ` Peter Zijlstra
2010-03-29 13:16 ` Mathieu Desnoyers
2010-03-29 13:55 ` Tejun Heo
2010-03-29 14:03 ` Mathieu Desnoyers
2010-03-29 13:39 ` [patch 0/6] rcu head debugobjects Mathieu Desnoyers
2010-03-29 14:53 ` Paul E. McKenney
2010-03-29 15:04 ` Mathieu Desnoyers
2010-03-29 16:01 ` Paul E. McKenney
2010-03-28 2:07 ` Thomas Gleixner
2010-03-28 4:30 ` Paul E. McKenney
2010-03-29 0:45 ` Mathieu Desnoyers
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=20100328000234.GA4924@Krystal \
--to=mathieu.desnoyers@efficios.com \
--cc=Valdis.Kletnieks@vt.edu \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=dipankar@in.ibm.com \
--cc=dvhltc@us.ibm.com \
--cc=eric.dumazet@gmail.com \
--cc=josh@joshtriplett.org \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=niv@us.ibm.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/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