Skip to contentSkip to conversation

Unifying LKL into UML

RFC Superseded Hajime Tazaki 8 participants 248 messages Feb 5, 2020 – Mar 18, 2021 1 message not in the archive Page 2 of 3

Subsystems (10)
Documentation x86 Kbuild Kselftest +6 more subsystems
lore
Share & tools
lore
#82 lore raw

RFC v5 8/21 um: add nommu mode for UML library mode

In reply to Hajime Tazaki

This 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
new file mode 100644
index 000000000000..792d6005489e
@@ -0,0 +1 @@
+#
arch/um/nommu/Makefile.um new file +18 -0
new file mode 100644
index 000000000000..6cb0e9494d05
@@ -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
new file mode 100644
index 000000000000..2532e1a0a0d1
@@ -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
new file mode 100644
index 000000000000..ea32a7d3cf1b
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0 */
arch/um/nommu/include/asm/atomic.h new file +11 -0
new file mode 100644
index 000000000000..63e2e16bda92
@@ -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
new file mode 100644
index 000000000000..a150cee41e75
@@ -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
new file mode 100644
index 000000000000..920a5fd26cad
@@ -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
new file mode 100644
index 000000000000..c101c078ef21
@@ -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
new file mode 100644
index 000000000000..edcf63edeed1
@@ -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
new file mode 100644
index 000000000000..a2e53984aabd
@@ -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
new file mode 100644
index 000000000000..b214410e9825
@@ -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
new file mode 100644
index 000000000000..a4496f482633
@@ -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(&current_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
new file mode 100644
index 000000000000..5608da95cb60
@@ -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
new file mode 100644
index 000000000000..4f79e5c4846d
@@ -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
new file mode 100644
index 000000000000..852566ac2e52
@@ -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
new file mode 100644
index 000000000000..e7ad11a751cf
@@ -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
new file mode 100644
index 000000000000..b934ae7f5550
@@ -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
new file mode 100644
index 000000000000..58a366d9b5f0
@@ -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
new file mode 100644
index 000000000000..4a5c10d7521b
@@ -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
new file mode 100644
index 000000000000..49210742212d
@@ -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
new file mode 100644
index 000000000000..a004bffb7b8d
@@ -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
new file mode 100644
index 000000000000..b734012a74da
@@ -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
new file mode 100644
index 000000000000..86d5cb20fb9f
@@ -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
new file mode 100644
index 000000000000..2245d3d24120
@@ -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)
#83 lore raw

RFC v5 9/21 um: nommu: host interface

In reply to Hajime Tazaki

This 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
new file mode 100644
index 000000000000..f52423cc4ced
@@ -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
new file mode 100644
index 000000000000..d3dad11b459e
@@ -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)
#84 lore raw

RFC v5 10/21 um: nommu: memory handling

In reply to Hajime Tazaki

nommu 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
index 5b072aba5b65..c06d6cb67dd7 100644
@@ -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
index b4deb1bfbb68..92cc838bb477 100644
@@ -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>
 
@@ -74,4 +75,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
index 95af12e82a32..c9d5e487ac6b 100644
@@ -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
index b5ddf5d98bd5..5c19f6a58ef7 100644
@@ -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
@@ -362,4 +364,29 @@ do {						\
 	__flush_tlb_one((vaddr));		\
 } while (0)
 
+#else  /* CONFIG_MMU */
+
+#include <asm-generic/pgtable-nopud.h>
+#include <asm-generic/pgtable.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
+
+/*
+ * 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
index fe66d659acad..95db8f06d295 100644
@@ -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
index d3dad11b459e..5253c3f8de0e 100644
@@ -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)
#85 lore raw

RFC v5 11/21 um: nommu: kernel thread support

In reply to Hajime Tazaki

nommu 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
index 4c19ce4c49f1..433584f6b9d0 100644
@@ -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
index e5238a42ea17..0dafded5947e 100644
@@ -157,7 +157,8 @@ int copy_thread_tls(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;
@@ -214,10 +215,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 · 1 line
2.21.0 (Apple Git-122.2)
#86 lore raw

RFC v5 12/21 um: nommu: system call interface and application API

In reply to Hajime Tazaki

The 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
new file mode 100644
index 000000000000..a983c7f049bc
@@ -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
new file mode 100644
index 000000000000..6061d9415dad
@@ -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
index 720385fccbdf..6ee9489fc47e 100644
@@ -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
new file mode 100644
index 000000000000..1762ebb829f5
@@ -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)
#87 lore raw

RFC v5 13/21 um: nommu: basic console support

In reply to Hajime Tazaki

This 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
index ae96c83e312d..694da4aa550d 100644
@@ -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
index 6ee9489fc47e..133877c857a1 100644
@@ -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)
#88 lore raw

RFC v5 14/21 um: nommu: initialization and cleanup

In reply to Hajime Tazaki

Add 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
index 133877c857a1..0811494c080c 100644
@@ -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
index e52dd37ddadc..c39d914e80ac 100644
@@ -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)
#89 lore raw

RFC v5 15/21 um: nommu: integrate with irq infrastructure of UML

In reply to Hajime Tazaki

In 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
index f467d28fc0b4..0da3ce22e16f 100644
@@ -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
index 3577118bb4a5..4ce7f5fef7f8 100644
@@ -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
index 25eaa6a0c658..9e141fe8fe27 100644
@@ -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
index c101c078ef21..c52a78c77bea 100644
@@ -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
index 9986a3f8c5dd..75d8bdc1847e 100644
@@ -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
index 25aa003792d4..f74baea50bd3 100644
@@ -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
index 3e70eccc191a..df96057100fd 100644
@@ -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
index b58bc68cbe64..2b5c98de21cd 100644
@@ -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)
#90 lore raw

RFC v5 16/21 um: nommu: plug in the build system

In reply to Hajime Tazaki

Basic 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
index a0a9fd3ab96c..300fcc90cff3 100644
@@ -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
index af0cf64c1428..7e640e65a80e 100644
@@ -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
index 5aa882011e04..bdc4108bc52e 100644
@@ -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
new file mode 100644
index 000000000000..20b3eaccb6f0
@@ -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
new file mode 100644
index 000000000000..b580e0fe97b5
@@ -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)
#91 lore raw

RFC v5 17/21 um: host: add nommu build for ARCH=um

In reply to Hajime Tazaki

This 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
index 552ed5f1edae..a93e060b1f89 100644
@@ -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
index a4711f1ef422..4e1f0f4d81a3 100644
@@ -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
new file mode 100644
index 000000000000..85e80eb4ad0d
@@ -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
index 435a9670d3ff..191c6479ad72 100644
@@ -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
new file mode 100644
index 000000000000..98fd6b86a085
@@ -0,0 +1 @@
+liblinux-y = registers.o unimplemented.o
tools/um/uml/nommu/registers.c new file +21 -0
new file mode 100644
index 000000000000..11573a204720
@@ -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
new file mode 100644
index 000000000000..9da3e5c8bafb
@@ -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)
#92 lore raw

RFC v5 18/21 um: host: add utilities functions

In reply to 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.

---
 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
new file mode 100644
index 000000000000..fc967af4104a
@@ -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
new file mode 100644
index 000000000000..f6bdd7e4bd83
@@ -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
new file mode 100644
index 000000000000..8782cbaaf51f
@@ -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)
#93 lore raw

RFC v5 19/21 um: host: posix host operations

In reply to Hajime Tazaki

This 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
index fc967af4104a..dddff26a3b4e 100644
@@ -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)
#94 lore raw

RFC v5 20/21 um: host: add test programs

In reply to Hajime Tazaki

Add 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
index a93e060b1f89..20de2e4c162f 100644
@@ -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
index 4e1f0f4d81a3..2bb90381843c 100644
@@ -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
new file mode 100644
index 000000000000..26a607f90dc8
@@ -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
new file mode 100755
index 000000000000..d985c04b0ac1
@@ -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)
#95 lore raw

RFC v5 21/21 um: nommu: add block device support of UML

In reply to 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.

---
 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
index 36b33d62a35d..a5ea458a1ae9 100644
@@ -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
index 5f286ef2721b..4423437a5ace 100644
@@ -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
index 78d6042fd2e6..ed0149821518 100644
@@ -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
index 0811494c080c..1b2507502969 100644
@@ -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
index 1762ebb829f5..320762099a62 100644
@@ -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
index 20b3eaccb6f0..c6a3f472fe75 100644
@@ -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
index f74baea50bd3..6b49bf7a99fb 100644
@@ -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
index 2bb90381843c..f5f8ec4b9dbb 100644
@@ -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
index 85e80eb4ad0d..12dd95616e43 100644
@@ -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
index dddff26a3b4e..29491b40746c 100644
@@ -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
index b6b5b2902254..8fd88031bf2b 100644
@@ -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
index 4930479a8a35..ac65cd744a14 100644
@@ -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
index 26a607f90dc8..b62919cadc50 100644
@@ -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
new file mode 100644
index 000000000000..3d879233681f
@@ -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
index c96ede90b6ad..97d6dedc217c 100755
@@ -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)
#96 lore raw

v6 cover Unifying LKL into UML

In reply to 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.

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)
#97 lore raw

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
index eb51fec75948..e41d31d0d875 100644
@@ -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
index 1cea46ff9bb7..fdfaff4633e8 100644
@@ -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
new file mode 100644
index 000000000000..a4711f1ef422
@@ -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
new file mode 100644
index 000000000000..e69de29bb2d1
Signature · 1 line
2.21.0 (Apple Git-122.2)
maintainer
#98 lore raw

Re: [RFC v6 01/21] um: split build in kernel and host parts

Quoted 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/um so 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=um

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.

Quoted 736 lines

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
index eb51fec75948..e41d31d0d875 100644
@@ -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
index 1cea46ff9bb7..fdfaff4633e8 100644
@@ -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
deleted file mode 100644
index eca6c452a41b..000000000000
@@ -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
deleted file mode 100644
index f5001481010c..000000000000
@@ -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
deleted file mode 100644
index 3b6dab3d4501..000000000000
@@ -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
index 16e49bfa2b42..aaedd66772fa 100644
@@ -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
index e6e2d9e5ff48..903fc8053d07 100755
@@ -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 debuginfo
tools/um/Makefile new file +72 -0
new file mode 100644
index 000000000000..a63466ef7ef5
@@ -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.o
tools/um/Targets new file +4 -0
new file mode 100644
index 000000000000..a4711f1ef422
@@ -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
new file mode 100644
index 000000000000..e69de29bb2d1
Signature · 3 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/
#99 lore raw

Re: [RFC v6 01/21] um: split build in kernel and host parts

Quoted 5 lines · Anton Ivanov
Quoted 5 lines

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

Quoted 7 lines
Quoted 5 lines
  $ make ARCH=um defconfig
  $ make ARCH=um

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 in arch/um/Makefile.

-- Hajime

maintainer
#100 lore raw

Re: [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/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
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 in arch/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
maintainer
#101 lore raw

Re: [RFC v6 01/21] um: split build in kernel and host parts

In reply to Hajime Tazaki
Quoted 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/um so 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=um

was 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/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
index eb51fec75948..e41d31d0d875 100644
@@ -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
index 1cea46ff9bb7..fdfaff4633e8 100644
@@ -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
deleted file mode 100644
index eca6c452a41b..000000000000
@@ -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
deleted file mode 100644
index f5001481010c..000000000000
@@ -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
deleted file mode 100644
index 3b6dab3d4501..000000000000
@@ -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
index 16e49bfa2b42..aaedd66772fa 100644
@@ -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
index e6e2d9e5ff48..903fc8053d07 100755
@@ -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 debuginfo
tools/um/Makefile new file +72 -0
new file mode 100644
index 000000000000..a63466ef7ef5
@@ -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.o
tools/um/Targets new file +4 -0
new file mode 100644
index 000000000000..a4711f1ef422
@@ -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
new file mode 100644
index 000000000000..e69de29bb2d1
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
#102 lore raw

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=um

was 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

#103 lore raw

RFC v6 2/21 um: add os init and exit calls

In reply to Hajime Tazaki

From: 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
index c66de434a983..d09308330ca5 100644
@@ -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
index 48c0610d506e..5420aec411f4 100644
@@ -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
index 00141e70de56..e2cb76c03b25 100644
@@ -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)
#104 lore raw

RFC v6 3/21 um: move arch/um/os-Linux dir to tools/um/uml

In reply to Hajime Tazaki

This 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
index fdfaff4633e8..1f958a9280fe 100644
@@ -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
index 2a249f619467..ae96c83e312d 100644
@@ -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
similarity index 100%
rename from arch/um/os-Linux/drivers/ethertap_kern.c
rename to arch/um/drivers/ethertap_kern.c
arch/um/drivers/tuntap_kern.c renamed from arch/um/os-Linux/drivers/tuntap_kern.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/drivers/tuntap_kern.c
rename to arch/um/drivers/tuntap_kern.c
arch/um/include/shared/etap.h renamed from arch/um/os-Linux/drivers/etap.h +0 -0
similarity index 100%
rename from arch/um/os-Linux/drivers/etap.h
rename to arch/um/include/shared/etap.h
arch/um/include/shared/init.h +5 -0
index d09308330ca5..305789667584 100644
@@ -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
similarity index 100%
rename from arch/um/os-Linux/drivers/tuntap.h
rename to arch/um/include/shared/tuntap.h
arch/um/os-Linux/Makefile deleted +0 -19
deleted file mode 100644
index 839915b8c31c..000000000000
@@ -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
deleted file mode 100644
index d79e75f1b69a..000000000000
@@ -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
index a63466ef7ef5..07b9b93ed817 100644
@@ -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
new file mode 100644
index 000000000000..c7a8eaa97d72
@@ -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
similarity index 100%
rename from arch/um/os-Linux/drivers/ethertap_user.c
rename to tools/um/uml/drivers/ethertap_user.c
tools/um/uml/drivers/tuntap_user.c renamed from arch/um/os-Linux/drivers/tuntap_user.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/drivers/tuntap_user.c
rename to tools/um/uml/drivers/tuntap_user.c
tools/um/uml/elf_aux.c renamed from arch/um/os-Linux/elf_aux.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/elf_aux.c
rename to tools/um/uml/elf_aux.c
tools/um/uml/execvp.c renamed from arch/um/os-Linux/execvp.c +0 -4
similarity index 98%
rename from arch/um/os-Linux/execvp.c
rename to tools/um/uml/execvp.c
index 84a0777c2a45..c105e0e7b778 100644
@@ -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
similarity index 100%
rename from arch/um/os-Linux/file.c
rename to tools/um/uml/file.c
tools/um/uml/helper.c renamed from arch/um/os-Linux/helper.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/helper.c
rename to tools/um/uml/helper.c
tools/um/uml/irq.c renamed from arch/um/os-Linux/irq.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/irq.c
rename to tools/um/uml/irq.c
tools/um/uml/main.c renamed from arch/um/os-Linux/main.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/main.c
rename to tools/um/uml/main.c
tools/um/uml/mem.c renamed from arch/um/os-Linux/mem.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/mem.c
rename to tools/um/uml/mem.c
tools/um/uml/process.c renamed from arch/um/os-Linux/process.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/process.c
rename to tools/um/uml/process.c
tools/um/uml/registers.c renamed from arch/um/os-Linux/registers.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/registers.c
rename to tools/um/uml/registers.c
tools/um/uml/sigio.c renamed from arch/um/os-Linux/sigio.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/sigio.c
rename to tools/um/uml/sigio.c
tools/um/uml/signal.c renamed from arch/um/os-Linux/signal.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/signal.c
rename to tools/um/uml/signal.c
tools/um/uml/skas/Build renamed from arch/um/os-Linux/skas/Makefile +1 -5
similarity index 56%
rename from arch/um/os-Linux/skas/Makefile
rename to tools/um/uml/skas/Build
index c4566e788815..5fc9d62df863 100644
@@ -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
similarity index 100%
rename from arch/um/os-Linux/skas/mem.c
rename to tools/um/uml/skas/mem.c
tools/um/uml/skas/process.c renamed from arch/um/os-Linux/skas/process.c +1 -2
similarity index 99%
rename from arch/um/os-Linux/skas/process.c
rename to tools/um/uml/skas/process.c
index 4fb877b99dde..fca6a08e81bd 100644
@@ -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
similarity index 100%
rename from arch/um/os-Linux/start_up.c
rename to tools/um/uml/start_up.c
tools/um/uml/time.c renamed from arch/um/os-Linux/time.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/time.c
rename to tools/um/uml/time.c
tools/um/uml/tty.c renamed from arch/um/os-Linux/tty.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/tty.c
rename to tools/um/uml/tty.c
tools/um/uml/umid.c renamed from arch/um/os-Linux/umid.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/umid.c
rename to tools/um/uml/umid.c
tools/um/uml/user_syms.c renamed from arch/um/os-Linux/user_syms.c +1 -0
similarity index 99%
rename from arch/um/os-Linux/user_syms.c
rename to tools/um/uml/user_syms.c
index 715594fe5719..4047fd7bfdb7 100644
@@ -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
similarity index 100%
rename from arch/um/os-Linux/util.c
rename to tools/um/uml/util.c
Signature · 1 line
2.21.0 (Apple Git-122.2)
#105 lore raw

RFC v6 4/21 um: host: implement os_initcalls and os_exitcalls

In reply to Hajime Tazaki

From: 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
index ecf2f390fad2..4011b36fee7e 100644
@@ -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)
#106 lore raw

RFC v6 5/21 um: move arch/x86/um/os-Linux to tools/um/uml/

In reply to Hajime Tazaki

Similar 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
index 77f70b969d14..25e9846b36a2 100644
@@ -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
deleted file mode 100644
index 253bfb8cb702..000000000000
@@ -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
index 07b9b93ed817..552ed5f1edae 100644
@@ -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
index 8e0607ee8b0a..435a9670d3ff 100644
@@ -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
new file mode 100644
index 000000000000..16bbc7eb19d1
@@ -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
similarity index 100%
rename from arch/x86/um/os-Linux/mcontext.c
rename to tools/um/uml/x86/mcontext.c
tools/um/uml/x86/prctl.c renamed from arch/x86/um/os-Linux/prctl.c +0 -0
similarity index 100%
rename from arch/x86/um/os-Linux/prctl.c
rename to tools/um/uml/x86/prctl.c
tools/um/uml/x86/registers.c renamed from arch/x86/um/os-Linux/registers.c +0 -0
similarity index 100%
rename from arch/x86/um/os-Linux/registers.c
rename to tools/um/uml/x86/registers.c
tools/um/uml/x86/task_size.c renamed from arch/x86/um/os-Linux/task_size.c +0 -0
similarity index 100%
rename from arch/x86/um/os-Linux/task_size.c
rename to tools/um/uml/x86/task_size.c
tools/um/uml/x86/tls.c renamed from arch/x86/um/os-Linux/tls.c +0 -0
similarity index 100%
rename from arch/x86/um/os-Linux/tls.c
rename to tools/um/uml/x86/tls.c
Signature · 1 line
2.21.0 (Apple Git-122.2)
#107 lore raw

RFC v6 6/21 scritps: um: suppress warnings if SRCARCH=um

In reply to Hajime Tazaki

This 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
index dd554bd436cc..8890a0147012 100755
@@ -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)
#108 lore raw

RFC v6 7/21 um: extend arch_switch_to for alternate SUBARCH

In reply to 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.

---
 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
index 26b5e243d3fc..87a8cfa228ca 100644
@@ -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
index 2497bac56066..0f184710d4ca 100644
@@ -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
index 58f51667e2e4..2ef9474d2bd2 100644
@@ -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)
#109 lore raw

RFC v6 8/21 um: add nommu mode for UML library mode

In reply to Hajime Tazaki

This 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
new file mode 100644
index 000000000000..792d6005489e
@@ -0,0 +1 @@
+#
arch/um/nommu/Makefile.um new file +18 -0
new file mode 100644
index 000000000000..6cb0e9494d05
@@ -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
new file mode 100644
index 000000000000..2532e1a0a0d1
@@ -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
new file mode 100644
index 000000000000..ea32a7d3cf1b
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0 */
arch/um/nommu/include/asm/atomic.h new file +11 -0
new file mode 100644
index 000000000000..63e2e16bda92
@@ -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
new file mode 100644
index 000000000000..a150cee41e75
@@ -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
new file mode 100644
index 000000000000..920a5fd26cad
@@ -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
new file mode 100644
index 000000000000..c101c078ef21
@@ -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
new file mode 100644
index 000000000000..edcf63edeed1
@@ -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
new file mode 100644
index 000000000000..a2e53984aabd
@@ -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
new file mode 100644
index 000000000000..b214410e9825
@@ -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
new file mode 100644
index 000000000000..a4496f482633
@@ -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(&current_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
new file mode 100644
index 000000000000..5608da95cb60
@@ -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
new file mode 100644
index 000000000000..4f79e5c4846d
@@ -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
new file mode 100644
index 000000000000..852566ac2e52
@@ -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
new file mode 100644
index 000000000000..e7ad11a751cf
@@ -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
new file mode 100644
index 000000000000..b934ae7f5550
@@ -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
new file mode 100644
index 000000000000..58a366d9b5f0
@@ -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
new file mode 100644
index 000000000000..4a5c10d7521b
@@ -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
new file mode 100644
index 000000000000..49210742212d
@@ -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
new file mode 100644
index 000000000000..a004bffb7b8d
@@ -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
new file mode 100644
index 000000000000..b734012a74da
@@ -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
new file mode 100644
index 000000000000..86d5cb20fb9f
@@ -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
new file mode 100644
index 000000000000..2245d3d24120
@@ -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)
#110 lore raw

RFC v6 9/21 um: nommu: host interface

In reply to Hajime Tazaki

This 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
new file mode 100644
index 000000000000..f52423cc4ced
@@ -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
new file mode 100644
index 000000000000..d3dad11b459e
@@ -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)
#111 lore raw

RFC v6 10/21 um: nommu: memory handling

In reply to Hajime Tazaki

nommu 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
index 5b072aba5b65..c06d6cb67dd7 100644
@@ -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
index 17ddd4edf875..4b06c29ae830 100644
@@ -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
index 95af12e82a32..c9d5e487ac6b 100644
@@ -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
index def376194dce..7e506d5406e3 100644
@@ -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
index fe66d659acad..95db8f06d295 100644
@@ -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
index d3dad11b459e..5253c3f8de0e 100644
@@ -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)
#112 lore raw

RFC v6 11/21 um: nommu: kernel thread support

In reply to Hajime Tazaki

nommu 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
index 4c19ce4c49f1..433584f6b9d0 100644
@@ -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
index 87a8cfa228ca..432edcbb5eea 100644
@@ -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
#113 lore raw

RFC v6 12/21 um: nommu: system call interface and application API

In reply to Hajime Tazaki

The 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
new file mode 100644
index 000000000000..a983c7f049bc
@@ -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
new file mode 100644
index 000000000000..6061d9415dad
@@ -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
index 720385fccbdf..6ee9489fc47e 100644
@@ -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
new file mode 100644
index 000000000000..1762ebb829f5
@@ -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)
#114 lore raw

RFC v6 13/21 um: nommu: basic console support

In reply to Hajime Tazaki

This 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
index ae96c83e312d..694da4aa550d 100644
@@ -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
index 6ee9489fc47e..133877c857a1 100644
@@ -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)
#115 lore raw

RFC v6 14/21 um: nommu: initialization and cleanup

In reply to Hajime Tazaki

Add 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
index 133877c857a1..0811494c080c 100644
@@ -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
index e52dd37ddadc..c39d914e80ac 100644
@@ -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)
#116 lore raw

RFC v6 15/21 um: nommu: integrate with irq infrastructure of UML

In reply to Hajime Tazaki

In 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
index f467d28fc0b4..0da3ce22e16f 100644
@@ -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
index 3577118bb4a5..4ce7f5fef7f8 100644
@@ -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
index 25eaa6a0c658..9e141fe8fe27 100644
@@ -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
index c101c078ef21..c52a78c77bea 100644
@@ -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
index 9986a3f8c5dd..75d8bdc1847e 100644
@@ -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
index eaa74d771f73..922188690139 100644
@@ -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
index 3e70eccc191a..df96057100fd 100644
@@ -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
index b58bc68cbe64..2b5c98de21cd 100644
@@ -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)
#117 lore raw

RFC v6 16/21 um: nommu: plug in the build system

In reply to Hajime Tazaki

Basic 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
index e41d31d0d875..df7daceb095c 100644
@@ -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
index 1f958a9280fe..73d3ac061b77 100644
@@ -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
index 5aa882011e04..bdc4108bc52e 100644
@@ -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
new file mode 100644
index 000000000000..20b3eaccb6f0
@@ -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
new file mode 100644
index 000000000000..b580e0fe97b5
@@ -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)
#118 lore raw

RFC v6 17/21 um: host: add nommu build for ARCH=um

In reply to Hajime Tazaki

This 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
index 552ed5f1edae..a93e060b1f89 100644
@@ -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
index a4711f1ef422..4e1f0f4d81a3 100644
@@ -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
new file mode 100644
index 000000000000..85e80eb4ad0d
@@ -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
index 435a9670d3ff..191c6479ad72 100644
@@ -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
new file mode 100644
index 000000000000..98fd6b86a085
@@ -0,0 +1 @@
+liblinux-y = registers.o unimplemented.o
tools/um/uml/nommu/registers.c new file +21 -0
new file mode 100644
index 000000000000..11573a204720
@@ -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
new file mode 100644
index 000000000000..9da3e5c8bafb
@@ -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)
#119 lore raw

RFC v6 18/21 um: host: add utilities functions

In reply to 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.

---
 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
new file mode 100644
index 000000000000..fc967af4104a
@@ -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
new file mode 100644
index 000000000000..f6bdd7e4bd83
@@ -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
new file mode 100644
index 000000000000..8782cbaaf51f
@@ -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)
#120 lore raw

RFC v6 19/21 um: host: posix host operations

In reply to Hajime Tazaki

This 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
index fc967af4104a..dddff26a3b4e 100644
@@ -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)
#121 lore raw

RFC v6 20/21 um: host: add test programs

In reply to Hajime Tazaki

Add 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
index a93e060b1f89..20de2e4c162f 100644
@@ -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
index 4e1f0f4d81a3..2bb90381843c 100644
@@ -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
new file mode 100644
index 000000000000..26a607f90dc8
@@ -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
new file mode 100755
index 000000000000..d985c04b0ac1
@@ -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
#122 lore raw

RFC v6 21/21 um: nommu: add block device support of UML

In reply to 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.

---
 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
index 36b33d62a35d..a5ea458a1ae9 100644
@@ -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
index 5f286ef2721b..4423437a5ace 100644
@@ -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
index e2cb76c03b25..da6e06cf2808 100644
@@ -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
index 0811494c080c..1b2507502969 100644
@@ -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
index 1762ebb829f5..320762099a62 100644
@@ -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
index 20b3eaccb6f0..c6a3f472fe75 100644
@@ -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
index 922188690139..d71d61979ad6 100644
@@ -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
index 2bb90381843c..f5f8ec4b9dbb 100644
@@ -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
index 85e80eb4ad0d..12dd95616e43 100644
@@ -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
index dddff26a3b4e..29491b40746c 100644
@@ -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
index b6b5b2902254..8fd88031bf2b 100644
@@ -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
index 4930479a8a35..ac65cd744a14 100644
@@ -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
index 26a607f90dc8..b62919cadc50 100644
@@ -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
new file mode 100644
index 000000000000..3d879233681f
@@ -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
index c96ede90b6ad..97d6dedc217c 100755
@@ -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)
#123 lore raw

v7 cover Unifying LKL into UML

