Unifying LKL into UML
Subsystems (10)
RFC v5 12/21 um: nommu: system call interface and application API
In reply to Hajime TazakiThe application API is based on the kernel system call interface in order to offer a stable API to applications. Note that we can't offer the full Linux system call interface due to the limitations of nommu mode such as lack of virtual memory, signal, user processes, etc.
The host is using dedicated kernel thread, which is switched upon the entry of lkl_syscall so that numbers of context switches can be reduced for the faster performance.
To expose the API definitions to applications, this commit uses syscall_wrapper to define arch-specific information of syscall, and this is used to generate syscall_defs.h for lkl so that it can be used as a template of the list of syscall available for LKL apps.
To avoid collisions between the Linux API and the LKL API (e.g. struct stat, MKNOD, etc.) we use a python script to modify the user headers and to prefix all of the global symbols (structures, typedefs, defines) with LKL, lkl, _LKL, _lkl, __LKL or __lkl.
--- arch/um/include/uapi/asm/Kbuild | 2 + arch/um/nommu/include/asm/syscall_wrapper.h | 57 ++++ arch/um/nommu/include/asm/syscalls.h | 15 + arch/um/nommu/include/uapi/asm/host_ops.h | 14 + arch/um/nommu/include/uapi/asm/syscalls.h | 287 ++++++++++++++++++++ arch/um/nommu/include/uapi/asm/unistd.h | 15 + arch/um/nommu/um/syscalls.c | 199 ++++++++++++++ arch/um/scripts/headers_install.py | 197 ++++++++++++++ 8 files changed, 786 insertions(+) create mode 100644 arch/um/include/uapi/asm/Kbuild create mode 100644 arch/um/nommu/include/asm/syscall_wrapper.h create mode 100644 arch/um/nommu/include/asm/syscalls.h create mode 100644 arch/um/nommu/include/uapi/asm/syscalls.h create mode 100644 arch/um/nommu/include/uapi/asm/unistd.h create mode 100644 arch/um/nommu/um/syscalls.c create mode 100755 arch/um/scripts/headers_install.py
arch/um/include/uapi/asm/Kbuild new file +2 -0
@@ -0,0 +1,2 @@ +# no generated-y since we need special user headers handling +# see arch/um/script/headers_install.py
arch/um/nommu/include/asm/syscall_wrapper.h new file +57 -0
57 lines not on this page · raw message
arch/um/nommu/include/asm/syscalls.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +int syscalls_init (void ); +void syscalls_cleanup (void ); +long lkl_syscall (long no,long *params); +void wakeup_idle_host_task (void ); + +#define sys_mmap sys_ni_syscall +#define sys_rt_sigreturn sys_ni_syscall +#define sys_arch_prctl sys_ni_syscall +#define sys_iopl sys_ni_syscall +#define sys_ioperm sys_ni_syscall +#define sys_clone sys_ni_syscall + +int run_syscalls (void );
arch/um/nommu/include/uapi/asm/host_ops.h +14 -0
@@ -38,6 +38,15 @@ struct lkl_jmp_buf {* @gettid - returns the host thread id of the caller, which need not * be the same as the handle returned by thread_create * +* @tls_alloc - allocate a thread local storage key; returns 0 if successful; if +* destructor is not NULL it will be called when a thread terminates with its +* argument set to the current thread local storage value +* @tls_free - frees a thread local storage key; returns 0 if successful +* @tls_set - associate data to the thread local storage key; returns 0 if +* successful +* @tls_get - return data associated with the thread local storage key or NULL +* on error +* * @jmp_buf_set - runs the give function and setups a jump back point by saving * the context in the jump buffer; jmp_buf_longjmp can be called from the give * function or any callee in that function to return back to the jump back
@@ -72,6 +81,11 @@ struct lkl_host_operations {int (*thread_equal)(lkl_thread_t a,lkl_thread_t b);long (*gettid)(void ); +struct lkl_tls_key *(*tls_alloc)(void (*destructor)(void *)); +void (*tls_free)(struct lkl_tls_key *key); +int (*tls_set)(struct lkl_tls_key *key,void *data); +void *(*tls_get)(struct lkl_tls_key *key); +void (*jmp_buf_set)(struct lkl_jmp_buf *jmpb,void (*f)(void ));void (*jmp_buf_longjmp)(struct lkl_jmp_buf *jmpb,int val);
arch/um/nommu/include/uapi/asm/syscalls.h new file +287 -0
287 lines not on this page · raw message
arch/um/nommu/include/uapi/asm/unistd.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __UM_NOMMU_UAPI_UNISTD_H +#define __UM_NOMMU_UAPI_UNISTD_H + +#define __ARCH_WANT_NEW_STAT +#include <asm/bitsperlong.h> + +#if __BITS_PER_LONG ==64 +#define __ARCH_WANT_SYS_NEWFSTATAT +#endif + +#include <asm-generic/unistd.h> + + +#endif
arch/um/nommu/um/syscalls.c new file +199 -0
199 lines not on this page · raw message
arch/um/scripts/headers_install.py new file +197 -0
197 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v5 13/21 um: nommu: basic console support
In reply to Hajime TazakiThis commit also disables stdio-console of UM if !CONFIG_MMU to avoid conflicts between multiple consoles.
--- arch/um/drivers/Makefile | 8 ++++- arch/um/nommu/include/uapi/asm/host_ops.h | 3 ++ arch/um/nommu/um/console.c | 42 +++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 arch/um/nommu/um/console.c
arch/um/drivers/Makefile +7 -1
@@ -37,7 +37,13 @@ $(obj)/vde.o: $(obj)/vde_kern.o $(obj)/vde_user.o # When the above is fixed, don't forget to add this too! #targets += $(obj)/pcap.o -obj-y := stdio_console.o fd.o chan_kern.o chan_user.o line.o +ifdef CONFIG_MMU +obj-y := stdio_console.o +else +obj-y := +endif +obj-y += fd.o chan_kern.o chan_user.o line.o + obj-$(CONFIG_SSL) += ssl.o obj-$(CONFIG_STDERR_CONSOLE) += stderr_console.o
arch/um/nommu/include/uapi/asm/host_ops.h +3 -0
@@ -15,6 +15,7 @@ struct lkl_jmp_buf {* * These operations must be provided by a host library or by the application * itself. +* @print - optional operation that receives console messages * * @sem_alloc - allocate a host semaphore an initialize it to count * @sem_free - free a host semaphore
@@ -63,6 +64,8 @@ struct lkl_jmp_buf {* */ struct lkl_host_operations { +void (*print)(const char *str,int len); +struct lkl_sem *(*sem_alloc)(int count);void (*sem_free)(struct lkl_sem *sem);void (*sem_up)(struct lkl_sem *sem);
arch/um/nommu/um/console.c new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v5 15/21 um: nommu: integrate with irq infrastructure of UML
In reply to Hajime TazakiIn order to cooperate with UML's irq infrastructure and nommu threads based on host threads, irq handlers shall synchronize the our scheduler which is controlled by struct lkl_cpu. To do that, the irq infra notifies its entry of handlers by obtaining cpu access of thread scheduler (lkl_cpu_try_run_irq) and its release (lkl_cpu_put).
In additon to that, in order to stick the signal handler's thread to the one of the idle thread, several required configurations of (thread's) signal mask are added: otherwise handlers running on arbitrary thread cannot obtain cpu access and immediately fall into pending interrupt which may slow down the delivery of signals.
--- arch/um/include/shared/os.h | 1 + arch/um/kernel/irq.c | 13 +++++++++++++ arch/um/kernel/time.c | 2 ++ arch/um/nommu/include/asm/cpu.h | 3 +++ arch/um/nommu/um/cpu.c | 17 ++++++++++++++--- arch/um/nommu/um/setup.c | 5 +++++ arch/um/nommu/um/threads.c | 3 +++ tools/um/uml/signal.c | 12 ++++++++++-- 8 files changed, 51 insertions(+), 5 deletions(-)
arch/um/include/shared/os.h +1 -0
@@ -241,6 +241,7 @@ extern int set_signals(int enable);extern int set_signals_trace (int enable);extern int os_is_signal_stack (void );extern void deliver_alarm (void ); +extern void set_pending_signals (int sig);/* util.c */ extern void stack_protections (unsigned long address);
arch/um/kernel/irq.c +13 -0
@@ -19,6 +19,7 @@#include <kern_util.h> #include <os.h> #include <irq_user.h> +#include <asm/cpu.h> extern void free_irqs (void );
@@ -541,6 +542,11 @@ unsigned long to_irq_stack(unsigned long *mask_out)unsigned long mask, old;int nested; +#ifndef CONFIG_MMU +if (!nommu_irq_enter (ffs (*mask_out) -1 )) +return 1 ; +#endif + mask =xchg (&pending_mask, *mask_out);if (mask !=0 ) {/*
@@ -557,6 +563,10 @@ unsigned long to_irq_stack(unsigned long *mask_out) old |= mask; mask =xchg (&pending_mask, old); }while (mask != old); + +#ifndef CONFIG_MMU +nommu_irq_exit (); +#endif return 1 ; }
@@ -594,6 +604,9 @@ unsigned long from_irq_stack(int nested) *to = *ti; mask =xchg (&pending_mask,0 ); +#ifndef CONFIG_MMU +nommu_irq_exit (); +#endif return mask & ~1 ; }
arch/um/kernel/time.c +2 -0
@@ -597,11 +597,13 @@ static struct clock_event_device timer_clockevent = {static irqreturn_t um_timer (int irq,void *dev) { +#ifdef CONFIG_MMU if (get_current ()->mm !=NULL ) {/* userspace - relay signal, results in correct userspace timers */ os_alarm_process (get_current ()->mm->context.id.u.pid); } +#endif (*timer_clockevent.event_handler)(&timer_clockevent);
arch/um/nommu/include/asm/cpu.h +3 -0
@@ -10,4 +10,7 @@ void lkl_cpu_wait_shutdown(void);void lkl_cpu_change_owner (lkl_thread_t owner);void lkl_cpu_set_irqs_pending (void ); +void nommu_irq_exit (void ); +int nommu_irq_enter (int sig); +#endif
arch/um/nommu/um/cpu.c +14 -3
@@ -8,15 +8,16 @@#include <asm/sched.h> #include <asm/syscalls.h> #include <init.h> +#include <os.h> void run_irqs (void ) { -panic ("unimplemented %s" , __func__); +unblock_signals (); } -int set_irq_pending (int irq) +void set_irq_pending (int sig) { -panic ("unimplemented %s" , __func__); +set_pending_signals (sig); }/*
@@ -174,6 +175,16 @@ int lkl_cpu_try_run_irq(int irq)return ret; } +int nommu_irq_enter (int sig) +{ +return lkl_cpu_try_run_irq (sig); +} + +void nommu_irq_exit (void ) +{ +return lkl_cpu_put (); +} +static void lkl_cpu_shutdown (void ) {__sync_fetch_and_add (&cpu.shutdown_gate,MAX_THREADS );
arch/um/nommu/um/setup.c +5 -0
@@ -36,6 +36,8 @@ static void __init *lkl_run_kernel(void *arg) panic_blink = lkl_panic_blink; +/* signal should be received at this thread (main and idle threads) */ +init_new_thread_signals ();threads_init ();lkl_cpu_get ();start_kernel ();
@@ -58,6 +60,9 @@ int __init lkl_start_kernel(struct lkl_host_operations *ops,if (ret) goto out_free_init_sem; +change_sig (SIGALRM ,0 ); +change_sig (SIGIO ,0 ); + ret = lkl_ops->thread_create (lkl_run_kernel,NULL );if (!ret) { ret = -ENOMEM ;
arch/um/nommu/um/threads.c +3 -0
@@ -151,6 +151,9 @@ static void *thread_bootstrap(void *_tba)int (*f)(void *) = tba->f;void *arg = tba->arg; +change_sig (SIGALRM ,0 ); +change_sig (SIGIO ,0 ); + lkl_ops->sem_down (ti->task->thread.arch.sched_sem);kfree (tba);if (ti->task->thread.prev_sched)
tools/um/uml/signal.c +10 -2
@@ -218,8 +218,8 @@ void set_handler(int sig)sigemptyset (&sig_mask);sigaddset (&sig_mask, sig); -if (sigprocmask (SIG_UNBLOCK , &sig_mask,NULL ) <0 ) -panic ("sigprocmask failed - errno = %d\n" , errno); +if (pthread_sigmask (SIG_UNBLOCK , &sig_mask,NULL ) <0 ) +panic ("pthread_sigmask failed - errno = %d\n" , errno); }int change_sig (int signal,int on)
@@ -355,3 +355,11 @@ int os_is_signal_stack(void)return ss.ss_flags &SS_ONSTACK ; } + +void set_pending_signals (int sig) +{ +if (sig ==SIGIO ) + signals_pending |=SIGIO_MASK ; +else if (sig ==SIGALRM ) + signals_pending |=SIGALRM_MASK ; +}
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v5 14/21 um: nommu: initialization and cleanup
In reply to Hajime TazakiAdd the lkl_start_kernel and lkl_sys_halt APIs that start and respectively stops the Linux kernel.
lkl_start_kernel creates a separate threads that will run the initial and idle kernel thread. It waits for the kernel to complete initialization before returning, to avoid races with system calls issues by the host application.
During the setup phase, we create "/init" in initial ramfs root filesystem to avoid mounting the "real" rootfs since ramfs is good enough for now.
lkl_sys_halt will shutdown the kernel, terminate all threads and free all host resources used by the kernel before returning.
--- arch/um/nommu/include/uapi/asm/host_ops.h | 14 ++ arch/um/nommu/um/setup.c | 161 ++++++++++++++++++++++ tools/um/uml/process.c | 2 + 3 files changed, 177 insertions(+) create mode 100644 arch/um/nommu/um/setup.c
arch/um/nommu/include/uapi/asm/host_ops.h +14 -0
@@ -16,6 +16,7 @@ struct lkl_jmp_buf {* These operations must be provided by a host library or by the application * itself. * @print - optional operation that receives console messages +* @panic - called during a kernel panic * * @sem_alloc - allocate a host semaphore an initialize it to count * @sem_free - free a host semaphore
@@ -65,6 +66,7 @@ struct lkl_jmp_buf {*/ struct lkl_host_operations {void (*print)(const char *str,int len); +void (*panic)(void );struct lkl_sem *(*sem_alloc)(int count);void (*sem_free)(struct lkl_sem *sem);
@@ -96,6 +98,18 @@ struct lkl_host_operations { void (*mem_free)(void *mem); }; +/** +* lkl_start_kernel - registers the host operations and starts the kernel +* +* The function returns only after the kernel is shutdown with lkl_sys_halt. +* +* @lkl_ops - pointer to host operations +* @cmd_line - format for command line string that is going to be used to +* generate the Linux kernel command line +*/ +int lkl_start_kernel (struct lkl_host_operations *ops, +const char *fmt, ...); +void lkl_bug (const char *fmt, ...);#endif
arch/um/nommu/um/setup.c new file +161 -0
161 lines not on this page · raw message
tools/um/uml/process.c +2 -0
@@ -114,6 +114,8 @@ void os_kill_process(int pid, int reap_child)void os_kill_ptraced_process (int pid,int reap_child) { +if (pid ==0 ) +return ;kill (pid,SIGKILL );ptrace (PTRACE_KILL , pid);ptrace (PTRACE_CONT , pid);
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v5 16/21 um: nommu: plug in the build system
In reply to Hajime TazakiBasic Makefiles for building library of nommu mode. Add a new architecture specific target for installing the resulting library files and headers.
To make nommu binaries build, UML introduced an additional option, UMMODE variable, to switch the output file of build: kernel (default), or library (nommu). Those modes are not able to be ON at the same time.
To build on library mode, users do the following:
make defconfig ARCH=um UMMODE=library
make ARCH=um UMMODE=library
--- arch/um/Kconfig | 17 ++++++++++++++--- arch/um/Makefile | 10 +++++++++- arch/um/kernel/Makefile | 12 ++++++++---- arch/um/nommu/um/Kconfig | 37 +++++++++++++++++++++++++++++++++++++ arch/um/nommu/um/Makefile | 4 ++++ 5 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 arch/um/nommu/um/Kconfig create mode 100644 arch/um/nommu/um/Makefile
arch/um/Kconfig +14 -3
@@ -22,9 +22,20 @@ config UML select TTY # Needed for line.c select MODULE_REL_CRCS if MODVERSIONS +config UMMODE_LIB + bool "UML mode: library mode" + default y if "$(UMMODE)" = "library" + help + This mode switches a mode to build a library of UML (Linux + Kernel Library/LKL). This switch is exclusive to "kernel mode" + of UML, which is traditional mode of UML. + + For more detail about LKL, see + <file:Documentation/virt/uml/lkl.txt>. + config MMU bool - default y + default y if !UMMODE_LIB config NO_IOMEM def_bool y
@@ -45,12 +56,12 @@ config LOCKDEP_SUPPORT config STACKTRACE_SUPPORT bool - default y + default y if MMU select STACKTRACE config GENERIC_CALIBRATE_DELAY bool - default y + default y if MMU config HZ int
arch/um/Makefile +9 -1
@@ -17,6 +17,10 @@ else KBUILD_DEFCONFIG := $(SUBARCH)_defconfig endif +ifeq ($(UMMODE),library) + SUBARCH := um/nommu +endif + ARCH_DIR := arch/um OS := $(shell uname -s) # We require bash because the vmlinux link and loader script cpp use bash
@@ -102,9 +106,13 @@ all: linux.o linux.o: vmlinux @echo ' LINK $@' - $(Q)$(OBJCOPY) -R .eh_frame $< $@ + $(Q)$(OBJCOPY) -R .eh_frame -L sem_init -L sem_post -L sem_wait -L sem_destroy $< $@ +ifeq ($(UMMODE),library) +install: linux.o um_headers_install +else install: linux.o +endif @echo " INSTALL $(INSTALL_PATH)/lib/$<" @mkdir -p $(INSTALL_PATH)/lib/ @cp $< $(INSTALL_PATH)/lib/
arch/um/kernel/Makefile +8 -4
@@ -14,10 +14,14 @@ CPPFLAGS_vmlinux.lds := -DSTART=$(LDS_START) \ $(LDS_EXTRA) extra-y := vmlinux.lds -obj-y = config.o exec.o exitcode.o irq.o ksyms.o mem.o \ - physmem.o process.o ptrace.o reboot.o sigio.o \ - signal.o syscall.o sysrq.o time.o tlb.o trap.o \ - um_arch.o umid.o maccess.o kmsg_dump.o skas/ +obj-y = config.o exitcode.o irq.o ksyms.o \ + process.o reboot.o sigio.o \ + signal.o syscall.o time.o \ + um_arch.o umid.o maccess.o kmsg_dump.o + +ifdef CONFIG_MMU +obj-y += exec.o mem.o physmem.o ptrace.o sysrq.o tlb.o trap.o skas/ +endif obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o obj-$(CONFIG_GPROF) += gprof_syms.o
arch/um/nommu/um/Kconfig new file +37 -0
@@ -0,0 +1,37 @@ +config UML_NOMMU + def_bool y + depends on !SMP && !MMU + select UACCESS_MEMCPY + select ARCH_THREAD_STACK_ALLOCATOR + select ARCH_HAS_SYSCALL_WRAPPER + +config 64BIT + bool + default y + +config GENERIC_CSUM + def_bool y + +config GENERIC_ATOMIC64 + bool + default y if !64BIT + +config SECCOMP + bool + default n + +config GENERIC_HWEIGHT + def_bool y + +config GENERIC_CALIBRATE_DELAY + bool + default n + +config STACKTRACE_SUPPORT + bool + default n + +# XXX: need this to work well with tap13.py +config PRINTK_TIME + bool + default y
arch/um/nommu/um/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +include/generated/user_constants.h: $(srctree)/arch/um/nommu/um/user_constants.h + $(Q)cp -f $^ $@ + +obj-y = bootmem.o console.o cpu.o delay.o setup.o syscalls.o threads.o unimplemented.o
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v5 17/21 um: host: add nommu build for ARCH=um
In reply to Hajime TazakiThis patch adds the skeleton for the host library.
The host library is implementing the host operations needed by nommu mode and is split into host dependent (depends on a specific host, e.g. POSIX hosts) and host independent parts (will work on all supported hosts).
--- tools/um/Makefile | 7 +- tools/um/Targets | 3 +- tools/um/include/lkl.h | 151 +++++++++++++++++++++++++++++ tools/um/include/lkl_host.h | 26 +++++ tools/um/uml/Build | 15 ++- tools/um/uml/nommu/Build | 1 + tools/um/uml/nommu/registers.c | 21 ++++ tools/um/uml/nommu/unimplemented.c | 21 ++++ 8 files changed, 238 insertions(+), 7 deletions(-) create mode 100644 tools/um/include/lkl.h create mode 100644 tools/um/include/lkl_host.h create mode 100644 tools/um/uml/nommu/Build create mode 100644 tools/um/uml/nommu/registers.c create mode 100644 tools/um/uml/nommu/unimplemented.c
tools/um/Makefile +5 -2
@@ -5,6 +5,7 @@ MAKEFLAGS += -r --no-print-directory KCONFIG?=defconfig +UMMODE?=kernel ifneq ($(silent),1) ifneq ($(V),1)
@@ -47,8 +48,9 @@ all: $(TARGETS) # rule to build linux.o $(OUTPUT)lib/linux.o: - $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) $(KCONFIG) - $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) install INSTALL_PATH=$(OUTPUT) + $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um UMMODE=$(UMMODE) $(KOPT) $(KCONFIG) + $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um UMMODE=$(UMMODE) $(KOPT) install \ + INSTALL_PATH=$(OUTPUT) $(OUTPUT)liblinux.a: $(OUTPUT)lib/linux.o $(OUTPUT)uml/liblinux-in.o $(OUTPUT)lib/liblinux-in.o $(QUIET_AR)$(AR) -rc $@ $^
@@ -67,6 +69,7 @@ $(OUTPUT)%-in.o: $(OUTPUT)lib/linux.o FORCE clean: $(call QUIET_CLEAN, objects)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd'\ -delete -o -name '\.*.d' -delete + $(call QUIET_CLEAN, headers)$(RM) -r $(OUTPUT)/include/lkl/ $(call QUIET_CLEAN, liblinux.a)$(RM) $(OUTPUT)/liblinux.a $(call QUIET_CLEAN, $(TARGETS))$(RM) $(TARGETS)
tools/um/Targets +2 -1
@@ -1,4 +1,5 @@ progs-y += uml/linux -LDLIBS_linux-y := -lrt -lpthread -lutil + +LDLIBS := -lrt -lpthread -lutil LDFLAGS_linux-y := -no-pie -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc LDFLAGS_linux-$(UML_STATIC) += -static
tools/um/include/lkl.h new file +151 -0
151 lines not on this page · raw message
tools/um/include/lkl_host.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LKL_HOST_H +#define _LKL_HOST_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <lkl/asm/host_ops.h> +#include <lkl.h> + +extern struct lkl_host_operations lkl_host_ops; + +/** +* lkl_printf - print a message via the host print operation +* +* @fmt: printf like format string +*/ +int lkl_printf (const char *fmt, ...); + + +#ifdef __cplusplus +} +#endif + +#endif
tools/um/uml/Build +11 -4
@@ -8,11 +8,19 @@ KCOV_INSTRUMENT := n include $(objtree)/include/config/auto.conf -liblinux-y += execvp.o file.o helper.o irq.o main.o mem.o process.o \ - registers.o sigio.o signal.o start_up.o time.o tty.o \ - umid.o user_syms.o util.o drivers/ skas/ +liblinux-y += execvp.o file.o helper.o irq.o mem.o process.o \ + registers.o sigio.o signal.o time.o tty.o \ + umid.o user_syms.o util.o drivers/ +ifdef CONFIG_MMU +liblinux-y += main.o start_up.o skas/ +HEADER_ARCH := x86 liblinux-y += x86/ +else +HEADER_ARCH := um/nommu +liblinux-y += nommu/ +endif + liblinux-$(CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA) += elf_aux.o
@@ -23,7 +31,6 @@ CFLAGS := -g -O2 # from arch/um/Makefile ARCH_DIR := arch/um -HEADER_ARCH := x86 HOST_DIR := arch/$(HEADER_ARCH) ifdef CONFIG_64BIT KBUILD_CFLAGS += -mcmodel=large
tools/um/uml/nommu/Build new file +1 -0
@@ -0,0 +1 @@ +liblinux-y = registers.o unimplemented.o
tools/um/uml/nommu/registers.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 + +struct uml_pt_regs ; + +int get_fp_registers (int pid,unsigned long *regs) +{ +return 0 ; +} + +int save_i387_registers (int pid,unsigned long *fp_regs) +{ +return 0 ; +} + +void arch_init_registers (int pid) +{ +} + +void get_regs_from_mc (struct uml_pt_regs *regs,void *mc) +{ +}
tools/um/uml/nommu/unimplemented.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <generated/user_constants.h> + +struct uml_pt_regs ; + +/* os-Linux/skas/process.c */ +int userspace_pid[UM_NR_CPUS ]; +void userspace (struct uml_pt_regs *regs,unsigned long *aux_fp_regs) +{} + + +/* x86/os-Linux/task_size.c */ +unsigned long os_get_top_address (void ) +{ +return 0 ; +} + +/* start-up.c */ +void os_early_checks (void ) +{ +}
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v5 18/21 um: host: add utilities functions
In reply to Hajime TazakiAdd basic utility functions for getting a string from a kernel error code and a fprintf like function that uses the host print operation. The latter is useful for informing the user about errors that occur in the host library.
--- tools/um/lib/Build | 4 + tools/um/lib/jmp_buf.c | 14 +++ tools/um/lib/jmp_buf.h | 8 ++ tools/um/lib/utils.c | 210 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 236 insertions(+) create mode 100644 tools/um/lib/Build create mode 100644 tools/um/lib/jmp_buf.c create mode 100644 tools/um/lib/jmp_buf.h create mode 100644 tools/um/lib/utils.c
tools/um/lib/Build new file +4 -0
@@ -0,0 +1,4 @@ +include $(objtree)/include/config/auto.conf + +liblinux-$(CONFIG_UMMODE_LIB) += utils.o +liblinux-$(CONFIG_UMMODE_LIB) += jmp_buf.o
tools/um/lib/jmp_buf.c new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <setjmp.h> +#include <lkl_host.h> + +void jmp_buf_set (struct lkl_jmp_buf *jmpb,void (*f)(void )) +{ +if (!setjmp (*((jmp_buf *)jmpb->buf))) +f (); +} + +void jmp_buf_longjmp (struct lkl_jmp_buf *jmpb,int val) +{ +longjmp (*((jmp_buf *)jmpb->buf), val); +}
tools/um/lib/jmp_buf.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LKL_LIB_JMP_BUF_H +#define _LKL_LIB_JMP_BUF_H + +void jmp_buf_set (struct lkl_jmp_buf *jmpb,void (*f)(void )); +void jmp_buf_longjmp (struct lkl_jmp_buf *jmpb,int val); + +#endif
tools/um/lib/utils.c new file +210 -0
210 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v5 19/21 um: host: posix host operations
In reply to Hajime TazakiThis commit implements LKL host operations for POSIX hosts. The operations are implemented to be portable in various POSIX OSs.
--- tools/um/lib/Build | 2 + tools/um/lib/posix-host.c | 292 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 294 insertions(+) create mode 100644 tools/um/lib/posix-host.c
tools/um/lib/Build +2 -0
@@ -1,4 +1,6 @@ include $(objtree)/include/config/auto.conf +CFLAGS_posix-host.o += -D_FILE_OFFSET_BITS=64 liblinux-$(CONFIG_UMMODE_LIB) += utils.o +liblinux-$(CONFIG_UMMODE_LIB) += posix-host.o liblinux-$(CONFIG_UMMODE_LIB) += jmp_buf.o
tools/um/lib/posix-host.c new file +292 -0
292 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v5 20/21 um: host: add test programs
In reply to Hajime TazakiAdd a simple LKL test application (boot) that starts the kernel and performs simple tests that minimally exercise the LKL API.
--- tools/um/Makefile | 5 +- tools/um/Targets | 6 + tools/um/tests/Build | 1 + tools/um/tests/boot.c | 393 ++++++++++++++++++++++++++++++++++++++++ tools/um/tests/boot.sh | 9 + tools/um/tests/run.py | 172 ++++++++++++++++++ tools/um/tests/tap13.py | 209 +++++++++++++++++++++ tools/um/tests/test.c | 126 +++++++++++++ tools/um/tests/test.h | 72 ++++++++ tools/um/tests/test.sh | 181 ++++++++++++++++++ 10 files changed, 1173 insertions(+), 1 deletion(-) create mode 100644 tools/um/tests/Build create mode 100644 tools/um/tests/boot.c create mode 100755 tools/um/tests/boot.sh create mode 100755 tools/um/tests/run.py create mode 100644 tools/um/tests/tap13.py create mode 100644 tools/um/tests/test.c create mode 100644 tools/um/tests/test.h create mode 100644 tools/um/tests/test.sh
tools/um/Makefile +4 -1
@@ -73,7 +73,10 @@ clean: $(call QUIET_CLEAN, liblinux.a)$(RM) $(OUTPUT)/liblinux.a $(call QUIET_CLEAN, $(TARGETS))$(RM) $(TARGETS) +run-tests: + ./tests/run.py $(tests) + FORCE: ; -.PHONY: all clean FORCE +.PHONY: all clean FORCE run-tests .IGNORE: clean .NOTPARALLEL : lib/linux.o
tools/um/Targets +6 -0
@@ -1,4 +1,10 @@ +ifeq ($(UMMODE),library) +progs-y += tests/boot +else progs-y += uml/linux +endif + +LDFLAGS_boot-y := -pie LDLIBS := -lrt -lpthread -lutil LDFLAGS_linux-y := -no-pie -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
tools/um/tests/Build new file +1 -0
@@ -0,0 +1 @@ +boot-y += boot.o test.o
tools/um/tests/boot.c new file +393 -0
393 lines not on this page · raw message
tools/um/tests/boot.sh new file +9 -0
@@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +script_dir=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd) +source $script_dir/test.sh + +lkl_test_plan 1 "boot" +lkl_test_run 1 +lkl_test_exec $script_dir/boot
tools/um/tests/run.py new file +172 -0
172 lines not on this page · raw message
tools/um/tests/tap13.py new file +209 -0
209 lines not on this page · raw message
tools/um/tests/test.c new file +126 -0
126 lines not on this page · raw message
tools/um/tests/test.h new file +72 -0
72 lines not on this page · raw message
tools/um/tests/test.sh new file +181 -0
181 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v5 21/21 um: nommu: add block device support of UML
In reply to Hajime TazakiThis commit adds block device support for nommu mode, and also added several host utilities to run a simple test program (tools/um/test/disk.c) successfully.
--- arch/um/include/asm/xor.h | 3 +- arch/um/include/shared/as-layout.h | 1 + arch/um/kernel/um_arch.c | 5 + arch/um/nommu/include/uapi/asm/host_ops.h | 7 + arch/um/nommu/include/uapi/asm/unistd.h | 2 + arch/um/nommu/um/Kconfig | 8 + arch/um/nommu/um/setup.c | 12 + tools/um/Targets | 2 + tools/um/include/lkl.h | 206 ++++++++++ tools/um/include/lkl_host.h | 1 + tools/um/lib/Build | 1 + tools/um/lib/fs.c | 461 ++++++++++++++++++++++ tools/um/lib/posix-host.c | 1 + tools/um/lib/utils.c | 3 + tools/um/tests/Build | 1 + tools/um/tests/cla.c | 159 ++++++++ tools/um/tests/cla.h | 33 ++ tools/um/tests/disk.c | 168 ++++++++ tools/um/tests/disk.sh | 70 ++++ tools/um/tests/run.py | 2 + 20 files changed, 1145 insertions(+), 1 deletion(-) create mode 100644 tools/um/lib/fs.c create mode 100644 tools/um/tests/cla.c create mode 100644 tools/um/tests/cla.h create mode 100644 tools/um/tests/disk.c create mode 100755 tools/um/tests/disk.sh
arch/um/include/asm/xor.h +2 -1
@@ -4,4 +4,5 @@/* pick an arbitrary one - measuring isn't possible with inf-cpu */ #define XOR_SELECT_TEMPLATE (x) \ - (time_travel_mode == TT_MODE_INFCPU ? &xor_block_8regs : NULL) + (time_travel_mode == TT_MODE_INFCPU || (!IS_ENABLED(CONFIG_MMU)) ? \ + &xor_block_8regs : NULL)
arch/um/include/shared/as-layout.h +1 -0
@@ -57,6 +57,7 @@ extern unsigned long host_task_size;extern int linux_main (int argc,char **argv);extern void uml_finishsetup (void ); +extern void uml_set_args (char *args);struct siginfo ;extern void (*sig_info[])(int ,struct siginfo *si,struct uml_pt_regs *);
arch/um/kernel/um_arch.c +5 -0
@@ -42,6 +42,11 @@ static void __init add_arg(char *arg)strcat (command_line, arg); } +void __init uml_set_args (char *args) +{ +strcat (command_line, args); +} +/* * These fields are initialized at boot time and not changed. * XXX This structure is used only in the non-SMP case. Maybe this
arch/um/nommu/include/uapi/asm/host_ops.h +7 -0
@@ -15,6 +15,11 @@ struct lkl_jmp_buf {* * These operations must be provided by a host library or by the application * itself. +* +* @um_devices - string containg the list of UML devices in command line +* format. This string is appended to the kernel command line and +* is provided here for convenience to be implemented by the host library. +* * @print - optional operation that receives console messages * @panic - called during a kernel panic *
@@ -65,6 +70,8 @@ struct lkl_jmp_buf {* */ struct lkl_host_operations { +const char *um_devices; +void (*print)(const char *str,int len);void (*panic)(void );
arch/um/nommu/include/uapi/asm/unistd.h +2 -0
@@ -3,6 +3,8 @@#define __UM_NOMMU_UAPI_UNISTD_H#define __ARCH_WANT_NEW_STAT +#define __ARCH_WANT_SET_GET_RLIMIT +#include <asm/bitsperlong.h> #if __BITS_PER_LONG ==64
arch/um/nommu/um/Kconfig +8 -0
@@ -4,6 +4,10 @@ config UML_NOMMU select UACCESS_MEMCPY select ARCH_THREAD_STACK_ALLOCATOR select ARCH_HAS_SYSCALL_WRAPPER + select VFAT_FS + select NLS_CODEPAGE_437 + select NLS_ISO8859_1 + select BTRFS_FS config 64BIT bool
@@ -35,3 +39,7 @@ config STACKTRACE_SUPPORT config PRINTK_TIME bool default y + +config RAID6_PQ_BENCHMARK + bool + default n
arch/um/nommu/um/setup.c +12 -0
@@ -45,13 +45,25 @@ static void __init *lkl_run_kernel(void *arg)return NULL ; } +static char _cmd_line[COMMAND_LINE_SIZE ];int __init lkl_start_kernel (struct lkl_host_operations *ops,const char *fmt, ...) { +va_list ap;int ret; lkl_ops = ops; +va_start (ap, fmt); + ret =vsnprintf (_cmd_line,COMMAND_LINE_SIZE , fmt, ap); +va_end (ap); + +if (ops->um_devices) +strscpy (_cmd_line + ret, ops->um_devices, +COMMAND_LINE_SIZE - ret); + +uml_set_args (_cmd_line); + init_sem = lkl_ops->sem_alloc (0 );if (!init_sem)return -ENOMEM ;
tools/um/Targets +2 -0
@@ -1,10 +1,12 @@ ifeq ($(UMMODE),library) progs-y += tests/boot +progs-y += tests/disk else progs-y += uml/linux endif LDFLAGS_boot-y := -pie +LDFLAGS_disk-y := -pie LDLIBS := -lrt -lpthread -lutil LDFLAGS_linux-y := -no-pie -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
tools/um/include/lkl.h +206 -0
224 lines not on this page · raw message
tools/um/include/lkl_host.h +1 -0
@@ -10,6 +10,7 @@ extern "C" {#include <lkl.h> extern struct lkl_host_operations lkl_host_ops; +extern char lkl_um_devs[4096 ];/** * lkl_printf - print a message via the host print operation
tools/um/lib/Build +1 -0
@@ -4,3 +4,4 @@ CFLAGS_posix-host.o += -D_FILE_OFFSET_BITS=64 liblinux-$(CONFIG_UMMODE_LIB) += utils.o liblinux-$(CONFIG_UMMODE_LIB) += posix-host.o liblinux-$(CONFIG_UMMODE_LIB) += jmp_buf.o +liblinux-$(CONFIG_UMMODE_LIB) += fs.o
tools/um/lib/fs.c new file +461 -0
461 lines not on this page · raw message
tools/um/lib/posix-host.c +1 -0
@@ -263,6 +263,7 @@ static void *tls_get(struct lkl_tls_key *key) }struct lkl_host_operations lkl_host_ops = { + .um_devices = lkl_um_devs, .panic = panic, .print = print, .mem_alloc = (void *)malloc,
tools/um/lib/utils.c +3 -0
@@ -4,6 +4,9 @@#include <string.h> #include <lkl_host.h> +/* XXX: find a better place */ +char lkl_um_devs[4096 ]; +static const char *const lkl_err_strings[] = {"Success" ,"Operation not permitted" ,
tools/um/tests/Build +1 -0
@@ -1 +1,2 @@ boot-y += boot.o test.o +disk-y += disk.o test.o cla.o
tools/um/tests/cla.c new file +159 -0
159 lines not on this page · raw message
tools/um/tests/cla.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _LKL_TEST_CLA_H +#define _LKL_TEST_CLA_H + +enum cl_arg_type { +CL_ARG_USER =0 , +CL_ARG_BOOL , +CL_ARG_INT , +CL_ARG_STR , +CL_ARG_STR_SET , +CL_ARG_IPV4 , +CL_ARG_END , +}; + +struct cl_arg ; + +typedef int (*cl_arg_parser_t )(struct cl_arg *arg,const char *value); + +struct cl_arg { +const char *long_name; +char short_name; +const char *help; +int has_arg; +enum cl_arg_type type; +void *store; +void *set; +cl_arg_parser_t parser; +}; + +int cla_parse_args (int argc,const char **argv,struct cl_arg *args); + + +#endif /* _LKL_TEST_CLA_H */
tools/um/tests/disk.c new file +168 -0
168 lines not on this page · raw message
tools/um/tests/disk.sh new file +70 -0
70 lines not on this page · raw message
tools/um/tests/run.py +2 -0
@@ -50,6 +50,8 @@ mydir=os.path.dirname(os.path.realpath(__file__)) tests = [ 'boot.sh', + 'disk.sh -t ext4', + 'disk.sh -t vfat', ] parser = argparse.ArgumentParser(description='LKL test runner')
Signature · 1 line
2.21.0 (Apple Git-122.2)
Anton Ivanov
maintainerRe: [RFC v5 01/21] um: split build in kernel and host parts
In reply to Hajime Tazakitools/um/uml/Build
Quoted 757 lines · Hajime Tazaki
From: Octavian Purdila <[email protected]>
This patch splits the UML build in two parts: a kernel part that generates a relocatable object (linux.o) and a host build part that links the relocatable object into an executable.
This allows us to simplify the linker script since we can now remove the host bits (e.g. .rel sections). It also gives us greater flexibility since it will be much easier to support other architectures and OSes if we use the standard linker script.
The host build part has been implemented in
tools/umso that we can reuse the available host build infrastructure.The patch also changes the UML build invocation, if before
$ make ARCH=um defconfig $ make ARCH=umwas generating the executable now this only generates the relocatable object.
To fully build UML use:
$ make -C tools/umwhich will generate
tools/lkl/linuxas the UML executable. To statically compiled UML use:$ make -C tools/lkl UML_STATIC=ySigned-off-by Octavian Purdila <[email protected]>Signed-off-by Hajime Tazaki <[email protected]>--- arch/um/Kconfig | 12 +-- arch/um/Makefile | 14 ++- arch/um/include/asm/common.lds.S | 99 ------------------ arch/um/kernel/dyn.lds.S | 171 ------------------------------- arch/um/kernel/uml.lds.S | 115 --------------------- arch/um/kernel/vmlinux.lds.S | 91 ++++++++++++++-- scripts/link-vmlinux.sh | 42 +++----- tools/um/Makefile | 72 +++++++++++++ tools/um/Targets | 4 + tools/um/uml/Build | 0 10 files changed, 184 insertions(+), 436 deletions(-)delete mode 100644
arch/um/include/asm/common.lds.Sdelete mode 100644arch/um/kernel/dyn.lds.Sdelete mode 100644arch/um/kernel/uml.lds.Screate mode 100644tools/um/Makefile
create mode 100644tools/um/Targets
create mode 100644tools/um/uml/Buildarch/um/Kconfig +1
-11@@ -20,6 +20,7 @@ config UML select GENERIC_CLOCKEVENTS select HAVE_GCC_PLUGINS select TTY # Needed for line.c + select MODULE_REL_CRCS if MODVERSIONS config MMU bool@@ -79,17 +80,6 @@ config STATIC_LINK NOTE: This option is incompatible with some networking features which depend on features that require being dynamically loaded (like NSS). -config LD_SCRIPT_STATIC - bool - default y - depends on STATIC_LINK - -config LD_SCRIPT_DYN - bool - default y - depends on !LD_SCRIPT_STATIC - select MODULE_REL_CRCS if MODVERSIONS - config HOSTFS tristate "Host filesystem" helparch/um/Makefile +10
-4@@ -95,14 +95,20 @@ KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/include \ KERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \ -Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES)) KBUILD_CFLAGS += $(KERNEL_DEFINES) +LDFLAGS_vmlinux += -r -PHONY += linux +PHONY += linux.o -all: linux +all: linux.o -linux: vmlinux +linux.o: vmlinux @echo ' LINK $@' - $(Q)ln -f $< $@ + $(Q)$(OBJCOPY) -R .eh_frame $< $@ + +install: linux.o + @echo " INSTALL $(INSTALL_PATH)/lib/$<" + @mkdir -p $(INSTALL_PATH)/lib/ + @cp $< $(INSTALL_PATH)/lib/ define archhelp echo '* linux - Binary kernel image (./linux) - for backward'arch/um/include/asm/common.lds.S deleted +0
-99@@ -1,99 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm-generic/vmlinux.lds.h> - - .fini : { *(.fini) } =0x9090 - _etext = .; - PROVIDE (etext = .); - - . = ALIGN(4096); - _sdata = .; - PROVIDE (sdata = .); - - RO_DATA(4096) - - .unprotected : { *(.unprotected) } - . = ALIGN(4096); - PROVIDE (_unprotected_end = .); - - . = ALIGN(4096); - EXCEPTION_TABLE(0) - - BUG_TABLE - - .uml.setup.init : { - __uml_setup_start = .; - *(.uml.setup.init) - __uml_setup_end = .; - } - - .uml.help.init : { - __uml_help_start = .; - *(.uml.help.init) - __uml_help_end = .; - } - - .uml.postsetup.init : { - __uml_postsetup_start = .; - *(.uml.postsetup.init) - __uml_postsetup_end = .; - } - - .init.setup : { - INIT_SETUP(0) - } - - PERCPU_SECTION(32) - - .initcall.init : { - INIT_CALLS - } - - .con_initcall.init : { - CON_INITCALL - } - - .exitcall : { - __exitcall_begin = .; - *(.exitcall.exit) - __exitcall_end = .; - } - - .uml.exitcall : { - __uml_exitcall_begin = .; - *(.uml.exitcall.exit) - __uml_exitcall_end = .; - } - - . = ALIGN(4); - .altinstructions : { - __alt_instructions = .; - *(.altinstructions) - __alt_instructions_end = .; - } - .altinstr_replacement : { *(.altinstr_replacement) } - /* .exit.text is discard at runtime, not link time, to deal with references - from .altinstructions and .eh_frame */ - .exit.text : { EXIT_TEXT } - .exit.data : { *(.exit.data) } - - .preinit_array : { - __preinit_array_start = .; - *(.preinit_array) - __preinit_array_end = .; - } - .init_array : { - __init_array_start = .; - *(.init_array) - __init_array_end = .; - } - .fini_array : { - __fini_array_start = .; - *(.fini_array) - __fini_array_end = .; - } - - . = ALIGN(4096); - .init.ramfs : { - INIT_RAM_FS - } -arch/um/kernel/dyn.lds.S deleted +0
-171@@ -1,171 +0,0 @@ -#include <asm/vmlinux.lds.h> -#include <asm/page.h> - -OUTPUT_FORMAT(ELF_FORMAT) -OUTPUT_ARCH(ELF_ARCH) -ENTRY(_start) -jiffies = jiffies_64; - -SECTIONS -{ - PROVIDE (__executable_start = START); - . = START + SIZEOF_HEADERS; - .interp : { *(.interp) } - __binary_start = .; - . = ALIGN(4096); /* Init code and data */ - _text = .; - INIT_TEXT_SECTION(PAGE_SIZE) - - . = ALIGN(PAGE_SIZE); - - /* Read-only sections, merged into text segment: */ - .hash : { *(.hash) } - .gnu.hash : { *(.gnu.hash) } - .dynsym : { *(.dynsym) } - .dynstr : { *(.dynstr) } - .gnu.version : { *(.gnu.version) } - .gnu.version_d : { *(.gnu.version_d) } - .gnu.version_r : { *(.gnu.version_r) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.text : { *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) } - .rela.text : { *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.rodata : { *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) } - .rela.rodata : { *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) } - .rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) } - .rela.data : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) } - .rel.tdata : { *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) } - .rela.tdata : { *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) } - .rel.tbss : { *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) } - .rela.tbss : { *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.bss : { *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) } - .rela.bss : { *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) } - .rel.plt : { - *(.rel.plt) - PROVIDE_HIDDEN(__rel_iplt_start = .); - *(.rel.iplt) - PROVIDE_HIDDEN(__rel_iplt_end = .); - } - .rela.plt : { - *(.rela.plt) - PROVIDE_HIDDEN(__rela_iplt_start = .); - *(.rela.iplt) - PROVIDE_HIDDEN(__rela_iplt_end = .); - } - .init : { - KEEP (*(.init)) - } =0x90909090 - .plt : { *(.plt) } - .text : { - _stext = .; - TEXT_TEXT - SCHED_TEXT - CPUIDLE_TEXT - LOCK_TEXT - IRQENTRY_TEXT - SOFTIRQENTRY_TEXT - *(.fixup) - *(.stub .text.* .gnu.linkonce.t.*) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - - . = ALIGN(PAGE_SIZE); - } =0x90909090 - . = ALIGN(PAGE_SIZE); - .syscall_stub : { - __syscall_stub_start = .; - *(.__syscall_stub*) - __syscall_stub_end = .; - } - .fini : { - KEEP (*(.fini)) - } =0x90909090 - - .kstrtab : { *(.kstrtab) } - - #include <asm/common.lds.S> - - __init_begin = .; - init.data : { INIT_DATA } - __init_end = .; - - /* Ensure the __preinit_array_start label is properly aligned. We - could instead move the label definition inside the section, but - the linker would then create the section even if it turns out to - be empty, which isn't pretty. */ - . = ALIGN(32 / 8); - .preinit_array : { *(.preinit_array) } - .init_array : { *(.init_array) } - .fini_array : { *(.fini_array) } - .data : { - INIT_TASK_DATA(KERNEL_STACK_SIZE) - . = ALIGN(KERNEL_STACK_SIZE); - *(.data..init_irqstack) - DATA_DATA - *(.data.* .gnu.linkonce.d.*) - SORT(CONSTRUCTORS) - } - .data1 : { *(.data1) } - .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } - .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } - .eh_frame : { KEEP (*(.eh_frame)) } - .gcc_except_table : { *(.gcc_except_table) } - .dynamic : { *(.dynamic) } - .ctors : { - /* gcc uses crtbegin.o to find the start of - the constructors, so we make sure it is - first. Because this is a wildcard, it - doesn't matter if the user does not - actually link against crtbegin.o; the - linker won't look for a file to match a - wildcard. The wildcard also means that it - doesn't matter which directory crtbegin.o - is in. */ - KEEP (*crtbegin.o(.ctors)) - /* We don't want to include the .ctor section from - from the crtend.o file until after the sorted ctors. - The .ctor section from the crtend file contains the - end of ctors marker and it must be last */ - KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors)) - KEEP (*(SORT(.ctors.*))) - KEEP (*(.ctors)) - } - .dtors : { - KEEP (*crtbegin.o(.dtors)) - KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors)) - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - } - .jcr : { KEEP (*(.jcr)) } - .got : { *(.got.plt) *(.got) } - _edata = .; - PROVIDE (edata = .); - .bss : { - __bss_start = .; - *(.dynbss) - *(.bss .bss.* .gnu.linkonce.b.*) - *(COMMON) - /* Align here to ensure that the .bss section occupies space up to - _end. Align after .bss to ensure correct alignment even if the - .bss section disappears because there are no input sections. */ - . = ALIGN(32 / 8); - . = ALIGN(32 / 8); - } - __bss_stop = .; - _end = .; - PROVIDE (end = .); - - STABS_DEBUG - - DWARF_DEBUG - - DISCARDS -}arch/um/kernel/uml.lds.S deleted +0
-115@@ -1,115 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/vmlinux.lds.h> -#include <asm/page.h> - -OUTPUT_FORMAT(ELF_FORMAT) -OUTPUT_ARCH(ELF_ARCH) -ENTRY(_start) -jiffies = jiffies_64; - -SECTIONS -{ - /* This must contain the right address - not quite the default ELF one.*/ - PROVIDE (__executable_start = START); - /* Static binaries stick stuff here, like the sigreturn trampoline, - * invisibly to objdump. So, just make __binary_start equal to the very - * beginning of the executable, and if there are unmapped pages after this, - * they are forever unusable. - */ - __binary_start = START; - - . = START + SIZEOF_HEADERS; - . = ALIGN(PAGE_SIZE); - - _text = .; - INIT_TEXT_SECTION(0) - - .text : - { - _stext = .; - TEXT_TEXT - SCHED_TEXT - CPUIDLE_TEXT - LOCK_TEXT - IRQENTRY_TEXT - SOFTIRQENTRY_TEXT - *(.fixup) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - *(.gnu.linkonce.t*) - } - - . = ALIGN(PAGE_SIZE); - .syscall_stub : { - __syscall_stub_start = .; - *(.__syscall_stub*) - __syscall_stub_end = .; - } - - /* - * These are needed even in a static link, even if they wind up being empty. - * Newer glibc needs these __rel{,a}_iplt_{start,end} symbols. - */ - .rel.plt : { - *(.rel.plt) - PROVIDE_HIDDEN(__rel_iplt_start = .); - *(.rel.iplt) - PROVIDE_HIDDEN(__rel_iplt_end = .); - } - .rela.plt : { - *(.rela.plt) - PROVIDE_HIDDEN(__rela_iplt_start = .); - *(.rela.iplt) - PROVIDE_HIDDEN(__rela_iplt_end = .); - } - - #include <asm/common.lds.S> - - __init_begin = .; - init.data : { INIT_DATA } - __init_end = .; - - .data : - { - INIT_TASK_DATA(KERNEL_STACK_SIZE) - . = ALIGN(KERNEL_STACK_SIZE); - *(.data..init_irqstack) - DATA_DATA - *(.gnu.linkonce.d*) - CONSTRUCTORS - } - .data1 : { *(.data1) } - .ctors : - { - *(.ctors) - } - .dtors : - { - *(.dtors) - } - - .got : { *(.got.plt) *(.got) } - .dynamic : { *(.dynamic) } - .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } - .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } - /* We want the small data sections together, so single-instruction offsets - can access them all, and initialized data all before uninitialized, so - we can shorten the on-disk segment size. */ - .sdata : { *(.sdata) } - _edata = .; - PROVIDE (edata = .); - . = ALIGN(PAGE_SIZE); - __bss_start = .; - PROVIDE(_bss_start = .); - SBSS(0) - BSS(0) - __bss_stop = .; - _end = .; - PROVIDE (end = .); - - STABS_DEBUG - - DWARF_DEBUG - - DISCARDS -}arch/um/kernel/vmlinux.lds.S +85
-6@@ -1,8 +1,87 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <asm/vmlinux.lds.h> +#include <asm/thread_info.h> +#include <asm/page.h> +#include <asm/thread_info.h> +#include <asm/cache.h> +#include <linux/export.h> -KERNEL_STACK_SIZE = 4096 * (1 << CONFIG_KERNEL_STACK_ORDER); +OUTPUT_FORMAT(ELF_FORMAT) +jiffies = jiffies_64; -#ifdef CONFIG_LD_SCRIPT_STATIC -#include "uml.lds.S" -#else -#include "dyn.lds.S" -#endif + +SECTIONS +{ + __init_begin = . ; + HEAD_TEXT_SECTION + INIT_TEXT_SECTION(PAGE_SIZE) + INIT_DATA_SECTION(16) + PERCPU_SECTION(L1_CACHE_BYTES) + __init_end = . ; + + _stext = . ; + _text = . ; + .text : ALIGN(THREAD_SIZE) + { + __binary_start = . ; + TEXT_TEXT + SCHED_TEXT + LOCK_TEXT + CPUIDLE_TEXT + IRQENTRY_TEXT + SOFTIRQENTRY_TEXT + } + _etext = . ; + + .syscall_stub : ALIGN(PAGE_SIZE) + { + __syscall_stub_start = .; + *(.__syscall_stub*) + __syscall_stub_end = .; + } + + _sdata = . ; + RO_DATA(PAGE_SIZE) + RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE) + .data : ALIGN(THREAD_SIZE) { } + + EXCEPTION_TABLE(16) + + .uml.init_irqstack : ALIGN(THREAD_SIZE) { + *(.data..init_irqstack) + } + + .uml.setup.init : ALIGN(8) { + __uml_setup_start = .; + *(.uml.setup.init) + __uml_setup_end = .; + } + + .uml.help.init : ALIGN(8) { + __uml_help_start = .; + *(.uml.help.init) + __uml_help_end = .; + } + + .uml.postsetup.init : ALIGN(8) { + __uml_postsetup_start = .; + *(.uml.postsetup.init) + __uml_postsetup_end = .; + } + + .uml.exitcall : ALIGN(8) { + __uml_exitcall_begin = .; + *(.uml.exitcall.exit) + __uml_exitcall_end = .; + } + _edata = . ; + + BSS_SECTION(0, 0, 0) + _end = . ; + + STABS_DEBUG + + DWARF_DEBUG + + DISCARDS +}scripts/link-vmlinux.sh +12
-30@@ -75,36 +75,18 @@ vmlinux_link() strip_debug=-Wl,--strip-debug fi - if [ "${SRCARCH}" != "um" ]; then - objects="--whole-archive \ - ${KBUILD_VMLINUX_OBJS} \ - --no-whole-archive \ - --start-group \ - ${KBUILD_VMLINUX_LIBS} \ - --end-group \ - ${@}" - - ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} \ - ${strip_debug#-Wl,} \ - -o ${output} \ - -T ${lds} ${objects} - else - objects="-Wl,--whole-archive \ - ${KBUILD_VMLINUX_OBJS} \ - -Wl,--no-whole-archive \ - -Wl,--start-group \ - ${KBUILD_VMLINUX_LIBS} \ - -Wl,--end-group \ - ${@}" - - ${CC} ${CFLAGS_vmlinux} \ - ${strip_debug} \ - -o ${output} \ - -Wl,-T,${lds} \ - ${objects} \ - -lutil -lrt -lpthread - rm -f linux - fi + objects="--whole-archive \ + ${KBUILD_VMLINUX_OBJS} \ + --no-whole-archive \ + --start-group \ + ${KBUILD_VMLINUX_LIBS} \ + --end-group \ + ${@}" + + ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} \ + ${strip_debug#-Wl,} \ + -o ${output} \ + -T ${lds} ${objects} } # generate .BTF typeinfo from DWARF debuginfotools/um/Makefile new file +72
-0@@ -0,0 +1,72 @@ +# Do not use make's built-in rules +# (this improves performance and avoids hard-to-debug behaviour); +# also do not print "Entering directory..." messages from make +.SUFFIXES: +MAKEFLAGS += -r --no-print-directory + +KCONFIG?=defconfig + +ifneq ($(silent),1) + ifneq ($(V),1) + QUIET_AUTOCONF = @echo ' AUTOCONF '$@; + Q = @ + endif +endif + +PREFIX := /usr + +ifeq (,$(srctree)) + srctree := $(patsubst %/,%,$(dir $(shell pwd))) + srctree := $(patsubst %/,%,$(dir $(srctree))) +endif +export srctree + +-include ../scripts/Makefile.include + +# OUTPUT fixup should be *after* include ../scripts/Makefile.include +ifneq ($(OUTPUT),) + OUTPUT := $(OUTPUT)/tools/um/ +else + OUTPUT := $(CURDIR)/ +endif +export OUTPUT +export objtree := $(OUTPUT)/../.. + + +all: + +export CFLAGS += -I$(OUTPUT)/include -Iinclude -Wall -g -O2 -Wextra -fPIC \ + -Wno-unused-parameter \ + -Wno-missing-field-initializers -fno-strict-aliasing + +-include Targets + +TARGETS := $(progs-y:%=$(OUTPUT)%) +TARGETS += $(libs-y:%=$(OUTPUT)%) +all: $(TARGETS) + +# rule to build linux.o +$(OUTPUT)lib/linux.o: + $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) $(KCONFIG) + $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) install INSTALL_PATH=$(OUTPUT) + +$(OUTPUT)liblinux.a: $(OUTPUT)lib/linux.o $(OUTPUT)uml/liblinux-in.o + $(QUIET_AR)$(AR) -rc $@ $^ + +# rule to link programs +$(OUTPUT)%: $(OUTPUT)%-in.o $(OUTPUT)liblinux.a + $(QUIET_LINK)$(CC) $(LDFLAGS) $(LDFLAGS_$(notdir $*)-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$(notdir $*)-y) + +$(OUTPUT)%-in.o: FORCE + $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) + +clean: + $(call QUIET_CLEAN, objects)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd'\ + -delete -o -name '\.*.d' -delete + $(call QUIET_CLEAN, liblinux.a)$(RM) $(OUTPUT)/liblinux.a + $(call QUIET_CLEAN, $(TARGETS))$(RM) $(TARGETS) + +FORCE: ; +.PHONY: all clean FORCE +.IGNORE: clean +.NOTPARALLEL : lib/linux.otools/um/Targets new file +4
-0@@ -0,0 +1,4 @@ +progs-y += uml/linux +LDLIBS_linux-y := -lrt -lpthread -lutil +LDFLAGS_linux-y := -no-pie -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc +LDFLAGS_linux-$(UML_STATIC) += -statictools/um/uml/Build new file +0
-0
Hi Hajime, hi Octavian,
I am going to have a bit more time to look at UML now. Can you rebase/update the patch versus the latest kernel so I can look at it.
It does not apply at present.
Thanks in advance,
Signature · 8 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/ _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [RFC v5 01/21] um: split build in kernel and host parts
Quoted 5 lines · Anton Ivanov
Hi Hajime, hi Octavian,
I am going to have a bit more time to look at UML now. Can you rebase/update the patch versus the latest kernel so I can look at it.
It does not apply at present.
Okay, I'll do it.
Thanks,
-- Hajime
v6 cover Unifying LKL into UML
In reply to Hajime TazakiThis is another spin of the unification of LKL into UML. Based on the discussion of v4 patchset, we have tried to address issue raised and rewrote the patchset from scratch. The summary is listed in the changelog below.
Although there are still bugs in the patchset, we'd like to ask your opinions on the design we changed.
The milestone section is also updated: this patchset is for the milestone 1, though the common init API is still not implemented yet.
Changes in rfc v6:
- rebase with the current linus tree
Changes in rfc v5:
- rewrite whole patchset from scratch
- move arch-dependent code of arch/um and arch/x86/um to tools/um
- mainly code under os-Linux/ involved
- introduce 2-stage build (kernel, and host-dependent parts)
- clean up vmlinux.lds.S
- put LKL-specific implementations as a SUBARCH under arch/um/nommu
- introduce !CONFIG_MMU in arch/um
- use struct arch_thread and arch_switch_to() for subarch-specific thread implementation
- integrate with the IRQ infrastructure of UML
- tested with block device drivers (ubd) for the proof
Changes in rfc v4: (https://lwn.net/Articles/816276/)
- Rebase on the current uml/master branch
- Fix IRQ handling (bug fix)
- drop a patch for CONFIG_GENERIC_ATOMIC64 (comment by Peter Zijlstra)
- implement vector net driver for UMMODE_LIB (comment by Anton)
- clean up uapi headers to avoid duplicates
- clean up IRQ handling code (comment by Anton)
- fix error handling in test code (comments by David Disseldorp)
Changes in rfc v3:
- use UML drivers (net, block) from LKL programs
- drop virtio device implementations
- drop mingw32 (Windows) host
- drop android (arm/aarch64) host
- drop FreeBSD (x86_64) host
- drop LD_PRELOAD (hijack) support
- update milestone
rfc v2:
- use UMMODE instead of SUBARCH to switch UML or LKL
- tools/lkl directory is still there. I confirmed we can move under arch/um (e.g., arch/um/lkl/hosts). I will move it IF this is preferable.
- drop several patches involved non-uml directory
- drop several patches which are not required
- refine commit logs
- document updated
LKL (Linux Kernel Library) is aiming to allow reusing the Linux kernel code as extensively as possible with minimal effort and reduced maintenance overhead.
Examples of how LKL can be used are: creating userspace applications (running on Linux and other operating systems) that can read or write Linux filesystems or can use the Linux networking stack, creating kernel drivers for other operating systems that can read Linux filesystems, bootloaders support for reading/writing Linux filesystems, etc.
With LKL, the kernel code is compiled into an object file that can be directly linked by applications. The API offered by LKL is based on the Linux system call interface.
LKL is originally implemented as an architecture port in arch/lkl, but this series of commits tries to integrate this into arch/um as one of the mode of UML. This was discussed during RFC email of LKL (*1).
The latest LKL version can be found at https://github.com/lkl/linux
Milestone
=========
This patches is a first step toward upstreaming *library mode* of Linux kernel, but we think we need to have several steps toward our goal, describing in the below.
Milestone 1: LKL lib on top of UML
* Kernel - Host build split
- Build UML as a relocatable object using the UML's kernel linker script.
- Move the ptrace and other well isolated os code out of arch/um to tools/um
- Use standard host toolchain to create a static library stripped of the ptrace code. Use standard host toolchain to build the main UML executable.
- Add library init API that creates the UML kernel process and starts UML.
* System calls APIs
- Add new system call interface based on UML's irq facility.
- Use the LKL scripts to export the required headers to create system calls APIs that use the UML system calls infrastructure.
- Keep the underlying host and driver operations (threads, irqs, etc.) as they are now in UML.
* Boot test
- Port the LKL boot test to verify that we are able to programatically issue system calls.
Milestone 2: add virtio disk support
* Export asm/io.h operations to host/os. Create IO access operations and redirect them to weak os_ variants that use the current UML implementation.
* Add the LKL IO access layer including generic virtio handling and the virtio block device code.
* Port LKL disk test and disk apps (lklfuse, fs2tar, cptofs)
Milestone 3: new arch ports
* Abstract the system call / IRQ mode the move the implementation to host
* Abstract the thread model and move the implementation to host
* Add LKL thread model and LKL ports
Building LKL the host library and LKL applications
==================================================
% cd tools/um
% make
will build LKL as a object file, it will install it in tools/um/lib together with the headers files in tools/um/include then will build the host library, tests and a few of application examples:
* tests/boot - a simple applications that uses LKL and exercises the basic LKL APIs
% make run-tests
should run the above tests/boot and tests/net-test and report errors if there are any.
Supported hosts
===============
Currently LKL supports Linux userspace applications. New hosts can be added relatively easy if the host supports gcc and GNU ld. Previous versions of LKL supported Windows kernel and Haiku kernel hosts, and we also have WIP patches with rump-hypercall interface, used in UEFI, as well as macOS userspace (part of POSIX).
There is also musl-libc port for LKL, which might be interested in for some folks.
Further readings about LKL
=========================
- Discussion in github LKL issue
https://github.com/lkl/linux/issues/304
- LKL (an article)
https://www.researchgate.net/profile/Nicolae_Tapus2/publication/224164682_LKL_The_Linux_kernel_library/links/02bfe50fd921ab4f7c000000.pdf
*1 RFC email to LKML (back in 2015)
https://www.mail-archive.com/[email protected]/msg1012277.html
Please review the following changes for suitability for inclusion. If you have any objections or suggestions for improvement, please respond to the patches. If you agree with the changes, please provide your Acked-by.
The following changes since commit 805c6d3c19210c90c109107d189744e960eae025:
Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs (2020-09-22 15:08:41 -0700)
are available in the Git repository at:
git://github.com/thehajime/linux b7b911105ecec6fd84f59e56d3a2c1789002bcbd
https://github.com/thehajime/linux/tree/uml-lkl-5.9rc6-v6
Hajime Tazaki (18):
um: move arch/um/os-Linux dir to tools/um/uml
um: move arch/x86/um/os-Linux to tools/um/uml/
scritps: um: suppress warnings if SRCARCH=um
um: extend arch_switch_to for alternate SUBARCH
um: add nommu mode for UML library mode
um: nommu: host interface
um: nommu: memory handling
um: nommu: kernel thread support
um: nommu: system call interface and application API
um: nommu: basic console support
um: nommu: initialization and cleanup
um: nommu: integrate with irq infrastructure of UML
um: nommu: plug in the build system
um: host: add nommu build for ARCH=um
um: host: add utilities functions
um: host: posix host operations
um: host: add test programs
um: nommu: add block device support of UML
Octavian Purdila (3):
um: split build in kernel and host parts
um: add os init and exit calls
um: host: implement os_initcalls and os_exitcalls
arch/um/Kconfig | 29 +-
arch/um/Makefile | 25 +-
arch/um/drivers/Makefile | 10 +-
.../um/{os-Linux => }/drivers/ethertap_kern.c | 0
arch/um/{os-Linux => }/drivers/tuntap_kern.c | 0
arch/um/include/asm/common.lds.S | 99 ----
arch/um/include/asm/host_ops.h | 9 +
arch/um/include/asm/mmu.h | 3 +
arch/um/include/asm/mmu_context.h | 8 +
arch/um/include/asm/page.h | 15 +
arch/um/include/asm/pgtable.h | 27 +
arch/um/include/asm/thread_info.h | 24 +
arch/um/include/asm/uaccess.h | 6 +
arch/um/include/asm/xor.h | 3 +-
arch/um/include/shared/as-layout.h | 1 +
.../drivers => include/shared}/etap.h | 0
arch/um/include/shared/init.h | 19 +-
arch/um/include/shared/os.h | 1 +
.../drivers => include/shared}/tuntap.h | 0
arch/um/include/uapi/asm/Kbuild | 2 +
arch/um/kernel/Makefile | 12 +-
arch/um/kernel/dyn.lds.S | 171 -------
arch/um/kernel/irq.c | 13 +
arch/um/kernel/process.c | 14 +-
arch/um/kernel/reboot.c | 5 +
arch/um/kernel/time.c | 2 +
arch/um/kernel/um_arch.c | 16 +
arch/um/kernel/uml.lds.S | 115 -----
arch/um/kernel/vmlinux.lds.S | 91 +++-
arch/um/nommu/Makefile | 1 +
arch/um/nommu/Makefile.um | 18 +
arch/um/nommu/include/asm/Kbuild | 6 +
arch/um/nommu/include/asm/archparam.h | 1 +
arch/um/nommu/include/asm/atomic.h | 11 +
arch/um/nommu/include/asm/atomic64.h | 114 +++++
arch/um/nommu/include/asm/bitsperlong.h | 12 +
arch/um/nommu/include/asm/byteorder.h | 7 +
arch/um/nommu/include/asm/cpu.h | 16 +
arch/um/nommu/include/asm/elf.h | 15 +
arch/um/nommu/include/asm/mm_context.h | 8 +
arch/um/nommu/include/asm/processor.h | 46 ++
arch/um/nommu/include/asm/ptrace.h | 21 +
arch/um/nommu/include/asm/sched.h | 23 +
arch/um/nommu/include/asm/segment.h | 9 +
arch/um/nommu/include/asm/syscall_wrapper.h | 57 +++
arch/um/nommu/include/asm/syscalls.h | 15 +
arch/um/nommu/include/uapi/asm/Kbuild | 4 +
arch/um/nommu/include/uapi/asm/bitsperlong.h | 11 +
arch/um/nommu/include/uapi/asm/byteorder.h | 11 +
arch/um/nommu/include/uapi/asm/host_ops.h | 122 +++++
arch/um/nommu/include/uapi/asm/sigcontext.h | 12 +
arch/um/nommu/include/uapi/asm/syscalls.h | 287 +++++++++++
arch/um/nommu/include/uapi/asm/unistd.h | 17 +
arch/um/nommu/um/Kconfig | 45 ++
arch/um/nommu/um/Makefile | 4 +
arch/um/nommu/um/bootmem.c | 86 ++++
arch/um/nommu/um/console.c | 42 ++
arch/um/nommu/um/cpu.c | 247 ++++++++++
arch/um/nommu/um/delay.c | 31 ++
arch/um/nommu/um/setup.c | 179 +++++++
arch/um/nommu/um/shared/sysdep/archsetjmp.h | 13 +
arch/um/nommu/um/shared/sysdep/faultinfo.h | 8 +
.../nommu/um/shared/sysdep/kernel-offsets.h | 12 +
arch/um/nommu/um/shared/sysdep/mcontext.h | 9 +
arch/um/nommu/um/shared/sysdep/ptrace.h | 42 ++
arch/um/nommu/um/shared/sysdep/ptrace_user.h | 7 +
arch/um/nommu/um/syscalls.c | 199 ++++++++
arch/um/nommu/um/threads.c | 261 ++++++++++
arch/um/nommu/um/unimplemented.c | 70 +++
arch/um/nommu/um/user_constants.h | 13 +
arch/um/os-Linux/Makefile | 19 -
arch/um/os-Linux/drivers/Makefile | 13 -
arch/um/scripts/headers_install.py | 197 ++++++++
arch/x86/um/Makefile | 2 +-
arch/x86/um/os-Linux/Makefile | 13 -
arch/x86/um/ptrace_32.c | 2 +-
arch/x86/um/syscalls_64.c | 2 +-
scripts/headers_install.sh | 4 +
scripts/link-vmlinux.sh | 42 +-
tools/um/Makefile | 82 ++++
tools/um/Targets | 13 +
tools/um/include/lkl.h | 357 ++++++++++++++
tools/um/include/lkl_host.h | 27 +
tools/um/lib/Build | 7 +
tools/um/lib/fs.c | 461 ++++++++++++++++++
tools/um/lib/jmp_buf.c | 14 +
tools/um/lib/jmp_buf.h | 8 +
tools/um/lib/posix-host.c | 293 +++++++++++
tools/um/lib/utils.c | 213 ++++++++
tools/um/tests/Build | 2 +
tools/um/tests/boot.c | 393 +++++++++++++++
tools/um/tests/boot.sh | 9 +
tools/um/tests/cla.c | 159 ++++++
tools/um/tests/cla.h | 33 ++
tools/um/tests/disk.c | 168 +++++++
tools/um/tests/disk.sh | 70 +++
tools/um/tests/run.py | 174 +++++++
tools/um/tests/tap13.py | 209 ++++++++
tools/um/tests/test.c | 126 +++++
tools/um/tests/test.h | 72 +++
tools/um/tests/test.sh | 181 +++++++
tools/um/uml/Build | 57 +++
tools/um/uml/drivers/Build | 10 +
.../um/uml}/drivers/ethertap_user.c | 0
.../um/uml}/drivers/tuntap_user.c | 0
{arch/um/os-Linux => tools/um/uml}/elf_aux.c | 0
{arch/um/os-Linux => tools/um/uml}/execvp.c | 4 -
{arch/um/os-Linux => tools/um/uml}/file.c | 0
{arch/um/os-Linux => tools/um/uml}/helper.c | 0
{arch/um/os-Linux => tools/um/uml}/irq.c | 0
{arch/um/os-Linux => tools/um/uml}/main.c | 0
{arch/um/os-Linux => tools/um/uml}/mem.c | 0
tools/um/uml/nommu/Build | 1 +
tools/um/uml/nommu/registers.c | 21 +
tools/um/uml/nommu/unimplemented.c | 21 +
{arch/um/os-Linux => tools/um/uml}/process.c | 2 +
.../um/os-Linux => tools/um/uml}/registers.c | 0
{arch/um/os-Linux => tools/um/uml}/sigio.c | 0
{arch/um/os-Linux => tools/um/uml}/signal.c | 12 +-
.../skas/Makefile => tools/um/uml/skas/Build | 6 +-
{arch/um/os-Linux => tools/um/uml}/skas/mem.c | 0
.../os-Linux => tools/um/uml}/skas/process.c | 3 +-
{arch/um/os-Linux => tools/um/uml}/start_up.c | 0
{arch/um/os-Linux => tools/um/uml}/time.c | 0
{arch/um/os-Linux => tools/um/uml}/tty.c | 0
{arch/um/os-Linux => tools/um/uml}/umid.c | 0
.../um/os-Linux => tools/um/uml}/user_syms.c | 1 +
{arch/um/os-Linux => tools/um/uml}/util.c | 26 +
tools/um/uml/x86/Build | 11 +
.../os-Linux => tools/um/uml/x86}/mcontext.c | 0
.../um/os-Linux => tools/um/uml/x86}/prctl.c | 0
.../os-Linux => tools/um/uml/x86}/registers.c | 0
.../os-Linux => tools/um/uml/x86}/task_size.c | 0
.../um/os-Linux => tools/um/uml/x86}/tls.c | 0
134 files changed, 5850 insertions(+), 522 deletions(-)
rename arch/um/{os-Linux => }/drivers/ethertap_kern.c (100%)
rename arch/um/{os-Linux => }/drivers/tuntap_kern.c (100%)
delete mode 100644 arch/um/include/asm/common.lds.S
create mode 100644 arch/um/include/asm/host_ops.h
rename arch/um/{os-Linux/drivers => include/shared}/etap.h (100%)
rename arch/um/{os-Linux/drivers => include/shared}/tuntap.h (100%)
create mode 100644 arch/um/include/uapi/asm/Kbuild
delete mode 100644 arch/um/kernel/dyn.lds.S
delete mode 100644 arch/um/kernel/uml.lds.S
create mode 100644 arch/um/nommu/Makefile
create mode 100644 arch/um/nommu/Makefile.um
create mode 100644 arch/um/nommu/include/asm/Kbuild
create mode 100644 arch/um/nommu/include/asm/archparam.h
create mode 100644 arch/um/nommu/include/asm/atomic.h
create mode 100644 arch/um/nommu/include/asm/atomic64.h
create mode 100644 arch/um/nommu/include/asm/bitsperlong.h
create mode 100644 arch/um/nommu/include/asm/byteorder.h
create mode 100644 arch/um/nommu/include/asm/cpu.h
create mode 100644 arch/um/nommu/include/asm/elf.h
create mode 100644 arch/um/nommu/include/asm/mm_context.h
create mode 100644 arch/um/nommu/include/asm/processor.h
create mode 100644 arch/um/nommu/include/asm/ptrace.h
create mode 100644 arch/um/nommu/include/asm/sched.h
create mode 100644 arch/um/nommu/include/asm/segment.h
create mode 100644 arch/um/nommu/include/asm/syscall_wrapper.h
create mode 100644 arch/um/nommu/include/asm/syscalls.h
create mode 100644 arch/um/nommu/include/uapi/asm/Kbuild
create mode 100644 arch/um/nommu/include/uapi/asm/bitsperlong.h
create mode 100644 arch/um/nommu/include/uapi/asm/byteorder.h
create mode 100644 arch/um/nommu/include/uapi/asm/host_ops.h
create mode 100644 arch/um/nommu/include/uapi/asm/sigcontext.h
create mode 100644 arch/um/nommu/include/uapi/asm/syscalls.h
create mode 100644 arch/um/nommu/include/uapi/asm/unistd.h
create mode 100644 arch/um/nommu/um/Kconfig
create mode 100644 arch/um/nommu/um/Makefile
create mode 100644 arch/um/nommu/um/bootmem.c
create mode 100644 arch/um/nommu/um/console.c
create mode 100644 arch/um/nommu/um/cpu.c
create mode 100644 arch/um/nommu/um/delay.c
create mode 100644 arch/um/nommu/um/setup.c
create mode 100644 arch/um/nommu/um/shared/sysdep/archsetjmp.h
create mode 100644 arch/um/nommu/um/shared/sysdep/faultinfo.h
create mode 100644 arch/um/nommu/um/shared/sysdep/kernel-offsets.h
create mode 100644 arch/um/nommu/um/shared/sysdep/mcontext.h
create mode 100644 arch/um/nommu/um/shared/sysdep/ptrace.h
create mode 100644 arch/um/nommu/um/shared/sysdep/ptrace_user.h
create mode 100644 arch/um/nommu/um/syscalls.c
create mode 100644 arch/um/nommu/um/threads.c
create mode 100644 arch/um/nommu/um/unimplemented.c
create mode 100644 arch/um/nommu/um/user_constants.h
delete mode 100644 arch/um/os-Linux/Makefile
delete mode 100644 arch/um/os-Linux/drivers/Makefile
create mode 100755 arch/um/scripts/headers_install.py
delete mode 100644 arch/x86/um/os-Linux/Makefile
create mode 100644 tools/um/Makefile
create mode 100644 tools/um/Targets
create mode 100644 tools/um/include/lkl.h
create mode 100644 tools/um/include/lkl_host.h
create mode 100644 tools/um/lib/Build
create mode 100644 tools/um/lib/fs.c
create mode 100644 tools/um/lib/jmp_buf.c
create mode 100644 tools/um/lib/jmp_buf.h
create mode 100644 tools/um/lib/posix-host.c
create mode 100644 tools/um/lib/utils.c
create mode 100644 tools/um/tests/Build
create mode 100644 tools/um/tests/boot.c
create mode 100755 tools/um/tests/boot.sh
create mode 100644 tools/um/tests/cla.c
create mode 100644 tools/um/tests/cla.h
create mode 100644 tools/um/tests/disk.c
create mode 100755 tools/um/tests/disk.sh
create mode 100755 tools/um/tests/run.py
create mode 100644 tools/um/tests/tap13.py
create mode 100644 tools/um/tests/test.c
create mode 100644 tools/um/tests/test.h
create mode 100644 tools/um/tests/test.sh
create mode 100644 tools/um/uml/Build
create mode 100644 tools/um/uml/drivers/Build
rename {arch/um/os-Linux => tools/um/uml}/drivers/ethertap_user.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/drivers/tuntap_user.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/elf_aux.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/execvp.c (98%)
rename {arch/um/os-Linux => tools/um/uml}/file.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/helper.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/irq.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/main.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/mem.c (100%)
create mode 100644 tools/um/uml/nommu/Build
create mode 100644 tools/um/uml/nommu/registers.c
create mode 100644 tools/um/uml/nommu/unimplemented.c
rename {arch/um/os-Linux => tools/um/uml}/process.c (99%)
rename {arch/um/os-Linux => tools/um/uml}/registers.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/sigio.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/signal.c (96%)
rename arch/um/os-Linux/skas/Makefile => tools/um/uml/skas/Build (56%)
rename {arch/um/os-Linux => tools/um/uml}/skas/mem.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/skas/process.c (99%)
rename {arch/um/os-Linux => tools/um/uml}/start_up.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/time.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/tty.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/umid.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/user_syms.c (99%)
rename {arch/um/os-Linux => tools/um/uml}/util.c (89%)
create mode 100644 tools/um/uml/x86/Build
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/mcontext.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/prctl.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/registers.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/task_size.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/tls.c (100%)Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 1/21 um: split build in kernel and host parts
From: Octavian Purdila <[email protected]>
This patch splits the UML build in two parts: a kernel part that generates a relocatable object (linux.o) and a host build part that links the relocatable object into an executable.
This allows us to simplify the linker script since we can now remove the host bits (e.g. .rel sections). It also gives us greater flexibility since it will be much easier to support other architectures and OSes if we use the standard linker script.
The host build part has been implemented in tools/um so that we can reuse the available host build infrastructure.
The patch also changes the UML build invocation, if before
$ make ARCH=um defconfig $ make ARCH=um
was generating the executable now this only generates the relocatable object.
To fully build UML use:
$ make -C tools/um
which will generate tools/lkl/linux as the UML executable. To statically compiled UML use:
$ make -C tools/lkl UML_STATIC=y
--- arch/um/Kconfig | 12 +-- arch/um/Makefile | 14 ++- arch/um/include/asm/common.lds.S | 99 ------------------ arch/um/kernel/dyn.lds.S | 171 ------------------------------- arch/um/kernel/uml.lds.S | 115 --------------------- arch/um/kernel/vmlinux.lds.S | 91 ++++++++++++++-- scripts/link-vmlinux.sh | 42 +++----- tools/um/Makefile | 72 +++++++++++++ tools/um/Targets | 4 + tools/um/uml/Build | 0 10 files changed, 184 insertions(+), 436 deletions(-) delete mode 100644 arch/um/include/asm/common.lds.S delete mode 100644 arch/um/kernel/dyn.lds.S delete mode 100644 arch/um/kernel/uml.lds.S create mode 100644 tools/um/Makefile create mode 100644 tools/um/Targets create mode 100644 tools/um/uml/Build
arch/um/Kconfig +1 -11
@@ -20,6 +20,7 @@ config UML select GENERIC_CLOCKEVENTS select HAVE_GCC_PLUGINS select TTY # Needed for line.c + select MODULE_REL_CRCS if MODVERSIONS config MMU bool
@@ -79,17 +80,6 @@ config STATIC_LINK NOTE: This option is incompatible with some networking features which depend on features that require being dynamically loaded (like NSS). -config LD_SCRIPT_STATIC - bool - default y - depends on STATIC_LINK - -config LD_SCRIPT_DYN - bool - default y - depends on !LD_SCRIPT_STATIC - select MODULE_REL_CRCS if MODVERSIONS - config HOSTFS tristate "Host filesystem" help
arch/um/Makefile +10 -4
@@ -95,14 +95,20 @@ KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/include \ KERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \ -Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES)) KBUILD_CFLAGS += $(KERNEL_DEFINES) +LDFLAGS_vmlinux += -r -PHONY += linux +PHONY += linux.o -all: linux +all: linux.o -linux: vmlinux +linux.o: vmlinux @echo ' LINK $@' - $(Q)ln -f $< $@ + $(Q)$(OBJCOPY) -R .eh_frame $< $@ + +install: linux.o + @echo " INSTALL $(INSTALL_PATH)/lib/$<" + @mkdir -p $(INSTALL_PATH)/lib/ + @cp $< $(INSTALL_PATH)/lib/ define archhelp echo '* linux - Binary kernel image (./linux) - for backward'
arch/um/include/asm/common.lds.S deleted +0 -99
99 lines not on this page · raw message
arch/um/kernel/dyn.lds.S deleted +0 -171
171 lines not on this page · raw message
arch/um/kernel/uml.lds.S deleted +0 -115
115 lines not on this page · raw message
arch/um/kernel/vmlinux.lds.S +85 -6
93 lines not on this page · raw message
scripts/link-vmlinux.sh +12 -30
48 lines not on this page · raw message
tools/um/Makefile new file +72 -0
72 lines not on this page · raw message
tools/um/Targets new file +4 -0
@@ -0,0 +1,4 @@ +progs-y += uml/linux +LDLIBS_linux-y := -lrt -lpthread -lutil +LDFLAGS_linux-y := -no-pie -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc +LDFLAGS_linux-$(UML_STATIC) += -static
tools/um/uml/Build new file +0 -0
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 2/21 um: add os init and exit calls
In reply to Hajime TazakiFrom: Octavian Purdila <[email protected]>
These calls are added in preparation for moving some of the code from the kernel to the host build.
--- arch/um/include/shared/init.h | 14 ++++---------- arch/um/kernel/reboot.c | 5 +++++ arch/um/kernel/um_arch.c | 11 +++++++++++ 3 files changed, 20 insertions(+), 10 deletions(-)
arch/um/include/shared/init.h +4 -10
@@ -109,19 +109,13 @@ extern struct uml_param __uml_setup_start, __uml_setup_end;#ifdef __UM_HOST__ -#define __define_initcall (level,fn) \ - static initcall_t __initcall_##fn __used \ - __attribute__((__section__(".initcall" level ".init"))) = fn - -/* Userspace initcalls shouldn't depend on anything in the kernel, so we'll -* make them run first. -*/ -#define __initcall (fn) __define_initcall("1", fn) +#undef __uml_exit_call +#define __uml_exit_call __used __section(os_exitcalls) +#define __init_call __used __section(os_initcalls) +#define __initcall (fn) static initcall_t __initcall_##fn __init_call = fn#define __exitcall (fn) static exitcall_t __exitcall_##fn __exit_call = fn -#define __init_call __used __section(.initcall.init) -#endif #endif /* _LINUX_UML_INIT_H */
arch/um/kernel/reboot.c +5 -0
@@ -35,10 +35,15 @@ static void kill_off_processes(void)read_unlock (&tasklist_lock); } +void __weak os_exitcalls (void ) +{ +} +void uml_cleanup (void ) { kmalloc_ok =0 ;do_uml_exitcalls (); +os_exitcalls ();kill_off_processes (); }
arch/um/kernel/um_arch.c +11 -0
@@ -377,3 +377,14 @@ void *text_poke(void *addr, const void *opcode, size_t len)void text_poke_sync (void ) { } + +int __weak os_initcalls (void ) +{ +return 0 ; +} + +int __init run_os_initcalls (void ) +{ +return os_initcalls (); +} +early_initcall (run_os_initcalls);
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 3/21 um: move arch/um/os-Linux dir to tools/um/uml
In reply to Hajime TazakiThis patch moves underlying OS dependent part under arch/um to tools/um directory so that arch/um code does not need to build host build facilities (e.g., libc).
---
arch/um/Makefile | 3 +-
arch/um/drivers/Makefile | 2 +
.../um/{os-Linux => }/drivers/ethertap_kern.c | 0
arch/um/{os-Linux => }/drivers/tuntap_kern.c | 0
.../drivers => include/shared}/etap.h | 0
arch/um/include/shared/init.h | 5 ++
.../drivers => include/shared}/tuntap.h | 0
arch/um/os-Linux/Makefile | 19 --------
arch/um/os-Linux/drivers/Makefile | 13 -----
tools/um/Makefile | 6 ++-
tools/um/uml/Build | 48 +++++++++++++++++++
tools/um/uml/drivers/Build | 10 ++++
.../um/uml}/drivers/ethertap_user.c | 0
.../um/uml}/drivers/tuntap_user.c | 0
{arch/um/os-Linux => tools/um/uml}/elf_aux.c | 0
{arch/um/os-Linux => tools/um/uml}/execvp.c | 4 --
{arch/um/os-Linux => tools/um/uml}/file.c | 0
{arch/um/os-Linux => tools/um/uml}/helper.c | 0
{arch/um/os-Linux => tools/um/uml}/irq.c | 0
{arch/um/os-Linux => tools/um/uml}/main.c | 0
{arch/um/os-Linux => tools/um/uml}/mem.c | 0
{arch/um/os-Linux => tools/um/uml}/process.c | 0
.../um/os-Linux => tools/um/uml}/registers.c | 0
{arch/um/os-Linux => tools/um/uml}/sigio.c | 0
{arch/um/os-Linux => tools/um/uml}/signal.c | 0
.../skas/Makefile => tools/um/uml/skas/Build | 6 +--
{arch/um/os-Linux => tools/um/uml}/skas/mem.c | 0
.../os-Linux => tools/um/uml}/skas/process.c | 3 +-
{arch/um/os-Linux => tools/um/uml}/start_up.c | 0
{arch/um/os-Linux => tools/um/uml}/time.c | 0
{arch/um/os-Linux => tools/um/uml}/tty.c | 0
{arch/um/os-Linux => tools/um/uml}/umid.c | 0
.../um/os-Linux => tools/um/uml}/user_syms.c | 1 +
{arch/um/os-Linux => tools/um/uml}/util.c | 0
34 files changed, 74 insertions(+), 46 deletions(-)
rename arch/um/{os-Linux => }/drivers/ethertap_kern.c (100%)
rename arch/um/{os-Linux => }/drivers/tuntap_kern.c (100%)
rename arch/um/{os-Linux/drivers => include/shared}/etap.h (100%)
rename arch/um/{os-Linux/drivers => include/shared}/tuntap.h (100%)
delete mode 100644 arch/um/os-Linux/Makefile
delete mode 100644 arch/um/os-Linux/drivers/Makefile
create mode 100644 tools/um/uml/drivers/Build
rename {arch/um/os-Linux => tools/um/uml}/drivers/ethertap_user.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/drivers/tuntap_user.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/elf_aux.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/execvp.c (98%)
rename {arch/um/os-Linux => tools/um/uml}/file.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/helper.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/irq.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/main.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/mem.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/process.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/registers.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/sigio.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/signal.c (100%)
rename arch/um/os-Linux/skas/Makefile => tools/um/uml/skas/Build (56%)
rename {arch/um/os-Linux => tools/um/uml}/skas/mem.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/skas/process.c (99%)
rename {arch/um/os-Linux => tools/um/uml}/start_up.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/time.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/tty.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/umid.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/user_syms.c (99%)
rename {arch/um/os-Linux => tools/um/uml}/util.c (100%)arch/um/Makefile +1 -2
@@ -24,8 +24,7 @@ OS := $(shell uname -s) SHELL := /bin/bash core-y += $(ARCH_DIR)/kernel/ \ - $(ARCH_DIR)/drivers/ \ - $(ARCH_DIR)/os-$(OS)/ + $(ARCH_DIR)/drivers/ MODE_INCLUDE += -I$(srctree)/$(ARCH_DIR)/include/shared/skas
arch/um/drivers/Makefile +2 -0
@@ -48,6 +48,8 @@ obj-$(CONFIG_UML_NET_VECTOR) += vector.o obj-$(CONFIG_UML_NET_VDE) += vde.o obj-$(CONFIG_UML_NET_MCAST) += umcast.o obj-$(CONFIG_UML_NET_PCAP) += pcap.o +obj-$(CONFIG_UML_NET_ETHERTAP) += ethertap_kern.o +obj-$(CONFIG_UML_NET_TUNTAP) += tuntap_kern.o obj-$(CONFIG_UML_NET) += net.o obj-$(CONFIG_MCONSOLE) += mconsole.o obj-$(CONFIG_MMAPPER) += mmapper_kern.o
arch/um/drivers/ethertap_kern.c renamed from arch/um/os-Linux/drivers/ethertap_kern.c +0 -0
arch/um/drivers/tuntap_kern.c renamed from arch/um/os-Linux/drivers/tuntap_kern.c +0 -0
arch/um/include/shared/etap.h renamed from arch/um/os-Linux/drivers/etap.h +0 -0
arch/um/include/shared/init.h +5 -0
@@ -41,7 +41,12 @@typedef int (*initcall_t )(void );typedef void (*exitcall_t )(void ); +#ifndef __UM_HOST__#include <linux/compiler_types.h> +#else +#define __used __attribute__((__used__)) +#define __section (S ) __attribute__((__section__(#S))) +#endif /* These are for everybody (although not all archs will actually discard it in modules) */
arch/um/include/shared/tuntap.h renamed from arch/um/os-Linux/drivers/tuntap.h +0 -0
arch/um/os-Linux/Makefile deleted +0 -19
@@ -1,19 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) -# - -# Don't instrument UML-specific code -KCOV_INSTRUMENT := n - -obj-y = execvp.o file.o helper.o irq.o main.o mem.o process.o \ - registers.o sigio.o signal.o start_up.o time.o tty.o \ - umid.o user_syms.o util.o drivers/ skas/ - -obj-$(CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA) += elf_aux.o - -USER_OBJS := $(user-objs-y) elf_aux.o execvp.o file.o helper.o irq.o \ - main.o mem.o process.o registers.o sigio.o signal.o start_up.o time.o \ - tty.o umid.o util.o - -include arch/um/scripts/Makefile.rules
arch/um/os-Linux/drivers/Makefile deleted +0 -13
@@ -1,13 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# Copyright (C) 2000, 2002 Jeff Dike ([email protected]) -# - -ethertap-objs := ethertap_kern.o ethertap_user.o -tuntap-objs := tuntap_kern.o tuntap_user.o - -obj-y = -obj-$(CONFIG_UML_NET_ETHERTAP) += ethertap.o -obj-$(CONFIG_UML_NET_TUNTAP) += tuntap.o - -include arch/um/scripts/Makefile.rules
tools/um/Makefile +5 -1
@@ -50,7 +50,7 @@ $(OUTPUT)lib/linux.o: $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) $(KCONFIG) $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) install INSTALL_PATH=$(OUTPUT) -$(OUTPUT)liblinux.a: $(OUTPUT)lib/linux.o $(OUTPUT)uml/liblinux-in.o +$(OUTPUT)liblinux.a: $(OUTPUT)lib/linux.o $(OUTPUT)uml/liblinux-in.o $(OUTPUT)lib/liblinux-in.o $(QUIET_AR)$(AR) -rc $@ $^ # rule to link programs
@@ -60,6 +60,10 @@ $(OUTPUT)%: $(OUTPUT)%-in.o $(OUTPUT)liblinux.a $(OUTPUT)%-in.o: FORCE $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) +# rule to build objects +$(OUTPUT)%-in.o: $(OUTPUT)lib/linux.o + $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) + clean: $(call QUIET_CLEAN, objects)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd'\ -delete -o -name '\.*.d' -delete
tools/um/uml/Build +48 -0
48 lines not on this page · raw message
tools/um/uml/drivers/Build new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2000, 2002 Jeff Dike ([email protected]) +# + +include $(objtree)/include/config/auto.conf + + +liblinux-$(CONFIG_UML_NET_ETHERTAP) += ethertap_user.o +liblinux-$(CONFIG_UML_NET_TUNTAP) += tuntap_user.o
tools/um/uml/drivers/ethertap_user.c renamed from arch/um/os-Linux/drivers/ethertap_user.c +0 -0
tools/um/uml/drivers/tuntap_user.c renamed from arch/um/os-Linux/drivers/tuntap_user.c +0 -0
tools/um/uml/elf_aux.c renamed from arch/um/os-Linux/elf_aux.c +0 -0
tools/um/uml/execvp.c renamed from arch/um/os-Linux/execvp.c +0 -4
@@ -26,12 +26,8 @@#include <errno.h> #include <limits.h> -#ifndef TEST -#include <um_malloc.h> -#else #include <stdio.h> #define um_kmalloc malloc -#endif #include <os.h> /* Execute FILE, searching in the `PATH' environment variable if it contains
tools/um/uml/file.c renamed from arch/um/os-Linux/file.c +0 -0
tools/um/uml/helper.c renamed from arch/um/os-Linux/helper.c +0 -0
tools/um/uml/irq.c renamed from arch/um/os-Linux/irq.c +0 -0
tools/um/uml/main.c renamed from arch/um/os-Linux/main.c +0 -0
tools/um/uml/mem.c renamed from arch/um/os-Linux/mem.c +0 -0
tools/um/uml/process.c renamed from arch/um/os-Linux/process.c +0 -0
tools/um/uml/registers.c renamed from arch/um/os-Linux/registers.c +0 -0
tools/um/uml/sigio.c renamed from arch/um/os-Linux/sigio.c +0 -0
tools/um/uml/signal.c renamed from arch/um/os-Linux/signal.c +0 -0
tools/um/uml/skas/Build renamed from arch/um/os-Linux/skas/Makefile +1 -5
@@ -3,8 +3,4 @@ # Copyright (C) 2002 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com) # -obj-y := mem.o process.o - -USER_OBJS := $(obj-y) - -include arch/um/scripts/Makefile.rules +liblinux-y += mem.o process.o
tools/um/uml/skas/mem.c renamed from arch/um/os-Linux/skas/mem.c +0 -0
tools/um/uml/skas/process.c renamed from arch/um/os-Linux/skas/process.c +1 -2
@@ -21,7 +21,6 @@#include <registers.h> #include <skas.h> #include <sysdep/stub.h> -#include <linux/threads.h> int is_skas_winch (int pid,int fd,void *data) {
@@ -248,7 +247,7 @@ static int userspace_tramp(void *stack)return 0 ; } -int userspace_pid[NR_CPUS ]; +int userspace_pid[UM_NR_CPUS ];/** * start_userspace() - prepare a new userspace process
tools/um/uml/start_up.c renamed from arch/um/os-Linux/start_up.c +0 -0
tools/um/uml/time.c renamed from arch/um/os-Linux/time.c +0 -0
tools/um/uml/tty.c renamed from arch/um/os-Linux/tty.c +0 -0
tools/um/uml/umid.c renamed from arch/um/os-Linux/umid.c +0 -0
tools/um/uml/user_syms.c renamed from arch/um/os-Linux/user_syms.c +1 -0
@@ -13,6 +13,7 @@#undef strstr#undef memcpy#undef memset +#define EXPORT_SYMBOL (x)extern size_t strlen (const char *);extern void *memmove (void *,const void *,size_t );
tools/um/uml/util.c renamed from arch/um/os-Linux/util.c +0 -0
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 4/21 um: host: implement os_initcalls and os_exitcalls
In reply to Hajime TazakiFrom: Octavian Purdila <[email protected]>
This patch implements the init and exit calls for host code. It uses the automatic __start_<section> and __stop_<section> variables that are defined by gcc / ld when using custom sections.
Note that this patch should be merged with "um: move arch/um/os-Linux dir to tools/um" but for now it is separate to make the review easier.
--- tools/um/uml/util.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
tools/um/uml/util.c +26 -0
@@ -186,3 +186,29 @@ void os_warn(const char *fmt, ...)vfprintf (stderr, fmt, list);va_end (list); } + +extern void (*__start_os_exitcalls)(void ); +extern void (*__stop_os_exitcalls)(void ); + +void os_exitcalls (void ) +{ +exitcall_t *call; + + call = &__stop_os_exitcalls; +while (--call >= &__start_os_exitcalls) + (*call)(); +} + +extern int (*__start_os_initcalls)(void ); +extern int (*__stop_os_initcalls)(void ); + +int os_initcalls (void ) +{ +initcall_t *call; + + call = &__stop_os_initcalls; +while (--call >= &__start_os_initcalls) + (*call)(); + +return 0 ; +}
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 5/21 um: move arch/x86/um/os-Linux to tools/um/uml/
In reply to Hajime TazakiSimilar to arch/um/os-Linux code, arch/x86 also contains OS dependent part as well. This patch moves underlying OS dependent part to tools/um directory so that arch/x86 code does not need to build host build facilities (e.g., libc).
---
arch/x86/um/Makefile | 2 +-
arch/x86/um/os-Linux/Makefile | 13 -------------
tools/um/Makefile | 2 +-
tools/um/uml/Build | 2 ++
tools/um/uml/x86/Build | 11 +++++++++++
.../x86/um/os-Linux => tools/um/uml/x86}/mcontext.c | 0
{arch/x86/um/os-Linux => tools/um/uml/x86}/prctl.c | 0
.../um/os-Linux => tools/um/uml/x86}/registers.c | 0
.../um/os-Linux => tools/um/uml/x86}/task_size.c | 0
{arch/x86/um/os-Linux => tools/um/uml/x86}/tls.c | 0
10 files changed, 15 insertions(+), 15 deletions(-)
delete mode 100644 arch/x86/um/os-Linux/Makefile
create mode 100644 tools/um/uml/x86/Build
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/mcontext.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/prctl.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/registers.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/task_size.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/tls.c (100%)arch/x86/um/Makefile +1 -1
@@ -13,7 +13,7 @@ obj-y = bugs_$(BITS).o delay.o fault.o ldt.o \ ptrace_$(BITS).o ptrace_user.o setjmp_$(BITS).o signal.o \ stub_$(BITS).o stub_segv.o \ sys_call_table_$(BITS).o sysrq_$(BITS).o tls_$(BITS).o \ - mem_$(BITS).o subarch.o os-$(OS)/ + mem_$(BITS).o subarch.o ifeq ($(CONFIG_X86_32),y)
arch/x86/um/os-Linux/Makefile deleted +0 -13
@@ -1,13 +0,0 @@ -# -# Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) -# Licensed under the GPL -# - -obj-y = registers.o task_size.o mcontext.o - -obj-$(CONFIG_X86_32) += tls.o -obj-$(CONFIG_64BIT) += prctl.o - -USER_OBJS := $(obj-y) - -include arch/um/scripts/Makefile.rules
tools/um/Makefile +1 -1
@@ -61,7 +61,7 @@ $(OUTPUT)%-in.o: FORCE $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) # rule to build objects -$(OUTPUT)%-in.o: $(OUTPUT)lib/linux.o +$(OUTPUT)%-in.o: $(OUTPUT)lib/linux.o FORCE $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) clean:
tools/um/uml/Build +2 -0
@@ -12,6 +12,8 @@ liblinux-y += execvp.o file.o helper.o irq.o main.o mem.o process.o \ registers.o sigio.o signal.o start_up.o time.o tty.o \ umid.o user_syms.o util.o drivers/ skas/ +liblinux-y += x86/ + liblinux-$(CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA) += elf_aux.o export O = $(srctree)
tools/um/uml/x86/Build new file +11 -0
@@ -0,0 +1,11 @@ +# +# Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) +# Licensed under the GPL +# + +include $(objtree)/include/config/auto.conf + +liblinux-y = registers.o task_size.o mcontext.o + +liblinux-$(CONFIG_X86_32) += tls.o +liblinux-$(CONFIG_64BIT) += prctl.o
tools/um/uml/x86/mcontext.c renamed from arch/x86/um/os-Linux/mcontext.c +0 -0
tools/um/uml/x86/prctl.c renamed from arch/x86/um/os-Linux/prctl.c +0 -0
tools/um/uml/x86/registers.c renamed from arch/x86/um/os-Linux/registers.c +0 -0
tools/um/uml/x86/task_size.c renamed from arch/x86/um/os-Linux/task_size.c +0 -0
tools/um/uml/x86/tls.c renamed from arch/x86/um/os-Linux/tls.c +0 -0
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 6/21 scritps: um: suppress warnings if SRCARCH=um
In reply to Hajime TazakiThis commit fixes numbers of warning messages about leaked CONFIG options. nommu mode of UML requires copies of kernel headers to offer syscall-like API for the library users. Thus, the warnings are to be avoided to function this exposure of API.
--- scripts/headers_install.sh | 4 ++++ 1 file changed, 4 insertions(+)
scripts/headers_install.sh +4 -0
@@ -93,6 +93,10 @@ include/uapi/linux/pktcdvd.h:CONFIG_CDROM_PKTCDVD_WCACHE for c in $configs do + if [ "$SRCARCH" = "um" ] ; then + break + fi + leak_error=1 for ignore in $config_leak_ignores
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 7/21 um: extend arch_switch_to for alternate SUBARCH
In reply to Hajime TazakiThis commit introduces additional argument of previous task when context switch happens. New SUBARCH can use the new information to switch tasks in a subarch-specific manner.
The patch is particularly required by nommu mode implemented as a SUBARCH of UML.
--- arch/um/kernel/process.c | 6 +++--- arch/x86/um/ptrace_32.c | 2 +- arch/x86/um/syscalls_64.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
arch/um/kernel/process.c +3 -3
@@ -80,7 +80,7 @@ static inline void set_current(struct task_struct *task) { external_pid(), task }); } -extern void arch_switch_to (struct task_struct *to); +extern void arch_switch_to (struct task_struct *from,struct task_struct *to);void *__switch_to (struct task_struct *from,struct task_struct *to) {
@@ -88,7 +88,7 @@ void *__switch_to(struct task_struct *from, struct task_struct *to)set_current (to);switch_threads (&from->thread.switch_buf, &to->thread.switch_buf); -arch_switch_to (current); +arch_switch_to (from, to);return current->thread.prev_sched; }
@@ -145,7 +145,7 @@ void fork_handler(void)* arch_switch_to isn't needed. We could want to apply this to * improve performance. -bb */ -arch_switch_to (current); +arch_switch_to (NULL , current); current->thread.prev_sched =NULL ;
arch/x86/um/ptrace_32.c +1 -1
@@ -11,7 +11,7 @@extern int arch_switch_tls (struct task_struct *to); -void arch_switch_to (struct task_struct *to) +void arch_switch_to (struct task_struct *from,struct task_struct *to) {int err =arch_switch_tls (to);if (!err)
arch/x86/um/syscalls_64.c +1 -1
@@ -80,7 +80,7 @@ SYSCALL_DEFINE2(arch_prctl, int, option, unsigned long, arg2)return arch_prctl (current, option, (unsigned long __user *) arg2); } -void arch_switch_to (struct task_struct *to) +void arch_switch_to (struct task_struct *from,struct task_struct *to) {if ((to->thread.arch.fs ==0 ) || (to->mm ==NULL ))return ;
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 8/21 um: add nommu mode for UML library mode
In reply to Hajime TazakiThis patch introduces the nommu operation with UML code so that host interface can be shrineked for broader environments support.
The nommu mode is implemneted as SUBARCH of arch/um, which places at arch/um/nommu. This SUBARCH defines mode-specific code of memory management as well as thread implementation, along with the uapi headers to be exported to users.
The headers we introduce in this patch are simple wrappers to the asm-generic headers or stubs for things we don't support, such as ptrace, DMA, signals, ELF handling and low level processor operations.
nommu mode shares most of arch/um code (irq, thread_info, process scheduling) but implements its own facilities, which are memory management (nommu), thread primitives (struct arch_thread), system call interface, and console.
The outlook of updated directory structure is as follows:
arch/um
|-- configs (untouched) |-- drivers unuse stdio_console.c for !MMU |-- include | |-- asm updated with !CONFIG_MMU | |-- linux (untouched) | `-- shareda updated with new functions | `-- skas (untouched) | `-- uapi added for upai header installation |-- kernel updated to integrate with !MMU | `-- skas (untouched, don't use for !MMU) |-- nommu SUBARCH dir (internally =um/nommu) | |-- include | | |-- asm headers for subarch specific info | | `-- uapi headers for user-visible APIs | `-- um | `-- shared headers for subarch specific info
`-- scripts added a script for header installation
--- arch/um/nommu/Makefile | 1 + arch/um/nommu/Makefile.um | 18 +++ arch/um/nommu/include/asm/Kbuild | 6 + arch/um/nommu/include/asm/archparam.h | 1 + arch/um/nommu/include/asm/atomic.h | 11 ++ arch/um/nommu/include/asm/atomic64.h | 114 ++++++++++++++++++ arch/um/nommu/include/asm/bitsperlong.h | 12 ++ arch/um/nommu/include/asm/byteorder.h | 7 ++ arch/um/nommu/include/asm/cpu.h | 13 ++ arch/um/nommu/include/asm/elf.h | 15 +++ arch/um/nommu/include/asm/mm_context.h | 8 ++ arch/um/nommu/include/asm/processor.h | 46 +++++++ arch/um/nommu/include/asm/ptrace.h | 21 ++++ arch/um/nommu/include/asm/sched.h | 23 ++++ arch/um/nommu/include/asm/segment.h | 9 ++ arch/um/nommu/include/uapi/asm/Kbuild | 4 + arch/um/nommu/include/uapi/asm/bitsperlong.h | 11 ++ arch/um/nommu/include/uapi/asm/byteorder.h | 11 ++ arch/um/nommu/include/uapi/asm/sigcontext.h | 12 ++ arch/um/nommu/um/delay.c | 31 +++++ arch/um/nommu/um/shared/sysdep/archsetjmp.h | 13 ++ arch/um/nommu/um/shared/sysdep/faultinfo.h | 8 ++ .../nommu/um/shared/sysdep/kernel-offsets.h | 12 ++ arch/um/nommu/um/shared/sysdep/mcontext.h | 9 ++ arch/um/nommu/um/shared/sysdep/ptrace.h | 42 +++++++ arch/um/nommu/um/shared/sysdep/ptrace_user.h | 7 ++ arch/um/nommu/um/unimplemented.c | 70 +++++++++++ arch/um/nommu/um/user_constants.h | 13 ++ 28 files changed, 548 insertions(+) create mode 100644 arch/um/nommu/Makefile create mode 100644 arch/um/nommu/Makefile.um create mode 100644 arch/um/nommu/include/asm/Kbuild create mode 100644 arch/um/nommu/include/asm/archparam.h create mode 100644 arch/um/nommu/include/asm/atomic.h create mode 100644 arch/um/nommu/include/asm/atomic64.h create mode 100644 arch/um/nommu/include/asm/bitsperlong.h create mode 100644 arch/um/nommu/include/asm/byteorder.h create mode 100644 arch/um/nommu/include/asm/cpu.h create mode 100644 arch/um/nommu/include/asm/elf.h create mode 100644 arch/um/nommu/include/asm/mm_context.h create mode 100644 arch/um/nommu/include/asm/processor.h create mode 100644 arch/um/nommu/include/asm/ptrace.h create mode 100644 arch/um/nommu/include/asm/sched.h create mode 100644 arch/um/nommu/include/asm/segment.h create mode 100644 arch/um/nommu/include/uapi/asm/Kbuild create mode 100644 arch/um/nommu/include/uapi/asm/bitsperlong.h create mode 100644 arch/um/nommu/include/uapi/asm/byteorder.h create mode 100644 arch/um/nommu/include/uapi/asm/sigcontext.h create mode 100644 arch/um/nommu/um/delay.c create mode 100644 arch/um/nommu/um/shared/sysdep/archsetjmp.h create mode 100644 arch/um/nommu/um/shared/sysdep/faultinfo.h create mode 100644 arch/um/nommu/um/shared/sysdep/kernel-offsets.h create mode 100644 arch/um/nommu/um/shared/sysdep/mcontext.h create mode 100644 arch/um/nommu/um/shared/sysdep/ptrace.h create mode 100644 arch/um/nommu/um/shared/sysdep/ptrace_user.h create mode 100644 arch/um/nommu/um/unimplemented.c create mode 100644 arch/um/nommu/um/user_constants.h
arch/um/nommu/Makefile new file +1 -0
@@ -0,0 +1 @@ +#
arch/um/nommu/Makefile.um new file +18 -0
@@ -0,0 +1,18 @@ +KBUILD_CFLAGS += -fno-builtin -fPIC +ELF_FORMAT=$(shell $(LD) -r -print-output-format) + +ifeq ($(shell uname -s), Linux) +NPROC=$(shell nproc) +else # e.g., FreeBSD +NPROC=$(shell sysctl -n hw.ncpu) +endif + +um_headers_install: $(objtree)/$(HOST_DIR)/include/generated/uapi/asm/syscall_defs.h headers + $(Q)$(srctree)/$(ARCH_DIR)/scripts/headers_install.py \ + $(subst -j,-j$(NPROC),$(findstring -j,$(MAKEFLAGS))) \ + $(INSTALL_PATH)/include + +$(objtree)/$(HOST_DIR)/include/generated/uapi/asm/syscall_defs.h: vmlinux + $(Q)$(OBJCOPY) -j .syscall_defs -O binary --set-section-flags .syscall_defs=alloc $< $@ + $(Q) export tmpfile=$(shell mktemp); \ + sed 's/\x0//g' $@ > $$tmpfile; mv $$tmpfile $@ ; rm -f $$tmpfile
arch/um/nommu/include/asm/Kbuild new file +6 -0
@@ -0,0 +1,6 @@ +generic-y += cmpxchg.h +generic-y += local64.h +generic-y += seccomp.h +generic-y += string.h +generic-y += syscall.h +generic-y += user.h
arch/um/nommu/include/asm/archparam.h new file +1 -0
@@ -0,0 +1 @@ +/* SPDX-License-Identifier: GPL-2.0 */
arch/um/nommu/include/asm/atomic.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_ATOMIC_H +#define __UM_NOMMU_ATOMIC_H + +#include <asm-generic/atomic.h> + +#ifndef CONFIG_GENERIC_ATOMIC64 +#include "atomic64.h" +#endif /* !CONFIG_GENERIC_ATOMIC64 */ + +#endif
arch/um/nommu/include/asm/atomic64.h new file +114 -0
114 lines not on this page · raw message
arch/um/nommu/include/asm/bitsperlong.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_BITSPERLONG_H +#define __UM_NOMMU_BITSPERLONG_H + +#include <uapi/asm/bitsperlong.h> + +#define BITS_PER_LONG __BITS_PER_LONG + +#define BITS_PER_LONG_LONG 64 + +#endif +
arch/um/nommu/include/asm/byteorder.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_BYTEORDER_H +#define __UM_NOMMU_BYTEORDER_H + +#include <uapi/asm/byteorder.h> + +#endif
arch/um/nommu/include/asm/cpu.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_CPU_H +#define __UM_NOMMU_CPU_H + +int lkl_cpu_get (void ); +void lkl_cpu_put (void ); +int lkl_cpu_try_run_irq (int irq); +int lkl_cpu_init (void ); +void lkl_cpu_wait_shutdown (void ); +void lkl_cpu_change_owner (lkl_thread_t owner); +void lkl_cpu_set_irqs_pending (void ); + +#endif
arch/um/nommu/include/asm/elf.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_ELF_H +#define __UM_NOMMU_ELF_H + +#define elf_check_arch (x) 0 + +#ifdef CONFIG_64BIT +#define ELF_CLASS ELFCLASS64 +#else +#define ELF_CLASS ELFCLASS32 +#endif + +#define elf_gregset_t long +#define elf_fpregset_t double +#endif
arch/um/nommu/include/asm/mm_context.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_MM_CONTEXT_H +#define __UM_NOMMU_MM_CONTEXT_H + +struct uml_arch_mm_context { +}; + +#endif
arch/um/nommu/include/asm/processor.h new file +46 -0
46 lines not on this page · raw message
arch/um/nommu/include/asm/ptrace.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_PTRACE_H +#define __UM_NOMMU_PTRACE_H + +#include <linux/errno.h> + +static int reg_dummy __attribute__((unused)); + +#define PT_REGS_ORIG_SYSCALL (r) (reg_dummy) +#define PT_REGS_SYSCALL_RET (r) (reg_dummy) +#define PT_REGS_SET_SYSCALL_RETURN (r, res) (reg_dummy = (res)) +#define REGS_SP (r) (reg_dummy) + +#define user_mode (regs) 0 +#define kernel_mode (regs) 1 +#define profile_pc (regs) 0 +#define user_stack_pointer (regs) 0 + +extern void new_thread_handler (void ); + +#endif
arch/um/nommu/include/asm/sched.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_SCHED_H +#define __UM_NOMMU_SCHED_H + +#include <linux/sched.h> +#include <uapi/asm/host_ops.h> + +static inline void thread_sched_jb (void ) +{ +if (test_ti_thread_flag (current_thread_info (),TIF_HOST_THREAD )) { +set_ti_thread_flag (current_thread_info (),TIF_SCHED_JB ); +set_current_state (TASK_UNINTERRUPTIBLE ); + lkl_ops->jmp_buf_set (¤t_thread_info ()->task->thread.arch.sched_jb, + schedule); + }else { +lkl_bug ("%s can be used only for host task" , __func__); + } +} + +void switch_to_host_task (struct task_struct *); +int host_task_stub (void *unused); + +#endif
arch/um/nommu/include/asm/segment.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_SEGMENT_H +#define __UM_NOMMU_SEGMENT_H + +typedef struct { +unsigned long seg; +}mm_segment_t ; + +#endif /* _ASM_LKL_SEGMENT_H */
arch/um/nommu/include/uapi/asm/Kbuild new file +4 -0
@@ -0,0 +1,4 @@ +# UAPI Header export list + +# no generated-y since we need special user headers handling +# see arch/um/script/headers_install.py
arch/um/nommu/include/uapi/asm/bitsperlong.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __UM_NOMMU_UAPI_BITSPERLONG_H +#define __UM_NOMMU_UAPI_BITSPERLONG_H + +#ifdef CONFIG_64BIT +#define __BITS_PER_LONG 64 +#else +#define __BITS_PER_LONG 32 +#endif + +#endif
arch/um/nommu/include/uapi/asm/byteorder.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __UM_NOMMU_UAPI_BYTEORDER_H +#define __UM_NOMMU_UAPI_BYTEORDER_H + +#if defined(CONFIG_BIG_ENDIAN ) +#include <linux/byteorder/big_endian.h> +#else +#include <linux/byteorder/little_endian.h> +#endif + +#endif
arch/um/nommu/include/uapi/asm/sigcontext.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __UM_NOMMU_UAPI_SIGCONTEXT_H +#define __UM_NOMMU_UAPI_SIGCONTEXT_H + +#include <asm/ptrace-generic.h> + +struct sigcontext { +struct pt_regs regs; +unsigned long oldmask; +}; + +#endif
arch/um/nommu/um/delay.c new file +31 -0
@@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/jiffies.h> +#include <linux/delay.h> +#include <os.h> + +void __ndelay (unsigned long nsecs) +{ +long long start =os_nsecs (); + +while (os_nsecs () < start + nsecs) + ; +} + +void __udelay (unsigned long usecs) +{ +__ndelay (usecs *NSEC_PER_USEC ); +} + +void __const_udelay (unsigned long xloops) +{ +__udelay (xloops /0x10c7ul ); +} + +void __delay (unsigned long loops) +{ +__ndelay (loops /5 ); +} + +void calibrate_delay (void ) +{ +}
arch/um/nommu/um/shared/sysdep/archsetjmp.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ARCH_UM_SETJMP_H +#define __ARCH_UM_SETJMP_H + +struct __jmp_buf { +unsigned long __dummy; +}; +#define JB_IP __dummy +#define JB_SP __dummy + +typedef struct __jmp_buf jmp_buf [1 ]; + +#endif /* __ARCH_UM_SETJMP_H */
arch/um/nommu/um/shared/sysdep/faultinfo.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ARCH_UM_FAULTINFO_H +#define __ARCH_UM_FAULTINFO_H + +struct faultinfo { +}; + +#endif /* __ARCH_UM_FAULTINFO_H */
arch/um/nommu/um/shared/sysdep/kernel-offsets.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/stddef.h> +#include <linux/sched.h> +#include <linux/elf.h> +#include <linux/crypto.h> +#include <linux/kbuild.h> +#include <asm/mman.h> + +void foo (void ) +{ +#include <common-offsets.h> +}
arch/um/nommu/um/shared/sysdep/mcontext.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ARCH_UM_MCONTEXT_H +#define __ARCH_UM_MCONTEXT_H + +extern void get_regs_from_mc (struct uml_pt_regs *regs,mcontext_t *mc); + +#define GET_FAULTINFO_FROM_MC (fi, mc) (fi = fi) + +#endif /* __ARCH_UM_MCONTEXT_H */
arch/um/nommu/um/shared/sysdep/ptrace.h new file +42 -0
42 lines not on this page · raw message
arch/um/nommu/um/shared/sysdep/ptrace_user.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ARCH_UM_PTRACE_USER_H +#define __ARCH_UM_PTRACE_USER_H + +#define FP_SIZE 1 + +#endif
arch/um/nommu/um/unimplemented.c new file +70 -0
70 lines not on this page · raw message
arch/um/nommu/um/user_constants.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_USER_CONSTANTS_H +#define __UM_NOMMU_USER_CONSTANTS_H + +/* XXX: put dummy values */ +#define UM_FRAME_SIZE 4 +#define HOST_FP_SIZE 1 +#define HOST_IP 1 +#define HOST_SP 2 +#define HOST_BP 3 +#define UM_NR_CPUS 1 + +#endif
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 9/21 um: nommu: host interface
In reply to Hajime TazakiThis patch introduces the host operations that define the interface between the LKL and the host. These operations must be provided either by a host library or by the application itself.
--- arch/um/include/asm/host_ops.h | 9 ++++++++ arch/um/nommu/include/uapi/asm/host_ops.h | 25 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 arch/um/include/asm/host_ops.h create mode 100644 arch/um/nommu/include/uapi/asm/host_ops.h
arch/um/include/asm/host_ops.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_LKL_HOST_OPS_H +#define _ASM_LKL_HOST_OPS_H + +#include <uapi/asm/host_ops.h> + +extern struct lkl_host_operations *lkl_ops; + +#endif
arch/um/nommu/include/uapi/asm/host_ops.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __UM_NOMMU_UAPI_HOST_OPS_H +#define __UM_NOMMU_UAPI_HOST_OPS_H + +/* Defined in {posix,nt}-host.c */ +struct lkl_mutex ; +struct lkl_sem ; +typedef unsigned long lkl_thread_t ; +struct lkl_jmp_buf { +unsigned long buf[128 ]; +}; + +/** +* lkl_host_operations - host operations used by the Linux kernel +* +* These operations must be provided by a host library or by the application +* itself. +* +*/ +struct lkl_host_operations { +}; + +void lkl_bug (const char *fmt, ...); + +#endif
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 10/21 um: nommu: memory handling
In reply to Hajime Tazakinommu mode follows the way !CONFIG_MMU architecture of other linux archs. Ther is not much work left to do other than initializing the boot allocator and providing the page and page table definitions.
The backstore memory is allocated via a host operation and the memory size to be used is specified when the kernel is started, in the lkl_start_kernel call.
--- arch/um/include/asm/mmu.h | 3 + arch/um/include/asm/mmu_context.h | 8 +++ arch/um/include/asm/page.h | 15 ++++ arch/um/include/asm/pgtable.h | 27 +++++++ arch/um/include/asm/uaccess.h | 6 ++ arch/um/nommu/include/uapi/asm/host_ops.h | 5 ++ arch/um/nommu/um/bootmem.c | 86 +++++++++++++++++++++++ 7 files changed, 150 insertions(+) create mode 100644 arch/um/nommu/um/bootmem.c
arch/um/include/asm/mmu.h +3 -0
@@ -13,6 +13,9 @@ typedef struct mm_context {struct mm_id id;struct uml_arch_mm_context arch;struct page *stub_pages[2 ]; +#ifndef CONFIG_MMU +unsigned long end_brk; +#endif } mm_context_t;extern void __switch_mm (struct mm_id * mm_idp);
arch/um/include/asm/mmu_context.h +8 -0
@@ -6,6 +6,7 @@#ifndef __UM_MMU_CONTEXT_H#define __UM_MMU_CONTEXT_H +#ifdef CONFIG_MMU #include <linux/sched.h> #include <linux/mm_types.h> #include <linux/mmap_lock.h>
@@ -75,4 +76,11 @@ extern int init_new_context(struct task_struct *task, struct mm_struct *mm);extern void destroy_context (struct mm_struct *mm); +#else +#include <asm-generic/mmu_context.h> + +extern void force_flush_all (void ); + +#endif /* CONFIG_MMU */ +#endif
arch/um/include/asm/page.h +15 -0
@@ -7,6 +7,8 @@#ifndef __UM_PAGE_H#define __UM_PAGE_H +#ifdef CONFIG_MMU +#include <linux/const.h> /* PAGE_SHIFT determines the page size */
@@ -120,4 +122,17 @@ extern unsigned long uml_physmem;#define __HAVE_ARCH_GATE_AREA 1#endif +#else /* CONFIG_MMU */ +#define CONFIG_KERNEL_RAM_BASE_ADDRESS memory_start +#include <asm-generic/page.h> + +#define __va_space (8*1024*1024) + +#ifndef __ASSEMBLY__ +#include <mem.h> +void free_mem (void ); +#endif + +#endif /* !CONFIG_MMU */ +#endif /* __UM_PAGE_H */
arch/um/include/asm/pgtable.h +27 -0
@@ -21,6 +21,8 @@#define _PAGE_PROTNONE 0x010/* if the user mapped it with PROT_NONE; pte_present gives true */ +#ifdef CONFIG_MMU +#ifdef CONFIG_3_LEVEL_PGTABLES #include <asm/pgtable-3level.h> #else
@@ -323,4 +325,29 @@ do { \__flush_tlb_one ((vaddr)); \ } while (0) +#else /* CONFIG_MMU */ + +#include <asm-generic/pgtable-nopud.h> + +#define swapper_pg_dir ((pgd_t *)0) +#define PAGE_KERNEL __pgprot(0) +#define PGDIR_SHIFT 21 +#define PGDIR_SIZE (1UL << PGDIR_SHIFT) +#define PGDIR_MASK (~(PGDIR_SIZE-1)) + +#define VMALLOC_START 0 +#define VMALLOC_END 0xffffffff + +/* +* ZERO_PAGE is a global shared page that is always zero: used +* for zero-mapped memory areas etc.. +*/ +extern unsigned long *empty_zero_page; +#define ZERO_PAGE (vaddr) (virt_to_page(empty_zero_page)) + +extern unsigned long end_iomem; + +#endif /* !CONFIG_MMU */ + +#endif
arch/um/include/asm/uaccess.h +6 -0
@@ -21,6 +21,7 @@#define __addr_range_nowrap (addr, size) \ ((unsigned long) (addr) <= ((unsigned long) (addr) + (size))) +#ifdef CONFIG_MMU extern unsigned long raw_copy_from_user (void *to,const void __user *from,unsigned long n);extern unsigned long raw_copy_to_user (void __user *to,const void *from,unsigned long n);extern long __strncpy_from_user (char *dst,const char __user *src,long count);
@@ -46,4 +47,9 @@ static inline int __access_ok(unsigned long addr, unsigned long size) uaccess_kernel()); } +#else +#include <asm-generic/uaccess.h> +#endif /* CONFIG_MMU */ + +#endif
arch/um/nommu/include/uapi/asm/host_ops.h +5 -0
@@ -16,8 +16,13 @@ struct lkl_jmp_buf {* These operations must be provided by a host library or by the application * itself. * +* @mem_alloc - allocate memory +* @mem_free - free memory +* */ struct lkl_host_operations { +void *(*mem_alloc)(unsigned long mem); +void (*mem_free)(void *mem); };void lkl_bug (const char *fmt, ...);
arch/um/nommu/um/bootmem.c new file +86 -0
86 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 11/21 um: nommu: kernel thread support
In reply to Hajime Tazakinommu mode does not support user processes but it must support kernel threads as part as the normal kernel work-flow. It uses host operations to create and terminate host threads that are going to run the kernel threads. It also uses semaphores to synchronize those threads and to allow the Linux kernel scheduler to control how the kernel threads run.
Each kernel thread runs in a host threads and has a host semaphore associated with it - the thread's scheduling semaphore. The semaphore counter is initialized to 0. The first thing a kernel thread does after getting spawned, before running any kernel code, is to perform a down operation to block the thread.
The kernel controls host threads scheduling by performing up and down operations on the scheduling semaphore. In __switch_context an up operation on the next thread is performed to wake up a blocked thread, and a down operation is performed on the prev thread to block it.
A thread is terminated by marking it in free_thread_info and performing an up operation on the scheduling semaphore at which point the marked thread will terminate itself.
UML common part (process.c) is extended to call idle functions of SUBARCH as well as kernel thread detection with a flag information of TIF_HOST_THREAD.
--- arch/um/include/asm/thread_info.h | 24 ++ arch/um/kernel/process.c | 8 +- arch/um/nommu/include/uapi/asm/host_ops.h | 54 +++++ arch/um/nommu/um/cpu.c | 236 ++++++++++++++++++++ arch/um/nommu/um/threads.c | 258 ++++++++++++++++++++++ 5 files changed, 579 insertions(+), 1 deletion(-) create mode 100644 arch/um/nommu/um/cpu.c create mode 100644 arch/um/nommu/um/threads.c
arch/um/include/asm/thread_info.h +24 -0
@@ -40,6 +40,7 @@ struct thread_info { .real_thread = NULL, \ } +#ifdef CONFIG_MMU /* how to get the thread information struct from C */ static inline struct thread_info *current_thread_info (void ) {
@@ -52,6 +53,27 @@ static inline struct thread_info *current_thread_info(void)return ti; } +#else + +#define __HAVE_THREAD_FUNCTIONS +#define task_thread_info (task) ((struct thread_info *)(task)->stack) +#define task_stack_page (task) ((task)->stack) +#define end_of_stack (p) (&task_thread_info(p)->aux_fp_regs[FP_SIZE-1]) + +void threads_init (void ); +void threads_cleanup (void ); + +unsigned long *alloc_thread_stack_node (struct task_struct *p,int node); +void setup_thread_stack (struct task_struct *p,struct task_struct *org); +void free_thread_stack (struct task_struct *tsk); + +extern struct thread_info *_current_thread_info; +static inline struct thread_info *current_thread_info (void ) +{ +return _current_thread_info; +} +#endif /* CONFIG_MMU */ +#endif #define TIF_SYSCALL_TRACE 0/* syscall trace active */
@@ -63,6 +85,8 @@ static inline struct thread_info *current_thread_info(void)#define TIF_RESTORE_SIGMASK 7#define TIF_NOTIFY_RESUME 8#define TIF_SECCOMP 9/* secure computing */ +#define TIF_SCHED_JB 10 +#define TIF_HOST_THREAD 11#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
arch/um/kernel/process.c +7 -1
@@ -156,7 +156,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg, struct task_struct * p, unsigned long tls) { void (*handler)(void); -int kthread = current->flags &PF_KTHREAD ; +int kthread = current->flags &PF_KTHREAD || +test_ti_thread_flag (current_thread_info (),TIF_HOST_THREAD );int ret =0 ; p->thread = (struct thread_struct )INIT_THREAD ;
@@ -213,10 +214,15 @@ static void um_idle_sleep(void) } } +void __weak subarch_cpu_idle (void ) +{ +} +void arch_cpu_idle (void ) { cpu_tasks[current_thread_info ()->cpu].pid =os_getpid ();um_idle_sleep (); +subarch_cpu_idle ();local_irq_enable (); }
arch/um/nommu/include/uapi/asm/host_ops.h +54 -0
65 lines not on this page · raw message
arch/um/nommu/um/cpu.c new file +236 -0
236 lines not on this page · raw message
arch/um/nommu/um/threads.c new file +258 -0
258 lines not on this page · raw message
Signature · 7 lines
2.21.0 (Apple Git-122.2) _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
RFC v6 12/21 um: nommu: system call interface and application API
In reply to Hajime TazakiThe application API is based on the kernel system call interface in order to offer a stable API to applications. Note that we can't offer the full Linux system call interface due to the limitations of nommu mode such as lack of virtual memory, signal, user processes, etc.
The host is using dedicated kernel thread, which is switched upon the entry of lkl_syscall so that numbers of context switches can be reduced for the faster performance.
To expose the API definitions to applications, this commit uses syscall_wrapper to define arch-specific information of syscall, and this is used to generate syscall_defs.h for lkl so that it can be used as a template of the list of syscall available for LKL apps.
To avoid collisions between the Linux API and the LKL API (e.g. struct stat, MKNOD, etc.) we use a python script to modify the user headers and to prefix all of the global symbols (structures, typedefs, defines) with LKL, lkl, _LKL, _lkl, __LKL or __lkl.
--- arch/um/include/uapi/asm/Kbuild | 2 + arch/um/nommu/include/asm/syscall_wrapper.h | 57 ++++ arch/um/nommu/include/asm/syscalls.h | 15 + arch/um/nommu/include/uapi/asm/host_ops.h | 14 + arch/um/nommu/include/uapi/asm/syscalls.h | 287 ++++++++++++++++++++ arch/um/nommu/include/uapi/asm/unistd.h | 15 + arch/um/nommu/um/syscalls.c | 199 ++++++++++++++ arch/um/scripts/headers_install.py | 197 ++++++++++++++ 8 files changed, 786 insertions(+) create mode 100644 arch/um/include/uapi/asm/Kbuild create mode 100644 arch/um/nommu/include/asm/syscall_wrapper.h create mode 100644 arch/um/nommu/include/asm/syscalls.h create mode 100644 arch/um/nommu/include/uapi/asm/syscalls.h create mode 100644 arch/um/nommu/include/uapi/asm/unistd.h create mode 100644 arch/um/nommu/um/syscalls.c create mode 100755 arch/um/scripts/headers_install.py
arch/um/include/uapi/asm/Kbuild new file +2 -0
@@ -0,0 +1,2 @@ +# no generated-y since we need special user headers handling +# see arch/um/script/headers_install.py
arch/um/nommu/include/asm/syscall_wrapper.h new file +57 -0
57 lines not on this page · raw message
arch/um/nommu/include/asm/syscalls.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +int syscalls_init (void ); +void syscalls_cleanup (void ); +long lkl_syscall (long no,long *params); +void wakeup_idle_host_task (void ); + +#define sys_mmap sys_ni_syscall +#define sys_rt_sigreturn sys_ni_syscall +#define sys_arch_prctl sys_ni_syscall +#define sys_iopl sys_ni_syscall +#define sys_ioperm sys_ni_syscall +#define sys_clone sys_ni_syscall + +int run_syscalls (void );
arch/um/nommu/include/uapi/asm/host_ops.h +14 -0
@@ -38,6 +38,15 @@ struct lkl_jmp_buf {* @gettid - returns the host thread id of the caller, which need not * be the same as the handle returned by thread_create * +* @tls_alloc - allocate a thread local storage key; returns 0 if successful; if +* destructor is not NULL it will be called when a thread terminates with its +* argument set to the current thread local storage value +* @tls_free - frees a thread local storage key; returns 0 if successful +* @tls_set - associate data to the thread local storage key; returns 0 if +* successful +* @tls_get - return data associated with the thread local storage key or NULL +* on error +* * @jmp_buf_set - runs the give function and setups a jump back point by saving * the context in the jump buffer; jmp_buf_longjmp can be called from the give * function or any callee in that function to return back to the jump back
@@ -72,6 +81,11 @@ struct lkl_host_operations {int (*thread_equal)(lkl_thread_t a,lkl_thread_t b);long (*gettid)(void ); +struct lkl_tls_key *(*tls_alloc)(void (*destructor)(void *)); +void (*tls_free)(struct lkl_tls_key *key); +int (*tls_set)(struct lkl_tls_key *key,void *data); +void *(*tls_get)(struct lkl_tls_key *key); +void (*jmp_buf_set)(struct lkl_jmp_buf *jmpb,void (*f)(void ));void (*jmp_buf_longjmp)(struct lkl_jmp_buf *jmpb,int val);
arch/um/nommu/include/uapi/asm/syscalls.h new file +287 -0
287 lines not on this page · raw message
arch/um/nommu/include/uapi/asm/unistd.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __UM_NOMMU_UAPI_UNISTD_H +#define __UM_NOMMU_UAPI_UNISTD_H + +#define __ARCH_WANT_NEW_STAT +#include <asm/bitsperlong.h> + +#if __BITS_PER_LONG ==64 +#define __ARCH_WANT_SYS_NEWFSTATAT +#endif + +#include <asm-generic/unistd.h> + + +#endif
arch/um/nommu/um/syscalls.c new file +199 -0
199 lines not on this page · raw message
arch/um/scripts/headers_install.py new file +197 -0
197 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 13/21 um: nommu: basic console support
In reply to Hajime TazakiThis commit also disables stdio-console of UM if !CONFIG_MMU to avoid conflicts between multiple consoles.
--- arch/um/drivers/Makefile | 8 ++++- arch/um/nommu/include/uapi/asm/host_ops.h | 3 ++ arch/um/nommu/um/console.c | 42 +++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 arch/um/nommu/um/console.c
arch/um/drivers/Makefile +7 -1
@@ -37,7 +37,13 @@ $(obj)/vde.o: $(obj)/vde_kern.o $(obj)/vde_user.o # When the above is fixed, don't forget to add this too! #targets += $(obj)/pcap.o -obj-y := stdio_console.o fd.o chan_kern.o chan_user.o line.o +ifdef CONFIG_MMU +obj-y := stdio_console.o +else +obj-y := +endif +obj-y += fd.o chan_kern.o chan_user.o line.o + obj-$(CONFIG_SSL) += ssl.o obj-$(CONFIG_STDERR_CONSOLE) += stderr_console.o
arch/um/nommu/include/uapi/asm/host_ops.h +3 -0
@@ -15,6 +15,7 @@ struct lkl_jmp_buf {* * These operations must be provided by a host library or by the application * itself. +* @print - optional operation that receives console messages * * @sem_alloc - allocate a host semaphore an initialize it to count * @sem_free - free a host semaphore
@@ -63,6 +64,8 @@ struct lkl_jmp_buf {* */ struct lkl_host_operations { +void (*print)(const char *str,int len); +struct lkl_sem *(*sem_alloc)(int count);void (*sem_free)(struct lkl_sem *sem);void (*sem_up)(struct lkl_sem *sem);
arch/um/nommu/um/console.c new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 14/21 um: nommu: initialization and cleanup
In reply to Hajime TazakiAdd the lkl_start_kernel and lkl_sys_halt APIs that start and respectively stops the Linux kernel.
lkl_start_kernel creates a separate threads that will run the initial and idle kernel thread. It waits for the kernel to complete initialization before returning, to avoid races with system calls issues by the host application.
During the setup phase, we create "/init" in initial ramfs root filesystem to avoid mounting the "real" rootfs since ramfs is good enough for now.
lkl_sys_halt will shutdown the kernel, terminate all threads and free all host resources used by the kernel before returning.
--- arch/um/nommu/include/uapi/asm/host_ops.h | 14 ++ arch/um/nommu/um/setup.c | 162 ++++++++++++++++++++++ tools/um/uml/process.c | 2 + 3 files changed, 178 insertions(+) create mode 100644 arch/um/nommu/um/setup.c
arch/um/nommu/include/uapi/asm/host_ops.h +14 -0
@@ -16,6 +16,7 @@ struct lkl_jmp_buf {* These operations must be provided by a host library or by the application * itself. * @print - optional operation that receives console messages +* @panic - called during a kernel panic * * @sem_alloc - allocate a host semaphore an initialize it to count * @sem_free - free a host semaphore
@@ -65,6 +66,7 @@ struct lkl_jmp_buf {*/ struct lkl_host_operations {void (*print)(const char *str,int len); +void (*panic)(void );struct lkl_sem *(*sem_alloc)(int count);void (*sem_free)(struct lkl_sem *sem);
@@ -96,6 +98,18 @@ struct lkl_host_operations { void (*mem_free)(void *mem); }; +/** +* lkl_start_kernel - registers the host operations and starts the kernel +* +* The function returns only after the kernel is shutdown with lkl_sys_halt. +* +* @lkl_ops - pointer to host operations +* @cmd_line - format for command line string that is going to be used to +* generate the Linux kernel command line +*/ +int lkl_start_kernel (struct lkl_host_operations *ops, +const char *fmt, ...); +void lkl_bug (const char *fmt, ...);#endif
arch/um/nommu/um/setup.c new file +162 -0
162 lines not on this page · raw message
tools/um/uml/process.c +2 -0
@@ -114,6 +114,8 @@ void os_kill_process(int pid, int reap_child)void os_kill_ptraced_process (int pid,int reap_child) { +if (pid ==0 ) +return ;kill (pid,SIGKILL );ptrace (PTRACE_KILL , pid);ptrace (PTRACE_CONT , pid);
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 15/21 um: nommu: integrate with irq infrastructure of UML
In reply to Hajime TazakiIn order to cooperate with UML's irq infrastructure and nommu threads based on host threads, irq handlers shall synchronize the our scheduler which is controlled by struct lkl_cpu. To do that, the irq infra notifies its entry of handlers by obtaining cpu access of thread scheduler (lkl_cpu_try_run_irq) and its release (lkl_cpu_put).
In additon to that, in order to stick the signal handler's thread to the one of the idle thread, several required configurations of (thread's) signal mask are added: otherwise handlers running on arbitrary thread cannot obtain cpu access and immediately fall into pending interrupt which may slow down the delivery of signals.
--- arch/um/include/shared/os.h | 1 + arch/um/kernel/irq.c | 13 +++++++++++++ arch/um/kernel/time.c | 2 ++ arch/um/nommu/include/asm/cpu.h | 3 +++ arch/um/nommu/um/cpu.c | 17 ++++++++++++++--- arch/um/nommu/um/setup.c | 5 +++++ arch/um/nommu/um/threads.c | 3 +++ tools/um/uml/signal.c | 12 ++++++++++-- 8 files changed, 51 insertions(+), 5 deletions(-)
arch/um/include/shared/os.h +1 -0
@@ -241,6 +241,7 @@ extern int set_signals(int enable);extern int set_signals_trace (int enable);extern int os_is_signal_stack (void );extern void deliver_alarm (void ); +extern void set_pending_signals (int sig);/* util.c */ extern void stack_protections (unsigned long address);
arch/um/kernel/irq.c +13 -0
@@ -19,6 +19,7 @@#include <kern_util.h> #include <os.h> #include <irq_user.h> +#include <asm/cpu.h> extern void free_irqs (void );
@@ -541,6 +542,11 @@ unsigned long to_irq_stack(unsigned long *mask_out)unsigned long mask, old;int nested; +#ifndef CONFIG_MMU +if (!nommu_irq_enter (ffs (*mask_out) -1 )) +return 1 ; +#endif + mask =xchg (&pending_mask, *mask_out);if (mask !=0 ) {/*
@@ -557,6 +563,10 @@ unsigned long to_irq_stack(unsigned long *mask_out) old |= mask; mask =xchg (&pending_mask, old); }while (mask != old); + +#ifndef CONFIG_MMU +nommu_irq_exit (); +#endif return 1 ; }
@@ -594,6 +604,9 @@ unsigned long from_irq_stack(int nested) *to = *ti; mask =xchg (&pending_mask,0 ); +#ifndef CONFIG_MMU +nommu_irq_exit (); +#endif return mask & ~1 ; }
arch/um/kernel/time.c +2 -0
@@ -597,11 +597,13 @@ static struct clock_event_device timer_clockevent = {static irqreturn_t um_timer (int irq,void *dev) { +#ifdef CONFIG_MMU if (get_current ()->mm !=NULL ) {/* userspace - relay signal, results in correct userspace timers */ os_alarm_process (get_current ()->mm->context.id.u.pid); } +#endif (*timer_clockevent.event_handler)(&timer_clockevent);
arch/um/nommu/include/asm/cpu.h +3 -0
@@ -10,4 +10,7 @@ void lkl_cpu_wait_shutdown(void);void lkl_cpu_change_owner (lkl_thread_t owner);void lkl_cpu_set_irqs_pending (void ); +void nommu_irq_exit (void ); +int nommu_irq_enter (int sig); +#endif
arch/um/nommu/um/cpu.c +14 -3
@@ -8,15 +8,16 @@#include <asm/sched.h> #include <asm/syscalls.h> #include <init.h> +#include <os.h> void run_irqs (void ) { -panic ("unimplemented %s" , __func__); +unblock_signals (); } -int set_irq_pending (int irq) +void set_irq_pending (int sig) { -panic ("unimplemented %s" , __func__); +set_pending_signals (sig); }/*
@@ -174,6 +175,16 @@ int lkl_cpu_try_run_irq(int irq)return ret; } +int nommu_irq_enter (int sig) +{ +return lkl_cpu_try_run_irq (sig); +} + +void nommu_irq_exit (void ) +{ +return lkl_cpu_put (); +} +static void lkl_cpu_shutdown (void ) {__sync_fetch_and_add (&cpu.shutdown_gate,MAX_THREADS );
arch/um/nommu/um/setup.c +5 -0
@@ -36,6 +36,8 @@ static void __init *lkl_run_kernel(void *arg) panic_blink = lkl_panic_blink; +/* signal should be received at this thread (main and idle threads) */ +init_new_thread_signals ();threads_init ();lkl_cpu_get ();start_kernel ();
@@ -58,6 +60,9 @@ int __init lkl_start_kernel(struct lkl_host_operations *ops,if (ret) goto out_free_init_sem; +change_sig (SIGALRM ,0 ); +change_sig (SIGIO ,0 ); + ret = lkl_ops->thread_create (lkl_run_kernel,NULL );if (!ret) { ret = -ENOMEM ;
arch/um/nommu/um/threads.c +3 -0
@@ -151,6 +151,9 @@ static void *thread_bootstrap(void *_tba)int (*f)(void *) = tba->f;void *arg = tba->arg; +change_sig (SIGALRM ,0 ); +change_sig (SIGIO ,0 ); + lkl_ops->sem_down (ti->task->thread.arch.sched_sem);kfree (tba);if (ti->task->thread.prev_sched)
tools/um/uml/signal.c +10 -2
@@ -218,8 +218,8 @@ void set_handler(int sig)sigemptyset (&sig_mask);sigaddset (&sig_mask, sig); -if (sigprocmask (SIG_UNBLOCK , &sig_mask,NULL ) <0 ) -panic ("sigprocmask failed - errno = %d\n" , errno); +if (pthread_sigmask (SIG_UNBLOCK , &sig_mask,NULL ) <0 ) +panic ("pthread_sigmask failed - errno = %d\n" , errno); }int change_sig (int signal,int on)
@@ -355,3 +355,11 @@ int os_is_signal_stack(void)return ss.ss_flags &SS_ONSTACK ; } + +void set_pending_signals (int sig) +{ +if (sig ==SIGIO ) + signals_pending |=SIGIO_MASK ; +else if (sig ==SIGALRM ) + signals_pending |=SIGALRM_MASK ; +}
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 16/21 um: nommu: plug in the build system
In reply to Hajime TazakiBasic Makefiles for building library of nommu mode. Add a new architecture specific target for installing the resulting library files and headers.
To make nommu binaries build, UML introduced an additional option, UMMODE variable, to switch the output file of build: kernel (default), or library (nommu). Those modes are not able to be ON at the same time.
To build on library mode, users do the following:
make defconfig ARCH=um UMMODE=library
make ARCH=um UMMODE=library
--- arch/um/Kconfig | 17 ++++++++++++++--- arch/um/Makefile | 10 +++++++++- arch/um/kernel/Makefile | 12 ++++++++---- arch/um/nommu/um/Kconfig | 37 +++++++++++++++++++++++++++++++++++++ arch/um/nommu/um/Makefile | 4 ++++ 5 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 arch/um/nommu/um/Kconfig create mode 100644 arch/um/nommu/um/Makefile
arch/um/Kconfig +14 -3
@@ -22,9 +22,20 @@ config UML select TTY # Needed for line.c select MODULE_REL_CRCS if MODVERSIONS +config UMMODE_LIB + bool "UML mode: library mode" + default y if "$(UMMODE)" = "library" + help + This mode switches a mode to build a library of UML (Linux + Kernel Library/LKL). This switch is exclusive to "kernel mode" + of UML, which is traditional mode of UML. + + For more detail about LKL, see + <file:Documentation/virt/uml/lkl.txt>. + config MMU bool - default y + default y if !UMMODE_LIB config NO_IOMEM def_bool y
@@ -45,12 +56,12 @@ config LOCKDEP_SUPPORT config STACKTRACE_SUPPORT bool - default y + default y if MMU select STACKTRACE config GENERIC_CALIBRATE_DELAY bool - default y + default y if MMU config HZ int
arch/um/Makefile +9 -1
@@ -17,6 +17,10 @@ else KBUILD_DEFCONFIG := $(SUBARCH)_defconfig endif +ifeq ($(UMMODE),library) + SUBARCH := um/nommu +endif + ARCH_DIR := arch/um OS := $(shell uname -s) # We require bash because the vmlinux link and loader script cpp use bash
@@ -102,9 +106,13 @@ all: linux.o linux.o: vmlinux @echo ' LINK $@' - $(Q)$(OBJCOPY) -R .eh_frame $< $@ + $(Q)$(OBJCOPY) -R .eh_frame -L sem_init -L sem_post -L sem_wait -L sem_destroy $< $@ +ifeq ($(UMMODE),library) +install: linux.o um_headers_install +else install: linux.o +endif @echo " INSTALL $(INSTALL_PATH)/lib/$<" @mkdir -p $(INSTALL_PATH)/lib/ @cp $< $(INSTALL_PATH)/lib/
arch/um/kernel/Makefile +8 -4
@@ -14,10 +14,14 @@ CPPFLAGS_vmlinux.lds := -DSTART=$(LDS_START) \ $(LDS_EXTRA) extra-y := vmlinux.lds -obj-y = config.o exec.o exitcode.o irq.o ksyms.o mem.o \ - physmem.o process.o ptrace.o reboot.o sigio.o \ - signal.o syscall.o sysrq.o time.o tlb.o trap.o \ - um_arch.o umid.o maccess.o kmsg_dump.o skas/ +obj-y = config.o exitcode.o irq.o ksyms.o \ + process.o reboot.o sigio.o \ + signal.o syscall.o time.o \ + um_arch.o umid.o maccess.o kmsg_dump.o + +ifdef CONFIG_MMU +obj-y += exec.o mem.o physmem.o ptrace.o sysrq.o tlb.o trap.o skas/ +endif obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o obj-$(CONFIG_GPROF) += gprof_syms.o
arch/um/nommu/um/Kconfig new file +37 -0
@@ -0,0 +1,37 @@ +config UML_NOMMU + def_bool y + depends on !SMP && !MMU + select UACCESS_MEMCPY + select ARCH_THREAD_STACK_ALLOCATOR + select ARCH_HAS_SYSCALL_WRAPPER + +config 64BIT + bool + default y + +config GENERIC_CSUM + def_bool y + +config GENERIC_ATOMIC64 + bool + default y if !64BIT + +config SECCOMP + bool + default n + +config GENERIC_HWEIGHT + def_bool y + +config GENERIC_CALIBRATE_DELAY + bool + default n + +config STACKTRACE_SUPPORT + bool + default n + +# XXX: need this to work well with tap13.py +config PRINTK_TIME + bool + default y
arch/um/nommu/um/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +include/generated/user_constants.h: $(srctree)/arch/um/nommu/um/user_constants.h + $(Q)cp -f $^ $@ + +obj-y = bootmem.o console.o cpu.o delay.o setup.o syscalls.o threads.o unimplemented.o
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 17/21 um: host: add nommu build for ARCH=um
In reply to Hajime TazakiThis patch adds the skeleton for the host library.
The host library is implementing the host operations needed by nommu mode and is split into host dependent (depends on a specific host, e.g. POSIX hosts) and host independent parts (will work on all supported hosts).
--- tools/um/Makefile | 7 +- tools/um/Targets | 3 +- tools/um/include/lkl.h | 151 +++++++++++++++++++++++++++++ tools/um/include/lkl_host.h | 26 +++++ tools/um/uml/Build | 15 ++- tools/um/uml/nommu/Build | 1 + tools/um/uml/nommu/registers.c | 21 ++++ tools/um/uml/nommu/unimplemented.c | 21 ++++ 8 files changed, 238 insertions(+), 7 deletions(-) create mode 100644 tools/um/include/lkl.h create mode 100644 tools/um/include/lkl_host.h create mode 100644 tools/um/uml/nommu/Build create mode 100644 tools/um/uml/nommu/registers.c create mode 100644 tools/um/uml/nommu/unimplemented.c
tools/um/Makefile +5 -2
@@ -5,6 +5,7 @@ MAKEFLAGS += -r --no-print-directory KCONFIG?=defconfig +UMMODE?=kernel ifneq ($(silent),1) ifneq ($(V),1)
@@ -47,8 +48,9 @@ all: $(TARGETS) # rule to build linux.o $(OUTPUT)lib/linux.o: - $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) $(KCONFIG) - $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) install INSTALL_PATH=$(OUTPUT) + $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um UMMODE=$(UMMODE) $(KOPT) $(KCONFIG) + $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um UMMODE=$(UMMODE) $(KOPT) install \ + INSTALL_PATH=$(OUTPUT) $(OUTPUT)liblinux.a: $(OUTPUT)lib/linux.o $(OUTPUT)uml/liblinux-in.o $(OUTPUT)lib/liblinux-in.o $(QUIET_AR)$(AR) -rc $@ $^
@@ -67,6 +69,7 @@ $(OUTPUT)%-in.o: $(OUTPUT)lib/linux.o FORCE clean: $(call QUIET_CLEAN, objects)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd'\ -delete -o -name '\.*.d' -delete + $(call QUIET_CLEAN, headers)$(RM) -r $(OUTPUT)/include/lkl/ $(call QUIET_CLEAN, liblinux.a)$(RM) $(OUTPUT)/liblinux.a $(call QUIET_CLEAN, $(TARGETS))$(RM) $(TARGETS)
tools/um/Targets +2 -1
@@ -1,4 +1,5 @@ progs-y += uml/linux -LDLIBS_linux-y := -lrt -lpthread -lutil + +LDLIBS := -lrt -lpthread -lutil LDFLAGS_linux-y := -no-pie -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc LDFLAGS_linux-$(UML_STATIC) += -static
tools/um/include/lkl.h new file +151 -0
151 lines not on this page · raw message
tools/um/include/lkl_host.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LKL_HOST_H +#define _LKL_HOST_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <lkl/asm/host_ops.h> +#include <lkl.h> + +extern struct lkl_host_operations lkl_host_ops; + +/** +* lkl_printf - print a message via the host print operation +* +* @fmt: printf like format string +*/ +int lkl_printf (const char *fmt, ...); + + +#ifdef __cplusplus +} +#endif + +#endif
tools/um/uml/Build +11 -4
@@ -8,11 +8,19 @@ KCOV_INSTRUMENT := n include $(objtree)/include/config/auto.conf -liblinux-y += execvp.o file.o helper.o irq.o main.o mem.o process.o \ - registers.o sigio.o signal.o start_up.o time.o tty.o \ - umid.o user_syms.o util.o drivers/ skas/ +liblinux-y += execvp.o file.o helper.o irq.o mem.o process.o \ + registers.o sigio.o signal.o time.o tty.o \ + umid.o user_syms.o util.o drivers/ +ifdef CONFIG_MMU +liblinux-y += main.o start_up.o skas/ +HEADER_ARCH := x86 liblinux-y += x86/ +else +HEADER_ARCH := um/nommu +liblinux-y += nommu/ +endif + liblinux-$(CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA) += elf_aux.o
@@ -23,7 +31,6 @@ CFLAGS := -g -O2 # from arch/um/Makefile ARCH_DIR := arch/um -HEADER_ARCH := x86 HOST_DIR := arch/$(HEADER_ARCH) ifdef CONFIG_64BIT KBUILD_CFLAGS += -mcmodel=large
tools/um/uml/nommu/Build new file +1 -0
@@ -0,0 +1 @@ +liblinux-y = registers.o unimplemented.o
tools/um/uml/nommu/registers.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 + +struct uml_pt_regs ; + +int get_fp_registers (int pid,unsigned long *regs) +{ +return 0 ; +} + +int save_i387_registers (int pid,unsigned long *fp_regs) +{ +return 0 ; +} + +void arch_init_registers (int pid) +{ +} + +void get_regs_from_mc (struct uml_pt_regs *regs,void *mc) +{ +}
tools/um/uml/nommu/unimplemented.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <generated/user_constants.h> + +struct uml_pt_regs ; + +/* os-Linux/skas/process.c */ +int userspace_pid[UM_NR_CPUS ]; +void userspace (struct uml_pt_regs *regs,unsigned long *aux_fp_regs) +{} + + +/* x86/os-Linux/task_size.c */ +unsigned long os_get_top_address (void ) +{ +return 0 ; +} + +/* start-up.c */ +void os_early_checks (void ) +{ +}
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 19/21 um: host: posix host operations
In reply to Hajime TazakiThis commit implements LKL host operations for POSIX hosts. The operations are implemented to be portable in various POSIX OSs.
--- tools/um/lib/Build | 2 + tools/um/lib/posix-host.c | 292 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 294 insertions(+) create mode 100644 tools/um/lib/posix-host.c
tools/um/lib/Build +2 -0
@@ -1,4 +1,6 @@ include $(objtree)/include/config/auto.conf +CFLAGS_posix-host.o += -D_FILE_OFFSET_BITS=64 liblinux-$(CONFIG_UMMODE_LIB) += utils.o +liblinux-$(CONFIG_UMMODE_LIB) += posix-host.o liblinux-$(CONFIG_UMMODE_LIB) += jmp_buf.o
tools/um/lib/posix-host.c new file +292 -0
292 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 18/21 um: host: add utilities functions
In reply to Hajime TazakiAdd basic utility functions for getting a string from a kernel error code and a fprintf like function that uses the host print operation. The latter is useful for informing the user about errors that occur in the host library.
--- tools/um/lib/Build | 4 + tools/um/lib/jmp_buf.c | 14 +++ tools/um/lib/jmp_buf.h | 8 ++ tools/um/lib/utils.c | 210 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 236 insertions(+) create mode 100644 tools/um/lib/Build create mode 100644 tools/um/lib/jmp_buf.c create mode 100644 tools/um/lib/jmp_buf.h create mode 100644 tools/um/lib/utils.c
tools/um/lib/Build new file +4 -0
@@ -0,0 +1,4 @@ +include $(objtree)/include/config/auto.conf + +liblinux-$(CONFIG_UMMODE_LIB) += utils.o +liblinux-$(CONFIG_UMMODE_LIB) += jmp_buf.o
tools/um/lib/jmp_buf.c new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <setjmp.h> +#include <lkl_host.h> + +void jmp_buf_set (struct lkl_jmp_buf *jmpb,void (*f)(void )) +{ +if (!setjmp (*((jmp_buf *)jmpb->buf))) +f (); +} + +void jmp_buf_longjmp (struct lkl_jmp_buf *jmpb,int val) +{ +longjmp (*((jmp_buf *)jmpb->buf), val); +}
tools/um/lib/jmp_buf.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LKL_LIB_JMP_BUF_H +#define _LKL_LIB_JMP_BUF_H + +void jmp_buf_set (struct lkl_jmp_buf *jmpb,void (*f)(void )); +void jmp_buf_longjmp (struct lkl_jmp_buf *jmpb,int val); + +#endif
tools/um/lib/utils.c new file +210 -0
210 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v6 20/21 um: host: add test programs
In reply to Hajime TazakiAdd a simple LKL test application (boot) that starts the kernel and performs simple tests that minimally exercise the LKL API.
--- tools/um/Makefile | 5 +- tools/um/Targets | 6 + tools/um/tests/Build | 1 + tools/um/tests/boot.c | 393 ++++++++++++++++++++++++++++++++++++++++ tools/um/tests/boot.sh | 9 + tools/um/tests/run.py | 172 ++++++++++++++++++ tools/um/tests/tap13.py | 209 +++++++++++++++++++++ tools/um/tests/test.c | 126 +++++++++++++ tools/um/tests/test.h | 72 ++++++++ tools/um/tests/test.sh | 181 ++++++++++++++++++ 10 files changed, 1173 insertions(+), 1 deletion(-) create mode 100644 tools/um/tests/Build create mode 100644 tools/um/tests/boot.c create mode 100755 tools/um/tests/boot.sh create mode 100755 tools/um/tests/run.py create mode 100644 tools/um/tests/tap13.py create mode 100644 tools/um/tests/test.c create mode 100644 tools/um/tests/test.h create mode 100644 tools/um/tests/test.sh
tools/um/Makefile +4 -1
@@ -73,7 +73,10 @@ clean: $(call QUIET_CLEAN, liblinux.a)$(RM) $(OUTPUT)/liblinux.a $(call QUIET_CLEAN, $(TARGETS))$(RM) $(TARGETS) +run-tests: + ./tests/run.py $(tests) + FORCE: ; -.PHONY: all clean FORCE +.PHONY: all clean FORCE run-tests .IGNORE: clean .NOTPARALLEL : lib/linux.o
tools/um/Targets +6 -0
@@ -1,4 +1,10 @@ +ifeq ($(UMMODE),library) +progs-y += tests/boot +else progs-y += uml/linux +endif + +LDFLAGS_boot-y := -pie LDLIBS := -lrt -lpthread -lutil LDFLAGS_linux-y := -no-pie -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
tools/um/tests/Build new file +1 -0
@@ -0,0 +1 @@ +boot-y += boot.o test.o
tools/um/tests/boot.c new file +393 -0
393 lines not on this page · raw message
tools/um/tests/boot.sh new file +9 -0
@@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +script_dir=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd) +source $script_dir/test.sh + +lkl_test_plan 1 "boot" +lkl_test_run 1 +lkl_test_exec $script_dir/boot
tools/um/tests/run.py new file +172 -0
172 lines not on this page · raw message
tools/um/tests/tap13.py new file +209 -0
209 lines not on this page · raw message
tools/um/tests/test.c new file +126 -0
126 lines not on this page · raw message
tools/um/tests/test.h new file +72 -0
72 lines not on this page · raw message
tools/um/tests/test.sh new file +181 -0
181 lines not on this page · raw message
Signature · 7 lines
2.21.0 (Apple Git-122.2) _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
RFC v6 21/21 um: nommu: add block device support of UML
In reply to Hajime TazakiThis commit adds block device support for nommu mode, and also added several host utilities to run a simple test program (tools/um/test/disk.c) successfully.
--- arch/um/include/asm/xor.h | 3 +- arch/um/include/shared/as-layout.h | 1 + arch/um/kernel/um_arch.c | 5 + arch/um/nommu/include/uapi/asm/host_ops.h | 7 + arch/um/nommu/include/uapi/asm/unistd.h | 2 + arch/um/nommu/um/Kconfig | 8 + arch/um/nommu/um/setup.c | 12 + tools/um/Targets | 2 + tools/um/include/lkl.h | 206 ++++++++++ tools/um/include/lkl_host.h | 1 + tools/um/lib/Build | 1 + tools/um/lib/fs.c | 461 ++++++++++++++++++++++ tools/um/lib/posix-host.c | 1 + tools/um/lib/utils.c | 3 + tools/um/tests/Build | 1 + tools/um/tests/cla.c | 159 ++++++++ tools/um/tests/cla.h | 33 ++ tools/um/tests/disk.c | 168 ++++++++ tools/um/tests/disk.sh | 70 ++++ tools/um/tests/run.py | 2 + 20 files changed, 1145 insertions(+), 1 deletion(-) create mode 100644 tools/um/lib/fs.c create mode 100644 tools/um/tests/cla.c create mode 100644 tools/um/tests/cla.h create mode 100644 tools/um/tests/disk.c create mode 100755 tools/um/tests/disk.sh
arch/um/include/asm/xor.h +2 -1
@@ -4,4 +4,5 @@/* pick an arbitrary one - measuring isn't possible with inf-cpu */ #define XOR_SELECT_TEMPLATE (x) \ - (time_travel_mode == TT_MODE_INFCPU ? &xor_block_8regs : NULL) + (time_travel_mode == TT_MODE_INFCPU || (!IS_ENABLED(CONFIG_MMU)) ? \ + &xor_block_8regs : NULL)
arch/um/include/shared/as-layout.h +1 -0
@@ -57,6 +57,7 @@ extern unsigned long host_task_size;extern int linux_main (int argc,char **argv);extern void uml_finishsetup (void ); +extern void uml_set_args (char *args);struct siginfo ;extern void (*sig_info[])(int ,struct siginfo *si,struct uml_pt_regs *);
arch/um/kernel/um_arch.c +5 -0
@@ -41,6 +41,11 @@ static void __init add_arg(char *arg)strcat (command_line, arg); } +void __init uml_set_args (char *args) +{ +strcat (command_line, args); +} +/* * These fields are initialized at boot time and not changed. * XXX This structure is used only in the non-SMP case. Maybe this
arch/um/nommu/include/uapi/asm/host_ops.h +7 -0
@@ -15,6 +15,11 @@ struct lkl_jmp_buf {* * These operations must be provided by a host library or by the application * itself. +* +* @um_devices - string containg the list of UML devices in command line +* format. This string is appended to the kernel command line and +* is provided here for convenience to be implemented by the host library. +* * @print - optional operation that receives console messages * @panic - called during a kernel panic *
@@ -65,6 +70,8 @@ struct lkl_jmp_buf {* */ struct lkl_host_operations { +const char *um_devices; +void (*print)(const char *str,int len);void (*panic)(void );
arch/um/nommu/include/uapi/asm/unistd.h +2 -0
@@ -3,6 +3,8 @@#define __UM_NOMMU_UAPI_UNISTD_H#define __ARCH_WANT_NEW_STAT +#define __ARCH_WANT_SET_GET_RLIMIT +#include <asm/bitsperlong.h> #if __BITS_PER_LONG ==64
arch/um/nommu/um/Kconfig +8 -0
@@ -4,6 +4,10 @@ config UML_NOMMU select UACCESS_MEMCPY select ARCH_THREAD_STACK_ALLOCATOR select ARCH_HAS_SYSCALL_WRAPPER + select VFAT_FS + select NLS_CODEPAGE_437 + select NLS_ISO8859_1 + select BTRFS_FS config 64BIT bool
@@ -35,3 +39,7 @@ config STACKTRACE_SUPPORT config PRINTK_TIME bool default y + +config RAID6_PQ_BENCHMARK + bool + default n
arch/um/nommu/um/setup.c +12 -0
@@ -45,13 +45,25 @@ static void __init *lkl_run_kernel(void *arg)return NULL ; } +static char _cmd_line[COMMAND_LINE_SIZE ];int __init lkl_start_kernel (struct lkl_host_operations *ops,const char *fmt, ...) { +va_list ap;int ret; lkl_ops = ops; +va_start (ap, fmt); + ret =vsnprintf (_cmd_line,COMMAND_LINE_SIZE , fmt, ap); +va_end (ap); + +if (ops->um_devices) +strscpy (_cmd_line + ret, ops->um_devices, +COMMAND_LINE_SIZE - ret); + +uml_set_args (_cmd_line); + init_sem = lkl_ops->sem_alloc (0 );if (!init_sem)return -ENOMEM ;
tools/um/Targets +2 -0
@@ -1,10 +1,12 @@ ifeq ($(UMMODE),library) progs-y += tests/boot +progs-y += tests/disk else progs-y += uml/linux endif LDFLAGS_boot-y := -pie +LDFLAGS_disk-y := -pie LDLIBS := -lrt -lpthread -lutil LDFLAGS_linux-y := -no-pie -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
tools/um/include/lkl.h +206 -0
224 lines not on this page · raw message
tools/um/include/lkl_host.h +1 -0
@@ -10,6 +10,7 @@ extern "C" {#include <lkl.h> extern struct lkl_host_operations lkl_host_ops; +extern char lkl_um_devs[4096 ];/** * lkl_printf - print a message via the host print operation
tools/um/lib/Build +1 -0
@@ -4,3 +4,4 @@ CFLAGS_posix-host.o += -D_FILE_OFFSET_BITS=64 liblinux-$(CONFIG_UMMODE_LIB) += utils.o liblinux-$(CONFIG_UMMODE_LIB) += posix-host.o liblinux-$(CONFIG_UMMODE_LIB) += jmp_buf.o +liblinux-$(CONFIG_UMMODE_LIB) += fs.o
tools/um/lib/fs.c new file +461 -0
461 lines not on this page · raw message
tools/um/lib/posix-host.c +1 -0
@@ -263,6 +263,7 @@ static void *tls_get(struct lkl_tls_key *key) }struct lkl_host_operations lkl_host_ops = { + .um_devices = lkl_um_devs, .panic = panic, .print = print, .mem_alloc = (void *)malloc,
tools/um/lib/utils.c +3 -0
@@ -4,6 +4,9 @@#include <string.h> #include <lkl_host.h> +/* XXX: find a better place */ +char lkl_um_devs[4096 ]; +static const char *const lkl_err_strings[] = {"Success" ,"Operation not permitted" ,
tools/um/tests/Build +1 -0
@@ -1 +1,2 @@ boot-y += boot.o test.o +disk-y += disk.o test.o cla.o
tools/um/tests/cla.c new file +159 -0
159 lines not on this page · raw message
tools/um/tests/cla.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _LKL_TEST_CLA_H +#define _LKL_TEST_CLA_H + +enum cl_arg_type { +CL_ARG_USER =0 , +CL_ARG_BOOL , +CL_ARG_INT , +CL_ARG_STR , +CL_ARG_STR_SET , +CL_ARG_IPV4 , +CL_ARG_END , +}; + +struct cl_arg ; + +typedef int (*cl_arg_parser_t )(struct cl_arg *arg,const char *value); + +struct cl_arg { +const char *long_name; +char short_name; +const char *help; +int has_arg; +enum cl_arg_type type; +void *store; +void *set; +cl_arg_parser_t parser; +}; + +int cla_parse_args (int argc,const char **argv,struct cl_arg *args); + + +#endif /* _LKL_TEST_CLA_H */
tools/um/tests/disk.c new file +168 -0
168 lines not on this page · raw message
tools/um/tests/disk.sh new file +70 -0
70 lines not on this page · raw message
tools/um/tests/run.py +2 -0
@@ -50,6 +50,8 @@ mydir=os.path.dirname(os.path.realpath(__file__)) tests = [ 'boot.sh', + 'disk.sh -t ext4', + 'disk.sh -t vfat', ] parser = argparse.ArgumentParser(description='LKL test runner')
Signature · 1 line
2.21.0 (Apple Git-122.2)
Anton Ivanov
maintainerRe: [RFC v6 01/21] um: split build in kernel and host parts
In reply to Hajime TazakiQuoted 14 lines · Hajime Tazaki
From: Octavian Purdila <[email protected]>
This patch splits the UML build in two parts: a kernel part that generates a relocatable object (linux.o) and a host build part that links the relocatable object into an executable.
This allows us to simplify the linker script since we can now remove the host bits (e.g. .rel sections). It also gives us greater flexibility since it will be much easier to support other architectures and OSes if we use the standard linker script.
The host build part has been implemented in
tools/umso that we can reuse the available host build infrastructure.
Quoted 7 lines
The patch also changes the UML build invocation, if before
$ make ARCH=um defconfig $ make ARCH=umwas generating the executable now this only generates the relocatable object.
This will break packaging in all distributions. We need to figure out an alternative way which is backward compatible with their builds.
Quoted 736 lines
To fully build UML use:
$ make -C tools/umwhich will generate
tools/lkl/linuxas the UML executable. To statically compiled UML use:$ make -C tools/lkl UML_STATIC=ySigned-off-by Octavian Purdila <[email protected]>Signed-off-by Hajime Tazaki <[email protected]>--- arch/um/Kconfig | 12 +-- arch/um/Makefile | 14 ++- arch/um/include/asm/common.lds.S | 99 ------------------ arch/um/kernel/dyn.lds.S | 171 ------------------------------- arch/um/kernel/uml.lds.S | 115 --------------------- arch/um/kernel/vmlinux.lds.S | 91 ++++++++++++++-- scripts/link-vmlinux.sh | 42 +++----- tools/um/Makefile | 72 +++++++++++++ tools/um/Targets | 4 + tools/um/uml/Build | 0 10 files changed, 184 insertions(+), 436 deletions(-)delete mode 100644
arch/um/include/asm/common.lds.Sdelete mode 100644arch/um/kernel/dyn.lds.Sdelete mode 100644arch/um/kernel/uml.lds.Screate mode 100644tools/um/Makefile
create mode 100644tools/um/Targets
create mode 100644tools/um/uml/Buildarch/um/Kconfig +1
-11@@ -20,6 +20,7 @@ config UML select GENERIC_CLOCKEVENTS select HAVE_GCC_PLUGINS select TTY # Needed for line.c + select MODULE_REL_CRCS if MODVERSIONS config MMU bool@@ -79,17 +80,6 @@ config STATIC_LINK NOTE: This option is incompatible with some networking features which depend on features that require being dynamically loaded (like NSS). -config LD_SCRIPT_STATIC - bool - default y - depends on STATIC_LINK - -config LD_SCRIPT_DYN - bool - default y - depends on !LD_SCRIPT_STATIC - select MODULE_REL_CRCS if MODVERSIONS - config HOSTFS tristate "Host filesystem" helparch/um/Makefile +10
-4@@ -95,14 +95,20 @@ KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/include \ KERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \ -Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES)) KBUILD_CFLAGS += $(KERNEL_DEFINES) +LDFLAGS_vmlinux += -r -PHONY += linux +PHONY += linux.o -all: linux +all: linux.o -linux: vmlinux +linux.o: vmlinux @echo ' LINK $@' - $(Q)ln -f $< $@ + $(Q)$(OBJCOPY) -R .eh_frame $< $@ + +install: linux.o + @echo " INSTALL $(INSTALL_PATH)/lib/$<" + @mkdir -p $(INSTALL_PATH)/lib/ + @cp $< $(INSTALL_PATH)/lib/ define archhelp echo '* linux - Binary kernel image (./linux) - for backward'arch/um/include/asm/common.lds.S deleted +0
-99@@ -1,99 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm-generic/vmlinux.lds.h> - - .fini : { *(.fini) } =0x9090 - _etext = .; - PROVIDE (etext = .); - - . = ALIGN(4096); - _sdata = .; - PROVIDE (sdata = .); - - RO_DATA(4096) - - .unprotected : { *(.unprotected) } - . = ALIGN(4096); - PROVIDE (_unprotected_end = .); - - . = ALIGN(4096); - EXCEPTION_TABLE(0) - - BUG_TABLE - - .uml.setup.init : { - __uml_setup_start = .; - *(.uml.setup.init) - __uml_setup_end = .; - } - - .uml.help.init : { - __uml_help_start = .; - *(.uml.help.init) - __uml_help_end = .; - } - - .uml.postsetup.init : { - __uml_postsetup_start = .; - *(.uml.postsetup.init) - __uml_postsetup_end = .; - } - - .init.setup : { - INIT_SETUP(0) - } - - PERCPU_SECTION(32) - - .initcall.init : { - INIT_CALLS - } - - .con_initcall.init : { - CON_INITCALL - } - - .exitcall : { - __exitcall_begin = .; - *(.exitcall.exit) - __exitcall_end = .; - } - - .uml.exitcall : { - __uml_exitcall_begin = .; - *(.uml.exitcall.exit) - __uml_exitcall_end = .; - } - - . = ALIGN(4); - .altinstructions : { - __alt_instructions = .; - *(.altinstructions) - __alt_instructions_end = .; - } - .altinstr_replacement : { *(.altinstr_replacement) } - /* .exit.text is discard at runtime, not link time, to deal with references - from .altinstructions and .eh_frame */ - .exit.text : { EXIT_TEXT } - .exit.data : { *(.exit.data) } - - .preinit_array : { - __preinit_array_start = .; - *(.preinit_array) - __preinit_array_end = .; - } - .init_array : { - __init_array_start = .; - *(.init_array) - __init_array_end = .; - } - .fini_array : { - __fini_array_start = .; - *(.fini_array) - __fini_array_end = .; - } - - . = ALIGN(4096); - .init.ramfs : { - INIT_RAM_FS - } -arch/um/kernel/dyn.lds.S deleted +0
-171@@ -1,171 +0,0 @@ -#include <asm/vmlinux.lds.h> -#include <asm/page.h> - -OUTPUT_FORMAT(ELF_FORMAT) -OUTPUT_ARCH(ELF_ARCH) -ENTRY(_start) -jiffies = jiffies_64; - -SECTIONS -{ - PROVIDE (__executable_start = START); - . = START + SIZEOF_HEADERS; - .interp : { *(.interp) } - __binary_start = .; - . = ALIGN(4096); /* Init code and data */ - _text = .; - INIT_TEXT_SECTION(PAGE_SIZE) - - . = ALIGN(PAGE_SIZE); - - /* Read-only sections, merged into text segment: */ - .hash : { *(.hash) } - .gnu.hash : { *(.gnu.hash) } - .dynsym : { *(.dynsym) } - .dynstr : { *(.dynstr) } - .gnu.version : { *(.gnu.version) } - .gnu.version_d : { *(.gnu.version_d) } - .gnu.version_r : { *(.gnu.version_r) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.text : { *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) } - .rela.text : { *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.rodata : { *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) } - .rela.rodata : { *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) } - .rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) } - .rela.data : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) } - .rel.tdata : { *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) } - .rela.tdata : { *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) } - .rel.tbss : { *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) } - .rela.tbss : { *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.bss : { *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) } - .rela.bss : { *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) } - .rel.plt : { - *(.rel.plt) - PROVIDE_HIDDEN(__rel_iplt_start = .); - *(.rel.iplt) - PROVIDE_HIDDEN(__rel_iplt_end = .); - } - .rela.plt : { - *(.rela.plt) - PROVIDE_HIDDEN(__rela_iplt_start = .); - *(.rela.iplt) - PROVIDE_HIDDEN(__rela_iplt_end = .); - } - .init : { - KEEP (*(.init)) - } =0x90909090 - .plt : { *(.plt) } - .text : { - _stext = .; - TEXT_TEXT - SCHED_TEXT - CPUIDLE_TEXT - LOCK_TEXT - IRQENTRY_TEXT - SOFTIRQENTRY_TEXT - *(.fixup) - *(.stub .text.* .gnu.linkonce.t.*) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - - . = ALIGN(PAGE_SIZE); - } =0x90909090 - . = ALIGN(PAGE_SIZE); - .syscall_stub : { - __syscall_stub_start = .; - *(.__syscall_stub*) - __syscall_stub_end = .; - } - .fini : { - KEEP (*(.fini)) - } =0x90909090 - - .kstrtab : { *(.kstrtab) } - - #include <asm/common.lds.S> - - __init_begin = .; - init.data : { INIT_DATA } - __init_end = .; - - /* Ensure the __preinit_array_start label is properly aligned. We - could instead move the label definition inside the section, but - the linker would then create the section even if it turns out to - be empty, which isn't pretty. */ - . = ALIGN(32 / 8); - .preinit_array : { *(.preinit_array) } - .init_array : { *(.init_array) } - .fini_array : { *(.fini_array) } - .data : { - INIT_TASK_DATA(KERNEL_STACK_SIZE) - . = ALIGN(KERNEL_STACK_SIZE); - *(.data..init_irqstack) - DATA_DATA - *(.data.* .gnu.linkonce.d.*) - SORT(CONSTRUCTORS) - } - .data1 : { *(.data1) } - .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } - .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } - .eh_frame : { KEEP (*(.eh_frame)) } - .gcc_except_table : { *(.gcc_except_table) } - .dynamic : { *(.dynamic) } - .ctors : { - /* gcc uses crtbegin.o to find the start of - the constructors, so we make sure it is - first. Because this is a wildcard, it - doesn't matter if the user does not - actually link against crtbegin.o; the - linker won't look for a file to match a - wildcard. The wildcard also means that it - doesn't matter which directory crtbegin.o - is in. */ - KEEP (*crtbegin.o(.ctors)) - /* We don't want to include the .ctor section from - from the crtend.o file until after the sorted ctors. - The .ctor section from the crtend file contains the - end of ctors marker and it must be last */ - KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors)) - KEEP (*(SORT(.ctors.*))) - KEEP (*(.ctors)) - } - .dtors : { - KEEP (*crtbegin.o(.dtors)) - KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors)) - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - } - .jcr : { KEEP (*(.jcr)) } - .got : { *(.got.plt) *(.got) } - _edata = .; - PROVIDE (edata = .); - .bss : { - __bss_start = .; - *(.dynbss) - *(.bss .bss.* .gnu.linkonce.b.*) - *(COMMON) - /* Align here to ensure that the .bss section occupies space up to - _end. Align after .bss to ensure correct alignment even if the - .bss section disappears because there are no input sections. */ - . = ALIGN(32 / 8); - . = ALIGN(32 / 8); - } - __bss_stop = .; - _end = .; - PROVIDE (end = .); - - STABS_DEBUG - - DWARF_DEBUG - - DISCARDS -}arch/um/kernel/uml.lds.S deleted +0
-115@@ -1,115 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/vmlinux.lds.h> -#include <asm/page.h> - -OUTPUT_FORMAT(ELF_FORMAT) -OUTPUT_ARCH(ELF_ARCH) -ENTRY(_start) -jiffies = jiffies_64; - -SECTIONS -{ - /* This must contain the right address - not quite the default ELF one.*/ - PROVIDE (__executable_start = START); - /* Static binaries stick stuff here, like the sigreturn trampoline, - * invisibly to objdump. So, just make __binary_start equal to the very - * beginning of the executable, and if there are unmapped pages after this, - * they are forever unusable. - */ - __binary_start = START; - - . = START + SIZEOF_HEADERS; - . = ALIGN(PAGE_SIZE); - - _text = .; - INIT_TEXT_SECTION(0) - - .text : - { - _stext = .; - TEXT_TEXT - SCHED_TEXT - CPUIDLE_TEXT - LOCK_TEXT - IRQENTRY_TEXT - SOFTIRQENTRY_TEXT - *(.fixup) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - *(.gnu.linkonce.t*) - } - - . = ALIGN(PAGE_SIZE); - .syscall_stub : { - __syscall_stub_start = .; - *(.__syscall_stub*) - __syscall_stub_end = .; - } - - /* - * These are needed even in a static link, even if they wind up being empty. - * Newer glibc needs these __rel{,a}_iplt_{start,end} symbols. - */ - .rel.plt : { - *(.rel.plt) - PROVIDE_HIDDEN(__rel_iplt_start = .); - *(.rel.iplt) - PROVIDE_HIDDEN(__rel_iplt_end = .); - } - .rela.plt : { - *(.rela.plt) - PROVIDE_HIDDEN(__rela_iplt_start = .); - *(.rela.iplt) - PROVIDE_HIDDEN(__rela_iplt_end = .); - } - - #include <asm/common.lds.S> - - __init_begin = .; - init.data : { INIT_DATA } - __init_end = .; - - .data : - { - INIT_TASK_DATA(KERNEL_STACK_SIZE) - . = ALIGN(KERNEL_STACK_SIZE); - *(.data..init_irqstack) - DATA_DATA - *(.gnu.linkonce.d*) - CONSTRUCTORS - } - .data1 : { *(.data1) } - .ctors : - { - *(.ctors) - } - .dtors : - { - *(.dtors) - } - - .got : { *(.got.plt) *(.got) } - .dynamic : { *(.dynamic) } - .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } - .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } - /* We want the small data sections together, so single-instruction offsets - can access them all, and initialized data all before uninitialized, so - we can shorten the on-disk segment size. */ - .sdata : { *(.sdata) } - _edata = .; - PROVIDE (edata = .); - . = ALIGN(PAGE_SIZE); - __bss_start = .; - PROVIDE(_bss_start = .); - SBSS(0) - BSS(0) - __bss_stop = .; - _end = .; - PROVIDE (end = .); - - STABS_DEBUG - - DWARF_DEBUG - - DISCARDS -}arch/um/kernel/vmlinux.lds.S +85
-6@@ -1,8 +1,87 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <asm/vmlinux.lds.h> +#include <asm/thread_info.h> +#include <asm/page.h> +#include <asm/thread_info.h> +#include <asm/cache.h> +#include <linux/export.h> -KERNEL_STACK_SIZE = 4096 * (1 << CONFIG_KERNEL_STACK_ORDER); +OUTPUT_FORMAT(ELF_FORMAT) +jiffies = jiffies_64; -#ifdef CONFIG_LD_SCRIPT_STATIC -#include "uml.lds.S" -#else -#include "dyn.lds.S" -#endif + +SECTIONS +{ + __init_begin = . ; + HEAD_TEXT_SECTION + INIT_TEXT_SECTION(PAGE_SIZE) + INIT_DATA_SECTION(16) + PERCPU_SECTION(L1_CACHE_BYTES) + __init_end = . ; + + _stext = . ; + _text = . ; + .text : ALIGN(THREAD_SIZE) + { + __binary_start = . ; + TEXT_TEXT + SCHED_TEXT + LOCK_TEXT + CPUIDLE_TEXT + IRQENTRY_TEXT + SOFTIRQENTRY_TEXT + } + _etext = . ; + + .syscall_stub : ALIGN(PAGE_SIZE) + { + __syscall_stub_start = .; + *(.__syscall_stub*) + __syscall_stub_end = .; + } + + _sdata = . ; + RO_DATA(PAGE_SIZE) + RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE) + .data : ALIGN(THREAD_SIZE) { } + + EXCEPTION_TABLE(16) + + .uml.init_irqstack : ALIGN(THREAD_SIZE) { + *(.data..init_irqstack) + } + + .uml.setup.init : ALIGN(8) { + __uml_setup_start = .; + *(.uml.setup.init) + __uml_setup_end = .; + } + + .uml.help.init : ALIGN(8) { + __uml_help_start = .; + *(.uml.help.init) + __uml_help_end = .; + } + + .uml.postsetup.init : ALIGN(8) { + __uml_postsetup_start = .; + *(.uml.postsetup.init) + __uml_postsetup_end = .; + } + + .uml.exitcall : ALIGN(8) { + __uml_exitcall_begin = .; + *(.uml.exitcall.exit) + __uml_exitcall_end = .; + } + _edata = . ; + + BSS_SECTION(0, 0, 0) + _end = . ; + + STABS_DEBUG + + DWARF_DEBUG + + DISCARDS +}scripts/link-vmlinux.sh +12
-30@@ -102,36 +102,18 @@ vmlinux_link() strip_debug=-Wl,--strip-debug fi - if [ "${SRCARCH}" != "um" ]; then - objects="--whole-archive \ - ${KBUILD_VMLINUX_OBJS} \ - --no-whole-archive \ - --start-group \ - ${KBUILD_VMLINUX_LIBS} \ - --end-group \ - ${@}" - - ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} \ - ${strip_debug#-Wl,} \ - -o ${output} \ - -T ${lds} ${objects} - else - objects="-Wl,--whole-archive \ - ${KBUILD_VMLINUX_OBJS} \ - -Wl,--no-whole-archive \ - -Wl,--start-group \ - ${KBUILD_VMLINUX_LIBS} \ - -Wl,--end-group \ - ${@}" - - ${CC} ${CFLAGS_vmlinux} \ - ${strip_debug} \ - -o ${output} \ - -Wl,-T,${lds} \ - ${objects} \ - -lutil -lrt -lpthread - rm -f linux - fi + objects="--whole-archive \ + ${KBUILD_VMLINUX_OBJS} \ + --no-whole-archive \ + --start-group \ + ${KBUILD_VMLINUX_LIBS} \ + --end-group \ + ${@}" + + ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} \ + ${strip_debug#-Wl,} \ + -o ${output} \ + -T ${lds} ${objects} } # generate .BTF typeinfo from DWARF debuginfotools/um/Makefile new file +72
-0@@ -0,0 +1,72 @@ +# Do not use make's built-in rules +# (this improves performance and avoids hard-to-debug behaviour); +# also do not print "Entering directory..." messages from make +.SUFFIXES: +MAKEFLAGS += -r --no-print-directory + +KCONFIG?=defconfig + +ifneq ($(silent),1) + ifneq ($(V),1) + QUIET_AUTOCONF = @echo ' AUTOCONF '$@; + Q = @ + endif +endif + +PREFIX := /usr + +ifeq (,$(srctree)) + srctree := $(patsubst %/,%,$(dir $(shell pwd))) + srctree := $(patsubst %/,%,$(dir $(srctree))) +endif +export srctree + +-include ../scripts/Makefile.include + +# OUTPUT fixup should be *after* include ../scripts/Makefile.include +ifneq ($(OUTPUT),) + OUTPUT := $(OUTPUT)/tools/um/ +else + OUTPUT := $(CURDIR)/ +endif +export OUTPUT +export objtree := $(OUTPUT)/../.. + + +all: + +export CFLAGS += -I$(OUTPUT)/include -Iinclude -Wall -g -O2 -Wextra -fPIC \ + -Wno-unused-parameter \ + -Wno-missing-field-initializers -fno-strict-aliasing + +-include Targets + +TARGETS := $(progs-y:%=$(OUTPUT)%) +TARGETS += $(libs-y:%=$(OUTPUT)%) +all: $(TARGETS) + +# rule to build linux.o +$(OUTPUT)lib/linux.o: + $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) $(KCONFIG) + $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) install INSTALL_PATH=$(OUTPUT) + +$(OUTPUT)liblinux.a: $(OUTPUT)lib/linux.o $(OUTPUT)uml/liblinux-in.o + $(QUIET_AR)$(AR) -rc $@ $^ + +# rule to link programs +$(OUTPUT)%: $(OUTPUT)%-in.o $(OUTPUT)liblinux.a + $(QUIET_LINK)$(CC) $(LDFLAGS) $(LDFLAGS_$(notdir $*)-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$(notdir $*)-y) + +$(OUTPUT)%-in.o: FORCE + $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) + +clean: + $(call QUIET_CLEAN, objects)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd'\ + -delete -o -name '\.*.d' -delete + $(call QUIET_CLEAN, liblinux.a)$(RM) $(OUTPUT)/liblinux.a + $(call QUIET_CLEAN, $(TARGETS))$(RM) $(TARGETS) + +FORCE: ; +.PHONY: all clean FORCE +.IGNORE: clean +.NOTPARALLEL : lib/linux.otools/um/Targets new file +4
-0@@ -0,0 +1,4 @@ +progs-y += uml/linux +LDLIBS_linux-y := -lrt -lpthread -lutil +LDFLAGS_linux-y := -no-pie -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc +LDFLAGS_linux-$(UML_STATIC) += -statictools/um/uml/Build new file +0
-0
Signature · 3 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/
Anton Ivanov
maintainerRe: [RFC v6 01/21] um: split build in kernel and host parts
In reply to Hajime TazakiQuoted 14 lines · Hajime Tazaki
From: Octavian Purdila <[email protected]>
This patch splits the UML build in two parts: a kernel part that generates a relocatable object (linux.o) and a host build part that links the relocatable object into an executable.
This allows us to simplify the linker script since we can now remove the host bits (e.g. .rel sections). It also gives us greater flexibility since it will be much easier to support other architectures and OSes if we use the standard linker script.
The host build part has been implemented in
tools/umso that we can reuse the available host build infrastructure.
Quoted 7 lines
The patch also changes the UML build invocation, if before
$ make ARCH=um defconfig $ make ARCH=umwas generating the executable now this only generates the relocatable object.
It also fails now.
ERROR: modpost: "memmove" [drivers/net/slip/slhc.ko] undefined!
ERROR: modpost: "memset" [drivers/net/ppp/ppp_generic.ko] undefined!
ERROR: modpost: "memset" [drivers/net/tun.ko] undefined!
ERROR: modpost: "memmove" [drivers/block/loop.ko] undefined!
ERROR: modpost: "memset" [drivers/block/loop.ko] undefined!
ERROR: modpost: "memset" [fs/autofs/autofs4.ko] undefined!
ERROR: modpost: "memset" [fs/isofs/isofs.ko] undefined!
ERROR: modpost: "memset" [fs/binfmt_misc.ko] undefined! make[1]: *** [scripts/Makefile.modpost:111: Module.symvers] Error 1 make[1]: *** Deleting file 'Module.symvers'
make: *** [Makefile:1388: modules] Error 2
make: *** Waiting for unfinished jobs....
Quoted 736 lines
To fully build UML use:
$ make -C tools/umwhich will generate
tools/lkl/linuxas the UML executable. To statically compiled UML use:$ make -C tools/lkl UML_STATIC=ySigned-off-by Octavian Purdila <[email protected]>Signed-off-by Hajime Tazaki <[email protected]>--- arch/um/Kconfig | 12 +-- arch/um/Makefile | 14 ++- arch/um/include/asm/common.lds.S | 99 ------------------ arch/um/kernel/dyn.lds.S | 171 ------------------------------- arch/um/kernel/uml.lds.S | 115 --------------------- arch/um/kernel/vmlinux.lds.S | 91 ++++++++++++++-- scripts/link-vmlinux.sh | 42 +++----- tools/um/Makefile | 72 +++++++++++++ tools/um/Targets | 4 + tools/um/uml/Build | 0 10 files changed, 184 insertions(+), 436 deletions(-)delete mode 100644
arch/um/include/asm/common.lds.Sdelete mode 100644arch/um/kernel/dyn.lds.Sdelete mode 100644arch/um/kernel/uml.lds.Screate mode 100644tools/um/Makefile
create mode 100644tools/um/Targets
create mode 100644tools/um/uml/Buildarch/um/Kconfig +1
-11@@ -20,6 +20,7 @@ config UML select GENERIC_CLOCKEVENTS select HAVE_GCC_PLUGINS select TTY # Needed for line.c + select MODULE_REL_CRCS if MODVERSIONS config MMU bool@@ -79,17 +80,6 @@ config STATIC_LINK NOTE: This option is incompatible with some networking features which depend on features that require being dynamically loaded (like NSS). -config LD_SCRIPT_STATIC - bool - default y - depends on STATIC_LINK - -config LD_SCRIPT_DYN - bool - default y - depends on !LD_SCRIPT_STATIC - select MODULE_REL_CRCS if MODVERSIONS - config HOSTFS tristate "Host filesystem" helparch/um/Makefile +10
-4@@ -95,14 +95,20 @@ KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/include \ KERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \ -Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES)) KBUILD_CFLAGS += $(KERNEL_DEFINES) +LDFLAGS_vmlinux += -r -PHONY += linux +PHONY += linux.o -all: linux +all: linux.o -linux: vmlinux +linux.o: vmlinux @echo ' LINK $@' - $(Q)ln -f $< $@ + $(Q)$(OBJCOPY) -R .eh_frame $< $@ + +install: linux.o + @echo " INSTALL $(INSTALL_PATH)/lib/$<" + @mkdir -p $(INSTALL_PATH)/lib/ + @cp $< $(INSTALL_PATH)/lib/ define archhelp echo '* linux - Binary kernel image (./linux) - for backward'arch/um/include/asm/common.lds.S deleted +0
-99@@ -1,99 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm-generic/vmlinux.lds.h> - - .fini : { *(.fini) } =0x9090 - _etext = .; - PROVIDE (etext = .); - - . = ALIGN(4096); - _sdata = .; - PROVIDE (sdata = .); - - RO_DATA(4096) - - .unprotected : { *(.unprotected) } - . = ALIGN(4096); - PROVIDE (_unprotected_end = .); - - . = ALIGN(4096); - EXCEPTION_TABLE(0) - - BUG_TABLE - - .uml.setup.init : { - __uml_setup_start = .; - *(.uml.setup.init) - __uml_setup_end = .; - } - - .uml.help.init : { - __uml_help_start = .; - *(.uml.help.init) - __uml_help_end = .; - } - - .uml.postsetup.init : { - __uml_postsetup_start = .; - *(.uml.postsetup.init) - __uml_postsetup_end = .; - } - - .init.setup : { - INIT_SETUP(0) - } - - PERCPU_SECTION(32) - - .initcall.init : { - INIT_CALLS - } - - .con_initcall.init : { - CON_INITCALL - } - - .exitcall : { - __exitcall_begin = .; - *(.exitcall.exit) - __exitcall_end = .; - } - - .uml.exitcall : { - __uml_exitcall_begin = .; - *(.uml.exitcall.exit) - __uml_exitcall_end = .; - } - - . = ALIGN(4); - .altinstructions : { - __alt_instructions = .; - *(.altinstructions) - __alt_instructions_end = .; - } - .altinstr_replacement : { *(.altinstr_replacement) } - /* .exit.text is discard at runtime, not link time, to deal with references - from .altinstructions and .eh_frame */ - .exit.text : { EXIT_TEXT } - .exit.data : { *(.exit.data) } - - .preinit_array : { - __preinit_array_start = .; - *(.preinit_array) - __preinit_array_end = .; - } - .init_array : { - __init_array_start = .; - *(.init_array) - __init_array_end = .; - } - .fini_array : { - __fini_array_start = .; - *(.fini_array) - __fini_array_end = .; - } - - . = ALIGN(4096); - .init.ramfs : { - INIT_RAM_FS - } -arch/um/kernel/dyn.lds.S deleted +0
-171@@ -1,171 +0,0 @@ -#include <asm/vmlinux.lds.h> -#include <asm/page.h> - -OUTPUT_FORMAT(ELF_FORMAT) -OUTPUT_ARCH(ELF_ARCH) -ENTRY(_start) -jiffies = jiffies_64; - -SECTIONS -{ - PROVIDE (__executable_start = START); - . = START + SIZEOF_HEADERS; - .interp : { *(.interp) } - __binary_start = .; - . = ALIGN(4096); /* Init code and data */ - _text = .; - INIT_TEXT_SECTION(PAGE_SIZE) - - . = ALIGN(PAGE_SIZE); - - /* Read-only sections, merged into text segment: */ - .hash : { *(.hash) } - .gnu.hash : { *(.gnu.hash) } - .dynsym : { *(.dynsym) } - .dynstr : { *(.dynstr) } - .gnu.version : { *(.gnu.version) } - .gnu.version_d : { *(.gnu.version_d) } - .gnu.version_r : { *(.gnu.version_r) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.text : { *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) } - .rela.text : { *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.rodata : { *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) } - .rela.rodata : { *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) } - .rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) } - .rela.data : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) } - .rel.tdata : { *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) } - .rela.tdata : { *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) } - .rel.tbss : { *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) } - .rela.tbss : { *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.bss : { *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) } - .rela.bss : { *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) } - .rel.plt : { - *(.rel.plt) - PROVIDE_HIDDEN(__rel_iplt_start = .); - *(.rel.iplt) - PROVIDE_HIDDEN(__rel_iplt_end = .); - } - .rela.plt : { - *(.rela.plt) - PROVIDE_HIDDEN(__rela_iplt_start = .); - *(.rela.iplt) - PROVIDE_HIDDEN(__rela_iplt_end = .); - } - .init : { - KEEP (*(.init)) - } =0x90909090 - .plt : { *(.plt) } - .text : { - _stext = .; - TEXT_TEXT - SCHED_TEXT - CPUIDLE_TEXT - LOCK_TEXT - IRQENTRY_TEXT - SOFTIRQENTRY_TEXT - *(.fixup) - *(.stub .text.* .gnu.linkonce.t.*) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - - . = ALIGN(PAGE_SIZE); - } =0x90909090 - . = ALIGN(PAGE_SIZE); - .syscall_stub : { - __syscall_stub_start = .; - *(.__syscall_stub*) - __syscall_stub_end = .; - } - .fini : { - KEEP (*(.fini)) - } =0x90909090 - - .kstrtab : { *(.kstrtab) } - - #include <asm/common.lds.S> - - __init_begin = .; - init.data : { INIT_DATA } - __init_end = .; - - /* Ensure the __preinit_array_start label is properly aligned. We - could instead move the label definition inside the section, but - the linker would then create the section even if it turns out to - be empty, which isn't pretty. */ - . = ALIGN(32 / 8); - .preinit_array : { *(.preinit_array) } - .init_array : { *(.init_array) } - .fini_array : { *(.fini_array) } - .data : { - INIT_TASK_DATA(KERNEL_STACK_SIZE) - . = ALIGN(KERNEL_STACK_SIZE); - *(.data..init_irqstack) - DATA_DATA - *(.data.* .gnu.linkonce.d.*) - SORT(CONSTRUCTORS) - } - .data1 : { *(.data1) } - .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } - .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } - .eh_frame : { KEEP (*(.eh_frame)) } - .gcc_except_table : { *(.gcc_except_table) } - .dynamic : { *(.dynamic) } - .ctors : { - /* gcc uses crtbegin.o to find the start of - the constructors, so we make sure it is - first. Because this is a wildcard, it - doesn't matter if the user does not - actually link against crtbegin.o; the - linker won't look for a file to match a - wildcard. The wildcard also means that it - doesn't matter which directory crtbegin.o - is in. */ - KEEP (*crtbegin.o(.ctors)) - /* We don't want to include the .ctor section from - from the crtend.o file until after the sorted ctors. - The .ctor section from the crtend file contains the - end of ctors marker and it must be last */ - KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors)) - KEEP (*(SORT(.ctors.*))) - KEEP (*(.ctors)) - } - .dtors : { - KEEP (*crtbegin.o(.dtors)) - KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors)) - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - } - .jcr : { KEEP (*(.jcr)) } - .got : { *(.got.plt) *(.got) } - _edata = .; - PROVIDE (edata = .); - .bss : { - __bss_start = .; - *(.dynbss) - *(.bss .bss.* .gnu.linkonce.b.*) - *(COMMON) - /* Align here to ensure that the .bss section occupies space up to - _end. Align after .bss to ensure correct alignment even if the - .bss section disappears because there are no input sections. */ - . = ALIGN(32 / 8); - . = ALIGN(32 / 8); - } - __bss_stop = .; - _end = .; - PROVIDE (end = .); - - STABS_DEBUG - - DWARF_DEBUG - - DISCARDS -}arch/um/kernel/uml.lds.S deleted +0
-115@@ -1,115 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm/vmlinux.lds.h> -#include <asm/page.h> - -OUTPUT_FORMAT(ELF_FORMAT) -OUTPUT_ARCH(ELF_ARCH) -ENTRY(_start) -jiffies = jiffies_64; - -SECTIONS -{ - /* This must contain the right address - not quite the default ELF one.*/ - PROVIDE (__executable_start = START); - /* Static binaries stick stuff here, like the sigreturn trampoline, - * invisibly to objdump. So, just make __binary_start equal to the very - * beginning of the executable, and if there are unmapped pages after this, - * they are forever unusable. - */ - __binary_start = START; - - . = START + SIZEOF_HEADERS; - . = ALIGN(PAGE_SIZE); - - _text = .; - INIT_TEXT_SECTION(0) - - .text : - { - _stext = .; - TEXT_TEXT - SCHED_TEXT - CPUIDLE_TEXT - LOCK_TEXT - IRQENTRY_TEXT - SOFTIRQENTRY_TEXT - *(.fixup) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - *(.gnu.linkonce.t*) - } - - . = ALIGN(PAGE_SIZE); - .syscall_stub : { - __syscall_stub_start = .; - *(.__syscall_stub*) - __syscall_stub_end = .; - } - - /* - * These are needed even in a static link, even if they wind up being empty. - * Newer glibc needs these __rel{,a}_iplt_{start,end} symbols. - */ - .rel.plt : { - *(.rel.plt) - PROVIDE_HIDDEN(__rel_iplt_start = .); - *(.rel.iplt) - PROVIDE_HIDDEN(__rel_iplt_end = .); - } - .rela.plt : { - *(.rela.plt) - PROVIDE_HIDDEN(__rela_iplt_start = .); - *(.rela.iplt) - PROVIDE_HIDDEN(__rela_iplt_end = .); - } - - #include <asm/common.lds.S> - - __init_begin = .; - init.data : { INIT_DATA } - __init_end = .; - - .data : - { - INIT_TASK_DATA(KERNEL_STACK_SIZE) - . = ALIGN(KERNEL_STACK_SIZE); - *(.data..init_irqstack) - DATA_DATA - *(.gnu.linkonce.d*) - CONSTRUCTORS - } - .data1 : { *(.data1) } - .ctors : - { - *(.ctors) - } - .dtors : - { - *(.dtors) - } - - .got : { *(.got.plt) *(.got) } - .dynamic : { *(.dynamic) } - .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } - .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } - /* We want the small data sections together, so single-instruction offsets - can access them all, and initialized data all before uninitialized, so - we can shorten the on-disk segment size. */ - .sdata : { *(.sdata) } - _edata = .; - PROVIDE (edata = .); - . = ALIGN(PAGE_SIZE); - __bss_start = .; - PROVIDE(_bss_start = .); - SBSS(0) - BSS(0) - __bss_stop = .; - _end = .; - PROVIDE (end = .); - - STABS_DEBUG - - DWARF_DEBUG - - DISCARDS -}arch/um/kernel/vmlinux.lds.S +85
-6@@ -1,8 +1,87 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <asm/vmlinux.lds.h> +#include <asm/thread_info.h> +#include <asm/page.h> +#include <asm/thread_info.h> +#include <asm/cache.h> +#include <linux/export.h> -KERNEL_STACK_SIZE = 4096 * (1 << CONFIG_KERNEL_STACK_ORDER); +OUTPUT_FORMAT(ELF_FORMAT) +jiffies = jiffies_64; -#ifdef CONFIG_LD_SCRIPT_STATIC -#include "uml.lds.S" -#else -#include "dyn.lds.S" -#endif + +SECTIONS +{ + __init_begin = . ; + HEAD_TEXT_SECTION + INIT_TEXT_SECTION(PAGE_SIZE) + INIT_DATA_SECTION(16) + PERCPU_SECTION(L1_CACHE_BYTES) + __init_end = . ; + + _stext = . ; + _text = . ; + .text : ALIGN(THREAD_SIZE) + { + __binary_start = . ; + TEXT_TEXT + SCHED_TEXT + LOCK_TEXT + CPUIDLE_TEXT + IRQENTRY_TEXT + SOFTIRQENTRY_TEXT + } + _etext = . ; + + .syscall_stub : ALIGN(PAGE_SIZE) + { + __syscall_stub_start = .; + *(.__syscall_stub*) + __syscall_stub_end = .; + } + + _sdata = . ; + RO_DATA(PAGE_SIZE) + RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE) + .data : ALIGN(THREAD_SIZE) { } + + EXCEPTION_TABLE(16) + + .uml.init_irqstack : ALIGN(THREAD_SIZE) { + *(.data..init_irqstack) + } + + .uml.setup.init : ALIGN(8) { + __uml_setup_start = .; + *(.uml.setup.init) + __uml_setup_end = .; + } + + .uml.help.init : ALIGN(8) { + __uml_help_start = .; + *(.uml.help.init) + __uml_help_end = .; + } + + .uml.postsetup.init : ALIGN(8) { + __uml_postsetup_start = .; + *(.uml.postsetup.init) + __uml_postsetup_end = .; + } + + .uml.exitcall : ALIGN(8) { + __uml_exitcall_begin = .; + *(.uml.exitcall.exit) + __uml_exitcall_end = .; + } + _edata = . ; + + BSS_SECTION(0, 0, 0) + _end = . ; + + STABS_DEBUG + + DWARF_DEBUG + + DISCARDS +}scripts/link-vmlinux.sh +12
-30@@ -102,36 +102,18 @@ vmlinux_link() strip_debug=-Wl,--strip-debug fi - if [ "${SRCARCH}" != "um" ]; then - objects="--whole-archive \ - ${KBUILD_VMLINUX_OBJS} \ - --no-whole-archive \ - --start-group \ - ${KBUILD_VMLINUX_LIBS} \ - --end-group \ - ${@}" - - ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} \ - ${strip_debug#-Wl,} \ - -o ${output} \ - -T ${lds} ${objects} - else - objects="-Wl,--whole-archive \ - ${KBUILD_VMLINUX_OBJS} \ - -Wl,--no-whole-archive \ - -Wl,--start-group \ - ${KBUILD_VMLINUX_LIBS} \ - -Wl,--end-group \ - ${@}" - - ${CC} ${CFLAGS_vmlinux} \ - ${strip_debug} \ - -o ${output} \ - -Wl,-T,${lds} \ - ${objects} \ - -lutil -lrt -lpthread - rm -f linux - fi + objects="--whole-archive \ + ${KBUILD_VMLINUX_OBJS} \ + --no-whole-archive \ + --start-group \ + ${KBUILD_VMLINUX_LIBS} \ + --end-group \ + ${@}" + + ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} \ + ${strip_debug#-Wl,} \ + -o ${output} \ + -T ${lds} ${objects} } # generate .BTF typeinfo from DWARF debuginfotools/um/Makefile new file +72
-0@@ -0,0 +1,72 @@ +# Do not use make's built-in rules +# (this improves performance and avoids hard-to-debug behaviour); +# also do not print "Entering directory..." messages from make +.SUFFIXES: +MAKEFLAGS += -r --no-print-directory + +KCONFIG?=defconfig + +ifneq ($(silent),1) + ifneq ($(V),1) + QUIET_AUTOCONF = @echo ' AUTOCONF '$@; + Q = @ + endif +endif + +PREFIX := /usr + +ifeq (,$(srctree)) + srctree := $(patsubst %/,%,$(dir $(shell pwd))) + srctree := $(patsubst %/,%,$(dir $(srctree))) +endif +export srctree + +-include ../scripts/Makefile.include + +# OUTPUT fixup should be *after* include ../scripts/Makefile.include +ifneq ($(OUTPUT),) + OUTPUT := $(OUTPUT)/tools/um/ +else + OUTPUT := $(CURDIR)/ +endif +export OUTPUT +export objtree := $(OUTPUT)/../.. + + +all: + +export CFLAGS += -I$(OUTPUT)/include -Iinclude -Wall -g -O2 -Wextra -fPIC \ + -Wno-unused-parameter \ + -Wno-missing-field-initializers -fno-strict-aliasing + +-include Targets + +TARGETS := $(progs-y:%=$(OUTPUT)%) +TARGETS += $(libs-y:%=$(OUTPUT)%) +all: $(TARGETS) + +# rule to build linux.o +$(OUTPUT)lib/linux.o: + $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) $(KCONFIG) + $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) install INSTALL_PATH=$(OUTPUT) + +$(OUTPUT)liblinux.a: $(OUTPUT)lib/linux.o $(OUTPUT)uml/liblinux-in.o + $(QUIET_AR)$(AR) -rc $@ $^ + +# rule to link programs +$(OUTPUT)%: $(OUTPUT)%-in.o $(OUTPUT)liblinux.a + $(QUIET_LINK)$(CC) $(LDFLAGS) $(LDFLAGS_$(notdir $*)-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$(notdir $*)-y) + +$(OUTPUT)%-in.o: FORCE + $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) + +clean: + $(call QUIET_CLEAN, objects)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd'\ + -delete -o -name '\.*.d' -delete + $(call QUIET_CLEAN, liblinux.a)$(RM) $(OUTPUT)/liblinux.a + $(call QUIET_CLEAN, $(TARGETS))$(RM) $(TARGETS) + +FORCE: ; +.PHONY: all clean FORCE +.IGNORE: clean +.NOTPARALLEL : lib/linux.otools/um/Targets new file +4
-0@@ -0,0 +1,4 @@ +progs-y += uml/linux +LDLIBS_linux-y := -lrt -lpthread -lutil +LDFLAGS_linux-y := -no-pie -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc +LDFLAGS_linux-$(UML_STATIC) += -statictools/um/uml/Build new file +0
-0
Signature · 8 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/ _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [RFC v6 01/21] um: split build in kernel and host parts
Quoted 11 lines · Anton Ivanov
Quoted 7 lines
The patch also changes the UML build invocation, if before
$ make ARCH=um defconfig $ make ARCH=umwas generating the executable now this only generates the relocatable object.
It also fails now.
Quoted 12 lines
ERROR: modpost: "memmove" [
drivers/net/slip/slhc.ko] undefined!
ERROR: modpost: "memset" [drivers/net/ppp/ppp_generic.ko] undefined!
ERROR: modpost: "memset" [drivers/net/tun.ko] undefined!
ERROR: modpost: "memmove" [drivers/block/loop.ko] undefined!
ERROR: modpost: "memset" [drivers/block/loop.ko] undefined!
ERROR: modpost: "memset" [fs/autofs/autofs4.ko] undefined!
ERROR: modpost: "memset" [fs/isofs/isofs.ko] undefined!
ERROR: modpost: "memset" [fs/binfmt_misc.ko] undefined! make[1]: *** [scripts/Makefile.modpost:111: Module.symvers] Error 1 make[1]: *** Deleting file 'Module.symvers'
make: *** [Makefile:1388: modules] Error 2
make: *** Waiting for unfinished jobs....
Thanks for the review, I found this is a regression of patch 03/21, 364a2fc126e5 um: move arch/um/os-Linux dir to tools/um/uml
I will try to find a fix.
-- Hajime
Re: [RFC v6 01/21] um: split build in kernel and host parts
In reply to Anton IvanovQuoted 5 lines · Anton Ivanov
Quoted 5 lines
The host build part has been implemented in
tools/umso that we can reuse the available host build infrastructure.The patch also changes the UML build invocation, if before
Quoted 7 lines
Quoted 5 lines
$ make ARCH=um defconfig $ make ARCH=umwas generating the executable now this only generates the relocatable object.
This will break packaging in all distributions. We need to figure out an alternative way which is backward compatible with their builds.
Hmm, I understand the situation.
We may have to put additional steps after generating the relocatable object in arch/um/Makefile.
-- Hajime
Anton Ivanov
maintainerRe: [RFC v6 01/21] um: split build in kernel and host parts
Quoted 12 lines · Hajime Tazaki
Quoted 8 lines · Anton Ivanov
Quoted 8 lines
The host build part has been implemented in
tools/umso that we can reuse the available host build infrastructure.The patch also changes the UML build invocation, if before
$ make ARCH=um defconfig $ make ARCH=um
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
was generating the executable now this only generates the relocatable object.
This will break packaging in all distributions. We need to figure out an alternative way which is backward compatible with their builds.
Hmm, I understand the situation.
We may have to put additional steps after generating the relocatable object inarch/um/Makefile.
Cool.
I will go through the rest of the patches and if I notice something I will comment on specific ones.
Brgds,
Quoted 8 lines
-- Hajime
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Signature · 8 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/ _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
v7 cover Unifying LKL into UML
In reply to Hajime TazakiThis is another spin of the unification of LKL into UML. Based on the discussion of v4 patchset, we have tried to address issue raised and rewrote the patchset from scratch. The summary is listed in the changelog below.
Although there are still bugs in the patchset, we'd like to ask your opinions on the design we changed.
The milestone section is also updated: this patchset is for the milestone 1, though the common init API is still not implemented yet.
Changes in rfc v7:
- preserve make ARCH=um syntax to build UML
- introduce make ARCH=um UMMODE=library to build library mode
- fix undefined symbols issue during modpost
- clean up makefiles (arch/um, tools/um)
Changes in rfc v6:
- rebase with the current linus tree
Changes in rfc v5:
- rewrite whole patchset from scratch
- move arch-dependent code of arch/um and arch/x86/um to tools/um
- mainly code under os-Linux/ involved
- introduce 2-stage build (kernel, and host-dependent parts)
- clean up vmlinux.lds.S
- put LKL-specific implementations as a SUBARCH under arch/um/nommu
- introduce !CONFIG_MMU in arch/um
- use struct arch_thread and arch_switch_to() for subarch-specific thread implementation
- integrate with the IRQ infrastructure of UML
- tested with block device drivers (ubd) for the proof
Changes in rfc v4: (https://lwn.net/Articles/816276/)
- Rebase on the current uml/master branch
- Fix IRQ handling (bug fix)
- drop a patch for CONFIG_GENERIC_ATOMIC64 (comment by Peter Zijlstra)
- implement vector net driver for UMMODE_LIB (comment by Anton)
- clean up uapi headers to avoid duplicates
- clean up IRQ handling code (comment by Anton)
- fix error handling in test code (comments by David Disseldorp)
Changes in rfc v3:
- use UML drivers (net, block) from LKL programs
- drop virtio device implementations
- drop mingw32 (Windows) host
- drop android (arm/aarch64) host
- drop FreeBSD (x86_64) host
- drop LD_PRELOAD (hijack) support
- update milestone
rfc v2:
- use UMMODE instead of SUBARCH to switch UML or LKL
- tools/lkl directory is still there. I confirmed we can move under arch/um (e.g., arch/um/lkl/hosts). I will move it IF this is preferable.
- drop several patches involved non-uml directory
- drop several patches which are not required
- refine commit logs
- document updated
LKL (Linux Kernel Library) is aiming to allow reusing the Linux kernel code as extensively as possible with minimal effort and reduced maintenance overhead.
Examples of how LKL can be used are: creating userspace applications (running on Linux and other operating systems) that can read or write Linux filesystems or can use the Linux networking stack, creating kernel drivers for other operating systems that can read Linux filesystems, bootloaders support for reading/writing Linux filesystems, etc.
With LKL, the kernel code is compiled into an object file that can be directly linked by applications. The API offered by LKL is based on the Linux system call interface.
LKL is originally implemented as an architecture port in arch/lkl, but this series of commits tries to integrate this into arch/um as one of the mode of UML. This was discussed during RFC email of LKL (*1).
The latest LKL version can be found at https://github.com/lkl/linux
Milestone
=========
This patches is a first step toward upstreaming *library mode* of Linux kernel, but we think we need to have several steps toward our goal, describing in the below.
Milestone 1: LKL lib on top of UML
* Kernel - Host build split
- Build UML as a relocatable object using the UML's kernel linker script.
- Move the ptrace and other well isolated os code out of arch/um to tools/um
- Use standard host toolchain to create a static library stripped of the ptrace code. Use standard host toolchain to build the main UML executable.
- Add library init API that creates the UML kernel process and starts UML.
* System calls APIs
- Add new system call interface based on UML's irq facility.
- Use the LKL scripts to export the required headers to create system calls APIs that use the UML system calls infrastructure.
- Keep the underlying host and driver operations (threads, irqs, etc.) as they are now in UML.
* Boot test
- Port the LKL boot test to verify that we are able to programatically issue system calls.
Milestone 2: add virtio disk support
* Export asm/io.h operations to host/os. Create IO access operations and redirect them to weak os_ variants that use the current UML implementation.
* Add the LKL IO access layer including generic virtio handling and the virtio block device code.
* Port LKL disk test and disk apps (lklfuse, fs2tar, cptofs)
Milestone 3: new arch ports
* Abstract the system call / IRQ mode the move the implementation to host
* Abstract the thread model and move the implementation to host
* Add LKL thread model and LKL ports
Building LKL the host library and LKL applications
==================================================
% cd tools/um
% make
will build LKL as a object file, it will install it in tools/um/lib together with the headers files in tools/um/include then will build the host library, tests and a few of application examples:
* tests/boot - a simple applications that uses LKL and exercises the basic LKL APIs
% make run-tests
should run the above tests/boot and tests/net-test and report errors if there are any.
Supported hosts
===============
Currently LKL supports Linux userspace applications. New hosts can be added relatively easy if the host supports gcc and GNU ld. Previous versions of LKL supported Windows kernel and Haiku kernel hosts, and we also have WIP patches with rump-hypercall interface, used in UEFI, as well as macOS userspace (part of POSIX).
There is also musl-libc port for LKL, which might be interested in for some folks.
Further readings about LKL
=========================
- Discussion in github LKL issue
https://github.com/lkl/linux/issues/304
- LKL (an article)
https://www.researchgate.net/profile/Nicolae_Tapus2/publication/224164682_LKL_The_Linux_kernel_library/links/02bfe50fd921ab4f7c000000.pdf
*1 RFC email to LKML (back in 2015)
https://www.mail-archive.com/[email protected]/msg1012277.html
Please review the following changes for suitability for inclusion. If you have any objections or suggestions for improvement, please respond to the patches. If you agree with the changes, please provide your Acked-by.
The following changes since commit 805c6d3c19210c90c109107d189744e960eae025:
Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs (2020-09-22 15:08:41 -0700)
are available in the Git repository at:
git://github.com/thehajime/linux a8686efcbad3c445d3e5bde054c04a58877915f1
https://github.com/thehajime/linux/tree/uml-lkl-5.9rc6-v7
Hajime Tazaki (18):
um: move arch/um/os-Linux dir to tools/um/uml
um: move arch/x86/um/os-Linux to tools/um/uml/
scritps: um: suppress warnings if SRCARCH=um
um: extend arch_switch_to for alternate SUBARCH
um: add nommu mode for UML library mode
um: nommu: host interface
um: nommu: memory handling
um: nommu: kernel thread support
um: nommu: system call interface and application API
um: nommu: basic console support
um: nommu: initialization and cleanup
um: nommu: integrate with irq infrastructure of UML
um: nommu: plug in the build system
um: host: add nommu build for ARCH=um
um: host: add utilities functions
um: host: posix host operations
um: host: add test programs
um: nommu: add block device support of UML
Octavian Purdila (3):
um: split build in kernel and host parts
um: add os init and exit calls
um: host: implement os_initcalls and os_exitcalls
arch/um/Kconfig | 29 +-
arch/um/Makefile | 35 +-
arch/um/drivers/Makefile | 10 +-
.../um/{os-Linux => }/drivers/ethertap_kern.c | 0
arch/um/{os-Linux => }/drivers/tuntap_kern.c | 0
arch/um/include/asm/common.lds.S | 99 ----
arch/um/include/asm/host_ops.h | 9 +
arch/um/include/asm/mmu.h | 3 +
arch/um/include/asm/mmu_context.h | 8 +
arch/um/include/asm/page.h | 15 +
arch/um/include/asm/pgtable.h | 27 +
arch/um/include/asm/thread_info.h | 24 +
arch/um/include/asm/uaccess.h | 6 +
arch/um/include/asm/xor.h | 3 +-
arch/um/include/shared/as-layout.h | 1 +
.../drivers => include/shared}/etap.h | 0
arch/um/include/shared/init.h | 19 +-
arch/um/include/shared/os.h | 1 +
.../drivers => include/shared}/tuntap.h | 0
arch/um/include/uapi/asm/Kbuild | 2 +
arch/um/kernel/Makefile | 13 +-
arch/um/kernel/dyn.lds.S | 171 -------
arch/um/kernel/irq.c | 13 +
arch/um/kernel/process.c | 14 +-
arch/um/kernel/reboot.c | 5 +
arch/um/kernel/time.c | 2 +
arch/um/kernel/um_arch.c | 16 +
arch/um/kernel/uml.lds.S | 115 -----
arch/um/{os-Linux => kernel}/user_syms.c | 0
arch/um/kernel/vmlinux.lds.S | 91 +++-
arch/um/nommu/Makefile | 1 +
arch/um/nommu/Makefile.um | 22 +
arch/um/nommu/include/asm/Kbuild | 6 +
arch/um/nommu/include/asm/archparam.h | 1 +
arch/um/nommu/include/asm/atomic.h | 11 +
arch/um/nommu/include/asm/atomic64.h | 114 +++++
arch/um/nommu/include/asm/bitsperlong.h | 12 +
arch/um/nommu/include/asm/byteorder.h | 7 +
arch/um/nommu/include/asm/cpu.h | 16 +
arch/um/nommu/include/asm/elf.h | 15 +
arch/um/nommu/include/asm/mm_context.h | 8 +
arch/um/nommu/include/asm/processor.h | 46 ++
arch/um/nommu/include/asm/ptrace.h | 21 +
arch/um/nommu/include/asm/sched.h | 23 +
arch/um/nommu/include/asm/segment.h | 9 +
arch/um/nommu/include/asm/syscall_wrapper.h | 57 +++
arch/um/nommu/include/asm/syscalls.h | 15 +
arch/um/nommu/include/uapi/asm/Kbuild | 6 +
arch/um/nommu/include/uapi/asm/bitsperlong.h | 11 +
arch/um/nommu/include/uapi/asm/byteorder.h | 11 +
arch/um/nommu/include/uapi/asm/host_ops.h | 122 +++++
arch/um/nommu/include/uapi/asm/sigcontext.h | 12 +
arch/um/nommu/include/uapi/asm/syscalls.h | 287 +++++++++++
arch/um/nommu/include/uapi/asm/unistd.h | 17 +
arch/um/nommu/um/Kconfig | 45 ++
arch/um/nommu/um/Makefile | 4 +
arch/um/nommu/um/bootmem.c | 87 ++++
arch/um/nommu/um/console.c | 42 ++
arch/um/nommu/um/cpu.c | 247 ++++++++++
arch/um/nommu/um/delay.c | 31 ++
arch/um/nommu/um/setup.c | 179 +++++++
arch/um/nommu/um/shared/sysdep/archsetjmp.h | 13 +
arch/um/nommu/um/shared/sysdep/faultinfo.h | 8 +
.../nommu/um/shared/sysdep/kernel-offsets.h | 12 +
arch/um/nommu/um/shared/sysdep/mcontext.h | 9 +
arch/um/nommu/um/shared/sysdep/ptrace.h | 42 ++
arch/um/nommu/um/shared/sysdep/ptrace_user.h | 7 +
arch/um/nommu/um/syscalls.c | 199 ++++++++
arch/um/nommu/um/threads.c | 262 ++++++++++
arch/um/nommu/um/unimplemented.c | 70 +++
arch/um/nommu/um/user_constants.h | 13 +
arch/um/os-Linux/Makefile | 19 -
arch/um/os-Linux/drivers/Makefile | 13 -
arch/um/scripts/headers_install.py | 197 ++++++++
arch/x86/um/Makefile | 2 +-
arch/x86/um/os-Linux/Makefile | 13 -
arch/x86/um/ptrace_32.c | 2 +-
arch/x86/um/syscalls_64.c | 2 +-
scripts/headers_install.sh | 4 +
scripts/link-vmlinux.sh | 42 +-
tools/um/.gitignore | 1 +
tools/um/Makefile | 81 +++
tools/um/Targets | 13 +
tools/um/include/lkl.h | 357 ++++++++++++++
tools/um/include/lkl_host.h | 27 +
tools/um/lib/Build | 7 +
tools/um/lib/fs.c | 461 ++++++++++++++++++
tools/um/lib/jmp_buf.c | 14 +
tools/um/lib/jmp_buf.h | 8 +
tools/um/lib/posix-host.c | 293 +++++++++++
tools/um/lib/utils.c | 213 ++++++++
tools/um/tests/Build | 4 +
tools/um/tests/boot.c | 393 +++++++++++++++
tools/um/tests/boot.sh | 9 +
tools/um/tests/cla.c | 159 ++++++
tools/um/tests/cla.h | 33 ++
tools/um/tests/disk.c | 168 +++++++
tools/um/tests/disk.sh | 70 +++
tools/um/tests/run.py | 174 +++++++
tools/um/tests/tap13.py | 209 ++++++++
tools/um/tests/test.c | 126 +++++
tools/um/tests/test.h | 72 +++
tools/um/tests/test.sh | 181 +++++++
tools/um/uml/Build | 58 +++
tools/um/uml/drivers/Build | 10 +
.../um/uml}/drivers/ethertap_user.c | 0
.../um/uml}/drivers/tuntap_user.c | 0
{arch/um/os-Linux => tools/um/uml}/elf_aux.c | 0
{arch/um/os-Linux => tools/um/uml}/execvp.c | 4 -
{arch/um/os-Linux => tools/um/uml}/file.c | 0
{arch/um/os-Linux => tools/um/uml}/helper.c | 0
{arch/um/os-Linux => tools/um/uml}/irq.c | 0
{arch/um/os-Linux => tools/um/uml}/main.c | 0
{arch/um/os-Linux => tools/um/uml}/mem.c | 0
tools/um/uml/nommu/Build | 1 +
tools/um/uml/nommu/registers.c | 21 +
tools/um/uml/nommu/unimplemented.c | 21 +
{arch/um/os-Linux => tools/um/uml}/process.c | 2 +
.../um/os-Linux => tools/um/uml}/registers.c | 0
{arch/um/os-Linux => tools/um/uml}/sigio.c | 0
{arch/um/os-Linux => tools/um/uml}/signal.c | 12 +-
.../skas/Makefile => tools/um/uml/skas/Build | 6 +-
{arch/um/os-Linux => tools/um/uml}/skas/mem.c | 0
.../os-Linux => tools/um/uml}/skas/process.c | 3 +-
{arch/um/os-Linux => tools/um/uml}/start_up.c | 0
{arch/um/os-Linux => tools/um/uml}/time.c | 0
{arch/um/os-Linux => tools/um/uml}/tty.c | 0
{arch/um/os-Linux => tools/um/uml}/umid.c | 0
{arch/um/os-Linux => tools/um/uml}/util.c | 26 +
tools/um/uml/x86/Build | 11 +
.../os-Linux => tools/um/uml/x86}/mcontext.c | 0
.../um/os-Linux => tools/um/uml/x86}/prctl.c | 0
.../os-Linux => tools/um/uml/x86}/registers.c | 0
.../os-Linux => tools/um/uml/x86}/task_size.c | 0
.../um/os-Linux => tools/um/uml/x86}/tls.c | 0
135 files changed, 5870 insertions(+), 523 deletions(-)
rename arch/um/{os-Linux => }/drivers/ethertap_kern.c (100%)
rename arch/um/{os-Linux => }/drivers/tuntap_kern.c (100%)
delete mode 100644 arch/um/include/asm/common.lds.S
create mode 100644 arch/um/include/asm/host_ops.h
rename arch/um/{os-Linux/drivers => include/shared}/etap.h (100%)
rename arch/um/{os-Linux/drivers => include/shared}/tuntap.h (100%)
create mode 100644 arch/um/include/uapi/asm/Kbuild
delete mode 100644 arch/um/kernel/dyn.lds.S
delete mode 100644 arch/um/kernel/uml.lds.S
rename arch/um/{os-Linux => kernel}/user_syms.c (100%)
create mode 100644 arch/um/nommu/Makefile
create mode 100644 arch/um/nommu/Makefile.um
create mode 100644 arch/um/nommu/include/asm/Kbuild
create mode 100644 arch/um/nommu/include/asm/archparam.h
create mode 100644 arch/um/nommu/include/asm/atomic.h
create mode 100644 arch/um/nommu/include/asm/atomic64.h
create mode 100644 arch/um/nommu/include/asm/bitsperlong.h
create mode 100644 arch/um/nommu/include/asm/byteorder.h
create mode 100644 arch/um/nommu/include/asm/cpu.h
create mode 100644 arch/um/nommu/include/asm/elf.h
create mode 100644 arch/um/nommu/include/asm/mm_context.h
create mode 100644 arch/um/nommu/include/asm/processor.h
create mode 100644 arch/um/nommu/include/asm/ptrace.h
create mode 100644 arch/um/nommu/include/asm/sched.h
create mode 100644 arch/um/nommu/include/asm/segment.h
create mode 100644 arch/um/nommu/include/asm/syscall_wrapper.h
create mode 100644 arch/um/nommu/include/asm/syscalls.h
create mode 100644 arch/um/nommu/include/uapi/asm/Kbuild
create mode 100644 arch/um/nommu/include/uapi/asm/bitsperlong.h
create mode 100644 arch/um/nommu/include/uapi/asm/byteorder.h
create mode 100644 arch/um/nommu/include/uapi/asm/host_ops.h
create mode 100644 arch/um/nommu/include/uapi/asm/sigcontext.h
create mode 100644 arch/um/nommu/include/uapi/asm/syscalls.h
create mode 100644 arch/um/nommu/include/uapi/asm/unistd.h
create mode 100644 arch/um/nommu/um/Kconfig
create mode 100644 arch/um/nommu/um/Makefile
create mode 100644 arch/um/nommu/um/bootmem.c
create mode 100644 arch/um/nommu/um/console.c
create mode 100644 arch/um/nommu/um/cpu.c
create mode 100644 arch/um/nommu/um/delay.c
create mode 100644 arch/um/nommu/um/setup.c
create mode 100644 arch/um/nommu/um/shared/sysdep/archsetjmp.h
create mode 100644 arch/um/nommu/um/shared/sysdep/faultinfo.h
create mode 100644 arch/um/nommu/um/shared/sysdep/kernel-offsets.h
create mode 100644 arch/um/nommu/um/shared/sysdep/mcontext.h
create mode 100644 arch/um/nommu/um/shared/sysdep/ptrace.h
create mode 100644 arch/um/nommu/um/shared/sysdep/ptrace_user.h
create mode 100644 arch/um/nommu/um/syscalls.c
create mode 100644 arch/um/nommu/um/threads.c
create mode 100644 arch/um/nommu/um/unimplemented.c
create mode 100644 arch/um/nommu/um/user_constants.h
delete mode 100644 arch/um/os-Linux/Makefile
delete mode 100644 arch/um/os-Linux/drivers/Makefile
create mode 100755 arch/um/scripts/headers_install.py
delete mode 100644 arch/x86/um/os-Linux/Makefile
create mode 100644 tools/um/.gitignore
create mode 100644 tools/um/Makefile
create mode 100644 tools/um/Targets
create mode 100644 tools/um/include/lkl.h
create mode 100644 tools/um/include/lkl_host.h
create mode 100644 tools/um/lib/Build
create mode 100644 tools/um/lib/fs.c
create mode 100644 tools/um/lib/jmp_buf.c
create mode 100644 tools/um/lib/jmp_buf.h
create mode 100644 tools/um/lib/posix-host.c
create mode 100644 tools/um/lib/utils.c
create mode 100644 tools/um/tests/Build
create mode 100644 tools/um/tests/boot.c
create mode 100755 tools/um/tests/boot.sh
create mode 100644 tools/um/tests/cla.c
create mode 100644 tools/um/tests/cla.h
create mode 100644 tools/um/tests/disk.c
create mode 100755 tools/um/tests/disk.sh
create mode 100755 tools/um/tests/run.py
create mode 100644 tools/um/tests/tap13.py
create mode 100644 tools/um/tests/test.c
create mode 100644 tools/um/tests/test.h
create mode 100644 tools/um/tests/test.sh
create mode 100644 tools/um/uml/Build
create mode 100644 tools/um/uml/drivers/Build
rename {arch/um/os-Linux => tools/um/uml}/drivers/ethertap_user.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/drivers/tuntap_user.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/elf_aux.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/execvp.c (98%)
rename {arch/um/os-Linux => tools/um/uml}/file.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/helper.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/irq.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/main.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/mem.c (100%)
create mode 100644 tools/um/uml/nommu/Build
create mode 100644 tools/um/uml/nommu/registers.c
create mode 100644 tools/um/uml/nommu/unimplemented.c
rename {arch/um/os-Linux => tools/um/uml}/process.c (99%)
rename {arch/um/os-Linux => tools/um/uml}/registers.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/sigio.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/signal.c (96%)
rename arch/um/os-Linux/skas/Makefile => tools/um/uml/skas/Build (56%)
rename {arch/um/os-Linux => tools/um/uml}/skas/mem.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/skas/process.c (99%)
rename {arch/um/os-Linux => tools/um/uml}/start_up.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/time.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/tty.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/umid.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/util.c (89%)
create mode 100644 tools/um/uml/x86/Build
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/mcontext.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/prctl.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/registers.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/task_size.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/tls.c (100%)Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 1/21 um: split build in kernel and host parts
From: Octavian Purdila <[email protected]>
This patch splits the UML build in two parts: a kernel part that generates a relocatable object (linux.o) and a host build part that links the relocatable object into an executable.
This allows us to simplify the linker script since we can now remove the host bits (e.g. .rel sections). It also gives us greater flexibility since it will be much easier to support other architectures and OSes if we use the standard linker script.
The host build part has been implemented in tools/um so that we can reuse the available host build infrastructure.
The patch preserves the way to invoke the UML build as follows,
$ make ARCH=um defconfig $ make ARCH=um
but it internally calls tools/um/Makefile in order to complete the full build to link the relocatable object and the rest of files.
To statically compiled UML use:
$ make ARCH=um UML_STATIC=y
--- arch/um/Kconfig | 12 +-- arch/um/Makefile | 22 +++- arch/um/include/asm/common.lds.S | 99 ------------------ arch/um/kernel/dyn.lds.S | 171 ------------------------------- arch/um/kernel/uml.lds.S | 115 --------------------- arch/um/kernel/vmlinux.lds.S | 91 ++++++++++++++-- scripts/link-vmlinux.sh | 42 +++----- tools/um/Makefile | 72 +++++++++++++ tools/um/Targets | 4 + tools/um/uml/Build | 0 10 files changed, 191 insertions(+), 437 deletions(-) delete mode 100644 arch/um/include/asm/common.lds.S delete mode 100644 arch/um/kernel/dyn.lds.S delete mode 100644 arch/um/kernel/uml.lds.S create mode 100644 tools/um/Makefile create mode 100644 tools/um/Targets create mode 100644 tools/um/uml/Build
arch/um/Kconfig +1 -11
@@ -20,6 +20,7 @@ config UML select GENERIC_CLOCKEVENTS select HAVE_GCC_PLUGINS select TTY # Needed for line.c + select MODULE_REL_CRCS if MODVERSIONS config MMU bool
@@ -79,17 +80,6 @@ config STATIC_LINK NOTE: This option is incompatible with some networking features which depend on features that require being dynamically loaded (like NSS). -config LD_SCRIPT_STATIC - bool - default y - depends on STATIC_LINK - -config LD_SCRIPT_DYN - bool - default y - depends on !LD_SCRIPT_STATIC - select MODULE_REL_CRCS if MODVERSIONS - config HOSTFS tristate "Host filesystem" help
arch/um/Makefile +17 -5
@@ -95,14 +95,25 @@ KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/include \ KERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \ -Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES)) KBUILD_CFLAGS += $(KERNEL_DEFINES) +LDFLAGS_vmlinux += -r -PHONY += linux - +INSTALL_PATH=$(objtree)/tools/um all: linux +install: linux.o + @echo " INSTALL $(INSTALL_PATH)/lib/$<" + @mkdir -p $(INSTALL_PATH)/lib/ + @cp $< $(INSTALL_PATH)/lib/ + +PHONY += linux.o + +linux: linux.o + $(Q)$(MAKE) -C $(srctree)/tools/um + $(Q)cp $(objtree)/tools/um/uml/linux $(objtree)/ -linux: vmlinux - @echo ' LINK $@' - $(Q)ln -f $< $@ +linux.o: vmlinux + @echo ' LINK $@' + $(Q)$(OBJCOPY) -R .eh_frame $< $@ + $(Q)mkdir -p $(objtree)/tools/um/lib define archhelp echo '* linux - Binary kernel image (./linux) - for backward'
@@ -144,5 +155,6 @@ MRPROPER_FILES += arch/$(SUBARCH)/include/generated archclean: @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \ -o -name '*.gcov' \) -type f -print | xargs rm -f + $(Q)$(MAKE) -C $(srctree)/tools/um clean export HEADER_ARCH SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING OS DEV_NULL_PATH
arch/um/include/asm/common.lds.S deleted +0 -99
99 lines not on this page · raw message
arch/um/kernel/dyn.lds.S deleted +0 -171
171 lines not on this page · raw message
arch/um/kernel/uml.lds.S deleted +0 -115
115 lines not on this page · raw message
arch/um/kernel/vmlinux.lds.S +85 -6
93 lines not on this page · raw message
scripts/link-vmlinux.sh +12 -30
48 lines not on this page · raw message
tools/um/Makefile new file +72 -0
72 lines not on this page · raw message
tools/um/Targets new file +4 -0
@@ -0,0 +1,4 @@ +progs-y += uml/linux +LDLIBS_linux-y := -lrt -lpthread -lutil +LDFLAGS_linux-y := -no-pie -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc +LDFLAGS_linux-$(UML_STATIC) += -static
tools/um/uml/Build new file +0 -0
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 2/21 um: add os init and exit calls
In reply to Hajime TazakiFrom: Octavian Purdila <[email protected]>
These calls are added in preparation for moving some of the code from the kernel to the host build.
--- arch/um/include/shared/init.h | 14 ++++---------- arch/um/kernel/reboot.c | 5 +++++ arch/um/kernel/um_arch.c | 11 +++++++++++ 3 files changed, 20 insertions(+), 10 deletions(-)
arch/um/include/shared/init.h +4 -10
@@ -109,19 +109,13 @@ extern struct uml_param __uml_setup_start, __uml_setup_end;#ifdef __UM_HOST__ -#define __define_initcall (level,fn) \ - static initcall_t __initcall_##fn __used \ - __attribute__((__section__(".initcall" level ".init"))) = fn - -/* Userspace initcalls shouldn't depend on anything in the kernel, so we'll -* make them run first. -*/ -#define __initcall (fn) __define_initcall("1", fn) +#undef __uml_exit_call +#define __uml_exit_call __used __section(os_exitcalls) +#define __init_call __used __section(os_initcalls) +#define __initcall (fn) static initcall_t __initcall_##fn __init_call = fn#define __exitcall (fn) static exitcall_t __exitcall_##fn __exit_call = fn -#define __init_call __used __section(.initcall.init) -#endif #endif /* _LINUX_UML_INIT_H */
arch/um/kernel/reboot.c +5 -0
@@ -35,10 +35,15 @@ static void kill_off_processes(void)read_unlock (&tasklist_lock); } +void __weak os_exitcalls (void ) +{ +} +void uml_cleanup (void ) { kmalloc_ok =0 ;do_uml_exitcalls (); +os_exitcalls ();kill_off_processes (); }
arch/um/kernel/um_arch.c +11 -0
@@ -377,3 +377,14 @@ void *text_poke(void *addr, const void *opcode, size_t len)void text_poke_sync (void ) { } + +int __weak os_initcalls (void ) +{ +return 0 ; +} + +int __init run_os_initcalls (void ) +{ +return os_initcalls (); +} +early_initcall (run_os_initcalls);
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 3/21 um: move arch/um/os-Linux dir to tools/um/uml
In reply to Hajime TazakiThis patch moves underlying OS dependent part under arch/um to tools/um directory so that arch/um code does not need to build host build facilities (e.g., libc).
---
arch/um/Makefile | 3 +-
arch/um/drivers/Makefile | 2 +
.../um/{os-Linux => }/drivers/ethertap_kern.c | 0
arch/um/{os-Linux => }/drivers/tuntap_kern.c | 0
.../drivers => include/shared}/etap.h | 0
arch/um/include/shared/init.h | 5 ++
.../drivers => include/shared}/tuntap.h | 0
arch/um/kernel/Makefile | 1 +
arch/um/{os-Linux => kernel}/user_syms.c | 0
arch/um/os-Linux/Makefile | 19 --------
arch/um/os-Linux/drivers/Makefile | 13 -----
tools/um/Makefile | 6 ++-
tools/um/uml/Build | 48 +++++++++++++++++++
tools/um/uml/drivers/Build | 10 ++++
.../um/uml}/drivers/ethertap_user.c | 0
.../um/uml}/drivers/tuntap_user.c | 0
{arch/um/os-Linux => tools/um/uml}/elf_aux.c | 0
{arch/um/os-Linux => tools/um/uml}/execvp.c | 4 --
{arch/um/os-Linux => tools/um/uml}/file.c | 0
{arch/um/os-Linux => tools/um/uml}/helper.c | 0
{arch/um/os-Linux => tools/um/uml}/irq.c | 0
{arch/um/os-Linux => tools/um/uml}/main.c | 0
{arch/um/os-Linux => tools/um/uml}/mem.c | 0
{arch/um/os-Linux => tools/um/uml}/process.c | 0
.../um/os-Linux => tools/um/uml}/registers.c | 0
{arch/um/os-Linux => tools/um/uml}/sigio.c | 0
{arch/um/os-Linux => tools/um/uml}/signal.c | 0
.../skas/Makefile => tools/um/uml/skas/Build | 6 +--
{arch/um/os-Linux => tools/um/uml}/skas/mem.c | 0
.../os-Linux => tools/um/uml}/skas/process.c | 3 +-
{arch/um/os-Linux => tools/um/uml}/start_up.c | 0
{arch/um/os-Linux => tools/um/uml}/time.c | 0
{arch/um/os-Linux => tools/um/uml}/tty.c | 0
{arch/um/os-Linux => tools/um/uml}/umid.c | 0
{arch/um/os-Linux => tools/um/uml}/util.c | 0
35 files changed, 74 insertions(+), 46 deletions(-)
rename arch/um/{os-Linux => }/drivers/ethertap_kern.c (100%)
rename arch/um/{os-Linux => }/drivers/tuntap_kern.c (100%)
rename arch/um/{os-Linux/drivers => include/shared}/etap.h (100%)
rename arch/um/{os-Linux/drivers => include/shared}/tuntap.h (100%)
rename arch/um/{os-Linux => kernel}/user_syms.c (100%)
delete mode 100644 arch/um/os-Linux/Makefile
delete mode 100644 arch/um/os-Linux/drivers/Makefile
create mode 100644 tools/um/uml/drivers/Build
rename {arch/um/os-Linux => tools/um/uml}/drivers/ethertap_user.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/drivers/tuntap_user.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/elf_aux.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/execvp.c (98%)
rename {arch/um/os-Linux => tools/um/uml}/file.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/helper.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/irq.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/main.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/mem.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/process.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/registers.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/sigio.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/signal.c (100%)
rename arch/um/os-Linux/skas/Makefile => tools/um/uml/skas/Build (56%)
rename {arch/um/os-Linux => tools/um/uml}/skas/mem.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/skas/process.c (99%)
rename {arch/um/os-Linux => tools/um/uml}/start_up.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/time.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/tty.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/umid.c (100%)
rename {arch/um/os-Linux => tools/um/uml}/util.c (100%)arch/um/Makefile +1 -2
@@ -24,8 +24,7 @@ OS := $(shell uname -s) SHELL := /bin/bash core-y += $(ARCH_DIR)/kernel/ \ - $(ARCH_DIR)/drivers/ \ - $(ARCH_DIR)/os-$(OS)/ + $(ARCH_DIR)/drivers/ MODE_INCLUDE += -I$(srctree)/$(ARCH_DIR)/include/shared/skas
arch/um/drivers/Makefile +2 -0
@@ -48,6 +48,8 @@ obj-$(CONFIG_UML_NET_VECTOR) += vector.o obj-$(CONFIG_UML_NET_VDE) += vde.o obj-$(CONFIG_UML_NET_MCAST) += umcast.o obj-$(CONFIG_UML_NET_PCAP) += pcap.o +obj-$(CONFIG_UML_NET_ETHERTAP) += ethertap_kern.o +obj-$(CONFIG_UML_NET_TUNTAP) += tuntap_kern.o obj-$(CONFIG_UML_NET) += net.o obj-$(CONFIG_MCONSOLE) += mconsole.o obj-$(CONFIG_MMAPPER) += mmapper_kern.o
arch/um/drivers/ethertap_kern.c renamed from arch/um/os-Linux/drivers/ethertap_kern.c +0 -0
arch/um/drivers/tuntap_kern.c renamed from arch/um/os-Linux/drivers/tuntap_kern.c +0 -0
arch/um/include/shared/etap.h renamed from arch/um/os-Linux/drivers/etap.h +0 -0
arch/um/include/shared/init.h +5 -0
@@ -41,7 +41,12 @@typedef int (*initcall_t )(void );typedef void (*exitcall_t )(void ); +#ifndef __UM_HOST__#include <linux/compiler_types.h> +#else +#define __used __attribute__((__used__)) +#define __section (S ) __attribute__((__section__(#S))) +#endif /* These are for everybody (although not all archs will actually discard it in modules) */
arch/um/include/shared/tuntap.h renamed from arch/um/os-Linux/drivers/tuntap.h +0 -0
arch/um/kernel/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_GPROF) += gprof_syms.o obj-$(CONFIG_GCOV) += gmon_syms.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-$(CONFIG_STACKTRACE) += stacktrace.o +obj-y += user_syms.o USER_OBJS := config.o
arch/um/kernel/user_syms.c renamed from arch/um/os-Linux/user_syms.c +0 -0
arch/um/os-Linux/Makefile deleted +0 -19
@@ -1,19 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) -# - -# Don't instrument UML-specific code -KCOV_INSTRUMENT := n - -obj-y = execvp.o file.o helper.o irq.o main.o mem.o process.o \ - registers.o sigio.o signal.o start_up.o time.o tty.o \ - umid.o user_syms.o util.o drivers/ skas/ - -obj-$(CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA) += elf_aux.o - -USER_OBJS := $(user-objs-y) elf_aux.o execvp.o file.o helper.o irq.o \ - main.o mem.o process.o registers.o sigio.o signal.o start_up.o time.o \ - tty.o umid.o util.o - -include arch/um/scripts/Makefile.rules
arch/um/os-Linux/drivers/Makefile deleted +0 -13
@@ -1,13 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# Copyright (C) 2000, 2002 Jeff Dike ([email protected]) -# - -ethertap-objs := ethertap_kern.o ethertap_user.o -tuntap-objs := tuntap_kern.o tuntap_user.o - -obj-y = -obj-$(CONFIG_UML_NET_ETHERTAP) += ethertap.o -obj-$(CONFIG_UML_NET_TUNTAP) += tuntap.o - -include arch/um/scripts/Makefile.rules
tools/um/Makefile +5 -1
@@ -50,7 +50,7 @@ $(OUTPUT)lib/linux.o: $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) $(KCONFIG) $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) install INSTALL_PATH=$(OUTPUT) -$(OUTPUT)liblinux.a: $(OUTPUT)lib/linux.o $(OUTPUT)uml/liblinux-in.o +$(OUTPUT)liblinux.a: $(OUTPUT)lib/linux.o $(OUTPUT)uml/liblinux-in.o $(OUTPUT)lib/liblinux-in.o $(QUIET_AR)$(AR) -rc $@ $^ # rule to link programs
@@ -60,6 +60,10 @@ $(OUTPUT)%: $(OUTPUT)%-in.o $(OUTPUT)liblinux.a $(OUTPUT)%-in.o: FORCE $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) +# rule to build objects +$(OUTPUT)%-in.o: $(OUTPUT)lib/linux.o + $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) + clean: $(call QUIET_CLEAN, objects)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd'\ -delete -o -name '\.*.d' -delete
tools/um/uml/Build +48 -0
48 lines not on this page · raw message
tools/um/uml/drivers/Build new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2000, 2002 Jeff Dike ([email protected]) +# + +include $(objtree)/include/config/auto.conf + + +liblinux-$(CONFIG_UML_NET_ETHERTAP) += ethertap_user.o +liblinux-$(CONFIG_UML_NET_TUNTAP) += tuntap_user.o
tools/um/uml/drivers/ethertap_user.c renamed from arch/um/os-Linux/drivers/ethertap_user.c +0 -0
tools/um/uml/drivers/tuntap_user.c renamed from arch/um/os-Linux/drivers/tuntap_user.c +0 -0
tools/um/uml/elf_aux.c renamed from arch/um/os-Linux/elf_aux.c +0 -0
tools/um/uml/execvp.c renamed from arch/um/os-Linux/execvp.c +0 -4
@@ -26,12 +26,8 @@#include <errno.h> #include <limits.h> -#ifndef TEST -#include <um_malloc.h> -#else #include <stdio.h> #define um_kmalloc malloc -#endif #include <os.h> /* Execute FILE, searching in the `PATH' environment variable if it contains
tools/um/uml/file.c renamed from arch/um/os-Linux/file.c +0 -0
tools/um/uml/helper.c renamed from arch/um/os-Linux/helper.c +0 -0
tools/um/uml/irq.c renamed from arch/um/os-Linux/irq.c +0 -0
tools/um/uml/main.c renamed from arch/um/os-Linux/main.c +0 -0
tools/um/uml/mem.c renamed from arch/um/os-Linux/mem.c +0 -0
tools/um/uml/process.c renamed from arch/um/os-Linux/process.c +0 -0
tools/um/uml/registers.c renamed from arch/um/os-Linux/registers.c +0 -0
tools/um/uml/sigio.c renamed from arch/um/os-Linux/sigio.c +0 -0
tools/um/uml/signal.c renamed from arch/um/os-Linux/signal.c +0 -0
tools/um/uml/skas/Build renamed from arch/um/os-Linux/skas/Makefile +1 -5
@@ -3,8 +3,4 @@ # Copyright (C) 2002 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com) # -obj-y := mem.o process.o - -USER_OBJS := $(obj-y) - -include arch/um/scripts/Makefile.rules +liblinux-y += mem.o process.o
tools/um/uml/skas/mem.c renamed from arch/um/os-Linux/skas/mem.c +0 -0
tools/um/uml/skas/process.c renamed from arch/um/os-Linux/skas/process.c +1 -2
@@ -21,7 +21,6 @@#include <registers.h> #include <skas.h> #include <sysdep/stub.h> -#include <linux/threads.h> int is_skas_winch (int pid,int fd,void *data) {
@@ -248,7 +247,7 @@ static int userspace_tramp(void *stack)return 0 ; } -int userspace_pid[NR_CPUS ]; +int userspace_pid[UM_NR_CPUS ];/** * start_userspace() - prepare a new userspace process
tools/um/uml/start_up.c renamed from arch/um/os-Linux/start_up.c +0 -0
tools/um/uml/time.c renamed from arch/um/os-Linux/time.c +0 -0
tools/um/uml/tty.c renamed from arch/um/os-Linux/tty.c +0 -0
tools/um/uml/umid.c renamed from arch/um/os-Linux/umid.c +0 -0
tools/um/uml/util.c renamed from arch/um/os-Linux/util.c +0 -0
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 4/21 um: host: implement os_initcalls and os_exitcalls
In reply to Hajime TazakiFrom: Octavian Purdila <[email protected]>
This patch implements the init and exit calls for host code. It uses the automatic __start_<section> and __stop_<section> variables that are defined by gcc / ld when using custom sections.
Note that this patch should be merged with "um: move arch/um/os-Linux dir to tools/um" but for now it is separate to make the review easier.
--- tools/um/uml/util.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
tools/um/uml/util.c +26 -0
@@ -186,3 +186,29 @@ void os_warn(const char *fmt, ...)vfprintf (stderr, fmt, list);va_end (list); } + +extern void (*__start_os_exitcalls)(void ); +extern void (*__stop_os_exitcalls)(void ); + +void os_exitcalls (void ) +{ +exitcall_t *call; + + call = &__stop_os_exitcalls; +while (--call >= &__start_os_exitcalls) + (*call)(); +} + +extern int (*__start_os_initcalls)(void ); +extern int (*__stop_os_initcalls)(void ); + +int os_initcalls (void ) +{ +initcall_t *call; + + call = &__stop_os_initcalls; +while (--call >= &__start_os_initcalls) + (*call)(); + +return 0 ; +}
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 5/21 um: move arch/x86/um/os-Linux to tools/um/uml/
In reply to Hajime TazakiSimilar to arch/um/os-Linux code, arch/x86 also contains OS dependent part as well. This patch moves underlying OS dependent part to tools/um directory so that arch/x86 code does not need to build host build facilities (e.g., libc).
---
arch/x86/um/Makefile | 2 +-
arch/x86/um/os-Linux/Makefile | 13 -------------
tools/um/Makefile | 2 +-
tools/um/uml/Build | 2 ++
tools/um/uml/x86/Build | 11 +++++++++++
.../x86/um/os-Linux => tools/um/uml/x86}/mcontext.c | 0
{arch/x86/um/os-Linux => tools/um/uml/x86}/prctl.c | 0
.../um/os-Linux => tools/um/uml/x86}/registers.c | 0
.../um/os-Linux => tools/um/uml/x86}/task_size.c | 0
{arch/x86/um/os-Linux => tools/um/uml/x86}/tls.c | 0
10 files changed, 15 insertions(+), 15 deletions(-)
delete mode 100644 arch/x86/um/os-Linux/Makefile
create mode 100644 tools/um/uml/x86/Build
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/mcontext.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/prctl.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/registers.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/task_size.c (100%)
rename {arch/x86/um/os-Linux => tools/um/uml/x86}/tls.c (100%)arch/x86/um/Makefile +1 -1
@@ -13,7 +13,7 @@ obj-y = bugs_$(BITS).o delay.o fault.o ldt.o \ ptrace_$(BITS).o ptrace_user.o setjmp_$(BITS).o signal.o \ stub_$(BITS).o stub_segv.o \ sys_call_table_$(BITS).o sysrq_$(BITS).o tls_$(BITS).o \ - mem_$(BITS).o subarch.o os-$(OS)/ + mem_$(BITS).o subarch.o ifeq ($(CONFIG_X86_32),y)
arch/x86/um/os-Linux/Makefile deleted +0 -13
@@ -1,13 +0,0 @@ -# -# Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) -# Licensed under the GPL -# - -obj-y = registers.o task_size.o mcontext.o - -obj-$(CONFIG_X86_32) += tls.o -obj-$(CONFIG_64BIT) += prctl.o - -USER_OBJS := $(obj-y) - -include arch/um/scripts/Makefile.rules
tools/um/Makefile +1 -1
@@ -61,7 +61,7 @@ $(OUTPUT)%-in.o: FORCE $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) # rule to build objects -$(OUTPUT)%-in.o: $(OUTPUT)lib/linux.o +$(OUTPUT)%-in.o: $(OUTPUT)lib/linux.o FORCE $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) clean:
tools/um/uml/Build +2 -0
@@ -12,6 +12,8 @@ liblinux-y += execvp.o file.o helper.o irq.o main.o mem.o process.o \ registers.o sigio.o signal.o start_up.o time.o tty.o \ umid.o util.o drivers/ skas/ +liblinux-y += x86/ + liblinux-$(CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA) += elf_aux.o export O = $(srctree)
tools/um/uml/x86/Build new file +11 -0
@@ -0,0 +1,11 @@ +# +# Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) +# Licensed under the GPL +# + +include $(objtree)/include/config/auto.conf + +liblinux-y = registers.o task_size.o mcontext.o + +liblinux-$(CONFIG_X86_32) += tls.o +liblinux-$(CONFIG_64BIT) += prctl.o
tools/um/uml/x86/mcontext.c renamed from arch/x86/um/os-Linux/mcontext.c +0 -0
tools/um/uml/x86/prctl.c renamed from arch/x86/um/os-Linux/prctl.c +0 -0
tools/um/uml/x86/registers.c renamed from arch/x86/um/os-Linux/registers.c +0 -0
tools/um/uml/x86/task_size.c renamed from arch/x86/um/os-Linux/task_size.c +0 -0
tools/um/uml/x86/tls.c renamed from arch/x86/um/os-Linux/tls.c +0 -0
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 6/21 scritps: um: suppress warnings if SRCARCH=um
In reply to Hajime TazakiThis commit fixes numbers of warning messages about leaked CONFIG options. nommu mode of UML requires copies of kernel headers to offer syscall-like API for the library users. Thus, the warnings are to be avoided to function this exposure of API.
--- scripts/headers_install.sh | 4 ++++ 1 file changed, 4 insertions(+)
scripts/headers_install.sh +4 -0
@@ -93,6 +93,10 @@ include/uapi/linux/pktcdvd.h:CONFIG_CDROM_PKTCDVD_WCACHE for c in $configs do + if [ "$SRCARCH" = "um" ] ; then + break + fi + leak_error=1 for ignore in $config_leak_ignores
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 7/21 um: extend arch_switch_to for alternate SUBARCH
In reply to Hajime TazakiThis commit introduces additional argument of previous task when context switch happens. New SUBARCH can use the new information to switch tasks in a subarch-specific manner.
The patch is particularly required by nommu mode implemented as a SUBARCH of UML.
--- arch/um/kernel/process.c | 6 +++--- arch/x86/um/ptrace_32.c | 2 +- arch/x86/um/syscalls_64.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
arch/um/kernel/process.c +3 -3
@@ -80,7 +80,7 @@ static inline void set_current(struct task_struct *task) { external_pid(), task }); } -extern void arch_switch_to (struct task_struct *to); +extern void arch_switch_to (struct task_struct *from,struct task_struct *to);void *__switch_to (struct task_struct *from,struct task_struct *to) {
@@ -88,7 +88,7 @@ void *__switch_to(struct task_struct *from, struct task_struct *to)set_current (to);switch_threads (&from->thread.switch_buf, &to->thread.switch_buf); -arch_switch_to (current); +arch_switch_to (from, to);return current->thread.prev_sched; }
@@ -145,7 +145,7 @@ void fork_handler(void)* arch_switch_to isn't needed. We could want to apply this to * improve performance. -bb */ -arch_switch_to (current); +arch_switch_to (NULL , current); current->thread.prev_sched =NULL ;
arch/x86/um/ptrace_32.c +1 -1
@@ -11,7 +11,7 @@extern int arch_switch_tls (struct task_struct *to); -void arch_switch_to (struct task_struct *to) +void arch_switch_to (struct task_struct *from,struct task_struct *to) {int err =arch_switch_tls (to);if (!err)
arch/x86/um/syscalls_64.c +1 -1
@@ -80,7 +80,7 @@ SYSCALL_DEFINE2(arch_prctl, int, option, unsigned long, arg2)return arch_prctl (current, option, (unsigned long __user *) arg2); } -void arch_switch_to (struct task_struct *to) +void arch_switch_to (struct task_struct *from,struct task_struct *to) {if ((to->thread.arch.fs ==0 ) || (to->mm ==NULL ))return ;
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 9/21 um: nommu: host interface
In reply to Hajime TazakiThis patch introduces the host operations that define the interface between the LKL and the host. These operations must be provided either by a host library or by the application itself.
--- arch/um/include/asm/host_ops.h | 9 ++++++++ arch/um/nommu/include/uapi/asm/host_ops.h | 25 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 arch/um/include/asm/host_ops.h create mode 100644 arch/um/nommu/include/uapi/asm/host_ops.h
arch/um/include/asm/host_ops.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_LKL_HOST_OPS_H +#define _ASM_LKL_HOST_OPS_H + +#include <uapi/asm/host_ops.h> + +extern struct lkl_host_operations *lkl_ops; + +#endif
arch/um/nommu/include/uapi/asm/host_ops.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __UM_NOMMU_UAPI_HOST_OPS_H +#define __UM_NOMMU_UAPI_HOST_OPS_H + +/* Defined in {posix,nt}-host.c */ +struct lkl_mutex ; +struct lkl_sem ; +typedef unsigned long lkl_thread_t ; +struct lkl_jmp_buf { +unsigned long buf[128 ]; +}; + +/** +* lkl_host_operations - host operations used by the Linux kernel +* +* These operations must be provided by a host library or by the application +* itself. +* +*/ +struct lkl_host_operations { +}; + +void lkl_bug (const char *fmt, ...); + +#endif
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 8/21 um: add nommu mode for UML library mode
In reply to Hajime TazakiThis patch introduces the nommu operation with UML code so that host interface can be shrineked for broader environments support.
The nommu mode is implemneted as SUBARCH of arch/um, which places at arch/um/nommu. This SUBARCH defines mode-specific code of memory management as well as thread implementation, along with the uapi headers to be exported to users.
The headers we introduce in this patch are simple wrappers to the asm-generic headers or stubs for things we don't support, such as ptrace, DMA, signals, ELF handling and low level processor operations.
nommu mode shares most of arch/um code (irq, thread_info, process scheduling) but implements its own facilities, which are memory management (nommu), thread primitives (struct arch_thread), system call interface, and console.
The outlook of updated directory structure is as follows:
arch/um
|-- configs (untouched) |-- drivers unuse stdio_console.c for !MMU |-- include | |-- asm updated with !CONFIG_MMU | |-- linux (untouched) | `-- shared updated with new functions | `-- skas (untouched) | `-- uapi added for upai header installation |-- kernel updated to integrate with !MMU | `-- skas (untouched, don't use for !MMU) |-- nommu SUBARCH dir (internally =um/nommu) | |-- include | | |-- asm headers for subarch specific info | | `-- uapi headers for user-visible APIs | `-- um | `-- shared headers for subarch specific info
`-- scripts added a script for header installation
--- arch/um/nommu/Makefile | 1 + arch/um/nommu/Makefile.um | 22 ++++ arch/um/nommu/include/asm/Kbuild | 6 + arch/um/nommu/include/asm/archparam.h | 1 + arch/um/nommu/include/asm/atomic.h | 11 ++ arch/um/nommu/include/asm/atomic64.h | 114 ++++++++++++++++++ arch/um/nommu/include/asm/bitsperlong.h | 12 ++ arch/um/nommu/include/asm/byteorder.h | 7 ++ arch/um/nommu/include/asm/cpu.h | 13 ++ arch/um/nommu/include/asm/elf.h | 15 +++ arch/um/nommu/include/asm/mm_context.h | 8 ++ arch/um/nommu/include/asm/processor.h | 46 +++++++ arch/um/nommu/include/asm/ptrace.h | 21 ++++ arch/um/nommu/include/asm/sched.h | 23 ++++ arch/um/nommu/include/asm/segment.h | 9 ++ arch/um/nommu/include/uapi/asm/Kbuild | 6 + arch/um/nommu/include/uapi/asm/bitsperlong.h | 11 ++ arch/um/nommu/include/uapi/asm/byteorder.h | 11 ++ arch/um/nommu/include/uapi/asm/sigcontext.h | 12 ++ arch/um/nommu/um/delay.c | 31 +++++ arch/um/nommu/um/shared/sysdep/archsetjmp.h | 13 ++ arch/um/nommu/um/shared/sysdep/faultinfo.h | 8 ++ .../nommu/um/shared/sysdep/kernel-offsets.h | 12 ++ arch/um/nommu/um/shared/sysdep/mcontext.h | 9 ++ arch/um/nommu/um/shared/sysdep/ptrace.h | 42 +++++++ arch/um/nommu/um/shared/sysdep/ptrace_user.h | 7 ++ arch/um/nommu/um/unimplemented.c | 70 +++++++++++ arch/um/nommu/um/user_constants.h | 13 ++ 28 files changed, 554 insertions(+) create mode 100644 arch/um/nommu/Makefile create mode 100644 arch/um/nommu/Makefile.um create mode 100644 arch/um/nommu/include/asm/Kbuild create mode 100644 arch/um/nommu/include/asm/archparam.h create mode 100644 arch/um/nommu/include/asm/atomic.h create mode 100644 arch/um/nommu/include/asm/atomic64.h create mode 100644 arch/um/nommu/include/asm/bitsperlong.h create mode 100644 arch/um/nommu/include/asm/byteorder.h create mode 100644 arch/um/nommu/include/asm/cpu.h create mode 100644 arch/um/nommu/include/asm/elf.h create mode 100644 arch/um/nommu/include/asm/mm_context.h create mode 100644 arch/um/nommu/include/asm/processor.h create mode 100644 arch/um/nommu/include/asm/ptrace.h create mode 100644 arch/um/nommu/include/asm/sched.h create mode 100644 arch/um/nommu/include/asm/segment.h create mode 100644 arch/um/nommu/include/uapi/asm/Kbuild create mode 100644 arch/um/nommu/include/uapi/asm/bitsperlong.h create mode 100644 arch/um/nommu/include/uapi/asm/byteorder.h create mode 100644 arch/um/nommu/include/uapi/asm/sigcontext.h create mode 100644 arch/um/nommu/um/delay.c create mode 100644 arch/um/nommu/um/shared/sysdep/archsetjmp.h create mode 100644 arch/um/nommu/um/shared/sysdep/faultinfo.h create mode 100644 arch/um/nommu/um/shared/sysdep/kernel-offsets.h create mode 100644 arch/um/nommu/um/shared/sysdep/mcontext.h create mode 100644 arch/um/nommu/um/shared/sysdep/ptrace.h create mode 100644 arch/um/nommu/um/shared/sysdep/ptrace_user.h create mode 100644 arch/um/nommu/um/unimplemented.c create mode 100644 arch/um/nommu/um/user_constants.h
arch/um/nommu/Makefile new file +1 -0
@@ -0,0 +1 @@ +#
arch/um/nommu/Makefile.um new file +22 -0
@@ -0,0 +1,22 @@ +KBUILD_CFLAGS += -fno-builtin -fPIC +ELF_FORMAT=$(shell $(LD) -r -print-output-format) + +ifeq ($(shell uname -s), Linux) +NPROC=$(shell nproc) +else # e.g., FreeBSD +NPROC=$(shell sysctl -n hw.ncpu) +endif + +um_headers_install: $(objtree)/$(HOST_DIR)/include/generated/uapi/asm/syscall_defs.h headers +# if syscall_defs.h is newer than generated headers (autoconf.h) + $(Q)if [ ! -r $(objtree)/tools/um/include/lkl/autoconf.h ] || \ + [ $< -nt $(objtree)/tools/um/include/lkl/autoconf.h ]; then \ + $(srctree)/$(ARCH_DIR)/scripts/headers_install.py \ + $(subst -j,-j$(NPROC),$(findstring -j,$(MAKEFLAGS))) \ + $(INSTALL_PATH)/include ; \ + fi + +$(objtree)/$(HOST_DIR)/include/generated/uapi/asm/syscall_defs.h: vmlinux + $(Q)$(OBJCOPY) -j .syscall_defs -O binary --set-section-flags .syscall_defs=alloc $< $@ + $(Q) export tmpfile=$(shell mktemp); \ + sed 's/\x0//g' $@ > $$tmpfile; mv $$tmpfile $@ ; rm -f $$tmpfile
arch/um/nommu/include/asm/Kbuild new file +6 -0
@@ -0,0 +1,6 @@ +generic-y += cmpxchg.h +generic-y += local64.h +generic-y += seccomp.h +generic-y += string.h +generic-y += syscall.h +generic-y += user.h
arch/um/nommu/include/asm/archparam.h new file +1 -0
@@ -0,0 +1 @@ +/* SPDX-License-Identifier: GPL-2.0 */
arch/um/nommu/include/asm/atomic.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_ATOMIC_H +#define __UM_NOMMU_ATOMIC_H + +#include <asm-generic/atomic.h> + +#ifndef CONFIG_GENERIC_ATOMIC64 +#include "atomic64.h" +#endif /* !CONFIG_GENERIC_ATOMIC64 */ + +#endif
arch/um/nommu/include/asm/atomic64.h new file +114 -0
114 lines not on this page · raw message
arch/um/nommu/include/asm/bitsperlong.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_BITSPERLONG_H +#define __UM_NOMMU_BITSPERLONG_H + +#include <uapi/asm/bitsperlong.h> + +#define BITS_PER_LONG __BITS_PER_LONG + +#define BITS_PER_LONG_LONG 64 + +#endif +
arch/um/nommu/include/asm/byteorder.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_BYTEORDER_H +#define __UM_NOMMU_BYTEORDER_H + +#include <uapi/asm/byteorder.h> + +#endif
arch/um/nommu/include/asm/cpu.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_CPU_H +#define __UM_NOMMU_CPU_H + +int lkl_cpu_get (void ); +void lkl_cpu_put (void ); +int lkl_cpu_try_run_irq (int irq); +int lkl_cpu_init (void ); +void lkl_cpu_wait_shutdown (void ); +void lkl_cpu_change_owner (lkl_thread_t owner); +void lkl_cpu_set_irqs_pending (void ); + +#endif
arch/um/nommu/include/asm/elf.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_ELF_H +#define __UM_NOMMU_ELF_H + +#define elf_check_arch (x) 0 + +#ifdef CONFIG_64BIT +#define ELF_CLASS ELFCLASS64 +#else +#define ELF_CLASS ELFCLASS32 +#endif + +#define elf_gregset_t long +#define elf_fpregset_t double +#endif
arch/um/nommu/include/asm/mm_context.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_MM_CONTEXT_H +#define __UM_NOMMU_MM_CONTEXT_H + +struct uml_arch_mm_context { +}; + +#endif
arch/um/nommu/include/asm/processor.h new file +46 -0
46 lines not on this page · raw message
arch/um/nommu/include/asm/ptrace.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_PTRACE_H +#define __UM_NOMMU_PTRACE_H + +#include <linux/errno.h> + +static int reg_dummy __attribute__((unused)); + +#define PT_REGS_ORIG_SYSCALL (r) (reg_dummy) +#define PT_REGS_SYSCALL_RET (r) (reg_dummy) +#define PT_REGS_SET_SYSCALL_RETURN (r, res) (reg_dummy = (res)) +#define REGS_SP (r) (reg_dummy) + +#define user_mode (regs) 0 +#define kernel_mode (regs) 1 +#define profile_pc (regs) 0 +#define user_stack_pointer (regs) 0 + +extern void new_thread_handler (void ); + +#endif
arch/um/nommu/include/asm/sched.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_SCHED_H +#define __UM_NOMMU_SCHED_H + +#include <linux/sched.h> +#include <uapi/asm/host_ops.h> + +static inline void thread_sched_jb (void ) +{ +if (test_ti_thread_flag (current_thread_info (),TIF_HOST_THREAD )) { +set_ti_thread_flag (current_thread_info (),TIF_SCHED_JB ); +set_current_state (TASK_UNINTERRUPTIBLE ); + lkl_ops->jmp_buf_set (¤t_thread_info ()->task->thread.arch.sched_jb, + schedule); + }else { +lkl_bug ("%s can be used only for host task" , __func__); + } +} + +void switch_to_host_task (struct task_struct *); +int host_task_stub (void *unused); + +#endif
arch/um/nommu/include/asm/segment.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_SEGMENT_H +#define __UM_NOMMU_SEGMENT_H + +typedef struct { +unsigned long seg; +}mm_segment_t ; + +#endif /* _ASM_LKL_SEGMENT_H */
arch/um/nommu/include/uapi/asm/Kbuild new file +6 -0
@@ -0,0 +1,6 @@ +# UAPI Header export list + +generated-y += syscall_defs.h + +# no generated-y since we need special user headers handling +# see arch/um/script/headers_install.py
arch/um/nommu/include/uapi/asm/bitsperlong.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __UM_NOMMU_UAPI_BITSPERLONG_H +#define __UM_NOMMU_UAPI_BITSPERLONG_H + +#ifdef CONFIG_64BIT +#define __BITS_PER_LONG 64 +#else +#define __BITS_PER_LONG 32 +#endif + +#endif
arch/um/nommu/include/uapi/asm/byteorder.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __UM_NOMMU_UAPI_BYTEORDER_H +#define __UM_NOMMU_UAPI_BYTEORDER_H + +#if defined(CONFIG_BIG_ENDIAN ) +#include <linux/byteorder/big_endian.h> +#else +#include <linux/byteorder/little_endian.h> +#endif + +#endif
arch/um/nommu/include/uapi/asm/sigcontext.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __UM_NOMMU_UAPI_SIGCONTEXT_H +#define __UM_NOMMU_UAPI_SIGCONTEXT_H + +#include <asm/ptrace-generic.h> + +struct sigcontext { +struct pt_regs regs; +unsigned long oldmask; +}; + +#endif
arch/um/nommu/um/delay.c new file +31 -0
@@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/jiffies.h> +#include <linux/delay.h> +#include <os.h> + +void __ndelay (unsigned long nsecs) +{ +long long start =os_nsecs (); + +while (os_nsecs () < start + nsecs) + ; +} + +void __udelay (unsigned long usecs) +{ +__ndelay (usecs *NSEC_PER_USEC ); +} + +void __const_udelay (unsigned long xloops) +{ +__udelay (xloops /0x10c7ul ); +} + +void __delay (unsigned long loops) +{ +__ndelay (loops /5 ); +} + +void calibrate_delay (void ) +{ +}
arch/um/nommu/um/shared/sysdep/archsetjmp.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ARCH_UM_SETJMP_H +#define __ARCH_UM_SETJMP_H + +struct __jmp_buf { +unsigned long __dummy; +}; +#define JB_IP __dummy +#define JB_SP __dummy + +typedef struct __jmp_buf jmp_buf [1 ]; + +#endif /* __ARCH_UM_SETJMP_H */
arch/um/nommu/um/shared/sysdep/faultinfo.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ARCH_UM_FAULTINFO_H +#define __ARCH_UM_FAULTINFO_H + +struct faultinfo { +}; + +#endif /* __ARCH_UM_FAULTINFO_H */
arch/um/nommu/um/shared/sysdep/kernel-offsets.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/stddef.h> +#include <linux/sched.h> +#include <linux/elf.h> +#include <linux/crypto.h> +#include <linux/kbuild.h> +#include <asm/mman.h> + +void foo (void ) +{ +#include <common-offsets.h> +}
arch/um/nommu/um/shared/sysdep/mcontext.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ARCH_UM_MCONTEXT_H +#define __ARCH_UM_MCONTEXT_H + +extern void get_regs_from_mc (struct uml_pt_regs *regs,mcontext_t *mc); + +#define GET_FAULTINFO_FROM_MC (fi, mc) (fi = fi) + +#endif /* __ARCH_UM_MCONTEXT_H */
arch/um/nommu/um/shared/sysdep/ptrace.h new file +42 -0
42 lines not on this page · raw message
arch/um/nommu/um/shared/sysdep/ptrace_user.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ARCH_UM_PTRACE_USER_H +#define __ARCH_UM_PTRACE_USER_H + +#define FP_SIZE 1 + +#endif
arch/um/nommu/um/unimplemented.c new file +70 -0
70 lines not on this page · raw message
arch/um/nommu/um/user_constants.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_USER_CONSTANTS_H +#define __UM_NOMMU_USER_CONSTANTS_H + +/* XXX: put dummy values */ +#define UM_FRAME_SIZE 4 +#define HOST_FP_SIZE 1 +#define HOST_IP 1 +#define HOST_SP 2 +#define HOST_BP 3 +#define UM_NR_CPUS 1 + +#endif
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 10/21 um: nommu: memory handling
In reply to Hajime Tazakinommu mode follows the way !CONFIG_MMU architecture of other linux archs. Ther is not much work left to do other than initializing the boot allocator and providing the page and page table definitions.
The backstore memory is allocated via a host operation and the memory size to be used is specified when the kernel is started, in the lkl_start_kernel call.
--- arch/um/include/asm/mmu.h | 3 + arch/um/include/asm/mmu_context.h | 8 +++ arch/um/include/asm/page.h | 15 ++++ arch/um/include/asm/pgtable.h | 27 +++++++ arch/um/include/asm/uaccess.h | 6 ++ arch/um/nommu/include/uapi/asm/host_ops.h | 5 ++ arch/um/nommu/um/bootmem.c | 87 +++++++++++++++++++++++ 7 files changed, 151 insertions(+) create mode 100644 arch/um/nommu/um/bootmem.c
arch/um/include/asm/mmu.h +3 -0
@@ -13,6 +13,9 @@ typedef struct mm_context {struct mm_id id;struct uml_arch_mm_context arch;struct page *stub_pages[2 ]; +#ifndef CONFIG_MMU +unsigned long end_brk; +#endif } mm_context_t;extern void __switch_mm (struct mm_id * mm_idp);
arch/um/include/asm/mmu_context.h +8 -0
@@ -6,6 +6,7 @@#ifndef __UM_MMU_CONTEXT_H#define __UM_MMU_CONTEXT_H +#ifdef CONFIG_MMU #include <linux/sched.h> #include <linux/mm_types.h> #include <linux/mmap_lock.h>
@@ -75,4 +76,11 @@ extern int init_new_context(struct task_struct *task, struct mm_struct *mm);extern void destroy_context (struct mm_struct *mm); +#else +#include <asm-generic/mmu_context.h> + +extern void force_flush_all (void ); + +#endif /* CONFIG_MMU */ +#endif
arch/um/include/asm/page.h +15 -0
@@ -7,6 +7,8 @@#ifndef __UM_PAGE_H#define __UM_PAGE_H +#ifdef CONFIG_MMU +#include <linux/const.h> /* PAGE_SHIFT determines the page size */
@@ -120,4 +122,17 @@ extern unsigned long uml_physmem;#define __HAVE_ARCH_GATE_AREA 1#endif +#else /* CONFIG_MMU */ +#define CONFIG_KERNEL_RAM_BASE_ADDRESS memory_start +#include <asm-generic/page.h> + +#define __va_space (8*1024*1024) + +#ifndef __ASSEMBLY__ +#include <mem.h> +void free_mem (void ); +#endif + +#endif /* !CONFIG_MMU */ +#endif /* __UM_PAGE_H */
arch/um/include/asm/pgtable.h +27 -0
@@ -21,6 +21,8 @@#define _PAGE_PROTNONE 0x010/* if the user mapped it with PROT_NONE; pte_present gives true */ +#ifdef CONFIG_MMU +#ifdef CONFIG_3_LEVEL_PGTABLES #include <asm/pgtable-3level.h> #else
@@ -323,4 +325,29 @@ do { \__flush_tlb_one ((vaddr)); \ } while (0) +#else /* CONFIG_MMU */ + +#include <asm-generic/pgtable-nopud.h> + +#define swapper_pg_dir ((pgd_t *)0) +#define PAGE_KERNEL __pgprot(0) +#define PGDIR_SHIFT 21 +#define PGDIR_SIZE (1UL << PGDIR_SHIFT) +#define PGDIR_MASK (~(PGDIR_SIZE-1)) + +#define VMALLOC_START 0 +#define VMALLOC_END 0xffffffff + +/* +* ZERO_PAGE is a global shared page that is always zero: used +* for zero-mapped memory areas etc.. +*/ +extern unsigned long *empty_zero_page; +#define ZERO_PAGE (vaddr) (virt_to_page(empty_zero_page)) + +extern unsigned long end_iomem; + +#endif /* !CONFIG_MMU */ + +#endif
arch/um/include/asm/uaccess.h +6 -0
@@ -21,6 +21,7 @@#define __addr_range_nowrap (addr, size) \ ((unsigned long) (addr) <= ((unsigned long) (addr) + (size))) +#ifdef CONFIG_MMU extern unsigned long raw_copy_from_user (void *to,const void __user *from,unsigned long n);extern unsigned long raw_copy_to_user (void __user *to,const void *from,unsigned long n);extern long __strncpy_from_user (char *dst,const char __user *src,long count);
@@ -46,4 +47,9 @@ static inline int __access_ok(unsigned long addr, unsigned long size) uaccess_kernel()); } +#else +#include <asm-generic/uaccess.h> +#endif /* CONFIG_MMU */ + +#endif
arch/um/nommu/include/uapi/asm/host_ops.h +5 -0
@@ -16,8 +16,13 @@ struct lkl_jmp_buf {* These operations must be provided by a host library or by the application * itself. * +* @mem_alloc - allocate memory +* @mem_free - free memory +* */ struct lkl_host_operations { +void *(*mem_alloc)(unsigned long mem); +void (*mem_free)(void *mem); };void lkl_bug (const char *fmt, ...);
arch/um/nommu/um/bootmem.c new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 11/21 um: nommu: kernel thread support
In reply to Hajime Tazakinommu mode does not support user processes but it must support kernel threads as part as the normal kernel work-flow. It uses host operations to create and terminate host threads that are going to run the kernel threads. It also uses semaphores to synchronize those threads and to allow the Linux kernel scheduler to control how the kernel threads run.
Each kernel thread runs in a host threads and has a host semaphore associated with it - the thread's scheduling semaphore. The semaphore counter is initialized to 0. The first thing a kernel thread does after getting spawned, before running any kernel code, is to perform a down operation to block the thread.
The kernel controls host threads scheduling by performing up and down operations on the scheduling semaphore. In __switch_context an up operation on the next thread is performed to wake up a blocked thread, and a down operation is performed on the prev thread to block it.
A thread is terminated by marking it in free_thread_info and performing an up operation on the scheduling semaphore at which point the marked thread will terminate itself.
UML common part (process.c) is extended to call idle functions of SUBARCH as well as kernel thread detection with a flag information of TIF_HOST_THREAD.
--- arch/um/include/asm/thread_info.h | 24 ++ arch/um/kernel/process.c | 8 +- arch/um/nommu/include/uapi/asm/host_ops.h | 54 +++++ arch/um/nommu/um/cpu.c | 236 ++++++++++++++++++++ arch/um/nommu/um/threads.c | 259 ++++++++++++++++++++++ 5 files changed, 580 insertions(+), 1 deletion(-) create mode 100644 arch/um/nommu/um/cpu.c create mode 100644 arch/um/nommu/um/threads.c
arch/um/include/asm/thread_info.h +24 -0
@@ -40,6 +40,7 @@ struct thread_info { .real_thread = NULL, \ } +#ifdef CONFIG_MMU /* how to get the thread information struct from C */ static inline struct thread_info *current_thread_info (void ) {
@@ -52,6 +53,27 @@ static inline struct thread_info *current_thread_info(void)return ti; } +#else + +#define __HAVE_THREAD_FUNCTIONS +#define task_thread_info (task) ((struct thread_info *)(task)->stack) +#define task_stack_page (task) ((task)->stack) +#define end_of_stack (p) (&task_thread_info(p)->aux_fp_regs[FP_SIZE-1]) + +void threads_init (void ); +void threads_cleanup (void ); + +unsigned long *alloc_thread_stack_node (struct task_struct *p,int node); +void setup_thread_stack (struct task_struct *p,struct task_struct *org); +void free_thread_stack (struct task_struct *tsk); + +extern struct thread_info *_current_thread_info; +static inline struct thread_info *current_thread_info (void ) +{ +return _current_thread_info; +} +#endif /* CONFIG_MMU */ +#endif #define TIF_SYSCALL_TRACE 0/* syscall trace active */
@@ -63,6 +85,8 @@ static inline struct thread_info *current_thread_info(void)#define TIF_RESTORE_SIGMASK 7#define TIF_NOTIFY_RESUME 8#define TIF_SECCOMP 9/* secure computing */ +#define TIF_SCHED_JB 10 +#define TIF_HOST_THREAD 11#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
arch/um/kernel/process.c +7 -1
@@ -156,7 +156,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg, struct task_struct * p, unsigned long tls) { void (*handler)(void); -int kthread = current->flags &PF_KTHREAD ; +int kthread = current->flags &PF_KTHREAD || +test_ti_thread_flag (current_thread_info (),TIF_HOST_THREAD );int ret =0 ; p->thread = (struct thread_struct )INIT_THREAD ;
@@ -213,10 +214,15 @@ static void um_idle_sleep(void) } } +void __weak subarch_cpu_idle (void ) +{ +} +void arch_cpu_idle (void ) { cpu_tasks[current_thread_info ()->cpu].pid =os_getpid ();um_idle_sleep (); +subarch_cpu_idle ();local_irq_enable (); }
arch/um/nommu/include/uapi/asm/host_ops.h +54 -0
65 lines not on this page · raw message
arch/um/nommu/um/cpu.c new file +236 -0
236 lines not on this page · raw message
arch/um/nommu/um/threads.c new file +259 -0
259 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 12/21 um: nommu: system call interface and application API
In reply to Hajime TazakiThe application API is based on the kernel system call interface in order to offer a stable API to applications. Note that we can't offer the full Linux system call interface due to the limitations of nommu mode such as lack of virtual memory, signal, user processes, etc.
The host is using dedicated kernel thread, which is switched upon the entry of lkl_syscall so that numbers of context switches can be reduced for the faster performance.
To expose the API definitions to applications, this commit uses syscall_wrapper to define arch-specific information of syscall, and this is used to generate syscall_defs.h for lkl so that it can be used as a template of the list of syscall available for LKL apps.
To avoid collisions between the Linux API and the LKL API (e.g. struct stat, MKNOD, etc.) we use a python script to modify the user headers and to prefix all of the global symbols (structures, typedefs, defines) with LKL, lkl, _LKL, _lkl, __LKL or __lkl.
--- arch/um/include/uapi/asm/Kbuild | 2 + arch/um/nommu/include/asm/syscall_wrapper.h | 57 ++++ arch/um/nommu/include/asm/syscalls.h | 15 + arch/um/nommu/include/uapi/asm/host_ops.h | 14 + arch/um/nommu/include/uapi/asm/syscalls.h | 287 ++++++++++++++++++++ arch/um/nommu/include/uapi/asm/unistd.h | 15 + arch/um/nommu/um/syscalls.c | 199 ++++++++++++++ arch/um/scripts/headers_install.py | 197 ++++++++++++++ 8 files changed, 786 insertions(+) create mode 100644 arch/um/include/uapi/asm/Kbuild create mode 100644 arch/um/nommu/include/asm/syscall_wrapper.h create mode 100644 arch/um/nommu/include/asm/syscalls.h create mode 100644 arch/um/nommu/include/uapi/asm/syscalls.h create mode 100644 arch/um/nommu/include/uapi/asm/unistd.h create mode 100644 arch/um/nommu/um/syscalls.c create mode 100755 arch/um/scripts/headers_install.py
arch/um/include/uapi/asm/Kbuild new file +2 -0
@@ -0,0 +1,2 @@ +# no generated-y since we need special user headers handling +# see arch/um/script/headers_install.py
arch/um/nommu/include/asm/syscall_wrapper.h new file +57 -0
57 lines not on this page · raw message
arch/um/nommu/include/asm/syscalls.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +int syscalls_init (void ); +void syscalls_cleanup (void ); +long lkl_syscall (long no,long *params); +void wakeup_idle_host_task (void ); + +#define sys_mmap sys_ni_syscall +#define sys_rt_sigreturn sys_ni_syscall +#define sys_arch_prctl sys_ni_syscall +#define sys_iopl sys_ni_syscall +#define sys_ioperm sys_ni_syscall +#define sys_clone sys_ni_syscall + +int run_syscalls (void );
arch/um/nommu/include/uapi/asm/host_ops.h +14 -0
@@ -38,6 +38,15 @@ struct lkl_jmp_buf {* @gettid - returns the host thread id of the caller, which need not * be the same as the handle returned by thread_create * +* @tls_alloc - allocate a thread local storage key; returns 0 if successful; if +* destructor is not NULL it will be called when a thread terminates with its +* argument set to the current thread local storage value +* @tls_free - frees a thread local storage key; returns 0 if successful +* @tls_set - associate data to the thread local storage key; returns 0 if +* successful +* @tls_get - return data associated with the thread local storage key or NULL +* on error +* * @jmp_buf_set - runs the give function and setups a jump back point by saving * the context in the jump buffer; jmp_buf_longjmp can be called from the give * function or any callee in that function to return back to the jump back
@@ -72,6 +81,11 @@ struct lkl_host_operations {int (*thread_equal)(lkl_thread_t a,lkl_thread_t b);long (*gettid)(void ); +struct lkl_tls_key *(*tls_alloc)(void (*destructor)(void *)); +void (*tls_free)(struct lkl_tls_key *key); +int (*tls_set)(struct lkl_tls_key *key,void *data); +void *(*tls_get)(struct lkl_tls_key *key); +void (*jmp_buf_set)(struct lkl_jmp_buf *jmpb,void (*f)(void ));void (*jmp_buf_longjmp)(struct lkl_jmp_buf *jmpb,int val);
arch/um/nommu/include/uapi/asm/syscalls.h new file +287 -0
287 lines not on this page · raw message
arch/um/nommu/include/uapi/asm/unistd.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __UM_NOMMU_UAPI_UNISTD_H +#define __UM_NOMMU_UAPI_UNISTD_H + +#define __ARCH_WANT_NEW_STAT +#include <asm/bitsperlong.h> + +#if __BITS_PER_LONG ==64 +#define __ARCH_WANT_SYS_NEWFSTATAT +#endif + +#include <asm-generic/unistd.h> + + +#endif
arch/um/nommu/um/syscalls.c new file +199 -0
199 lines not on this page · raw message
arch/um/scripts/headers_install.py new file +197 -0
197 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 13/21 um: nommu: basic console support
In reply to Hajime TazakiThis commit also disables stdio-console of UM if !CONFIG_MMU to avoid conflicts between multiple consoles.
--- arch/um/drivers/Makefile | 8 ++++- arch/um/nommu/include/uapi/asm/host_ops.h | 3 ++ arch/um/nommu/um/console.c | 42 +++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 arch/um/nommu/um/console.c
arch/um/drivers/Makefile +7 -1
@@ -37,7 +37,13 @@ $(obj)/vde.o: $(obj)/vde_kern.o $(obj)/vde_user.o # When the above is fixed, don't forget to add this too! #targets += $(obj)/pcap.o -obj-y := stdio_console.o fd.o chan_kern.o chan_user.o line.o +ifdef CONFIG_MMU +obj-y := stdio_console.o +else +obj-y := +endif +obj-y += fd.o chan_kern.o chan_user.o line.o + obj-$(CONFIG_SSL) += ssl.o obj-$(CONFIG_STDERR_CONSOLE) += stderr_console.o
arch/um/nommu/include/uapi/asm/host_ops.h +3 -0
@@ -15,6 +15,7 @@ struct lkl_jmp_buf {* * These operations must be provided by a host library or by the application * itself. +* @print - optional operation that receives console messages * * @sem_alloc - allocate a host semaphore an initialize it to count * @sem_free - free a host semaphore
@@ -63,6 +64,8 @@ struct lkl_jmp_buf {* */ struct lkl_host_operations { +void (*print)(const char *str,int len); +struct lkl_sem *(*sem_alloc)(int count);void (*sem_free)(struct lkl_sem *sem);void (*sem_up)(struct lkl_sem *sem);
arch/um/nommu/um/console.c new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 15/21 um: nommu: integrate with irq infrastructure of UML
In reply to Hajime TazakiIn order to cooperate with UML's irq infrastructure and nommu threads based on host threads, irq handlers shall synchronize the our scheduler which is controlled by struct lkl_cpu. To do that, the irq infra notifies its entry of handlers by obtaining cpu access of thread scheduler (lkl_cpu_try_run_irq) and its release (lkl_cpu_put).
In additon to that, in order to stick the signal handler's thread to the one of the idle thread, several required configurations of (thread's) signal mask are added: otherwise handlers running on arbitrary thread cannot obtain cpu access and immediately fall into pending interrupt which may slow down the delivery of signals.
--- arch/um/include/shared/os.h | 1 + arch/um/kernel/irq.c | 13 +++++++++++++ arch/um/kernel/time.c | 2 ++ arch/um/nommu/include/asm/cpu.h | 3 +++ arch/um/nommu/um/cpu.c | 17 ++++++++++++++--- arch/um/nommu/um/setup.c | 5 +++++ arch/um/nommu/um/threads.c | 3 +++ tools/um/uml/signal.c | 12 ++++++++++-- 8 files changed, 51 insertions(+), 5 deletions(-)
arch/um/include/shared/os.h +1 -0
@@ -241,6 +241,7 @@ extern int set_signals(int enable);extern int set_signals_trace (int enable);extern int os_is_signal_stack (void );extern void deliver_alarm (void ); +extern void set_pending_signals (int sig);/* util.c */ extern void stack_protections (unsigned long address);
arch/um/kernel/irq.c +13 -0
@@ -19,6 +19,7 @@#include <kern_util.h> #include <os.h> #include <irq_user.h> +#include <asm/cpu.h> extern void free_irqs (void );
@@ -541,6 +542,11 @@ unsigned long to_irq_stack(unsigned long *mask_out)unsigned long mask, old;int nested; +#ifndef CONFIG_MMU +if (!nommu_irq_enter (ffs (*mask_out) -1 )) +return 1 ; +#endif + mask =xchg (&pending_mask, *mask_out);if (mask !=0 ) {/*
@@ -557,6 +563,10 @@ unsigned long to_irq_stack(unsigned long *mask_out) old |= mask; mask =xchg (&pending_mask, old); }while (mask != old); + +#ifndef CONFIG_MMU +nommu_irq_exit (); +#endif return 1 ; }
@@ -594,6 +604,9 @@ unsigned long from_irq_stack(int nested) *to = *ti; mask =xchg (&pending_mask,0 ); +#ifndef CONFIG_MMU +nommu_irq_exit (); +#endif return mask & ~1 ; }
arch/um/kernel/time.c +2 -0
@@ -597,11 +597,13 @@ static struct clock_event_device timer_clockevent = {static irqreturn_t um_timer (int irq,void *dev) { +#ifdef CONFIG_MMU if (get_current ()->mm !=NULL ) {/* userspace - relay signal, results in correct userspace timers */ os_alarm_process (get_current ()->mm->context.id.u.pid); } +#endif (*timer_clockevent.event_handler)(&timer_clockevent);
arch/um/nommu/include/asm/cpu.h +3 -0
@@ -10,4 +10,7 @@ void lkl_cpu_wait_shutdown(void);void lkl_cpu_change_owner (lkl_thread_t owner);void lkl_cpu_set_irqs_pending (void ); +void nommu_irq_exit (void ); +int nommu_irq_enter (int sig); +#endif
arch/um/nommu/um/cpu.c +14 -3
@@ -8,15 +8,16 @@#include <asm/sched.h> #include <asm/syscalls.h> #include <init.h> +#include <os.h> void run_irqs (void ) { -panic ("unimplemented %s" , __func__); +unblock_signals (); } -int set_irq_pending (int irq) +void set_irq_pending (int sig) { -panic ("unimplemented %s" , __func__); +set_pending_signals (sig); }/*
@@ -174,6 +175,16 @@ int lkl_cpu_try_run_irq(int irq)return ret; } +int nommu_irq_enter (int sig) +{ +return lkl_cpu_try_run_irq (sig); +} + +void nommu_irq_exit (void ) +{ +return lkl_cpu_put (); +} +static void lkl_cpu_shutdown (void ) {__sync_fetch_and_add (&cpu.shutdown_gate,MAX_THREADS );
arch/um/nommu/um/setup.c +5 -0
@@ -36,6 +36,8 @@ static void __init *lkl_run_kernel(void *arg) panic_blink = lkl_panic_blink; +/* signal should be received at this thread (main and idle threads) */ +init_new_thread_signals ();threads_init ();lkl_cpu_get ();start_kernel ();
@@ -58,6 +60,9 @@ int __init lkl_start_kernel(struct lkl_host_operations *ops,if (ret) goto out_free_init_sem; +change_sig (SIGALRM ,0 ); +change_sig (SIGIO ,0 ); + ret = lkl_ops->thread_create (lkl_run_kernel,NULL );if (!ret) { ret = -ENOMEM ;
arch/um/nommu/um/threads.c +3 -0
@@ -152,6 +152,9 @@ static void *thread_bootstrap(void *_tba)int (*f)(void *) = tba->f;void *arg = tba->arg; +change_sig (SIGALRM ,0 ); +change_sig (SIGIO ,0 ); + lkl_ops->sem_down (ti->task->thread.arch.sched_sem);kfree (tba);if (ti->task->thread.prev_sched)
tools/um/uml/signal.c +10 -2
@@ -218,8 +218,8 @@ void set_handler(int sig)sigemptyset (&sig_mask);sigaddset (&sig_mask, sig); -if (sigprocmask (SIG_UNBLOCK , &sig_mask,NULL ) <0 ) -panic ("sigprocmask failed - errno = %d\n" , errno); +if (pthread_sigmask (SIG_UNBLOCK , &sig_mask,NULL ) <0 ) +panic ("pthread_sigmask failed - errno = %d\n" , errno); }int change_sig (int signal,int on)
@@ -355,3 +355,11 @@ int os_is_signal_stack(void)return ss.ss_flags &SS_ONSTACK ; } + +void set_pending_signals (int sig) +{ +if (sig ==SIGIO ) + signals_pending |=SIGIO_MASK ; +else if (sig ==SIGALRM ) + signals_pending |=SIGALRM_MASK ; +}
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 14/21 um: nommu: initialization and cleanup
In reply to Hajime TazakiAdd the lkl_start_kernel and lkl_sys_halt APIs that start and respectively stops the Linux kernel.
lkl_start_kernel creates a separate threads that will run the initial and idle kernel thread. It waits for the kernel to complete initialization before returning, to avoid races with system calls issues by the host application.
During the setup phase, we create "/init" in initial ramfs root filesystem to avoid mounting the "real" rootfs since ramfs is good enough for now.
lkl_sys_halt will shutdown the kernel, terminate all threads and free all host resources used by the kernel before returning.
--- arch/um/nommu/include/uapi/asm/host_ops.h | 14 ++ arch/um/nommu/um/setup.c | 162 ++++++++++++++++++++++ tools/um/uml/process.c | 2 + 3 files changed, 178 insertions(+) create mode 100644 arch/um/nommu/um/setup.c
arch/um/nommu/include/uapi/asm/host_ops.h +14 -0
@@ -16,6 +16,7 @@ struct lkl_jmp_buf {* These operations must be provided by a host library or by the application * itself. * @print - optional operation that receives console messages +* @panic - called during a kernel panic * * @sem_alloc - allocate a host semaphore an initialize it to count * @sem_free - free a host semaphore
@@ -65,6 +66,7 @@ struct lkl_jmp_buf {*/ struct lkl_host_operations {void (*print)(const char *str,int len); +void (*panic)(void );struct lkl_sem *(*sem_alloc)(int count);void (*sem_free)(struct lkl_sem *sem);
@@ -96,6 +98,18 @@ struct lkl_host_operations { void (*mem_free)(void *mem); }; +/** +* lkl_start_kernel - registers the host operations and starts the kernel +* +* The function returns only after the kernel is shutdown with lkl_sys_halt. +* +* @lkl_ops - pointer to host operations +* @cmd_line - format for command line string that is going to be used to +* generate the Linux kernel command line +*/ +int lkl_start_kernel (struct lkl_host_operations *ops, +const char *fmt, ...); +void lkl_bug (const char *fmt, ...);#endif
arch/um/nommu/um/setup.c new file +162 -0
162 lines not on this page · raw message
tools/um/uml/process.c +2 -0
@@ -114,6 +114,8 @@ void os_kill_process(int pid, int reap_child)void os_kill_ptraced_process (int pid,int reap_child) { +if (pid ==0 ) +return ;kill (pid,SIGKILL );ptrace (PTRACE_KILL , pid);ptrace (PTRACE_CONT , pid);
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 16/21 um: nommu: plug in the build system
In reply to Hajime TazakiBasic Makefiles for building library of nommu mode. Add a new architecture specific target for installing the resulting library files and headers.
To make nommu binaries build, UML introduced an additional option, UMMODE variable, to switch the output file of build: kernel (default), or library (nommu). Those modes are not able to be ON at the same time.
To build on library mode, users do the following:
make defconfig ARCH=um UMMODE=library
make ARCH=um UMMODE=library
--- arch/um/Kconfig | 17 ++++++++++++++--- arch/um/Makefile | 12 +++++++++++- arch/um/kernel/Makefile | 14 +++++++++----- arch/um/nommu/um/Kconfig | 37 +++++++++++++++++++++++++++++++++++++ arch/um/nommu/um/Makefile | 4 ++++ 5 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 arch/um/nommu/um/Kconfig create mode 100644 arch/um/nommu/um/Makefile
arch/um/Kconfig +14 -3
@@ -22,9 +22,20 @@ config UML select TTY # Needed for line.c select MODULE_REL_CRCS if MODVERSIONS +config UMMODE_LIB + bool "UML mode: library mode" + default y if "$(UMMODE)" = "library" + help + This mode switches a mode to build a library of UML (Linux + Kernel Library/LKL). This switch is exclusive to "kernel mode" + of UML, which is traditional mode of UML. + + For more detail about LKL, see + <file:Documentation/virt/uml/lkl.txt>. + config MMU bool - default y + default y if !UMMODE_LIB config NO_IOMEM def_bool y
@@ -45,12 +56,12 @@ config LOCKDEP_SUPPORT config STACKTRACE_SUPPORT bool - default y + default y if MMU select STACKTRACE config GENERIC_CALIBRATE_DELAY bool - default y + default y if MMU config HZ int
arch/um/Makefile +11 -1
@@ -17,6 +17,10 @@ else KBUILD_DEFCONFIG := $(SUBARCH)_defconfig endif +ifeq ($(UMMODE),library) + SUBARCH := um/nommu +endif + ARCH_DIR := arch/um OS := $(shell uname -s) # We require bash because the vmlinux link and loader script cpp use bash
@@ -97,8 +101,14 @@ KBUILD_CFLAGS += $(KERNEL_DEFINES) LDFLAGS_vmlinux += -r INSTALL_PATH=$(objtree)/tools/um +ifeq ($(UMMODE),library) +all: install + $(Q)$(MAKE) -C $(srctree)/tools/um +install: linux.o um_headers_install +else all: linux install: linux.o +endif @echo " INSTALL $(INSTALL_PATH)/lib/$<" @mkdir -p $(INSTALL_PATH)/lib/ @cp $< $(INSTALL_PATH)/lib/
@@ -111,7 +121,7 @@ linux: linux.o linux.o: vmlinux @echo ' LINK $@' - $(Q)$(OBJCOPY) -R .eh_frame $< $@ + $(Q)$(OBJCOPY) -R .eh_frame -L sem_init -L sem_post -L sem_wait -L sem_destroy $< $@ $(Q)mkdir -p $(objtree)/tools/um/lib define archhelp
arch/um/kernel/Makefile +9 -5
@@ -14,17 +14,21 @@ CPPFLAGS_vmlinux.lds := -DSTART=$(LDS_START) \ $(LDS_EXTRA) extra-y := vmlinux.lds -obj-y = config.o exec.o exitcode.o irq.o ksyms.o mem.o \ - physmem.o process.o ptrace.o reboot.o sigio.o \ - signal.o syscall.o sysrq.o time.o tlb.o trap.o \ - um_arch.o umid.o maccess.o kmsg_dump.o skas/ +obj-y = config.o exitcode.o irq.o ksyms.o \ + process.o reboot.o sigio.o \ + signal.o syscall.o time.o \ + um_arch.o umid.o maccess.o kmsg_dump.o + +ifdef CONFIG_MMU +obj-y += exec.o mem.o physmem.o ptrace.o sysrq.o tlb.o trap.o skas/ +endif obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o obj-$(CONFIG_GPROF) += gprof_syms.o obj-$(CONFIG_GCOV) += gmon_syms.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-$(CONFIG_STACKTRACE) += stacktrace.o -obj-y += user_syms.o +obj-$(CONFIG_MMU) += user_syms.o USER_OBJS := config.o
arch/um/nommu/um/Kconfig new file +37 -0
@@ -0,0 +1,37 @@ +config UML_NOMMU + def_bool y + depends on !SMP && !MMU + select UACCESS_MEMCPY + select ARCH_THREAD_STACK_ALLOCATOR + select ARCH_HAS_SYSCALL_WRAPPER + +config 64BIT + bool + default y + +config GENERIC_CSUM + def_bool y + +config GENERIC_ATOMIC64 + bool + default y if !64BIT + +config SECCOMP + bool + default n + +config GENERIC_HWEIGHT + def_bool y + +config GENERIC_CALIBRATE_DELAY + bool + default n + +config STACKTRACE_SUPPORT + bool + default n + +# XXX: need this to work well with tap13.py +config PRINTK_TIME + bool + default y
arch/um/nommu/um/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +include/generated/user_constants.h: $(srctree)/arch/um/nommu/um/user_constants.h + $(Q)cp -f $^ $@ + +obj-y = bootmem.o console.o cpu.o delay.o setup.o syscalls.o threads.o unimplemented.o
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 17/21 um: host: add nommu build for ARCH=um
In reply to Hajime TazakiThis patch adds the skeleton for the host library.
The host library is implementing the host operations needed by nommu mode and is split into host dependent (depends on a specific host, e.g. POSIX hosts) and host independent parts (will work on all supported hosts).
--- tools/um/.gitignore | 1 + tools/um/Makefile | 32 +++--- tools/um/Targets | 3 +- tools/um/include/lkl.h | 151 +++++++++++++++++++++++++++++ tools/um/include/lkl_host.h | 26 +++++ tools/um/uml/Build | 16 ++- tools/um/uml/nommu/Build | 1 + tools/um/uml/nommu/registers.c | 21 ++++ tools/um/uml/nommu/unimplemented.c | 21 ++++ 9 files changed, 252 insertions(+), 20 deletions(-) create mode 100644 tools/um/.gitignore create mode 100644 tools/um/include/lkl.h create mode 100644 tools/um/include/lkl_host.h create mode 100644 tools/um/uml/nommu/Build create mode 100644 tools/um/uml/nommu/registers.c create mode 100644 tools/um/uml/nommu/unimplemented.c
tools/um/.gitignore new file +1 -0
@@ -0,0 +1 @@ +*.pyc
tools/um/Makefile +17 -15
@@ -5,6 +5,7 @@ MAKEFLAGS += -r --no-print-directory KCONFIG?=defconfig +UMMODE?=kernel ifneq ($(silent),1) ifneq ($(V),1)
@@ -15,10 +16,8 @@ endif PREFIX := /usr -ifeq (,$(srctree)) - srctree := $(patsubst %/,%,$(dir $(shell pwd))) - srctree := $(patsubst %/,%,$(dir $(srctree))) -endif +srctree := $(patsubst %/,%,$(dir $(shell pwd))) +srctree := $(patsubst %/,%,$(dir $(srctree))) export srctree -include ../scripts/Makefile.include
@@ -32,9 +31,6 @@ endif export OUTPUT export objtree := $(OUTPUT)/../.. - -all: - export CFLAGS += -I$(OUTPUT)/include -Iinclude -Wall -g -O2 -Wextra -fPIC \ -Wno-unused-parameter \ -Wno-missing-field-initializers -fno-strict-aliasing
@@ -45,28 +41,34 @@ TARGETS := $(progs-y:%=$(OUTPUT)%) TARGETS += $(libs-y:%=$(OUTPUT)%) all: $(TARGETS) -# rule to build linux.o -$(OUTPUT)lib/linux.o: - $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) $(KCONFIG) - $(Q)CFLAGS= $(MAKE) -C ../.. ARCH=um $(KOPT) install INSTALL_PATH=$(OUTPUT) +$(objtree)/linux.o: + $(Q)echo "" + $(Q)echo "" + $(Q)echo "==> $@ isn't found; please make ARCH=um" + $(Q)echo "" + $(Q)echo "" + $(Q)exit 1 -$(OUTPUT)liblinux.a: $(OUTPUT)lib/linux.o $(OUTPUT)uml/liblinux-in.o $(OUTPUT)lib/liblinux-in.o +$(OUTPUT)lib/linux.o: $(objtree)/linux.o + $(Q)cp $(objtree)/linux.o $(OUTPUT)lib/linux.o + +# rule to build linux.o +$(OUTPUT)liblinux.a: $(OUTPUT)uml/liblinux-in.o $(OUTPUT)lib/liblinux-in.o $(OUTPUT)lib/linux.o $(QUIET_AR)$(AR) -rc $@ $^ # rule to link programs $(OUTPUT)%: $(OUTPUT)%-in.o $(OUTPUT)liblinux.a $(QUIET_LINK)$(CC) $(LDFLAGS) $(LDFLAGS_$(notdir $*)-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$(notdir $*)-y) -$(OUTPUT)%-in.o: FORCE - $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) - # rule to build objects $(OUTPUT)%-in.o: $(OUTPUT)lib/linux.o FORCE $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) +RM := rm -f clean: $(call QUIET_CLEAN, objects)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd'\ -delete -o -name '\.*.d' -delete + $(call QUIET_CLEAN, headers)$(RM) -r $(OUTPUT)/include/lkl/ $(call QUIET_CLEAN, liblinux.a)$(RM) $(OUTPUT)/liblinux.a $(call QUIET_CLEAN, $(TARGETS))$(RM) $(TARGETS)
tools/um/Targets +2 -1
@@ -1,4 +1,5 @@ progs-y += uml/linux -LDLIBS_linux-y := -lrt -lpthread -lutil + +LDLIBS := -lrt -lpthread -lutil LDFLAGS_linux-y := -no-pie -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc LDFLAGS_linux-$(UML_STATIC) += -static
tools/um/include/lkl.h new file +151 -0
151 lines not on this page · raw message
tools/um/include/lkl_host.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LKL_HOST_H +#define _LKL_HOST_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <lkl/asm/host_ops.h> +#include <lkl.h> + +extern struct lkl_host_operations lkl_host_ops; + +/** +* lkl_printf - print a message via the host print operation +* +* @fmt: printf like format string +*/ +int lkl_printf (const char *fmt, ...); + + +#ifdef __cplusplus +} +#endif + +#endif
tools/um/uml/Build +12 -4
@@ -8,11 +8,19 @@ KCOV_INSTRUMENT := n include $(objtree)/include/config/auto.conf -liblinux-y += execvp.o file.o helper.o irq.o main.o mem.o process.o \ - registers.o sigio.o signal.o start_up.o time.o tty.o \ - umid.o util.o drivers/ skas/ +liblinux-y += execvp.o file.o helper.o irq.o mem.o process.o \ + registers.o sigio.o signal.o time.o tty.o \ + umid.o util.o drivers/ +ifdef CONFIG_MMU +liblinux-y += main.o start_up.o skas/ +HEADER_ARCH := x86 liblinux-y += x86/ +else +HEADER_ARCH := um/nommu +liblinux-y += nommu/ +endif + liblinux-$(CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA) += elf_aux.o
@@ -23,7 +31,6 @@ CFLAGS := -g -O2 # from arch/um/Makefile ARCH_DIR := arch/um -HEADER_ARCH := x86 HOST_DIR := arch/$(HEADER_ARCH) ifdef CONFIG_64BIT KBUILD_CFLAGS += -mcmodel=large
@@ -33,6 +40,7 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \ -Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \ -Din6addr_loopback=kernel_in6addr_loopback \ -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr +KBUILD_CFLAGS := $(filter-out -Dsigprocmask=kernel_sigprocmask,$(KBUILD_CFLAGS)) SHARED_HEADERS := $(ARCH_DIR)/include/shared MODE_INCLUDE += -I$(srctree)/$(ARCH_DIR)/include/shared/skas ARCH_INCLUDE := -I$(srctree)/$(SHARED_HEADERS)
tools/um/uml/nommu/Build new file +1 -0
@@ -0,0 +1 @@ +liblinux-y = registers.o unimplemented.o
tools/um/uml/nommu/registers.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 + +struct uml_pt_regs ; + +int get_fp_registers (int pid,unsigned long *regs) +{ +return 0 ; +} + +int save_i387_registers (int pid,unsigned long *fp_regs) +{ +return 0 ; +} + +void arch_init_registers (int pid) +{ +} + +void get_regs_from_mc (struct uml_pt_regs *regs,void *mc) +{ +}
tools/um/uml/nommu/unimplemented.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <generated/user_constants.h> + +struct uml_pt_regs ; + +/* os-Linux/skas/process.c */ +int userspace_pid[UM_NR_CPUS ]; +void userspace (struct uml_pt_regs *regs,unsigned long *aux_fp_regs) +{} + + +/* x86/os-Linux/task_size.c */ +unsigned long os_get_top_address (void ) +{ +return 0 ; +} + +/* start-up.c */ +void os_early_checks (void ) +{ +}
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 18/21 um: host: add utilities functions
In reply to Hajime TazakiAdd basic utility functions for getting a string from a kernel error code and a fprintf like function that uses the host print operation. The latter is useful for informing the user about errors that occur in the host library.
--- tools/um/lib/Build | 4 + tools/um/lib/jmp_buf.c | 14 +++ tools/um/lib/jmp_buf.h | 8 ++ tools/um/lib/utils.c | 210 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 236 insertions(+) create mode 100644 tools/um/lib/Build create mode 100644 tools/um/lib/jmp_buf.c create mode 100644 tools/um/lib/jmp_buf.h create mode 100644 tools/um/lib/utils.c
tools/um/lib/Build new file +4 -0
@@ -0,0 +1,4 @@ +include $(objtree)/include/config/auto.conf + +liblinux-$(CONFIG_UMMODE_LIB) += utils.o +liblinux-$(CONFIG_UMMODE_LIB) += jmp_buf.o
tools/um/lib/jmp_buf.c new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <setjmp.h> +#include <lkl_host.h> + +void jmp_buf_set (struct lkl_jmp_buf *jmpb,void (*f)(void )) +{ +if (!setjmp (*((jmp_buf *)jmpb->buf))) +f (); +} + +void jmp_buf_longjmp (struct lkl_jmp_buf *jmpb,int val) +{ +longjmp (*((jmp_buf *)jmpb->buf), val); +}
tools/um/lib/jmp_buf.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LKL_LIB_JMP_BUF_H +#define _LKL_LIB_JMP_BUF_H + +void jmp_buf_set (struct lkl_jmp_buf *jmpb,void (*f)(void )); +void jmp_buf_longjmp (struct lkl_jmp_buf *jmpb,int val); + +#endif
tools/um/lib/utils.c new file +210 -0
210 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 19/21 um: host: posix host operations
In reply to Hajime TazakiThis commit implements LKL host operations for POSIX hosts. The operations are implemented to be portable in various POSIX OSs.
--- tools/um/lib/Build | 2 + tools/um/lib/posix-host.c | 292 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 294 insertions(+) create mode 100644 tools/um/lib/posix-host.c
tools/um/lib/Build +2 -0
@@ -1,4 +1,6 @@ include $(objtree)/include/config/auto.conf +CFLAGS_posix-host.o += -D_FILE_OFFSET_BITS=64 liblinux-$(CONFIG_UMMODE_LIB) += utils.o +liblinux-$(CONFIG_UMMODE_LIB) += posix-host.o liblinux-$(CONFIG_UMMODE_LIB) += jmp_buf.o
tools/um/lib/posix-host.c new file +292 -0
292 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 20/21 um: host: add test programs
In reply to Hajime TazakiAdd a simple LKL test application (boot) that starts the kernel and performs simple tests that minimally exercise the LKL API.
--- tools/um/Makefile | 5 +- tools/um/Targets | 6 + tools/um/tests/Build | 3 + tools/um/tests/boot.c | 393 ++++++++++++++++++++++++++++++++++++++++ tools/um/tests/boot.sh | 9 + tools/um/tests/run.py | 172 ++++++++++++++++++ tools/um/tests/tap13.py | 209 +++++++++++++++++++++ tools/um/tests/test.c | 126 +++++++++++++ tools/um/tests/test.h | 72 ++++++++ tools/um/tests/test.sh | 181 ++++++++++++++++++ 10 files changed, 1175 insertions(+), 1 deletion(-) create mode 100644 tools/um/tests/Build create mode 100644 tools/um/tests/boot.c create mode 100755 tools/um/tests/boot.sh create mode 100755 tools/um/tests/run.py create mode 100644 tools/um/tests/tap13.py create mode 100644 tools/um/tests/test.c create mode 100644 tools/um/tests/test.h create mode 100644 tools/um/tests/test.sh
tools/um/Makefile +4 -1
@@ -72,7 +72,10 @@ clean: $(call QUIET_CLEAN, liblinux.a)$(RM) $(OUTPUT)/liblinux.a $(call QUIET_CLEAN, $(TARGETS))$(RM) $(TARGETS) +run-tests: + ./tests/run.py $(tests) + FORCE: ; -.PHONY: all clean FORCE +.PHONY: all clean FORCE run-tests .IGNORE: clean .NOTPARALLEL : lib/linux.o
tools/um/Targets +6 -0
@@ -1,4 +1,10 @@ +ifeq ($(UMMODE),library) +progs-y += tests/boot +else progs-y += uml/linux +endif + +LDFLAGS_boot-y := -pie LDLIBS := -lrt -lpthread -lutil LDFLAGS_linux-y := -no-pie -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
tools/um/tests/Build new file +3 -0
@@ -0,0 +1,3 @@ +boot-y += boot.o test.o + +CFLAGS_test.o += -Wno-implicit-fallthrough
tools/um/tests/boot.c new file +393 -0
393 lines not on this page · raw message
tools/um/tests/boot.sh new file +9 -0
@@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +script_dir=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd) +source $script_dir/test.sh + +lkl_test_plan 1 "boot" +lkl_test_run 1 +lkl_test_exec $script_dir/boot
tools/um/tests/run.py new file +172 -0
172 lines not on this page · raw message
tools/um/tests/tap13.py new file +209 -0
209 lines not on this page · raw message
tools/um/tests/test.c new file +126 -0
126 lines not on this page · raw message
tools/um/tests/test.h new file +72 -0
72 lines not on this page · raw message
tools/um/tests/test.sh new file +181 -0
181 lines not on this page · raw message
Signature · 1 line
2.21.0 (Apple Git-122.2)
RFC v7 21/21 um: nommu: add block device support of UML
In reply to Hajime TazakiThis commit adds block device support for nommu mode, and also added several host utilities to run a simple test program (tools/um/test/disk.c) successfully.
--- arch/um/include/asm/xor.h | 3 +- arch/um/include/shared/as-layout.h | 1 + arch/um/kernel/um_arch.c | 5 + arch/um/nommu/include/uapi/asm/host_ops.h | 7 + arch/um/nommu/include/uapi/asm/unistd.h | 2 + arch/um/nommu/um/Kconfig | 8 + arch/um/nommu/um/setup.c | 12 + tools/um/Targets | 2 + tools/um/include/lkl.h | 206 ++++++++++ tools/um/include/lkl_host.h | 1 + tools/um/lib/Build | 1 + tools/um/lib/fs.c | 461 ++++++++++++++++++++++ tools/um/lib/posix-host.c | 1 + tools/um/lib/utils.c | 3 + tools/um/tests/Build | 1 + tools/um/tests/cla.c | 159 ++++++++ tools/um/tests/cla.h | 33 ++ tools/um/tests/disk.c | 168 ++++++++ tools/um/tests/disk.sh | 70 ++++ tools/um/tests/run.py | 2 + 20 files changed, 1145 insertions(+), 1 deletion(-) create mode 100644 tools/um/lib/fs.c create mode 100644 tools/um/tests/cla.c create mode 100644 tools/um/tests/cla.h create mode 100644 tools/um/tests/disk.c create mode 100755 tools/um/tests/disk.sh
arch/um/include/asm/xor.h +2 -1
@@ -4,4 +4,5 @@/* pick an arbitrary one - measuring isn't possible with inf-cpu */ #define XOR_SELECT_TEMPLATE (x) \ - (time_travel_mode == TT_MODE_INFCPU ? &xor_block_8regs : NULL) + (time_travel_mode == TT_MODE_INFCPU || (!IS_ENABLED(CONFIG_MMU)) ? \ + &xor_block_8regs : NULL)
arch/um/include/shared/as-layout.h +1 -0
@@ -57,6 +57,7 @@ extern unsigned long host_task_size;extern int linux_main (int argc,char **argv);extern void uml_finishsetup (void ); +extern void uml_set_args (char *args);struct siginfo ;extern void (*sig_info[])(int ,struct siginfo *si,struct uml_pt_regs *);
arch/um/kernel/um_arch.c +5 -0
@@ -41,6 +41,11 @@ static void __init add_arg(char *arg)strcat (command_line, arg); } +void __init uml_set_args (char *args) +{ +strcat (command_line, args); +} +/* * These fields are initialized at boot time and not changed. * XXX This structure is used only in the non-SMP case. Maybe this
arch/um/nommu/include/uapi/asm/host_ops.h +7 -0
@@ -15,6 +15,11 @@ struct lkl_jmp_buf {* * These operations must be provided by a host library or by the application * itself. +* +* @um_devices - string containg the list of UML devices in command line +* format. This string is appended to the kernel command line and +* is provided here for convenience to be implemented by the host library. +* * @print - optional operation that receives console messages * @panic - called during a kernel panic *
@@ -65,6 +70,8 @@ struct lkl_jmp_buf {* */ struct lkl_host_operations { +const char *um_devices; +void (*print)(const char *str,int len);void (*panic)(void );
arch/um/nommu/include/uapi/asm/unistd.h +2 -0
@@ -3,6 +3,8 @@#define __UM_NOMMU_UAPI_UNISTD_H#define __ARCH_WANT_NEW_STAT +#define __ARCH_WANT_SET_GET_RLIMIT +#include <asm/bitsperlong.h> #if __BITS_PER_LONG ==64
arch/um/nommu/um/Kconfig +8 -0
@@ -4,6 +4,10 @@ config UML_NOMMU select UACCESS_MEMCPY select ARCH_THREAD_STACK_ALLOCATOR select ARCH_HAS_SYSCALL_WRAPPER + select VFAT_FS + select NLS_CODEPAGE_437 + select NLS_ISO8859_1 + select BTRFS_FS config 64BIT bool
@@ -35,3 +39,7 @@ config STACKTRACE_SUPPORT config PRINTK_TIME bool default y + +config RAID6_PQ_BENCHMARK + bool + default n
arch/um/nommu/um/setup.c +12 -0
@@ -45,13 +45,25 @@ static void __init *lkl_run_kernel(void *arg)return NULL ; } +static char _cmd_line[COMMAND_LINE_SIZE ];int __init lkl_start_kernel (struct lkl_host_operations *ops,const char *fmt, ...) { +va_list ap;int ret; lkl_ops = ops; +va_start (ap, fmt); + ret =vsnprintf (_cmd_line,COMMAND_LINE_SIZE , fmt, ap); +va_end (ap); + +if (ops->um_devices) +strscpy (_cmd_line + ret, ops->um_devices, +COMMAND_LINE_SIZE - ret); + +uml_set_args (_cmd_line); + init_sem = lkl_ops->sem_alloc (0 );if (!init_sem)return -ENOMEM ;
tools/um/Targets +2 -0
@@ -1,10 +1,12 @@ ifeq ($(UMMODE),library) progs-y += tests/boot +progs-y += tests/disk else progs-y += uml/linux endif LDFLAGS_boot-y := -pie +LDFLAGS_disk-y := -pie LDLIBS := -lrt -lpthread -lutil LDFLAGS_linux-y := -no-pie -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
tools/um/include/lkl.h +206 -0
224 lines not on this page · raw message
tools/um/include/lkl_host.h +1 -0
@@ -10,6 +10,7 @@ extern "C" {#include <lkl.h> extern struct lkl_host_operations lkl_host_ops; +extern char lkl_um_devs[4096 ];/** * lkl_printf - print a message via the host print operation
tools/um/lib/Build +1 -0
@@ -4,3 +4,4 @@ CFLAGS_posix-host.o += -D_FILE_OFFSET_BITS=64 liblinux-$(CONFIG_UMMODE_LIB) += utils.o liblinux-$(CONFIG_UMMODE_LIB) += posix-host.o liblinux-$(CONFIG_UMMODE_LIB) += jmp_buf.o +liblinux-$(CONFIG_UMMODE_LIB) += fs.o
tools/um/lib/fs.c new file +461 -0
461 lines not on this page · raw message
tools/um/lib/posix-host.c +1 -0
@@ -263,6 +263,7 @@ static void *tls_get(struct lkl_tls_key *key) }struct lkl_host_operations lkl_host_ops = { + .um_devices = lkl_um_devs, .panic = panic, .print = print, .mem_alloc = (void *)malloc,
tools/um/lib/utils.c +3 -0
@@ -4,6 +4,9 @@#include <string.h> #include <lkl_host.h> +/* XXX: find a better place */ +char lkl_um_devs[4096 ]; +static const char *const lkl_err_strings[] = {"Success" ,"Operation not permitted" ,
tools/um/tests/Build +1 -0
@@ -1,3 +1,4 @@ boot-y += boot.o test.o +disk-y += disk.o test.o cla.o CFLAGS_test.o += -Wno-implicit-fallthrough
tools/um/tests/cla.c new file +159 -0
159 lines not on this page · raw message
tools/um/tests/cla.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _LKL_TEST_CLA_H +#define _LKL_TEST_CLA_H + +enum cl_arg_type { +CL_ARG_USER =0 , +CL_ARG_BOOL , +CL_ARG_INT , +CL_ARG_STR , +CL_ARG_STR_SET , +CL_ARG_IPV4 , +CL_ARG_END , +}; + +struct cl_arg ; + +typedef int (*cl_arg_parser_t )(struct cl_arg *arg,const char *value); + +struct cl_arg { +const char *long_name; +char short_name; +const char *help; +int has_arg; +enum cl_arg_type type; +void *store; +void *set; +cl_arg_parser_t parser; +}; + +int cla_parse_args (int argc,const char **argv,struct cl_arg *args); + + +#endif /* _LKL_TEST_CLA_H */
tools/um/tests/disk.c new file +168 -0
168 lines not on this page · raw message
tools/um/tests/disk.sh new file +70 -0
70 lines not on this page · raw message
tools/um/tests/run.py +2 -0
@@ -50,6 +50,8 @@ mydir=os.path.dirname(os.path.realpath(__file__)) tests = [ 'boot.sh', + 'disk.sh -t ext4', + 'disk.sh -t vfat', ] parser = argparse.ArgumentParser(description='LKL test runner')
Signature · 1 line
2.21.0 (Apple Git-122.2)
Anton Ivanov
maintainerQuoted 12 lines · Hajime Tazaki
This is another spin of the unification of LKL into UML. Based on the discussion of v4 patchset, we have tried to address issue raised and rewrote the patchset from scratch. The summary is listed in the changelog below.
Although there are still bugs in the patchset, we'd like to ask your opinions on the design we changed.
The milestone section is also updated: this patchset is for the milestone 1, though the common init API is still not implemented yet.
Quoted 5 lines
Changes in rfc v7:
- preservemake ARCH=umsyntax to build UML
- introducemake ARCH=um UMMODE=libraryto build library mode
- fix undefined symbols issue during modpost
- clean up makefiles (arch/um,tools/um)
Hi Hajime, hi Tavi,
Our starting point should be that it does not break the existing build. It still does.
If I build a "stock configuration" UML after applying the patchset the resulting vmlinux is not executable.
On the positive side, it builds cleanly now. I will try to go through the rest of the patchset later today and see if there is anything else that needs fixing before we do the next version.
Brgds,
A.
Quoted 437 lines
Changes in rfc v6:
- rebase with the current linus treeChanges in rfc v5:
- rewrite whole patchset from scratch
- move arch-dependent code ofarch/umandarch/x86/umtotools/um
- mainly code under os-Linux/ involved
- introduce 2-stage build (kernel, and host-dependent parts)
- clean upvmlinux.lds.S
- put LKL-specific implementations as a SUBARCH underarch/um/nommu
- introduce !CONFIG_MMU inarch/um
- use structarch_threadandarch_switch_to()for subarch-specific thread implementation
- integrate with the IRQ infrastructure of UML
- tested with block device drivers (ubd) for the proofChanges in rfc v4: (https://lwn.net/Articles/816276/)
- Rebase on the current uml/master branch
- Fix IRQ handling (bug fix)
- drop a patch forCONFIG_GENERIC_ATOMIC64(comment by Peter Zijlstra)
- implement vector net driver forUMMODE_LIB(comment by Anton)
- clean up uapi headers to avoid duplicates
- clean up IRQ handling code (comment by Anton)
- fix error handling in test code (comments by David Disseldorp)Changes in rfc v3:
- use UML drivers (net, block) from LKL programs
- drop virtio device implementations
- drop mingw32 (Windows) host
- drop android (arm/aarch64) host
- drop FreeBSD (x86_64) host
- dropLD_PRELOAD(hijack) support
- update milestonerfc v2:
- use UMMODE instead of SUBARCH to switch UML or LKL
-tools/lkldirectory is still there. I confirmed we can move underarch/um(e.g.,arch/um/lkl/hosts). I will move it IF this is preferable.
- drop several patches involved non-uml directory
- drop several patches which are not required
- refine commit logs
- document updatedLKL (Linux Kernel Library) is aiming to allow reusing the Linux kernel code as extensively as possible with minimal effort and reduced maintenance overhead.
Examples of how LKL can be used are: creating userspace applications (running on Linux and other operating systems) that can read or write Linux filesystems or can use the Linux networking stack, creating kernel drivers for other operating systems that can read Linux filesystems, bootloaders support for reading/writing Linux filesystems, etc.
With LKL, the kernel code is compiled into an object file that can be directly linked by applications. The API offered by LKL is based on the Linux system call interface.
LKL is originally implemented as an architecture port in
arch/lkl, but this series of commits tries to integrate this intoarch/umas one of the mode of UML. This was discussed during RFC email of LKL (*1).The latest LKL version can be found at https://github.com/lkl/linux
Milestone
=========
This patches is a first step toward upstreaming *library mode* of Linux kernel, but we think we need to have several steps toward our goal, describing in the below.Milestone 1: LKL lib on top of UML
* Kernel - Host build split
- Build UML as a relocatable object using the UML's kernel linker script.
- Move the ptrace and other well isolated os code out ofarch/umtotools/um
- Use standard host toolchain to create a static library stripped of the ptrace code. Use standard host toolchain to build the main UML executable.
- Add library init API that creates the UML kernel process and starts UML.
* System calls APIs
- Add new system call interface based on UML's irq facility.
- Use the LKL scripts to export the required headers to create system calls APIs that use the UML system calls infrastructure.
- Keep the underlying host and driver operations (threads, irqs, etc.) as they are now in UML.
* Boot test
- Port the LKL boot test to verify that we are able to programatically issue system calls.Milestone 2: add virtio disk support
* Exportasm/io.hoperations to host/os. Create IO access operations and redirect them to weakos_variants that use the current UML implementation.
* Add the LKL IO access layer including generic virtio handling and the virtio block device code.
* Port LKL disk test and disk apps (lklfuse, fs2tar, cptofs)Milestone 3: new arch ports
* Abstract the system call / IRQ mode the move the implementation to host
* Abstract the thread model and move the implementation to host
* Add LKL thread model and LKL portsBuilding LKL the host library and LKL applications
==================================================% cd
tools/um
% makewill build LKL as a object file, it will install it in
tools/um/libtogether with the headers files intools/um/includethen will build the host library, tests and a few of application examples:* tests/boot - a simple applications that uses LKL and exercises the basic LKL APIs
% make run-tests
should run the above
tests/bootandtests/net-testand report errors if there are any.Supported hosts
===============Currently LKL supports Linux userspace applications. New hosts can be added relatively easy if the host supports gcc and GNU ld. Previous versions of LKL supported Windows kernel and Haiku kernel hosts, and we also have WIP patches with rump-hypercall interface, used in UEFI, as well as macOS userspace (part of POSIX).
There is also musl-libc port for LKL, which might be interested in for some folks.
Further readings about LKL
=========================- Discussion in github LKL issue
https://github.com/lkl/linux/issues/304- LKL (an article)
https://www.researchgate.net/profile/Nicolae_Tapus2/publication/224164682_LKL_The_Linux_kernel_library/links/02bfe50fd921ab4f7c000000.pdf*1 RFC email to LKML (back in 2015)
https://www.mail-archive.com/[email protected]/msg1012277.htmlPlease review the following changes for suitability for inclusion. If you have any objections or suggestions for improvement, please respond to the patches. If you agree with the changes, please provide your Acked-by.
The following changes since commit
805c6d3c19210c90c109107d189744e960eae025:Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs (2020-09-22 15:08:41 -0700)are available in the Git repository at:
git://github.com/thehajime/linux a8686efcbad3c445d3e5bde054c04a58877915f1 https://github.com/thehajime/linux/tree/uml-lkl-5.9rc6-v7Hajime Tazaki (18):
um: movearch/um/os-Linuxdir totools/um/uml
um: movearch/x86/um/os-Linuxtotools/um/uml/
scritps: um: suppress warnings if SRCARCH=um
um: extendarch_switch_tofor alternate SUBARCH
um: add nommu mode for UML library mode
um: nommu: host interface
um: nommu: memory handling
um: nommu: kernel thread support
um: nommu: system call interface and application API
um: nommu: basic console support
um: nommu: initialization and cleanup
um: nommu: integrate with irq infrastructure of UML
um: nommu: plug in the build system
um: host: add nommu build for ARCH=um
um: host: add utilities functions
um: host: posix host operations
um: host: add test programs
um: nommu: add block device support of UMLOctavian Purdila (3):
um: split build in kernel and host parts
um: add os init and exit calls
um: host: implementos_initcallsandos_exitcallsarch/um/Kconfig | 29 +- arch/um/Makefile | 35 +- arch/um/drivers/Makefile | 10 +- .../um/{os-Linux => }/drivers/ethertap_kern.c | 0 arch/um/{os-Linux => }/drivers/tuntap_kern.c | 0 arch/um/include/asm/common.lds.S | 99 ---- arch/um/include/asm/host_ops.h | 9 + arch/um/include/asm/mmu.h | 3 + arch/um/include/asm/mmu_context.h | 8 + arch/um/include/asm/page.h | 15 + arch/um/include/asm/pgtable.h | 27 + arch/um/include/asm/thread_info.h | 24 + arch/um/include/asm/uaccess.h | 6 + arch/um/include/asm/xor.h | 3 +- arch/um/include/shared/as-layout.h | 1 + .../drivers => include/shared}/etap.h | 0 arch/um/include/shared/init.h | 19 +- arch/um/include/shared/os.h | 1 + .../drivers => include/shared}/tuntap.h | 0 arch/um/include/uapi/asm/Kbuild | 2 + arch/um/kernel/Makefile | 13 +- arch/um/kernel/dyn.lds.S | 171 ------- arch/um/kernel/irq.c | 13 + arch/um/kernel/process.c | 14 +- arch/um/kernel/reboot.c | 5 + arch/um/kernel/time.c | 2 + arch/um/kernel/um_arch.c | 16 + arch/um/kernel/uml.lds.S | 115 ----- arch/um/{os-Linux => kernel}/user_syms.c | 0 arch/um/kernel/vmlinux.lds.S | 91 +++- arch/um/nommu/Makefile | 1 + arch/um/nommu/Makefile.um | 22 + arch/um/nommu/include/asm/Kbuild | 6 + arch/um/nommu/include/asm/archparam.h | 1 + arch/um/nommu/include/asm/atomic.h | 11 + arch/um/nommu/include/asm/atomic64.h | 114 +++++ arch/um/nommu/include/asm/bitsperlong.h | 12 + arch/um/nommu/include/asm/byteorder.h | 7 + arch/um/nommu/include/asm/cpu.h | 16 + arch/um/nommu/include/asm/elf.h | 15 + arch/um/nommu/include/asm/mm_context.h | 8 + arch/um/nommu/include/asm/processor.h | 46 ++ arch/um/nommu/include/asm/ptrace.h | 21 + arch/um/nommu/include/asm/sched.h | 23 + arch/um/nommu/include/asm/segment.h | 9 + arch/um/nommu/include/asm/syscall_wrapper.h | 57 +++ arch/um/nommu/include/asm/syscalls.h | 15 + arch/um/nommu/include/uapi/asm/Kbuild | 6 + arch/um/nommu/include/uapi/asm/bitsperlong.h | 11 + arch/um/nommu/include/uapi/asm/byteorder.h | 11 + arch/um/nommu/include/uapi/asm/host_ops.h | 122 +++++ arch/um/nommu/include/uapi/asm/sigcontext.h | 12 + arch/um/nommu/include/uapi/asm/syscalls.h | 287 +++++++++++ arch/um/nommu/include/uapi/asm/unistd.h | 17 + arch/um/nommu/um/Kconfig | 45 ++ arch/um/nommu/um/Makefile | 4 + arch/um/nommu/um/bootmem.c | 87 ++++ arch/um/nommu/um/console.c | 42 ++ arch/um/nommu/um/cpu.c | 247 ++++++++++ arch/um/nommu/um/delay.c | 31 ++ arch/um/nommu/um/setup.c | 179 +++++++ arch/um/nommu/um/shared/sysdep/archsetjmp.h | 13 + arch/um/nommu/um/shared/sysdep/faultinfo.h | 8 + .../nommu/um/shared/sysdep/kernel-offsets.h | 12 + arch/um/nommu/um/shared/sysdep/mcontext.h | 9 + arch/um/nommu/um/shared/sysdep/ptrace.h | 42 ++ arch/um/nommu/um/shared/sysdep/ptrace_user.h | 7 + arch/um/nommu/um/syscalls.c | 199 ++++++++ arch/um/nommu/um/threads.c | 262 ++++++++++ arch/um/nommu/um/unimplemented.c | 70 +++ arch/um/nommu/um/user_constants.h | 13 + arch/um/os-Linux/Makefile | 19 - arch/um/os-Linux/drivers/Makefile | 13 - arch/um/scripts/headers_install.py | 197 ++++++++ arch/x86/um/Makefile | 2 +- arch/x86/um/os-Linux/Makefile | 13 - arch/x86/um/ptrace_32.c | 2 +- arch/x86/um/syscalls_64.c | 2 +- scripts/headers_install.sh | 4 + scripts/link-vmlinux.sh | 42 +- tools/um/.gitignore | 1 + tools/um/Makefile | 81 +++ tools/um/Targets | 13 + tools/um/include/lkl.h | 357 ++++++++++++++ tools/um/include/lkl_host.h | 27 + tools/um/lib/Build | 7 + tools/um/lib/fs.c | 461 ++++++++++++++++++ tools/um/lib/jmp_buf.c | 14 + tools/um/lib/jmp_buf.h | 8 + tools/um/lib/posix-host.c | 293 +++++++++++ tools/um/lib/utils.c | 213 ++++++++ tools/um/tests/Build | 4 + tools/um/tests/boot.c | 393 +++++++++++++++ tools/um/tests/boot.sh | 9 + tools/um/tests/cla.c | 159 ++++++ tools/um/tests/cla.h | 33 ++ tools/um/tests/disk.c | 168 +++++++ tools/um/tests/disk.sh | 70 +++ tools/um/tests/run.py | 174 +++++++ tools/um/tests/tap13.py | 209 ++++++++ tools/um/tests/test.c | 126 +++++ tools/um/tests/test.h | 72 +++ tools/um/tests/test.sh | 181 +++++++ tools/um/uml/Build | 58 +++ tools/um/uml/drivers/Build | 10 + .../um/uml}/drivers/ethertap_user.c | 0 .../um/uml}/drivers/tuntap_user.c | 0 {arch/um/os-Linux => tools/um/uml}/elf_aux.c | 0 {arch/um/os-Linux => tools/um/uml}/execvp.c | 4 - {arch/um/os-Linux => tools/um/uml}/file.c | 0 {arch/um/os-Linux => tools/um/uml}/helper.c | 0 {arch/um/os-Linux => tools/um/uml}/irq.c | 0 {arch/um/os-Linux => tools/um/uml}/main.c | 0 {arch/um/os-Linux => tools/um/uml}/mem.c | 0 tools/um/uml/nommu/Build | 1 + tools/um/uml/nommu/registers.c | 21 + tools/um/uml/nommu/unimplemented.c | 21 + {arch/um/os-Linux => tools/um/uml}/process.c | 2 + .../um/os-Linux => tools/um/uml}/registers.c | 0 {arch/um/os-Linux => tools/um/uml}/sigio.c | 0 {arch/um/os-Linux => tools/um/uml}/signal.c | 12 +- .../skas/Makefile => tools/um/uml/skas/Build | 6 +- {arch/um/os-Linux => tools/um/uml}/skas/mem.c | 0 .../os-Linux => tools/um/uml}/skas/process.c | 3 +- {arch/um/os-Linux => tools/um/uml}/start_up.c | 0 {arch/um/os-Linux => tools/um/uml}/time.c | 0 {arch/um/os-Linux => tools/um/uml}/tty.c | 0 {arch/um/os-Linux => tools/um/uml}/umid.c | 0 {arch/um/os-Linux => tools/um/uml}/util.c | 26 + tools/um/uml/x86/Build | 11 + .../os-Linux => tools/um/uml/x86}/mcontext.c | 0 .../um/os-Linux => tools/um/uml/x86}/prctl.c | 0 .../os-Linux => tools/um/uml/x86}/registers.c | 0 .../os-Linux => tools/um/uml/x86}/task_size.c | 0 .../um/os-Linux => tools/um/uml/x86}/tls.c | 0 135 files changed, 5870 insertions(+), 523 deletions(-)rename
arch/um/{os-Linux=>}/drivers/ethertap_kern.c(100%) renamearch/um/{os-Linux=>}/drivers/tuntap_kern.c(100%) delete mode 100644arch/um/include/asm/common.lds.S
create mode 100644arch/um/include/asm/host_ops.h
renamearch/um/{os-Linux/drivers=>include/shared}/etap.h(100%) renamearch/um/{os-Linux/drivers=>include/shared}/tuntap.h(100%) create mode 100644arch/um/include/uapi/asm/Kbuild
delete mode 100644arch/um/kernel/dyn.lds.S
delete mode 100644arch/um/kernel/uml.lds.S
renamearch/um/{os-Linux=>kernel}/user_syms.c(100%) create mode 100644arch/um/nommu/Makefile
create mode 100644arch/um/nommu/Makefile.um
create mode 100644arch/um/nommu/include/asm/Kbuild
create mode 100644arch/um/nommu/include/asm/archparam.hcreate mode 100644arch/um/nommu/include/asm/atomic.h
create mode 100644arch/um/nommu/include/asm/atomic64.hcreate mode 100644arch/um/nommu/include/asm/bitsperlong.hcreate mode 100644arch/um/nommu/include/asm/byteorder.hcreate mode 100644arch/um/nommu/include/asm/cpu.h
create mode 100644arch/um/nommu/include/asm/elf.h
create mode 100644arch/um/nommu/include/asm/mm_context.hcreate mode 100644arch/um/nommu/include/asm/processor.hcreate mode 100644arch/um/nommu/include/asm/ptrace.h
create mode 100644arch/um/nommu/include/asm/sched.h
create mode 100644arch/um/nommu/include/asm/segment.hcreate mode 100644arch/um/nommu/include/asm/syscall_wrapper.hcreate mode 100644arch/um/nommu/include/asm/syscalls.hcreate mode 100644arch/um/nommu/include/uapi/asm/Kbuildcreate mode 100644arch/um/nommu/include/uapi/asm/bitsperlong.hcreate mode 100644arch/um/nommu/include/uapi/asm/byteorder.hcreate mode 100644arch/um/nommu/include/uapi/asm/host_ops.hcreate mode 100644arch/um/nommu/include/uapi/asm/sigcontext.hcreate mode 100644arch/um/nommu/include/uapi/asm/syscalls.hcreate mode 100644arch/um/nommu/include/uapi/asm/unistd.hcreate mode 100644arch/um/nommu/um/Kconfig
create mode 100644arch/um/nommu/um/Makefile
create mode 100644arch/um/nommu/um/bootmem.c
create mode 100644arch/um/nommu/um/console.c
create mode 100644arch/um/nommu/um/cpu.c
create mode 100644arch/um/nommu/um/delay.c
create mode 100644arch/um/nommu/um/setup.c
create mode 100644arch/um/nommu/um/shared/sysdep/archsetjmp.hcreate mode 100644arch/um/nommu/um/shared/sysdep/faultinfo.hcreate mode 100644arch/um/nommu/um/shared/sysdep/kernel-offsets.hcreate mode 100644arch/um/nommu/um/shared/sysdep/mcontext.hcreate mode 100644arch/um/nommu/um/shared/sysdep/ptrace.hcreate mode 100644arch/um/nommu/um/shared/sysdep/ptrace_user.hcreate mode 100644arch/um/nommu/um/syscalls.c
create mode 100644arch/um/nommu/um/threads.c
create mode 100644arch/um/nommu/um/unimplemented.c
create mode 100644arch/um/nommu/um/user_constants.h
delete mode 100644arch/um/os-Linux/Makefile
delete mode 100644arch/um/os-Linux/drivers/Makefile
create mode 100755arch/um/scripts/headers_install.py
delete mode 100644arch/x86/um/os-Linux/Makefile
create mode 100644tools/um/.gitignore
create mode 100644tools/um/Makefile
create mode 100644tools/um/Targets
create mode 100644tools/um/include/lkl.h
create mode 100644tools/um/include/lkl_host.h
create mode 100644tools/um/lib/Build
create mode 100644tools/um/lib/fs.c
create mode 100644tools/um/lib/jmp_buf.c
create mode 100644tools/um/lib/jmp_buf.h
create mode 100644tools/um/lib/posix-host.c
create mode 100644tools/um/lib/utils.c
create mode 100644tools/um/tests/Build
create mode 100644tools/um/tests/boot.c
create mode 100755tools/um/tests/boot.sh
create mode 100644tools/um/tests/cla.c
create mode 100644tools/um/tests/cla.h
create mode 100644tools/um/tests/disk.c
create mode 100755tools/um/tests/disk.sh
create mode 100755tools/um/tests/run.py
create mode 100644tools/um/tests/tap13.py
create mode 100644tools/um/tests/test.c
create mode 100644tools/um/tests/test.h
create mode 100644tools/um/tests/test.sh
create mode 100644tools/um/uml/Build
create mode 100644tools/um/uml/drivers/Build
rename {arch/um/os-Linux=>tools/um/uml}/drivers/ethertap_user.c(100%) rename {arch/um/os-Linux=>tools/um/uml}/drivers/tuntap_user.c(100%) rename {arch/um/os-Linux=>tools/um/uml}/elf_aux.c(100%) rename {arch/um/os-Linux=>tools/um/uml}/execvp.c(98%) rename {arch/um/os-Linux=>tools/um/uml}/file.c(100%) rename {arch/um/os-Linux=>tools/um/uml}/helper.c(100%) rename {arch/um/os-Linux=>tools/um/uml}/irq.c(100%) rename {arch/um/os-Linux=>tools/um/uml}/main.c(100%) rename {arch/um/os-Linux=>tools/um/uml}/mem.c(100%) create mode 100644tools/um/uml/nommu/Build
create mode 100644tools/um/uml/nommu/registers.c
create mode 100644tools/um/uml/nommu/unimplemented.c
rename {arch/um/os-Linux=>tools/um/uml}/process.c(99%) rename {arch/um/os-Linux=>tools/um/uml}/registers.c(100%) rename {arch/um/os-Linux=>tools/um/uml}/sigio.c(100%) rename {arch/um/os-Linux=>tools/um/uml}/signal.c(96%) renamearch/um/os-Linux/skas/Makefile=>tools/um/uml/skas/Build(56%) rename {arch/um/os-Linux=>tools/um/uml}/skas/mem.c(100%) rename {arch/um/os-Linux=>tools/um/uml}/skas/process.c(99%) rename {arch/um/os-Linux=>tools/um/uml}/start_up.c(100%) rename {arch/um/os-Linux=>tools/um/uml}/time.c(100%) rename {arch/um/os-Linux=>tools/um/uml}/tty.c(100%) rename {arch/um/os-Linux=>tools/um/uml}/umid.c(100%) rename {arch/um/os-Linux=>tools/um/uml}/util.c(89%) create mode 100644tools/um/uml/x86/Build
rename {arch/x86/um/os-Linux=>tools/um/uml/x86}/mcontext.c(100%) rename {arch/x86/um/os-Linux=>tools/um/uml/x86}/prctl.c(100%) rename {arch/x86/um/os-Linux=>tools/um/uml/x86}/registers.c(100%) rename {arch/x86/um/os-Linux=>tools/um/uml/x86}/task_size.c(100%) rename {arch/x86/um/os-Linux=>tools/um/uml/x86}/tls.c(100%)
Signature · 3 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/
Anton Ivanov
maintainerRe: [RFC v7 21/21] um: nommu: add block device support of UML
In reply to Hajime TazakiQuoted 126 lines · Hajime Tazaki
This commit adds block device support for nommu mode, and also added several host utilities to run a simple test program (
tools/um/test/disk.c) successfully.Signed-off-by Hajime Tazaki <[email protected]>--- arch/um/include/asm/xor.h | 3 +- arch/um/include/shared/as-layout.h | 1 + arch/um/kernel/um_arch.c | 5 + arch/um/nommu/include/uapi/asm/host_ops.h | 7 + arch/um/nommu/include/uapi/asm/unistd.h | 2 + arch/um/nommu/um/Kconfig | 8 + arch/um/nommu/um/setup.c | 12 + tools/um/Targets | 2 + tools/um/include/lkl.h | 206 ++++++++++ tools/um/include/lkl_host.h | 1 + tools/um/lib/Build | 1 + tools/um/lib/fs.c | 461 ++++++++++++++++++++++ tools/um/lib/posix-host.c | 1 + tools/um/lib/utils.c | 3 + tools/um/tests/Build | 1 + tools/um/tests/cla.c | 159 ++++++++ tools/um/tests/cla.h | 33 ++ tools/um/tests/disk.c | 168 ++++++++ tools/um/tests/disk.sh | 70 ++++ tools/um/tests/run.py | 2 + 20 files changed, 1145 insertions(+), 1 deletion(-)create mode 100644
tools/um/lib/fs.c
create mode 100644tools/um/tests/cla.c
create mode 100644tools/um/tests/cla.h
create mode 100644tools/um/tests/disk.c
create mode 100755tools/um/tests/disk.sharch/um/include/asm/xor.h +2
-1@@ -4,4 +4,5 @@/* pick an arbitrary one - measuring isn't possible with inf-cpu */ #define XOR_SELECT_TEMPLATE (x) \ - (time_travel_mode == TT_MODE_INFCPU ? &xor_block_8regs : NULL) + (time_travel_mode == TT_MODE_INFCPU || (!IS_ENABLED(CONFIG_MMU)) ? \ + &xor_block_8regs : NULL)arch/um/include/shared/as-layout.h +1
-0@@ -57,6 +57,7 @@ extern unsigned long host_task_size;extern int linux_main (int argc,char **argv);extern void uml_finishsetup (void ); +extern void uml_set_args (char *args);struct siginfo ;extern void (*sig_info[])(int ,struct siginfo *si,struct uml_pt_regs *);arch/um/kernel/um_arch.c +5
-0@@ -41,6 +41,11 @@ static void __init add_arg(char *arg)strcat (command_line, arg); } +void __init uml_set_args (char *args) +{ +strcat (command_line, args); +} +/* * These fields are initialized at boot time and not changed. * XXX This structure is used only in the non-SMP case. Maybe this arch/um/nommu/include/uapi/asm/host_ops.h +7
-0@@ -15,6 +15,11 @@ struct lkl_jmp_buf {* * These operations must be provided by a host library or by the application * itself. +* +* @um_devices - string containg the list of UML devices in command line +* format. This string is appended to the kernel command line and +* is provided here for convenience to be implemented by the host library. +* * @print - optional operation that receives console messages * @panic - called during a kernel panic * @@ -65,6 +70,8 @@ struct lkl_jmp_buf {* */ struct lkl_host_operations { +const char *um_devices; +void (*print)(const char *str,int len);void (*panic)(void );arch/um/nommu/include/uapi/asm/unistd.h +2
-0@@ -3,6 +3,8 @@#define __UM_NOMMU_UAPI_UNISTD_H#define __ARCH_WANT_NEW_STAT +#define __ARCH_WANT_SET_GET_RLIMIT +#include <asm/bitsperlong.h> #if __BITS_PER_LONG ==64 arch/um/nommu/um/Kconfig +4
-0@@ -4,6 +4,10 @@ config UML_NOMMU select UACCESS_MEMCPY select ARCH_THREAD_STACK_ALLOCATOR select ARCH_HAS_SYSCALL_WRAPPER + select VFAT_FS + select NLS_CODEPAGE_437 + select NLS_ISO8859_1 + select BTRFS_FS config 64BIT bool
arch/um/nommu/um/Kconfig config STACKTRACE_SUPPORT · line 45
Quoted 7 lines
arch/um/nommu/um/Kconfig +4
-0@@ -35,3 +39,7 @@ config STACKTRACE_SUPPORT config PRINTK_TIME bool default y + +config RAID6_PQ_BENCHMARK + bool + default n
Why are we touching this? I thought this is already defined in lib/Kconfig?
Brgds,
A.
Quoted 1,268 lines
arch/um/nommu/um/setup.c +12
-0@@ -45,13 +45,25 @@ static void __init *lkl_run_kernel(void *arg)return NULL ; } +static char _cmd_line[COMMAND_LINE_SIZE ];int __init lkl_start_kernel (struct lkl_host_operations *ops,const char *fmt, ...) { +va_list ap;int ret; lkl_ops = ops; +va_start (ap, fmt); + ret =vsnprintf (_cmd_line,COMMAND_LINE_SIZE , fmt, ap); +va_end (ap); + +if (ops->um_devices) +strscpy (_cmd_line + ret, ops->um_devices, +COMMAND_LINE_SIZE - ret); + +uml_set_args (_cmd_line); + init_sem = lkl_ops->sem_alloc (0 );if (!init_sem)return -ENOMEM ;tools/um/Targets +2
-0@@ -1,10 +1,12 @@ ifeq ($(UMMODE),library) progs-y += tests/boot +progs-y += tests/disk else progs-y += uml/linux endif LDFLAGS_boot-y := -pie +LDFLAGS_disk-y := -pie LDLIBS := -lrt -lpthread -lutil LDFLAGS_linux-y := -no-pie -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloctools/um/include/lkl.h +206
-0@@ -113,6 +113,16 @@ static inline long lkl_sys_creat(const char *file, int mode) }#endif +#ifdef __lkl__NR_faccessat +/** +* lkl_sys_access - wrapper for lkl_sys_faccessat +*/ +static inline long lkl_sys_access (const char *file,int mode) +{ +return lkl_sys_faccessat (LKL_AT_FDCWD , file, mode); +} +#endif +#ifdef __lkl__NR_mkdirat/** * lkl_sys_mkdir - wrapper for lkl_sys_mkdirat @@ -123,6 +133,36 @@ static inline long lkl_sys_mkdir(const char *path, mode_t mode) }#endif +#ifdef __lkl__NR_unlinkat +/** +* lkl_sys_rmdir - wrapper for lkl_sys_unlinkrat +*/ +static inline long lkl_sys_rmdir (const char *path) +{ +return lkl_sys_unlinkat (LKL_AT_FDCWD , path,LKL_AT_REMOVEDIR ); +} +#endif + +#ifdef __lkl__NR_unlinkat +/** +* lkl_sys_unlink - wrapper for lkl_sys_unlinkat +*/ +static inline long lkl_sys_unlink (const char *path) +{ +return lkl_sys_unlinkat (LKL_AT_FDCWD , path,0 ); +} +#endif + +#ifdef __lkl__NR_mknodat +/** +* lkl_sys_mknod - wrapper for lkl_sys_mknodat +*/ +static inline long lkl_sys_mknod (const char *path,mode_t mode,dev_t dev) +{ +return lkl_sys_mknodat (LKL_AT_FDCWD , path, mode, dev); +} +#endif +#ifdef __lkl__NR_epoll_create1/** * lkl_sys_epoll_create - wrapper for lkl_sys_epoll_create1 @@ -144,6 +184,172 @@ static inline long lkl_sys_epoll_wait(int fd, struct lkl_epoll_event *ev, }#endif +/** +* struct lkl_dev_blk_ops - block device host operations, defined in lkl_host.h. +*/ +struct lkl_dev_blk_ops ; + +/** +* lkl_disk - host disk handle +* +* @dev - a pointer to private information for this disk backend +* @fd - a POSIX file descriptor that can be used by preadv/pwritev +* @handle - an NT file handle that can be used by ReadFile/WriteFile +*/ +struct lkl_disk { +void *dev; +union { +int fd; +void *handle; + }; +struct lkl_dev_blk_ops *ops; +}; + +/** +* lkl_disk_add - add a new disk +* +* @disk - the host disk handle +* @returns a disk id (0 is valid) or a strictly negative value in case of error +*/ +int lkl_disk_add (struct lkl_disk *disk); + +/** +* lkl_disk_remove - remove a disk +* +* This function makes a cleanup of the @disk's private information +* that was initialized by lkl_disk_add before. +* +* @disk - the host disk handle +*/ +int lkl_disk_remove (struct lkl_disk disk); + +/** +* lkl_encode_dev_from_sysfs_blkdev - extract device id from sysfs +* +* This function returns the device id for the given sysfs dev node. +* The content of the node has to be in the form 'MAJOR:MINOR'. +* Also, this function expects an absolute path which means that sysfs +* already has to be mounted at the given path +* +* @sysfs_path - absolute path to the sysfs dev node +* @pdevid - pointer to memory where dev id will be returned +* @returns - 0 on success, a negative value on error +*/ +int lkl_encode_dev_from_sysfs (const char *sysfs_path,uint32_t *pdevid); + +/** +* lkl_mount_dev - mount a disk +* +* This functions creates a device file for the given disk, creates a mount +* point and mounts the device over the mount point. +* +* @disk_id - the disk id identifying the disk to be mounted +* @part - disk partition or zero for full disk +* @fs_type - filesystem type +* @flags - mount flags +* @opts - additional filesystem specific mount options +* @mnt_str - a string that will be filled by this function with the path where +* the filesystem has been mounted +* @mnt_str_len - size of mnt_str +* @returns - 0 on success, a negative value on error +*/ +long lkl_mount_dev (unsigned int disk_id,unsigned int part,const char *fs_type, +int flags,const char *opts, +char *mnt_str,unsigned int mnt_str_len); + +/** +* lkl_umount_dev - umount a disk +* +* This functions umounts the given disks and removes the device file and the +* mount point. +* +* @disk_id - the disk id identifying the disk to be mounted +* @part - disk partition or zero for full disk +* @flags - umount flags +* @timeout_ms - timeout to wait for the kernel to flush closed files so that +* umount can succeed +* @returns - 0 on success, a negative value on error +*/ +long lkl_umount_dev (unsigned int disk_id,unsigned int part,int flags, +long timeout_ms); + +/** +* lkl_umount_timeout - umount filesystem with timeout +* +* @path - the path to unmount +* @flags - umount flags +* @timeout_ms - timeout to wait for the kernel to flush closed files so that +* umount can succeed +* @returns - 0 on success, a negative value on error +*/ +long lkl_umount_timeout (char *path,int flags,long timeout_ms); + +/** +* lkl_opendir - open a directory +* +* @path - directory path +* @err - pointer to store the error in case of failure +* @returns - a handle to be used when calling lkl_readdir +*/ +struct lkl_dir *lkl_opendir (const char *path,int *err); + +/** +* lkl_fdopendir - open a directory +* +* @fd - file descriptor +* @err - pointer to store the error in case of failure +* @returns - a handle to be used when calling lkl_readdir +*/ +struct lkl_dir *lkl_fdopendir (int fd,int *err); + +/** +* lkl_rewinddir - reset directory stream +* +* @dir - the directory handler as returned by lkl_opendir +*/ +void lkl_rewinddir (struct lkl_dir *dir); + +/** +* lkl_closedir - close the directory +* +* @dir - the directory handler as returned by lkl_opendir +*/ +int lkl_closedir (struct lkl_dir *dir); + +/** +* lkl_readdir - get the next available entry of the directory +* +* @dir - the directory handler as returned by lkl_opendir +* @returns - a lkl_dirent64 entry or NULL if the end of the directory stream is +* reached or if an error occurred; check lkl_errdir() to distinguish between +* errors or end of the directory stream +*/ +struct lkl_linux_dirent64 *lkl_readdir (struct lkl_dir *dir); + +/** +* lkl_errdir - checks if an error occurred during the last lkl_readdir call +* +* @dir - the directory handler as returned by lkl_opendir +* @returns - 0 if no error occurred, or a negative value otherwise +*/ +int lkl_errdir (struct lkl_dir *dir); + +/** +* lkl_dirfd - gets the file descriptor associated with the directory handle +* +* @dir - the directory handle as returned by lkl_opendir +* @returns - a positive value,which is the LKL file descriptor associated with +* the directory handle, or a negative value otherwise +*/ +int lkl_dirfd (struct lkl_dir *dir); + +/** +* lkl_mount_fs - mount a file system type like proc, sys +* @fstype - file system type. e.g. proc, sys +* @returns - 0 on success. 1 if it's already mounted. negative on failure. +*/ +int lkl_mount_fs (char *fstype); +#ifdef __cplusplus }#endif tools/um/include/lkl_host.h +1
-0@@ -10,6 +10,7 @@ extern "C" {#include <lkl.h> extern struct lkl_host_operations lkl_host_ops; +extern char lkl_um_devs[4096 ];/** * lkl_printf - print a message via the host print operation tools/um/lib/Build +1
-0@@ -4,3 +4,4 @@ CFLAGS_posix-host.o += -D_FILE_OFFSET_BITS=64 liblinux-$(CONFIG_UMMODE_LIB) += utils.o liblinux-$(CONFIG_UMMODE_LIB) += posix-host.o liblinux-$(CONFIG_UMMODE_LIB) += jmp_buf.o +liblinux-$(CONFIG_UMMODE_LIB) += fs.otools/um/lib/fs.c new file +461
-0@@ -0,0 +1,461 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <stdarg.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <lkl_host.h> + +#define MAX_FSTYPE_LEN 50 + +static struct lkl_disk *lkl_disks[16 ]; +static int registered_blk_dev_idx; + +static int lkl_disk_um_add (struct lkl_disk *disk,const char *blkparams) +{ +/* concat strings */ +snprintf (lkl_um_devs +strlen (lkl_um_devs),sizeof (lkl_um_devs), +" ubd%d=%s" , registered_blk_dev_idx, blkparams); + +return registered_blk_dev_idx++; +} + +int lkl_disk_add (struct lkl_disk *disk) +{ +int ret =-1 ; + + ret =lkl_disk_um_add (disk, disk->dev); + + lkl_disks[ret] = disk; + +return ret; +} + +int lkl_disk_remove (struct lkl_disk disk) +{ +/* FIXME */ +return 0 ; +} + +int lkl_mount_fs (char *fstype) +{ +char dir[MAX_FSTYPE_LEN +2 ] ="/" ; +int flags =0 , ret =0 ; + +strncat (dir, fstype,MAX_FSTYPE_LEN ); + +/* Create with regular umask */ + ret =lkl_sys_mkdir (dir,0xff ); +if (ret && ret != -LKL_EEXIST ) { +lkl_perror ("mount_fs mkdir" , ret); +return ret; + } + +/* We have no use for nonzero flags right now */ + ret =lkl_sys_mount ("none" , dir, fstype, flags,NULL ); +if (ret && ret != -LKL_EBUSY ) { +lkl_sys_rmdir (dir); +return ret; + } + +if (ret == -LKL_EBUSY ) +return 1 ; +return 0 ; +} + +static uint32_t new_encode_dev (unsigned int major,unsigned int minor) +{ +return (minor &0xff ) | (major <<8 ) | ((minor & ~0xff ) <<12 ); +} + +static int startswith (const char *str,const char *pre) +{ +return strncmp (pre, str,strlen (pre)) ==0 ; +} + +static int get_node_with_prefix (const char *path,const char *prefix, +char *result,unsigned int result_len) +{ +struct lkl_dir *dir =NULL ; +struct lkl_linux_dirent64 *dirent; +int ret; + + dir =lkl_opendir (path, &ret); +if (!dir) +return ret; + + ret = -LKL_ENOENT ; + +while ((dirent =lkl_readdir (dir))) { +if (startswith (dirent->d_name, prefix)) { +if (strlen (dirent->d_name) +1 > result_len) { + ret = -LKL_ENOMEM ; +break ; + } +memcpy (result, dirent->d_name,strlen (dirent->d_name)); + result[strlen (dirent->d_name)] ='\0' ; + ret =0 ; +break ; + } + } + +lkl_closedir (dir); + +return ret; +} + +int lkl_encode_dev_from_sysfs (const char *sysfs_path,uint32_t *pdevid) +{ +int ret; +long fd; +int major, minor; +char buf[16 ] = {0 , }; +char *bufptr; + + fd =lkl_sys_open (sysfs_path,LKL_O_RDONLY ,0 ); +if (fd <0 ) +return fd; + + ret =lkl_sys_read (fd, buf,sizeof (buf)); +if (ret <0 ) + goto out_close; + +if (ret ==sizeof (buf)) { + ret = -LKL_ENOBUFS ; + goto out_close; + } + + bufptr =strchr (buf,':' ); +if (bufptr ==NULL ) { + ret = -LKL_EINVAL ; + goto out_close; + } + bufptr[0 ] ='\0' ; + bufptr++; + + major =atoi (buf); + minor =atoi (bufptr); + + *pdevid =new_encode_dev (major, minor); + ret =0 ; + +out_close: +lkl_sys_close (fd); + +return ret; +} + +#define SYSFS_DEV_UMBLK_CMDLINE_PATH \ + "/sysfs/devices/platform/uml-blkdev.%d" + +struct abuf { +char *mem, *ptr; +unsigned int len; +}; + +static int snprintf_append (struct abuf *buf,const char *fmt, ...) +{ +int ret; +va_list args; + +if (!buf->ptr) + buf->ptr = buf->mem; + +va_start (args, fmt); + ret =vsnprintf (buf->ptr, buf->len - (buf->ptr - buf->mem), fmt, args); +va_end (args); + +if (ret <0 || (ret >= (int )(buf->len - (buf->ptr - buf->mem)))) +return -LKL_ENOMEM ; + + buf->ptr += ret; + +return 0 ; +} + +static int __lkl_get_blkdev (int disk_id,unsigned int part,uint32_t *pdevid, +const char *sysfs_path_fmt,const char *drv_prefix, +const char *disk_prefix) +{ +char sysfs_path[LKL_PATH_MAX ]; +char drv_name[LKL_PATH_MAX ]; +char disk_name[LKL_PATH_MAX ]; +struct abuf sysfs_path_buf = { + .mem = sysfs_path, + .len =sizeof (sysfs_path), + }; +int ret; + +if (disk_id <0 ) +return -LKL_EINVAL ; + + ret =lkl_mount_fs ("sysfs" ); +if (ret <0 ) +return ret; + + ret =snprintf_append (&sysfs_path_buf, sysfs_path_fmt, disk_id); +if (ret) +return ret; + + ret =get_node_with_prefix (sysfs_path, drv_prefix, drv_name, +sizeof (drv_name)); +if (ret) +return ret; + + ret =snprintf_append (&sysfs_path_buf,"/%s/block" , drv_name); +if (ret) +return ret; + + ret =get_node_with_prefix (sysfs_path, disk_prefix, disk_name, +sizeof (disk_name)); +if (ret) +return ret; + +if (!part) + ret =snprintf_append (&sysfs_path_buf,"/%s/dev" , disk_name); +else + ret =snprintf_append (&sysfs_path_buf,"/%s/%s%d/dev" , + disk_name, disk_name, part); +if (ret) +return ret; + +return lkl_encode_dev_from_sysfs (sysfs_path, pdevid); +} + +int lkl_get_blkdev (int disk_id,unsigned int part,uint32_t *pdevid) +{ +char *fmt; + + fmt =SYSFS_DEV_UMBLK_CMDLINE_PATH ; +return __lkl_get_blkdev (disk_id, part, pdevid, fmt,"" ,"ubd" ); +} + +long lkl_mount_dev (unsigned int disk_id,unsigned int part, +const char *fs_type,int flags, +const char *data,char *mnt_str,unsigned int mnt_str_len) +{ +char dev_str[] = {"/dev/xxxxxxxx" }; +unsigned int dev; +int err; +char _data[4096 ];/* FIXME: PAGE_SIZE is not exported by LKL */ + +if (mnt_str_len <sizeof (dev_str)) +return -LKL_ENOMEM ; + + err =lkl_get_blkdev (disk_id, part, &dev); +if (err <0 ) +return err; + +snprintf (dev_str,sizeof (dev_str),"/dev/%08x" , dev); +snprintf (mnt_str, mnt_str_len,"/mnt/%08x" , dev); + + err =lkl_sys_access ("/dev" ,LKL_S_IRWXO ); +if (err <0 ) { +if (err == -LKL_ENOENT ) + err =lkl_sys_mkdir ("/dev" ,0700 ); +if (err <0 ) +return err; + } + + err =lkl_sys_mknod (dev_str,LKL_S_IFBLK |0600 , dev); +if (err <0 ) +return err; + + err =lkl_sys_access ("/mnt" ,LKL_S_IRWXO ); +if (err <0 ) { +if (err == -LKL_ENOENT ) + err =lkl_sys_mkdir ("/mnt" ,0700 ); +if (err <0 ) +return err; + } + + err =lkl_sys_mkdir (mnt_str,0700 ); +if (err <0 ) { +lkl_sys_unlink (dev_str); +return err; + } + +/* kernel always copies a full page */ +if (data) { +strncpy (_data, data,sizeof (_data)); + _data[sizeof (_data) -1 ] =0 ; + }else { + _data[0 ] =0 ; + } + + err =lkl_sys_mount (dev_str, mnt_str, (char *)fs_type, flags, _data); +if (err <0 ) { +lkl_sys_unlink (dev_str); +lkl_sys_rmdir (mnt_str); +return err; + } + +return 0 ; +} + +long lkl_umount_timeout (char *path,int flags,long timeout_ms) +{ +long incr =10000000 ;/* 10 ms */ +struct lkl_timespec ts = { + .tv_sec =0 , + .tv_nsec = incr, + }; +long err; + +do { + err =lkl_sys_umount (path, flags); +if (err == -LKL_EBUSY ) { +lkl_sys_nanosleep ((struct __lkl__kernel_timespec *)&ts, +NULL ); + timeout_ms -= incr /1000000 ; + } + }while (err == -LKL_EBUSY && timeout_ms >0 ); + +return err; +} + +long lkl_umount_dev (unsigned int disk_id,unsigned int part,int flags, +long timeout_ms) +{ +char dev_str[] = {"/dev/xxxxxxxx" }; +char mnt_str[] = {"/mnt/xxxxxxxx" }; +unsigned int dev; +int err; + + err =lkl_get_blkdev (disk_id, part, &dev); +if (err <0 ) +return err; + +snprintf (dev_str,sizeof (dev_str),"/dev/%08x" , dev); +snprintf (mnt_str,sizeof (mnt_str),"/mnt/%08x" , dev); + + err =lkl_umount_timeout (mnt_str, flags, timeout_ms); +if (err) +return err; + + err =lkl_sys_unlink (dev_str); +if (err) +return err; + +return lkl_sys_rmdir (mnt_str); +} + +struct lkl_dir { +int fd; +char buf[1024 ]; +char *pos; +int len; +}; + +static struct lkl_dir *lkl_dir_alloc (int *err) +{ +struct lkl_dir *dir = lkl_host_ops.mem_alloc (sizeof (struct lkl_dir )); + +if (!dir) { + *err = -LKL_ENOMEM ; +return NULL ; + } + + dir->len =0 ; + dir->pos =NULL ; + +return dir; +} + +struct lkl_dir *lkl_opendir (const char *path,int *err) +{ +struct lkl_dir *dir =lkl_dir_alloc (err); + +if (!dir) { + *err = -LKL_ENOMEM ; +return NULL ; + } + + dir->fd =lkl_sys_open (path,LKL_O_RDONLY |LKL_O_DIRECTORY ,0 ); +if (dir->fd <0 ) { + *err = dir->fd; + lkl_host_ops.mem_free (dir); +return NULL ; + } + + *err =0 ; + +return dir; +} + +struct lkl_dir *lkl_fdopendir (int fd,int *err) +{ +struct lkl_dir *dir =lkl_dir_alloc (err); + +if (!dir) +return NULL ; + + dir->fd = fd; + +return dir; +} + +void lkl_rewinddir (struct lkl_dir *dir) +{ +lkl_sys_lseek (dir->fd,0 ,LKL_SEEK_SET ); + dir->len =0 ; + dir->pos =NULL ; +} + +int lkl_closedir (struct lkl_dir *dir) +{ +int ret; + + ret =lkl_sys_close (dir->fd); + lkl_host_ops.mem_free (dir); + +return ret; +} + +struct lkl_linux_dirent64 *lkl_readdir (struct lkl_dir *dir) +{ +struct lkl_linux_dirent64 *de; + +if (dir->len <0 ) +return NULL ; + +if (!dir->pos || dir->pos - dir->buf >= dir->len) + goto read_buf; + +return_de: + de = (struct lkl_linux_dirent64 *)dir->pos; + dir->pos += de->d_reclen; + +return de; + +read_buf: + dir->pos =NULL ; + de = (struct lkl_linux_dirent64 *)dir->buf; + dir->len =lkl_sys_getdents64 (dir->fd, de,sizeof (dir->buf)); +if (dir->len <=0 ) +return NULL ; + + dir->pos = dir->buf; + goto return_de; +} + +int lkl_errdir (struct lkl_dir *dir) +{ +if (dir->len >=0 ) +return 0 ; + +return dir->len; +} + +int lkl_dirfd (struct lkl_dir *dir) +{ +return dir->fd; +} + +int lkl_set_fd_limit (unsigned int fd_limit) +{ +struct lkl_rlimit rlim = { + .rlim_cur = fd_limit, + .rlim_max = fd_limit, + }; +return lkl_sys_setrlimit (LKL_RLIMIT_NOFILE , &rlim); +}tools/um/lib/posix-host.c +1
-0@@ -263,6 +263,7 @@ static void *tls_get(struct lkl_tls_key *key) }struct lkl_host_operations lkl_host_ops = { + .um_devices = lkl_um_devs, .panic = panic, .print = print, .mem_alloc = (void *)malloc,tools/um/lib/utils.c +3
-0@@ -4,6 +4,9 @@#include <string.h> #include <lkl_host.h> +/* XXX: find a better place */ +char lkl_um_devs[4096 ]; +static const char *const lkl_err_strings[] = {"Success" ,"Operation not permitted" ,tools/um/tests/Build +1
-0@@ -1,3 +1,4 @@ boot-y += boot.o test.o +disk-y += disk.o test.o cla.o CFLAGS_test.o += -Wno-implicit-fallthroughtools/um/tests/cla.c new file +159
-0@@ -0,0 +1,159 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <stdlib.h> +#ifdef __MINGW32__ +#include <winsock2.h> +#else +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#endif + +#include "cla.h" + +static int cl_arg_parse_bool (struct cl_arg *arg,const char *value) +{ + *((int *)arg->store) =1 ; +return 0 ; +} + +static int cl_arg_parse_str (struct cl_arg *arg,const char *value) +{ + *((const char **)arg->store) = value; +return 0 ; +} + +static int cl_arg_parse_int (struct cl_arg *arg,const char *value) +{ + errno =0 ; + *((int *)arg->store) =strtol (value,NULL ,0 ); +return errno ==0 ; +} + +static int cl_arg_parse_str_set (struct cl_arg *arg,const char *value) +{ +const char **set = arg->set; +int i; + +for (i =0 ; set[i] !=NULL ; i++) { +if (strcmp (set[i], value) ==0 ) { + *((int *)arg->store) = i; +return 0 ; + } + } + +return (-1 ); +} + +static int cl_arg_parse_ipv4 (struct cl_arg *arg,const char *value) +{ +unsigned int addr; + +if (!value) +return (-1 ); + + addr =inet_addr (value); +if (addr ==INADDR_NONE ) +return (-1 ); + *((unsigned int *)arg->store) = addr; +return 0 ; +} + +static cl_arg_parser_t parsers[] = { + [CL_ARG_BOOL ] = cl_arg_parse_bool, + [CL_ARG_INT ] = cl_arg_parse_int, + [CL_ARG_STR ] = cl_arg_parse_str, + [CL_ARG_STR_SET ] = cl_arg_parse_str_set, + [CL_ARG_IPV4 ] = cl_arg_parse_ipv4, +}; + +static struct cl_arg *find_short_arg (char name,struct cl_arg *args) +{ +struct cl_arg *arg; + +for (arg = args; arg->short_name !=0 ; arg++) { +if (arg->short_name == name) +return arg; + } + +return NULL ; +} + +static struct cl_arg *find_long_arg (const char *name,struct cl_arg *args) +{ +struct cl_arg *arg; + +for (arg = args; arg->long_name; arg++) { +if (strcmp (arg->long_name, name) ==0 ) +return arg; + } + +return NULL ; +} + +static void print_help (struct cl_arg *args) +{ +struct cl_arg *arg; + +fprintf (stderr,"usage:\n" ); +for (arg = args; arg->long_name; arg++) { +fprintf (stderr,"-%c, --%-20s %s" , arg->short_name, + arg->long_name, arg->help); +if (arg->type ==CL_ARG_STR_SET ) { +const char **set = arg->set; + +fprintf (stderr," [ " ); +while (*set !=NULL ) +fprintf (stderr,"%s " , *(set++)); +fprintf (stderr,"]" ); + } +fprintf (stderr,"\n" ); + } +} + +int cla_parse_args (int argc,const char **argv,struct cl_arg *args) +{ +int i; + +for (i =1 ; i < argc; i++) { +struct cl_arg *arg =NULL ; +cl_arg_parser_t parser; + +if (argv[i][0 ] =='-' ) { +if (argv[i][1 ] !='-' ) + arg =find_short_arg (argv[i][1 ], args); +else + arg =find_long_arg (&argv[i][2 ], args); + } + +if (!arg) { +fprintf (stderr,"unknown option '%s'\n" , argv[i]); +print_help (args); +return (-1 ); + } + +if (arg->type ==CL_ARG_USER || arg->type >=CL_ARG_END ) + parser = arg->parser; +else + parser = parsers[arg->type]; + +if (!parser) { +fprintf (stderr,"can't parse --'%s'/-'%c'\n" , + arg->long_name, args->short_name); +return (-1 ); + } + +if (parser (arg, argv[i +1 ]) <0 ) { +fprintf (stderr,"can't parse '%s'\n" , argv[i]); +print_help (args); +return (-1 ); + } + +if (arg->has_arg) + i++; + } + +return 0 ; +}tools/um/tests/cla.h new file +33
-0@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _LKL_TEST_CLA_H +#define _LKL_TEST_CLA_H + +enum cl_arg_type { +CL_ARG_USER =0 , +CL_ARG_BOOL , +CL_ARG_INT , +CL_ARG_STR , +CL_ARG_STR_SET , +CL_ARG_IPV4 , +CL_ARG_END , +}; + +struct cl_arg ; + +typedef int (*cl_arg_parser_t )(struct cl_arg *arg,const char *value); + +struct cl_arg { +const char *long_name; +char short_name; +const char *help; +int has_arg; +enum cl_arg_type type; +void *store; +void *set; +cl_arg_parser_t parser; +}; + +int cla_parse_args (int argc,const char **argv,struct cl_arg *args); + + +#endif /* _LKL_TEST_CLA_H */ tools/um/tests/disk.c new file +168
-0@@ -0,0 +1,168 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <time.h> +#include <stdlib.h> +#include <stdint.h> +#include <lkl.h> +#include <lkl_host.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/ioctl.h> + +#include "test.h" +#include "cla.h" + +static struct { +int printk; +const char *disk; +const char *fstype; +int partition; +} cla; + +struct cl_arg args[] = { + {"disk" ,'d' ,"disk file to use" ,1 ,CL_ARG_STR , &cla.disk}, + {"partition" ,'P' ,"partition to mount" ,1 ,CL_ARG_INT , &cla.partition}, + {"type" ,'t' ,"filesystem type" ,1 ,CL_ARG_STR , &cla.fstype}, + {0 }, +}; + + +static struct lkl_disk disk; +static int disk_id =-1 ; + +int lkl_test_disk_add (void ) +{ + disk.fd =open (cla.disk,O_RDWR ); +if (disk.fd <0 ) + goto out_unlink; + + disk.ops =NULL ; + disk.dev = (char *)cla.disk; + + disk_id =lkl_disk_add (&disk); +if (disk_id <0 ) + goto out_close; + + goto out; + +out_close: +close (disk.fd); + +out_unlink: +unlink (cla.disk); + +out: +lkl_test_logf ("disk fd/handle %x disk_id %d" , disk.fd, disk_id); + +if (disk_id >=0 ) +return TEST_SUCCESS ; + +return TEST_FAILURE ; +} + +int lkl_test_disk_remove (void ) +{ +int ret; + + ret =lkl_disk_remove (disk); + +close (disk.fd); + +if (ret ==0 ) +return TEST_SUCCESS ; + +return TEST_FAILURE ; +} + + +static char mnt_point[32 ]; + +LKL_TEST_CALL (mount_dev, lkl_mount_dev,0 , disk_id, cla.partition, cla.fstype, + 0, NULL, mnt_point, sizeof(mnt_point)) + +static int lkl_test_umount_dev (void ) +{ +long ret, ret2; + + ret =lkl_sys_chdir ("/" ); + + ret2 =lkl_umount_dev (disk_id, cla.partition,0 ,1000 ); + +lkl_test_logf ("%ld %ld" , ret, ret2); + +if (!ret && !ret2) +return TEST_SUCCESS ; + +return TEST_FAILURE ; +} + +struct lkl_dir *dir; + +static int lkl_test_opendir (void ) +{ +int err; + + dir =lkl_opendir (mnt_point, &err); + +lkl_test_logf ("lkl_opedir(%s) = %d %s\n" , mnt_point, err, +lkl_strerror (err)); + +if (err ==0 ) +return TEST_SUCCESS ; + +return TEST_FAILURE ; +} + +static int lkl_test_readdir (void ) +{ +struct lkl_linux_dirent64 *de =lkl_readdir (dir); +int wr =0 ; + +while (de) { + wr +=lkl_test_logf ("%s " , de->d_name); +if (wr >=70 ) { +lkl_test_logf ("\n" ); + wr =0 ; +break ; + } + de =lkl_readdir (dir); + } + +if (lkl_errdir (dir) ==0 ) +return TEST_SUCCESS ; + +return TEST_FAILURE ; +} + +LKL_TEST_CALL (closedir, lkl_closedir,0 , dir); +LKL_TEST_CALL (chdir_mnt_point, lkl_sys_chdir,0 , mnt_point); +LKL_TEST_CALL (start_kernel, lkl_start_kernel,0 , &lkl_host_ops, +"mem=16M loglevel=8" ); +LKL_TEST_CALL (stop_kernel, lkl_sys_halt,0 ); + +struct lkl_test tests[] = { +LKL_TEST (disk_add), +LKL_TEST (start_kernel), +LKL_TEST (mount_dev), +LKL_TEST (chdir_mnt_point), +LKL_TEST (opendir), +LKL_TEST (readdir), +LKL_TEST (closedir), +LKL_TEST (umount_dev), +LKL_TEST (stop_kernel), +LKL_TEST (disk_remove), + +}; + +int main (int argc,const char **argv) +{ +if (cla_parse_args (argc, argv, args) <0 ) +return (-1 ); + + lkl_host_ops.print = lkl_test_log; + +return lkl_test_run (tests,sizeof (tests)/sizeof (struct lkl_test ), +"disk %s" , cla.fstype); +}tools/um/tests/disk.sh new file +70
-0@@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +script_dir=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd) + +source $script_dir/test.sh + +function prepfs() +{ + set -e + + file=`mktemp` + + dd if=/dev/zero of=$file bs=1024 count=204800 + + yes | mkfs.$1 $file + + if ! [ -z $ANDROID_WDIR ]; then + adb shell mkdir -p $ANDROID_WDIR + adb push $file $ANDROID_WDIR + rm $file + file=$ANDROID_WDIR/$(basename $file) + fi + if ! [ -z $BSD_WDIR ]; then + $MYSSH mkdir -p $BSD_WDIR + ssh_copy $file $BSD_WDIR + rm $file + file=$BSD_WDIR/$(basename $file) + fi + + export_vars file +} + +function cleanfs() +{ + set -e + + if ! [ -z $ANDROID_WDIR ]; then + adb shell rm $1 + adb shell rm $ANDROID_WDIR/disk + elif ! [ -z $BSD_WDIR ]; then + $MYSSH rm $1 + $MYSSH rm $BSD_WDIR/disk + else + rm $1 + fi +} + +if [ "$1" = "-t" ]; then + shift + fstype=$1 + shift +fi + +if [ -z "$fstype" ]; then + fstype="ext4" +fi + +if [ -z $(which mkfs.$fstype) ]; then + lkl_test_plan 0 "disk $fstype" + echo "no mkfs.$fstype command" + exit 0 +fi + +lkl_test_plan 1 "disk $fstype" +lkl_test_run 1 prepfs $fstype +lkl_test_exec $script_dir/disk -d $file -t $fstype $@ +lkl_test_plan 1 "disk $fstype" +lkl_test_run 1 cleanfs $file +tools/um/tests/run.py +2
-0@@ -50,6 +50,8 @@ mydir=os.path.dirname(os.path.realpath(__file__)) tests = [ 'boot.sh', + 'disk.sh -t ext4', + 'disk.sh -t vfat', ] parser = argparse.ArgumentParser(description='LKL test runner')
Signature · 3 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/
Anton Ivanov
maintainerRe: [RFC v7 18/21] um: host: add utilities functions
In reply to Hajime TazakiQuoted 67 lines · Hajime Tazaki
Add basic utility functions for getting a string from a kernel error code and a fprintf like function that uses the host print operation. The latter is useful for informing the user about errors that occur in the host library.
Signed-off-by Hajime Tazaki <[email protected]>--- tools/um/lib/Build | 4 + tools/um/lib/jmp_buf.c | 14 +++ tools/um/lib/jmp_buf.h | 8 ++ tools/um/lib/utils.c | 210 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 236 insertions(+)create mode 100644
tools/um/lib/Build
create mode 100644tools/um/lib/jmp_buf.c
create mode 100644tools/um/lib/jmp_buf.h
create mode 100644tools/um/lib/utils.ctools/um/lib/Build new file +4
-0@@ -0,0 +1,4 @@ +include $(objtree)/include/config/auto.conf + +liblinux-$(CONFIG_UMMODE_LIB) += utils.o +liblinux-$(CONFIG_UMMODE_LIB) += jmp_buf.otools/um/lib/jmp_buf.c new file +14
-0@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <setjmp.h> +#include <lkl_host.h> + +void jmp_buf_set (struct lkl_jmp_buf *jmpb,void (*f)(void )) +{ +if (!setjmp (*((jmp_buf *)jmpb->buf))) +f (); +} + +void jmp_buf_longjmp (struct lkl_jmp_buf *jmpb,int val) +{ +longjmp (*((jmp_buf *)jmpb->buf), val); +}tools/um/lib/jmp_buf.h new file +8
-0@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LKL_LIB_JMP_BUF_H +#define _LKL_LIB_JMP_BUF_H + +void jmp_buf_set (struct lkl_jmp_buf *jmpb,void (*f)(void )); +void jmp_buf_longjmp (struct lkl_jmp_buf *jmpb,int val); + +#endif tools/um/lib/utils.c new file +0
-0
tools/um/lib/utils.c line 5
Quoted 5 lines
tools/um/lib/utils.c new file +5
-0@@ -0,0 +1,210 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <stdarg.h> +#include <stdio.h> +#include <string.h> +#include <lkl_host.h>
These are actually different on different architectures. These look like the x86 values.
IMHO a kernel strerror() would be the right way of dealing with this in the long term (i understand that we cannot call the platform one, because it may be different from the internal Linux errors). It will be useful in a lot of other places.
If we leave it as is, we need to make this arch specific at some point.
Quoted 206 lines
tools/um/lib/utils.c new file +205
-0+ +static const char *const lkl_err_strings[] = { +"Success" , +"Operation not permitted" , +"No such file or directory" , +"No such process" , +"Interrupted system call" , +"I/O error" , +"No such device or address" , +"Argument list too long" , +"Exec format error" , +"Bad file number" , +"No child processes" , +"Try again" , +"Out of memory" , +"Permission denied" , +"Bad address" , +"Block device required" , +"Device or resource busy" , +"File exists" , +"Cross-device link" , +"No such device" , +"Not a directory" , +"Is a directory" , +"Invalid argument" , +"File table overflow" , +"Too many open files" , +"Not a typewriter" , +"Text file busy" , +"File too large" , +"No space left on device" , +"Illegal seek" , +"Read-only file system" , +"Too many links" , +"Broken pipe" , +"Math argument out of domain of func" , +"Math result not representable" , +"Resource deadlock would occur" , +"File name too long" , +"No record locks available" , +"Invalid system call number" , +"Directory not empty" , +"Too many symbolic links encountered" , +"Bad error code" ,/* EWOULDBLOCK is EAGAIN */ +"No message of desired type" , +"Identifier removed" , +"Channel number out of range" , +"Level 2 not synchronized" , +"Level 3 halted" , +"Level 3 reset" , +"Link number out of range" , +"Protocol driver not attached" , +"No CSI structure available" , +"Level 2 halted" , +"Invalid exchange" , +"Invalid request descriptor" , +"Exchange full" , +"No anode" , +"Invalid request code" , +"Invalid slot" , +"Bad error code" ,/* EDEADLOCK is EDEADLK */ +"Bad font file format" , +"Device not a stream" , +"No data available" , +"Timer expired" , +"Out of streams resources" , +"Machine is not on the network" , +"Package not installed" , +"Object is remote" , +"Link has been severed" , +"Advertise error" , +"Srmount error" , +"Communication error on send" , +"Protocol error" , +"Multihop attempted" , +"RFS specific error" , +"Not a data message" , +"Value too large for defined data type" , +"Name not unique on network" , +"File descriptor in bad state" , +"Remote address changed" , +"Can not access a needed shared library" , +"Accessing a corrupted shared library" , +".lib section in a.out corrupted" , +"Attempting to link in too many shared libraries" , +"Cannot exec a shared library directly" , +"Illegal byte sequence" , +"Interrupted system call should be restarted" , +"Streams pipe error" , +"Too many users" , +"Socket operation on non-socket" , +"Destination address required" , +"Message too long" , +"Protocol wrong type for socket" , +"Protocol not available" , +"Protocol not supported" , +"Socket type not supported" , +"Operation not supported on transport endpoint" , +"Protocol family not supported" , +"Address family not supported by protocol" , +"Address already in use" , +"Cannot assign requested address" , +"Network is down" , +"Network is unreachable" , +"Network dropped connection because of reset" , +"Software caused connection abort" , +"Connection reset by peer" , +"No buffer space available" , +"Transport endpoint is already connected" , +"Transport endpoint is not connected" , +"Cannot send after transport endpoint shutdown" , +"Too many references: cannot splice" , +"Connection timed out" , +"Connection refused" , +"Host is down" , +"No route to host" , +"Operation already in progress" , +"Operation now in progress" , +"Stale file handle" , +"Structure needs cleaning" , +"Not a XENIX named type file" , +"No XENIX semaphores available" , +"Is a named type file" , +"Remote I/O error" , +"Quota exceeded" , +"No medium found" , +"Wrong medium type" , +"Operation Canceled" , +"Required key not available" , +"Key has expired" , +"Key has been revoked" , +"Key was rejected by service" , +"Owner died" , +"State not recoverable" , +"Operation not possible due to RF-kill" , +"Memory page has hardware error" , +}; + +const char *lkl_strerror (int err) +{ +if (err <0 ) + err = -err; + +if ((size_t )err >=sizeof (lkl_err_strings) /sizeof (const char *)) +return "Bad error code" ; + +return lkl_err_strings[err]; +} + +void lkl_perror (char *msg,int err) +{ +const char *err_msg =lkl_strerror (err); +/* We need to use 'real' printf because lkl_host_ops.print can +* be turned off when debugging is off. +*/ +lkl_printf ("%s: %s\n" , msg, err_msg); +} + +static int lkl_vprintf (const char *fmt,va_list args) +{ +int n; +char *buffer; +va_list copy; + +if (!lkl_host_ops.print) +return 0 ; + +va_copy (copy, args); + n =vsnprintf (NULL ,0 , fmt, copy); +va_end (copy); + + buffer = lkl_host_ops.mem_alloc (n +1 ); +if (!buffer) +return (-1 ); + +vsnprintf (buffer, n +1 , fmt, args); + + lkl_host_ops.mem_free (buffer); + +return n; +} + +int lkl_printf (const char *fmt, ...) +{ +int n; +va_list args; + +va_start (args, fmt); + n =lkl_vprintf (fmt, args); +va_end (args); + +return n; +} + +void lkl_bug (const char *fmt, ...) +{ +va_list args; + +va_start (args, fmt); +lkl_vprintf (fmt, args); +va_end (args); + + lkl_host_ops.panic (); +}
Signature · 3 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/
Johannes Berg
maintainerRe: [RFC v7 18/21] um: host: add utilities functions
Quoted 9 lines · Anton Ivanov
These are actually different on different architectures. These look like the x86 values.
IMHO a kernel
strerror()would be the right way of dealing with this in the long term (i understand that we cannot call the platform one, because it may be different from the internal Linux errors). It will be useful in a lot of other places.
Quoted 7 lines
If we leave it as is, we need to make this arch specific at some point.
tools/um/lib/utils.c line 9
Quoted 4 lines
tools/um/lib/utils.c new file +4
-0+ +static const char *const lkl_err_strings[] = { +"Success" , +"Operation not permitted" ,
Might be possible to more or less address this (except for arch-specific errors that don't always exist) but using C99 initializers?
[0] = "Success",
[EPERM] = "Operation not permitted",
..
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [RFC v7 18/21] um: host: add utilities functions
Quoted 20 lines · Johannes Berg
Quoted 8 lines · Anton Ivanov
These are actually different on different architectures. These look like the x86 values.
IMHO a kernel
strerror()would be the right way of dealing with this in the long term (i understand that we cannot call the platform one, because it may be different from the internal Linux errors). It will be useful in a lot of other places.Quoted 7 lines
If we leave it as is, we need to make this arch specific at some point.
tools/um/lib/utils.c line 9
Quoted 4 lines
tools/um/lib/utils.c new file +4
-0+ +static const char *const lkl_err_strings[] = { +"Success" , +"Operation not permitted" ,Might be possible to more or less address this (except for arch-specific errors that don't always exist) but using C99 initializers?
Quoted 3 lines
[0] = "Success",
[EPERM] = "Operation not permitted",
..
But, on the other hand, is it needed at all? I don't think the kernel ever prints out the actual string ...
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Anton Ivanov
maintainerRe: [RFC v7 18/21] um: host: add utilities functions
Quoted 20 lines · Johannes Berg
Quoted 19 lines · Johannes Berg
Quoted 8 lines · Anton Ivanov
These are actually different on different architectures. These look like the x86 values.
IMHO a kernel
strerror()would be the right way of dealing with this in the long term (i understand that we cannot call the platform one, because it may be different from the internal Linux errors). It will be useful in a lot of other places.Quoted 7 lines
If we leave it as is, we need to make this arch specific at some point.
tools/um/lib/utils.c line 9
Quoted 4 lines
tools/um/lib/utils.c new file +4
-0+ +static const char *const lkl_err_strings[] = { +"Success" , +"Operation not permitted" ,Might be possible to more or less address this (except for arch-specific errors that don't always exist) but using C99 initializers?
Quoted 5 lines
Quoted 3 lines
[0] = "Success",
[EPERM] = "Operation not permitted",
..But, on the other hand, is it needed at all? I don't think the kernel ever prints out the actual string ...
I can see the use case for a library in a multi-arch environment (which IMHO is the intended use case). It saves the user the effort of digging into the build and figuring out what does this error mean today :)
It is nice to have :)
If we will have it, however, it should be done as you suggested - C99 or some other way where it maps correctly to actual underlying error codes as they may end up being different depending on build config.
Quoted 8 lines
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Signature · 3 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/
Johannes Berg
maintainerRe: [RFC v7 02/21] um: add os init and exit calls
In reply to Hajime Tazakiarch/um/include/shared/init.h extern struct uml_param __uml_setup_start, __uml_setup_end; · line 113
Quoted 11 lines · Hajime Tazaki
arch/um/include/shared/init.h +2
-8-#define __define_initcall (level,fn) \ - static initcall_t __initcall_##fn __used \ - __attribute__((__section__(".initcall" level ".init"))) = fn - -/* Userspace initcalls shouldn't depend on anything in the kernel, so we'll -* make them run first. -*/ -#define __initcall (fn) __define_initcall("1", fn) +#undef __uml_exit_call +#define __uml_exit_call __used __section(os_exitcalls)
Doesn't that break calling of sigio_cleanup and remove_umid_dir?
After all,
arch/um/kernel/reboot.c static void kill_off_processes(void) · line 40
Quoted 3 lines
arch/um/kernel/reboot.c +3
-0+void __weak os_exitcalls (void ) +{ +}
This does nothing so far.
Also, why the __weak?
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [RFC v7 03/21] um: move arch/um/os-Linux dir to tools/um/uml
In reply to Hajime TazakiQuoted 3 lines · Hajime Tazaki
This patch moves underlying OS dependent part under
arch/umtotools/umdirectory so thatarch/umcode does not need to build host build facilities (e.g., libc).
Hmm. On the one hand, that build separation seems sensible, but on the other hand this stuff *does* fundamentally belong to arch/um/, and it's not a "tool" like basically everything else there that is a pure userspace application to run *inside* the kernel, not *part of* it.
For that reason, I don't really like this much.
Quoted 2 lines
tools/um/uml/Build | 48 +++++++++++++++++++ tools/um/uml/drivers/Build | 10 ++++
Also, what's with the names here? What's wrong with "Makefile"?
I'm also not sure I see how this is built at all from the top level Makefile? Oh. I think Anton said it doesn't ... that alone would be a reason not to do it I guess.
So why do you think it must be under tools/? Even if you consider "lkl" a "tool", that doesn't mean it must be there. I also consider a UML binary ("linux") a "tool" in my simulation environment, etc.
And even LKL, which is the eventual goal here - why would you consider that a "tool"? I don't think we should.
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [RFC v7 04/21] um: host: implement os_initcalls and os_exitcalls
In reply to Hajime TazakiQuoted 2 lines · Hajime Tazaki
Note that this patch should be merged with "um: move
arch/um/os-Linuxdir totools/um" but for now it is separate to make the review easier.
Not a fan of that, I must say ...
tools/um/uml/util.c void os_warn(const char *fmt, ...) · line 199
Quoted 10 lines
tools/um/uml/util.c +10
-0+extern void (*__start_os_exitcalls)(void ); +extern void (*__stop_os_exitcalls)(void ); + +void os_exitcalls (void ) +{ +exitcall_t *call; + + call = &__stop_os_exitcalls; +while (--call >= &__start_os_exitcalls) + (*call)();
You should check for and skip NULL pointers, there always are alignment issues with automatic section filling like this, more so with clang than gcc.
tools/um/uml/util.c void os_warn(const char *fmt, ...) · line 211
Quoted 12 lines
tools/um/uml/util.c +12
-0+} + +extern int (*__start_os_initcalls)(void ); +extern int (*__stop_os_initcalls)(void ); + +int os_initcalls (void ) +{ +initcall_t *call; + + call = &__stop_os_initcalls; +while (--call >= &__start_os_initcalls) + (*call)();
Same here.
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [RFC v7 05/21] um: move arch/x86/um/os-Linux to tools/um/uml/
In reply to Hajime TazakiQuoted 4 lines · Hajime Tazaki
Similar to
arch/um/os-Linuxcode,arch/x86also contains OS dependent part as well. This patch moves underlying OS dependent part totools/umdirectory so thatarch/x86code does not need to build host build facilities (e.g., libc).
Again, I don't agree with the rationale. This isn't a tool in the kernel sense, and separating only by "what does it link against" doesn't make much sense either.
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [RFC v7 06/21] scritps: um: suppress warnings if SRCARCH=um
In reply to Hajime TazakiQuoted 2 lines · Hajime Tazaki
This commit fixes numbers of warning messages about leaked CONFIG options.
No it doesn't ... it suppresses them, not a fan at all.
Quoted 3 lines
nommu mode of UML requires copies of kernel headers to offer syscall-like API for the library users. Thus, the warnings are to be avoided to function this exposure of API.
I don't see that here, so maybe make that part of the patch where it actually happens, with a big comment, and maybe only when actually building for NOMMU/LKL?
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [RFC v7 07/21] um: extend arch_switch_to for alternate SUBARCH
In reply to Hajime TazakiQuoted 6 lines · Hajime Tazaki
This commit introduces additional argument of previous task when context switch happens. New SUBARCH can use the new information to switch tasks in a subarch-specific manner.
The patch is particularly required by nommu mode implemented as a SUBARCH of UML.
Would probably be good to already say why here?
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um