* [PATCH] [2/9] Add a kernel_address() that works for data too
[not found] <20100105315.789846878@firstfloor.org>
@ 2010-01-05 2:15 ` Andi Kleen
2010-01-05 8:44 ` Russell King
2010-01-05 8:58 ` Sam Ravnborg
0 siblings, 2 replies; 7+ messages in thread
From: Andi Kleen @ 2010-01-05 2:15 UTC (permalink / raw)
To: linux-arch, ebiederm, paulmck, akpm, linux-kernel
Add a variant of kernel_text_address() that includes kernel data.
Assumes kernel is _text ... _end - init section. True everywhere?
Cc: linux-arch@vger.kernel.org
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
include/linux/kernel.h | 1 +
kernel/extable.c | 18 ++++++++++++++++++
2 files changed, 19 insertions(+)
Index: linux-2.6.33-rc2-ak/include/linux/kernel.h
===================================================================
--- linux-2.6.33-rc2-ak.orig/include/linux/kernel.h
+++ linux-2.6.33-rc2-ak/include/linux/kernel.h
@@ -205,6 +205,7 @@ extern unsigned long long memparse(const
extern int core_kernel_text(unsigned long addr);
extern int __kernel_text_address(unsigned long addr);
extern int kernel_text_address(unsigned long addr);
+extern int kernel_address(unsigned long addr);
extern int func_ptr_is_kernel_text(void *ptr);
struct pid;
Index: linux-2.6.33-rc2-ak/kernel/extable.c
===================================================================
--- linux-2.6.33-rc2-ak.orig/kernel/extable.c
+++ linux-2.6.33-rc2-ak/kernel/extable.c
@@ -72,6 +72,18 @@ int core_kernel_text(unsigned long addr)
return 0;
}
+static int core_kernel_address(unsigned long addr)
+{
+ if ((addr >= (unsigned long)_text &&
+ addr <= (unsigned long)_end)) {
+ if (addr >= (unsigned long)__init_begin &&
+ addr < (unsigned long)__init_end)
+ return system_state == SYSTEM_BOOTING;
+ return 1;
+ }
+ return 0;
+}
+
int __kernel_text_address(unsigned long addr)
{
if (core_kernel_text(addr))
@@ -98,6 +110,12 @@ int kernel_text_address(unsigned long ad
return is_module_text_address(addr);
}
+/* text or data in core kernel or module */
+int kernel_address(unsigned long addr)
+{
+ return core_kernel_address(addr) || is_module_address(addr);
+}
+
/*
* On some architectures (PPC64, IA64) function pointers
* are actually only tokens to some data that then holds the
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] [2/9] Add a kernel_address() that works for data too
2010-01-05 2:15 ` [PATCH] [2/9] Add a kernel_address() that works for data too Andi Kleen
@ 2010-01-05 8:44 ` Russell King
2010-01-05 8:58 ` Sam Ravnborg
1 sibling, 0 replies; 7+ messages in thread
From: Russell King @ 2010-01-05 8:44 UTC (permalink / raw)
To: Andi Kleen; +Cc: linux-arch, ebiederm, paulmck, akpm, linux-kernel
On Tue, Jan 05, 2010 at 03:15:27AM +0100, Andi Kleen wrote:
>
> Add a variant of kernel_text_address() that includes kernel data.
>
> Assumes kernel is _text ... _end - init section. True everywhere?
No. XIP kernels have the text and data/bss separated into two distinct
address regions.
--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of:
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] [2/9] Add a kernel_address() that works for data too
2010-01-05 2:15 ` [PATCH] [2/9] Add a kernel_address() that works for data too Andi Kleen
2010-01-05 8:44 ` Russell King
@ 2010-01-05 8:58 ` Sam Ravnborg
2010-01-05 19:04 ` Russell King
1 sibling, 1 reply; 7+ messages in thread
From: Sam Ravnborg @ 2010-01-05 8:58 UTC (permalink / raw)
To: Andi Kleen; +Cc: linux-arch, ebiederm, paulmck, akpm, linux-kernel
On Tue, Jan 05, 2010 at 03:15:27AM +0100, Andi Kleen wrote:
>
> Add a variant of kernel_text_address() that includes kernel data.
>
> Assumes kernel is _text ... _end - init section. True everywhere?
Tim Abbott has done a great job lately to unify the various
linker scripts used by the different architectures.
Architectures are supposed to follow the skeleton outlined
in include/asm-generic/vmlinux.lds.h
But I think the skeleton needs a small update.
It describes that we mark start of .text with _stext.
But reality is that we use _text for this.
But you can trust _etext an almost all architectures.
It is a bug if it is missing.
So [_text, _etext] is the text section.
The data section may be placed before or after - it depends on the architecture.
But again - only some architectures define _sdata.
But all? define _edata.
Sam
>
> Cc: linux-arch@vger.kernel.org
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
>
> ---
> include/linux/kernel.h | 1 +
> kernel/extable.c | 18 ++++++++++++++++++
> 2 files changed, 19 insertions(+)
>
> Index: linux-2.6.33-rc2-ak/include/linux/kernel.h
> ===================================================================
> --- linux-2.6.33-rc2-ak.orig/include/linux/kernel.h
> +++ linux-2.6.33-rc2-ak/include/linux/kernel.h
> @@ -205,6 +205,7 @@ extern unsigned long long memparse(const
> extern int core_kernel_text(unsigned long addr);
> extern int __kernel_text_address(unsigned long addr);
> extern int kernel_text_address(unsigned long addr);
> +extern int kernel_address(unsigned long addr);
> extern int func_ptr_is_kernel_text(void *ptr);
>
> struct pid;
> Index: linux-2.6.33-rc2-ak/kernel/extable.c
> ===================================================================
> --- linux-2.6.33-rc2-ak.orig/kernel/extable.c
> +++ linux-2.6.33-rc2-ak/kernel/extable.c
> @@ -72,6 +72,18 @@ int core_kernel_text(unsigned long addr)
> return 0;
> }
>
> +static int core_kernel_address(unsigned long addr)
> +{
> + if ((addr >= (unsigned long)_text &&
> + addr <= (unsigned long)_end)) {
> + if (addr >= (unsigned long)__init_begin &&
> + addr < (unsigned long)__init_end)
> + return system_state == SYSTEM_BOOTING;
> + return 1;
> + }
> + return 0;
> +}
> +
> int __kernel_text_address(unsigned long addr)
> {
> if (core_kernel_text(addr))
> @@ -98,6 +110,12 @@ int kernel_text_address(unsigned long ad
> return is_module_text_address(addr);
> }
>
> +/* text or data in core kernel or module */
> +int kernel_address(unsigned long addr)
> +{
> + return core_kernel_address(addr) || is_module_address(addr);
> +}
> +
> /*
> * On some architectures (PPC64, IA64) function pointers
> * are actually only tokens to some data that then holds the
> --
> To unsubscribe from this list: send the line "unsubscribe linux-arch" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] [2/9] Add a kernel_address() that works for data too
2010-01-05 8:58 ` Sam Ravnborg
@ 2010-01-05 19:04 ` Russell King
2010-01-05 19:15 ` Andi Kleen
0 siblings, 1 reply; 7+ messages in thread
From: Russell King @ 2010-01-05 19:04 UTC (permalink / raw)
To: Sam Ravnborg
Cc: Andi Kleen, linux-arch, ebiederm, paulmck, akpm, linux-kernel
On Tue, Jan 05, 2010 at 09:58:53AM +0100, Sam Ravnborg wrote:
> But you can trust _etext an almost all architectures.
> It is a bug if it is missing.
>
> So [_text, _etext] is the text section.
>
> The data section may be placed before or after - it depends on the architecture.
> But again - only some architectures define _sdata.
> But all? define _edata.
You can not guarantee that the data segment is after the text segment,
unless you want to outlaw XIP kernels. XIP kernels have the text
segment mapped at a completely different address to the data segment.
I'd suggest the only way to identify the data segment in a generic way
is to have everyone define _sdata, or more preferably _data (to be
consistent with _text), to be the start of the data segment.
--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of:
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] [2/9] Add a kernel_address() that works for data too
2010-01-05 19:04 ` Russell King
@ 2010-01-05 19:15 ` Andi Kleen
2010-01-05 19:15 ` Andi Kleen
2010-01-08 23:51 ` Andrew Morton
0 siblings, 2 replies; 7+ messages in thread
From: Andi Kleen @ 2010-01-05 19:15 UTC (permalink / raw)
To: Sam Ravnborg, Andi Kleen, linux-arch, ebiederm, paulmck, akpm,
linux-kern
> I'd suggest the only way to identify the data segment in a generic way
> is to have everyone define _sdata, or more preferably _data (to be
> consistent with _text), to be the start of the data segment.
I agree. I'll take a look at that.
-Andi
--
ak@linux.intel.com -- Speaking for myself only.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] [2/9] Add a kernel_address() that works for data too
2010-01-05 19:15 ` Andi Kleen
@ 2010-01-05 19:15 ` Andi Kleen
2010-01-08 23:51 ` Andrew Morton
1 sibling, 0 replies; 7+ messages in thread
From: Andi Kleen @ 2010-01-05 19:15 UTC (permalink / raw)
To: Sam Ravnborg, Andi Kleen, linux-arch, ebiederm, paulmck, akpm,
linux-kernel
> I'd suggest the only way to identify the data segment in a generic way
> is to have everyone define _sdata, or more preferably _data (to be
> consistent with _text), to be the start of the data segment.
I agree. I'll take a look at that.
-Andi
--
ak@linux.intel.com -- Speaking for myself only.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] [2/9] Add a kernel_address() that works for data too
2010-01-05 19:15 ` Andi Kleen
2010-01-05 19:15 ` Andi Kleen
@ 2010-01-08 23:51 ` Andrew Morton
1 sibling, 0 replies; 7+ messages in thread
From: Andrew Morton @ 2010-01-08 23:51 UTC (permalink / raw)
To: Andi Kleen; +Cc: Sam Ravnborg, linux-arch, ebiederm, paulmck, linux-kernel
On Tue, 5 Jan 2010 20:15:03 +0100
Andi Kleen <andi@firstfloor.org> wrote:
> > I'd suggest the only way to identify the data segment in a generic way
> > is to have everyone define _sdata, or more preferably _data (to be
> > consistent with _text), to be the start of the data segment.
>
> I agree. I'll take a look at that.
>
I'll merge this as-is for now. Please send updates when convenient.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-01-08 23:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20100105315.789846878@firstfloor.org>
2010-01-05 2:15 ` [PATCH] [2/9] Add a kernel_address() that works for data too Andi Kleen
2010-01-05 8:44 ` Russell King
2010-01-05 8:58 ` Sam Ravnborg
2010-01-05 19:04 ` Russell King
2010-01-05 19:15 ` Andi Kleen
2010-01-05 19:15 ` Andi Kleen
2010-01-08 23:51 ` Andrew Morton
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).