In reply to 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.

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)
#124 lore raw

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
index eb51fec75948..e41d31d0d875 100644
@@ -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
index 1cea46ff9bb7..09745b40c52d 100644
@@ -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
new file mode 100644
index 000000000000..a4711f1ef422
@@ -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
new file mode 100644
index 000000000000..e69de29bb2d1
Signature · 1 line
2.21.0 (Apple Git-122.2)
#125 lore raw

RFC v7 2/21 um: add os init and exit calls

In reply to Hajime Tazaki

From: 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
index c66de434a983..d09308330ca5 100644
@@ -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
index 48c0610d506e..5420aec411f4 100644
@@ -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
index 00141e70de56..e2cb76c03b25 100644
@@ -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)
maintainer
#126 lore raw

Re: [RFC v7 02/21] um: add os init and exit calls

arch/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

#127 lore raw

Re: [RFC v7 02/21] um: add os init and exit calls

Quoted 15 lines · Johannes Berg

arch/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?

Without the patch 04/21 um: host: implement os_initcalls and os_exitcalls, yes you're right.

Quoted 9 lines

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?

The intention is to define os_exitcalls() under tools/um so that the actual exitcalls is located in different ELF sections (we defined multiple __uml_exit_call for __UM_HOST__ and ! __UM_HOST__). Thus uml_cleanup() must see the symbol but give the place where actual function is defined at tools/um. Thus, this is __weak symbol-ed.

-- Hajime

#128 lore raw

RFC v7 3/21 um: move arch/um/os-Linux dir to tools/um/uml

In reply to Hajime Tazaki

This 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
index 09745b40c52d..8be7bc479442 100644
@@ -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
index 2a249f619467..ae96c83e312d 100644
@@ -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
similarity index 100%
rename from arch/um/os-Linux/drivers/ethertap_kern.c
rename to arch/um/drivers/ethertap_kern.c
arch/um/drivers/tuntap_kern.c renamed from arch/um/os-Linux/drivers/tuntap_kern.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/drivers/tuntap_kern.c
rename to arch/um/drivers/tuntap_kern.c
arch/um/include/shared/etap.h renamed from arch/um/os-Linux/drivers/etap.h +0 -0
similarity index 100%
rename from arch/um/os-Linux/drivers/etap.h
rename to arch/um/include/shared/etap.h
arch/um/include/shared/init.h +5 -0
index d09308330ca5..305789667584 100644
@@ -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
similarity index 100%
rename from arch/um/os-Linux/drivers/tuntap.h
rename to arch/um/include/shared/tuntap.h
arch/um/kernel/Makefile +1 -0
index 5aa882011e04..9b63831a69e1 100644
@@ -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
similarity index 100%
rename from arch/um/os-Linux/user_syms.c
rename to arch/um/kernel/user_syms.c
arch/um/os-Linux/Makefile deleted +0 -19
deleted file mode 100644
index 839915b8c31c..000000000000
@@ -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
deleted file mode 100644
index d79e75f1b69a..000000000000
@@ -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
index a63466ef7ef5..07b9b93ed817 100644
@@ -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
new file mode 100644
index 000000000000..c7a8eaa97d72
@@ -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
similarity index 100%
rename from arch/um/os-Linux/drivers/ethertap_user.c
rename to tools/um/uml/drivers/ethertap_user.c
tools/um/uml/drivers/tuntap_user.c renamed from arch/um/os-Linux/drivers/tuntap_user.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/drivers/tuntap_user.c
rename to tools/um/uml/drivers/tuntap_user.c
tools/um/uml/elf_aux.c renamed from arch/um/os-Linux/elf_aux.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/elf_aux.c
rename to tools/um/uml/elf_aux.c
tools/um/uml/execvp.c renamed from arch/um/os-Linux/execvp.c +0 -4
similarity index 98%
rename from arch/um/os-Linux/execvp.c
rename to tools/um/uml/execvp.c
index 84a0777c2a45..c105e0e7b778 100644
@@ -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
similarity index 100%
rename from arch/um/os-Linux/file.c
rename to tools/um/uml/file.c
tools/um/uml/helper.c renamed from arch/um/os-Linux/helper.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/helper.c
rename to tools/um/uml/helper.c
tools/um/uml/irq.c renamed from arch/um/os-Linux/irq.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/irq.c
rename to tools/um/uml/irq.c
tools/um/uml/main.c renamed from arch/um/os-Linux/main.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/main.c
rename to tools/um/uml/main.c
tools/um/uml/mem.c renamed from arch/um/os-Linux/mem.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/mem.c
rename to tools/um/uml/mem.c
tools/um/uml/process.c renamed from arch/um/os-Linux/process.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/process.c
rename to tools/um/uml/process.c
tools/um/uml/registers.c renamed from arch/um/os-Linux/registers.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/registers.c
rename to tools/um/uml/registers.c
tools/um/uml/sigio.c renamed from arch/um/os-Linux/sigio.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/sigio.c
rename to tools/um/uml/sigio.c
tools/um/uml/signal.c renamed from arch/um/os-Linux/signal.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/signal.c
rename to tools/um/uml/signal.c
tools/um/uml/skas/Build renamed from arch/um/os-Linux/skas/Makefile +1 -5
similarity index 56%
rename from arch/um/os-Linux/skas/Makefile
rename to tools/um/uml/skas/Build
index c4566e788815..5fc9d62df863 100644
@@ -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
similarity index 100%
rename from arch/um/os-Linux/skas/mem.c
rename to tools/um/uml/skas/mem.c
tools/um/uml/skas/process.c renamed from arch/um/os-Linux/skas/process.c +1 -2
similarity index 99%
rename from arch/um/os-Linux/skas/process.c
rename to tools/um/uml/skas/process.c
index 4fb877b99dde..fca6a08e81bd 100644
@@ -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
similarity index 100%
rename from arch/um/os-Linux/start_up.c
rename to tools/um/uml/start_up.c
tools/um/uml/time.c renamed from arch/um/os-Linux/time.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/time.c
rename to tools/um/uml/time.c
tools/um/uml/tty.c renamed from arch/um/os-Linux/tty.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/tty.c
rename to tools/um/uml/tty.c
tools/um/uml/umid.c renamed from arch/um/os-Linux/umid.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/umid.c
rename to tools/um/uml/umid.c
tools/um/uml/util.c renamed from arch/um/os-Linux/util.c +0 -0
similarity index 100%
rename from arch/um/os-Linux/util.c
rename to tools/um/uml/util.c
Signature · 1 line
2.21.0 (Apple Git-122.2)
maintainer
#129 lore raw

Re: [RFC v7 03/21] um: move arch/um/os-Linux dir to tools/um/uml

Quoted 3 lines · Hajime Tazaki

This 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).

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

#130 lore raw

Re: [RFC v7 03/21] um: move arch/um/os-Linux dir to tools/um/uml

Quoted 1 line · Johannes Berg

Hi Johannes,

Thank you for the review.

Quoted 5 lines · Hajime Tazaki
Quoted 3 lines

This 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).

Quoted 7 lines

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.

I see the os_*() calls as dependencies that the kernel uses. Sort of like calls into the hypervisor or firmware.

The current UML build is already partially split. USER_OBJS build with a different rule set than the rest of the kernel objects. IMHO this change just makes this more clear and streamlined, especially with regard to linking.

Quoted 7 lines
Quoted 3 lines
 tools/um/uml/Build                            | 48 +++++++++++++++++++
 tools/um/uml/drivers/Build                    | 10 ++++

Also, what's with the names here? What's wrong with "Makefile"?

We are using the same build system as the rest of the stuff in tools. Since it is building programs and libraries and not part of the kernel binary build, it is using a slightly different infrastructure, which is detailed in tools/build/Documentation/Build.txt

Quoted 5 lines

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.

Quoted 8 lines

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.

The reason for picking tools was that it already has the infrastructure to build programs and shared libraries and the fact that it is the only place in the kernel source tree where code is not built directly into the kernel binary.

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

maintainer
#131 lore raw

Re: [RFC v7 03/21] um: move arch/um/os-Linux dir to tools/um/uml

Quoted 10 lines · Octavian Purdila
Quoted 10 lines · Hajime Tazaki
Quoted 3 lines

This 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).

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.

Quoted 5 lines
Quoted 2 lines

For that reason, I don't really like this much.

I see the os_*() calls as dependencies that the kernel uses. Sort of like calls into the hypervisor or firmware.

Right.

Quoted 2 lines

The current UML build is already partially split. USER_OBJS build with a different rule set than the rest of the kernel objects.

Yes, that's true.

Quoted 3 lines

IMHO this
change just makes this more clear and streamlined, especially with regard to linking.

Well, maybe? But I actually tend to see this less as a question of (technical) convenience but semantics, and the tools are just not *meant* to be things that build a kernel, they're things to be used inside that kernel.

I dunno. Maybe the technical convenience should win, but OTOH the "contortions" that UML build goes through with USER_OBJS don't really seem bad enough to merit breaking the notion of what tools are?

Quoted 4 lines

We are using the same build system as the rest of the stuff in tools. Since it is building programs and libraries and not part of the kernel binary build, it is using a slightly different infrastructure, which is detailed in tools/build/Documentation/Build.txt

OK, thanks for the pointer, I hadn't seen that before.

Quoted 4 lines

The reason for picking tools was that it already has the infrastructure to build programs and shared libraries and the fact that it is the only place in the kernel source tree where code is not built directly into the kernel binary.

Yeah, but all of UML/LKL _is_ eventually built into the kernel binary (or library as it may be). Which is in a way exactly my objection.

You're looking at it the other way around I think - it seems that you're thinking the kernel binary is the vmlinux.a, and that's what the kernel's build system worries about; then the "vmlinux.so" (library mode) or "linux" (standalone mode - perhaps that's a good name?) is the eventual 'tool' that we build, using the previously built vmlinux.a.

But that really isn't how standalone mode works, and IMHO it also doesn't match what tools are today.

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#132 lore raw

Re: [RFC v7 03/21] um: move arch/um/os-Linux dir to tools/um/uml

Quoted 30 lines · Johannes Berg
Quoted 10 lines · Octavian Purdila
Quoted 10 lines · Hajime Tazaki
Quoted 3 lines

This 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).

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.

Quoted 5 lines
Quoted 2 lines

For that reason, I don't really like this much.

I see the os_*() calls as dependencies that the kernel uses. Sort of like calls into the hypervisor or firmware.

Right.

Quoted 2 lines

The current UML build is already partially split. USER_OBJS build with a different rule set than the rest of the kernel objects.

Yes, that's true.

Quoted 3 lines

IMHO this
change just makes this more clear and streamlined, especially with regard to linking.

Quoted 9 lines

Well, maybe? But I actually tend to see this less as a question of (technical) convenience but semantics, and the tools are just not *meant* to be things that build a kernel, they're things to be used inside that kernel.

I dunno. Maybe the technical convenience should win, but OTOH the "contortions" that UML build goes through with USER_OBJS don't really seem bad enough to merit breaking the notion of what tools are?

Half-joking, technically uml is not a kernel, it is a tool that simulates a kernel and it uses part of the Linux kernel to do that :)

Quoted 7 lines
Quoted 4 lines

We are using the same build system as the rest of the stuff in tools. Since it is building programs and libraries and not part of the kernel binary build, it is using a slightly different infrastructure, which is detailed in tools/build/Documentation/Build.txt

OK, thanks for the pointer, I hadn't seen that before.

Quoted 8 lines
Quoted 4 lines

The reason for picking tools was that it already has the infrastructure to build programs and shared libraries and the fact that it is the only place in the kernel source tree where code is not built directly into the kernel binary.

Yeah, but all of UML/LKL _is_ eventually built into the kernel binary (or library as it may be). Which is in a way exactly my objection.

Leaving the library/standalone build itself aside for a while, do you agree that the various tools we are building with library mode should be placed in tools? Things like lklfuse - mounting Linux filesystems with fuse, or lklhijack.so - a preload library that intercept network/file system calls and routes them through the library mode.

Quoted 6 lines

