Skip to content

Commit deac93d

Browse files
James Bottomleytorvalds
authored andcommitted
lib: Correct printk %pF to work on all architectures
It was introduced by "vsprintf: add support for '%pS' and '%pF' pointer formats" in commit 0fe1ef2. However, the current way its coded doesn't work on parisc64. For two reasons: 1) parisc isn't in the #ifdef and 2) parisc has a different format for function descriptors Make dereference_function_descriptor() more accommodating by allowing architecture overrides. I put the three overrides (for parisc64, ppc64 and ia64) in arch/kernel/module.c because that's where the kernel internal linker which knows how to deal with function descriptors sits. Signed-off-by: James Bottomley <[email protected]> Acked-by: Benjamin Herrenschmidt <[email protected]> Acked-by: Tony Luck <[email protected]> Acked-by: Kyle McMartin <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7ae115b commit deac93d

File tree

8 files changed

+56
-11
lines changed

8 files changed

+56
-11
lines changed

arch/ia64/include/asm/sections.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ extern char __start_gate_brl_fsys_bubble_down_patchlist[], __end_gate_brl_fsys_b
2121
extern char __start_unwind[], __end_unwind[];
2222
extern char __start_ivt_text[], __end_ivt_text[];
2323

24+
#undef dereference_function_descriptor
25+
void *dereference_function_descriptor(void *);
26+
2427
#endif /* _ASM_IA64_SECTIONS_H */
2528

arch/ia64/kernel/module.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
#include <linux/elf.h>
3232
#include <linux/moduleloader.h>
3333
#include <linux/string.h>
34+
#include <linux/uaccess.h>
3435
#include <linux/vmalloc.h>
3536

3637
#include <asm/patch.h>
38+
#include <asm/sections.h>
3739
#include <asm/unaligned.h>
3840

3941
#define ARCH_MODULE_DEBUG 0
@@ -941,3 +943,13 @@ module_arch_cleanup (struct module *mod)
941943
if (mod->arch.core_unw_table)
942944
unw_remove_unwind_table(mod->arch.core_unw_table);
943945
}
946+
947+
void *dereference_function_descriptor(void *ptr)
948+
{
949+
struct fdesc *desc = ptr;
950+
void *p;
951+
952+
if (!probe_kernel_address(&desc->ip, p))
953+
ptr = p;
954+
return ptr;
955+
}

arch/parisc/kernel/module.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
#include <linux/string.h>
4848
#include <linux/kernel.h>
4949
#include <linux/bug.h>
50+
#include <linux/uaccess.h>
5051

52+
#include <asm/sections.h>
5153
#include <asm/unwind.h>
5254

5355
#if 0
@@ -860,3 +862,15 @@ void module_arch_cleanup(struct module *mod)
860862
deregister_unwind_table(mod);
861863
module_bug_cleanup(mod);
862864
}
865+
866+
#ifdef CONFIG_64BIT
867+
void *dereference_function_descriptor(void *ptr)
868+
{
869+
Elf64_Fdesc *desc = ptr;
870+
void *p;
871+
872+
if (!probe_kernel_address(&desc->addr, p))
873+
ptr = p;
874+
return ptr;
875+
}
876+
#endif

arch/powerpc/include/asm/sections.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ static inline int in_kernel_text(unsigned long addr)
1616
return 0;
1717
}
1818

19+
#undef dereference_function_descriptor
20+
void *dereference_function_descriptor(void *);
21+
1922
#endif
2023

2124
#endif /* __KERNEL__ */

arch/powerpc/kernel/module_64.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
#include <linux/err.h>
2222
#include <linux/vmalloc.h>
2323
#include <linux/bug.h>
24+
#include <linux/uaccess.h>
2425
#include <asm/module.h>
25-
#include <asm/uaccess.h>
26+
#include <asm/sections.h>
2627
#include <asm/firmware.h>
2728
#include <asm/code-patching.h>
2829
#include <linux/sort.h>
@@ -451,3 +452,13 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
451452

452453
return 0;
453454
}
455+
456+
void *dereference_function_descriptor(void *ptr)
457+
{
458+
struct ppc64_opd_entry *desc = ptr;
459+
void *p;
460+
461+
if (!probe_kernel_address(&desc->funcaddr, p))
462+
ptr = p;
463+
return ptr;
464+
}

include/asm-generic/sections.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ extern char __kprobes_text_start[], __kprobes_text_end[];
1414
extern char __initdata_begin[], __initdata_end[];
1515
extern char __start_rodata[], __end_rodata[];
1616

17+
/* function descriptor handling (if any). Override
18+
* in asm/sections.h */
19+
#ifndef dereference_function_descriptor
20+
#define dereference_function_descriptor(p) (p)
21+
#endif
22+
1723
#endif /* _ASM_GENERIC_SECTIONS_H_ */

include/asm-parisc/sections.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
/* nothing to see, move along */
55
#include <asm-generic/sections.h>
66

7+
#ifdef CONFIG_64BIT
8+
#undef dereference_function_descriptor
9+
void *dereference_function_descriptor(void *);
10+
#endif
11+
712
#endif

lib/vsprintf.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include <asm/page.h> /* for PAGE_SIZE */
2929
#include <asm/div64.h>
30+
#include <asm/sections.h> /* for dereference_function_descriptor() */
3031

3132
/* Works only for digits and letters, but small and fast */
3233
#define TOLOWER(x) ((x) | 0x20)
@@ -513,16 +514,6 @@ static char *string(char *buf, char *end, char *s, int field_width, int precisio
513514
return buf;
514515
}
515516

516-
static inline void *dereference_function_descriptor(void *ptr)
517-
{
518-
#if defined(CONFIG_IA64) || defined(CONFIG_PPC64)
519-
void *p;
520-
if (!probe_kernel_address(ptr, p))
521-
ptr = p;
522-
#endif
523-
return ptr;
524-
}
525-
526517
static char *symbol_string(char *buf, char *end, void *ptr, int field_width, int precision, int flags)
527518
{
528519
unsigned long value = (unsigned long) ptr;

0 commit comments

Comments
 (0)