From nobody Sun Feb 8 10:33:49 2026 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC8312C21EB for ; Wed, 4 Feb 2026 02:28:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172106; cv=none; b=iI7znrG5BXoYU2AT1JoyyUyP6lLH/EhxsEyKFjvz664wzLhvRzEOVc9Uh5gHEJfc/po8RKohAR18VcB7/r5j8A3lu1E49iUErUQS6kch81ZwgnBSKH8EjvDvyCOp09qFq4GtMpaej0uaKMaaE3sEKmMo+QxrYRoQZoGb0rWfOOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172106; c=relaxed/simple; bh=ohZr8TN+3EzzLa/zdEUa/3GcfCV2x/KsAaalXoHEw/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rKXm5BntwDDg9uNRfIpwR26R5+/AXK57zUXPMPrVVvvmxx1uJIESZYsn/rTf7wpAmyMSZuzR1GavLv/7OffblylrmQzYEzHIAiFfVH7T+qG5po3Kd8q25nG7BzedEV+zfOYRcxlQCmhmir0cswAXNg0h0ncDlbxPLxC9WZdOduI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JuG9pt+7; arc=none smtp.client-ip=209.85.215.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JuG9pt+7" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-c633984fbeeso157102a12.0 for ; Tue, 03 Feb 2026 18:28:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770172104; x=1770776904; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fo64Q14KD7RJjz3s47AhqXDA7DbhSnhy3sX7mHpz33g=; b=JuG9pt+7JIcztBlhXxsNiw+Q40BVAnQD1m60C2UED5yU+I4vkdw6xSqwxBuG5ljeGD 2KEUwwf+ER7nmkq2pg+xxQV7eIT3JzalmJHy/7HSEsWoEsKjPazpxfnixqFtgNfyeYp8 QcaKp/p5UD9OlIwoLMH8XfpSTi/ur6XfZmUZHNZn7b1wi09lHceNP3R5y4dPEEpqFoGQ KmZW6anYWjmVO/Wb0CNgpHMIYE/vRlJI0+Krn2rILkIWx0PAs9Lp1PZrcR53kz1IPqvF kxuph0Dv3YSno9x+iyXpS9LXMZnyceuXkF+6QolGApLd0M3KY+K7ujMMRU0Hzklmn5AY kQ4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770172104; x=1770776904; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=fo64Q14KD7RJjz3s47AhqXDA7DbhSnhy3sX7mHpz33g=; b=SoCzksXL1haHsV766M2+At6En1DLSKPNTYokG4zupWa0075r+SKFBQ9p7OlGmrvHpA UQITGtAGL8CMyN/l/l2V90c1VxHPm5BWXplgP5ntgIY/IAvAXHvel+l1WaYBJYknEWVx Px2a9vpIu71I0hYtcmdIHcbo7La1AIzTy0bPqZ8Cb4yhtjjbobFEjSmqTwqUfRm6Eyg6 3HTmAOqZifUu0ACd5h/soJ6/2FNomOn6we8kjvkcA0/mXN9ZoZP+FX+Q0+2bLgi6lgzV bxyzvmgKV90g/Eq1y0L6bUyb1iZHLQvm0iAeLg82fGwqIiEf7NjoXPso0GpP2qfARv0n hQhw== X-Forwarded-Encrypted: i=1; AJvYcCW0S0t0PH/bI+XH2VwewG6PiRCBl4RG/Ae4YgF7RDF/cR71NKSKeY5V4Ezu6IOXGfNJp1r0JogCU2V+e8k=@vger.kernel.org X-Gm-Message-State: AOJu0YwjgIiGwK0fVJ//Je41V+NC+d1m7fSjzqQwqujT/kUNZaxzhiKE BIKnahXYmIFGjn2bAfGDLo4A2zg3x0Wn9AGloxTIuDG9YQA9aj7iwyXT X-Gm-Gg: AZuq6aIzHIIf6nyeDgX4PpASPP/RJWwWFU+pLS+jHOE1Rzfy4Kji9gnazMAOf2abJ56 yV8sLBbv4PAy8/RlMdx86pi2CPA9Qed0e451dHHTY4Bl8aVzB1BHXdfHWhKNKyg29e5XWu1RJlO T6Vl6SMjIZl/swmqlsG2CNLOSSfiq4OsibWaDWuWCQXZTntonffklA3XI3dr6tqtm6T80paoeBB 3B14NYSrehcWMQ0LBJ4AASTqxQxvg67YZmK8pZS+hjovv+hRq1eE7aksiaF9hnyyRbOiav6wgv/ DOsQ4LLtORdndifzgelXdFg5MqcDSD00nsWwSl5thoRa8eIkKPm0AhuwPrbTdUaage3Fz1icRXx b0PpoW/uDfaGQoLy2BaKF43RtUCQS0dzCIJcA+8l7tEl1r5rkf4E+LTNE2e7DsreQOXb5oT1lsI He4X/YYsjpfv+tBoAFmvo4l2I8DF1ykcMq9QhcLBHyKI+smZ9CxtksvCNuN4bgB30QKJZprmWTP MfOVQhwEjxSxu+6 X-Received: by 2002:a17:90b:1c8d:b0:354:57eb:c826 with SMTP id 98e67ed59e1d1-35486bacb31mr1186796a91.2.1770172104122; Tue, 03 Feb 2026 18:28:24 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3548630dfa2sm900607a91.14.2026.02.03.18.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 18:28:22 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 705C11200C37; Wed, 4 Feb 2026 11:28:21 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v14 04/13] x86/um: nommu: syscall handling Date: Wed, 4 Feb 2026 11:28:02 +0900 Message-ID: <3208da96a38b9109acd031dd4fec54afd2721deb.1770170302.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit introduces an entry point of syscall interface for !MMU mode. It uses an entry function, __kernel_vsyscall, a kernel-wide global symbol accessible from any locations. Although it isn't in the scope of this commit, it can be also exposed via vdso image which is directly accessible from userspace. A standard library (i.e., libc) can utilize this entry point to implement syscall wrapper; we can also use this by hooking syscall for unmodified userspace applications/libraries, which will be implemented in the subsequent commit. This only supports 64-bit mode of x86 architecture. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/x86/um/Makefile | 4 ++ arch/x86/um/asm/syscall.h | 6 ++ arch/x86/um/nommu/Makefile | 8 +++ arch/x86/um/nommu/do_syscall_64.c | 32 +++++++++ arch/x86/um/nommu/entry_64.S | 112 ++++++++++++++++++++++++++++++ arch/x86/um/nommu/syscalls.h | 16 +++++ 6 files changed, 178 insertions(+) create mode 100644 arch/x86/um/nommu/Makefile create mode 100644 arch/x86/um/nommu/do_syscall_64.c create mode 100644 arch/x86/um/nommu/entry_64.S create mode 100644 arch/x86/um/nommu/syscalls.h diff --git a/arch/x86/um/Makefile b/arch/x86/um/Makefile index f9ea75bf43ac..39693807755a 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -31,6 +31,10 @@ obj-y +=3D mem_64.o syscalls_64.o vdso/ subarch-y =3D ../lib/csum-partial_64.o ../lib/memcpy_64.o \ ../lib/memmove_64.o ../lib/memset_64.o =20 +ifneq ($(CONFIG_MMU),y) +obj-y +=3D nommu/ +endif + endif =20 subarch-$(CONFIG_MODULES) +=3D ../kernel/module.o diff --git a/arch/x86/um/asm/syscall.h b/arch/x86/um/asm/syscall.h index d6208d0fad51..bb4f6f011667 100644 --- a/arch/x86/um/asm/syscall.h +++ b/arch/x86/um/asm/syscall.h @@ -20,4 +20,10 @@ static inline int syscall_get_arch(struct task_struct *t= ask) #endif } =20 +#ifndef CONFIG_MMU +extern void do_syscall_64(struct pt_regs *regs); +extern long __kernel_vsyscall(int64_t a0, int64_t a1, int64_t a2, int64_t = a3, + int64_t a4, int64_t a5, int64_t a6); +#endif + #endif /* __UM_ASM_SYSCALL_H */ diff --git a/arch/x86/um/nommu/Makefile b/arch/x86/um/nommu/Makefile new file mode 100644 index 000000000000..d72c63afffa5 --- /dev/null +++ b/arch/x86/um/nommu/Makefile @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +ifeq ($(CONFIG_X86_32),y) + BITS :=3D 32 +else + BITS :=3D 64 +endif + +obj-y =3D do_syscall_$(BITS).o entry_$(BITS).o diff --git a/arch/x86/um/nommu/do_syscall_64.c b/arch/x86/um/nommu/do_sysca= ll_64.c new file mode 100644 index 000000000000..292d7c578622 --- /dev/null +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include + +__visible void do_syscall_64(struct pt_regs *regs) +{ + int syscall; + + syscall =3D PT_SYSCALL_NR(regs->regs.gp); + UPT_SYSCALL_NR(®s->regs) =3D syscall; + + if (likely(syscall < NR_syscalls)) { + unsigned long ret; + + ret =3D (*sys_call_table[syscall])(UPT_SYSCALL_ARG1(®s->regs), + UPT_SYSCALL_ARG2(®s->regs), + UPT_SYSCALL_ARG3(®s->regs), + UPT_SYSCALL_ARG4(®s->regs), + UPT_SYSCALL_ARG5(®s->regs), + UPT_SYSCALL_ARG6(®s->regs)); + PT_REGS_SET_SYSCALL_RETURN(regs, ret); + } + + PT_REGS_SYSCALL_RET(regs) =3D regs->regs.gp[HOST_AX]; + + /* handle tasks and signals at the end */ + interrupt_end(); +} diff --git a/arch/x86/um/nommu/entry_64.S b/arch/x86/um/nommu/entry_64.S new file mode 100644 index 000000000000..485c578aae64 --- /dev/null +++ b/arch/x86/um/nommu/entry_64.S @@ -0,0 +1,112 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include + +#include +#include +#include + +#include "../entry/calling.h" + +#ifdef CONFIG_SMP +#error need to stash these variables somewhere else +#endif + +#define UM_GLOBAL_VAR(x) .data; .align 8; .globl x; x:; .long 0 + +UM_GLOBAL_VAR(current_top_of_stack) +UM_GLOBAL_VAR(current_ptregs) + +.code64 +.section .entry.text, "ax" + +.align 8 +#undef ENTRY +#define ENTRY(x) .text; .globl x; .type x,%function; x: +#undef END +#define END(x) .size x, . - x + +/* + * %rcx has the return address (we set it before entering __kernel_vsyscal= l). + * + * Registers on entry: + * rax system call number + * rcx return address + * rdi arg0 + * rsi arg1 + * rdx arg2 + * r10 arg3 + * r8 arg4 + * r9 arg5 + * + * (note: we are allowed to mess with r11: r11 is callee-clobbered + * register in C ABI) + */ +ENTRY(__kernel_vsyscall) + + movq %rsp, %r11 + + /* Point rsp to the top of the ptregs array, so we can + just fill it with a bunch of push'es. */ + movq current_ptregs, %rsp + + /* 8 bytes * 20 registers (plus 8 for the push) */ + addq $168, %rsp + + /* Construct struct pt_regs on stack */ + pushq $0 /* pt_regs->ss (index 20) */ + pushq %r11 /* pt_regs->sp */ + pushfq /* pt_regs->flags */ + pushq $0 /* pt_regs->cs */ + pushq %rcx /* pt_regs->ip */ + pushq %rax /* pt_regs->orig_ax */ + + PUSH_AND_CLEAR_REGS rax=3D$-ENOSYS + + mov %rsp, %rdi + + /* + * Switch to current top of stack, so "current->" points + * to the right task. + */ + movq current_top_of_stack, %rsp + + call do_syscall_64 + + jmp userspace + +END(__kernel_vsyscall) + +/* + * common userspace returning routine + * + * all procedures like syscalls, signal handlers, umh processes, will gate + * this routine to properly configure registers/stacks. + * + * void userspace(struct uml_pt_regs *regs) + */ +ENTRY(userspace) + + /* clear direction flag to meet ABI */ + cld + /* align the stack for x86_64 ABI */ + and $-0x10, %rsp + /* Handle any immediate reschedules or signals */ + call interrupt_end + + movq current_ptregs, %rsp + + POP_REGS + + addq $8, %rsp /* skip orig_ax */ + popq %rcx /* pt_regs->ip */ + addq $8, %rsp /* skip cs */ + addq $8, %rsp /* skip flags */ + popq %rsp + + /* + * not return w/ ret but w/ jmp as the stack is already popped before + * entering __kernel_vsyscall + */ + jmp *%rcx + +END(userspace) diff --git a/arch/x86/um/nommu/syscalls.h b/arch/x86/um/nommu/syscalls.h new file mode 100644 index 000000000000..a2433756b1fc --- /dev/null +++ b/arch/x86/um/nommu/syscalls.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_SYSCALLS_H +#define __UM_NOMMU_SYSCALLS_H + + +#define task_top_of_stack(task) \ +({ \ + unsigned long __ptr =3D (unsigned long)task->stack; \ + __ptr +=3D THREAD_SIZE; \ + __ptr; \ +}) + +extern long current_top_of_stack; +extern long current_ptregs; + +#endif --=20 2.43.0