From nobody Wed Apr 22 19:21:26 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4g18Gg2xWXz6b93v for ; Wed, 22 Apr 2026 19:21:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g18Gg1mFLz3Cj8 for ; Wed, 22 Apr 2026 19:21:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776885691; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TVma6qTpqSCZTlpJxqBM8riLHQXU55D6GeH27QPtxb4=; b=HnUXhqlxGC5N4tN+APiHdyIBx3XbTT5tlB/o4R/Kl3CCWPdQum2l3k0bnRaI+STeP7QqTO kiKz5WQRpORxNys4K/0DxWyYBTY0iVhz+M3JwyzT/JP2dTpxVfFOijQhrtR3g/ugOAkMLV rMz8iw2nlSK1yW/feN1YkGSKHgFeSpTZdv/jfw705qE5DwzOJHkwNUipfyAkkUqb/NGGg4 ZmZ6uyQ2RBLr8LYWTOQ4kNnis+npyAL7jT7Uix3DUrUVeXljhTbkFWn0hmtAEteJ7jOFTy OwJ3ok7RM3EDV2SQTfI8V60i63w1Xa9t02gVJeFntavsMYWt/jMt3L/1TO9mqg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776885691; a=rsa-sha256; cv=none; b=d3ppY+tojeSbRT3YBY6MLSBFJQPsQcUuaR+b0XN2YX76IR1lJzd/wlUbm2+hYGjpJK+TPo o4SRmZdnSEWriVysubZw7XGH3O2DaLosg9RJEo6aOkI0N18quL2pOA4KUObXS4N9+9CIfR UJ9geCTW4hnji6TFJPYsWLz/+MOGfaO/tdUptCyIfewB9M8v4dOCiz+lSH6kP7fodyyEHp 3uq3rODXVRB+/yGI3YS6AtCqjUqfY5fzAScqgACc3i8QirTmhZQbfK9Rp9xgovwYLpkYsT i9RM3911x9MojESXGOs7WD/bDTDtGV6EKGReoV/HbYln73nD9giYxk8Y2EZw4Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776885691; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TVma6qTpqSCZTlpJxqBM8riLHQXU55D6GeH27QPtxb4=; b=QL41M7nfBsMVhVnZnK7IKjcc40ap+Okm5D82GAUg/IOlNExWXYd29MhXIKATqzwSG7RNlZ y1T0f7Yae4Y14UzxAzjl5/uQ9TuGG6m/IBj3MBaM3WP5LQXC76nwUKfRXUgMSChyQ2TD/U q+beA4+lMhQ6Abncm2mF1F+ybDTw954TgGKzitVPqcpV1+Tzf2GG9pl/uFU2kFK/QcRYyQ F9k2FqUJDOY9M1uhpsBDvoF096mVJc4hv88CfMho0CBIY5xr7Ikm68kxiW/w5NwkzyJcBH C2kEGeKGbNOFaCnCRbHzBqRp7yeYqJfQzROmz6b+d35etiO6gGb03iQWAcdE/Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g18Gg1FC2zkJc for ; Wed, 22 Apr 2026 19:21:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1c2a7 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 22 Apr 2026 19:21:26 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Ricardo Branco From: Pouria Mousavizadeh Tehrani Subject: git: 1594fe0b1029 - main - linux: Add support for membarrier(2) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pouria X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1594fe0b1029f246b3a14c8b21637091968362aa Auto-Submitted: auto-generated Date: Wed, 22 Apr 2026 19:21:26 +0000 Message-Id: <69e91fb6.1c2a7.69fa18e8@gitrepo.freebsd.org> The branch main has been updated by pouria: URL: https://cgit.FreeBSD.org/src/commit/?id=1594fe0b1029f246b3a14c8b21637091968362aa commit 1594fe0b1029f246b3a14c8b21637091968362aa Author: Ricardo Branco AuthorDate: 2026-04-18 10:11:44 +0000 Commit: Pouria Mousavizadeh Tehrani CommitDate: 2026-04-22 19:15:30 +0000 linux: Add support for membarrier(2) FreeBSD has a native membarrier(2) syscall which is mostly compatible with Linux. This is a thin wrapper around kern_membarrier() that translates all available commands and flags. Also update the syscalls.master prototypes to match the Linux 5.10+ three-argument form. Pre-5.10 binaries using the two-argument form continue to work: cpu_id is only consulted for RSEQ commands, which FreeBSD does not support and which kern_membarrier() rejects with EINVAL, matching Linux semantics. Signed-off-by: Ricardo Branco PR: 281691 Reviewed by: kib, pouria Pull-Request: https://github.com/freebsd/freebsd-src/pull/2147 --- sys/amd64/linux/syscalls.master | 3 +- sys/amd64/linux32/syscalls.master | 3 +- sys/arm64/linux/syscalls.master | 3 +- sys/compat/linux/linux_dummy.c | 2 -- sys/compat/linux/linux_misc.c | 64 +++++++++++++++++++++++++++++++++++++++ sys/compat/linux/linux_misc.h | 16 ++++++++++ sys/i386/linux/syscalls.master | 3 +- 7 files changed, 88 insertions(+), 6 deletions(-) diff --git a/sys/amd64/linux/syscalls.master b/sys/amd64/linux/syscalls.master index 5e1394751ef6..b3bbd917c013 100644 --- a/sys/amd64/linux/syscalls.master +++ b/sys/amd64/linux/syscalls.master @@ -1976,7 +1976,8 @@ 324 AUE_NULL STD { int linux_membarrier( l_int cmd, - l_int flags + l_uint flags, + l_int cpu_id ); } ; Linux 4.4: diff --git a/sys/amd64/linux32/syscalls.master b/sys/amd64/linux32/syscalls.master index 7bd522a598e8..fab68854af03 100644 --- a/sys/amd64/linux32/syscalls.master +++ b/sys/amd64/linux32/syscalls.master @@ -2194,7 +2194,8 @@ 375 AUE_NULL STD { int linux_membarrier( l_int cmd, - l_int flags + l_uint flags, + l_int cpu_id ); } ; Linux 4.4: diff --git a/sys/arm64/linux/syscalls.master b/sys/arm64/linux/syscalls.master index 2babdcaf03bf..f4ab6f49c363 100644 --- a/sys/arm64/linux/syscalls.master +++ b/sys/arm64/linux/syscalls.master @@ -1655,7 +1655,8 @@ 283 AUE_NULL STD { int linux_membarrier( l_int cmd, - l_int flags + l_uint flags, + l_int cpu_id ); } 284 AUE_NULL STD { diff --git a/sys/compat/linux/linux_dummy.c b/sys/compat/linux/linux_dummy.c index 46f98f4da1eb..dfabf33eb8a6 100644 --- a/sys/compat/linux/linux_dummy.c +++ b/sys/compat/linux/linux_dummy.c @@ -106,8 +106,6 @@ DUMMY(bpf); DUMMY(execveat); /* Linux 4.2: */ DUMMY(userfaultfd); -/* Linux 4.3: */ -DUMMY(membarrier); /* Linux 4.4: */ DUMMY(mlock2); /* Linux 4.6: */ diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index 85088e8ed7ca..4c8ad669f03c 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -3115,4 +3116,67 @@ linux_kcmp(struct thread *td, struct linux_kcmp_args *args) args->idx)); } +int +linux_membarrier(struct thread *td, struct linux_membarrier_args *args) +{ + static const struct { + int linux_cmd; + int freebsd_cmd; + } cmds[] = { + { LINUX_MEMBARRIER_CMD_QUERY, + MEMBARRIER_CMD_QUERY }, + { LINUX_MEMBARRIER_CMD_GLOBAL, + MEMBARRIER_CMD_GLOBAL }, + { LINUX_MEMBARRIER_CMD_GLOBAL_EXPEDITED, + MEMBARRIER_CMD_GLOBAL_EXPEDITED }, + { LINUX_MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED, + MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED }, + { LINUX_MEMBARRIER_CMD_PRIVATE_EXPEDITED, + MEMBARRIER_CMD_PRIVATE_EXPEDITED }, + { LINUX_MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED, + MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED }, + { LINUX_MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE, + MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE }, + { LINUX_MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE, + MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE }, + { LINUX_MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ, + MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ }, + { LINUX_MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ, + MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ }, + { LINUX_MEMBARRIER_CMD_GET_REGISTRATIONS, + MEMBARRIER_CMD_GET_REGISTRATIONS }, + }; + int cmd, error, flags, i, mask; + + cmd = -1; + for (i = 0; i < nitems(cmds); i++) { + if (args->cmd == cmds[i].linux_cmd) { + cmd = cmds[i].freebsd_cmd; + break; + } + } + + if (cmd == -1 || (args->flags & ~LINUX_MEMBARRIER_CMD_FLAG_CPU) != 0) + return (EINVAL); + + flags = 0; + if ((args->flags & LINUX_MEMBARRIER_CMD_FLAG_CPU) != 0) + flags |= MEMBARRIER_CMD_FLAG_CPU; + + error = kern_membarrier(td, cmd, flags, args->cpu_id); + if (error != 0) + return (error); + + if (args->cmd == LINUX_MEMBARRIER_CMD_QUERY || + args->cmd == LINUX_MEMBARRIER_CMD_GET_REGISTRATIONS) { + mask = td->td_retval[0]; + td->td_retval[0] = 0; + for (i = 0; i < nitems(cmds); i++) + if ((mask & cmds[i].freebsd_cmd) != 0) + td->td_retval[0] |= cmds[i].linux_cmd; + } + + return (0); +} + MODULE_DEPEND(linux, mqueuefs, 1, 1, 1); diff --git a/sys/compat/linux/linux_misc.h b/sys/compat/linux/linux_misc.h index 269fb734a69a..2044f23f30ee 100644 --- a/sys/compat/linux/linux_misc.h +++ b/sys/compat/linux/linux_misc.h @@ -229,4 +229,20 @@ struct syscall_info { #define LINUX_KCMP_EPOLL_TFD 7 #define LINUX_KCMP_TYPES 8 +/* Linux membarrier commands from */ +#define LINUX_MEMBARRIER_CMD_QUERY 0 +#define LINUX_MEMBARRIER_CMD_GLOBAL (1 << 0) +#define LINUX_MEMBARRIER_CMD_GLOBAL_EXPEDITED (1 << 1) +#define LINUX_MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED (1 << 2) +#define LINUX_MEMBARRIER_CMD_PRIVATE_EXPEDITED (1 << 3) +#define LINUX_MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED (1 << 4) +#define LINUX_MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE (1 << 5) +#define LINUX_MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE (1 << 6) +#define LINUX_MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ (1 << 7) +#define LINUX_MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ (1 << 8) +#define LINUX_MEMBARRIER_CMD_GET_REGISTRATIONS (1 << 9) + +/* Linux membarrier flags from */ +#define LINUX_MEMBARRIER_CMD_FLAG_CPU (1 << 0) + #endif /* _LINUX_MISC_H_ */ diff --git a/sys/i386/linux/syscalls.master b/sys/i386/linux/syscalls.master index 2113ea51ac5d..b93f28acae14 100644 --- a/sys/i386/linux/syscalls.master +++ b/sys/i386/linux/syscalls.master @@ -2206,7 +2206,8 @@ 375 AUE_NULL STD { int linux_membarrier( l_int cmd, - l_int flags + l_uint flags, + l_int cpu_id ); } ; Linux 4.4: