From: Helge Deller <deller@kernel.org>
To: qemu-devel@nongnu.org
Cc: Weiwei Li <liwei1518@gmail.com>, Helge Deller <deller@gmx.de>,
qemu-riscv@nongnu.org, Palmer Dabbelt <palmer@dabbelt.com>,
Liu Zhiwei <zhiwei_liu@linux.alibaba.com>,
Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>,
Laurent Vivier <laurent@vivier.eu>,
Alistair Francis <alistair.francis@wdc.com>,
Chao Liu <chao.liu@processmission.com>,
Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Subject: [PULL 3/4] linux-user: implement mlock2(2) syscall
Date: Fri, 18 Sep 2026 22:29:46 +0200 [thread overview]
Message-ID: <20260918202947.5322-4-deller@kernel.org> (raw)
In-Reply-To: <20260918202947.5322-1-deller@kernel.org>
From: Michael Morrell <mmorrell@tachyum.com>
TARGET_NR_mlock2 is defined for every target's syscall table (it has
been available on all Linux architectures since it was added in
kernel 4.4), and linux-user/strace.list already has an entry for it,
but linux-user/syscall.c has no case handler for it. A guest mlock2()
call therefore falls through to the default case and gets -ENOSYS
instead of being emulated, on every target.
mlock2() differs from mlock() only by a third `flags` argument
(MLOCK_ONFAULT). Add TARGET_MLOCK_ONFAULT and a case that validates
the flags argument and forwards to the host mlock2(), mirroring the
existing TARGET_NR_mlock case immediately above it.
Signed-off-by: Michael Morrell <mmorrell@tachyum.com>
Signed-off-by: Helge Deller <deller@gmx.de>
---
linux-user/syscall.c | 9 +++++++++
linux-user/syscall_defs.h | 4 ++++
2 files changed, 13 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index cfa68dfbdb..9f454502cb 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11230,6 +11230,15 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
case TARGET_NR_mlock:
return get_errno(mlock(g2h(cpu, arg1), arg2));
#endif
+#ifdef TARGET_NR_mlock2
+ case TARGET_NR_mlock2:
+ if (arg3 & ~TARGET_MLOCK_ONFAULT) {
+ return -TARGET_EINVAL;
+ }
+ return get_errno(mlock2(g2h(cpu, arg1), arg2,
+ (arg3 & TARGET_MLOCK_ONFAULT) ?
+ MLOCK_ONFAULT : 0));
+#endif
#ifdef TARGET_NR_munlock
case TARGET_NR_munlock:
return get_errno(munlock(g2h(cpu, arg1), arg2));
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index e28853c93b..f5831a6bad 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2795,6 +2795,10 @@ struct target_mount_attr_ver0 {
#ifndef RESOLVE_IN_ROOT
#define RESOLVE_IN_ROOT 0x10
#endif
+
+/* flags for mlock2() */
+#define TARGET_MLOCK_ONFAULT 0x01
+
#if (defined(TARGET_I386) && defined(TARGET_ABI32)) || \
(defined(TARGET_ARM) && defined(TARGET_ABI32)) || \
defined(TARGET_M68K) || defined(TARGET_MICROBLAZE) || \
--
2.54.0
next prev parent reply other threads:[~2026-09-18 20:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 20:29 [PULL 0/4] Linux user patches Helge Deller
2026-09-18 20:29 ` [PULL 1/4] linux-user/riscv: honor zicntr=false for base counterCSRs Helge Deller
2026-09-18 20:29 ` [PULL 2/4] linux-user/riscv: invalidate reservations after stores Helge Deller
2026-09-18 20:29 ` Helge Deller [this message]
2026-09-18 20:29 ` [PULL 4/4] linux-user/loongarch64: Detect vector stores in host_signal_write() Helge Deller
2026-09-19 20:41 ` [PULL 0/4] Linux user patches Richard Henderson
2026-09-21 6:54 ` Michael Tokarev
2026-09-21 12:37 ` Helge Deller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260918202947.5322-4-deller@kernel.org \
--to=deller@kernel.org \
--cc=alistair.francis@wdc.com \
--cc=chao.liu@processmission.com \
--cc=daniel.barboza@oss.qualcomm.com \
--cc=deller@gmx.de \
--cc=laurent@vivier.eu \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=zhiwei_liu@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.