Hello
RFC
On some arches C function pointers are indirect and point to
a function descriptor, which contains the actual pointer to the code.
This mostly doesn't matter, except for cases when people want to print
out function pointers in symbolic format, because the usual '%pS/%ps'
does not work on those arches as expected. That's the reason why we
have '%pF/%pf', but since it's here because of a subtle ABI detail
specific to some arches (ppc64/ia64/parisc64) it's easy to misuse
'%pF/%pf' and '%pS/%ps' (see [1], for example).
This patch set attempts to move ia64/ppc64/parisc64 C function
pointer ABI details out of printk() to arch code. Function dereference
code now checks if a pointer belongs to a .opd ELF section and dereferences
that pointer only if it does. The kernel and modules have their own .opd
sections that's why I use two different ARCH functions: for kernel and
for module pointer dereference.
I planned to remove dereference_function_descriptor() entirely,
but then I discovered a bunch other uses cases (kgdbts, init/main.c,
extable, etc.), so I decided to keep dereference_function_descriptor()
around because the main point of this patch set is to deprecate %pF/%pf.
But at the same time, I think I can go further and handle both kernel
and module descriptor dereference in dereference_function_descriptor().
We need a module pointer for module .opd check, so that will come at an
extra cost of module lookup (may be there will some other issues along
the way, haven't checked it).
Right now we've got:
- dereference_function_descriptor(addr)
a generic (old) function. it simply attempts to dereference
whatever pointer we give it.
- dereference_kernel_function_descriptor(addr)
dereferences a kernel pointer if it's within the kernel's .opd
section.
- dereference_module_function_descriptor(module, addr)
dereference a module pointer if it's within the module's .opd
section.
*** A BIG NOTE ***
I don't own ia64/ppc64/parisc64 hardware, so the patches are not
tested. Sorry about that!
Another note:
I need to check what is BPF symbol lookup and do we need to
do any dereference there.
v2:
-- convert dereference_function_descriptor() to unsigned long
-- fix kernel descriptor range checks (Helge)
-- fix parisc module descriptor range check (Helge)
-- fix ppc64 module range check
-- add checkpatch patch
Sergey Senozhatsky (7):
switch dereference_function_descriptor() to `unsigned long'
sections: split dereference_function_descriptor()
ia64: Add .opd based function descriptor dereference
powerpc64: Add .opd based function descriptor dereference
parisc64: Add .opd based function descriptor dereference
symbol lookup: use new kernel and module dereference functions
checkpatch: add pF/pf deprecation warning
Documentation/printk-formats.txt | 15 +++++----------
arch/ia64/include/asm/sections.h | 16 ++++++++++++----
arch/ia64/kernel/module.c | 13 +++++++++++++
arch/ia64/kernel/vmlinux.lds.S | 2 ++
arch/parisc/boot/compressed/vmlinux.lds.S | 2 ++
arch/parisc/include/asm/sections.h | 4 +++-
arch/parisc/kernel/module.c | 17 +++++++++++++++++
arch/parisc/kernel/process.c | 15 ++++++++++++---
arch/parisc/kernel/vmlinux.lds.S | 2 ++
arch/parisc/mm/init.c | 4 ++--
arch/powerpc/include/asm/module.h | 3 +++
arch/powerpc/include/asm/sections.h | 17 ++++++++++++++---
arch/powerpc/kernel/module_64.c | 16 ++++++++++++++++
arch/powerpc/kernel/vmlinux.lds.S | 2 ++
drivers/misc/kgdbts.c | 2 +-
include/asm-generic/sections.h | 8 ++++++--
include/linux/moduleloader.h | 4 ++++
init/main.c | 2 +-
kernel/extable.c | 2 +-
kernel/kallsyms.c | 1 +
kernel/module.c | 9 ++++++++-
lib/vsprintf.c | 5 +----
scripts/checkpatch.pl | 6 ++++--
23 files changed, 132 insertions(+), 35 deletions(-)
--
2.14.1
@@ -150,7 +150,7 @@ int kernel_text_address(unsigned long addr)intfunc_ptr_is_kernel_text(void*ptr){unsignedlongaddr;-addr=(unsignedlong)dereference_function_descriptor(ptr);+addr=dereference_function_descriptor((unsignedlong)ptr);if(core_kernel_text(addr))return1;returnis_module_text_address(addr);
There are two format specifiers to print out a pointer in symbolic
format: '%pS/%ps' and '%pF/%pf'. On most architectures, the two
mean exactly the same thing, but some architectures (ia64, ppc64,
parisc64) use an indirect pointer for C function pointers, where
the function pointer points to a function descriptor (which in
turn contains the actual pointer to the code). The '%pF/%pf, when
used appropriately, automatically does the appropriate function
descriptor dereference on such architectures.
The "when used appropriately" part is tricky. Basically this is
a subtle ABI detail, specific to some platforms, that made it to
the API level and people can be unaware of it and miss the whole
"we need to dereference the function" business out. [1] proves
that point (note that it fixes only '%pF' and '%pS', there might
be '%pf' and '%ps' cases as well).
It appears that we can handle everything within the affected
arches and make '%pS/%ps' smart enough to retire '%pF/%pf'.
Function descriptors live in .opd elf section and all affected
arches (ia64, ppc64, parisc64) handle it properly for kernel
and modules. So we, technically, can decide if the dereference
is needed by simply looking at the pointer: if it belongs to
.opd section then we need to dereference it.
The kernel and modules have their own .opd sections, obviously,
that's why we need to split dereference_function_descriptor()
and use separate kernel and module dereference arch callbacks.
This patch does the first step, it
a) adds dereference_kernel_function_descriptor() function.
b) adds a weak alias to dereference_module_function_descriptor()
function.
So, for the time being, we will have:
1) dereference_function_descriptor()
A generic function, that simply dereferences the pointer. There is
bunch of places that call it: kgdbts, init/main.c, extable, etc.
2) dereference_kernel_function_descriptor()
A function to call on kernel symbols that does kernel .opd section
address range test.
3) dereference_module_function_descriptor()
A function to call on modules' symbols that does modules' .opd
section address range test.
[1] https://marc.info/?l=linux-kernel&m=150472969730573
Signed-off-by: Sergey Senozhatsky <redacted>
---
include/asm-generic/sections.h | 8 ++++++--
include/linux/moduleloader.h | 4 ++++
kernel/module.c | 6 ++++++
3 files changed, 16 insertions(+), 2 deletions(-)
@@ -47,12 +48,15 @@ extern char __softirqentry_text_start[], __softirqentry_text_end[];/* Start and end of .ctors section - used for constructor calls. */externchar__ctors_start[],__ctors_end[];+/* Start and end of .opd section - used for function descriptors. */+externchar__start_opd[],__end_opd[];+extern__visibleconstvoid__nosave_begin,__nosave_end;-/* function descriptor handling (if any). Override-*inasm/sections.h*/+/* Function descriptor handling (if any). Override in asm/sections.h */#ifndef dereference_function_descriptor#define dereference_function_descriptor(p) (p)+#define dereference_kernel_function_descriptor(p) (p)#endif/* random extra sections (if any). Override
We are moving towards separate kernel and module function descriptor
dereference callbacks. This patch enables it for IA64.
For pointers that belong to the kernel
- Added __start_opd and __end_opd pointers, to track the kernel
.opd section address range;
- Added dereference_kernel_function_descriptor(). Now we
will dereference only function pointers that are within
[__start_opd, __end_opd];
For pointers that belong to a module
- Added dereference_module_function_descriptor() to handle module
function descriptor dereference. Now we will dereference only
pointers that are within [module->opd.start, module->opd.end].
Signed-off-by: Sergey Senozhatsky <redacted>
---
arch/ia64/include/asm/sections.h | 10 +++++++++-
arch/ia64/kernel/module.c | 13 +++++++++++++
arch/ia64/kernel/vmlinux.lds.S | 2 ++
3 files changed, 24 insertions(+), 1 deletion(-)
We are moving towards separate kernel and module function descriptor
dereference callbacks. This patch enables it for parisc64.
For pointers that belong to the kernel
- Added __start_opd and __end_opd pointers, to track the kernel
.opd section address range;
- Added dereference_kernel_function_descriptor(). Now we
will dereference only function pointers that are within
[__start_opd, __end_opd];
For pointers that belong to a module
- Added dereference_module_function_descriptor() to handle module
function descriptor dereference. Now we will dereference only
pointers that are within [module->opd.start, module->opd.end].
Signed-off-by: Sergey Senozhatsky <redacted>
Signed-off-by: Helge Deller <deller@gmx.de>
---
arch/parisc/boot/compressed/vmlinux.lds.S | 2 ++
arch/parisc/include/asm/sections.h | 2 ++
arch/parisc/kernel/module.c | 17 +++++++++++++++++
arch/parisc/kernel/process.c | 9 +++++++++
arch/parisc/kernel/vmlinux.lds.S | 2 ++
5 files changed, 32 insertions(+)
@@ -276,6 +276,15 @@ unsigned long dereference_function_descriptor(unsigned long ptr)ptr=(unsignedlong)p;returnptr;}++unsignedlongdereference_kernel_function_descriptor(unsignedlongaddr)+{+if(addr<(unsignedlong)__start_opd||+addr>=(unsignedlong)__end_opd)+returnaddr;++returndereference_function_descriptor(addr);+}#endifstaticinlineunsignedlongbrk_rnd(void)
Call appropriate function descriptor dereference ARCH callbacks:
- dereference_kernel_function_descriptor() if the pointer is a
kernel symbol;
- dereference_module_function_descriptor() if the pointer is a
module symbol.
This patch also removes dereference_function_descriptor() from
'%pF/%pf' vsprintf handler, because it has the same behavior with
'%pS/%ps' now.
Signed-off-by: Sergey Senozhatsky <redacted>
---
Documentation/printk-formats.txt | 15 +++++----------
kernel/kallsyms.c | 1 +
kernel/module.c | 1 +
lib/vsprintf.c | 5 +----
4 files changed, 8 insertions(+), 14 deletions(-)
@@ -50,26 +50,23 @@ Symbols/Function Pointers ::+ %pS versatile_init+0x0/0x110+ %ps versatile_init %pF versatile_init+0x0/0x110 %pf versatile_init- %pS versatile_init+0x0/0x110 %pSR versatile_init+0x9/0x110 (with __builtin_extract_return_addr() translation)- %ps versatile_init %pB prev_fn_of_versatile_init+0x88/0x88-The ``F`` and ``f`` specifiers are for printing function pointers,-for example, f->func, &gettimeofday. They have the same result as-``S`` and ``s`` specifiers. But they do an extra conversion on-ia64, ppc64 and parisc64 architectures where the function pointers-are actually function descriptors.- The ``S`` and ``s`` specifiers can be used for printing symbols from direct addresses, for example, __builtin_return_address(0), (void *)regs->ip. They result in the symbol name with (``S``) or without (``s``) offsets. If KALLSYMS are disabled then the symbol address is printed instead.+Note, that the ``F`` and ``f`` specifiers are identical to ``S`` (``s``)+and thus deprecated.+ The ``B`` specifier results in the symbol name with offsets and should be used when printing stack backtraces. The specifier takes into consideration the effect of compiler optimisations which may occur
@@ -77,8 +74,6 @@ when tail-call``s are used and marked with the noreturn GCC attribute. Examples::- printk("Going to call: %pF\n", gettimeofday);- printk("Going to call: %pF\n", p->func); printk("%s: called from %pS\n", __func__, (void *)_RET_IP_); printk("%s: called from %pS\n", __func__, (void *)__builtin_return_address(0));
We deprecated '%pF/%pf' printk specifiers, since '%pS/%ps' is now smart
enough to handle function pointer dereference on platforms where such
dereference is required.
checkpatch warning example:
WARNING: Use '%pS/%ps' instead. This pointer extension was deprecated: '%pF'
Signed-off-by: Sergey Senozhatsky <redacted>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Joe Perches <joe@perches.com>
---
scripts/checkpatch.pl | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
We deprecated '%pF/%pf' printk specifiers, since '%pS/%ps' is now smart
enough to handle function pointer dereference on platforms where such
dereference is required.
checkpatch warning example:
WARNING: Use '%pS/%ps' instead. This pointer extension was deprecated: '%pF'
Signed-off-by: Sergey Senozhatsky <redacted>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Joe Perches <joe@perches.com>
---
scripts/checkpatch.pl | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
We are moving towards separate kernel and module function descriptor
dereference callbacks. This patch enables it for powerpc64.
For pointers that belong to the kernel
- Added __start_opd and __end_opd pointers, to track the kernel
.opd section address range;
- Added dereference_kernel_function_descriptor(). Now we
will dereference only function pointers that are within
[__start_opd, __end_opd];
For pointers that belong to a module
- Added dereference_module_function_descriptor() to handle module
function descriptor dereference. Now we will dereference only
pointers that are within [module->opd.start, module->opd.end].
Signed-off-by: Sergey Senozhatsky <redacted>
---
arch/powerpc/include/asm/module.h | 3 +++
arch/powerpc/include/asm/sections.h | 11 +++++++++++
arch/powerpc/kernel/module_64.c | 16 ++++++++++++++++
arch/powerpc/kernel/vmlinux.lds.S | 2 ++
4 files changed, 32 insertions(+)
@@ -45,6 +45,9 @@ struct mod_arch_specific {unsignedlongtramp;#endif+/* For module function descriptor dereference */+unsignedlongstart_opd;+unsignedlongend_opd;#else /* powerpc64 *//* Indices of PLT sections within module. */unsignedintcore_plt_section;
@@ -344,6 +344,11 @@ int module_frob_arch_sections(Elf64_Ehdr *hdr,elseif(strcmp(secstrings+sechdrs[i].sh_name,"__versions")==0)dedotify_versions((void*)hdr+sechdrs[i].sh_offset,sechdrs[i].sh_size);+elseif(!strcmp(secstrings+sechdrs[i].sh_name,".opd")){+me->arch.start_opd=sechdrs[i].sh_addr;+me->arch.end_opd=sechdrs[i].sh_addr++sechdrs[i].sh_size;+}/* We don't handle .init for the moment: rename to _init */while((p=strstr(secstrings+sechdrs[i].sh_name,".init")))
We deprecated '%pF/%pf' printk specifiers, since '%pS/%ps' is now smart
enough to handle function pointer dereference on platforms where such
dereference is required.
checkpatch warning example:
WARNING: Use '%pS/%ps' instead. This pointer extension was deprecated: '%pF'
weird... somehow I sent this patch twice. please ignore this one.
-ss
From: Joe Perches <joe@perches.com> Date: 2017-09-20 17:39:05
On Thu, 2017-09-21 at 01:29 +0900, Sergey Senozhatsky wrote:
We deprecated '%pF/%pf' printk specifiers, since '%pS/%ps' is now smart
enough to handle function pointer dereference on platforms where such
dereference is required.
checkpatch warning example:
WARNING: Use '%pS/%ps' instead. This pointer extension was deprecated: '%pF'
If this series is accepted, I think this message
is unclear and would prefer something like:
---
scripts/checkpatch.pl | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
On Thu, 2017-09-21 at 01:29 +0900, Sergey Senozhatsky wrote:
quoted
We deprecated '%pF/%pf' printk specifiers, since '%pS/%ps' is now smart
enough to handle function pointer dereference on platforms where such
dereference is required.
checkpatch warning example:
WARNING: Use '%pS/%ps' instead. This pointer extension was deprecated: '%pF'
If this series is accepted, I think this message
is unclear and would prefer something like:
Is it worth to mention, that it's still needed in older kernels?
Just in case some patch get's backported.
Helge
From: Joe Perches <joe@perches.com> Date: 2017-09-20 18:24:35
On Wed, 2017-09-20 at 19:53 +0200, Helge Deller wrote:
On 20.09.2017 19:38, Joe Perches wrote:
quoted
On Thu, 2017-09-21 at 01:29 +0900, Sergey Senozhatsky wrote:
quoted
We deprecated '%pF/%pf' printk specifiers, since '%pS/%ps' is now smart
enough to handle function pointer dereference on platforms where such
dereference is required.
checkpatch warning example:
WARNING: Use '%pS/%ps' instead. This pointer extension was deprecated: '%pF'
If this series is accepted, I think this message
is unclear and would prefer something like:
Is it worth to mention, that it's still needed in older kernels?
Just in case some patch get's backported.
I think probably not.
There are relatively few references and
modifications are unlikely to be backported.
This patch set attempts to move ia64/ppc64/parisc64 C function
pointer ABI details out of printk() to arch code. Function dereference
code now checks if a pointer belongs to a .opd ELF section and dereferences
that pointer only if it does. The kernel and modules have their own .opd
sections that's why I use two different ARCH functions: for kernel and
for module pointer dereference.
...> *** A BIG NOTE ***
I don't own ia64/ppc64/parisc64 hardware, so the patches are not
tested. Sorry about that!
I just now tested your patch series successfully on parisc64.
You may add to the whole series:
Tested-by: Helge Deller <deller@gmx.de> # parisc64
Another note:
I need to check what is BPF symbol lookup and do we need to
do any dereference there.
Not relevant for parisc, since we don't support it yet.
Helge
On Thu, 2017-09-21 at 01:29 +0900, Sergey Senozhatsky wrote:
quoted
We deprecated '%pF/%pf' printk specifiers, since '%pS/%ps' is now smart
enough to handle function pointer dereference on platforms where such
dereference is required.
checkpatch warning example:
WARNING: Use '%pS/%ps' instead. This pointer extension was deprecated: '%pF'
If this series is accepted, I think this message
is unclear and would prefer something like:
sure, can tweak the patch.
[..]
if ($bad_extension ne "") {
my $stat_real = raw_line($linenr, 0);
+ my $ext_type = "Invalid";
+ my $use = "";
for (my $count = $linenr + 1; $count <= $lc; $count++) {
$stat_real = $stat_real . "\n" . raw_line($count, 0);
}
+ if ($bad_extension =~ /p[Ff]/i) {
I think /i is not necessary here
+ $ext_type = "Deprecated";
+ $use = " - use %pS instead";
+ $use =~ s/pS/ps/ if ($bad_extension =~ /pf/);
This patch set attempts to move ia64/ppc64/parisc64 C function
pointer ABI details out of printk() to arch code. Function dereference
code now checks if a pointer belongs to a .opd ELF section and dereferences
that pointer only if it does. The kernel and modules have their own .opd
sections that's why I use two different ARCH functions: for kernel and
for module pointer dereference.
...> *** A BIG NOTE ***
I don't own ia64/ppc64/parisc64 hardware, so the patches are not
tested. Sorry about that!
I just now tested your patch series successfully on parisc64.
You may add to the whole series:
Tested-by: Helge Deller <deller@gmx.de> # parisc64
thanks, Helge!
quoted
Another note:
I need to check what is BPF symbol lookup and do we need to
do any dereference there.
Not relevant for parisc, since we don't support it yet.
so that was my suspicion as well. at glance it didn't look like
bpf symbol resolution would work on platforms that do description
dereference.
-ss
From: Joe Perches <joe@perches.com> Date: 2017-09-21 02:28:41
On Thu, 2017-09-21 at 09:27 +0900, Sergey Senozhatsky wrote:
On (09/20/17 10:38), Joe Perches wrote:
quoted
On Thu, 2017-09-21 at 01:29 +0900, Sergey Senozhatsky wrote:
quoted
We deprecated '%pF/%pf' printk specifiers, since '%pS/%ps' is now smart
enough to handle function pointer dereference on platforms where such
dereference is required.
checkpatch warning example:
WARNING: Use '%pS/%ps' instead. This pointer extension was deprecated: '%pF'
If this series is accepted, I think this message
is unclear and would prefer something like:
sure, can tweak the patch.
[..]
quoted
if ($bad_extension ne "") {
my $stat_real = raw_line($linenr, 0);
+ my $ext_type = "Invalid";
+ my $use = "";
for (my $count = $linenr + 1; $count <= $lc; $count++) {
$stat_real = $stat_real . "\n" . raw_line($count, 0);
}
+ if ($bad_extension =~ /p[Ff]/i) {
On Wed, 2017-09-20 at 19:53 +0200, Helge Deller wrote:
[..]
quoted
Is it worth to mention, that it's still needed in older kernels?
Just in case some patch get's backported.
good question.
I think probably not.
There are relatively few references and
modifications are unlikely to be backported.
I tend to agree.
unlikely anyone backports printk message updates. I have quickly glanced
through stable-4.9 and haven't seen such backports. well, may be there
are some.
can tweak the warning a bit, probably. e.g. "if you are planning to
backport your change to kernels older than 4.14 then ignore this
warning". but not sure if it's worth it.
-ss
On (09/21/17 01:29), Sergey Senozhatsky wrote:
[..]
+ %pS versatile_init+0x0/0x110
+ %ps versatile_init
%pF versatile_init+0x0/0x110
%pf versatile_init
- %pS versatile_init+0x0/0x110
%pSR versatile_init+0x9/0x110
(with __builtin_extract_return_addr() translation)
- %ps versatile_init
%pB prev_fn_of_versatile_init+0x88/0x88
-The ``F`` and ``f`` specifiers are for printing function pointers,
-for example, f->func, &gettimeofday. They have the same result as
-``S`` and ``s`` specifiers. But they do an extra conversion on
-ia64, ppc64 and parisc64 architectures where the function pointers
-are actually function descriptors.
-
The ``S`` and ``s`` specifiers can be used for printing symbols
from direct addresses, for example, __builtin_return_address(0),
(void *)regs->ip. They result in the symbol name with (``S``) or
without (``s``) offsets. If KALLSYMS are disabled then the symbol
address is printed instead.
+Note, that the ``F`` and ``f`` specifiers are identical to ``S`` (``s``)
+and thus deprecated.
JFI,
I have updated this part. it's probably too early to completely
wipe out pF/pf info.
the updated Doc goes like this:
+Note, that the ``F`` and ``f`` specifiers are identical to ``S`` (``s``)
+and thus deprecated. We have ``F`` and ``f`` because on ia64, ppc64 and
+parisc64 function pointers are indirect and, in fact, are function
+descriptors, which require additional dereferencing before we can lookup
+the symbol. As of now, ``S`` and ``s`` perform dereferencing on those
+platforms (when needed), so ``F`` and ``f`` exist for compatibility
+reasons only.
-ss
* Sergey Senozhatsky [off-list ref] wrote (on 2017-09-20 16:29:02 +0000):
Hello
RFC
On some arches C function pointers are indirect and point to
a function descriptor, which contains the actual pointer to the code.
This mostly doesn't matter, except for cases when people want to print
out function pointers in symbolic format, because the usual '%pS/%ps'
does not work on those arches as expected. That's the reason why we
have '%pF/%pf', but since it's here because of a subtle ABI detail
specific to some arches (ppc64/ia64/parisc64) it's easy to misuse
'%pF/%pf' and '%pS/%ps' (see [1], for example).
This patch set attempts to move ia64/ppc64/parisc64 C function
pointer ABI details out of printk() to arch code. Function dereference
code now checks if a pointer belongs to a .opd ELF section and dereferences
that pointer only if it does. The kernel and modules have their own .opd
sections that's why I use two different ARCH functions: for kernel and
for module pointer dereference.
I planned to remove dereference_function_descriptor() entirely,
but then I discovered a bunch other uses cases (kgdbts, init/main.c,
extable, etc.), so I decided to keep dereference_function_descriptor()
around because the main point of this patch set is to deprecate %pF/%pf.
But at the same time, I think I can go further and handle both kernel
and module descriptor dereference in dereference_function_descriptor().
We need a module pointer for module .opd check, so that will come at an
extra cost of module lookup (may be there will some other issues along
the way, haven't checked it).
Right now we've got:
- dereference_function_descriptor(addr)
a generic (old) function. it simply attempts to dereference
whatever pointer we give it.
- dereference_kernel_function_descriptor(addr)
dereferences a kernel pointer if it's within the kernel's .opd
section.
- dereference_module_function_descriptor(module, addr)
dereference a module pointer if it's within the module's .opd
section.
*** A BIG NOTE ***
I don't own ia64/ppc64/parisc64 hardware, so the patches are not
tested. Sorry about that!
Tested patch series on ppc64 sucessfully.
You may add tested by to the series.
Tested-by: Santosh Sivaraj <redacted>
Thanks,
Santosh
Another note:
I need to check what is BPF symbol lookup and do we need to
do any dereference there.
v2:
-- convert dereference_function_descriptor() to unsigned long
-- fix kernel descriptor range checks (Helge)
-- fix parisc module descriptor range check (Helge)
-- fix ppc64 module range check
-- add checkpatch patch
Sergey Senozhatsky (7):
switch dereference_function_descriptor() to `unsigned long'
sections: split dereference_function_descriptor()
ia64: Add .opd based function descriptor dereference
powerpc64: Add .opd based function descriptor dereference
parisc64: Add .opd based function descriptor dereference
symbol lookup: use new kernel and module dereference functions
checkpatch: add pF/pf deprecation warning
Documentation/printk-formats.txt | 15 +++++----------
arch/ia64/include/asm/sections.h | 16 ++++++++++++----
arch/ia64/kernel/module.c | 13 +++++++++++++
arch/ia64/kernel/vmlinux.lds.S | 2 ++
arch/parisc/boot/compressed/vmlinux.lds.S | 2 ++
arch/parisc/include/asm/sections.h | 4 +++-
arch/parisc/kernel/module.c | 17 +++++++++++++++++
arch/parisc/kernel/process.c | 15 ++++++++++++---
arch/parisc/kernel/vmlinux.lds.S | 2 ++
arch/parisc/mm/init.c | 4 ++--
arch/powerpc/include/asm/module.h | 3 +++
arch/powerpc/include/asm/sections.h | 17 ++++++++++++++---
arch/powerpc/kernel/module_64.c | 16 ++++++++++++++++
arch/powerpc/kernel/vmlinux.lds.S | 2 ++
drivers/misc/kgdbts.c | 2 +-
include/asm-generic/sections.h | 8 ++++++--
include/linux/moduleloader.h | 4 ++++
init/main.c | 2 +-
kernel/extable.c | 2 +-
kernel/kallsyms.c | 1 +
kernel/module.c | 9 ++++++++-
lib/vsprintf.c | 5 +----
scripts/checkpatch.pl | 6 ++++--
23 files changed, 132 insertions(+), 35 deletions(-)
Tested patch series on ia64 successfully.
Tested-by: Tony Luck <tony.luck@intel.com>
After this goes upstream, you should submit a patch to get rid of
all uses of %pF (70 instances in 35 files) and %pf (63 in 34)
Perhaps break the patch by top-level directory (e.g. get all the %pF
and %pF in the 17 files under drivers/ in one patch).
-Tony
Tested patch series on ia64 successfully.
Tested-by: Tony Luck <tony.luck@intel.com>
thanks!
After this goes upstream, you should submit a patch to get rid of
all uses of %pF (70 instances in 35 files) and %pf (63 in 34)
Perhaps break the patch by top-level directory (e.g. get all the %pF
and %pF in the 17 files under drivers/ in one patch).
frankly, I was going to have some sort of a lazy deprecation process:
didn't plan to send out a patch set that would hunt down all pf/pF-s.
hm...
speaking of upstream, any objections if this patch set will go through
the printk tree, in one piece?
I'll wait for several more days and then resend v3 with updated
Documentation and tweaked checkpatch warning message.
-ss
From: Michael Ellerman <mpe@ellerman.id.au> Date: 2017-09-27 05:01:55
Sergey Senozhatsky [off-list ref] writes:
On (09/22/17 16:48), Luck, Tony wrote:
[..]
quoted
Tested patch series on ia64 successfully.
Tested-by: Tony Luck <tony.luck@intel.com>
thanks!
quoted
After this goes upstream, you should submit a patch to get rid of
all uses of %pF (70 instances in 35 files) and %pf (63 in 34)
Perhaps break the patch by top-level directory (e.g. get all the %pF
and %pF in the 17 files under drivers/ in one patch).
frankly, I was going to have some sort of a lazy deprecation process:
didn't plan to send out a patch set that would hunt down all pf/pF-s.
hm...
That never works though, we have lots of cruft left over from times when
that's happened and the conversion never quite got finished.
At least if you send out the patches to do the removal they might
eventually get merged.
speaking of upstream, any objections if this patch set will go through
the printk tree, in one piece?
Do you mind putting it in a topic branch (based on rc2) and then merge
that into the printk tree? That way I can merge the topic branch iff
there are conflicts later down the line towards 4.15.
cheers
From: Michael Ellerman <mpe@ellerman.id.au> Date: 2017-09-27 06:26:53
Santosh Sivaraj [off-list ref] writes:
* Sergey Senozhatsky [off-list ref] wrote (on 2017-09-20 16:29:02 +0000):
quoted
Hello
RFC
On some arches C function pointers are indirect and point to
a function descriptor, which contains the actual pointer to the code.
This mostly doesn't matter, except for cases when people want to print
out function pointers in symbolic format, because the usual '%pS/%ps'
does not work on those arches as expected. That's the reason why we
have '%pF/%pf', but since it's here because of a subtle ABI detail
specific to some arches (ppc64/ia64/parisc64) it's easy to misuse
'%pF/%pf' and '%pS/%ps' (see [1], for example).
This patch set attempts to move ia64/ppc64/parisc64 C function
pointer ABI details out of printk() to arch code. Function dereference
code now checks if a pointer belongs to a .opd ELF section and dereferences
that pointer only if it does. The kernel and modules have their own .opd
sections that's why I use two different ARCH functions: for kernel and
for module pointer dereference.
I planned to remove dereference_function_descriptor() entirely,
but then I discovered a bunch other uses cases (kgdbts, init/main.c,
extable, etc.), so I decided to keep dereference_function_descriptor()
around because the main point of this patch set is to deprecate %pF/%pf.
But at the same time, I think I can go further and handle both kernel
and module descriptor dereference in dereference_function_descriptor().
We need a module pointer for module .opd check, so that will come at an
extra cost of module lookup (may be there will some other issues along
the way, haven't checked it).
Right now we've got:
- dereference_function_descriptor(addr)
a generic (old) function. it simply attempts to dereference
whatever pointer we give it.
- dereference_kernel_function_descriptor(addr)
dereferences a kernel pointer if it's within the kernel's .opd
section.
- dereference_module_function_descriptor(module, addr)
dereference a module pointer if it's within the module's .opd
section.
*** A BIG NOTE ***
I don't own ia64/ppc64/parisc64 hardware, so the patches are not
tested. Sorry about that!
Tested patch series on ppc64 sucessfully.
You may add tested by to the series.
Tested-by: Santosh Sivaraj <redacted>
Thanks Santosh.
I also gave it a quick spin. I'll give you an ack for the powerpc changes.
Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
Thanks for cleaning this up Sergey.
cheers
Thanks Santosh.
I also gave it a quick spin. I'll give you an ack for the powerpc changes.
Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
Thanks for cleaning this up Sergey.
Michael,
On (09/27/17 15:01), Michael Ellerman wrote:
Sergey Senozhatsky [off-list ref] writes:
quoted
On (09/22/17 16:48), Luck, Tony wrote:
[..]
quoted
Tested patch series on ia64 successfully.
Tested-by: Tony Luck <tony.luck@intel.com>
thanks!
quoted
After this goes upstream, you should submit a patch to get rid of
all uses of %pF (70 instances in 35 files) and %pf (63 in 34)
Perhaps break the patch by top-level directory (e.g. get all the %pF
and %pF in the 17 files under drivers/ in one patch).
frankly, I was going to have some sort of a lazy deprecation process:
didn't plan to send out a patch set that would hunt down all pf/pF-s.
hm...
That never works though, we have lots of cruft left over from times when
that's happened and the conversion never quite got finished.
this time around it's different, I promise! :)
well...
I guess I can send out a tree wide pf/pF removal patch set. later.
when we will see that .opd based dereference does not make anyone
unhappy.
and I think we can't remove pf/pF from the kernel completely. it
will stay in vscnprintf() for some time. old habits die hard, I suppose,
there might be people using it for debugging/etc.
At least if you send out the patches to do the removal they might
eventually get merged.
quoted
speaking of upstream, any objections if this patch set will go through
the printk tree, in one piece?
Do you mind putting it in a topic branch (based on rc2) and then merge
that into the printk tree? That way I can merge the topic branch iff
there are conflicts later down the line towards 4.15.
ok, let me re-spin the series. there are some changes here
and there, so I'll drop Tested-by/Reviewed-by tags and will
ask platforms' maintainers to re-test the patch set :(
if everything goes OK, then we can ask Petr to do the topic
branch (I don't have a kernel.org account).
-ss