Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zpoline nommu #1

Draft
wants to merge 14 commits into
base: uml-next
Choose a base branch
from
Draft

zpoline nommu #1

wants to merge 14 commits into from

Conversation

thehajime
Copy link
Owner

No description provided.

arch/um/include/asm/mmu.h Outdated Show resolved Hide resolved
arch/um/include/asm/tlbflush.h Outdated Show resolved Hide resolved
arch/x86/um/zpoline.c Outdated Show resolved Hide resolved
arch/x86/um/zpoline.c Outdated Show resolved Hide resolved
arch/x86/um/zpoline.c Outdated Show resolved Hide resolved
arch/x86/um/syscalls_64.c Outdated Show resolved Hide resolved
tools/testing/selftests/vDSO/Makefile Outdated Show resolved Hide resolved
arch/x86/um/syscalls_64.c Outdated Show resolved Hide resolved
arch/x86/um/Makefile Show resolved Hide resolved
@thehajime thehajime force-pushed the zpoline-nommu-v6.10 branch 19 times, most recently from 9b86626 to a754e79 Compare September 17, 2024 10:28
arch/x86/um/do_syscall_64.c Show resolved Hide resolved
arch/x86/um/do_syscall_64.c Show resolved Hide resolved
arch/x86/um/entry_64.S Show resolved Hide resolved
arch/x86/um/asm/elf.h Show resolved Hide resolved
arch/x86/um/zpoline.c Outdated Show resolved Hide resolved
arch/x86/um/zpoline.c Outdated Show resolved Hide resolved
@thehajime thehajime force-pushed the zpoline-nommu-v6.10 branch 2 times, most recently from 90042db to 3496039 Compare September 18, 2024 06:18
@thehajime thehajime changed the title Zpoline nommu v6.10 zpoline nommu Sep 18, 2024
@thehajime thehajime force-pushed the zpoline-nommu-v6.10 branch 2 times, most recently from 3e8124f to ddc2ef9 Compare September 19, 2024 05:17
@thehajime
Copy link
Owner Author

thehajime commented Sep 21, 2024

for the record:

lmbench (usec)

native um um-nommu
select-10 0.2584 28.7245 0.2751
select-100 0.7548 31.3977 0.9887
select-1000 5.7399 60.8596 8.4134
syscall 0.0806 11.4508 0.0780
read 0.1464 19.6901 0.1166
write 0.1110 27.3296 0.1140
stat 1.5114 46.2612 0.4372
open/close 283.9560 101.4579 0.7859
fork+sh 3539.0000 15725.0000 38561.0000
fork+execve 1679.5714 5462.0000 9611.0000

do_getpid bench (nsec)

native um um-nommu
getpid 117 24733 83

image

Repository owner deleted a comment from github-actions bot Nov 12, 2024
Repository owner deleted a comment from github-actions bot Nov 12, 2024
Repository owner deleted a comment from github-actions bot Nov 12, 2024
FDPIC ELF loader adds an architecture hook at the end of loading
binaries to finalize the mapped memory before moving toward exec
function.  The hook is used by UML under !MMU when translating
syscall/sysenter instructions before calling execve.

Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Kees Cook <kees@kernel.org>
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-mm@kvack.org
Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
As UML supports CONFIG_MMU=n case, it has to use an alternate ELF
loader, FDPIC ELF loader.  In this commit, we added necessary
definitions in the arch, as UML has not been used so far.  It also
updates Kconfig file to use BINFMT_ELF_FDPIC under !MMU environment.

Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: linux-mm@kvack.org
Cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
Signed-off-by: Ricardo Koller <ricarkol@google.com>
This commit adds memory operations on UML under !MMU environment.