You're looking at it the other way around I think - it seems that you're thinking the kernel binary is the vmlinux.a, and that's what the kernel's build system worries about; then the "vmlinux.so" (library mode) or "linux" (standalone mode - perhaps that's a good name?) is the eventual 'tool' that we build, using the previously built vmlinux.a.

Correct, this is my perspective.

Quoted 3 lines

But that really isn't how standalone mode works, and IMHO it also doesn't match what tools are today.

What if we could use standalone mode for other purposes that would require creating a new binary in addition to the current linux binary?

maintainer
#133 lore raw

Re: [RFC v7 03/21] um: move arch/um/os-Linux dir to tools/um/uml

Quoted 5 lines · Octavian Purdila

Leaving the library/standalone build itself aside for a while, do you agree that the various tools we are building with library mode should be placed in tools? Things like lklfuse - mounting Linux filesystems with fuse, or lklhijack.so - a preload library that intercept network/file system calls and routes them through the library mode.

Yeah, I guess that makes sense. I realize the line gets blurry ...

OTOH, should these even live in the kernel tree? Almost seems like if the base lkl library is there, the other stuff might not really need to be, it's supposed to use the (stable) syscall API?

Dunno. Not sure "doesn't need to be" really is an argument for "shouldn't be" anyway.

Quoted 7 lines
Quoted 6 lines

You're looking at it the other way around I think - it seems that you're thinking the kernel binary is the vmlinux.a, and that's what the kernel's build system worries about; then the "vmlinux.so" (library mode) or "linux" (standalone mode - perhaps that's a good name?) is the eventual 'tool' that we build, using the previously built vmlinux.a.

Quoted 8 lines

Correct, this is my perspective.

Quoted 3 lines

But that really isn't how standalone mode works, and IMHO it also doesn't match what tools are today.

What if we could use standalone mode for other purposes that would require creating a new binary in addition to the current linux binary?

Anything specific you have in mind?

But I still think that "UML standalone 'linux' binary" is something that seems like the kernel build system should be able do? If only to avoid regressions from what we have now ...

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#134 lore raw

RFC v7 4/21 um: host: implement os_initcalls and os_exitcalls

In reply to Hajime Tazaki

From: 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
index ecf2f390fad2..4011b36fee7e 100644
@@ -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)
maintainer
#135 lore raw

Re: [RFC v7 04/21] um: host: implement os_initcalls and os_exitcalls

Quoted 2 lines · Hajime Tazaki

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.

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

#136 lore raw

Re: [RFC v7 04/21] um: host: implement os_initcalls and os_exitcalls

Quoted 7 lines · Johannes Berg
Quoted 2 lines · Hajime Tazaki

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.

Not a fan of that, I must say ...

Now I found that this patch should be together with the patch 02/21
um: add os init and exit calls. I will do that from next time.

Quoted 6 lines
Quoted 6 lines
tools/um/uml/util.c +6 -0
+extern void (*__start_os_exitcalls)(void);
+extern void (*__stop_os_exitcalls)(void);
+
+void os_exitcalls(void)
+{
+	exitcall_t *call;
Quoted 8 lines

tools/um/uml/util.c void os_warn(const char *fmt, ...) · line 199

Quoted 4 lines
tools/um/uml/util.c +4 -0
+
+	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.

Understand, I'll fix it.

Quoted 6 lines
Quoted 6 lines
tools/um/uml/util.c +6 -0
+}
+
+extern int (*__start_os_initcalls)(void);
+extern int (*__stop_os_initcalls)(void);
+
+int os_initcalls(void)
Quoted 8 lines

tools/um/uml/util.c void os_warn(const char *fmt, ...) · line 211

Quoted 6 lines
tools/um/uml/util.c +6 -0
+{
+	initcall_t *call;
+
+	call = &__stop_os_initcalls;
+	while (--call >= &__start_os_initcalls)
+		(*call)();

Same here.

Okay.

-- Hajime

#137 lore raw

RFC v7 5/21 um: move arch/x86/um/os-Linux to tools/um/uml/

In reply to Hajime Tazaki

Similar 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
index 77f70b969d14..25e9846b36a2 100644
@@ -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
deleted file mode 100644
index 253bfb8cb702..000000000000
@@ -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
index 07b9b93ed817..552ed5f1edae 100644
@@ -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
index ad93c6ad51fc..0d87d601bc06 100644
@@ -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
new file mode 100644
index 000000000000..16bbc7eb19d1
@@ -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
similarity index 100%
rename from arch/x86/um/os-Linux/mcontext.c
rename to tools/um/uml/x86/mcontext.c
tools/um/uml/x86/prctl.c renamed from arch/x86/um/os-Linux/prctl.c +0 -0
similarity index 100%
rename from arch/x86/um/os-Linux/prctl.c
rename to tools/um/uml/x86/prctl.c
tools/um/uml/x86/registers.c renamed from arch/x86/um/os-Linux/registers.c +0 -0
similarity index 100%
rename from arch/x86/um/os-Linux/registers.c
rename to tools/um/uml/x86/registers.c
tools/um/uml/x86/task_size.c renamed from arch/x86/um/os-Linux/task_size.c +0 -0
similarity index 100%
rename from arch/x86/um/os-Linux/task_size.c
rename to tools/um/uml/x86/task_size.c
tools/um/uml/x86/tls.c renamed from arch/x86/um/os-Linux/tls.c +0 -0
similarity index 100%
rename from arch/x86/um/os-Linux/tls.c
rename to tools/um/uml/x86/tls.c
Signature · 1 line
2.21.0 (Apple Git-122.2)
maintainer
#138 lore raw

Re: [RFC v7 05/21] um: move arch/x86/um/os-Linux to tools/um/uml/

Quoted 4 lines · Hajime Tazaki

Similar 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).

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

#139 lore raw

RFC v7 6/21 scritps: um: suppress warnings if SRCARCH=um

In reply to Hajime Tazaki

This 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
index dd554bd436cc..8890a0147012 100755
@@ -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)
maintainer
#140 lore raw

Re: [RFC v7 06/21] scritps: um: suppress warnings if SRCARCH=um

Quoted 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

#141 lore raw

Re: [RFC v7 06/21] scritps: um: suppress warnings if SRCARCH=um

Quoted 6 lines · Johannes Berg
Quoted 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.

Agree to rewrite the description.

Quoted 6 lines
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,

Although I didn't, this patch should Cc the maintainer of ./scripts/headers_install.sh. I thought this should be as a separate one, but I can Cc (in the commit message) to the commit that actual build happens if that helps to understand.

Quoted 1 line

and maybe only when actually building for NOMMU/LKL?

The standalone UML doesn't use the headers_install.sh script (AFAIK), so I think this would be okay.

-- Hajime

maintainer
#142 lore raw

Re: [RFC v7 06/21] scritps: um: suppress warnings if SRCARCH=um

Quoted 5 lines · Hajime Tazaki
Quoted 2 lines

and maybe only when actually building for NOMMU/LKL?

The standalone UML doesn't use the headers_install.sh script (AFAIK), so I think this would be okay.

Yes, I was more thinking in terms of documenting the purpose in the code, similar really to the argument I made elsewhere about "NOMMU" vs "LKL mode".

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#143 lore raw

RFC v7 7/21 um: extend arch_switch_to for alternate SUBARCH

In reply to 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.

---
 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
index 26b5e243d3fc..87a8cfa228ca 100644
@@ -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
index 2497bac56066..0f184710d4ca 100644
@@ -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
index 58f51667e2e4..2ef9474d2bd2 100644
@@ -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)
maintainer
#144 lore raw

Re: [RFC v7 07/21] um: extend arch_switch_to for alternate SUBARCH

Quoted 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

#145 lore raw

Re: [RFC v7 07/21] um: extend arch_switch_to for alternate SUBARCH

Quoted 10 lines · Johannes Berg
Quoted 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?

Agree.

The patch is particularly required by nommu mode because it uses previous task information to control the previous thread (e.g., down semaphore, terminate thread, clean up thread flags).

Something like this ?

-- Hajime

maintainer
#146 lore raw

Re: [RFC v7 07/21] um: extend arch_switch_to for alternate SUBARCH

Quoted 12 lines · Hajime Tazaki
Quoted 9 lines · Johannes Berg
Quoted 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?

Quoted 7 lines

Agree.

The patch is particularly required by nommu mode because it uses previous task information to control the previous thread (e.g., down semaphore, terminate thread, clean up thread flags).

Something like this ?

Well, still not sure I like "nommu" to refer to "library mode", but I'm also not sure that you can understand that without the context of how threads actually work in library mode?

Maybe even something vague like

Having access to the previous thread will be required in library mode for it to implement thread switching correctly.

would give some rationale?

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#147 lore raw

RFC v7 8/21 um: add nommu mode for UML library mode

In reply to Hajime Tazaki

This 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
new file mode 100644
index 000000000000..792d6005489e
@@ -0,0 +1 @@
+#
arch/um/nommu/Makefile.um new file +22 -0
new file mode 100644
index 000000000000..3808462d8283
@@ -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
new file mode 100644
index 000000000000..2532e1a0a0d1
@@ -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
new file mode 100644
index 000000000000..ea32a7d3cf1b
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0 */
arch/um/nommu/include/asm/atomic.h new file +11 -0
new file mode 100644
index 000000000000..63e2e16bda92
@@ -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
new file mode 100644
index 000000000000..a150cee41e75
@@ -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
new file mode 100644
index 000000000000..920a5fd26cad
@@ -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
new file mode 100644
index 000000000000..c101c078ef21
@@ -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
new file mode 100644
index 000000000000..edcf63edeed1
@@ -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
new file mode 100644
index 000000000000..a2e53984aabd
@@ -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
new file mode 100644
index 000000000000..b214410e9825
@@ -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
new file mode 100644
index 000000000000..a4496f482633
@@ -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(&current_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
new file mode 100644
index 000000000000..5608da95cb60
@@ -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
new file mode 100644
index 000000000000..0d55c408dac2
@@ -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
new file mode 100644
index 000000000000..852566ac2e52
@@ -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
new file mode 100644
index 000000000000..e7ad11a751cf
@@ -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
new file mode 100644
index 000000000000..b934ae7f5550
@@ -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
new file mode 100644
index 000000000000..58a366d9b5f0
@@ -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
new file mode 100644
index 000000000000..4a5c10d7521b
@@ -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
new file mode 100644
index 000000000000..49210742212d
@@ -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
new file mode 100644
index 000000000000..a004bffb7b8d
@@ -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
new file mode 100644
index 000000000000..b734012a74da
@@ -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
new file mode 100644
index 000000000000..86d5cb20fb9f
@@ -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
new file mode 100644
index 000000000000..2245d3d24120
@@ -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)
maintainer
#148 lore raw

Re: [RFC v7 08/21] um: add nommu mode for UML library mode

Quoted 2 lines · Hajime Tazaki

This patch introduces the nommu operation with UML code so that host interface can be shrineked for broader environments support.

shrunk

Quoted 1 line

The nommu mode is implemneted as SUBARCH of arch/um, which places at

implemented

Quoted 32 lines

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
Quoted 1 line

`-- scripts added a script for header installation

That seems awkward. Might be nice now for "as little changes as possible", but eventually it seems it would be better to separate that out into arch/um/{common,nommu,mmu}/ or something like that?

Or perhaps something like

	arch/um/{common,lkl,full}

or something? Not sure I like 'full' though. 'vm'? Hmm.

(also, scripts/ doesn't exist in this patch?)

arch/um/nommu/Makefile line 1

Quoted 3 lines

+++ b/arch/um/nommu/Makefile

arch/um/nommu/Makefile new file +1 -0
@@ -0,0 +1 @@
+#

hmm? maybe add a comment why an empty makefile is needed.

Quoted 5 lines
arch/um/nommu/Makefile.um new file +0 -0
new file mode 100644
index 000000000000..3808462d8283

[...]

arch/um/nommu/Makefile.um line 8

Quoted 5 lines
arch/um/nommu/Makefile.um new file +5 -0
+ifeq ($(shell uname -s), Linux)
+NPROC=$(shell nproc)
+else # e.g., FreeBSD
+NPROC=$(shell sysctl -n hw.ncpu)
+endif

That seems very inappropriate here.

arch/um/nommu/Makefile.um line 15

Quoted 7 lines
arch/um/nommu/Makefile.um new file +7 -0
+
+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))) \

Yeah ... just don't.

arch/um/nommu/include/asm/atomic64.h

Quoted 18 lines

+++ b/arch/um/nommu/include/asm/atomic.h

arch/um/nommu/Makefile.um 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 +0 -0
new file mode 100644
index 000000000000..949360dea7af

That doesn't make sense to me, you can control CONFIG_GENERIC_ATOMIC64 to be on, and don't need the ifdef and this file?

Quoted 7 lines
arch/um/nommu/include/asm/bitsperlong.h new file +1 -0
new file mode 100644
index 000000000000..a150cee41e75
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */

arch/um/nommu/include/asm/bitsperlong.h line 11

Quoted 10 lines
arch/um/nommu/include/asm/bitsperlong.h new file +10 -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

That's very similar to the contents of include/asm- generic/bitsperlong.h, add comments why it's needed?

arch/um/nommu/include/asm/byteorder.h line 7

Quoted 13 lines
arch/um/nommu/include/asm/byteorder.h new file +7 -0
new file mode 100644
index 000000000000..920a5fd26cad
@@ -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

Not sure why this file even exists, it doesn't for any other arch (except for h8300 which seems odd).

arch/um/nommu/include/asm/elf.h line 5

Quoted 11 lines
arch/um/nommu/include/asm/elf.h new file +5 -0
new file mode 100644
index 000000000000..edcf63edeed1
@@ -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

Please add a comment ...

arch/um/nommu/include/asm/elf.h line 14

Quoted 8 lines
arch/um/nommu/include/asm/elf.h new file +8 -0
+#ifdef CONFIG_64BIT
+#define ELF_CLASS ELFCLASS64
+#else
+#define ELF_CLASS ELFCLASS32
+#endif
+
+#define elf_gregset_t long
+#define elf_fpregset_t double

Also here.

Quoted 7 lines
arch/um/nommu/include/asm/elf.h new file +7 -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)

arch/um/nommu/include/asm/elf.h

Quoted 10 lines
arch/um/nommu/include/asm/elf.h new file +10 -0
+{
+	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(&current_thread_info()->task->thread.arch.sched_jb,
+				     schedule);
+	} else {
+		lkl_bug("%s can be used only for host task", __func__);
+	}
+}

What's "thread_sched_jb"? Doesn't really seem to exist? Neither does "TIF_SCHED_JB", at least in my kernel?

Looks like that's added by a later patch, should probably then add this file also only later so it's actually consistent and one can review all the pieces together.

arch/um/nommu/include/asm/elf.h line 6

Quoted 8 lines

+++ b/arch/um/nommu/include/uapi/asm/Kbuild

arch/um/nommu/include/asm/elf.h 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

Also doesn't exist yet.

Quoted 1 line

+++ b/arch/um/nommu/um/delay.c

why the double um/ path?

arch/um/nommu/include/asm/elf.h

Quoted 3 lines
arch/um/nommu/include/asm/elf.h new file +3 -0
+/* skas/process.c */
+void halt_skas(void)
+{}

nit: missing blank line after this

arch/um/nommu/include/asm/elf.h

Quoted 11 lines
arch/um/nommu/include/asm/elf.h new file +11 -0
+int is_skas_winch(int pid, int fd, void *data)
+{
+	return 0;
+}
+void reboot_skas(void)
+{}
+
+int __init start_uml(void)
+{
+	return 0;
+}

That seems odd?

Might be better to have an own os.h, or split that into os-uml.h and os-lkl.h or so?

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#149 lore raw

Re: [RFC v7 08/21] um: add nommu mode for UML library mode

Hello Johannes,

Quoted 10 lines · Johannes Berg
Quoted 2 lines · Hajime Tazaki

This patch introduces the nommu operation with UML code so that host interface can be shrineked for broader environments support.

shrunk

Quoted 1 line

The nommu mode is implemneted as SUBARCH of arch/um, which places at

implemented

thanks; will fix both in the next round.

Quoted 38 lines
Quoted 32 lines

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
Quoted 1 line

`-- scripts added a script for header installation

