Skip to content

Commit 8640de0

Browse files
rohanmclurempe
authored andcommitted
powerpc: Use common syscall handler type
Cause syscall handlers to be typed as follows when called indirectly throughout the kernel. This is to allow for better type checking. typedef long (*syscall_fn)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); Since both 32 and 64-bit abis allow for at least the first six machine-word length parameters to a function to be passed by registers, even handlers which admit fewer than six parameters may be viewed as having the above type. Coercing syscalls to syscall_fn requires a cast to void* to avoid -Wcast-function-type. Fixup comparisons in VDSO to avoid pointer-integer comparison. Introduce explicit cast on systems with SPUs. Signed-off-by: Rohan McLure <rmclure@linux.ibm.com> Reviewed-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20220921065605.1051927-19-rmclure@linux.ibm.com
1 parent 39859ae commit 8640de0

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

arch/powerpc/include/asm/syscall.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
#include <linux/sched.h>
1515
#include <linux/thread_info.h>
1616

17+
typedef long (*syscall_fn)(unsigned long, unsigned long, unsigned long,
18+
unsigned long, unsigned long, unsigned long);
19+
1720
/* ftrace syscalls requires exporting the sys_call_table */
18-
extern const unsigned long sys_call_table[];
19-
extern const unsigned long compat_sys_call_table[];
21+
extern const syscall_fn sys_call_table[];
22+
extern const syscall_fn compat_sys_call_table[];
2023

2124
static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
2225
{

arch/powerpc/include/asm/syscalls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/types.h>
99
#include <linux/compat.h>
1010

11+
#include <asm/syscall.h>
1112
#ifdef CONFIG_PPC64
1213
#include <asm/syscalls_32.h>
1314
#endif

arch/powerpc/kernel/syscall.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <asm/unistd.h>
1313

1414

15-
typedef long (*syscall_fn)(long, long, long, long, long, long);
16-
1715
/* Has to run notrace because it is entered not completely "reconciled" */
1816
notrace long system_call_exception(long r3, long r4, long r5,
1917
long r6, long r7, long r8,

arch/powerpc/kernel/systbl.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@
1616
#include <asm/syscalls.h>
1717

1818
#define __SYSCALL_WITH_COMPAT(nr, entry, compat) __SYSCALL(nr, entry)
19-
#define __SYSCALL(nr, entry) [nr] = (unsigned long) &entry,
2019

21-
const unsigned long sys_call_table[] = {
20+
/*
21+
* Coerce syscall handlers with arbitrary parameters to common type
22+
* requires cast to void* to avoid -Wcast-function-type.
23+
*/
24+
#define __SYSCALL(nr, entry) [nr] = (void *) entry,
25+
26+
const syscall_fn sys_call_table[] = {
2227
#ifdef CONFIG_PPC64
2328
#include <asm/syscall_table_64.h>
2429
#else
@@ -29,7 +34,7 @@ const unsigned long sys_call_table[] = {
2934
#ifdef CONFIG_COMPAT
3035
#undef __SYSCALL_WITH_COMPAT
3136
#define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, compat)
32-
const unsigned long compat_sys_call_table[] = {
37+
const syscall_fn compat_sys_call_table[] = {
3338
#include <asm/syscall_table_32.h>
3439
};
3540
#endif /* CONFIG_COMPAT */

arch/powerpc/kernel/vdso.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ static void __init vdso_setup_syscall_map(void)
304304
unsigned int i;
305305

306306
for (i = 0; i < NR_syscalls; i++) {
307-
if (sys_call_table[i] != (unsigned long)&sys_ni_syscall)
307+
if (sys_call_table[i] != (void *)&sys_ni_syscall)
308308
vdso_data->syscall_map[i >> 5] |= 0x80000000UL >> (i & 0x1f);
309309
if (IS_ENABLED(CONFIG_COMPAT) &&
310-
compat_sys_call_table[i] != (unsigned long)&sys_ni_syscall)
310+
compat_sys_call_table[i] != (void *)&sys_ni_syscall)
311311
vdso_data->compat_syscall_map[i >> 5] |= 0x80000000UL >> (i & 0x1f);
312312
}
313313
}

arch/powerpc/platforms/cell/spu_callbacks.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@
3434
* mbind, mq_open, ipc, ...
3535
*/
3636

37-
static void *spu_syscall_table[] = {
37+
static const syscall_fn spu_syscall_table[] = {
3838
#define __SYSCALL_WITH_COMPAT(nr, entry, compat) __SYSCALL(nr, entry)
39-
#define __SYSCALL(nr, entry) [nr] = entry,
39+
#define __SYSCALL(nr, entry) [nr] = (void *) entry,
4040
#include <asm/syscall_table_spu.h>
4141
};
4242

4343
long spu_sys_callback(struct spu_syscall_block *s)
4444
{
45-
long (*syscall)(u64 a1, u64 a2, u64 a3, u64 a4, u64 a5, u64 a6);
45+
syscall_fn syscall;
4646

4747
if (s->nr_ret >= ARRAY_SIZE(spu_syscall_table)) {
4848
pr_debug("%s: invalid syscall #%lld", __func__, s->nr_ret);

0 commit comments

Comments
 (0)