Some part of the original UML code relying on CONFIG_MMU are excluded
from compilation when !CONFIG_MMU.  Additionally, generic functions such as
uaccess, futex, memcpy/strnlen/strncpy can be used as user- and
kernel-space share the address space in !CONFIG_MMU mode.

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
Signed-off-by: Ricardo Koller <ricarkol@google.com>
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 <thehajime@gmail.com>
Signed-off-by: Ricardo Koller <ricarkol@google.com>
This commit adds a mechanism to hook syscalls for unmodified userspace
programs used under UML in !MMU mode. The mechanism, called zpoline,
translates syscall/sysenter instructions with `call *%rax`, which can be
processed by a trampoline code also installed upon an initcall during
boot. The translation is triggered by elf_arch_finalize_exec(), an arch
hook introduced by another commit.

All syscalls issued by userspace thus redirected to a specific function,
__kernel_vsyscall, introduced as a syscall entry point for !MMU UML.  This
totally changes the code path to hook syscall with ptrace(2) used by
MMU-full UML.

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
As syscall translation done by zpoline assumes that there are no direct
syscalls issued by userspace code, but there would be possibly issued by
1) dlopen-ed code containing syscall instructions, or 2) JIT-generated
code.  This commit add a seccomp filter to prevent such syscalls from
userspace code.

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
Since ptrace facility isn't used under !MMU of UML, there is different
code path to invoke processes/threads; on an entry to the syscall
interface, the stack pointer should be manipulated to handle vfork(2)
return address, no external process is used, and need to properly
configure some of registers (fs segment register for TLS, etc) on every
context switch, etc.

Signals aren't delivered in non-ptrace syscall entry/leave so, we also
need to handle pending signal by ourselves.

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
Signed-off-by: Ricardo Koller <ricarkol@google.com>
As userspace on UML/!MMU also need to configure %fs register when it is
running to correctly access thread structure, host syscalls implemented
in os-Linux drivers may be puzzled when they are called.  Thus it has to
configure %fs register via arch_prctl(SET_FS) on every host syscalls.

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
Signed-off-by: Ricardo Koller <ricarkol@google.com>
On !MMU mode, the address of vdso is accessible from userspace.  This
commit implements the entry point by pointing a block of page address.

This commit also add memory permission configuration of vdso page to be
executable.

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
Signed-off-by: Ricardo Koller <ricarkol@google.com>
This commit updates the behavior of signal handling under !MMU
environment. 1) the stack preparation for the signal handlers and
2) restoration of stack after rt_sigreturn(2) syscall.  Those are needed
as the stack usage on vfork(2) syscall is different.

It also adds the follow up routine for SIGSEGV as a signal delivery runs
in the same stack frame while we have to avoid endless SIGSEGV.

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
This commit tries to display MMU/!MMU mode from the output of uname(2)
so that users can distinguish which mode of UML is running right now.

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
This commit adds an initial documentation for !MMU mode of UML.

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
Add nommu kernel for um build.  defconfig is also provided.

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
Signed-off-by: Ricardo Koller <ricarkol@google.com>
Repository owner deleted a comment from github-actions bot Nov 13, 2024
@thehajime thehajime force-pushed the zpoline-nommu-v6.10 branch 4 times, most recently from 31736aa to df6df43 Compare November 13, 2024 05:37
Repository owner deleted a comment from github-actions bot Nov 13, 2024
Repository owner deleted a comment from github-actions bot Nov 13, 2024
Copy link

lmbench (usec)

native um um-nommu
select-10 0.5565 30.2530 0.2780
select-100 2.3874 27.1509 1.0883
select-1000 20.7721 35.9023 9.1076
syscall 0.1736 25.5674 0.0999
read 0.3432 27.2637 0.1353
write 0.2862 27.3502 0.1355
stat 1.9310 38.2341 0.4677
open/close 3.8225 63.9635 0.7399
fork+sh 1171.4444 5283.5000 20640.0000
fork+execve 543.3000 2125.2000 4949.0000

do_getpid bench (nsec)

native um um-nommu
getpid 172 27177 106

Imgur Images

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uml + veth for docker
1 participant