* [PATCH] m68k: Define the m68k-specific syscalls with SYSCALL_DEFINE
@ 2026-11-24 2:55 Daniel Palmer
2026-11-24 3:45 ` Daniel Palmer
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Palmer @ 2026-11-24 2:55 UTC (permalink / raw)
To: geert, gerg, linux-m68k; +Cc: linux-kernel, arnd, Daniel Palmer
On m68k a syscall handler's stack arguments are the user's registers
saved in pt_regs, and RESTORE_ALL reloads them on the way out. The C
ABI lets a function reuse its incoming argument slots, so anything the
handler writes there ends up in user space. SYSCALL_DEFINEn() stops
the compiler doing that with asmlinkage_protect(), but sys_mmap2() and
the other m68k-specific syscalls are plain asmlinkage functions.
With GCC 16 and a kernel built with -O2, sys_mmap2() becomes a tail
call to ksys_mmap_pgoff(), which builds its call to vm_mmap_pgoff() by
shifting its arguments up one slot in place. User space gets d2-d5
back holding addr/len/prot/flags.
This issue was noticed in nolibc programs that are using mmap() and
I initially thought nolibc's m68k support was to blame.
Define sys_mmap2(), sys_cacheflush(), sys_atomic_cmpxchg_32() and
sys_set_thread_area() with SYSCALL_DEFINEn() so their arguments are
protected, and make their prototypes in asm/syscalls.h return long to
match.
Fixes: a90f590a1bee ("mm: add ksys_mmap_pgoff() helper; remove in-kernel calls to sys_mmap_pgoff()")
Signed-off-by: Daniel Palmer <daniel@0x0f.com>
---
I think this is right, I've tested it on real 030, 040 and 060 machines.
I found this issue making DRM/KMS programs with nolibc. Since I wrote the m68k
support for nolibc I suspected I had missed some ABI thing and messed it up and
I put a local workaround in there. Then the issue started showing up a normal libc.
I fixed the sys_mmap2() place by stepping through the kernel in QEMU and working
out who was messing up the registers. My fix worked but I wasn't sure why
there was an issue to start with so I asked my clanker and it disassembled the
kernel and explained the tail-call thing in the commit message.
arch/m68k/include/asm/syscalls.h | 10 +++++-----
arch/m68k/kernel/sys_m68k.c | 26 ++++++++++++--------------
2 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/arch/m68k/include/asm/syscalls.h b/arch/m68k/include/asm/syscalls.h
index fb3639acd07b..f317b35d6970 100644
--- a/arch/m68k/include/asm/syscalls.h
+++ b/arch/m68k/include/asm/syscalls.h
@@ -5,13 +5,13 @@
#include <linux/compiler_types.h>
#include <linux/linkage.h>
-asmlinkage int sys_cacheflush(unsigned long addr, int scope, int cache,
- unsigned long len);
-asmlinkage int sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3,
- int d4, int d5, unsigned long __user *mem);
+asmlinkage long sys_cacheflush(unsigned long addr, int scope, int cache,
+ unsigned long len);
+asmlinkage long sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3,
+ int d4, int d5, unsigned long __user *mem);
asmlinkage int sys_getpagesize(void);
asmlinkage unsigned long sys_get_thread_area(void);
-asmlinkage int sys_set_thread_area(unsigned long tp);
+asmlinkage long sys_set_thread_area(unsigned long tp);
asmlinkage int sys_atomic_barrier(void);
#include <asm-generic/syscalls.h>
diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c
index 1af5e6082467..9e6d38e57495 100644
--- a/arch/m68k/kernel/sys_m68k.c
+++ b/arch/m68k/kernel/sys_m68k.c
@@ -37,9 +37,9 @@
#include "../mm/fault.h"
-asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
- unsigned long prot, unsigned long flags,
- unsigned long fd, unsigned long pgoff)
+SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
+ unsigned long, prot, unsigned long, flags,
+ unsigned long, fd, unsigned long, pgoff)
{
/*
* This is wrong for sun3 - there PAGE_SIZE is 8Kb,
@@ -374,8 +374,8 @@ cache_flush_060 (unsigned long addr, int scope, int cache, unsigned long len)
}
/* sys_cacheflush -- flush (part of) the processor cache. */
-asmlinkage int
-sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
+SYSCALL_DEFINE4(cacheflush, unsigned long, addr, int, scope, int, cache,
+ unsigned long, len)
{
int ret = -EINVAL;
@@ -459,9 +459,8 @@ sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
/* This syscall gets its arguments in A0 (mem), D2 (oldval) and
D1 (newval). */
-asmlinkage int
-sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,
- unsigned long __user * mem)
+SYSCALL_DEFINE6(atomic_cmpxchg_32, unsigned long, newval, int, oldval,
+ int, d3, int, d4, int, d5, unsigned long __user *, mem)
{
/* This was borrowed from ARM's implementation. */
for (;;) {
@@ -533,8 +532,8 @@ sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,
#else
/* sys_cacheflush -- flush (part of) the processor cache. */
-asmlinkage int
-sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
+SYSCALL_DEFINE4(cacheflush, unsigned long, addr, int, scope, int, cache,
+ unsigned long, len)
{
flush_cache_all();
return 0;
@@ -542,9 +541,8 @@ sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
/* This syscall gets its arguments in A0 (mem), D2 (oldval) and
D1 (newval). */
-asmlinkage int
-sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,
- unsigned long __user * mem)
+SYSCALL_DEFINE6(atomic_cmpxchg_32, unsigned long, newval, int, oldval,
+ int, d3, int, d4, int, d5, unsigned long __user *, mem)
{
struct mm_struct *mm = current->mm;
unsigned long mem_value;
@@ -571,7 +569,7 @@ asmlinkage unsigned long sys_get_thread_area(void)
return current_thread_info()->tp_value;
}
-asmlinkage int sys_set_thread_area(unsigned long tp)
+SYSCALL_DEFINE1(set_thread_area, unsigned long, tp)
{
current_thread_info()->tp_value = tp;
return 0;
--
2.55.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] m68k: Define the m68k-specific syscalls with SYSCALL_DEFINE
2026-11-24 2:55 [PATCH] m68k: Define the m68k-specific syscalls with SYSCALL_DEFINE Daniel Palmer
@ 2026-11-24 3:45 ` Daniel Palmer
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Palmer @ 2026-11-24 3:45 UTC (permalink / raw)
To: geert, gerg, linux-m68k; +Cc: linux-kernel, arnd
Replying to myself..
On Tue, 24 Nov 2026 at 11:56, Daniel Palmer <daniel@0x0f.com> wrote:
>sys_atomic_cmpxchg_32()
Sashiko reports that this got broken because it can't use its trick
for getting pt_regs now that it's wrapped.
I'll send a v2 with this fix at some point:
--- a/arch/m68k/kernel/sys_m68k.c
+++ b/arch/m68k/kernel/sys_m68k.c
@@ -514,12 +514,8 @@ SYSCALL_DEFINE6(atomic_cmpxchg_32, unsigned long,
newval, int, oldval,
Make the kernel do the necessary page stuff, then re-iterate.
Simulate a write access fault to do that. */
{
- /* The first argument of the function corresponds to
- D1, which is the first field of struct pt_regs. */
- struct pt_regs *fp = (struct pt_regs *)&newval;
-
/* '3' is an RMW flag. */
- if (do_page_fault(fp, (unsigned long)mem, 3))
+ if (do_page_fault(current_pt_regs(), (unsigned
long)mem, 3))
/* If the do_page_fault() failed, we don't
have anything meaningful to return.
There should be a SIGSEGV pending for
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-24 3:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 2:55 [PATCH] m68k: Define the m68k-specific syscalls with SYSCALL_DEFINE Daniel Palmer
2026-11-24 3:45 ` Daniel Palmer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®