That seems awkward. Might be nice now for "as little changes as possible", but eventually it seems it would be better to separate that out into arch/um/{common,nommu,mmu}/ or something like that?

Quoted 5 lines

Or perhaps something like

	arch/um/{common,lkl,full}

or something? Not sure I like 'full' though. 'vm'? Hmm.

(I will leave this to the other thread if any)

Quoted 7 lines

(also, scripts/ doesn't exist in this patch?)

arch/um/nommu/Makefile line 1

Quoted 3 lines

+++ b/arch/um/nommu/Makefile

arch/um/nommu/Makefile new file +1 -0
@@ -0,0 +1 @@
+#

hmm? maybe add a comment why an empty makefile is needed.

Thanks, we will.

Quoted 8 lines
Quoted 5 lines
arch/um/nommu/Makefile.um new file +0 -0
new file mode 100644
index 000000000000..3808462d8283

[...]

Quoted 7 lines

arch/um/nommu/Makefile.um line 8

Quoted 5 lines
arch/um/nommu/Makefile.um new file +5 -0
+ifeq ($(shell uname -s), Linux)
+NPROC=$(shell nproc)
+else # e.g., FreeBSD
+NPROC=$(shell sysctl -n hw.ncpu)
+endif

That seems very inappropriate here.

Will cut the FreeBSD part.

Quoted 9 lines

arch/um/nommu/Makefile.um line 15

Quoted 7 lines
arch/um/nommu/Makefile.um new file +7 -0
+
+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))) \

Yeah ... just don't.

Will clean up this part.

Quoted 13 lines
Quoted 13 lines

+++ b/arch/um/nommu/include/asm/atomic.h

arch/um/nommu/Makefile.um 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
Quoted 8 lines

arch/um/nommu/include/asm/atomic64.h

Quoted 5 lines
arch/um/nommu/include/asm/atomic64.h new file +0 -0
new file mode 100644
index 000000000000..949360dea7af

That doesn't make sense to me, you can control CONFIG_GENERIC_ATOMIC64 to be on, and don't need the ifdef and this file?

We were suggested to not use GENERIC_ATOMIC64 on 64bit build during our v3 patchset. So we actually control CONFIG_GENERIC_ATOMIC64 to be on only when !64BIT, and thus need atomic64.h for the 64BIT build.

https://lwn.net/ml/linux-arch/[email protected]/

Quoted 12 lines
Quoted 12 lines
arch/um/nommu/include/asm/bitsperlong.h new file +6 -0
new file mode 100644
index 000000000000..a150cee41e75
@@ -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>
+
Quoted 8 lines

arch/um/nommu/include/asm/bitsperlong.h line 11

Quoted 5 lines
arch/um/nommu/include/asm/bitsperlong.h new file +5 -0
+#define BITS_PER_LONG __BITS_PER_LONG
+
+#define BITS_PER_LONG_LONG 64
+
+#endif

That's very similar to the contents of include/asm- generic/bitsperlong.h, add comments why it's needed?

thanks, it seems that this is unnecessary now. will fix them.

Quoted 8 lines
Quoted 8 lines
arch/um/nommu/include/asm/byteorder.h new file +2 -0
new file mode 100644
index 000000000000..920a5fd26cad
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __UM_NOMMU_BYTEORDER_H
Quoted 8 lines

arch/um/nommu/include/asm/byteorder.h line 7

Quoted 5 lines
arch/um/nommu/include/asm/byteorder.h new file +5 -0
+#define __UM_NOMMU_BYTEORDER_H
+
+#include <uapi/asm/byteorder.h>
+
+#endif

Not sure why this file even exists, it doesn't for any other arch (except for h8300 which seems odd).

You're right. We will remove this.

Quoted 14 lines

arch/um/nommu/include/asm/elf.h line 5

Quoted 11 lines
arch/um/nommu/include/asm/elf.h new file +5 -0
new file mode 100644
index 000000000000..edcf63edeed1
@@ -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

Please add a comment ...

Quoted 10 lines

arch/um/nommu/include/asm/elf.h line 14

Quoted 8 lines
arch/um/nommu/include/asm/elf.h new file +8 -0
+#ifdef CONFIG_64BIT
+#define ELF_CLASS ELFCLASS64
+#else
+#define ELF_CLASS ELFCLASS32
+#endif
+
+#define elf_gregset_t long
+#define elf_fpregset_t double

Also here.

thanks, will add the comments.

Quoted 21 lines
Quoted 7 lines
arch/um/nommu/include/asm/elf.h new file +7 -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)

arch/um/nommu/include/asm/elf.h

Quoted 10 lines
arch/um/nommu/include/asm/elf.h new file +10 -0
+{
+	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(&current_thread_info()->task->thread.arch.sched_jb,
+				     schedule);
+	} else {
+		lkl_bug("%s can be used only for host task", __func__);
+	}
+}

What's "thread_sched_jb"? Doesn't really seem to exist? Neither does "TIF_SCHED_JB", at least in my kernel?

Quoted 3 lines

Looks like that's added by a later patch, should probably then add this file also only later so it's actually consistent and one can review all the pieces together.

I understand. I will move this file to the later patch (11/21).

Quoted 10 lines

arch/um/nommu/include/asm/elf.h line 6

Quoted 8 lines

+++ b/arch/um/nommu/include/uapi/asm/Kbuild

arch/um/nommu/include/asm/elf.h 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

Also doesn't exist yet.

The message is incorrect since uapi header infra has changed. This also applies to the comment in arch/um/nommu/include/asm/Kbuild.

Will fix both in the next round.

Quoted 3 lines
Quoted 1 line

+++ b/arch/um/nommu/um/delay.c

why the double um/ path?

This is because now in arch/um/Makefile,

- SUBARCH := um/nommu
- HEADER_ARCH := $(SUBARCH)
- HOST_DIR := arch/$(HEADER_ARCH)
- core-y += $(HOST_DIR)/um

the last line expands as arch/um/nommu/um.

Quoted 5 lines

arch/um/nommu/include/asm/elf.h

Quoted 3 lines
arch/um/nommu/include/asm/elf.h new file +3 -0
+/* skas/process.c */
+void halt_skas(void)
+{}

nit: missing blank line after this

will fix this and other parts of the whole patchset.

Quoted 14 lines

arch/um/nommu/include/asm/elf.h

Quoted 11 lines
arch/um/nommu/include/asm/elf.h new file +11 -0
+int is_skas_winch(int pid, int fd, void *data)
+{
+	return 0;
+}
+void reboot_skas(void)
+{}
+
+int __init start_uml(void)
+{
+	return 0;
+}

That seems odd?

Quoted 2 lines

Might be better to have an own os.h, or split that into os-uml.h and os-lkl.h or so?

Okay, we will think about this.

-- Hajime

maintainer
#150 lore raw

Re: [RFC v7 08/21] um: add nommu mode for UML library mode

Quoted 13 lines · Hajime Tazaki
Quoted 5 lines
Quoted 2 lines

+++ b/arch/um/nommu/Makefile.um

[...]

Quoted 7 lines

arch/um/nommu/Makefile.um line 8

Quoted 5 lines
arch/um/nommu/Makefile.um new file +5 -0
+ifeq ($(shell uname -s), Linux)
+NPROC=$(shell nproc)
+else # e.g., FreeBSD
+NPROC=$(shell sysctl -n hw.ncpu)
+endif

That seems very inappropriate here.

Quoted 1 line

Will cut the FreeBSD part.

But even the NPROC and -j flag mangling seems ... awful?

Quoted 11 lines
Quoted 5 lines

arch/um/nommu/include/asm/atomic64.h

Quoted 2 lines
arch/um/nommu/include/asm/atomic64.h new file +0 -0

That doesn't make sense to me, you can control CONFIG_GENERIC_ATOMIC64 to be on, and don't need the ifdef and this file?

We were suggested to not use GENERIC_ATOMIC64 on 64bit build during our v3 patchset. So we actually control CONFIG_GENERIC_ATOMIC64 to be on only when !64BIT, and thus need atomic64.h for the 64BIT build.

https://lwn.net/ml/linux-arch/[email protected]/

Well, yeah, but your architecture _is_ a piece of crap in needing atomic64 emulation? :-)

How about just using the real atomic64 implementation like UML normally does? I mean, falling back to the actual underlying CPU. Or even gcc intrinsics?

You've basically re-implemented CONFIG_GENERIC_ATOMIC64, so perhaps you've hidden it from PeterZ's view now because you're no longer touching the real generic atomic64 (which is for 32-bit machines), but that doesn't actually make this any *better*. Arguably *worse* since you've just copied it ...

Quoted 4 lines
Quoted 3 lines
Quoted 1 line

+++ b/arch/um/nommu/um/delay.c

why the double um/ path?

Quoted 8 lines

This is because now in arch/um/Makefile,

- SUBARCH := um/nommu
- HEADER_ARCH := $(SUBARCH)
- HOST_DIR := arch/$(HEADER_ARCH)
- core-y += $(HOST_DIR)/um

the last line expands as arch/um/nommu/um.

But is there a reason for it? Couldn't it be changed?

Anyway, we're still debating the whole build system and layout so not much point in going into the details now ...

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#151 lore raw

Re: [RFC v7 08/21] um: add nommu mode for UML library mode

Hello,

sorry for the late response.

Quoted 15 lines · Johannes Berg
Quoted 13 lines · Hajime Tazaki
Quoted 12 lines
Quoted 2 lines

+++ b/arch/um/nommu/Makefile.um

[...]

arch/um/nommu/Makefile.um line 8

Quoted 5 lines
arch/um/nommu/Makefile.um new file +5 -0
+ifeq ($(shell uname -s), Linux)
+NPROC=$(shell nproc)
+else # e.g., FreeBSD
+NPROC=$(shell sysctl -n hw.ncpu)
+endif

That seems very inappropriate here.

Quoted 3 lines
Quoted 1 line

Will cut the FreeBSD part.

But even the NPROC and -j flag mangling seems ... awful?

Okay, we won't use the -j flag at this place.

Quoted 19 lines
Quoted 11 lines
Quoted 5 lines

arch/um/nommu/include/asm/atomic64.h

Quoted 2 lines
arch/um/nommu/include/asm/atomic64.h new file +0 -0

That doesn't make sense to me, you can control CONFIG_GENERIC_ATOMIC64 to be on, and don't need the ifdef and this file?

We were suggested to not use GENERIC_ATOMIC64 on 64bit build during our v3 patchset. So we actually control CONFIG_GENERIC_ATOMIC64 to be on only when !64BIT, and thus need atomic64.h for the 64BIT build.

https://lwn.net/ml/linux-arch/[email protected]/

Well, yeah, but your architecture _is_ a piece of crap in needing atomic64 emulation? :-)

How about just using the real atomic64 implementation like UML normally does? I mean, falling back to the actual underlying CPU. Or even gcc intrinsics?

Quoted 5 lines

You've basically re-implemented CONFIG_GENERIC_ATOMIC64, so perhaps you've hidden it from PeterZ's view now because you're no longer touching the real generic atomic64 (which is for 32-bit machines), but that doesn't actually make this any *better*. Arguably *worse* since you've just copied it ...

We're trying to reimplement atomic64 ops with gcc builtins.

We're now trying to address all of comments we got, and will get here back once we have done.

-- Hajime

#152 lore raw

RFC v7 9/21 um: nommu: host interface

In reply to Hajime Tazaki

This 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
new file mode 100644
index 000000000000..f52423cc4ced
@@ -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
new file mode 100644
index 000000000000..d3dad11b459e
@@ -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)
maintainer
#153 lore raw

Re: [RFC v7 09/21] um: nommu: host interface

Quoted 4 lines · Hajime Tazaki

This 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.

I kinda find patches like this very pointless ... you see nothing, and can't really say anything. Maybe add the infra with the first user?

Quoted 1 line

+/* Defined in {posix,nt}-host.c */

That doesn't exist either yet ...

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#154 lore raw

Re: [RFC v7 09/21] um: nommu: host interface

Quoted 7 lines · Johannes Berg
Quoted 4 lines · Hajime Tazaki

This 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.

Quoted 7 lines

I kinda find patches like this very pointless ... you see nothing, and can't really say anything. Maybe add the infra with the first user?

Quoted 1 line

+/* Defined in {posix,nt}-host.c */

That doesn't exist either yet ...

Noted, we will fix it in the next patch series.

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#155 lore raw

RFC v7 10/21 um: nommu: memory handling

In reply to Hajime Tazaki

nommu 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
index 5b072aba5b65..c06d6cb67dd7 100644
@@ -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
index 17ddd4edf875..4b06c29ae830 100644
@@ -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
index 95af12e82a32..c9d5e487ac6b 100644
@@ -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
index def376194dce..7e506d5406e3 100644
@@ -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
index fe66d659acad..95db8f06d295 100644
@@ -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
index d3dad11b459e..5253c3f8de0e 100644
@@ -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)
maintainer
#156 lore raw

Re: [RFC v7 10/21] um: nommu: memory handling

Quoted 7 lines · Hajime Tazaki

* These operations must be provided by a host library or by the application
* itself.
*
+ * @mem_alloc - allocate memory
+ * @mem_free - free memory
+ *

Actual kernel-doc would be nicer.

arch/um/nommu/um/bootmem.c line 46

Quoted 5 lines
arch/um/nommu/um/bootmem.c new file +5 -0
+	empty_zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
+	memset((void *)empty_zero_page, 0, PAGE_SIZE);
+
+	{
+		unsigned long zones_size[MAX_NR_ZONES] = {0, };

Hmm, what's with the extra scope?

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#157 lore raw

Re: [RFC v7 10/21] um: nommu: memory handling

Quoted 12 lines · Johannes Berg
Quoted 7 lines · Hajime Tazaki

* These operations must be provided by a host library or by the application
* itself.
*
+ * @mem_alloc - allocate memory
+ * @mem_free - free memory
+ *

Actual kernel-doc would be nicer.

Thank you, we will make sure to use the proper kernel doc throughout all patches for the next patch series

Quoted 8 lines

arch/um/nommu/um/bootmem.c line 46

Quoted 5 lines
arch/um/nommu/um/bootmem.c new file +5 -0
+     empty_zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
+     memset((void *)empty_zero_page, 0, PAGE_SIZE);
+
+     {
+             unsigned long zones_size[MAX_NR_ZONES] = {0, };

Hmm, what's with the extra scope?

Will clean it up in the next patch series, thank you.

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#158 lore raw

RFC v7 11/21 um: nommu: kernel thread support

In reply to Hajime Tazaki

nommu 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
index 4c19ce4c49f1..433584f6b9d0 100644
@@ -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
index 87a8cfa228ca..432edcbb5eea 100644
@@ -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)
maintainer
#159 lore raw

Re: [RFC v7 11/21] um: nommu: kernel thread support

Quoted 1 line · Hajime Tazaki

nommu mode does not support user processes

I find this really confusing. I'm not sure why you ended up calling this "nommu mode", but there *are* (still) (other) nommu arches, and they *do* support userspace processes.

Isn't this really just "LKL mode" or something like that?

arch/um/include/asm/thread_info.h static inline struct thread_info *current_thread_info(void) · line 89

Quoted 7 lines

#define TIF_SYSCALL_TRACE 0 /* syscall trace active */

arch/um/include/asm/thread_info.h +2 -0
@@ -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

It'd be nice to document what those mean, and even what "JB" means ... I saw something about "jump buffer" somewhere, but I have no idea why that should be a thread flag.

Quoted 29 lines
arch/um/nommu/include/uapi/asm/host_ops.h +25 -0
@@ -16,11 +16,65 @@ struct lkl_jmp_buf {
  * These operations must be provided by a host library or by the application
  * itself.
  *
+ * @sem_alloc - allocate a host semaphore an initialize it to count
+ * @sem_free - free a host semaphore
+ * @sem_up - perform an up operation on the semaphore
+ * @sem_down - perform a down operation on the semaphore
+ *
+ * @mutex_alloc - allocate and initialize a host mutex; the recursive parameter
+ * determines if the mutex is recursive or not
+ * @mutex_free - free a host mutex
+ * @mutex_lock - acquire the mutex
+ * @mutex_unlock - release the mutex
+ *
+ * @thread_create - create a new thread and run f(arg) in its context; returns a
+ * thread handle or 0 if the thread could not be created
+ * @thread_detach - on POSIX systems, free up resources held by
+ * pthreads. Noop on Win32.
+ * @thread_exit - terminates the current thread
+ * @thread_join - wait for the given thread to terminate. Returns 0
+ * for success, -1 otherwise
+ *
+ * @gettid - returns the host thread id of the caller, which need not
+ * be the same as the handle returned by thread_create
+ *
+ * @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

arch/um/nommu/include/uapi/asm/host_ops.h struct lkl_jmp_buf { · line 53

Quoted 10 lines
arch/um/nommu/include/uapi/asm/host_ops.h +8 -0
+ * point
+ *
+ * NOTE: we can't return from jmp_buf_set before calling jmp_buf_longjmp or
+ * otherwise the saved context (stack) is not going to be valid, so we must pass
+ * the function that will eventually call longjmp here
+ *
+ * @jmp_buf_longjmp - perform a jump back to the saved jump buffer
+ *
  * @mem_alloc - allocate memory
  * @mem_free - free memory

again, kernel-doc.

But I'm starting to doubt the value of having this struct at all. Care you explain? You're doing everything else already with weak functions, and you can't very well have _two_ hosts compiled anyway, so what's the point?

IOW, why isn't this just

void lkl_sem_free(struct lkl_sem *sem);
void lkl_sem_up(struct lkl_sem *sem);
...

and then posix-host.c just includes the header file and implements those functions?

I don't see any reason for this to be allowed to have multiple variants linked and then picking them at runtime?

arch/um/nommu/um/cpu.c line 23

Quoted 2 lines
arch/um/nommu/um/cpu.c new file +2 -0
+/*
+ * This structure is used to get access to the "LKL CPU" that allows us to run

Are you trying to implement SMP? This seems ... rather complex?

Quoted 169 lines
arch/um/nommu/um/cpu.c new file +169 -0
+ * Linux code. Because we have to deal with various synchronization requirements
+ * between idle thread, system calls, interrupts, "reentrancy", CPU shutdown,
+ * imbalance wake up (i.e. acquire the CPU from one thread and release it from
+ * another), we can't use a simple synchronization mechanism such as (recursive)
+ * mutex or semaphore. Instead, we use a mutex and a bunch of status data plus a
+ * semaphore.
+ */
+static struct lkl_cpu {
+	/* lock that protects the CPU status data */
+	struct lkl_mutex *lock;
+	/*
+	 * Since we must free the cpu lock during shutdown we need a
+	 * synchronization algorithm between lkl_cpu_shutdown() and the CPU
+	 * access functions since lkl_cpu_get() gets called from thread
+	 * destructor callback functions which may be scheduled after
+	 * lkl_cpu_shutdown() has freed the cpu lock.
+	 *
+	 * An atomic counter is used to keep track of the number of running
+	 * CPU access functions and allow the shutdown function to wait for
+	 * them.
+	 *
+	 * The shutdown functions adds MAX_THREADS to this counter which allows
+	 * the CPU access functions to check if the shutdown process has
+	 * started.
+	 *
+	 * This algorithm assumes that we never have more the MAX_THREADS
+	 * requesting CPU access.
+	 */
+	#define MAX_THREADS 1000000
+	unsigned int shutdown_gate;
+	bool irqs_pending;
+	/* no of threads waiting the CPU */
+	unsigned int sleepers;
+	/* no of times the current thread got the CPU */
+	unsigned int count;
+	/* current thread that owns the CPU */
+	lkl_thread_t owner;
+	/* semaphore for threads waiting the CPU */
+	struct lkl_sem *sem;
+	/* semaphore used for shutdown */
+	struct lkl_sem *shutdown_sem;
+} cpu;
+
+static int __cpu_try_get_lock(int n)
+{
+	lkl_thread_t self;
+
+	if (__sync_fetch_and_add(&cpu.shutdown_gate, n) >= MAX_THREADS)
+		return -2;
+
+	lkl_ops->mutex_lock(cpu.lock);
+
+	if (cpu.shutdown_gate >= MAX_THREADS)
+		return -1;
+
+	self = lkl_ops->thread_self();
+
+	if (cpu.owner && !lkl_ops->thread_equal(cpu.owner, self))
+		return 0;
+
+	cpu.owner = self;
+	cpu.count++;
+
+	return 1;
+}
+
+static void __cpu_try_get_unlock(int lock_ret, int n)
+{
+	if (lock_ret >= -1)
+		lkl_ops->mutex_unlock(cpu.lock);
+	__sync_fetch_and_sub(&cpu.shutdown_gate, n);
+}
+
+void lkl_cpu_change_owner(lkl_thread_t owner)
+{
+	lkl_ops->mutex_lock(cpu.lock);
+	if (cpu.count > 1)
+		lkl_bug("bad count while changing owner\n");
+	cpu.owner = owner;
+	lkl_ops->mutex_unlock(cpu.lock);
+}
+
+int lkl_cpu_get(void)
+{
+	int ret;
+
+	ret = __cpu_try_get_lock(1);
+
+	while (ret == 0) {
+		cpu.sleepers++;
+		__cpu_try_get_unlock(ret, 0);
+		lkl_ops->sem_down(cpu.sem);
+		ret = __cpu_try_get_lock(0);
+	}
+
+	__cpu_try_get_unlock(ret, 1);
+
+	return ret;
+}
+
+void lkl_cpu_put(void)
+{
+	lkl_ops->mutex_lock(cpu.lock);
+
+	if (!cpu.count || !cpu.owner ||
+	    !lkl_ops->thread_equal(cpu.owner, lkl_ops->thread_self()))
+		lkl_bug("%s: unbalanced put\n", __func__);
+
+	while (cpu.irqs_pending && !irqs_disabled()) {
+		cpu.irqs_pending = false;
+		lkl_ops->mutex_unlock(cpu.lock);
+		run_irqs();
+		lkl_ops->mutex_lock(cpu.lock);
+	}
+
+	if (test_ti_thread_flag(current_thread_info(), TIF_HOST_THREAD) &&
+	    !single_task_running() && cpu.count == 1) {
+		if (in_interrupt())
+			lkl_bug("%s: in interrupt\n", __func__);
+		lkl_ops->mutex_unlock(cpu.lock);
+		thread_sched_jb();
+		return;
+	}
+
+	if (--cpu.count > 0) {
+		lkl_ops->mutex_unlock(cpu.lock);
+		return;
+	}
+
+	if (cpu.sleepers) {
+		cpu.sleepers--;
+		lkl_ops->sem_up(cpu.sem);
+	}
+
+	cpu.owner = 0;
+
+	lkl_ops->mutex_unlock(cpu.lock);
+}
+
+int lkl_cpu_try_run_irq(int irq)
+{
+	int ret;
+
+	ret = __cpu_try_get_lock(1);
+	if (!ret) {
+		set_irq_pending(irq);
+		cpu.irqs_pending = true;
+	}
+	__cpu_try_get_unlock(ret, 1);
+
+	return ret;
+}
+
+static void lkl_cpu_shutdown(void)
+{
+	__sync_fetch_and_add(&cpu.shutdown_gate, MAX_THREADS);
+}
+__uml_exitcall(lkl_cpu_shutdown);
+
+void lkl_cpu_wait_shutdown(void)
+{
+	lkl_ops->sem_down(cpu.shutdown_sem);
+	lkl_ops->sem_free(cpu.shutdown_sem);
+}
+
+static void lkl_cpu_cleanup(bool shutdown)
+{
+	while (__sync_fetch_and_add(&cpu.shutdown_gate, 0) > MAX_THREADS)
+		;

arch/um/nommu/um/cpu.c line 202

Quoted 10 lines
arch/um/nommu/um/cpu.c new file +10 -0
+
+	if (shutdown)
+		lkl_ops->sem_up(cpu.shutdown_sem);
+	else if (cpu.shutdown_sem)
+		lkl_ops->sem_free(cpu.shutdown_sem);
+	if (cpu.sem)
+		lkl_ops->sem_free(cpu.sem);
+	if (cpu.lock)
+		lkl_ops->mutex_free(cpu.lock);
+}

Yeah, what? That's an incomprehensible piece of code. At least add comments, if it _really_ is necessary?

arch/um/nommu/um/cpu.c line 221

Quoted 4 lines
arch/um/nommu/um/cpu.c new file +4 -0
+#ifdef doesntwork
+	/* switch to idle_host_task */
+	wakeup_idle_host_task();
+#endif

Well ...

Quoted 4 lines

+/**
+ * This is called before the kernel initializes, so no kernel calls (including
+ * printk) can't be made yet.
+ */

not kernel-doc

try to compile with W=1 :)

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#160 lore raw

Re: [RFC v7 11/21] um: nommu: kernel thread support

Quoted 10 lines · Johannes Berg
Quoted 1 line · Hajime Tazaki

nommu mode does not support user processes

I find this really confusing. I'm not sure why you ended up calling this "nommu mode", but there *are* (still) (other) nommu arches, and they *do* support userspace processes.

Isn't this really just "LKL mode" or something like that?

This is a very good point, while some other patches make sense in the nommu mode, this one does not - it is rather needed because of the "library mode".

Not sure what we can do other than creating a new "library mode" in addition to the "nommu mode". Any suggestions?

Quoted 65 lines

arch/um/include/asm/thread_info.h static inline struct thread_info *current_thread_info(void) · line 89

Quoted 7 lines

#define TIF_SYSCALL_TRACE 0 /* syscall trace active */

arch/um/include/asm/thread_info.h +2 -0
@@ -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

It'd be nice to document what those mean, and even what "JB" means ... I saw something about "jump buffer" somewhere, but I have no idea why that should be a thread flag.

Quoted 29 lines
arch/um/nommu/include/uapi/asm/host_ops.h +25 -0
@@ -16,11 +16,65 @@ struct lkl_jmp_buf {
  * These operations must be provided by a host library or by the application
  * itself.
  *
+ * @sem_alloc - allocate a host semaphore an initialize it to count
+ * @sem_free - free a host semaphore
+ * @sem_up - perform an up operation on the semaphore
+ * @sem_down - perform a down operation on the semaphore
+ *
+ * @mutex_alloc - allocate and initialize a host mutex; the recursive parameter
+ * determines if the mutex is recursive or not
+ * @mutex_free - free a host mutex
+ * @mutex_lock - acquire the mutex
+ * @mutex_unlock - release the mutex
+ *
+ * @thread_create - create a new thread and run f(arg) in its context; returns a
+ * thread handle or 0 if the thread could not be created
+ * @thread_detach - on POSIX systems, free up resources held by
+ * pthreads. Noop on Win32.
+ * @thread_exit - terminates the current thread
+ * @thread_join - wait for the given thread to terminate. Returns 0
+ * for success, -1 otherwise
+ *
+ * @gettid - returns the host thread id of the caller, which need not
+ * be the same as the handle returned by thread_create
+ *
+ * @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

arch/um/nommu/include/uapi/asm/host_ops.h struct lkl_jmp_buf { · line 53

Quoted 10 lines
arch/um/nommu/include/uapi/asm/host_ops.h +8 -0
+ * point
+ *
+ * NOTE: we can't return from jmp_buf_set before calling jmp_buf_longjmp or
+ * otherwise the saved context (stack) is not going to be valid, so we must pass
+ * the function that will eventually call longjmp here
+ *
+ * @jmp_buf_longjmp - perform a jump back to the saved jump buffer
+ *
  * @mem_alloc - allocate memory
  * @mem_free - free memory

again, kernel-doc.

But I'm starting to doubt the value of having this struct at all. Care you explain? You're doing everything else already with weak functions, and you can't very well have _two_ hosts compiled anyway, so what's the point?

IOW, why isn't this just

void lkl_sem_free(struct lkl_sem *sem);
void lkl_sem_up(struct lkl_sem *sem);
...

Quoted 6 lines

and then posix-host.c just includes the header file and implements those functions?

I don't see any reason for this to be allowed to have multiple variants linked and then picking them at runtime?

We could try that and see how it goes. This was baked liked this long time ago, when we wanted to support Windows and there was no proper support for weak functions in mingw for PE/COFF (it still not supported but at least we do have a few patches that fix that).

Quoted 179 lines

arch/um/nommu/um/cpu.c line 23

Quoted 2 lines
arch/um/nommu/um/cpu.c new file +2 -0
+/*
+ * This structure is used to get access to the "LKL CPU" that allows us to run

Are you trying to implement SMP? This seems ... rather complex?

Quoted 174 lines
arch/um/nommu/um/cpu.c new file +174 -0
+ * Linux code. Because we have to deal with various synchronization requirements
+ * between idle thread, system calls, interrupts, "reentrancy", CPU shutdown,
+ * imbalance wake up (i.e. acquire the CPU from one thread and release it from
+ * another), we can't use a simple synchronization mechanism such as (recursive)
+ * mutex or semaphore. Instead, we use a mutex and a bunch of status data plus a
+ * semaphore.
+ */
+static struct lkl_cpu {
+     /* lock that protects the CPU status data */
+     struct lkl_mutex *lock;
+     /*
+      * Since we must free the cpu lock during shutdown we need a
+      * synchronization algorithm between lkl_cpu_shutdown() and the CPU
+      * access functions since lkl_cpu_get() gets called from thread
+      * destructor callback functions which may be scheduled after
+      * lkl_cpu_shutdown() has freed the cpu lock.
+      *
+      * An atomic counter is used to keep track of the number of running
+      * CPU access functions and allow the shutdown function to wait for
+      * them.
+      *
+      * The shutdown functions adds MAX_THREADS to this counter which allows
+      * the CPU access functions to check if the shutdown process has
+      * started.
+      *
+      * This algorithm assumes that we never have more the MAX_THREADS
+      * requesting CPU access.
+      */
+     #define MAX_THREADS 1000000
+     unsigned int shutdown_gate;
+     bool irqs_pending;
+     /* no of threads waiting the CPU */
+     unsigned int sleepers;
+     /* no of times the current thread got the CPU */
+     unsigned int count;
+     /* current thread that owns the CPU */
+     lkl_thread_t owner;
+     /* semaphore for threads waiting the CPU */
+     struct lkl_sem *sem;
+     /* semaphore used for shutdown */
+     struct lkl_sem *shutdown_sem;
+} cpu;
+
+static int __cpu_try_get_lock(int n)
+{
+     lkl_thread_t self;
+
+     if (__sync_fetch_and_add(&cpu.shutdown_gate, n) >= MAX_THREADS)
+             return -2;
+
+     lkl_ops->mutex_lock(cpu.lock);
+
+     if (cpu.shutdown_gate >= MAX_THREADS)
+             return -1;
+
+     self = lkl_ops->thread_self();
+
+     if (cpu.owner && !lkl_ops->thread_equal(cpu.owner, self))
+             return 0;
+
+     cpu.owner = self;
+     cpu.count++;
+
+     return 1;
+}
+
+static void __cpu_try_get_unlock(int lock_ret, int n)
+{
+     if (lock_ret >= -1)
+             lkl_ops->mutex_unlock(cpu.lock);
+     __sync_fetch_and_sub(&cpu.shutdown_gate, n);
+}
+
+void lkl_cpu_change_owner(lkl_thread_t owner)
+{
+     lkl_ops->mutex_lock(cpu.lock);
+     if (cpu.count > 1)
+             lkl_bug("bad count while changing owner\n");
+     cpu.owner = owner;
+     lkl_ops->mutex_unlock(cpu.lock);
+}
+
+int lkl_cpu_get(void)
+{
+     int ret;
+
+     ret = __cpu_try_get_lock(1);
+
+     while (ret == 0) {
+             cpu.sleepers++;
+             __cpu_try_get_unlock(ret, 0);
+             lkl_ops->sem_down(cpu.sem);
+             ret = __cpu_try_get_lock(0);
+     }
+
+     __cpu_try_get_unlock(ret, 1);
+
+     return ret;
+}
+
+void lkl_cpu_put(void)
+{
+     lkl_ops->mutex_lock(cpu.lock);
+
+     if (!cpu.count || !cpu.owner ||
+         !lkl_ops->thread_equal(cpu.owner, lkl_ops->thread_self()))
+             lkl_bug("%s: unbalanced put\n", __func__);
+
+     while (cpu.irqs_pending && !irqs_disabled()) {
+             cpu.irqs_pending = false;
+             lkl_ops->mutex_unlock(cpu.lock);
+             run_irqs();
+             lkl_ops->mutex_lock(cpu.lock);
+     }
+
+     if (test_ti_thread_flag(current_thread_info(), TIF_HOST_THREAD) &&
+         !single_task_running() && cpu.count == 1) {
+             if (in_interrupt())
+                     lkl_bug("%s: in interrupt\n", __func__);
+             lkl_ops->mutex_unlock(cpu.lock);
+             thread_sched_jb();
+             return;
+     }
+
+     if (--cpu.count > 0) {
+             lkl_ops->mutex_unlock(cpu.lock);
+             return;
+     }
+
+     if (cpu.sleepers) {
+             cpu.sleepers--;
+             lkl_ops->sem_up(cpu.sem);
+     }
+
+     cpu.owner = 0;
+
+     lkl_ops->mutex_unlock(cpu.lock);
+}
+
+int lkl_cpu_try_run_irq(int irq)
+{
+     int ret;
+
+     ret = __cpu_try_get_lock(1);
+     if (!ret) {
+             set_irq_pending(irq);
+             cpu.irqs_pending = true;
+     }
+     __cpu_try_get_unlock(ret, 1);
+
+     return ret;
+}
+
+static void lkl_cpu_shutdown(void)
+{
+     __sync_fetch_and_add(&cpu.shutdown_gate, MAX_THREADS);
+}
+__uml_exitcall(lkl_cpu_shutdown);
+
+void lkl_cpu_wait_shutdown(void)
+{
+     lkl_ops->sem_down(cpu.shutdown_sem);
+     lkl_ops->sem_free(cpu.shutdown_sem);
+}
+
+static void lkl_cpu_cleanup(bool shutdown)
+{
+     while (__sync_fetch_and_add(&cpu.shutdown_gate, 0) > MAX_THREADS)
+             ;
+
+     if (shutdown)
+             lkl_ops->sem_up(cpu.shutdown_sem);
+     else if (cpu.shutdown_sem)
+             lkl_ops->sem_free(cpu.shutdown_sem);
Quoted 9 lines

arch/um/nommu/um/cpu.c line 202

Quoted 5 lines
arch/um/nommu/um/cpu.c new file +5 -0
+     if (cpu.sem)
+             lkl_ops->sem_free(cpu.sem);
+     if (cpu.lock)
+             lkl_ops->mutex_free(cpu.lock);
+}

Yeah, what? That's an incomprehensible piece of code. At least add comments, if it _really_ is necessary?

Yeah, sorry about that. We missed adding a bunch of comments in the commit message. It got this complicated because of optimizations to avoid context switching between the native thread running the application and the kernel thread running the system call or interrupt handler.

Maybe we should revert to the initial simpler implementation for now and add it later?

Quoted 18 lines

arch/um/nommu/um/cpu.c line 221

Quoted 4 lines
arch/um/nommu/um/cpu.c new file +4 -0
+#ifdef doesntwork
+     /* switch to idle_host_task */
+     wakeup_idle_host_task();
+#endif

Well ...

Quoted 4 lines

+/**
+ * This is called before the kernel initializes, so no kernel calls (including
+ * printk) can't be made yet.
+ */

not kernel-doc

try to compile with W=1 :)

johannes

maintainer
#161 lore raw

Re: [RFC v7 11/21] um: nommu: kernel thread support

Quoted 11 lines · Octavian Purdila
Quoted 9 lines · Johannes Berg
Quoted 1 line · Hajime Tazaki

nommu mode does not support user processes

I find this really confusing. I'm not sure why you ended up calling this "nommu mode", but there *are* (still) (other) nommu arches, and they *do* support userspace processes.

Isn't this really just "LKL mode" or something like that?

Quoted 6 lines

This is a very good point, while some other patches make sense in the nommu mode, this one does not - it is rather needed because of the "library mode".

Not sure what we can do other than creating a new "library mode" in addition to the "nommu mode". Any suggestions?

Well there's no "nommu mode" in UML other than what you're doing here, so as I said on some other patch, it sort of makes sense to have "LKL == NOMMU", but the equation doesn't make sense everywhere, since it's not fundamentally NOMMU that drives the need for things (like here no userspace, elsewhere the ifdefs, etc.), but LKL-mode.

So I don't think it would be *in addition* to "nommu mode" since such a thing doesn't exist on UML (only on other architectures), but mostly be a rename of "nommu mode" to "lkl mode" or so?

Don't really have any other suggestions, or maybe I'm not understanding your question right.

Quoted 9 lines
Quoted 9 lines

IOW, why isn't this just

void lkl_sem_free(struct lkl_sem *sem);
void lkl_sem_up(struct lkl_sem *sem);
...

and then posix-host.c just includes the header file and implements those functions?

Quoted 8 lines
Quoted 3 lines

I don't see any reason for this to be allowed to have multiple variants linked and then picking them at runtime?

We could try that and see how it goes. This was baked liked this long time ago, when we wanted to support Windows and there was no proper support for weak functions in mingw for PE/COFF (it still not supported but at least we do have a few patches that fix that).

You've required weak functions elsewhere, but in this case you don't even need them since you don't need things to link without an implementation? At least I don't see why you'd want to be able to link a binary that doesn't have an implementation of the ops required to run?

Quoted 4 lines
Quoted 3 lines

Yeah, what? That's an incomprehensible piece of code. At least add comments, if it _really_ is necessary?

Quoted 8 lines

Yeah, sorry about that. We missed adding a bunch of comments in the commit message. It got this complicated because of optimizations to avoid context switching between the native thread running the application and the kernel thread running the system call or interrupt handler.

Maybe we should revert to the initial simpler implementation for now and add it later?

Perhaps? Not really sure. Could the optimisations be added in steps so they're something that can be explained/followed? If not, well, perhaps to ease review for now it'd make sense to start simpler, but I guess eventually it'd still want some better explanation of what's going on.

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#162 lore raw

Re: [RFC v7 11/21] um: nommu: kernel thread support

Quoted 26 lines · Johannes Berg
Quoted 11 lines · Octavian Purdila
Quoted 9 lines · Johannes Berg
Quoted 1 line · Hajime Tazaki

nommu mode does not support user processes

I find this really confusing. I'm not sure why you ended up calling this "nommu mode", but there *are* (still) (other) nommu arches, and they *do* support userspace processes.

Isn't this really just "LKL mode" or something like that?

Quoted 6 lines

This is a very good point, while some other patches make sense in the nommu mode, this one does not - it is rather needed because of the "library mode".

Not sure what we can do other than creating a new "library mode" in addition to the "nommu mode". Any suggestions?

Well there's no "nommu mode" in UML other than what you're doing here, so as I said on some other patch, it sort of makes sense to have "LKL == NOMMU", but the equation doesn't make sense everywhere, since it's not fundamentally NOMMU that drives the need for things (like here no userspace, elsewhere the ifdefs, etc.), but LKL-mode.

Quoted 6 lines

So I don't think it would be *in addition* to "nommu mode" since such a thing doesn't exist on UML (only on other architectures), but mostly be a rename of "nommu mode" to "lkl mode" or so?

Don't really have any other suggestions, or maybe I'm not understanding your question right.

OK, I agree, renaming "nommu mode" to "lkl mode" looks like the right thing to do for now.

Quoted 19 lines
Quoted 10 lines
Quoted 10 lines

IOW, why isn't this just

void lkl_sem_free(struct lkl_sem *sem);
void lkl_sem_up(struct lkl_sem *sem);
...

and then posix-host.c just includes the header file and implements those functions?

Quoted 8 lines
Quoted 3 lines

I don't see any reason for this to be allowed to have multiple variants linked and then picking them at runtime?

We could try that and see how it goes. This was baked liked this long time ago, when we wanted to support Windows and there was no proper support for weak functions in mingw for PE/COFF (it still not supported but at least we do have a few patches that fix that).

Quoted 4 lines

You've required weak functions elsewhere, but in this case you don't even need them since you don't need things to link without an implementation? At least I don't see why you'd want to be able to link a binary that doesn't have an implementation of the ops required to run?

Yeah, all good points :) I'll discuss it more with Hajime to make sure I haven't missed anything and we will try it in the next patch series.

Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

Yeah, what? That's an incomprehensible piece of code. At least add comments, if it _really_ is necessary?

Yeah, sorry about that. We missed adding a bunch of comments in the commit message. It got this complicated because of optimizations to avoid context switching between the native thread running the application and the kernel thread running the system call or interrupt handler.

Quoted 8 lines
Quoted 2 lines

Maybe we should revert to the initial simpler implementation for now and add it later?

Perhaps? Not really sure. Could the optimisations be added in steps so they're something that can be explained/followed? If not, well, perhaps to ease review for now it'd make sense to start simpler, but I guess eventually it'd still want some better explanation of what's going on.

OK, I'll discuss more with Hajime, at this point I think we might want to focus on getting the basics merged first. In either case we will make sure to have it properly explained.

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#163 lore raw

RFC v7 12/21 um: nommu: system call interface and application API

In reply to Hajime Tazaki

The 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
new file mode 100644
index 000000000000..a983c7f049bc
@@ -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
new file mode 100644
index 000000000000..6061d9415dad
@@ -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
index 720385fccbdf..6ee9489fc47e 100644
@@ -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
new file mode 100644
index 000000000000..1762ebb829f5
@@ -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)
maintainer
#164 lore raw

Re: [RFC v7 12/21] um: nommu: system call interface and application API

Review line 1

Quoted 4 lines · Hajime Tazaki

+++ b/arch/um/nommu/include/uapi/asm/syscalls.h

(quoted diff) +1 -0
@@ -0,0 +1,287 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */

That doesn't really make sense - if you use LKL you're linking Linux, so you can't use this "WITH Linux-syscall-note"?

arch/um/nommu/include/uapi/asm/syscalls.h line 3

Quoted 2 lines
arch/um/nommu/include/uapi/asm/syscalls.h new file +2 -0
+#ifndef __UM_NOMMU_UAPI_SYSCALLS_H
+#define __UM_NOMMU_UAPI_SYSCALLS_H

[snip]

This file really worries me, it includes half the world and (re)defines the other half ... How is this ever going to be maintained?

arch/um/scripts/headers_install.py line 1

Quoted 5 lines

index 000000000000..ec7356c0dee9

arch/um/scripts/headers_install.py new file +1 -0
@@ -0,0 +1,197 @@
+#!/usr/bin/env python

might want to make that explicitly 'python3', some newer distros (e.g. ubuntu 20.04) are now shipping without a 'python' by default.

arch/um/scripts/headers_install.py

Quoted 9 lines
arch/um/scripts/headers_install.py new file +6 -0
+def has_lkl_prefix(w):
+  return w.startswith("lkl") or w.startswith("_lkl") or w.startswith("__lkl") \
+         or w.startswith("LKL") or w.startswith("_LKL") or w.startswith("__LKL")
 
 
+        content = re.sub(re.compile("(\/\*(\*(?!\/)|[^*])*\*\/)", re.S|re.M), " ", open(h).read())
 
+    dir = os.path.dirname(h)
+    out_dir = args.path + "/" + re.sub("(" + srctree + "/arch/um/nommu/include/uapi/|arch/um/nommu/include/generated/uapi/|include/generated/uapi/|include/generated|" + install_hdr_path + "/include/)(.*)", "lkl/\\2", dir)

you have some very long lines in places, I'm sure you could fix that (e.g. the last one by doing something with '|'.join([...]))

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#165 lore raw

Re: [RFC v7 12/21] um: nommu: system call interface and application API

Quoted 10 lines · Johannes Berg

Review line 1

Quoted 4 lines · Hajime Tazaki

+++ b/arch/um/nommu/include/uapi/asm/syscalls.h

(quoted diff) +1 -0
@@ -0,0 +1,287 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */

That doesn't really make sense - if you use LKL you're linking Linux, so you can't use this "WITH Linux-syscall-note"?

Quoted 8 lines

arch/um/nommu/include/uapi/asm/syscalls.h line 3

Quoted 2 lines
arch/um/nommu/include/uapi/asm/syscalls.h new file +2 -0
+#ifndef __UM_NOMMU_UAPI_SYSCALLS_H
+#define __UM_NOMMU_UAPI_SYSCALLS_H

[snip]

This file really worries me, it includes half the world and (re)defines the other half ... How is this ever going to be maintained?

There are not that many definitions here, just the ones that were never defined in uapi headers. And, AFAIK, new code that exposes structures and data types should always go into uapi headers and not directly in glibc, etc. So once we fix the old stuff, it should be fine?

Quoted 9 lines

arch/um/scripts/headers_install.py line 1

Quoted 5 lines

index 000000000000..ec7356c0dee9

arch/um/scripts/headers_install.py new file +1 -0
@@ -0,0 +1,197 @@
+#!/usr/bin/env python

might want to make that explicitly 'python3', some newer distros (e.g. ubuntu 20.04) are now shipping without a 'python' by default.

Good point, will fix it in the next patch series.

Quoted 5 lines
Quoted 3 lines
arch/um/scripts/headers_install.py new file +3 -0
+def has_lkl_prefix(w):
+  return w.startswith("lkl") or w.startswith("_lkl") or w.startswith("__lkl") \
+         or w.startswith("LKL") or w.startswith("_LKL") or w.startswith("__LKL")
Quoted 9 lines

arch/um/scripts/headers_install.py line 146

Quoted 4 lines
arch/um/scripts/headers_install.py new file +3 -0
+        content = re.sub(re.compile("(\/\*(\*(?!\/)|[^*])*\*\/)", re.S|re.M), " ", open(h).read())
 
+    dir = os.path.dirname(h)
+    out_dir = args.path + "/" + re.sub("(" + srctree + "/arch/um/nommu/include/uapi/|arch/um/nommu/include/generated/uapi/|include/generated/uapi/|include/generated|" + install_hdr_path + "/include/)(.*)", "lkl/\\2", dir)

you have some very long lines in places, I'm sure you could fix that (e.g. the last one by doing something with '|'.join([...]))

Thanks for pointing it out, we will fix it :)

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

maintainer
#166 lore raw

Re: [RFC v7 12/21] um: nommu: system call interface and application API

Quoted 18 lines · Octavian Purdila
Quoted 8 lines · Johannes Berg

Review line 1

Quoted 3 lines · Hajime Tazaki

+++ b/arch/um/nommu/include/uapi/asm/syscalls.h

(quoted diff) +1 -0
@@ -0,0 +1,287 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */

That doesn't really make sense - if you use LKL you're linking Linux, so you can't use this "WITH Linux-syscall-note"?

Quoted 8 lines

arch/um/nommu/include/uapi/asm/syscalls.h line 3

Quoted 2 lines
arch/um/nommu/include/uapi/asm/syscalls.h new file +2 -0
+#ifndef __UM_NOMMU_UAPI_SYSCALLS_H
+#define __UM_NOMMU_UAPI_SYSCALLS_H

[snip]

This file really worries me, it includes half the world and (re)defines the other half ... How is this ever going to be maintained?

Quoted 5 lines

There are not that many definitions here, just the ones that were never defined in uapi headers. And, AFAIK, new code that exposes structures and data types should always go into uapi headers and not directly in glibc, etc. So once we fix the old stuff, it should be fine?

Yeah, not really sure. Not all of this is really old stuff, e.g. keyring things were here I noticed.

But since it's userspace API I guess the changes of it breaking are fairly small anyway, so maybe I just shouldn't worry about it :)

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#167 lore raw

RFC v7 13/21 um: nommu: basic console support

In reply to Hajime Tazaki

This 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
index ae96c83e312d..694da4aa550d 100644
@@ -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
index 6ee9489fc47e..133877c857a1 100644
@@ -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)
#168 lore raw

RFC v7 14/21 um: nommu: initialization and cleanup

In reply to Hajime Tazaki

Add 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
index 133877c857a1..0811494c080c 100644
@@ -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
index e52dd37ddadc..c39d914e80ac 100644
@@ -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)
#169 lore raw

RFC v7 15/21 um: nommu: integrate with irq infrastructure of UML

In reply to Hajime Tazaki

In 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
index f467d28fc0b4..0da3ce22e16f 100644
@@ -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
index 3577118bb4a5..4ce7f5fef7f8 100644
@@ -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
index 25eaa6a0c658..9e141fe8fe27 100644
@@ -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
index c101c078ef21..c52a78c77bea 100644
@@ -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
index 9986a3f8c5dd..75d8bdc1847e 100644
@@ -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
index eaa74d771f73..922188690139 100644
@@ -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
index e9a49100d40e..fe2fa3e688fd 100644
@@ -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
index b58bc68cbe64..2b5c98de21cd 100644
@@ -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)
maintainer
#170 lore raw

Re: [RFC v7 15/21] um: nommu: integrate with irq infrastructure of UML

arch/um/kernel/irq.c unsigned long to_irq_stack(unsigned long *mask_out) · line 545

Quoted 6 lines
arch/um/kernel/irq.c +1 -0
@@ -541,6 +542,11 @@ unsigned long to_irq_stack(unsigned long *mask_out)
 	unsigned long mask, old;
 	int nested;
 
+#ifndef CONFIG_MMU

Also here and throughout, not sure I like (and it makes sense) to have the equation of !CONFIG_MMU == LKL.

I mean, sure, that may actually be _true_ (at least right now), but it doesn't feel like all of this really is a consequence of *NOMMU*, it's more a consequence of LKL.

At least I think it is?

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#171 lore raw

RFC v7 16/21 um: nommu: plug in the build system

In reply to Hajime Tazaki

Basic 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
index e41d31d0d875..df7daceb095c 100644
@@ -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
index 8be7bc479442..ee35bd030bf8 100644
@@ -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
index 9b63831a69e1..01605ed439cb 100644
@@ -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
new file mode 100644
index 000000000000..20b3eaccb6f0
@@ -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
new file mode 100644
index 000000000000..b580e0fe97b5
@@ -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)
maintainer
#172 lore raw

Re: [RFC v7 16/21] um: nommu: plug in the build system

Quoted 6 lines · Hajime Tazaki

Basic 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.

Here you did that again :)

I think you should really be up-front about it and call it "kernel" and "library" mode. Then do the ifdefs on library mode etc.

Sure, kernel mode will be CONFIG_MMU=y and library mode will be !CONFIG_MMU instead, but it really makes more sense to call things CONFIG_UMMODE_LIB in most cases, I think?

Yes, a lot of stuff *does* depend on CONFIG_MMU, and that still makes sense. It just feels like a lot of stuff you made depend on CONFIG_MMU here (or !CONFIG_MMU) really isn't related too much to that, rather than being related to "library mode".

Quoted 2 lines

make defconfig ARCH=um UMMODE=library
make ARCH=um UMMODE=library

Why not make it a real Kconfig symbol? I find the ARCH=um tricky enough to remember all the time, so much I usually write a "GNUmakefile" with

export ARCH=um
include Makefile

:-)

arch/um/Kconfig config UML · line 27

Quoted 3 lines
arch/um/Kconfig +3 -0
+config UMMODE_LIB
+	bool "UML mode: library mode"
+	default y if "$(UMMODE)" = "library"

So wait, you _can_ switch that through Kconfig then, because you made it a visible option (string after "bool"). But it won't work, because then you later in the build system etc. still check UMMODE instead of CONFIG_UMMODE_LIB. Seems like something that ought to be fixed one way or the other - at the very least hide this symbol if setting it manually is invalid.

arch/um/Kconfig config UML · line 31

Quoted 4 lines
arch/um/Kconfig +4 -0
+	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.

Not sure if that historically made more sense, but you don't have any UMMODE_KERNEL option or something like that, so the help text seems confusing?

Quoted 11 lines
arch/um/Kconfig +4 -1
+	 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

arch/um/Kconfig config LOCKDEP_SUPPORT · line 59

Quoted 5 lines
arch/um/Kconfig +1 -1
@@ -45,12 +56,12 @@ config LOCKDEP_SUPPORT
 
 config STACKTRACE_SUPPORT
 	bool
-	default y
+	default y if MMU

Same as what I said above - there really shouldn't be any inherent reason why STACKTRACE_SUPPORT depends on CONFIG_MMU, is there? Apart from not having implemented it in UMMODE_LIB, that is, and then you should make this if !UMMODE_LIB?

arch/um/Kconfig config LOCKDEP_SUPPORT · line 64

Quoted 4 lines
arch/um/Kconfig +1 -1
 config GENERIC_CALIBRATE_DELAY
 	bool
-	default y
+	default y if MMU

Same here. This one _surely_ has no relation to MMU.

arch/um/Makefile else

Quoted 6 lines
arch/um/Makefile +4 -0
+ifeq ($(UMMODE),library)
+  SUBARCH := um/nommu
+endif
 
 INSTALL_PATH=$(objtree)/tools/um
+ifeq ($(UMMODE),library)

Here a few places using UMMODE which must come from the command line.

arch/um/Makefile linux: linux.o · line 124

Quoted 4 lines

linux.o: vmlinux

arch/um/Makefile +1 -1
 	@echo '  LINK	$@'
-	$(Q)$(OBJCOPY) -R .eh_frame $< $@
+	$(Q)$(OBJCOPY) -R .eh_frame -L sem_init -L sem_post -L sem_wait -L sem_destroy $< $@

Care to explain?

Quoted 40 lines
arch/um/Makefile +0 -0
 	$(Q)mkdir -p $(objtree)/tools/um/lib
 
 define archhelp
arch/um/kernel/Makefile +9 -5
index 9b63831a69e1..01605ed439cb 100644
@@ -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 +0 -0
new file mode 100644
index 000000000000..20b3eaccb6f0

arch/um/nommu/um/Kconfig line 3

Quoted 3 lines
arch/um/nommu/um/Kconfig new file +3 -0
@@ -0,0 +1,37 @@
+config UML_NOMMU
+	def_bool y
+	depends on !SMP && !MMU

again, using MMU to mean "LKL" (both UML_NOMMU and !MMU places)

arch/um/nommu/um/Kconfig line 6

Quoted 3 lines
arch/um/nommu/um/Kconfig new file +3 -0
+	select UACCESS_MEMCPY
+	select ARCH_THREAD_STACK_ALLOCATOR
+	select ARCH_HAS_SYSCALL_WRAPPER

You never use this except for the selects, maybe can go elsewhere?

Quoted 15 lines
arch/um/nommu/um/Kconfig new file +15 -0
+config 64BIT
+	bool
+	default y
+
+config GENERIC_CSUM
+	def_bool y
+
+config GENERIC_ATOMIC64
+	bool
+	default y if !64BIT
+
+config SECCOMP
+	bool
+	default n
+

arch/um/nommu/um/Kconfig line 32

Quoted 10 lines
arch/um/nommu/um/Kconfig new file +10 -0
+config GENERIC_HWEIGHT
+	def_bool y
+
+config GENERIC_CALIBRATE_DELAY
+	bool
+	default n
+
+config STACKTRACE_SUPPORT
+	bool
+	default n

You ... were just changing these elsewhere, so one of that isn't needed?

arch/um/nommu/um/Kconfig line 34

Quoted 1 line
arch/um/nommu/um/Kconfig new file +1 -0
+# XXX: need this to work well with tap13.py

What's tap13.py??

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um