From patchwork Thu Sep 24 07:12:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370365 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=ZlU4PoCW; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=MZcYl5hC; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmVs5kDNz9sSt for ; Thu, 24 Sep 2020 17:13:57 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Dwv+/TVow7p1+erFcJqtyuJlJWSWF6jGKNefERKEeTQ=; b=ZlU4PoCWBqYhZyKoeHBgN8pcT S+sxTmhxfpeRHizVnIToB4y0vhhRK2maLzj1EgP+TvSlYF9kEN698frb8g1QtZ4F+RgNVpeNyEXMy LzUHtEuOW3jWke0vAtOgQmdOO/fGeC/fkhD1dyN726xd5BGQxDh5uWIpcijj5rnzEIF+vWjfO2WDn hMgtT4mhT0NK3n03wtOiUb26epXAQQLfR/fn4FjwZCXd/hzSLI79brTUHZ8ROgsZM8vNuETpxUAoJ I9TYs1yJW32hA6hTOXO8jEBzbjTZZwsOYiVNMtFcq/GdnwNGkpm6RuW/mZkOosmAjyzHFrZUP2WRX Tia/z4SZA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLRy-00035k-1s; Thu, 24 Sep 2020 07:13:54 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLRu-00033e-IF for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:13:51 +0000 Received: by mail-pj1-x1035.google.com with SMTP id b17so1130464pji.1 for ; Thu, 24 Sep 2020 00:13:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=814TJhGALpQIsQzh5yodGQph5takwWkT3dX38PmHDR8=; b=MZcYl5hCQOFcBZJxH0wYt6WahcVdD9UvbMOWqdwsD1Kror4ozQKFq2LR16y2fO+Q4+ cEeJSiUHWdrJT/onjpdPJyi2nedm/amcZJxVz2z+AecjoMQh5e8jmhXIdfmaAZ9PVFy6 EsslMExHWn/9/zlq8yafBPRlIt+K8jWzTyFcpZ4nNLTYnWBKu1Wn3I0un4n0JyELZrKS NoldPgYOiwE7Oe60mdIebOkZs8cBwQQz7jZobP/BTggYnAG7wcFUUEHnU+173CgNw8wh c+KTEMA2/pGWWDqCWeQic/hQIPkkEBZJYBmrip0EHn5IHMEayszOF5EAfIHs1jcvXlLh wQvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=814TJhGALpQIsQzh5yodGQph5takwWkT3dX38PmHDR8=; b=pcv4vqiF5Nq3d5L2t2mwW9c/41+++yio5ke+1HzyrLTxHZXHQrLhiymx+1D+FX0wS1 TBwQOmVuu0+H76xSOO3knBg9/T7SGx4MX03GOPdh9Mf9R4OKXLHF10VXENBM5xaL8umf 5KiMUgCNJBTtH4x8QvvSTgQxynSSST3fA0xzh/iKEaoTHFGpXdC2BJNHA2rSClD5s5rr GOt6SXcDopx6IdTxMHIgeEC/Ls6GVZMJQsz3xj8clIFV4ALEkT0M+g+o7L3G+n8VOnD5 89AVJtlPl5/LMRSqr7y3/CDHaFiHUKxC/RGNF2Xdw65H+jb2CBj1g4OAUUjq4AGInFx9 JJew== X-Gm-Message-State: AOAM530tk8JZm7QanJLJ9zu7Dlf3fypm8bAkkF+Jhx00EFuGkGwSNF8v vOyZqEfrgBoQBaX52+6rguOLy8AMJMaHsQ== X-Google-Smtp-Source: ABdhPJyHsUMgPnTsBBdISlfADBBRn40lClT82eijEJg0eaICBu4up9W2TUGfgEJtCha/FNn4TgsNkw== X-Received: by 2002:a17:90a:f682:: with SMTP id cl2mr2841592pjb.158.1600931628195; Thu, 24 Sep 2020 00:13:48 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id b18sm1743991pfr.4.2020.09.24.00.13.47 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:13:47 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 098772037C202D; Thu, 24 Sep 2020 16:13:45 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 01/21] um: split build in kernel and host parts Date: Thu, 24 Sep 2020 16:12:41 +0900 Message-Id: <034e4235086fceb43659c679770b7088e974f5d7.1600922528.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031350_629527_C94B6A33 X-CRM114-Status: GOOD ( 25.21 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1035 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, tavi.purdila@gmail.com, Octavian Purdila , retrage01@gmail.com, linux-kernel-library@freelists.org, Hajime Tazaki Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Octavian Purdila 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 Signed-off-by: Octavian Purdila Signed-off-by: Hajime Tazaki --- 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 diff --git a/arch/um/Kconfig b/arch/um/Kconfig index eb51fec75948..e41d31d0d875 100644 --- a/arch/um/Kconfig +++ b/arch/um/Kconfig @@ -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 diff --git a/arch/um/Makefile b/arch/um/Makefile index 1cea46ff9bb7..fdfaff4633e8 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -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' diff --git a/arch/um/include/asm/common.lds.S b/arch/um/include/asm/common.lds.S deleted file mode 100644 index eca6c452a41b..000000000000 --- a/arch/um/include/asm/common.lds.S +++ /dev/null @@ -1,99 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include - - .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 - } - diff --git a/arch/um/kernel/dyn.lds.S b/arch/um/kernel/dyn.lds.S deleted file mode 100644 index f5001481010c..000000000000 --- a/arch/um/kernel/dyn.lds.S +++ /dev/null @@ -1,171 +0,0 @@ -#include -#include - -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 - - __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 -} diff --git a/arch/um/kernel/uml.lds.S b/arch/um/kernel/uml.lds.S deleted file mode 100644 index 3b6dab3d4501..000000000000 --- a/arch/um/kernel/uml.lds.S +++ /dev/null @@ -1,115 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include -#include - -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 - - __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 -} diff --git a/arch/um/kernel/vmlinux.lds.S b/arch/um/kernel/vmlinux.lds.S index 16e49bfa2b42..aaedd66772fa 100644 --- a/arch/um/kernel/vmlinux.lds.S +++ b/arch/um/kernel/vmlinux.lds.S @@ -1,8 +1,87 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include +#include +#include +#include +#include +#include -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 +} diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index e6e2d9e5ff48..903fc8053d07 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -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 diff --git a/tools/um/Makefile b/tools/um/Makefile new file mode 100644 index 000000000000..a63466ef7ef5 --- /dev/null +++ b/tools/um/Makefile @@ -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 diff --git a/tools/um/Targets b/tools/um/Targets new file mode 100644 index 000000000000..a4711f1ef422 --- /dev/null +++ b/tools/um/Targets @@ -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 diff --git a/tools/um/uml/Build b/tools/um/uml/Build new file mode 100644 index 000000000000..e69de29bb2d1 From patchwork Thu Sep 24 07:12:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370366 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=Mp4/HcRi; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=e9hMfqV+; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmVx3Xbqz9sTH for ; Thu, 24 Sep 2020 17:14:01 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zx+hE9Ceci1GW3e3anSC/uqMrAfteAtB4nlumS2snyU=; b=Mp4/HcRi+/+cembmwJ+/VAIRO 7am9Mzd4VdEipx7E2zVVXIDFywCZBoWdum8CaCfNQ9r8K9bvhYGue56VU6iP1U0IAodI2I/XLs41P 6Cs9Ef1CiuZN5cHKOWiPZwieI8Ihtt5PBz2Wbim/8cXxhIcjtCR7hwuMwTEbJdI0kGXfVCWCHcWBa 5Cm2cR3phDEDHvitnuucA/cgSBoznG3WVudLXoyjDMN3ds8cckcjbYzS+GnXjZMOPpCSuHrrShLF/ gq0yHJLYr5VZCVvy6FAJ83OsVgphqS0llHYxORhWJI6AFP31kqxyeoQuNPYnZ+sjPGkglrCqYk6qj /nDdXWMNw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLS2-000385-9O; Thu, 24 Sep 2020 07:13:58 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLRx-00034u-U0 for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:13:55 +0000 Received: by mail-pl1-x641.google.com with SMTP id q12so1171265plr.12 for ; Thu, 24 Sep 2020 00:13:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aeduLP4IxG8QLm5XBKojGInFwj9Qco6vm9ib8DpEzok=; b=e9hMfqV+8Qyp+mFEsnlBzQhOkdw4jChVTgzW2atFzOcF6eQ2Ofe+ye8hUrWWTsOjbQ KkdbtHtBxKy1AJRynUw4HSB0vXLCxFsa14oVWiRAm5JrhM3q0VdvWCLDqpl+yAIknf66 iZUAiqGudwylI/vJ76rkJXpQYUawD+CYpv2uwpS1p1VxTrS2qAaeKS/rMVxpm0XdeyJs xizwF8wbY5eO7ItoYXfu0UsFcPWjtleNbAdGhB70x0F/6M7pCEoIXIJtSisOBVbVNo2P ZbIl0bNdqIWGtBwCmC3JEfIlHJrgxbiMzleiQwicYy8uiE7YPq5LoNK/0jPejrVzOn0g SNfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aeduLP4IxG8QLm5XBKojGInFwj9Qco6vm9ib8DpEzok=; b=AbUwnVGyINFORZ7x58YD5iMOBX9B/fnr0o00DYwnryUsQqWCqcRhaV0QRqc8OxKRbU JlPxnz2ku2tzw+fgpfdbPINiussY5J81YhCTm2544EjuYYAuSjzHeR6k/rpSMosJ4ahK cbTmhsHVni9XiyNNKVWYzGti137Egt2N9DGbU0hANU9WS11B2cvPwA77ZzZSg7VJys4y xy+YETgHASGsDDxsXeTDlXR1ay5jNyHWZomFGzOuGQa7SZxiHEzaBYpBeOt8fxrkPFJs U09l/xoZG4TcAYE8+ZtmvqmN58I9xoPkUcWvzt17DVXdJxbv0/OG6E6DNqcj5wrp8cka vdjA== X-Gm-Message-State: AOAM531qTfdT/vvQIe2KXAyF+hfaOiUcyoIDLf92w3UEwdHFnbJgBGiC 4G5tQVQnUCCCTR5mkq2wy/I= X-Google-Smtp-Source: ABdhPJy6l/2edLKPoLJJy/XOmFKZ6m7ZQp1W8mAAVtYqAunDxDl8EBLdy0PozZJ9/JBpa04m6QK7UA== X-Received: by 2002:a17:902:ec02:b029:d1:fc2b:fe95 with SMTP id l2-20020a170902ec02b02900d1fc2bfe95mr3408136pld.79.1600931631684; Thu, 24 Sep 2020 00:13:51 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id y79sm1846800pfb.45.2020.09.24.00.13.51 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:13:51 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 5B88E2037C202F; Thu, 24 Sep 2020 16:13:49 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 02/21] um: add os init and exit calls Date: Thu, 24 Sep 2020 16:12:42 +0900 Message-Id: <0479e4453fbc20abc3a9a7fbd892bb258440712a.1600922528.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031354_055174_6FAB3C7B X-CRM114-Status: GOOD ( 13.64 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:641 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Octavian Purdila , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Octavian Purdila These calls are added in preparation for moving some of the code from the kernel to the host build. Signed-off-by: Octavian Purdila --- 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(-) diff --git a/arch/um/include/shared/init.h b/arch/um/include/shared/init.h index c66de434a983..d09308330ca5 100644 --- a/arch/um/include/shared/init.h +++ b/arch/um/include/shared/init.h @@ -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 */ diff --git a/arch/um/kernel/reboot.c b/arch/um/kernel/reboot.c index 48c0610d506e..5420aec411f4 100644 --- a/arch/um/kernel/reboot.c +++ b/arch/um/kernel/reboot.c @@ -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(); } diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c index 00141e70de56..e2cb76c03b25 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c @@ -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); From patchwork Thu Sep 24 07:12:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370367 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=0/N0pu0o; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=oGivdU6A; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmW46SY4z9sSt for ; Thu, 24 Sep 2020 17:14:08 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bEHdPgHuIWWjWDe4l6kukHiwY8ncwuP7Ay2Gy0oIq/s=; b=0/N0pu0oVEeQB2Z49o6P6FORz G4nYyBgln+VCsrjX8ACrglQZ65CUy5Rbr/DoVV11pEkZROIAjwu76x5vGMT8pGk9cgVYq1i5WmFxk hD08uxw1/3zFAtwVwO7CcUGHcVSySBdLz/Ezox1kVSFrPXnfwgagg5NLsZwMfJxpSa5eyKnqJrTWf 9DBUuPJtYnRKFgcm1QX7a65RSFe/7qIfIH+QZSC7vl18MRL4HVz/xX1NM+YfdQMe1rM8rjoiG8CTe MAEXcJP0iOCvJsYS4c7sfEI262HVZL5r3rCg2Du4eGVQ8YZt4A60ZolvXO0eKTcUMS0hcygzhErAu 9BfzmUI0A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLS9-0003BZ-QB; Thu, 24 Sep 2020 07:14:05 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLS6-00039p-9L for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:14:03 +0000 Received: by mail-pg1-x542.google.com with SMTP id t14so1338650pgl.10 for ; Thu, 24 Sep 2020 00:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=V39OSq8BYtEwCP/WlLr+fNgdgKv2eYc9I6KQ+MlDE8I=; b=oGivdU6AJxfNAcYQJD30qCYP+6+l5dPXyiebKfpaEskk6ln0rmNkxnoaHPAT9oULpg aiLoInIhal68QrzMYpkTSu/U5mlnpydtytqu4rBHHyiVvqhQ1rQ7WigE8FHPSkIJAfOF psezfVmRvsbC6ZsSN6hQjlG1iTzwmRsVLfovFn65MdNG3pubhxExTJN2Isjhj/rCf6OY 2+mcJ4zmTOienRiwCpRmnDxLd1U4meSMmPud+j54chfbQDhtGuNNKTprc7DuE7EMmuOP bgzICGJsPOa6KCFrwuZOLN0XvDbxwMbab7+N+mgbl28DQx0tijG7s9kF4VYLdeF5UsIA 9pWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V39OSq8BYtEwCP/WlLr+fNgdgKv2eYc9I6KQ+MlDE8I=; b=OVNtDdcTHFahFFgwbNh0qXk7IQYSblaqc8eCRiGLTAcXnSkXpT5ANCacfP80s3Sbbb CQq8F5EDGlkk1Fj/AOOeK4pfIv0ya5o46xYHjoCM+yhPSuAO2ZDmbuQpeUuQ0V4WOxNc 4WnaqCqtjhBHVXGXf+0jiGJ9GraNWppg/NN9X/Kgnyofz6UX4tr7nA3g3MNT+TffbwmJ FcBgX7wbjKPAlIFZDyiRrK2+mni83y5EvVMVDP1Eo2sP8RAWQAsRhPxncmJYbR0eFd5m 0EOKOFsEUOojXuUJVx15MZuCM524lrN51BU83Oby7ctNh4Sttir5L+bV/IhXH1yjfBF7 Tcaw== X-Gm-Message-State: AOAM530EFpPg0fxNkBqg3erBlbSheqfnTX3UWFKB/F0BUHSLWY8H+3uZ 6hUpvCjEdTXd8FWOS4xVaY3ra29BzMR/uA== X-Google-Smtp-Source: ABdhPJwIRzRaurRWjMgy0EBoDbqpmJStrS/2eT7p2204Qd9z59AnjorNZ84PD1CP/l9mH7L7DXhg0A== X-Received: by 2002:a62:52d3:0:b029:142:2501:3a00 with SMTP id g202-20020a6252d30000b029014225013a00mr3188378pfb.79.1600931639900; Thu, 24 Sep 2020 00:13:59 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id r16sm1416899pjo.19.2020.09.24.00.13.58 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:13:59 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id C7B392037C2035; Thu, 24 Sep 2020 16:13:56 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 03/21] um: move arch/um/os-Linux dir to tools/um/uml Date: Thu, 24 Sep 2020 16:12:43 +0900 Message-Id: <364a2fc126e5d3035e6968c339aa04944614405d.1600922528.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031402_346844_48A555F5 X-CRM114-Status: GOOD ( 17.79 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:542 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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). Signed-off-by: Hajime Tazaki --- 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%) diff --git a/arch/um/Makefile b/arch/um/Makefile index fdfaff4633e8..1f958a9280fe 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -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 diff --git a/arch/um/drivers/Makefile b/arch/um/drivers/Makefile index 2a249f619467..ae96c83e312d 100644 --- a/arch/um/drivers/Makefile +++ b/arch/um/drivers/Makefile @@ -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 diff --git a/arch/um/os-Linux/drivers/ethertap_kern.c b/arch/um/drivers/ethertap_kern.c similarity index 100% rename from arch/um/os-Linux/drivers/ethertap_kern.c rename to arch/um/drivers/ethertap_kern.c diff --git a/arch/um/os-Linux/drivers/tuntap_kern.c b/arch/um/drivers/tuntap_kern.c similarity index 100% rename from arch/um/os-Linux/drivers/tuntap_kern.c rename to arch/um/drivers/tuntap_kern.c diff --git a/arch/um/os-Linux/drivers/etap.h b/arch/um/include/shared/etap.h similarity index 100% rename from arch/um/os-Linux/drivers/etap.h rename to arch/um/include/shared/etap.h diff --git a/arch/um/include/shared/init.h b/arch/um/include/shared/init.h index d09308330ca5..305789667584 100644 --- a/arch/um/include/shared/init.h +++ b/arch/um/include/shared/init.h @@ -41,7 +41,12 @@ typedef int (*initcall_t)(void); typedef void (*exitcall_t)(void); +#ifndef __UM_HOST__ #include +#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) */ diff --git a/arch/um/os-Linux/drivers/tuntap.h b/arch/um/include/shared/tuntap.h similarity index 100% rename from arch/um/os-Linux/drivers/tuntap.h rename to arch/um/include/shared/tuntap.h diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile deleted file mode 100644 index 839915b8c31c..000000000000 --- a/arch/um/os-Linux/Makefile +++ /dev/null @@ -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 diff --git a/arch/um/os-Linux/drivers/Makefile b/arch/um/os-Linux/drivers/Makefile deleted file mode 100644 index d79e75f1b69a..000000000000 --- a/arch/um/os-Linux/drivers/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# Copyright (C) 2000, 2002 Jeff Dike (jdike@karaya.com) -# - -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 diff --git a/tools/um/Makefile b/tools/um/Makefile index a63466ef7ef5..07b9b93ed817 100644 --- a/tools/um/Makefile +++ b/tools/um/Makefile @@ -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 diff --git a/tools/um/uml/Build b/tools/um/uml/Build index e69de29bb2d1..8e0607ee8b0a 100644 --- a/tools/um/uml/Build +++ b/tools/um/uml/Build @@ -0,0 +1,48 @@ +# 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 + +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-$(CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA) += elf_aux.o + +export O = $(srctree) +objtree := $(O) +# reset CFLAGS +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 +endif +KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \ + $(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap \ + -Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \ + -Din6addr_loopback=kernel_in6addr_loopback \ + -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr +SHARED_HEADERS := $(ARCH_DIR)/include/shared +MODE_INCLUDE += -I$(srctree)/$(ARCH_DIR)/include/shared/skas +ARCH_INCLUDE := -I$(srctree)/$(SHARED_HEADERS) +ARCH_INCLUDE += -I$(srctree)/$(HOST_DIR)/um/shared +KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/um +USER_CFLAGS := $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \ + $(ARCH_INCLUDE) $(MODE_INCLUDE) $(filter -I%,$(CFLAGS)) \ + -D_FILE_OFFSET_BITS=64 -idirafter $(srctree)/include/uapi \ + -idirafter $(objtree)/include -D__KERNEL__ -D__UM_HOST__ + +# from Makefile-os-Linux +USER_CFLAGS += -D_GNU_SOURCE -D_LARGEFILE64_SOURCE + +# from Makefile.rules +CFLAGS += $(USER_CFLAGS) -include $(srctree)/tools/include/linux/kern_levels.h -include user.h $(CFLAGS_$(basetarget).o) diff --git a/tools/um/uml/drivers/Build b/tools/um/uml/drivers/Build new file mode 100644 index 000000000000..c7a8eaa97d72 --- /dev/null +++ b/tools/um/uml/drivers/Build @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2000, 2002 Jeff Dike (jdike@karaya.com) +# + +include $(objtree)/include/config/auto.conf + + +liblinux-$(CONFIG_UML_NET_ETHERTAP) += ethertap_user.o +liblinux-$(CONFIG_UML_NET_TUNTAP) += tuntap_user.o diff --git a/arch/um/os-Linux/drivers/ethertap_user.c b/tools/um/uml/drivers/ethertap_user.c similarity index 100% rename from arch/um/os-Linux/drivers/ethertap_user.c rename to tools/um/uml/drivers/ethertap_user.c diff --git a/arch/um/os-Linux/drivers/tuntap_user.c b/tools/um/uml/drivers/tuntap_user.c similarity index 100% rename from arch/um/os-Linux/drivers/tuntap_user.c rename to tools/um/uml/drivers/tuntap_user.c diff --git a/arch/um/os-Linux/elf_aux.c b/tools/um/uml/elf_aux.c similarity index 100% rename from arch/um/os-Linux/elf_aux.c rename to tools/um/uml/elf_aux.c diff --git a/arch/um/os-Linux/execvp.c b/tools/um/uml/execvp.c similarity index 98% rename from arch/um/os-Linux/execvp.c rename to tools/um/uml/execvp.c index 84a0777c2a45..c105e0e7b778 100644 --- a/arch/um/os-Linux/execvp.c +++ b/tools/um/uml/execvp.c @@ -26,12 +26,8 @@ #include #include -#ifndef TEST -#include -#else #include #define um_kmalloc malloc -#endif #include /* Execute FILE, searching in the `PATH' environment variable if it contains diff --git a/arch/um/os-Linux/file.c b/tools/um/uml/file.c similarity index 100% rename from arch/um/os-Linux/file.c rename to tools/um/uml/file.c diff --git a/arch/um/os-Linux/helper.c b/tools/um/uml/helper.c similarity index 100% rename from arch/um/os-Linux/helper.c rename to tools/um/uml/helper.c diff --git a/arch/um/os-Linux/irq.c b/tools/um/uml/irq.c similarity index 100% rename from arch/um/os-Linux/irq.c rename to tools/um/uml/irq.c diff --git a/arch/um/os-Linux/main.c b/tools/um/uml/main.c similarity index 100% rename from arch/um/os-Linux/main.c rename to tools/um/uml/main.c diff --git a/arch/um/os-Linux/mem.c b/tools/um/uml/mem.c similarity index 100% rename from arch/um/os-Linux/mem.c rename to tools/um/uml/mem.c diff --git a/arch/um/os-Linux/process.c b/tools/um/uml/process.c similarity index 100% rename from arch/um/os-Linux/process.c rename to tools/um/uml/process.c diff --git a/arch/um/os-Linux/registers.c b/tools/um/uml/registers.c similarity index 100% rename from arch/um/os-Linux/registers.c rename to tools/um/uml/registers.c diff --git a/arch/um/os-Linux/sigio.c b/tools/um/uml/sigio.c similarity index 100% rename from arch/um/os-Linux/sigio.c rename to tools/um/uml/sigio.c diff --git a/arch/um/os-Linux/signal.c b/tools/um/uml/signal.c similarity index 100% rename from arch/um/os-Linux/signal.c rename to tools/um/uml/signal.c diff --git a/arch/um/os-Linux/skas/Makefile b/tools/um/uml/skas/Build similarity index 56% rename from arch/um/os-Linux/skas/Makefile rename to tools/um/uml/skas/Build index c4566e788815..5fc9d62df863 100644 --- a/arch/um/os-Linux/skas/Makefile +++ b/tools/um/uml/skas/Build @@ -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 diff --git a/arch/um/os-Linux/skas/mem.c b/tools/um/uml/skas/mem.c similarity index 100% rename from arch/um/os-Linux/skas/mem.c rename to tools/um/uml/skas/mem.c diff --git a/arch/um/os-Linux/skas/process.c b/tools/um/uml/skas/process.c similarity index 99% rename from arch/um/os-Linux/skas/process.c rename to tools/um/uml/skas/process.c index 4fb877b99dde..fca6a08e81bd 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/tools/um/uml/skas/process.c @@ -21,7 +21,6 @@ #include #include #include -#include 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 diff --git a/arch/um/os-Linux/start_up.c b/tools/um/uml/start_up.c similarity index 100% rename from arch/um/os-Linux/start_up.c rename to tools/um/uml/start_up.c diff --git a/arch/um/os-Linux/time.c b/tools/um/uml/time.c similarity index 100% rename from arch/um/os-Linux/time.c rename to tools/um/uml/time.c diff --git a/arch/um/os-Linux/tty.c b/tools/um/uml/tty.c similarity index 100% rename from arch/um/os-Linux/tty.c rename to tools/um/uml/tty.c diff --git a/arch/um/os-Linux/umid.c b/tools/um/uml/umid.c similarity index 100% rename from arch/um/os-Linux/umid.c rename to tools/um/uml/umid.c diff --git a/arch/um/os-Linux/user_syms.c b/tools/um/uml/user_syms.c similarity index 99% rename from arch/um/os-Linux/user_syms.c rename to tools/um/uml/user_syms.c index 715594fe5719..4047fd7bfdb7 100644 --- a/arch/um/os-Linux/user_syms.c +++ b/tools/um/uml/user_syms.c @@ -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); diff --git a/arch/um/os-Linux/util.c b/tools/um/uml/util.c similarity index 100% rename from arch/um/os-Linux/util.c rename to tools/um/uml/util.c From patchwork Thu Sep 24 07:12:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370368 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=KuMfLBfa; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=bDRiwy+O; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmWL3gLPz9sSC for ; Thu, 24 Sep 2020 17:14:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IPYyAsuQtzcDqJhz6EcRK6irOrsXliDY5xwBxVmakJ0=; b=KuMfLBfaZ4psOGuZCqv1y20/y rU1i0rvgh3SAps8/VfVYSLoSBn7Q83YJPnAG38jajavQVvbttgigp2BtopCCVGCXmDLF58N6c3wDO IDCV/Z9AU0HCKHTYOg1AyLLpuukOZPRKXPPdTIHTJ1yBCSBP8Zgrdj6n1a/D7c2Y59mXpF7SrjAM/ TC2qDcdfNSaSvwZqpdQA6W1P7Q9TtGn8HSGCT2lY9qx+0ihKQy778T+Phk9j78lMLQi+nxUNUFzra WorSuJPDJlJhDg+rDIb8EhRyh1ac/zcIKNcvk2Jtcw6CbWb0EoeAw6nG82gDlVNrJd7gYbqvG5llE SdmA288nA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLSN-0003Ea-Dy; Thu, 24 Sep 2020 07:14:19 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLSK-0003De-TE for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:14:17 +0000 Received: by mail-pg1-x543.google.com with SMTP id y14so1328499pgf.12 for ; Thu, 24 Sep 2020 00:14:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bfz1YZ5dIoN2aGR7YJ8XQT/WwiC9kxrzNC++l1jbOuI=; b=bDRiwy+OBmf9+dYoD0f6rZFMOQ5EIJ4Gj9fz1X8mEeMvEPNyzevLyIaaNPhAWtOHzF xE/Res2P+sLHlqQnnfN4rfk5q9lyM7x5UGs/FIKoJdpiEmqlZQgDqb0x7wdLaIE7Tmn1 F1Kab+CvwFDkXtahnmViPvWRhqZLKglR9+1LjoRP4ZIPMEOoQcYVpp7G+Dc6GFv+yY59 YiEmXFSS9kp+aLv8U5olm//VkbX3uAMnkgfB1Ea3pbKNyJLkonXJrz2ab4XF+ZOoXwW3 gfujKiLKlrLr4XV/l9Z7X2uuaYCAl9TfnLNtEvjZ2yJC8rWvGxxZZhrq//CxVkL4etZ9 sXXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bfz1YZ5dIoN2aGR7YJ8XQT/WwiC9kxrzNC++l1jbOuI=; b=SYsH5+eHUvTAlcM0tT2rxoehlB6on20hc9eT3oQMGg+Xx2Ifkv5FFiCmtLoRlPz+Bp 3/9trqvyjjfjZIDSB48ZrGcNOXjetgTfG2vx0wDzMdJoFoENtKZ95ji96n/L6359lO2y fYoSDaPawxMoIpAkuH/EU8JBht0sunWXNgU79boffr3XaCOp0AELJV/1iVIhFNYcE0Hh 84hM2A4wXYfG/zMds2ex6PjVQBVeA+hGMok1n1lECkTKevPJ1PRqWJAWEAC5xnGB4/tS uXkd7pK+4lz8hJTrqOVA8JfJLdgey2c3LMfVEa4TnyLy3NxRwaERyD3eDg2ZDFARv1es Vimg== X-Gm-Message-State: AOAM530n/KGonUwOe0DM3GBirVfILw1MTAMOfR8WkesvJlpEE2F6+yom VQfR9yzWOC3NioMsquChEn0= X-Google-Smtp-Source: ABdhPJx76/l2E/HyukrgHAeLcdQc2Ypx9BzDY/iDm8vH17cL8MGrc7Kg8/O/vBwyEGStE8W+Emy/Hg== X-Received: by 2002:a63:c64c:: with SMTP id x12mr2837301pgg.138.1600931654773; Thu, 24 Sep 2020 00:14:14 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id v205sm1762846pfc.110.2020.09.24.00.14.13 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:14:14 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 575762037C203D; Thu, 24 Sep 2020 16:14:12 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 04/21] um: host: implement os_initcalls and os_exitcalls Date: Thu, 24 Sep 2020 16:12:44 +0900 Message-Id: <278b23a9e7f1cb0de260f2c6fe9f5919fb51cce9.1600922528.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031416_957558_B84C26B4 X-CRM114-Status: GOOD ( 11.69 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:543 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Octavian Purdila , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Octavian Purdila This patch implements the init and exit calls for host code. It uses the automatic __start_
and __stop_
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. Signed-off-by: Octavian Purdila --- tools/um/uml/util.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/um/uml/util.c b/tools/um/uml/util.c index ecf2f390fad2..4011b36fee7e 100644 --- a/tools/um/uml/util.c +++ b/tools/um/uml/util.c @@ -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; +} From patchwork Thu Sep 24 07:12:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370369 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=UFuOwfmb; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=PrbxtanW; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmWS73zrz9sSC for ; Thu, 24 Sep 2020 17:14:28 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=BpW7Yw5aDeuidOFMasY8hNdc9wyE/p1Ko+vL383LbdI=; b=UFuOwfmb/I/pL4ud7x7bgaJCm ozTvIQ/RR+Py+ye3ebqka75YnmgpqpzuGkAWchbxVbo8uOvYk5ZxsyvZTXIwqy1ISvEywOTmOmXUe 6Om8j/3aes9PmmcASv6u2Pfa1L+2zqxC00OxMnH9sV/U8d7sYeo6CvBwAKIQNw0SvhO0lSZMQU+VZ pM4BCCcGfzOXiigjxp3IBgMh5ELM/N8JP14DC2SK+4KfX4LAPLD+yKMTFCZ/QyG+WaHP7fLkJaPA8 fa+dtQVzshAHmICpzXziOgKPl/h2pqdBxy0JMlNI4yHoCzjh8PPmJlcsQURz7sUBBXNUqn/2BWfZp vTcrJ1KzQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLST-0003GW-Sq; Thu, 24 Sep 2020 07:14:25 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLSR-0003FG-Ep for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:14:24 +0000 Received: by mail-pg1-x544.google.com with SMTP id u24so1368033pgi.1 for ; Thu, 24 Sep 2020 00:14:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=47LI9gybmx8klq4KsxiEL3i23ye+Wbjeal49mNMq+js=; b=PrbxtanWZPrk4/P4t4XJcH42p58dhbzoAcZRrVniRvWo1M+gjwsxwzquEn0tMN/32B KEIDzBM3FZq4hse4PIK+Cuvpg/UOMiNLCtB1un7p/dq26GyZhhTFp0Yg75cULR1wpSJU 4PuQ/u2/Z8LO1+lX/7jXMEE0+G+KXFTsvmDcupI6W+gaApZSzMupNHblnKNaUy9DpbT/ wEju4Rug80kKWEL+ctonQqvXQUIm7+Nlg2ySviUOGzLgHPpm9qwbn5jY7Tkur5ZjFXkC B5zYYvNmTXY5uvLZNNu7pGzT16+gxcEaLl1aJFC8ebO+LVRbz3L5dX5fXcgwlx3UGWz+ kTjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=47LI9gybmx8klq4KsxiEL3i23ye+Wbjeal49mNMq+js=; b=SH2fu4gV0ipLOVdpBevUjNgjeXrfDphdSIbSCHj7us94uCjZN8nZ0Z+uLNG4QawmHD wSv5qWA9SjElJaOm0A4/YUYIVRpndqeKbYb5h9F83q4vG0ROI4d1Wf4F5V+Pcuf2mkdy jEq3dHwALMuJPZBbPCrts82xjBv3c6oWKa1rh99WyAP8AXlqaATvVBeA0N+dYyOzVpbF p/a3Y/KQrPxtO2VjE5/1mOb8N2v08YH6GvbtcG1FjjI7uNkQRInzn0qnxutYpPauk2xl XU4kFtF8fMagc/ahLrijCeeYz9obiD4op5D9xegCQWuIuvO7AZDY+0fC37mUnBllqjvl B0/Q== X-Gm-Message-State: AOAM533Gkw2/2mPf6SkdXqtzzbDvnJOFvKTSPVROUAxHOxTG8dE3KoqC nLWphbcH/b+Sm6MKdTsVP58= X-Google-Smtp-Source: ABdhPJzrCV7ckpkPuk3w1HYurznDoZxodAv8mOknAH184zS7pQyap2xs79T9r19ifBD5dV4iFRdCeg== X-Received: by 2002:a63:b44f:: with SMTP id n15mr2907772pgu.282.1600931661297; Thu, 24 Sep 2020 00:14:21 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id z1sm1687528pgu.80.2020.09.24.00.14.20 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:14:20 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 8273D2037C204E; Thu, 24 Sep 2020 16:14:18 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 05/21] um: move arch/x86/um/os-Linux to tools/um/uml/ Date: Thu, 24 Sep 2020 16:12:45 +0900 Message-Id: <3e7c2da8fc1ad973d4b1df0a770e8ccfc75e45a6.1600922528.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031423_540571_FDCCE160 X-CRM114-Status: GOOD ( 15.54 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:544 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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). Signed-off-by: Hajime Tazaki --- 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%) diff --git a/arch/x86/um/Makefile b/arch/x86/um/Makefile index 77f70b969d14..25e9846b36a2 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -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) diff --git a/arch/x86/um/os-Linux/Makefile b/arch/x86/um/os-Linux/Makefile deleted file mode 100644 index 253bfb8cb702..000000000000 --- a/arch/x86/um/os-Linux/Makefile +++ /dev/null @@ -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 diff --git a/tools/um/Makefile b/tools/um/Makefile index 07b9b93ed817..552ed5f1edae 100644 --- a/tools/um/Makefile +++ b/tools/um/Makefile @@ -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: diff --git a/tools/um/uml/Build b/tools/um/uml/Build index 8e0607ee8b0a..435a9670d3ff 100644 --- a/tools/um/uml/Build +++ b/tools/um/uml/Build @@ -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) diff --git a/tools/um/uml/x86/Build b/tools/um/uml/x86/Build new file mode 100644 index 000000000000..16bbc7eb19d1 --- /dev/null +++ b/tools/um/uml/x86/Build @@ -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 diff --git a/arch/x86/um/os-Linux/mcontext.c b/tools/um/uml/x86/mcontext.c similarity index 100% rename from arch/x86/um/os-Linux/mcontext.c rename to tools/um/uml/x86/mcontext.c diff --git a/arch/x86/um/os-Linux/prctl.c b/tools/um/uml/x86/prctl.c similarity index 100% rename from arch/x86/um/os-Linux/prctl.c rename to tools/um/uml/x86/prctl.c diff --git a/arch/x86/um/os-Linux/registers.c b/tools/um/uml/x86/registers.c similarity index 100% rename from arch/x86/um/os-Linux/registers.c rename to tools/um/uml/x86/registers.c diff --git a/arch/x86/um/os-Linux/task_size.c b/tools/um/uml/x86/task_size.c similarity index 100% rename from arch/x86/um/os-Linux/task_size.c rename to tools/um/uml/x86/task_size.c diff --git a/arch/x86/um/os-Linux/tls.c b/tools/um/uml/x86/tls.c similarity index 100% rename from arch/x86/um/os-Linux/tls.c rename to tools/um/uml/x86/tls.c From patchwork Thu Sep 24 07:12:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370370 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=yAt1F4PM; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=WtO/UiL/; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmWp5Q0zz9sTQ for ; Thu, 24 Sep 2020 17:14:46 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+tC00qXfnQjXHoEYaiw+ZPy7g02jXOxC9dNm9zw7gP4=; b=yAt1F4PMr0/9d7BbzRqC2cHid yZnQWWnnbfZc6f3SsNxA4lNjVUZF3Wov09QXaeB2V3xRfBE0oUkF82amjDR1KvmfnhMqJ7vB/Sb5Z BNfasfiwcIhGgK9BAo57mOF6O9AwtGhyahRzHbGcwalGYQt2F96Mdx7F8/FX2hTbOx9RTPDzPs8AZ K50C7c7UrWAoR2G5I1qaMLMtZ93oyZ6Xqsj6pBANidb9MnavZwjaptfRKvQwLKREPLnWIc30+l8E7 rpxi1jkC4UE62Rqe3ocIdlO95yS6eIz98i2WENJrOZXKJTJ/iNCDxJiiuZDXa7klTwe70Uq3Z4sJM Lswsi3Q0w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLSl-0003L8-B4; Thu, 24 Sep 2020 07:14:43 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLSj-0003K5-Hc for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:14:42 +0000 Received: by mail-pf1-x441.google.com with SMTP id x123so1329499pfc.7 for ; Thu, 24 Sep 2020 00:14:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ux6BIm5/rJSpjWcuZxKCIwp0MrSLeyKL6rWTSIGyLyg=; b=WtO/UiL/zz4M8ysG/wBE+QP2vtWwNvlayy9W4Xt1Xk9ZKr36gU4V6bVUIXrG3hvBS2 afq7yUqRvk9NKC56VGiOxe46UWu3YEPgJBUcZpLmj55ULEovrvPk9G6HTTpmV2A+HL5V 14vqCGyxls2v6V5P4A/ZCjkp0kundR0PIMGuNrfkMiOmb59qUcL7xDTfLiqUIdLHv4w3 gAEswgmqwW1IkiLjSrucycQybScELl0jZGqZL1Tt2AA2JngL7njO9Q5W+6/JNlm4R9hs tysBVB1oRFlHyx7+lI8Z+zVu7Spoc19YsI1kk1rXAkmMbcJsgVE3bD7+ZvrHyRnJjGeb c7Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ux6BIm5/rJSpjWcuZxKCIwp0MrSLeyKL6rWTSIGyLyg=; b=EstumiYZPkQejMEn9JAhK0M+gCDKupVwWQN/9VuqbXPfjPb44e1tPUYW5c5JoG8NjD J76ygvpYeRHZYps8wphAtcgRH1urdDlRHtTHvmecwtyk84ZHuSqw4o4PdSha5/44TbPn pAcslBV5SaP4CwWfsyWnB4AfsonvUlsWHjlyyd+fE/bP1WBOz3DY7FBOL7sQemZJDc0U YWPgZS6cLtq3VkhOTk3mPyyuRXlxsxnq/fsVO1SkLPhW1yehz1BDbRWILqxgBc/ribKW jc9ulvdwYmHYPWxNQP/R8wOdmaeGhnY9xGwFpdlkRLsIJpW5+MYj7xYLSa687dhLAl2T RFiA== X-Gm-Message-State: AOAM532AY7kzCAbgCWT1X7+f/zMNYq1vqEDnNQfditW6I8Q9XJjqPd9W n8RePv2W+3z7OQPtoeR/ors= X-Google-Smtp-Source: ABdhPJyQ4zr142YUwOvfs73T/SmyGr/3TkkxuGXP7bAaMT5m/1RvLOe1H4VGMDWeqOBTjEbE+Pcwsg== X-Received: by 2002:a62:6490:0:b029:13f:c196:bb77 with SMTP id y138-20020a6264900000b029013fc196bb77mr3255458pfb.14.1600931679391; Thu, 24 Sep 2020 00:14:39 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id q21sm1823229pgt.48.2020.09.24.00.14.38 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:14:38 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id D9E782037C207B; Thu, 24 Sep 2020 16:14:35 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 06/21] scritps: um: suppress warnings if SRCARCH=um Date: Thu, 24 Sep 2020 16:12:46 +0900 Message-Id: X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031441_607222_152E30C9 X-CRM114-Status: UNSURE ( 8.77 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:441 listed in] [list.dnswl.org] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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. Signed-off-by: Hajime Tazaki --- scripts/headers_install.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh index dd554bd436cc..8890a0147012 100755 --- a/scripts/headers_install.sh +++ b/scripts/headers_install.sh @@ -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 From patchwork Thu Sep 24 07:12:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370371 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=ZOSeQ1sH; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=C41INqRQ; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmWx277Tz9sTH for ; Thu, 24 Sep 2020 17:14:53 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=5NEopfub8EWbX2BNoa1P4c+xQG4YWk4I/Yr/bktHaRo=; b=ZOSeQ1sH5RXxUFDZ7z2I21kTr SD+pl/F7mc+hdrU4YxmZcsdxjwORfV0BT/9MRewzqJ9MiYJ2bDSsa2JCXtOuHDg7Qu2LbUM0uIayN kxqPOph76TpPSrIuRhWWyd5P7/H4uaZDJadaYfqQ93p/xpJtIblUo55bJkAew0AcdfH+3xk0wCIUD KjBTVIvJ04ONPibWGcLTt8YEdPCu10j1BkNAxWdEwXSJOa89fOHOdqmN7ltq1h8UW3xpFFxel7YCl nVL/0JGlIQ4CQmZoKG6oh6C8h4s1omw3YBT0yjncHkQ0X8ZAX5OKUk1ETVQcfyTDnOE0SM5pf11sX DcKOWzu3Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLSs-0003MZ-2B; Thu, 24 Sep 2020 07:14:50 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLSp-0003Lq-Ea for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:14:48 +0000 Received: by mail-pl1-x642.google.com with SMTP id d19so1214826pld.0 for ; Thu, 24 Sep 2020 00:14:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uaZaINJO8RTX0sihp8PXPyj8BsV/dJ4sIfFZwNQgCoc=; b=C41INqRQL9wXKNEMfa2Cq9gnH6tyU2aaAcWC397Yxc+X4rbSPPDuT66/6sfi0KWWiT AV3W/hiYgfEi7XEvgRLQHFGN+ClX5VSYAGb+czXbF0QvJFcUcEy8uC8efnlgsJxn6QwE wExB+u9FVWDObRSI8l6Yn6/IWedlC0TTpsCC/yHTLrr9ayV5jt/FiPRL0YbuzkF3zp/9 z7A1A/C+OQeVCNntpiqOrcndO4LluVX7E/gAthh1z6+i8ZgFHrCTPYuJ7cHctzeIz1Kl maTHGbAbHeMgLeIg1DQRmAwQU1GCGzRdTqETNRbZMscyGlhpQ3VWu8JlIzBcZVG4nsij Hlqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uaZaINJO8RTX0sihp8PXPyj8BsV/dJ4sIfFZwNQgCoc=; b=COo0AxRsB4eFskoNXEJLtiE2Fkg26JT8nb6Rs3KvPIyR/xKBEm36r4T3po6FwvJ0EQ 2TIAUgmFOZ1GWEQfipZ0SHB83jI4HsKo63kU0oanywWJordj/5cluLAGOe3MLBliSOU3 FsZcnPKArvEjGpc1LDmUS9by32F+PWDB3zOre3FfVrqCCWuQYr7TUmDQlWlMoDNQJAdO 6SZl4+idwlv0THjpQu0XIvq2iesosELCDDWBGF+B925WgkM0puh8xwrYNl8LbnloQiUv zG/YgHq9AXFYQsY9pnppMKphicKfABjyekOihOcM9HkdZcGjZ7ABcqJ7wPqzRvLjxv7/ 5kfw== X-Gm-Message-State: AOAM533S7jQz4F6MW66VyH/U6Ee8ElSFGcAGuKyGzQhqj8mdNgR6CrVG BlglnIU+bysX/c+OxBzs+pA= X-Google-Smtp-Source: ABdhPJzq28mbtDOOoVJ8ZaXyYQry4wEm+ND0PGC2ggHIOU4euhMPSKxxXqQqIPUN5c589bjLvrdp5A== X-Received: by 2002:a17:902:ba8c:b029:d1:e5e7:be6a with SMTP id k12-20020a170902ba8cb02900d1e5e7be6amr3375156pls.68.1600931685359; Thu, 24 Sep 2020 00:14:45 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id v8sm1950402pgg.58.2020.09.24.00.14.44 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:14:44 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 0CC762037C2080; Thu, 24 Sep 2020 16:14:43 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 07/21] um: extend arch_switch_to for alternate SUBARCH Date: Thu, 24 Sep 2020 16:12:47 +0900 Message-Id: <4a3090dbb622a5892739573441bbc12a1a849330.1600922528.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031447_521066_B609816F X-CRM114-Status: GOOD ( 13.87 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:642 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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. Signed-off-by: Hajime Tazaki --- 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(-) diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c index 26b5e243d3fc..87a8cfa228ca 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -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; diff --git a/arch/x86/um/ptrace_32.c b/arch/x86/um/ptrace_32.c index 2497bac56066..0f184710d4ca 100644 --- a/arch/x86/um/ptrace_32.c +++ b/arch/x86/um/ptrace_32.c @@ -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) diff --git a/arch/x86/um/syscalls_64.c b/arch/x86/um/syscalls_64.c index 58f51667e2e4..2ef9474d2bd2 100644 --- a/arch/x86/um/syscalls_64.c +++ b/arch/x86/um/syscalls_64.c @@ -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; From patchwork Thu Sep 24 07:12:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370372 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=vVu0CSmD; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=F69KX5y7; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmXC5CR7z9sTH for ; Thu, 24 Sep 2020 17:15:07 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wZViYxwonuZR0Z+G6LYBU3E4xbhYV3x3kwcLIITCapM=; b=vVu0CSmD/LfMkqp/WLdz13taj hNCl1Yibg5bPYOiuxRzRHRCV9x9bYf27Z4tJCseaaKX4wx1PQFi1v3MJof+n/x9EvnETsYp+5jN+J mCQRBXaoVGIhCXJQiZ94Lc1WLpYqTf8ahPl7o8oYwQ8xMy8xBklnBA/yDJKP8EA8H7octuzERV+6K 1oABf6Q6UxKD+fwaGpnitYmNnI8CCgmGO6+id8q1JikaafIbU/4ASbBRON6ItZzlneiN3IxlxX8Ke roPPb78dmw7ZlFe79zPA3S6Uh96rXoF2yjJ1qmMOeKsXRjgEYAv5fP9SYuLcEiadNuVqAwV97rlk4 mqCaW6Nmw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLT6-0003PW-FH; Thu, 24 Sep 2020 07:15:04 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLT2-0003OQ-Nb for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:15:02 +0000 Received: by mail-pl1-x643.google.com with SMTP id j7so1173073plk.11 for ; Thu, 24 Sep 2020 00:15:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9DCkQlhWzbW4VmnEBn9lL1XJPXIhp4lgIV/TN2Yu03A=; b=F69KX5y7Ap7z+Uk18GoVPg9GUHhu30dTryxBEiz8owITRbHBsHQ904rWsMab+NyPtt 3h1xuKno4nYWVkQ2t/TLPm2syRSrKgzf8eacVCta7H3h06sbuFyrZx//4FhwbbFarC/6 iTdYpSjZPKSggM8bbjGEJffICBwwV5qUi74I3yWDZcrvmGur5gZ/my52M7e+j8xWvR4G usoNSdWG9yf5SDaVk4KclS5YRwib+iB0q9onesUmBNOVjuY5qaDEDNoLmj0Ha/Tx1S75 wO7DzljHUpQllApkJrTyKkyydFRIypukRD/G2XIQg+i/Ky+NMWBtVXTe/gqSJLTPRgYk h/QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9DCkQlhWzbW4VmnEBn9lL1XJPXIhp4lgIV/TN2Yu03A=; b=HG9ZISL8foIkUsy/t7KwJlBsftjqNbJNZDeEw91T8wie2LtKCgpRDlcU1xrDzIqzoG YR1PeoI9XlJJIerGMVvehiOwFXycZ4TbEAzzk8gFFx5IulGKA5VfT4cLNiTOI535PGun 3cr5BfhVQxsawCopW2sL6j+i3mmOQOQ16N03ApZGhv9b6bssyWH36rQGxTKsblJ5vRzn 5aKsypPw8jWeGuW3W8h09Ub01oKFRYj7L+S3Y01y+tFYYlkz5WTf63Gp1Iyy5rI1LfyQ 0vmLhqZ/jBO+xYtBA6jfHK2baV1UJmO+nZHeVFJaXt3MmxmvSjlhLT1xEnlMY9LroVWd kLjg== X-Gm-Message-State: AOAM531ucAcu1ihg+RtrSpl7rYrMaCSMP3SAwFkYhvfXud4dnWkEHWhB ONPGPYOK3vIG+5QgPA/a0oo= X-Google-Smtp-Source: ABdhPJwSxe5qELjWOC0AqltULuOC7ss2go4JPm+jgqcVtBxppodBoRqTXjA6TUppks/nCdTWYj041A== X-Received: by 2002:a17:90a:d315:: with SMTP id p21mr2872775pju.88.1600931698390; Thu, 24 Sep 2020 00:14:58 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id a14sm1386544pju.30.2020.09.24.00.14.57 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:14:57 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 578932037C208C; Thu, 24 Sep 2020 16:14:55 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 08/21] um: add nommu mode for UML library mode Date: Thu, 24 Sep 2020 16:12:48 +0900 Message-Id: <70437de3b6ec4ac3826f6288891cdf794dfae326.1600922528.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031500_774981_9F75BCF8 X-CRM114-Status: GOOD ( 21.51 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:643 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 Signed-off-by: Hajime Tazaki Signed-off-by: Octavian Purdila --- 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 diff --git a/arch/um/nommu/Makefile b/arch/um/nommu/Makefile new file mode 100644 index 000000000000..792d6005489e --- /dev/null +++ b/arch/um/nommu/Makefile @@ -0,0 +1 @@ +# diff --git a/arch/um/nommu/Makefile.um b/arch/um/nommu/Makefile.um new file mode 100644 index 000000000000..6cb0e9494d05 --- /dev/null +++ b/arch/um/nommu/Makefile.um @@ -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 diff --git a/arch/um/nommu/include/asm/Kbuild b/arch/um/nommu/include/asm/Kbuild new file mode 100644 index 000000000000..2532e1a0a0d1 --- /dev/null +++ b/arch/um/nommu/include/asm/Kbuild @@ -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 diff --git a/arch/um/nommu/include/asm/archparam.h b/arch/um/nommu/include/asm/archparam.h new file mode 100644 index 000000000000..ea32a7d3cf1b --- /dev/null +++ b/arch/um/nommu/include/asm/archparam.h @@ -0,0 +1 @@ +/* SPDX-License-Identifier: GPL-2.0 */ diff --git a/arch/um/nommu/include/asm/atomic.h b/arch/um/nommu/include/asm/atomic.h new file mode 100644 index 000000000000..63e2e16bda92 --- /dev/null +++ b/arch/um/nommu/include/asm/atomic.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_ATOMIC_H +#define __UM_NOMMU_ATOMIC_H + +#include + +#ifndef CONFIG_GENERIC_ATOMIC64 +#include "atomic64.h" +#endif /* !CONFIG_GENERIC_ATOMIC64 */ + +#endif diff --git a/arch/um/nommu/include/asm/atomic64.h b/arch/um/nommu/include/asm/atomic64.h new file mode 100644 index 000000000000..949360dea7af --- /dev/null +++ b/arch/um/nommu/include/asm/atomic64.h @@ -0,0 +1,114 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_ATOMIC64_H +#define __UM_NOMMU_ATOMIC64_H + +#include + +#ifdef CONFIG_SMP +#error "SMP is not supported on this platform" +#else +#define ATOMIC64_OP(op, c_op) \ + static inline void atomic64_##op(s64 i, atomic64_t *v) \ + { \ + unsigned long flags; \ + \ + raw_local_irq_save(flags); \ + v->counter = v->counter c_op i; \ + raw_local_irq_restore(flags); \ + } + +#define ATOMIC64_OP_RETURN(op, c_op) \ + static inline s64 atomic64_##op##_return(s64 i, atomic64_t *v) \ + { \ + unsigned long flags; \ + s64 ret; \ + \ + raw_local_irq_save(flags); \ + ret = (v->counter = v->counter c_op i); \ + raw_local_irq_restore(flags); \ + \ + return ret; \ + } + +#define ATOMIC64_FETCH_OP(op, c_op) \ + static inline s64 atomic64_fetch_##op(s64 i, atomic64_t *v) \ + { \ + unsigned long flags; \ + s64 ret; \ + \ + raw_local_irq_save(flags); \ + ret = v->counter; \ + v->counter = v->counter c_op i; \ + raw_local_irq_restore(flags); \ + \ + return ret; \ + } +#endif /* CONFIG_SMP */ + +#ifndef atomic64_add_return +ATOMIC64_OP_RETURN(add, +) +#endif + +#ifndef atomic64_sub_return + ATOMIC64_OP_RETURN(sub, -) +#endif + +#ifndef atomic64_fetch_add + ATOMIC64_FETCH_OP(add, +) +#endif + +#ifndef atomic64_fetch_sub + ATOMIC64_FETCH_OP(sub, -) +#endif + +#ifndef atomic64_fetch_and + ATOMIC64_FETCH_OP(and, &) +#endif + +#ifndef atomic64_fetch_or + ATOMIC64_FETCH_OP(or, |) +#endif + +#ifndef atomic64_fetch_xor + ATOMIC64_FETCH_OP(xor, ^) +#endif + +#ifndef atomic64_and + ATOMIC64_OP(and, &) +#endif + +#ifndef atomic64_or + ATOMIC64_OP(or, |) +#endif + +#ifndef atomic64_xor + ATOMIC64_OP(xor, ^) +#endif + +#undef ATOMIC64_FETCH_OP +#undef ATOMIC64_OP_RETURN +#undef ATOMIC64_OP + + +#define ATOMIC64_INIT(i) { (i) } + + static inline void atomic64_add(s64 i, atomic64_t *v) +{ + atomic64_add_return(i, v); +} + +static inline void atomic64_sub(s64 i, atomic64_t *v) +{ + atomic64_sub_return(i, v); +} + +#ifndef atomic64_read +#define atomic64_read(v) READ_ONCE((v)->counter) +#endif + +#define atomic64_set(v, i) WRITE_ONCE(((v)->counter), (i)) + +#define atomic64_xchg(ptr, v) (xchg(&(ptr)->counter, (v))) +#define atomic64_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), (old), (new))) + +#endif /* __LKL_ATOMIC64_H */ diff --git a/arch/um/nommu/include/asm/bitsperlong.h b/arch/um/nommu/include/asm/bitsperlong.h new file mode 100644 index 000000000000..a150cee41e75 --- /dev/null +++ b/arch/um/nommu/include/asm/bitsperlong.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_BITSPERLONG_H +#define __UM_NOMMU_BITSPERLONG_H + +#include + +#define BITS_PER_LONG __BITS_PER_LONG + +#define BITS_PER_LONG_LONG 64 + +#endif + diff --git a/arch/um/nommu/include/asm/byteorder.h b/arch/um/nommu/include/asm/byteorder.h new file mode 100644 index 000000000000..920a5fd26cad --- /dev/null +++ b/arch/um/nommu/include/asm/byteorder.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_BYTEORDER_H +#define __UM_NOMMU_BYTEORDER_H + +#include + +#endif diff --git a/arch/um/nommu/include/asm/cpu.h b/arch/um/nommu/include/asm/cpu.h new file mode 100644 index 000000000000..c101c078ef21 --- /dev/null +++ b/arch/um/nommu/include/asm/cpu.h @@ -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 diff --git a/arch/um/nommu/include/asm/elf.h b/arch/um/nommu/include/asm/elf.h new file mode 100644 index 000000000000..edcf63edeed1 --- /dev/null +++ b/arch/um/nommu/include/asm/elf.h @@ -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 diff --git a/arch/um/nommu/include/asm/mm_context.h b/arch/um/nommu/include/asm/mm_context.h new file mode 100644 index 000000000000..a2e53984aabd --- /dev/null +++ b/arch/um/nommu/include/asm/mm_context.h @@ -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 diff --git a/arch/um/nommu/include/asm/processor.h b/arch/um/nommu/include/asm/processor.h new file mode 100644 index 000000000000..3e8ba870caaf --- /dev/null +++ b/arch/um/nommu/include/asm/processor.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_PROCESSOR_H +#define __UM_NOMMU_PROCESSOR_H + +#include + +struct arch_thread { + struct lkl_sem *sched_sem; + bool dead; + lkl_thread_t tid; + struct lkl_jmp_buf sched_jb; + unsigned long stackend; +}; + +#include +#include + +#define INIT_ARCH_THREAD {} +#define task_pt_regs(tsk) (struct pt_regs *)(NULL) + +static inline void cpu_relax(void) +{ + unsigned long flags; + + /* since this is usually called in a tight loop waiting for some + * external condition (e.g. jiffies) lets run interrupts now to allow + * the external condition to propagate + */ + local_irq_save(flags); + local_irq_restore(flags); +} + +#define KSTK_EIP(tsk) (0) +#define KSTK_ESP(tsk) (0) + +static inline void trap_init(void) +{ +} + +static inline void arch_copy_thread(struct arch_thread *from, + struct arch_thread *to) +{ + panic("unimplemented %s: fork isn't supported yet", __func__); +} + +#endif diff --git a/arch/um/nommu/include/asm/ptrace.h b/arch/um/nommu/include/asm/ptrace.h new file mode 100644 index 000000000000..b214410e9825 --- /dev/null +++ b/arch/um/nommu/include/asm/ptrace.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_PTRACE_H +#define __UM_NOMMU_PTRACE_H + +#include + +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 diff --git a/arch/um/nommu/include/asm/sched.h b/arch/um/nommu/include/asm/sched.h new file mode 100644 index 000000000000..a4496f482633 --- /dev/null +++ b/arch/um/nommu/include/asm/sched.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_SCHED_H +#define __UM_NOMMU_SCHED_H + +#include +#include + +static inline void thread_sched_jb(void) +{ + if (test_ti_thread_flag(current_thread_info(), TIF_HOST_THREAD)) { + set_ti_thread_flag(current_thread_info(), TIF_SCHED_JB); + set_current_state(TASK_UNINTERRUPTIBLE); + lkl_ops->jmp_buf_set(¤t_thread_info()->task->thread.arch.sched_jb, + schedule); + } else { + lkl_bug("%s can be used only for host task", __func__); + } +} + +void switch_to_host_task(struct task_struct *); +int host_task_stub(void *unused); + +#endif diff --git a/arch/um/nommu/include/asm/segment.h b/arch/um/nommu/include/asm/segment.h new file mode 100644 index 000000000000..5608da95cb60 --- /dev/null +++ b/arch/um/nommu/include/asm/segment.h @@ -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 */ diff --git a/arch/um/nommu/include/uapi/asm/Kbuild b/arch/um/nommu/include/uapi/asm/Kbuild new file mode 100644 index 000000000000..4f79e5c4846d --- /dev/null +++ b/arch/um/nommu/include/uapi/asm/Kbuild @@ -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 diff --git a/arch/um/nommu/include/uapi/asm/bitsperlong.h b/arch/um/nommu/include/uapi/asm/bitsperlong.h new file mode 100644 index 000000000000..852566ac2e52 --- /dev/null +++ b/arch/um/nommu/include/uapi/asm/bitsperlong.h @@ -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 diff --git a/arch/um/nommu/include/uapi/asm/byteorder.h b/arch/um/nommu/include/uapi/asm/byteorder.h new file mode 100644 index 000000000000..e7ad11a751cf --- /dev/null +++ b/arch/um/nommu/include/uapi/asm/byteorder.h @@ -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 +#else +#include +#endif + +#endif diff --git a/arch/um/nommu/include/uapi/asm/sigcontext.h b/arch/um/nommu/include/uapi/asm/sigcontext.h new file mode 100644 index 000000000000..b934ae7f5550 --- /dev/null +++ b/arch/um/nommu/include/uapi/asm/sigcontext.h @@ -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 + +struct sigcontext { + struct pt_regs regs; + unsigned long oldmask; +}; + +#endif diff --git a/arch/um/nommu/um/delay.c b/arch/um/nommu/um/delay.c new file mode 100644 index 000000000000..58a366d9b5f0 --- /dev/null +++ b/arch/um/nommu/um/delay.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include + +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) +{ +} diff --git a/arch/um/nommu/um/shared/sysdep/archsetjmp.h b/arch/um/nommu/um/shared/sysdep/archsetjmp.h new file mode 100644 index 000000000000..4a5c10d7521b --- /dev/null +++ b/arch/um/nommu/um/shared/sysdep/archsetjmp.h @@ -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 */ diff --git a/arch/um/nommu/um/shared/sysdep/faultinfo.h b/arch/um/nommu/um/shared/sysdep/faultinfo.h new file mode 100644 index 000000000000..49210742212d --- /dev/null +++ b/arch/um/nommu/um/shared/sysdep/faultinfo.h @@ -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 */ diff --git a/arch/um/nommu/um/shared/sysdep/kernel-offsets.h b/arch/um/nommu/um/shared/sysdep/kernel-offsets.h new file mode 100644 index 000000000000..a004bffb7b8d --- /dev/null +++ b/arch/um/nommu/um/shared/sysdep/kernel-offsets.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include +#include +#include +#include +#include +#include + +void foo(void) +{ +#include +} diff --git a/arch/um/nommu/um/shared/sysdep/mcontext.h b/arch/um/nommu/um/shared/sysdep/mcontext.h new file mode 100644 index 000000000000..b734012a74da --- /dev/null +++ b/arch/um/nommu/um/shared/sysdep/mcontext.h @@ -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 */ diff --git a/arch/um/nommu/um/shared/sysdep/ptrace.h b/arch/um/nommu/um/shared/sysdep/ptrace.h new file mode 100644 index 000000000000..bfdfb520a21d --- /dev/null +++ b/arch/um/nommu/um/shared/sysdep/ptrace.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ARCH_UM_PTRACE_H +#define __ARCH_UM_PTRACE_H + +#include +#include + +struct task_struct; + +#define UPT_SYSCALL_NR(r) ((r)->syscall) +#define UPT_RESTART_SYSCALL(r) ((r)->syscall--) /* XXX */ + +#define UPT_SP(r) 0 +#define UPT_IP(r) 0 +#define EMPTY_UML_PT_REGS { } + +#define MAX_REG_OFFSET (UM_FRAME_SIZE) +#define MAX_REG_NR ((MAX_REG_OFFSET) / sizeof(unsigned long)) + +/* unused */ +struct uml_pt_regs { + unsigned long gp[1]; + unsigned long fp[1]; + long faultinfo; + long syscall; + int is_user; +}; + +extern void arch_init_registers(int pid); + +static inline long arch_ptrace(struct task_struct *child, + long request, unsigned long addr, + unsigned long data) +{ + return -EINVAL; +} + +static inline void ptrace_disable(struct task_struct *child) {} +static inline void user_enable_single_step(struct task_struct *child) {} +static inline void user_disable_single_step(struct task_struct *child) {} + +#endif /* __ARCH_UM_PTRACE_H */ diff --git a/arch/um/nommu/um/shared/sysdep/ptrace_user.h b/arch/um/nommu/um/shared/sysdep/ptrace_user.h new file mode 100644 index 000000000000..86d5cb20fb9f --- /dev/null +++ b/arch/um/nommu/um/shared/sysdep/ptrace_user.h @@ -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 diff --git a/arch/um/nommu/um/unimplemented.c b/arch/um/nommu/um/unimplemented.c new file mode 100644 index 000000000000..fe33e02e39e5 --- /dev/null +++ b/arch/um/nommu/um/unimplemented.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include + +/* physmem.c */ +unsigned long high_physmem; + +/* x86/um/setjmp*.S */ +void kernel_longjmp(void) +{} +void kernel_setjmp(void) +{} + +/* trap.c */ +void relay_signal(int sig, struct siginfo *si, struct uml_pt_regs *regs) +{} +void bus_handler(int sig, struct siginfo *si, struct uml_pt_regs *regs) +{} +void segv_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs) +{} +void winch(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs) +{} + +/* tlb.c */ +void flush_tlb_kernel_vm(void) +{} +void force_flush_all(void) +{} + +/* skas/process.c */ +void halt_skas(void) +{} +int is_skas_winch(int pid, int fd, void *data) +{ + return 0; +} +void reboot_skas(void) +{} + +int __init start_uml(void) +{ + return 0; +} + +/* exec.c */ +void flush_thread(void) +{} + +/* x86/ptrace_64.c */ +int is_syscall(unsigned long addr) +{ + return 0; +} + + +/* x86/sysrq.c */ +void show_regs(struct pt_regs *regs) +{} + +/* x86/signal.c */ +int setup_signal_stack_si(unsigned long stack_top, struct ksignal *ksig, + struct pt_regs *regs, sigset_t *mask) +{ + return 0; +} + +/* x86/bugs.c */ +void arch_check_bugs(void) +{} diff --git a/arch/um/nommu/um/user_constants.h b/arch/um/nommu/um/user_constants.h new file mode 100644 index 000000000000..2245d3d24120 --- /dev/null +++ b/arch/um/nommu/um/user_constants.h @@ -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 From patchwork Thu Sep 24 07:12:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370373 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=jxB0oxew; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=BH0a5uo5; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmXH0zqtz9sTh for ; Thu, 24 Sep 2020 17:15:11 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Ev13io4BoF4mfWDVVWgJkh+r+Ekl97MOI/ZzFe2QKKQ=; b=jxB0oxewRsh8rd8j87CN9Ctw+ /kQ1qSwt3xysPOGA4LWP9nzKsjHOoD5R5o/CHZa7pth4rGBtyJbNTbhwHUOBf5AH0yJR22P563caQ PCfE6JdyNyGQtj3bTVJXfmqKcSg7jxx7nplzt+0lsq3CCsA8gL/1lyNYX7Q/zXwbOYdoYguGUS29u +w2Lo88/ID2O/b8X22STi4CwDmPd444qqdT+mF2Z8H4pD0FLPqVOTKzP1rsxIHwKv6jEiQI6mnlip JSe2iCjOfxEJl8UOjktukBcRdQpWcYsMjzxT2Nq+YP2z5f4TCDiLAGPnnuQGm3IV8zUth92Qm+5+3 /rNtmdHyA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLT9-0003Qy-Vr; Thu, 24 Sep 2020 07:15:08 +0000 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLT7-0003PV-Pc for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:15:06 +0000 Received: by mail-pj1-x1044.google.com with SMTP id kk9so1126733pjb.2 for ; Thu, 24 Sep 2020 00:15:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QwdAwomAk2ltg1grbV+9NQkaDdoDFru+sqVSXHRR9r4=; b=BH0a5uo5jp049dqpjp2ECh38Gi0b4GWVN5mpv8oiL7iDE5F8xxUTMP+Kh9mbaC0VAf kBSJpAHtEemOQDoQlYnYYJYGY8Mu00iynsbyEOeKioDsuYeMZIsGm5FiZBbJ48Mdnfbr Tni8MJDilbEReq/W9dd96KVMIhcnmXEbpTPUSsuR9KdCF4mypx1DTRYOatXv7fbng1MT 9HZg98c2ky+ONVmut762iJrb+bd9NNE0ksZF9dw0LmVhRE6LjhSvyMBkD+W949R39NOV j7UTwFr+zE28GNkzCrlit6aW6dSiNfB5vb3JuuLmDYFsQIF/RX1xSa5TjLJqaVo2UgMo 1M9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QwdAwomAk2ltg1grbV+9NQkaDdoDFru+sqVSXHRR9r4=; b=foFhMPmFvL/hdLfVo04Z823AYuj3yLFdE03/sxv3iFnCs8gOxwH8vIXTZus/Ci134f KR2SOU/cQpa+1OwsETRlsGl37qDmY5LS1MxF9ydLR0Is0eE3WubU4IAmqnVgPz8WPSS2 odE7jEUmsclqIZRZud58QpKIaD7Z5uvtyItiji7sN9exvK9rFVTtf3rMWBmhcwfFFyIl sgUTeACY/oUoZpDdC7C7YpDoDHHdKNkX8Bp5cZKp3R11otQq1ikEvMokv5WOpbS4EBMP JDOScZab2/Q6ssjELZ9JP6HltHvcV94/nB1v2fPO+qna8w3CbKrRdbyrgDMmisjUT3mZ Gt4g== X-Gm-Message-State: AOAM530ewAVqoDhkZNWczcNd9HAk0V47Y3eIoO99iSYIy9TA1ouMhGTb wP+3thZWhBn7G9RT5K3qVco= X-Google-Smtp-Source: ABdhPJxqYiC/7wivghrhZuAtVVI0RhkfS67HzvSRJ9NVggJKLS5sbQF8uk+t/hJn1ibvXRCjfpdreQ== X-Received: by 2002:a17:902:7286:b029:d1:e598:400f with SMTP id d6-20020a1709027286b02900d1e598400fmr3264071pll.73.1600931703572; Thu, 24 Sep 2020 00:15:03 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id f207sm1897142pfa.54.2020.09.24.00.15.02 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:15:02 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id C3F0B2037C208E; Thu, 24 Sep 2020 16:15:00 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 09/21] um: nommu: host interface Date: Thu, 24 Sep 2020 16:12:49 +0900 Message-Id: <8ee5307216dda4f695e84eb1dcc2dab166e08ee7.1600922528.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031505_833535_BF0E42C9 X-CRM114-Status: GOOD ( 13.80 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1044 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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. Signed-off-by: Hajime Tazaki --- 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 diff --git a/arch/um/include/asm/host_ops.h b/arch/um/include/asm/host_ops.h new file mode 100644 index 000000000000..f52423cc4ced --- /dev/null +++ b/arch/um/include/asm/host_ops.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_LKL_HOST_OPS_H +#define _ASM_LKL_HOST_OPS_H + +#include + +extern struct lkl_host_operations *lkl_ops; + +#endif diff --git a/arch/um/nommu/include/uapi/asm/host_ops.h b/arch/um/nommu/include/uapi/asm/host_ops.h new file mode 100644 index 000000000000..d3dad11b459e --- /dev/null +++ b/arch/um/nommu/include/uapi/asm/host_ops.h @@ -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 From patchwork Thu Sep 24 07:12:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370374 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=n4yW79FY; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=DFArfsPF; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmXM5JSbz9sTH for ; Thu, 24 Sep 2020 17:15:15 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=FdGtLmtU6bG+df7iVpwJx+q9zgNFX6ZT0/koGGFInyI=; b=n4yW79FYumNbFEMf3EpCMwJnI d/f2e+wVC1euONYQy5VyOlW+MV/5gl/wLEWxN2JM7ezKas9Xp0hc668qN6z7WXtix9ckw4DCHFxh/ cbku1WrdTmcphK99O1OeZJY5BQVtdYZUKyKxBdTGkuM/wzsTWByPKheOxytxThxNEGcpNTYSM2Rmb an82ZzzYQSruYa2POx+C+5rozy+CDY6YAbniSf2AE/h+eS5TBZyXlL5avhfvZCaXJX9gWy3Pwv20i tZB6W/qx2M4vHuejDK0Nd/G+A4qzlMNizuTOupp9B2+HKYvsFk0VEoyi4Dzji/spwTIbij4B7cp7Q 8n2b+sFQA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLTE-0003T6-G5; Thu, 24 Sep 2020 07:15:12 +0000 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLTB-0003RG-Mg for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:15:10 +0000 Received: by mail-pj1-x1041.google.com with SMTP id mm21so1189171pjb.4 for ; Thu, 24 Sep 2020 00:15:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S9Vu5NCJNPF2O2RM9kWkruAVRja6D8FxeGaKm3ixWZA=; b=DFArfsPFj3BIIeVrqGnBkw5T+DqIanUQbbs2ql9tRRKVZUTATXdhbTNd9uYDV6qH+Y ggvyO7aZONngEzbQbWS5imltSlH6SpDb+AXsLMIygq/wIaiD6Zr8F732QvFR5be5htDU MaQYs+GLa+Fcc0FfN3qWKVfFwKcg9jqTMgMUvVywPzmnX0tqwmGNEnTxWe51Qlzy+T5s escTcovtJR6HAUeBQAH5J76Sq5bpCcnMARwVyUBoFhuC+NZSJ9p387Ac9MssXI5mOU6m d6IOEMj0SwnRK1T109VME9wxDGM0z1vKrF3IKY68MyXtYblsr9+mzmDVv3YEWj2xQX/6 OgSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S9Vu5NCJNPF2O2RM9kWkruAVRja6D8FxeGaKm3ixWZA=; b=ogSDBikfGwoiTIzYOaKBx+0ODv+gIdZbvVQh0jMCDB/qkeFZGXX0eBd2yKrd5KXMoV 0gdWeL0KSMoCx6Evbl3vMjcy4E+++HsaKT2S+hOralVmaNuuue8Ltkao6w4V34hSLTng bm1XvOwzDkltl7k9W+F/NeFOL37CE7O6RSyPBuhNNRsmxqlbGwmbkmFOCtJGP2KDZs4W 8zMF+3Y4tDNozunYHbzbP9cUSB+aiK9Fqxj/k/dAOAUq8JnMhy2wXjYMJA8G3uhLs1ZC BS6+wo1tqfubu2R1MDQbpc9wfDVTC0i2NN3uNRZ0c9TZmc7krKXXri2rHpmT9pJnTUCR DEyA== X-Gm-Message-State: AOAM531gxEqaP0RM3MsmGj7kw2HcV+8H2SW62LSR/Rb7bDWHb1HjrxSm vK83djT/q2IQtq7CTblkoS6dOYc14nBpcA== X-Google-Smtp-Source: ABdhPJyelWoKvjgxpRkDjh6jugO1oBlNHdNcabq6LpmcFIStM/OuLhEjx77H826+WD2xbRDn7zIDvg== X-Received: by 2002:a17:902:d711:b029:d1:c6b5:ae5f with SMTP id w17-20020a170902d711b02900d1c6b5ae5fmr3371753ply.38.1600931707414; Thu, 24 Sep 2020 00:15:07 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id 16sm1365403pjl.27.2020.09.24.00.15.06 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:15:06 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id AFC5E2037C2090; Thu, 24 Sep 2020 16:15:04 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 10/21] um: nommu: memory handling Date: Thu, 24 Sep 2020 16:12:50 +0900 Message-Id: X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031509_741062_5565F193 X-CRM114-Status: GOOD ( 26.90 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1041 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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. Signed-off-by: Hajime Tazaki Signed-off-by: Octavian Purdila --- 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 diff --git a/arch/um/include/asm/mmu.h b/arch/um/include/asm/mmu.h index 5b072aba5b65..c06d6cb67dd7 100644 --- a/arch/um/include/asm/mmu.h +++ b/arch/um/include/asm/mmu.h @@ -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); diff --git a/arch/um/include/asm/mmu_context.h b/arch/um/include/asm/mmu_context.h index 17ddd4edf875..4b06c29ae830 100644 --- a/arch/um/include/asm/mmu_context.h +++ b/arch/um/include/asm/mmu_context.h @@ -6,6 +6,7 @@ #ifndef __UM_MMU_CONTEXT_H #define __UM_MMU_CONTEXT_H +#ifdef CONFIG_MMU #include #include #include @@ -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 + +extern void force_flush_all(void); + +#endif /* CONFIG_MMU */ + #endif diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h index 95af12e82a32..c9d5e487ac6b 100644 --- a/arch/um/include/asm/page.h +++ b/arch/um/include/asm/page.h @@ -7,6 +7,8 @@ #ifndef __UM_PAGE_H #define __UM_PAGE_H +#ifdef CONFIG_MMU + #include /* 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 + +#define __va_space (8*1024*1024) + +#ifndef __ASSEMBLY__ +#include +void free_mem(void); +#endif + +#endif /* !CONFIG_MMU */ + #endif /* __UM_PAGE_H */ diff --git a/arch/um/include/asm/pgtable.h b/arch/um/include/asm/pgtable.h index def376194dce..7e506d5406e3 100644 --- a/arch/um/include/asm/pgtable.h +++ b/arch/um/include/asm/pgtable.h @@ -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 #else @@ -323,4 +325,29 @@ do { \ __flush_tlb_one((vaddr)); \ } while (0) +#else /* CONFIG_MMU */ + +#include + +#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 diff --git a/arch/um/include/asm/uaccess.h b/arch/um/include/asm/uaccess.h index fe66d659acad..95db8f06d295 100644 --- a/arch/um/include/asm/uaccess.h +++ b/arch/um/include/asm/uaccess.h @@ -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 +#endif /* CONFIG_MMU */ + + #endif diff --git a/arch/um/nommu/include/uapi/asm/host_ops.h b/arch/um/nommu/include/uapi/asm/host_ops.h index d3dad11b459e..5253c3f8de0e 100644 --- a/arch/um/nommu/include/uapi/asm/host_ops.h +++ b/arch/um/nommu/include/uapi/asm/host_ops.h @@ -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, ...); diff --git a/arch/um/nommu/um/bootmem.c b/arch/um/nommu/um/bootmem.c new file mode 100644 index 000000000000..6ae4c26e2b74 --- /dev/null +++ b/arch/um/nommu/um/bootmem.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include + +unsigned long memory_start, memory_end; +static unsigned long _memory_start, mem_size; + +unsigned long *empty_zero_page; + +/* XXX: unused */ +unsigned long long highmem; +int iomem_size; +int kmalloc_ok = 1; + +void __init setup_physmem(unsigned long start, unsigned long reserve_end, + unsigned long mem_sz, unsigned long long _highmem) +{ + mem_size = mem_sz; + + _memory_start = (unsigned long)lkl_ops->mem_alloc(mem_size); + memory_start = _memory_start; + WARN_ON(!memory_start); + memory_end = memory_start + mem_size; + + if (PAGE_ALIGN(memory_start) != memory_start) { + mem_size -= PAGE_ALIGN(memory_start) - memory_start; + memory_start = PAGE_ALIGN(memory_start); + mem_size = (mem_size / PAGE_SIZE) * PAGE_SIZE; + } + pr_info("memblock address range: 0x%lx - 0x%lx\n", memory_start, + memory_start+mem_size); + /* + * Give all the memory to the bootmap allocator, tell it to put the + * boot mem_map at the start of memory. + */ + max_low_pfn = virt_to_pfn(memory_end); + min_low_pfn = virt_to_pfn(memory_start); + memblock_add(memory_start, mem_size); + + 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, }; + + zones_size[ZONE_NORMAL] = max_low_pfn; + free_area_init(zones_size); + } +} + +void __init mem_init(void) +{ + max_mapnr = (((unsigned long)high_memory) - PAGE_OFFSET) >> PAGE_SHIFT; + /* this will put all memory onto the freelists */ + totalram_pages_add(memblock_free_all()); + pr_info("Memory available: %luk/%luk RAM\n", + (nr_free_pages() << PAGE_SHIFT) >> 10, mem_size >> 10); +} + +/* + * In our case __init memory is not part of the page allocator so there is + * nothing to free. + */ +void free_initmem(void) +{ +} + +void free_mem(void) +{ + lkl_ops->mem_free((void *)_memory_start); +} + +void *uml_kmalloc(int size, int flags) +{ + return kmalloc(size, flags); +} + +void __init mem_total_pages(unsigned long physmem, unsigned long iomem, + unsigned long _highmem) +{ +} + +void __init paging_init(void) +{ +} From patchwork Thu Sep 24 07:12:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370375 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=Zi3h3Pnk; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=HhcKKWh5; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmXT4Rd3z9sSC for ; Thu, 24 Sep 2020 17:15:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=7Bm6LhSmSEORs8BuwUxnNvlNgMS231IMq96F2pYW3mk=; b=Zi3h3PnkL2cmXgqpN3nNIYywK mfA0rDUURt/KvIL047fxI9k3YV3F29XQASi1UJGgMQOMiQaVDAcNc4d5OQdNd5Xt7hG34UZtsl51a 9MuGXubeotpjrN+YddxswwL0uGW4zT78nkroIxG4pWGmuamGLJtcsX3q/4yMJBRF5EQc1P6VUyHz7 tJIGJJqVJdfZfY2684aGnGXxla8juUBivuxIei52YojRrMtXioi522EeyVrQyKCA9i5C8SpFkWYPE 3fGNiZgQrqEU7fqD6O2Yv0Wz5W9Se6gz2ef+HukbejmyJ9ysaaBavjvEijeai4i7fAuQzAGeNBBnx DJ74qX6cA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLTK-0003VE-BH; Thu, 24 Sep 2020 07:15:18 +0000 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLTH-0003TY-CB for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:15:16 +0000 Received: by mail-pg1-x536.google.com with SMTP id y14so1329849pgf.12 for ; Thu, 24 Sep 2020 00:15:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2kFH8N4Cgjs+ANsx5ksO/8NB2yUFBlkb+VOjV48yrUE=; b=HhcKKWh5EPGe0PgeD4kFrSezQJDJBrjMlZCxx+wDLfavx2A7G1Ovdv/4afQT1qODvo AVTz39LBwbBzxxVy5Gvv2brXKzKgXVuYXqvsc/4V1t4jzd0bLRKsoGj1wW47xz+NJxcM ThI+7/lL7rBj7k7czk9PIXprp4m70liUsxkABjsoTT/4aWgo3rNUxtWsrI5A2j99FZrF VBW5jAcI7SAmAaUiM0ppMU/ddoUHWElIO5y5KeGJMuH8Wxz+ounWVBFI0WYljW5AJO+B dDnfA8qyEg4q/zpEH+9dCudG1dxFqNnwDDimC97upYtBdOls6wNgoYTSWADeb8dp/htO G1Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2kFH8N4Cgjs+ANsx5ksO/8NB2yUFBlkb+VOjV48yrUE=; b=Nsz0/nLiBUb+DHC9cDGYkg/nocg8DM15B16DTRfN1PT98sZSSOM6/7A6bf7dB17gbL MAVxkpCQmDCUjREZ302806C/Elwb6YapFal/elZGeEtWjiKpq/YjWYZE/EWzOH7lvoCz Z2IWkXPO22FEBbN4U/x6nKoCnuYh20Q8Af5Emyhg5Bka1CUqddNFdvCC2Fc1ZY/H73Kd L7kLIP8vo9acgM36p2zNCf1jzQPVeJ03MLy0QFe7zXqcOhiZvPqKoGIO211iySNviQxq rTC5jhM+R4x+dOHKUfXRuS2uxlyWmSsYtndP/Aw4ujC4eqy8S2IzngzEe6VLHORCXwTP aQjw== X-Gm-Message-State: AOAM531zrHKY0ddwdNqr6OC4R00Ko75Drl+6ylIfbqll2Nxt9yL9bBM3 37bVlFZpXyAFymMOcijifjM= X-Google-Smtp-Source: ABdhPJyiBOWxuX4EY3nwNh3PWeEB8YdJ/ezLmbIIF4qLSRx+W/1e8wbi55aqOS/KL+sY1potSOz/+Q== X-Received: by 2002:a63:1a66:: with SMTP id a38mr2790621pgm.253.1600931712768; Thu, 24 Sep 2020 00:15:12 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id c3sm1767316pfn.23.2020.09.24.00.15.11 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:15:12 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 8E6262037C2093; Thu, 24 Sep 2020 16:15:09 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 11/21] um: nommu: kernel thread support Date: Thu, 24 Sep 2020 16:12:51 +0900 Message-Id: <96fbcabaab75ab8d78cb1da58a8fefb355d8c687.1600922529.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031515_425431_69917E3C X-CRM114-Status: GOOD ( 37.18 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:536 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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. Signed-off-by: Hajime Tazaki Signed-off-by: Octavian Purdila --- 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 diff --git a/arch/um/include/asm/thread_info.h b/arch/um/include/asm/thread_info.h index 4c19ce4c49f1..433584f6b9d0 100644 --- a/arch/um/include/asm/thread_info.h +++ b/arch/um/include/asm/thread_info.h @@ -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) diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c index 87a8cfa228ca..432edcbb5eea 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -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(); } diff --git a/arch/um/nommu/include/uapi/asm/host_ops.h b/arch/um/nommu/include/uapi/asm/host_ops.h index 5253c3f8de0e..720385fccbdf 100644 --- a/arch/um/nommu/include/uapi/asm/host_ops.h +++ b/arch/um/nommu/include/uapi/asm/host_ops.h @@ -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 + * 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 * */ struct lkl_host_operations { + struct lkl_sem *(*sem_alloc)(int count); + void (*sem_free)(struct lkl_sem *sem); + void (*sem_up)(struct lkl_sem *sem); + void (*sem_down)(struct lkl_sem *sem); + + struct lkl_mutex *(*mutex_alloc)(int recursive); + void (*mutex_free)(struct lkl_mutex *mutex); + void (*mutex_lock)(struct lkl_mutex *mutex); + void (*mutex_unlock)(struct lkl_mutex *mutex); + + lkl_thread_t (*thread_create)(void *(*f)(void *), void *arg); + void (*thread_detach)(void); + void (*thread_exit)(void); + int (*thread_join)(lkl_thread_t tid); + lkl_thread_t (*thread_self)(void); + int (*thread_equal)(lkl_thread_t a, lkl_thread_t b); + long (*gettid)(void); + + void (*jmp_buf_set)(struct lkl_jmp_buf *jmpb, void (*f)(void)); + void (*jmp_buf_longjmp)(struct lkl_jmp_buf *jmpb, int val); + void *(*mem_alloc)(unsigned long mem); void (*mem_free)(void *mem); }; diff --git a/arch/um/nommu/um/cpu.c b/arch/um/nommu/um/cpu.c new file mode 100644 index 000000000000..9986a3f8c5dd --- /dev/null +++ b/arch/um/nommu/um/cpu.c @@ -0,0 +1,236 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void run_irqs(void) +{ + panic("unimplemented %s", __func__); +} + +int set_irq_pending(int irq) +{ + panic("unimplemented %s", __func__); +} + +/* + * This structure is used to get access to the "LKL CPU" that allows us to run + * 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); + if (cpu.sem) + lkl_ops->sem_free(cpu.sem); + if (cpu.lock) + lkl_ops->mutex_free(cpu.lock); +} + +void subarch_cpu_idle(void) +{ + if (cpu.shutdown_gate >= MAX_THREADS) { + + lkl_ops->mutex_lock(cpu.lock); + while (cpu.sleepers--) + lkl_ops->sem_up(cpu.sem); + lkl_ops->mutex_unlock(cpu.lock); + + lkl_cpu_cleanup(true); + + lkl_ops->thread_exit(); + } + +#ifdef doesntwork + /* switch to idle_host_task */ + wakeup_idle_host_task(); +#endif +} + +int lkl_cpu_init(void) +{ + cpu.lock = lkl_ops->mutex_alloc(0); + cpu.sem = lkl_ops->sem_alloc(0); + cpu.shutdown_sem = lkl_ops->sem_alloc(0); + + if (!cpu.lock || !cpu.sem || !cpu.shutdown_sem) { + lkl_cpu_cleanup(false); + return -ENOMEM; + } + + return 0; +} diff --git a/arch/um/nommu/um/threads.c b/arch/um/nommu/um/threads.c new file mode 100644 index 000000000000..3e70eccc191a --- /dev/null +++ b/arch/um/nommu/um/threads.c @@ -0,0 +1,258 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include + +#include + +static int init_arch_thread(struct arch_thread *thread) +{ + thread->sched_sem = lkl_ops->sem_alloc(0); + if (!thread->sched_sem) + return -ENOMEM; + + thread->dead = false; + thread->tid = 0; + + return 0; +} + +unsigned long *alloc_thread_stack_node(struct task_struct *task, int node) +{ + struct thread_info *ti; + + ti = kmalloc(sizeof(*ti), GFP_KERNEL | __GFP_ZERO); + if (!ti) + return NULL; + + ti->task = task; + return (unsigned long *)ti; +} + +/* + * The only new tasks created are kernel threads that have a predefined starting + * point thus no stack copy is required. + */ +void setup_thread_stack(struct task_struct *p, struct task_struct *org) +{ + struct thread_info *ti = task_thread_info(p); + struct thread_info *org_ti = task_thread_info(org); + + ti->flags = org_ti->flags; + ti->preempt_count = org_ti->preempt_count; + ti->addr_limit = org_ti->addr_limit; +} + +static void kill_thread(struct thread_info *ti) +{ + if (!test_ti_thread_flag(ti, TIF_HOST_THREAD)) { + ti->task->thread.arch.dead = true; + lkl_ops->sem_up(ti->task->thread.arch.sched_sem); + lkl_ops->thread_join(ti->task->thread.arch.tid); + } + lkl_ops->sem_free(ti->task->thread.arch.sched_sem); +} + +void free_thread_stack(struct task_struct *tsk) +{ + struct thread_info *ti = task_thread_info(tsk); + + kill_thread(ti); + kfree(ti); +} + +struct thread_info *_current_thread_info = &init_thread_union.thread_info; + +void switch_threads(jmp_buf *me, jmp_buf *you) +{ + /* NOP */ +} + +/* + * schedule() expects the return of this function to be the task that we + * switched away from. Returning prev is not going to work because we are + * actually going to return the previous taks that was scheduled before the + * task we are going to wake up, and not the current task, e.g.: + * + * swapper -> init: saved prev on swapper stack is swapper + * init -> ksoftirqd0: saved prev on init stack is init + * ksoftirqd0 -> swapper: returned prev is swapper + */ +static struct task_struct *abs_prev = &init_task; + +void arch_switch_to(struct task_struct *prev, + struct task_struct *next) +{ + struct arch_thread *_prev = &prev->thread.arch; + struct arch_thread *_next = &next->thread.arch; + unsigned long _prev_flags = task_thread_info(prev)->flags; + struct lkl_jmp_buf *_prev_jb; + + _current_thread_info = task_thread_info(next); + next->thread.prev_sched = prev; + abs_prev = prev; + + WARN_ON(!_next->tid); + lkl_cpu_change_owner(_next->tid); + + if (test_bit(TIF_SCHED_JB, &_prev_flags)) { + /* Atomic. Must be done before wakeup next */ + clear_ti_thread_flag(task_thread_info(prev), TIF_SCHED_JB); + _prev_jb = &_prev->sched_jb; + } + + lkl_ops->sem_up(_next->sched_sem); + if (test_bit(TIF_SCHED_JB, &_prev_flags)) + lkl_ops->jmp_buf_longjmp(_prev_jb, 1); + else + lkl_ops->sem_down(_prev->sched_sem); + + if (_prev->dead) + lkl_ops->thread_exit(); + + /* __switch_to (arch/um) returns this value */ + current->thread.prev_sched = abs_prev; +} + +int host_task_stub(void *unused) +{ + return 0; +} + +void switch_to_host_task(struct task_struct *task) +{ + if (WARN_ON(!test_tsk_thread_flag(task, TIF_HOST_THREAD))) + return; + + task->thread.arch.tid = lkl_ops->thread_self(); + + if (current == task) + return; + + wake_up_process(task); + thread_sched_jb(); + lkl_ops->sem_down(task->thread.arch.sched_sem); + schedule_tail(abs_prev); +} + +struct thread_bootstrap_arg { + struct thread_info *ti; + int (*f)(void *a); + void *arg; +}; + +static void *thread_bootstrap(void *_tba) +{ + struct thread_bootstrap_arg *tba = (struct thread_bootstrap_arg *)_tba; + struct thread_info *ti = tba->ti; + int (*f)(void *) = tba->f; + void *arg = tba->arg; + + lkl_ops->sem_down(ti->task->thread.arch.sched_sem); + kfree(tba); + if (ti->task->thread.prev_sched) + schedule_tail(ti->task->thread.prev_sched); + + f(arg); + do_exit(0); + + return NULL; +} + +void new_thread(void *stack, jmp_buf *buf, void (*handler)(void)) +{ + struct thread_info *ti = (struct thread_info *)stack; + struct task_struct *p = ti->task; + struct thread_bootstrap_arg *tba; + int ret; + + unsigned long esp = (unsigned long)p->thread.request.u.thread.proc; + unsigned long unused = (unsigned long)p->thread.request.u.thread.arg; + + ret = init_arch_thread(&p->thread.arch); + if (ret < 0) + panic("%s: init_arch_thread", __func__); + + if ((int (*)(void *))esp == host_task_stub) { + set_ti_thread_flag(ti, TIF_HOST_THREAD); + return; + } + + tba = kmalloc(sizeof(*tba), GFP_KERNEL); + if (!tba) + return; + + tba->f = (int (*)(void *))esp; + tba->arg = (void *)unused; + tba->ti = ti; + + p->thread.arch.tid = lkl_ops->thread_create(thread_bootstrap, tba); + if (!p->thread.arch.tid) { + kfree(tba); + return; + } +} + +void show_stack(struct task_struct *task, unsigned long *esp) +{ +} + +static inline void pr_early(const char *str) +{ + if (lkl_ops->print) + lkl_ops->print(str, strlen(str)); +} + +/** + * This is called before the kernel initializes, so no kernel calls (including + * printk) can't be made yet. + */ +void threads_init(void) +{ + int ret; + struct thread_info *ti = &init_thread_union.thread_info; + + ti->task->thread = (struct thread_struct) INIT_THREAD; + ret = init_arch_thread(&ti->task->thread.arch); + if (ret < 0) + pr_early("lkl: failed to allocate init schedule semaphore\n"); + + ti->task->thread.arch.tid = lkl_ops->thread_self(); +} + +void threads_cleanup(void) +{ + struct task_struct *p, *t; + + for_each_process_thread(p, t) { + struct thread_info *ti = task_thread_info(t); + + if (t->pid != 1 && !test_ti_thread_flag(ti, TIF_HOST_THREAD)) + WARN(!(t->flags & PF_KTHREAD), + "non kernel thread task %s\n", t->comm); + WARN(t->state == TASK_RUNNING, + "thread %s still running while halting\n", t->comm); + + kill_thread(ti); + } + + lkl_ops->sem_free( + init_thread_union.thread_info.task->thread.arch.sched_sem); +} + +void initial_thread_cb_skas(void (*proc)(void *), void *arg) +{ + pr_warn("unimplemented %s", __func__); +} + +int arch_set_tls(struct task_struct *new, unsigned long tls) +{ + panic("unimplemented %s", __func__); +} +void clear_flushed_tls(struct task_struct *task) +{ + panic("unimplemented %s", __func__); +} From patchwork Thu Sep 24 07:12:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370376 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=xFKV67e7; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=IKxLofcp; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmXp4pQBz9sSt for ; Thu, 24 Sep 2020 17:15:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=75MD9s74ESPIasqqTVNJG2h6VqEaS35AzNrrsvD5+Dw=; b=xFKV67e7nroieFXD49b7VQviW HxKdC5jyStGie5KkEBr48g4UQlwPBpzFh4XwVtmPfCUtWMdYj9ERILxcUKnXyI/Isi+fuI0jvbPxQ 8XCjO1mYWSHgv6Wy433pugvANi7zN4Tc3S5UQQp2z0DDN/ShVFsVG0/hLTezLmPpi1EZ7T1TA2SyY 9utZzij1kUFxpj3tjgn1NsZg6Ph0JInsDfKXlQ2Ute3vH9DQKb8fePdoFklH3OXIJyeeeqMiedHf+ 88NLsubMzSLEPFo/celvSdLgk48+95VxZ3LcW4tLisM8MQUfshucQdbDuu1uXIIIJW0xceI3tvnHd jZIeQJCKw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLTb-0003Zq-GA; Thu, 24 Sep 2020 07:15:35 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLTU-0003XW-9U for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:15:33 +0000 Received: by mail-pg1-x544.google.com with SMTP id y14so1330204pgf.12 for ; Thu, 24 Sep 2020 00:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wT5jpOPDB0NInqu4SBIEU+dMeRQLws/J0n6IzbaAb/A=; b=IKxLofcpHHyXaagV7ELl9bEP9e9+Qy3+M+h0z9vYNtEl5y/vmbK7TZAPgrfUmJUe3T QN0QBtQhTMtsWTsbcPfJnhBFEuVOPW59G7HHAS4eMSmo6JiIJQTtrh5Ccy4SqWV4oSWW 3EQ6jGSNtu2HlHbVDAfi3NrUwIcT/uC14URz62rIs17UnqfbG+t3Oqo//wp6aByuuXu4 L/xJKG/DsMG27XDxThUOcptFBj03sb48MYEBINfXiiVy2WDe79z/oS9ioMtcY2aQHoJY 9sKidnIGJepZl8KH6fjsloNji16LCwg+djPkcPdzgkznx/MRwqA7JMMDyTvgRAh9WTck 1Xjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wT5jpOPDB0NInqu4SBIEU+dMeRQLws/J0n6IzbaAb/A=; b=WtEdAy1OKqgYBdtxDgv/XGDs9849eMYNmToW4faW2bwjUcJj8h1k94ZX5d5PsU8T/P VkJN6T86q91POemmmHkIU7Qysw+0ENzHHe8fNzLUOaUK5AYqbjV4LpAG6zgxd7Cwczet dk3KidvB3uRXACx8aFOapVxPjPvnm//efIqMz7ieDWMxy/6wc5KqBXxPlk41QjmT0pwv ow6UUreqfUW9lqwjeHfavXm0/vrOyPZlpDPzkZ7l9blu8nHaQ1PmOWfZ6/eQB8ycecCg DxjuQQm9ESuDhCukcBxLSQ+b3McfOqDMnvYC9U+NHGJvr+hcpWhxdQ0lH6GVEi5HH/Cw YRxQ== X-Gm-Message-State: AOAM532Xk0Hid8uKzbVrq9E3f/FH7aF1qPMyPDC3dpW7yag4XDpRfpq6 vnT0pEVjmq/xhMVGLuj58Xc= X-Google-Smtp-Source: ABdhPJzi5G88TnTAz55cCJPbmpHdLXhZ14WCzXTbr5iuL9On3tcLNGW1oHH7HG3tyn5BJndsuS+w+Q== X-Received: by 2002:a63:2dc2:: with SMTP id t185mr2858514pgt.28.1600931726222; Thu, 24 Sep 2020 00:15:26 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id gt11sm1313285pjb.48.2020.09.24.00.15.25 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:15:25 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 8DDEB2037C20A8; Thu, 24 Sep 2020 16:15:22 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 12/21] um: nommu: system call interface and application API Date: Thu, 24 Sep 2020 16:12:52 +0900 Message-Id: <76505ddefc45c782659fcf02797d4bb86b489b55.1600922529.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031528_720632_5E74A1C0 X-CRM114-Status: GOOD ( 25.04 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:544 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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. Signed-off-by: Hajime Tazaki Signed-off-by: Octavian Purdila --- 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 diff --git a/arch/um/include/uapi/asm/Kbuild b/arch/um/include/uapi/asm/Kbuild new file mode 100644 index 000000000000..a983c7f049bc --- /dev/null +++ b/arch/um/include/uapi/asm/Kbuild @@ -0,0 +1,2 @@ +# no generated-y since we need special user headers handling +# see arch/um/script/headers_install.py diff --git a/arch/um/nommu/include/asm/syscall_wrapper.h b/arch/um/nommu/include/asm/syscall_wrapper.h new file mode 100644 index 000000000000..bb2a7d4274f6 --- /dev/null +++ b/arch/um/nommu/include/asm/syscall_wrapper.h @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __UM_SYSCALL_WRAPPER_H +#define __UM_SYSCALL_WRAPPER_H + +#define __SC_ASCII(t, a) #t "," #a + +#define __ASCII_MAP0(m, ...) +#define __ASCII_MAP1(m, t, a) m(t, a) +#define __ASCII_MAP2(m, t, a, ...) m(t, a) "," __ASCII_MAP1(m, __VA_ARGS__) +#define __ASCII_MAP3(m, t, a, ...) m(t, a) "," __ASCII_MAP2(m, __VA_ARGS__) +#define __ASCII_MAP4(m, t, a, ...) m(t, a) "," __ASCII_MAP3(m, __VA_ARGS__) +#define __ASCII_MAP5(m, t, a, ...) m(t, a) "," __ASCII_MAP4(m, __VA_ARGS__) +#define __ASCII_MAP6(m, t, a, ...) m(t, a) "," __ASCII_MAP5(m, __VA_ARGS__) +#define __ASCII_MAP(n, ...) __ASCII_MAP##n(__VA_ARGS__) + +#ifdef __MINGW32__ +#define SECTION_ATTRS "n0" +#else +#define SECTION_ATTRS "a" +#endif + +#define __SYSCALL_DEFINE_ARCH(x, name, ...) \ + asm(".section .syscall_defs,\"" SECTION_ATTRS "\"\n" \ + ".ascii \"#ifdef __NR" #name "\\n\"\n" \ + ".ascii \"SYSCALL_DEFINE" #x "(" #name "," \ + __ASCII_MAP(x, __SC_ASCII, __VA_ARGS__) ")\\n\"\n" \ + ".ascii \"#endif\\n\"\n" \ + ".section .text\n") + +#define SYSCALL_DEFINE0(sname) \ + SYSCALL_METADATA(_##sname, 0); \ + __SYSCALL_DEFINE_ARCH(0, _##sname); \ + asmlinkage long sys_##sname(void); \ + ALLOW_ERROR_INJECTION(sys_##sname, ERRNO); \ + asmlinkage long sys_##sname(void) + +#define __SYSCALL_DEFINEx(x, name, ...) \ + __SYSCALL_DEFINE_ARCH(x, name, __VA_ARGS__); \ + __diag_push(); \ + __diag_ignore(GCC, 8, "-Wattribute-alias", \ + "Type aliasing is used to sanitize syscall arguments");\ + asmlinkage long sys##name(__MAP(x, __SC_DECL, __VA_ARGS__)) \ + __attribute__((alias(__stringify(__se_sys##name)))); \ + ALLOW_ERROR_INJECTION(sys##name, ERRNO); \ + static inline long __do_sys##name(__MAP(x, __SC_DECL, __VA_ARGS__)); \ + asmlinkage long __se_sys##name(__MAP(x, __SC_LONG, __VA_ARGS__)); \ + asmlinkage long __se_sys##name(__MAP(x, __SC_LONG, __VA_ARGS__)) \ + { \ + long ret = __do_sys##name(__MAP(x, __SC_CAST, __VA_ARGS__)); \ + __MAP(x, __SC_TEST, __VA_ARGS__); \ + __PROTECT(x, ret, __MAP(x, __SC_ARGS, __VA_ARGS__)); \ + return ret; \ + } \ + __diag_pop(); \ + static inline long __do_sys##name(__MAP(x, __SC_DECL, __VA_ARGS__)) + +#endif /* __UM_SYSCALL_WRAPPER_H */ diff --git a/arch/um/nommu/include/asm/syscalls.h b/arch/um/nommu/include/asm/syscalls.h new file mode 100644 index 000000000000..6061d9415dad --- /dev/null +++ b/arch/um/nommu/include/asm/syscalls.h @@ -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); diff --git a/arch/um/nommu/include/uapi/asm/host_ops.h b/arch/um/nommu/include/uapi/asm/host_ops.h index 720385fccbdf..6ee9489fc47e 100644 --- a/arch/um/nommu/include/uapi/asm/host_ops.h +++ b/arch/um/nommu/include/uapi/asm/host_ops.h @@ -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); diff --git a/arch/um/nommu/include/uapi/asm/syscalls.h b/arch/um/nommu/include/uapi/asm/syscalls.h new file mode 100644 index 000000000000..751957b978cd --- /dev/null +++ b/arch/um/nommu/include/uapi/asm/syscalls.h @@ -0,0 +1,287 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef __UM_NOMMU_UAPI_SYSCALLS_H +#define __UM_NOMMU_UAPI_SYSCALLS_H + +#include +#include + +typedef __kernel_uid32_t qid_t; +typedef __kernel_fd_set fd_set; +typedef __kernel_mode_t mode_t; +typedef unsigned short umode_t; +typedef __u32 nlink_t; +typedef __kernel_off_t off_t; +typedef __kernel_pid_t pid_t; +typedef __kernel_key_t key_t; +typedef __kernel_suseconds_t suseconds_t; +typedef __kernel_timer_t timer_t; +typedef __kernel_clockid_t clockid_t; +typedef __kernel_mqd_t mqd_t; +typedef __kernel_uid32_t uid_t; +typedef __kernel_gid32_t gid_t; +typedef __kernel_uid16_t uid16_t; +typedef __kernel_gid16_t gid16_t; +typedef unsigned long uintptr_t; +#ifdef CONFIG_UID16 +typedef __kernel_old_uid_t old_uid_t; +typedef __kernel_old_gid_t old_gid_t; +#endif +typedef __kernel_loff_t loff_t; +typedef __kernel_size_t size_t; +typedef __kernel_ssize_t ssize_t; +typedef __kernel_time_t time_t; +typedef __kernel_clock_t clock_t; +typedef __u32 u32; +typedef __s32 s32; +typedef __u64 u64; +typedef __s64 s64; + +typedef __kernel_long_t __kernel_old_time_t; + +#define __user + +#include +/* Temporary undefine system calls that don't have data types defined in UAPI + * headers + */ +#undef __NR_kexec_load +#undef __NR_getcpu +#undef __NR_sched_getattr +#undef __NR_sched_setattr +#undef __NR_sched_setparam +#undef __NR_sched_getparam +#undef __NR_sched_setscheduler +#undef __NR_name_to_handle_at +#undef __NR_open_by_handle_at + +/* deprecated system calls */ +#undef __NR_access +#undef __NR_chmod +#undef __NR_chown +#undef __NR_lchown +#undef __NR_open +#undef __NR_creat +#undef __NR_readlink +#undef __NR_pipe +#undef __NR_mknod +#undef __NR_mkdir +#undef __NR_rmdir +#undef __NR_unlink +#undef __NR_symlink +#undef __NR_link +#undef __NR_rename +#undef __NR_getdents +#undef __NR_select +#undef __NR_poll +#undef __NR_dup2 +#undef __NR_sysfs +#undef __NR_ustat +#undef __NR_inotify_init +#undef __NR_epoll_create +#undef __NR_epoll_wait +#undef __NR_signalfd +#undef __NR_eventfd + +#undef __NR_umount +#define __NR_umount __NR_umount2 + +#ifdef CONFIG_64BIT +#define __NR_newfstat __NR3264_fstat +#define __NR_newfstatat __NR3264_fstatat +#endif + +#include +#include +#include +#include +#define __KERNEL__ /* to pull in S_ definitions */ +#include +#undef __KERNEL__ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Define data structures used in system calls that are not defined in UAPI + * headers + */ +struct sockaddr { + unsigned short int sa_family; + char sa_data[14]; +}; + +#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1 +#define __UAPI_DEF_IF_IFNAMSIZ 1 +#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1 +#define __UAPI_DEF_IF_IFREQ 1 +#define __UAPI_DEF_IF_IFMAP 1 +#include +#define __UAPI_DEF_IN_IPPROTO 1 +#define __UAPI_DEF_IN_ADDR 1 +#define __UAPI_DEF_IN6_ADDR 1 +#define __UAPI_DEF_IP_MREQ 1 +#define __UAPI_DEF_IN_PKTINFO 1 +#define __UAPI_DEF_SOCKADDR_IN 1 +#define __UAPI_DEF_IN_CLASS 1 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +struct user_msghdr { + void __user *msg_name; + int msg_namelen; + struct iovec __user *msg_iov; + __kernel_size_t msg_iovlen; + void __user *msg_control; + __kernel_size_t msg_controllen; + unsigned int msg_flags; +}; + +typedef __u32 key_serial_t; + +struct mmsghdr { + struct user_msghdr msg_hdr; + unsigned int msg_len; +}; + +struct linux_dirent64 { + u64 d_ino; + s64 d_off; + unsigned short d_reclen; + unsigned char d_type; + char d_name[0]; +}; + +struct linux_dirent { + unsigned long d_ino; + unsigned long d_off; + unsigned short d_reclen; + char d_name[1]; +}; + +struct ustat { + __kernel_daddr_t f_tfree; + __kernel_ino_t f_tinode; + char f_fname[6]; + char f_fpack[6]; +}; + +struct __aio_sigset; +struct clone_args; + +typedef __kernel_rwf_t rwf_t; + +long lkl_syscall(long no, long *params); +long lkl_sys_halt(void); + +#define __MAP0(m, ...) +#define __MAP1(m, t, a) m(t, a) +#define __MAP2(m, t, a, ...) m(t, a), __MAP1(m, __VA_ARGS__) +#define __MAP3(m, t, a, ...) m(t, a), __MAP2(m, __VA_ARGS__) +#define __MAP4(m, t, a, ...) m(t, a), __MAP3(m, __VA_ARGS__) +#define __MAP5(m, t, a, ...) m(t, a), __MAP4(m, __VA_ARGS__) +#define __MAP6(m, t, a, ...) m(t, a), __MAP5(m, __VA_ARGS__) +#define __MAP(n, ...) __MAP##n(__VA_ARGS__) + +#define __SC_LONG(t, a) (long)(a) +#define __SC_TABLE(t, a) {sizeof(t), (long long)(a)} +#define __SC_DECL(t, a) t a + +#define LKL_SYSCALL0(name) \ + static inline long lkl_sys##name(void) \ + { \ + long params[6]; \ + return lkl_syscall(__lkl__NR##name, params); \ + } + +#if __BITS_PER_LONG == 32 +#define LKL_SYSCALLx(x, name, ...) \ + static inline \ + long lkl_sys##name(__MAP(x, __SC_DECL, __VA_ARGS__)) \ + { \ + struct { \ + unsigned int size; \ + long long value; \ + } lkl_params[x] = { __MAP(x, __SC_TABLE, __VA_ARGS__) }; \ + long sys_params[6], i, k; \ + for (i = k = 0; i < x && k < 6; i++, k++) { \ + if (lkl_params[i].size > sizeof(long) && \ + k + 1 < 6) { \ + sys_params[k] = \ + (long)(lkl_params[i].value & (-1UL)); \ + k++; \ + sys_params[k] = \ + (long)(lkl_params[i].value >> \ + __BITS_PER_LONG); \ + } else { \ + sys_params[k] = (long)(lkl_params[i].value); \ + } \ + } \ + return lkl_syscall(__lkl__NR##name, sys_params); \ + } +#else +#define LKL_SYSCALLx(x, name, ...) \ + static inline \ + long lkl_sys##name(__MAP(x, __SC_DECL, __VA_ARGS__)) \ + { \ + long lkl_params[6] = { __MAP(x, __SC_LONG, __VA_ARGS__) }; \ + return lkl_syscall(__lkl__NR##name, lkl_params); \ + } +#endif + +#define SYSCALL_DEFINE0(name, ...) LKL_SYSCALL0(name) +#define SYSCALL_DEFINE1(name, ...) LKL_SYSCALLx(1, name, __VA_ARGS__) +#define SYSCALL_DEFINE2(name, ...) LKL_SYSCALLx(2, name, __VA_ARGS__) +#define SYSCALL_DEFINE3(name, ...) LKL_SYSCALLx(3, name, __VA_ARGS__) +#define SYSCALL_DEFINE4(name, ...) LKL_SYSCALLx(4, name, __VA_ARGS__) +#define SYSCALL_DEFINE5(name, ...) LKL_SYSCALLx(5, name, __VA_ARGS__) +#define SYSCALL_DEFINE6(name, ...) LKL_SYSCALLx(6, name, __VA_ARGS__) + +#if __BITS_PER_LONG == 32 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpointer-to-int-cast" +#endif + +#include + +#if __BITS_PER_LONG == 32 +#pragma GCC diagnostic pop +#endif + +#endif diff --git a/arch/um/nommu/include/uapi/asm/unistd.h b/arch/um/nommu/include/uapi/asm/unistd.h new file mode 100644 index 000000000000..1762ebb829f5 --- /dev/null +++ b/arch/um/nommu/include/uapi/asm/unistd.h @@ -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 + +#if __BITS_PER_LONG == 64 +#define __ARCH_WANT_SYS_NEWFSTATAT +#endif + +#include + + +#endif diff --git a/arch/um/nommu/um/syscalls.c b/arch/um/nommu/um/syscalls.c new file mode 100644 index 000000000000..fd343f855bad --- /dev/null +++ b/arch/um/nommu/um/syscalls.c @@ -0,0 +1,199 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER +#undef CONFIG_ARCH_HAS_SYSCALL_WRAPPER +#include +#define CONFIG_ARCH_HAS_SYSCALL_WRAPPER +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +typedef long (*syscall_handler_t)(long arg1, ...); + +#undef __SYSCALL +#define __SYSCALL(nr, sym)[nr] = (syscall_handler_t)sym, + +syscall_handler_t syscall_table[__NR_syscalls] = { + [0 ... __NR_syscalls - 1] = (syscall_handler_t)sys_ni_syscall, +#undef __UM_NOMMU_UAPI_UNISTD_H +#include + +#if __BITS_PER_LONG == 32 +#include +#endif +}; + + +static long run_syscall(long no, long *params) +{ + long ret; + + if (no < 0 || no >= __NR_syscalls) + return -ENOSYS; + + ret = syscall_table[no](params[0], params[1], params[2], params[3], + params[4], params[5]); + + task_work_run(); + + return ret; +} + + +#define CLONE_FLAGS (CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_THREAD | \ + CLONE_SIGHAND | SIGCHLD) + +static int host_task_id; +static struct task_struct *host0; + +static int new_host_task(struct task_struct **task) +{ + pid_t pid; + + switch_to_host_task(host0); + + pid = kernel_thread(host_task_stub, NULL, CLONE_FLAGS); + if (pid < 0) + return pid; + + rcu_read_lock(); + *task = find_task_by_pid_ns(pid, &init_pid_ns); + rcu_read_unlock(); + + host_task_id++; + + snprintf((*task)->comm, sizeof((*task)->comm), "host%d", host_task_id); + + return 0; +} +static void exit_task(void) +{ + do_exit(0); +} + +static void del_host_task(void *arg) +{ + struct task_struct *task = (struct task_struct *)arg; + struct thread_info *ti = task_thread_info(task); + + if (lkl_cpu_get() < 0) + return; + + switch_to_host_task(task); + host_task_id--; + set_ti_thread_flag(ti, TIF_SCHED_JB); + lkl_ops->jmp_buf_set(&ti->task->thread.arch.sched_jb, exit_task); +} + +static struct lkl_tls_key *task_key; + +long lkl_syscall(long no, long *params) +{ + struct task_struct *task = host0; + long ret; + + ret = lkl_cpu_get(); + if (ret < 0) + return ret; + + if (lkl_ops->tls_get) { + task = lkl_ops->tls_get(task_key); + if (!task) { + ret = new_host_task(&task); + if (ret) + goto out; + lkl_ops->tls_set(task_key, task); + } + } + + switch_to_host_task(task); + + ret = run_syscall(no, params); + + if (no == __NR_reboot) { + thread_sched_jb(); + return ret; + } + +out: + lkl_cpu_put(); + + return ret; +} + +static struct task_struct *idle_host_task; + +/* called from idle, don't failed, don't block */ +void wakeup_idle_host_task(void) +{ + if (!need_resched() && idle_host_task) + wake_up_process(idle_host_task); +} + +static int idle_host_task_loop(void *unused) +{ + struct thread_info *ti = task_thread_info(current); + + snprintf(current->comm, sizeof(current->comm), "idle_host_task"); + set_thread_flag(TIF_HOST_THREAD); + idle_host_task = current; + + for (;;) { + lkl_cpu_put(); + lkl_ops->sem_down(ti->task->thread.arch.sched_sem); + if (idle_host_task == NULL) { + lkl_ops->thread_exit(); + return 0; + } + schedule_tail(ti->task->thread.prev_sched); + } +} + +int syscalls_init(void) +{ + snprintf(current->comm, sizeof(current->comm), "host0"); + set_thread_flag(TIF_HOST_THREAD); + host0 = current; + + if (lkl_ops->tls_alloc) { + task_key = lkl_ops->tls_alloc(del_host_task); + if (!task_key) + return -1; + } + + if (kernel_thread(idle_host_task_loop, NULL, CLONE_FLAGS) < 0) { + if (lkl_ops->tls_free) + lkl_ops->tls_free(task_key); + return -1; + } + + return 0; +} + +void syscalls_cleanup(void) +{ + if (idle_host_task) { + struct thread_info *ti = task_thread_info(idle_host_task); + + idle_host_task = NULL; + lkl_ops->sem_up(ti->task->thread.arch.sched_sem); + lkl_ops->thread_join(ti->task->thread.arch.tid); + } + + if (lkl_ops->tls_free) + lkl_ops->tls_free(task_key); +} diff --git a/arch/um/scripts/headers_install.py b/arch/um/scripts/headers_install.py new file mode 100755 index 000000000000..ec7356c0dee9 --- /dev/null +++ b/arch/um/scripts/headers_install.py @@ -0,0 +1,197 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: GPL-2.0 +import re, os, sys, argparse, multiprocessing, fnmatch + +srctree = os.environ["srctree"] +objtree = os.environ["objtree"] +install_hdr_path = os.environ["INSTALL_HDR_PATH"] +header_paths = [ install_hdr_path + "/include/", "arch/um/nommu/include/uapi/", + "arch/um/nommu/include/generated/uapi/", "include/generated/" ] + +headers = set() +includes = set() + +def relpath2abspath(relpath): + if "generated" in relpath or install_hdr_path in relpath: + return objtree + "/" + relpath + else: + return srctree + "/" + relpath + +def find_headers(path): + headers.add(path) + f = open(relpath2abspath(path)) + for l in f.readlines(): + m = re.search("#\s*include <(.*)>", l) + try: + i = m.group(1) + for p in header_paths: + if os.access(relpath2abspath(p + i), os.R_OK): + if p + i not in headers: + includes.add(i) + headers.add(p + i) + find_headers(p + i) + except: + pass + f.close() + +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") + +def find_symbols(regexp, store): + for h in headers: + f = open(h) + for l in f.readlines(): + m = regexp.search(l) + if not m: + continue + for e in reversed(m.groups()): + if e: + if not has_lkl_prefix(e): + store.add(e) + break + f.close() + +def find_ml_symbols(regexp, store): + for h in headers: + for i in regexp.finditer(open(h).read()): + for j in reversed(i.groups()): + if j: + if not has_lkl_prefix(j): + store.add(j) + break + +def find_enums(block_regexp, symbol_regexp, store): + for h in headers: + # remove comments + content = re.sub(re.compile("(\/\*(\*(?!\/)|[^*])*\*\/)", re.S|re.M), " ", open(h).read()) + # remove preprocesor lines + clean_content = "" + for l in content.split("\n"): + if re.match("\s*#", l): + continue + clean_content += l + "\n" + for i in block_regexp.finditer(clean_content): + for j in reversed(i.groups()): + if j: + for k in symbol_regexp.finditer(j): + for l in k.groups(): + if l: + if not has_lkl_prefix(l): + store.add(l) + break + +def lkl_prefix(w): + r = "" + + if w.startswith("__"): + r = "__" + elif w.startswith("_"): + r = "_" + + if w.isupper(): + r += "LKL" + else: + r += "lkl" + + if not w.startswith("_"): + r += "_" + + r += w + + return r + +def replace(h): + content = open(h).read() + for i in includes: + search_str = "(#[ \t]*include[ \t]*[<\"][ \t]*)" + i + "([ \t]*[>\"])" + replace_str = "\\1" + "lkl/" + i + "\\2" + content = re.sub(search_str, replace_str, content) + tmp = "" + for w in re.split("(\W+)", content): + if w in defines: + w = lkl_prefix(w) + tmp += w + content = tmp + for s in structs: + search_str = "(\W?struct\s+)" + s + "(\W)" + replace_str = "\\1" + lkl_prefix(s) + "\\2" + content = re.sub(search_str, replace_str, content, flags = re.MULTILINE) + for s in unions: + search_str = "(\W?union\s+)" + s + "(\W)" + replace_str = "\\1" + lkl_prefix(s) + "\\2" + content = re.sub(search_str, replace_str, content, flags = re.MULTILINE) + open(h, 'w').write(content) + +parser = argparse.ArgumentParser(description='install lkl headers') +parser.add_argument('path', help='path to install to', ) +parser.add_argument('-j', '--jobs', help='number of parallel jobs', default=1, type=int) +args = parser.parse_args() + +find_headers("arch/um/nommu/include/uapi/asm/syscalls.h") +headers.add("arch/um/nommu/include/uapi/asm/host_ops.h") + +if 'LKL_INSTALL_ADDITIONAL_HEADERS' in os.environ: + with open(os.environ['LKL_INSTALL_ADDITIONAL_HEADERS'], 'rU') as f: + for line in f.readlines(): + line = line.split('#', 1)[0].strip() + if line != '': + headers.add(line) + +new_headers = set() + +for h in headers: + h = relpath2abspath(h) + 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) + try: + os.makedirs(out_dir) + except: + pass + print(" INSTALL\t%s" % (out_dir + "/" + os.path.basename(h))) + os.system(srctree+"/scripts/headers_install.sh %s %s" % (os.path.abspath(h), + out_dir + "/" + os.path.basename(h))) + new_headers.add(out_dir + "/" + os.path.basename(h)) + +headers = new_headers + +defines = set() +structs = set() +unions = set() + +p = re.compile("#[ \t]*define[ \t]*(\w+)") +find_symbols(p, defines) +p = re.compile("typedef.*(\(\*(\w+)\)\(.*\)\s*|\W+(\w+)\s*|\s+(\w+)\(.*\)\s*);") +find_symbols(p, defines) +p = re.compile("typedef\s+(struct|union)\s+\w*\s*{[^\\{\}]*}\W*(\w+)\s*;", re.M|re.S) +find_ml_symbols(p, defines) +defines.add("siginfo_t") +defines.add("sigevent_t") +p = re.compile("struct\s+(\w+)\s*\{") +find_symbols(p, structs) +structs.add("iovec") +p = re.compile("union\s+(\w+)\s*\{") +find_symbols(p, unions) +p = re.compile("static\s+__inline__(\s+\w+)+\s+(\w+)\([^)]*\)\s") +find_symbols(p, defines) +p = re.compile("static\s+__always_inline(\s+\w+)+\s+(\w+)\([^)]*\)\s") +find_symbols(p, defines) +p = re.compile("enum\s+(\w*)\s*{([^}]*)}", re.M|re.S) +q = re.compile("(\w+)\s*(,|=[^,]*|$)", re.M|re.S) +find_enums(p, q, defines) + +# needed for i386 +defines.add("__NR_stime") + +def process_header(h): + print(" REPLACE\t%s" % (out_dir + "/" + os.path.basename(h))) + replace(h) + +p = multiprocessing.Pool(args.jobs) +try: + p.map_async(process_header, headers).wait(999999) + p.close() +except: + p.terminate() +finally: + p.join() From patchwork Thu Sep 24 07:12:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370377 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=IVAIpCo4; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Zmy1SS6k; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmXt564Wz9sTN for ; Thu, 24 Sep 2020 17:15:42 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=fAZ/cSiOUCISz6QtsSLAFQTlDLruQjvmpiwIJhQIycQ=; b=IVAIpCo4SEEpIlTj3ntlsddGM 7D2x3DKZfJZjFyFzem09mTQ1jnSdKI48qaEo2SXlJNI0j9cz9BfBlmKtvQsfPr3kPM42QMyWSUboy VRqkyCQ25zy/1oQJNmnPPpsD1Mn33YoQA6IvClWSb4TuBf3iYgphRjERRbp8o5Kf+mS+tWPyDCsdG qLwJAbBFR807JFZWAfJg6teHaYXK8jE+hdw42uAMv9o8Cs0CF5YYVg3C/ohlr1ONg22+o0Y2vtKqv //QU3fN93KvYP7I5mc2dhhoYm/OMQYcz7KfVr89eQ2fxIT7b1t1+Y4paPxc6lm7cMsw9vK9QHJvDi qlg7u90uA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLTf-0003ah-7Z; Thu, 24 Sep 2020 07:15:39 +0000 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLTZ-0003ZB-Nb for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:15:37 +0000 Received: by mail-pj1-x1042.google.com with SMTP id mn7so1120135pjb.5 for ; Thu, 24 Sep 2020 00:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dw71STGvxu+fI7O/Zk3vtwTxDzn/GLjAFDhUcWGe5Xc=; b=Zmy1SS6kl0jxxONEvBC4wfmfIJ1KuHy2r4cVTdhd5TSpg0pk/4s08WSU0NLFyQNpQt y2lIxp9PemHVppTSCraE3H6U1KBIvC01tzr3p6gvSFfFt2tC0veYPgb31cou+32kYAfY 3BFeWKUb4qhfeVPliICJFB5BrNVWCSKeiXIeG7RJnUYwfGJr3kvEajYCNuYuf/hbpTqm A9SZEuxnNoZUUHeZB18ecNm3ESGb8KUSy7f4N0/t17jMzJcxf+DQpsgdU+LKuq5R7EHx JTmHt+kPxqUF0WqrzwkrcNr3GvZOgHg7bGmLSMr3aQPlL7B6mBPg3xgrbdOFOXdxfPPJ KC6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dw71STGvxu+fI7O/Zk3vtwTxDzn/GLjAFDhUcWGe5Xc=; b=PXQ/XNKZPPNFjVdTV1z3j+jEAK1u7BER4TaiFIOUPiIRfOuJNH30UAaL5mzXn/yH+6 l11arj3jKlIyQsb3i/zub8DZnmHCuSBK9oa8BQYvNQfF/JkRtH7vQmmg83E6gkxvJmvC Gc6GCYJTozHFCjYJ8aX6S7EZkhGwTiAQiE3zMNtOClcemDoBH9eUiwJ1Dc7vT0Fkm9Rn Cjm7/z9HV8oyk2Tf8GP6EzMq9D1v2u/+j7dkRcmtAkN/DLRMyBIfwfygRRutGFcWri/R 7E3os7NxLp74lC6sE0iqKntXClF2PwxHVFfXlpe6nWiPXRuUPojA29S3qAdSLURMk821 Kb9g== X-Gm-Message-State: AOAM533xn/YZIQd/fgymglEX2Iuevoogy2DM59ssYrBn0DWkFGB0QCo0 1xjCdyYOhc/UbmzNiYzmvnw= X-Google-Smtp-Source: ABdhPJyyI9b4RjXtue10Pcn9wOYh23pY5YnZqTM4dKsIAg9ZR7hWxwRFU9TNytr+vT5qmL/RfOGtog== X-Received: by 2002:a17:90a:e44b:: with SMTP id jp11mr2724334pjb.96.1600931731555; Thu, 24 Sep 2020 00:15:31 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id 124sm1722152pfd.132.2020.09.24.00.15.30 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:15:30 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 8B05D2037C20AD; Thu, 24 Sep 2020 16:15:28 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 13/21] um: nommu: basic console support Date: Thu, 24 Sep 2020 16:12:53 +0900 Message-Id: <379481a81c96e9a073df02dc49f976dc6e346cc4.1600922529.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031533_783171_503DA22F X-CRM114-Status: GOOD ( 17.25 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1042 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This commit also disables stdio-console of UM if !CONFIG_MMU to avoid conflicts between multiple consoles. Signed-off-by: Hajime Tazaki --- 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 diff --git a/arch/um/drivers/Makefile b/arch/um/drivers/Makefile index ae96c83e312d..694da4aa550d 100644 --- a/arch/um/drivers/Makefile +++ b/arch/um/drivers/Makefile @@ -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 diff --git a/arch/um/nommu/include/uapi/asm/host_ops.h b/arch/um/nommu/include/uapi/asm/host_ops.h index 6ee9489fc47e..133877c857a1 100644 --- a/arch/um/nommu/include/uapi/asm/host_ops.h +++ b/arch/um/nommu/include/uapi/asm/host_ops.h @@ -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); diff --git a/arch/um/nommu/um/console.c b/arch/um/nommu/um/console.c new file mode 100644 index 000000000000..e3194f7bb0dd --- /dev/null +++ b/arch/um/nommu/um/console.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include + +static void console_write(struct console *con, const char *str, unsigned len) +{ + if (lkl_ops->print) + lkl_ops->print(str, len); +} + +#ifdef CONFIG_LKL_EARLY_CONSOLE +static struct console lkl_boot_console = { + .name = "lkl_boot_console", + .write = console_write, + .flags = CON_PRINTBUFFER | CON_BOOT, + .index = -1, +}; + +int __init lkl_boot_console_init(void) +{ + register_console(&lkl_boot_console); + return 0; +} +early_initcall(lkl_boot_console_init); +#endif + +static struct console lkl_console = { + .name = "lkl_console", + .write = console_write, + .flags = CON_PRINTBUFFER, + .index = -1, +}; + +int __init lkl_console_init(void) +{ + register_console(&lkl_console); + return 0; +} +core_initcall(lkl_console_init); + From patchwork Thu Sep 24 07:12:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370378 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=XopINfu5; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=f38weITE; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmY159Hmz9sTH for ; Thu, 24 Sep 2020 17:15:49 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SdvmCbudIaKEldkOZhTAuL+PTlCIJJf4cSkstnypYBk=; b=XopINfu5KTB4mznijN1jUCkhw R/kZNWam9FhjSEcyPeQx2575MG16Ca786JIFjbaKcWcox5B7IvfsAq5jd6iA1IP/6nA7IzAv39XvY Hix8lTanq2GGX6bIElwBtjr2rQRhXJdFdmxnz4e8oNXwVQNx7CLIwcVOKXNbXCr4ljTlFK2+gfzsx aogaUNyvu9hrFu+F0SAK+2rfA8lX1i9dLTUU/SfMqt8TnS6odLk8TAyI3jkRurgNWpnGk/a9y7T06 /xGN7zlFrCrVQqYdAuA4mmb/vteNsOKdM/J0afJXtONRW9RaSiLM/lGxWF2yvJhWxq8zPlccXtbAb I+J6Hf3pw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLTm-0003dT-0D; Thu, 24 Sep 2020 07:15:46 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLTi-0003c0-RC for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:15:44 +0000 Received: by mail-pl1-x643.google.com with SMTP id y6so1182880plt.9 for ; Thu, 24 Sep 2020 00:15:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jYKWSZpS/C8VsskkJfHhWWpBDQWCJdoW8/7KByaLGe0=; b=f38weITEX6kqbHCteojypv/g238Ry4uszmYgf5LI0oPwoANsVqQ9D4IAAgFd3GZoQa X3l5yBNP/Xwt6IqzIdReEmqMhKUYR6FaXxbLeehcztCHzxTjGuFv+BY8c9ANNL0eE19x JSN7TALRcnTkpEEYMrWA1cxJ6v/Dal3CrbvbyUaei4a4UoXovSS6CaFkTdcLEyrBoYOg p1nC7JNE7tKHqwqxj9cYrf+9z/AxWhV6yUMRzYtIFUJzlfUHyAhEByywxN8q2jlVpe2c N+WJwVYk8IGij1pbSARSY0Tr+6P5yCMPPv+v3DBrgtQbXCryroOitqMberZFW43aMTDD p+Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jYKWSZpS/C8VsskkJfHhWWpBDQWCJdoW8/7KByaLGe0=; b=t0MxqirbYNaIphizVwkWWtEmuuc57Xths5Bi5NPZXTKGYXwsaoTVUTknxoMBgIOH9/ /7NB2N37IrhI4KrKbD3rhkkkTr1xS58olejDVf61Ccad9zEYeaqfxZYLXYK2YOz+US4h H/uC0kpZx58nkqSqq9rra/UXL+YASuBDPM3pXs5n3dFcT0rmO7TgqtnQ9kfSi2VD+Lw3 Jq8/CjH5W1nNbme6OMF4O0q2WfiGqf2jueqXLJNOtWeB9t3OoZJDBqcE9j9uluIRegpO VcZrfOgi2QjyROE3vUYHzIDQ6TTcyc7bw/lmZptKVIo95eBo6bZ8LpI1owYkGKsw66tZ NsrA== X-Gm-Message-State: AOAM5335/bywnVPVKtZglUgZMlVnqdqDg3+zNZYGIC2qCF30rSl/O0ii ZCJPfjWI+g3LsQIKU2eCQVc= X-Google-Smtp-Source: ABdhPJxdkd66wudGGPo0TVb1Xyuk0MImYs87Nzu4aJK2YbOnApLjyX2mf6T7t9fOUWKOetsiFc0UjQ== X-Received: by 2002:a17:902:b117:b029:d1:e5e7:bdf5 with SMTP id q23-20020a170902b117b02900d1e5e7bdf5mr3116803plr.85.1600931740912; Thu, 24 Sep 2020 00:15:40 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id 75sm1879070pgg.22.2020.09.24.00.15.39 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:15:40 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 5C7D12037C20B1; Thu, 24 Sep 2020 16:15:34 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 14/21] um: nommu: initialization and cleanup Date: Thu, 24 Sep 2020 16:12:54 +0900 Message-Id: <12f3ba8d5a73a068c5bb116cadbb0a2e55334b06.1600922529.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031542_967219_4FCE5AAF X-CRM114-Status: GOOD ( 25.46 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:643 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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. Signed-off-by: Hajime Tazaki Signed-off-by: Octavian Purdila --- 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 diff --git a/arch/um/nommu/include/uapi/asm/host_ops.h b/arch/um/nommu/include/uapi/asm/host_ops.h index 133877c857a1..0811494c080c 100644 --- a/arch/um/nommu/include/uapi/asm/host_ops.h +++ b/arch/um/nommu/include/uapi/asm/host_ops.h @@ -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 diff --git a/arch/um/nommu/um/setup.c b/arch/um/nommu/um/setup.c new file mode 100644 index 000000000000..eaa74d771f73 --- /dev/null +++ b/arch/um/nommu/um/setup.c @@ -0,0 +1,162 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +static void *init_sem; +static int is_running; + + +struct lkl_host_operations *lkl_ops; + +long lkl_panic_blink(int state) +{ + lkl_ops->panic(); + return 0; +} + +static void __init *lkl_run_kernel(void *arg) +{ + + panic_blink = lkl_panic_blink; + + threads_init(); + lkl_cpu_get(); + start_kernel(); + + return NULL; +} + +int __init lkl_start_kernel(struct lkl_host_operations *ops, + const char *fmt, ...) +{ + int ret; + + lkl_ops = ops; + + init_sem = lkl_ops->sem_alloc(0); + if (!init_sem) + return -ENOMEM; + + ret = lkl_cpu_init(); + if (ret) + goto out_free_init_sem; + + ret = lkl_ops->thread_create(lkl_run_kernel, NULL); + if (!ret) { + ret = -ENOMEM; + goto out_free_init_sem; + } + + lkl_ops->sem_down(init_sem); + lkl_ops->sem_free(init_sem); + current_thread_info()->task->thread.arch.tid = lkl_ops->thread_self(); + lkl_cpu_change_owner(current_thread_info()->task->thread.arch.tid); + + lkl_cpu_put(); + is_running = 1; + + return 0; + +out_free_init_sem: + lkl_ops->sem_free(init_sem); + + return ret; +} + +int lkl_is_running(void) +{ + return is_running; +} + + +long lkl_sys_halt(void) +{ + long err; + long params[6] = {LINUX_REBOOT_MAGIC1, + LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART, }; + + err = lkl_syscall(__NR_reboot, params); + if (err < 0) + return err; + + is_running = false; + + lkl_cpu_wait_shutdown(); + + syscalls_cleanup(); + threads_cleanup(); + /* Shutdown the clockevents source. */ + tick_suspend_local(); + free_mem(); + lkl_ops->thread_join(current_thread_info()->task->thread.arch.tid); + + return 0; +} + + +static int lkl_run_init(struct linux_binprm *bprm); + +static struct linux_binfmt lkl_run_init_binfmt = { + .module = THIS_MODULE, + .load_binary = lkl_run_init, +}; + +static int lkl_run_init(struct linux_binprm *bprm) +{ + int ret; + + if (strcmp("/init", bprm->filename) != 0) + return -EINVAL; + + ret = begin_new_exec(bprm); + if (ret) + return ret; + set_personality(PER_LINUX); + setup_new_exec(bprm); + + set_binfmt(&lkl_run_init_binfmt); + + init_pid_ns.child_reaper = 0; + + syscalls_init(); + + lkl_ops->sem_up(init_sem); + lkl_ops->thread_exit(); + + return 0; +} + + +/* skip mounting the "real" rootfs. ramfs is good enough. */ +static int __init fs_setup(void) +{ + int fd, flags; + + if (force_o_largefile()) + flags |= O_LARGEFILE; + fd = do_sys_open(AT_FDCWD, "/init", O_CREAT | flags, 0700); + WARN_ON(fd < 0); + ksys_close(fd); + + register_binfmt(&lkl_run_init_binfmt); + + return 0; +} +late_initcall(fs_setup); diff --git a/tools/um/uml/process.c b/tools/um/uml/process.c index e52dd37ddadc..c39d914e80ac 100644 --- a/tools/um/uml/process.c +++ b/tools/um/uml/process.c @@ -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); From patchwork Thu Sep 24 07:12:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370379 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=cFbeEuzq; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=WE0nx41N; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmY30nyCz9sTQ for ; Thu, 24 Sep 2020 17:15:51 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=rGGK3gRIBSsq/0XWrtQ1bgOOZVuKTwvtFJqX2LSZyd8=; b=cFbeEuzq3SEAUbAficn0OlBJ2 PHA5FzHd9hfQN+dhKeCZJHXo1MW2iycnST3NE0p/FM07EekDO7NoLjSTa8ywZ3PEDh31PBMVDSYWF 3GavWrC5Wcde7zipy8pl/wbVCtQALwffsBgyaOe07nGBI0YGN7Wj1NLC+1FqKWcrSE1Tf1oOENvyO f8jyryDX6xIp8tj0B2LZiBqnYEhNh6zKZYzi8E1d07XMJyp+Ro+6PxbFcR7J4DmPV8oKSqXLcrzV1 yoSSbCnn9j1JD2E4unJf0U43Rx/PM2rgbkpdU5KX8Nj/ZyvnXB/z9Z1yZBaUDC2H2izQEj+wMMzHw KqlpWBoVw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLTn-0003eS-Tv; Thu, 24 Sep 2020 07:15:47 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLTl-0003dJ-Dm for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:15:46 +0000 Received: by mail-pf1-x444.google.com with SMTP id o20so1317855pfp.11 for ; Thu, 24 Sep 2020 00:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=imyNk/pfD/Crh/h3JilzWEWmXyUrqyB5bMwtrpzuDLg=; b=WE0nx41N26rnHl186xWg/PAGD2ArGQgS5Xc3YlKMmbP4nDDcuGJZ5UcAK5fXa9K9xm rIi9uaLtfGxHy0yqMapS2KVfs0CAnezmrtOEgJKz06hQ5nxUR67cPe7LISJL4xxTbASC w0YgOBTf6GCNQBAwrPcegcev7kogxSd5s/iPx5v7eZQdtE6pzLL49h3dbDcytYDtqFPm yx33ExwZ2/XgLeWKO8vFDnqliI/AnmU4He8PxHS9dQxRrCL53xW2NUxc1NcOIdHsEm+b Ic+CWlwhccfmHbvDSLdIm84oGNOLawD+YASVIaNRK1jhtbCz5DqjeguqCPz3uwUbHlZR omaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=imyNk/pfD/Crh/h3JilzWEWmXyUrqyB5bMwtrpzuDLg=; b=kWg9jtkhb2watAIHDJOPVBOxPkNsStcyfxiAv/fFXur4PvvB7pVrBNac6a3ZYkC22g 5I2m8arzK5rImtrimtxBbRweEWBOAYgYZc2vsANBzh34Ym4hRelxI2bIlFAnXLYLbGwB MFWi94Dvs+YXbeSGcz/LgN0VWFud6b4KDyJ7e23ZYIw5NNJ4icR3dLVbXV7UJRX7TLMo TRgtWljJMSaJtU4WmhJbFSpP4QxFLcluSrQ4VJ4TF34Ki4nBGpLr+BXpyGmAqJQ3ndFN qbOTs90zeG7Owhdla3wtecJAEDa9fFE7QkU/BewRQbVx9W/t39S9MUqDLkBf3YeBoYn+ xepA== X-Gm-Message-State: AOAM532s3NN040IZWEFnowzvwien3ijYI0lLNQL0jzLHC4W3fzdTXnox z8dZxETbme1Kw3bFNNiIiBo= X-Google-Smtp-Source: ABdhPJzFfcms7QZG3J3BosBrXJB8/VT20RwNmsl8TcTNp0i82LyTcqwG7Ll+GJZ2XO2dz4SVTE1wAw== X-Received: by 2002:aa7:9409:0:b029:142:2501:3989 with SMTP id x9-20020aa794090000b029014225013989mr3380219pfo.78.1600931743490; Thu, 24 Sep 2020 00:15:43 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id bx22sm1439120pjb.23.2020.09.24.00.15.42 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:15:42 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 398F22037C20D0; Thu, 24 Sep 2020 16:15:40 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 15/21] um: nommu: integrate with irq infrastructure of UML Date: Thu, 24 Sep 2020 16:12:55 +0900 Message-Id: <7ec39a8cb91902ff2cdb22f9143f3449f9f9d009.1600922529.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031545_516505_C067B619 X-CRM114-Status: GOOD ( 19.65 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:444 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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. Signed-off-by: Hajime Tazaki --- 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(-) diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index f467d28fc0b4..0da3ce22e16f 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -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); diff --git a/arch/um/kernel/irq.c b/arch/um/kernel/irq.c index 3577118bb4a5..4ce7f5fef7f8 100644 --- a/arch/um/kernel/irq.c +++ b/arch/um/kernel/irq.c @@ -19,6 +19,7 @@ #include #include #include +#include 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; } diff --git a/arch/um/kernel/time.c b/arch/um/kernel/time.c index 25eaa6a0c658..9e141fe8fe27 100644 --- a/arch/um/kernel/time.c +++ b/arch/um/kernel/time.c @@ -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); diff --git a/arch/um/nommu/include/asm/cpu.h b/arch/um/nommu/include/asm/cpu.h index c101c078ef21..c52a78c77bea 100644 --- a/arch/um/nommu/include/asm/cpu.h +++ b/arch/um/nommu/include/asm/cpu.h @@ -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 diff --git a/arch/um/nommu/um/cpu.c b/arch/um/nommu/um/cpu.c index 9986a3f8c5dd..75d8bdc1847e 100644 --- a/arch/um/nommu/um/cpu.c +++ b/arch/um/nommu/um/cpu.c @@ -8,15 +8,16 @@ #include #include #include +#include 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); diff --git a/arch/um/nommu/um/setup.c b/arch/um/nommu/um/setup.c index eaa74d771f73..922188690139 100644 --- a/arch/um/nommu/um/setup.c +++ b/arch/um/nommu/um/setup.c @@ -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; diff --git a/arch/um/nommu/um/threads.c b/arch/um/nommu/um/threads.c index 3e70eccc191a..df96057100fd 100644 --- a/arch/um/nommu/um/threads.c +++ b/arch/um/nommu/um/threads.c @@ -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) diff --git a/tools/um/uml/signal.c b/tools/um/uml/signal.c index b58bc68cbe64..2b5c98de21cd 100644 --- a/tools/um/uml/signal.c +++ b/tools/um/uml/signal.c @@ -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; +} From patchwork Thu Sep 24 07:12:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370380 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=LSamcmP/; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=pzaY2AuL; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmYH1k28z9sSC for ; Thu, 24 Sep 2020 17:16:03 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Fj8acObnGepdeQ+0UY080Gz/oxXdbFyanTasbZamAr0=; b=LSamcmP/x8VB05EmrZ9DwOxP8 /IF8To8yW5KTEf/AHc8IKp95qc7em9p0Ye+U1tjVERkiTJju124/GDhUxLz/a3fohzMogAbW7eBa2 X0QlfXtkuTYNMKI/pv8Eikx7vDlv+egTMDEflweBYbriwIhWmlIGKyvBt2sibw+8RbgxgvGHVe3Tq 9b4eCc4LOiqi0gqod+49EMPJYMBqrEGuUFHCnnuPbTFSHhzq7D4Rsu+mk3fQrvkNeTqV+hQRWu5IF i95J8gE2vC5Qkk5F26X+N8bFebkEreOmVGiMcBqWdjsSx9OaAVgF6ey9S68nl9Cveu1IAP4BPVpcW glm2R8SLw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLU0-0003iv-1P; Thu, 24 Sep 2020 07:16:00 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLTx-0003hK-9S for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:15:58 +0000 Received: by mail-pg1-x543.google.com with SMTP id 5so1354795pgf.5 for ; Thu, 24 Sep 2020 00:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nKyrI8T3WpefS58p4nYoXNvPuy8WkBwPKR8dWEqpiec=; b=pzaY2AuLkHBpmT2HSX6hCrBvpQKijE79tfz00pvsIymQHL7nid/ivk12crWkAkqLOf FgUZesbVCZSpYPYSNUvV0BkTnQ1cAsqrzFxaVWS4Xyvk6tzmAQvebTBCpFmXg/HwA7c5 GVf55DjGyCci83TtKYaDDImCeQ0ltUY68MZMpK+j4Htvy3i3ZlBjly7mgGURXH497r3k 6K2U2dg1fq13BRhUIBaYXnu94hEFUjnWUQPeXirVEyOa8Y8QIhXSlxVC6+kokqivexq3 eHUhvmWMX6RNsyb5XpOkf3r8q5I9zml+SJG5tcuz0zkIvlIgSLjsZyL55K/cJYH5jQFj UMBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nKyrI8T3WpefS58p4nYoXNvPuy8WkBwPKR8dWEqpiec=; b=jX0K81qnzgR5KoUulT0kzUnP6btpbwkEVtKSYv72qfBX2vuQPCGcD8wDZGZAlVS4bC vhqXX3Wuna5iNlxcFce9DfDLdekedTSAWyle+CA2dDH9hdOOtXfFqAw0HbaAYUO+Rnsj EIXLYKr+6+JBpBcMW15Haew0ZsjHVyLCVryH7EpKmuy6fBcoC5FmSw40b4B0CP1QkkGl 6HYNmOLiAxhOGH6VSNJ8Pmt+uMiPXJhYnSe+054VJR4n5rTDvuk2OvZYCo/W8FkSypq6 UDOOUOxECZ7EF+BrO7BI+xybomy6OUH4DZSKyWp6yOGBz2CwLwhu73VJg4SSl28zGQ0T vETQ== X-Gm-Message-State: AOAM532HvK8rkDhU0lM2Kj6xgrOp6AhXuLFU3McFHYAtQEN4MC+q4Q9n 08Hof6Y5Sk4lQOL5Geirwys= X-Google-Smtp-Source: ABdhPJxlY33RutyUgn6a2ahhIO736oQkAwLVlBiuZVcMtSfRX4/cVVjmnQM71v9A+iWF3JFGD0pOXg== X-Received: by 2002:a63:5363:: with SMTP id t35mr2816015pgl.443.1600931755411; Thu, 24 Sep 2020 00:15:55 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id gj6sm1371509pjb.10.2020.09.24.00.15.54 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:15:54 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 0A0A52037C20E7; Thu, 24 Sep 2020 16:15:52 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 16/21] um: nommu: plug in the build system Date: Thu, 24 Sep 2020 16:12:56 +0900 Message-Id: <8e8af2d046852b7ddedf36e36e522261ebd2350e.1600922529.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031557_403135_32318B30 X-CRM114-Status: GOOD ( 18.84 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:543 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 Signed-off-by: Octavian Purdila Signed-off-by: Hajime Tazaki --- 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 diff --git a/arch/um/Kconfig b/arch/um/Kconfig index e41d31d0d875..df7daceb095c 100644 --- a/arch/um/Kconfig +++ b/arch/um/Kconfig @@ -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 + . + 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 diff --git a/arch/um/Makefile b/arch/um/Makefile index 1f958a9280fe..73d3ac061b77 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -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/ diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile index 5aa882011e04..bdc4108bc52e 100644 --- a/arch/um/kernel/Makefile +++ b/arch/um/kernel/Makefile @@ -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 diff --git a/arch/um/nommu/um/Kconfig b/arch/um/nommu/um/Kconfig new file mode 100644 index 000000000000..20b3eaccb6f0 --- /dev/null +++ b/arch/um/nommu/um/Kconfig @@ -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 diff --git a/arch/um/nommu/um/Makefile b/arch/um/nommu/um/Makefile new file mode 100644 index 000000000000..b580e0fe97b5 --- /dev/null +++ b/arch/um/nommu/um/Makefile @@ -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 From patchwork Thu Sep 24 07:12:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370381 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=j+8B1au2; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=XSAI0NJY; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmYT39h6z9sSC for ; Thu, 24 Sep 2020 17:16:13 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vOUrgPKBkZVbOrXpdwKZwu2pF270lo3kAHX3Xxcf6YY=; b=j+8B1au27C7iUmQnICRk8s/pT Zf+k8tKoXnFLzxCiRPVWFgae60SHZnMhjc+TatXJqVE76gNamp4w7mL3OfjES6DqNRJm6ExubY48L B651bjmi6XGWbWvie7sZiM4j4E9iiHTfxkclTPbko7B2Wa6yaAXSGCoX2Dxgj1790r15SN+NkR9+v fJ/KxtS9wmguUSOXXIDXW5sXx10j2gBIo+owIB6qt/kKW28MiQsgxS5uu8GUtux8uxiRXMCRjeNHT D8JJ83qdHCKS3p7ZDqP8OAIpNG/hO4V4xI49rOA46JK4yGjFjXW9sVZ8Dlinj9vqkyJyEvnabBhEE x4wzXn6yA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLU9-0003mF-2G; Thu, 24 Sep 2020 07:16:09 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLU6-0003kS-45 for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:16:08 +0000 Received: by mail-pl1-x636.google.com with SMTP id u4so1203183plr.4 for ; Thu, 24 Sep 2020 00:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6+EfrryUMCL7dAKUwTQI3rDTtu8cnZJN4QfF5pBjSyY=; b=XSAI0NJYSfH/OUrsLJg4wuX5Y9DD5i3xRZ++HX9BnjSe/o5lsPuIfnXYkauQvVUtu8 2YIKgeJc1CyRZbOVdrq04ZG9sefQ/V0t4YyxgxbtSiOawcrKa9KEhm4a20i7txGHlq2e t0kBi+uhmwDRw/T8nE6UBaxXZKfULdy19wnvuMjDFNHduwlS/Khj/4GVA/EpUZoe0/sY OuGsu1Z3kAJVFR7kDq1H1ALbpshCbSJG90IJnibP99vexpJc34yQMenlb0ygR9M5LMH3 CL5SpFHY1Q+nhglBkFip4gxUargLJLm8dYZ2RF0Xu91Lyw7wAu0mXHEmfokvbkmaaDjO pf2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6+EfrryUMCL7dAKUwTQI3rDTtu8cnZJN4QfF5pBjSyY=; b=cy5I4FrFo4Vf7d492ZMJRZume/H6/x500wyPTBZ3vXIirHipZ7TiB1NNV7FdqxykSi af+GSKb4a+oGt6DSURilt8jYAwG/x6gvW4pO89gUIQxrCMBzDRCNSttaiQhZpIvtYHI4 KH6WVI6CBoBVKeSZI5eEmIGZX37AOOKkDACsJUv2XCNik1WjAYxy2BMiJN/4ZPUZxvVj Hf0/lLmR6PGRqUZyDZ3AnXjZwAw4xBhv0GLPcTuaI5yu9gcdED5RTc6ctI9WXUNkgkhM L6afsuRzbvkCUUQbBcZeXmCQXKARV/NQ8372NR2dqn8QPewp9A0sm5N4Tn0kvR0xjCbM rBTg== X-Gm-Message-State: AOAM533b9G4HFEXtPQZ1d/GnXw1DAZGvLDX+0JEEBGMz0O8C9YSktj3H 3CS1ufNbUt68Z/iD0YaA0OY= X-Google-Smtp-Source: ABdhPJwdQoxxfqH9UED8pz+nyIQsa2d+m40FuBdHRW8Hzx4pnWRxSbLhjEFnCBkg2kRCMyLOG4JEGA== X-Received: by 2002:a17:902:b90b:b029:d2:2a15:53e9 with SMTP id bf11-20020a170902b90bb02900d22a1553e9mr3176210plb.84.1600931763682; Thu, 24 Sep 2020 00:16:03 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id bj2sm1368098pjb.20.2020.09.24.00.16.02 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:16:03 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 33B642037C20EB; Thu, 24 Sep 2020 16:16:00 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 17/21] um: host: add nommu build for ARCH=um Date: Thu, 24 Sep 2020 16:12:57 +0900 Message-Id: <3999a68d78871b3378a7c15915cec49af708357c.1600922529.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031606_194621_B7205646 X-CRM114-Status: GOOD ( 19.40 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:636 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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). Signed-off-by: Hajime Tazaki Signed-off-by: Octavian Purdila --- 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 diff --git a/tools/um/Makefile b/tools/um/Makefile index 552ed5f1edae..a93e060b1f89 100644 --- a/tools/um/Makefile +++ b/tools/um/Makefile @@ -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) diff --git a/tools/um/Targets b/tools/um/Targets index a4711f1ef422..4e1f0f4d81a3 100644 --- a/tools/um/Targets +++ b/tools/um/Targets @@ -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 diff --git a/tools/um/include/lkl.h b/tools/um/include/lkl.h new file mode 100644 index 000000000000..707e01b64a70 --- /dev/null +++ b/tools/um/include/lkl.h @@ -0,0 +1,151 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LKL_H +#define _LKL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define _LKL_LIBC_COMPAT_H + +#ifdef __cplusplus +#define class __lkl__class +#endif + +/* + * Avoid collisions between Android which defines __unused and + * linux/icmp.h which uses __unused as a structure field. + */ +#pragma push_macro("__unused") +#undef __unused + +#include + +#pragma pop_macro("__unused") + +#ifdef __cplusplus +#undef class +#endif + +/** + * lkl_strerror - returns a string describing the given error code + * + * @err - error code + * @returns - string for the given error code + */ +const char *lkl_strerror(int err); + +/** + * lkl_perror - prints a string describing the given error code + * + * @msg - prefix for the error message + * @err - error code + */ +void lkl_perror(char *msg, int err); + +#if __LKL__BITS_PER_LONG == 64 +#define lkl_sys_fstatat lkl_sys_newfstatat +#define lkl_sys_fstat lkl_sys_newfstat + +#else +#define __lkl__NR_fcntl __lkl__NR_fcntl64 + +#define lkl_stat lkl_stat64 +#define lkl_sys_stat lkl_sys_stat64 +#define lkl_sys_lstat lkl_sys_lstat64 +#define lkl_sys_truncate lkl_sys_truncate64 +#define lkl_sys_ftruncate lkl_sys_ftruncate64 +#define lkl_sys_sendfile lkl_sys_sendfile64 +#define lkl_sys_fstatat lkl_sys_fstatat64 +#define lkl_sys_fstat lkl_sys_fstat64 +#define lkl_sys_fcntl lkl_sys_fcntl64 + +#define lkl_statfs lkl_statfs64 + +static inline int lkl_sys_statfs(const char *path, struct lkl_statfs *buf) +{ + return lkl_sys_statfs64(path, sizeof(*buf), buf); +} + +static inline int lkl_sys_fstatfs(unsigned int fd, struct lkl_statfs *buf) +{ + return lkl_sys_fstatfs64(fd, sizeof(*buf), buf); +} + +#define lkl_sys_nanosleep lkl_sys_nanosleep_time32 +static inline int lkl_sys_nanosleep_time32(struct lkl_timespec *rqtp, + struct lkl_timespec *rmtp) +{ + long p[6] = {(long)rqtp, (long)rmtp, 0, 0, 0, 0}; + + return lkl_syscall(__lkl__NR_nanosleep, p); +} + +#endif + +static inline int lkl_sys_stat(const char *path, struct lkl_stat *buf) +{ + return lkl_sys_fstatat(LKL_AT_FDCWD, path, buf, 0); +} + +static inline int lkl_sys_lstat(const char *path, struct lkl_stat *buf) +{ + return lkl_sys_fstatat(LKL_AT_FDCWD, path, buf, + LKL_AT_SYMLINK_NOFOLLOW); +} + +#ifdef __lkl__NR_openat +/** + * lkl_sys_open - wrapper for lkl_sys_openat + */ +static inline long lkl_sys_open(const char *file, int flags, int mode) +{ + return lkl_sys_openat(LKL_AT_FDCWD, file, flags, mode); +} + +/** + * lkl_sys_creat - wrapper for lkl_sys_openat + */ +static inline long lkl_sys_creat(const char *file, int mode) +{ + return lkl_sys_openat(LKL_AT_FDCWD, file, + LKL_O_CREAT|LKL_O_WRONLY|LKL_O_TRUNC, mode); +} +#endif + +#ifdef __lkl__NR_mkdirat +/** + * lkl_sys_mkdir - wrapper for lkl_sys_mkdirat + */ +static inline long lkl_sys_mkdir(const char *path, mode_t mode) +{ + return lkl_sys_mkdirat(LKL_AT_FDCWD, path, mode); +} +#endif + +#ifdef __lkl__NR_epoll_create1 +/** + * lkl_sys_epoll_create - wrapper for lkl_sys_epoll_create1 + */ +static inline long lkl_sys_epoll_create(int size) +{ + return lkl_sys_epoll_create1(0); +} +#endif + +#ifdef __lkl__NR_epoll_pwait +/** + * lkl_sys_epoll_wait - wrapper for lkl_sys_epoll_pwait + */ +static inline long lkl_sys_epoll_wait(int fd, struct lkl_epoll_event *ev, + int cnt, int to) +{ + return lkl_sys_epoll_pwait(fd, ev, cnt, to, 0, _LKL_NSIG/8); +} +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/tools/um/include/lkl_host.h b/tools/um/include/lkl_host.h new file mode 100644 index 000000000000..85e80eb4ad0d --- /dev/null +++ b/tools/um/include/lkl_host.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LKL_HOST_H +#define _LKL_HOST_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +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 diff --git a/tools/um/uml/Build b/tools/um/uml/Build index 435a9670d3ff..191c6479ad72 100644 --- a/tools/um/uml/Build +++ b/tools/um/uml/Build @@ -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 diff --git a/tools/um/uml/nommu/Build b/tools/um/uml/nommu/Build new file mode 100644 index 000000000000..98fd6b86a085 --- /dev/null +++ b/tools/um/uml/nommu/Build @@ -0,0 +1 @@ +liblinux-y = registers.o unimplemented.o diff --git a/tools/um/uml/nommu/registers.c b/tools/um/uml/nommu/registers.c new file mode 100644 index 000000000000..11573a204720 --- /dev/null +++ b/tools/um/uml/nommu/registers.c @@ -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) +{ +} diff --git a/tools/um/uml/nommu/unimplemented.c b/tools/um/uml/nommu/unimplemented.c new file mode 100644 index 000000000000..9da3e5c8bafb --- /dev/null +++ b/tools/um/uml/nommu/unimplemented.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +#include + +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) +{ +} From patchwork Thu Sep 24 07:12:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370383 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=abtUqnQE; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=p2UFUQc7; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmYl0fxFz9sSC for ; Thu, 24 Sep 2020 17:16:27 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=7cHrtNpaFWobObkyrRVJFfvYzBFiTznYFrzZdn0nFGw=; b=abtUqnQEb0hemk7YEFAvTsMqi Kdoyq6cvD/v0SCFn5qMBhlrEGuNu6vyEFYAZQvAygad0CfoNUI0GQwBDLpoCQXCFscyHWf2aQsNmS 6vczzhrQJcBJj67J3m4f+qzb0lgJVDD8il+0EXBwZQNEZt8U8ZS//R8DHzeze2RzZ6y40BqwMNKC1 TfifARsYrZnO4UsHTSu3i85SLb0CyA0ViceGPjeH9HVAaT8OAt91549hExzYNRiDW5yR47G1YMSq8 PDRskckLqXRzq4WcjY9Kz/reC9hG0UlyCK9BEunjASrLtvPKa28L0xQ1AuQyCW+qd6nm3IXM5J5e3 rrFN2Gizw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLUN-0003ro-LG; Thu, 24 Sep 2020 07:16:23 +0000 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLUH-0003p2-Vx for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:16:22 +0000 Received: by mail-pg1-x52e.google.com with SMTP id y14so1331511pgf.12 for ; Thu, 24 Sep 2020 00:16:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f8X530ewYdklTpRShu04QgcFqIloEAYvsR2T5wI/7yQ=; b=p2UFUQc7xZvO0JVqEnhRfp+Mn7w7n+RjKhglUpdVcTm36RmXPrIGfX5o+h36chiVW0 5HbnnlQ8n3n31U2wzMQWnD9mZq0Mzhv/57KNbMVnyPmBfjAcrkeVRUSfxB2joLzOfbd1 4Tg/s+QoD+Q+z/W3ANj0rINyTVlwLYktLPVO85VIk79BuXBBiuxRetaaj7o0GjvhDJq5 ze4Jk4/zdj8ylO8iXPThxvz0k9xh6Agl71fisfklIAOC7PZ7oXFc8bc+SDo09kqEeaKW VkdPs9AyxSGU3YEcK+zuRCvCTxu0VLkE0PI4OYHYtuTQmNzqr0LoIhuLzu7yBeFL6FxV NewA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f8X530ewYdklTpRShu04QgcFqIloEAYvsR2T5wI/7yQ=; b=tDYE1JZ1Ihc03hKcXeK1/3VzwmD1LiEFoOxm2Ns85jyU4ol1DCd1zx5l+7BpgYBJHu JTpXVfBX2Q5I17Vm3TORa0ggkNvVeBGZvpyQvKnxx1Xur1cLMyb7rlFg5i3nApOWDaOu XpIY7XCTUMksCWbT6P5BVI5jGmVAVkVbQ5HN5zoLYFJEdiNu0up0R0fORe0Y0EynMiGn figRI2KNlIpTX8lTeNjWIeZTF3vsez+zM6aHpsFP0NdUEMxiASUIU9Esn+xwHrLO+gH+ iRIywgXksnLNQJHggd6Cn0ZUzQ+u+PhDnZVN7abwH1lbXp1XM8+eidbxpqeUpdD4DvEO IWgw== X-Gm-Message-State: AOAM530X5zIzlJ7EMIRoKWNE6ZX+oU9Q3JaFxPG/ej2bTbsnWk+YDRYU qu7VOSOTi7AacaJnxuw1138= X-Google-Smtp-Source: ABdhPJxfifKa0OZyq8V4uwu3hypYKMx7Q9NBWA07LeiSLhHRAmaFGtH6rPXcFFgUMcW149QsTlSu9w== X-Received: by 2002:aa7:96af:0:b029:142:6a8f:c04b with SMTP id g15-20020aa796af0000b02901426a8fc04bmr3396020pfk.30.1600931775668; Thu, 24 Sep 2020 00:16:15 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id x4sm1811050pfm.86.2020.09.24.00.16.14 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:16:15 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 192FE2037C20F0; Thu, 24 Sep 2020 16:16:05 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 18/21] um: host: add utilities functions Date: Thu, 24 Sep 2020 16:12:58 +0900 Message-Id: <598d65c578c9cc5a61509241cf9a63234be1cfeb.1600922529.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031618_112257_43D82A44 X-CRM114-Status: GOOD ( 24.32 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:52e listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add basic utility functions for getting a string from a kernel error code and a fprintf like function that uses the host print operation. The latter is useful for informing the user about errors that occur in the host library. Signed-off-by: Hajime Tazaki --- 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 diff --git a/tools/um/lib/Build b/tools/um/lib/Build new file mode 100644 index 000000000000..fc967af4104a --- /dev/null +++ b/tools/um/lib/Build @@ -0,0 +1,4 @@ +include $(objtree)/include/config/auto.conf + +liblinux-$(CONFIG_UMMODE_LIB) += utils.o +liblinux-$(CONFIG_UMMODE_LIB) += jmp_buf.o diff --git a/tools/um/lib/jmp_buf.c b/tools/um/lib/jmp_buf.c new file mode 100644 index 000000000000..f6bdd7e4bd83 --- /dev/null +++ b/tools/um/lib/jmp_buf.c @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include + +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); +} diff --git a/tools/um/lib/jmp_buf.h b/tools/um/lib/jmp_buf.h new file mode 100644 index 000000000000..8782cbaaf51f --- /dev/null +++ b/tools/um/lib/jmp_buf.h @@ -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 diff --git a/tools/um/lib/utils.c b/tools/um/lib/utils.c new file mode 100644 index 000000000000..4930479a8a35 --- /dev/null +++ b/tools/um/lib/utils.c @@ -0,0 +1,210 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include + +static const char * const lkl_err_strings[] = { + "Success", + "Operation not permitted", + "No such file or directory", + "No such process", + "Interrupted system call", + "I/O error", + "No such device or address", + "Argument list too long", + "Exec format error", + "Bad file number", + "No child processes", + "Try again", + "Out of memory", + "Permission denied", + "Bad address", + "Block device required", + "Device or resource busy", + "File exists", + "Cross-device link", + "No such device", + "Not a directory", + "Is a directory", + "Invalid argument", + "File table overflow", + "Too many open files", + "Not a typewriter", + "Text file busy", + "File too large", + "No space left on device", + "Illegal seek", + "Read-only file system", + "Too many links", + "Broken pipe", + "Math argument out of domain of func", + "Math result not representable", + "Resource deadlock would occur", + "File name too long", + "No record locks available", + "Invalid system call number", + "Directory not empty", + "Too many symbolic links encountered", + "Bad error code", /* EWOULDBLOCK is EAGAIN */ + "No message of desired type", + "Identifier removed", + "Channel number out of range", + "Level 2 not synchronized", + "Level 3 halted", + "Level 3 reset", + "Link number out of range", + "Protocol driver not attached", + "No CSI structure available", + "Level 2 halted", + "Invalid exchange", + "Invalid request descriptor", + "Exchange full", + "No anode", + "Invalid request code", + "Invalid slot", + "Bad error code", /* EDEADLOCK is EDEADLK */ + "Bad font file format", + "Device not a stream", + "No data available", + "Timer expired", + "Out of streams resources", + "Machine is not on the network", + "Package not installed", + "Object is remote", + "Link has been severed", + "Advertise error", + "Srmount error", + "Communication error on send", + "Protocol error", + "Multihop attempted", + "RFS specific error", + "Not a data message", + "Value too large for defined data type", + "Name not unique on network", + "File descriptor in bad state", + "Remote address changed", + "Can not access a needed shared library", + "Accessing a corrupted shared library", + ".lib section in a.out corrupted", + "Attempting to link in too many shared libraries", + "Cannot exec a shared library directly", + "Illegal byte sequence", + "Interrupted system call should be restarted", + "Streams pipe error", + "Too many users", + "Socket operation on non-socket", + "Destination address required", + "Message too long", + "Protocol wrong type for socket", + "Protocol not available", + "Protocol not supported", + "Socket type not supported", + "Operation not supported on transport endpoint", + "Protocol family not supported", + "Address family not supported by protocol", + "Address already in use", + "Cannot assign requested address", + "Network is down", + "Network is unreachable", + "Network dropped connection because of reset", + "Software caused connection abort", + "Connection reset by peer", + "No buffer space available", + "Transport endpoint is already connected", + "Transport endpoint is not connected", + "Cannot send after transport endpoint shutdown", + "Too many references: cannot splice", + "Connection timed out", + "Connection refused", + "Host is down", + "No route to host", + "Operation already in progress", + "Operation now in progress", + "Stale file handle", + "Structure needs cleaning", + "Not a XENIX named type file", + "No XENIX semaphores available", + "Is a named type file", + "Remote I/O error", + "Quota exceeded", + "No medium found", + "Wrong medium type", + "Operation Canceled", + "Required key not available", + "Key has expired", + "Key has been revoked", + "Key was rejected by service", + "Owner died", + "State not recoverable", + "Operation not possible due to RF-kill", + "Memory page has hardware error", +}; + +const char *lkl_strerror(int err) +{ + if (err < 0) + err = -err; + + if ((size_t)err >= sizeof(lkl_err_strings) / sizeof(const char *)) + return "Bad error code"; + + return lkl_err_strings[err]; +} + +void lkl_perror(char *msg, int err) +{ + const char *err_msg = lkl_strerror(err); + /* We need to use 'real' printf because lkl_host_ops.print can + * be turned off when debugging is off. + */ + lkl_printf("%s: %s\n", msg, err_msg); +} + +static int lkl_vprintf(const char *fmt, va_list args) +{ + int n; + char *buffer; + va_list copy; + + if (!lkl_host_ops.print) + return 0; + + va_copy(copy, args); + n = vsnprintf(NULL, 0, fmt, copy); + va_end(copy); + + buffer = lkl_host_ops.mem_alloc(n + 1); + if (!buffer) + return (-1); + + vsnprintf(buffer, n + 1, fmt, args); + + lkl_host_ops.print(buffer, n); + lkl_host_ops.mem_free(buffer); + + return n; +} + +int lkl_printf(const char *fmt, ...) +{ + int n; + va_list args; + + va_start(args, fmt); + n = lkl_vprintf(fmt, args); + va_end(args); + + return n; +} + +void lkl_bug(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + lkl_vprintf(fmt, args); + va_end(args); + + lkl_host_ops.panic(); +} From patchwork Thu Sep 24 07:12:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370382 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=RhQDsxBO; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=K1DzyR8a; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmYf0Vk1z9sTH for ; Thu, 24 Sep 2020 17:16:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=DRKNQJIBjeC9z3jHhrcHVsD5si0LzQrTrevhzh2Yeeo=; b=RhQDsxBOMdrGwHyqyXKxNJS+n xo1ZzK5xRM5VcGFC4p2fZoQy4fsJnZjDxJ6ZkkuP41GtcS5wg1V94LcwFLdXnP6vWOHAVILg8qoGd lSSzgwdQw0XnQeW8EObRjE28sSrHCNS4PRjWXKSgw2q2w1ozL8K0ZjzD3tpxbu4gi9730ZO+UgUgD LcKHD+Zk86Urd9vZibOrQ8wjW2l3esY13c1STZlcRIWAQj/Roq9EYra4uw8YxkJJ36FvthOGXEnWt DoiG5NWUWYRXHYBco5l5q0iiqvN46USQlkAlUAa1GX4016cmXrGWntLWM11RhB9Xw+ivk+702K6HM elGWLDw1Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLUI-0003q4-Kv; Thu, 24 Sep 2020 07:16:18 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLUE-0003nT-G6 for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:16:16 +0000 Received: by mail-pg1-x544.google.com with SMTP id k133so1345398pgc.7 for ; Thu, 24 Sep 2020 00:16:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MZNukGqivXQcGV5PlGwWwQGP0z/tZaH3aPXDvp4XDIk=; b=K1DzyR8aihUvyNTfmn2rwfFaBNxygggevVdEo4KidS+jCxtQyzzk/Vmk5qgdrrgMea F0lYOQrwJ42hOHWdZzMyuKX6wVUqYCwV5E/K3u5xiE0P29s0iHXT6E8GdBRwOmYlIlou Zb0inyYgwqmS5vY5EDKOZo+H3pZ1DS182YLuMObz8M7Wxyz9+SfFK7fw8jxwxEIXnOji nQ0EOvmeuFaqeOrwa7wmAN0RtwASSwU520AEJNOFa8RVr9C48o9uTkgeZeM+UN3D3e2w iT2rqMEiIcmIChnl2ih4xDA48z6Q1LawZ0eQKwu6ZknhDiVJQwEnDH9Ckuq6Q21iaH92 1r5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MZNukGqivXQcGV5PlGwWwQGP0z/tZaH3aPXDvp4XDIk=; b=SKpso8vknvx9QDbZvuR8WG0C0GJA8BpT/9dahs/cV0mDa+e5dz95+ELqnPDxnWmRer UWSFZsjzuX/dNS6fPSTEuhUt5SWjMoOGdMP1qSO+peAQi0ksofi3cUdlVpoDuA3u+DyY 3eEKv1sG8AYJ4Yr56xI0maVUljtCFDD3nDpg/3il+FBWnxIZ6fsvdgkvv+VykplancIt WYfA9VAIShZytEEBfggrGnipA8eDaS1GEAt/TK2Irc8WuuErXcLwl0uRYgHAANwEQtiS ilQaHTwyRjARlfs2U1GSxr9UrLLuYbg6kXK/7+9+7sAyhY4dE8oZA8q2s4VO4kJiP2eJ IX8g== X-Gm-Message-State: AOAM5309SxGrIyT2KuiGN3e6evfo8bORDjGFSaZEZ92AwSyb+DKLo6gc PqANatykYHv4O0XmWCTAQkQ= X-Google-Smtp-Source: ABdhPJyJk5I+KkUjmXoEJD/BasV0qYcai8W43BqI+HjzDFidHEjzJ+aNzzsRAg1f0eiHSMK2libbNw== X-Received: by 2002:a63:f922:: with SMTP id h34mr2966593pgi.235.1600931772590; Thu, 24 Sep 2020 00:16:12 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id d8sm1396490pjs.47.2020.09.24.00.16.11 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:16:11 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 8C9692037C20F5; Thu, 24 Sep 2020 16:16:09 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 19/21] um: host: posix host operations Date: Thu, 24 Sep 2020 16:12:59 +0900 Message-Id: <1d47038718e449c24670bfc81406c792c14a6212.1600922529.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031614_614683_39159D11 X-CRM114-Status: GOOD ( 20.81 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:544 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This commit implements LKL host operations for POSIX hosts. The operations are implemented to be portable in various POSIX OSs. Signed-off-by: Octavian Purdila Signed-off-by: Hajime Tazaki --- 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 diff --git a/tools/um/lib/Build b/tools/um/lib/Build index fc967af4104a..dddff26a3b4e 100644 --- a/tools/um/lib/Build +++ b/tools/um/lib/Build @@ -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 diff --git a/tools/um/lib/posix-host.c b/tools/um/lib/posix-host.c new file mode 100644 index 000000000000..b6b5b2902254 --- /dev/null +++ b/tools/um/lib/posix-host.c @@ -0,0 +1,292 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include "jmp_buf.h" + +/* Let's see if the host has semaphore.h */ +#include + +#ifdef _POSIX_SEMAPHORES +#include +/* TODO(pscollins): We don't support fork() for now, but maybe one day + * we will? + */ +#define SHARE_SEM 0 +#endif /* _POSIX_SEMAPHORES */ + + +struct lkl_mutex { + pthread_mutex_t mutex; +}; + +struct lkl_sem { +#ifdef _POSIX_SEMAPHORES + sem_t sem; +#else + pthread_mutex_t lock; + int count; + pthread_cond_t cond; +#endif /* _POSIX_SEMAPHORES */ +}; + +struct lkl_tls_key { + pthread_key_t key; +}; + +static void print(const char *str, int len) +{ + int ret __attribute__((unused)); + + ret = write(STDOUT_FILENO, str, len); +} + +static void panic(void) +{ + assert(0); +} + +#define WARN_UNLESS(exp) do { \ + if (exp < 0) \ + lkl_printf("%s: %s\n", #exp, strerror(errno)); \ + } while (0) + +static int _warn_pthread(int ret, char *str_exp) +{ + if (ret > 0) + lkl_printf("%s: %s\n", str_exp, strerror(ret)); + + return ret; +} + + +/* pthread_* functions use the reverse convention */ +#define WARN_PTHREAD(exp) _warn_pthread(exp, #exp) + +static struct lkl_sem *sem_alloc(int count) +{ + struct lkl_sem *sem; + + sem = malloc(sizeof(*sem)); + if (!sem) + return NULL; + +#ifdef _POSIX_SEMAPHORES + if (sem_init(&sem->sem, SHARE_SEM, count) < 0) { + lkl_printf("sem_init: %s\n", strerror(errno)); + free(sem); + return NULL; + } +#else + pthread_mutex_init(&sem->lock, NULL); + sem->count = count; + WARN_PTHREAD(pthread_cond_init(&sem->cond, NULL)); +#endif /* _POSIX_SEMAPHORES */ + + return sem; +} + +static void sem_free(struct lkl_sem *sem) +{ +#ifdef _POSIX_SEMAPHORES + WARN_UNLESS(sem_destroy(&sem->sem)); +#else + WARN_PTHREAD(pthread_cond_destroy(&sem->cond)); + WARN_PTHREAD(pthread_mutex_destroy(&sem->lock)); +#endif /* _POSIX_SEMAPHORES */ + free(sem); +} + +static void sem_up(struct lkl_sem *sem) +{ +#ifdef _POSIX_SEMAPHORES + WARN_UNLESS(sem_post(&sem->sem)); +#else + WARN_PTHREAD(pthread_mutex_lock(&sem->lock)); + sem->count++; + if (sem->count > 0) + WARN_PTHREAD(pthread_cond_signal(&sem->cond)); + WARN_PTHREAD(pthread_mutex_unlock(&sem->lock)); +#endif /* _POSIX_SEMAPHORES */ + +} + +static void sem_down(struct lkl_sem *sem) +{ +#ifdef _POSIX_SEMAPHORES + int err; + + do { + err = sem_wait(&sem->sem); + } while (err < 0 && errno == EINTR); + if (err < 0 && errno != EINTR) + lkl_printf("sem_wait: %s\n", strerror(errno)); +#else + WARN_PTHREAD(pthread_mutex_lock(&sem->lock)); + while (sem->count <= 0) + WARN_PTHREAD(pthread_cond_wait(&sem->cond, &sem->lock)); + sem->count--; + WARN_PTHREAD(pthread_mutex_unlock(&sem->lock)); +#endif /* _POSIX_SEMAPHORES */ +} + +static struct lkl_mutex *mutex_alloc(int recursive) +{ + struct lkl_mutex *_mutex = malloc(sizeof(struct lkl_mutex)); + pthread_mutex_t *mutex = NULL; + pthread_mutexattr_t attr; + + if (!_mutex) + return NULL; + + mutex = &_mutex->mutex; + WARN_PTHREAD(pthread_mutexattr_init(&attr)); + + /* PTHREAD_MUTEX_ERRORCHECK is *very* useful for debugging, + * but has some overhead, so we provide an option to turn it + * off. + */ +#ifdef DEBUG + if (!recursive) + WARN_PTHREAD(pthread_mutexattr_settype( + &attr, PTHREAD_MUTEX_ERRORCHECK)); +#endif /* DEBUG */ + + if (recursive) + WARN_PTHREAD(pthread_mutexattr_settype( + &attr, PTHREAD_MUTEX_RECURSIVE)); + + WARN_PTHREAD(pthread_mutex_init(mutex, &attr)); + + return _mutex; +} + +static void mutex_lock(struct lkl_mutex *mutex) +{ + WARN_PTHREAD(pthread_mutex_lock(&mutex->mutex)); +} + +static void mutex_unlock(struct lkl_mutex *_mutex) +{ + pthread_mutex_t *mutex = &_mutex->mutex; + + WARN_PTHREAD(pthread_mutex_unlock(mutex)); +} + +static void mutex_free(struct lkl_mutex *_mutex) +{ + pthread_mutex_t *mutex = &_mutex->mutex; + + WARN_PTHREAD(pthread_mutex_destroy(mutex)); + free(_mutex); +} + +static lkl_thread_t thread_create(void* (*fn)(void *), void *arg) +{ + pthread_t thread; + + if (WARN_PTHREAD(pthread_create(&thread, NULL, fn, arg))) + return 0; + else + return (lkl_thread_t) thread; +} + +static void thread_detach(void) +{ + WARN_PTHREAD(pthread_detach(pthread_self())); +} + +static void thread_exit(void) +{ + pthread_exit(NULL); +} + +static int thread_join(lkl_thread_t tid) +{ + if (WARN_PTHREAD(pthread_join((pthread_t)tid, NULL))) + return (-1); + else + return 0; +} + +static lkl_thread_t thread_self(void) +{ + return (lkl_thread_t)pthread_self(); +} + +static int thread_equal(lkl_thread_t a, lkl_thread_t b) +{ + return pthread_equal((pthread_t)a, (pthread_t)b); +} + +static long _gettid(void) +{ +#ifdef __FreeBSD__ + return (long)pthread_self(); +#else + return syscall(SYS_gettid); +#endif +} + +static struct lkl_tls_key *tls_alloc(void (*destructor)(void *)) +{ + struct lkl_tls_key *ret = malloc(sizeof(struct lkl_tls_key)); + + if (WARN_PTHREAD(pthread_key_create(&ret->key, destructor))) { + free(ret); + return NULL; + } + return ret; +} + +static void tls_free(struct lkl_tls_key *key) +{ + WARN_PTHREAD(pthread_key_delete(key->key)); + free(key); +} + +static int tls_set(struct lkl_tls_key *key, void *data) +{ + if (WARN_PTHREAD(pthread_setspecific(key->key, data))) + return (-1); + return 0; +} + +static void *tls_get(struct lkl_tls_key *key) +{ + return pthread_getspecific(key->key); +} + +struct lkl_host_operations lkl_host_ops = { + .panic = panic, + .print = print, + .mem_alloc = (void *)malloc, + .mem_free = free, + .thread_create = thread_create, + .thread_detach = thread_detach, + .thread_exit = thread_exit, + .thread_join = thread_join, + .thread_self = thread_self, + .thread_equal = thread_equal, + .sem_alloc = sem_alloc, + .sem_free = sem_free, + .sem_up = sem_up, + .sem_down = sem_down, + .mutex_alloc = mutex_alloc, + .mutex_free = mutex_free, + .mutex_lock = mutex_lock, + .mutex_unlock = mutex_unlock, + .gettid = _gettid, + .tls_alloc = tls_alloc, + .tls_free = tls_free, + .tls_set = tls_set, + .tls_get = tls_get, + .jmp_buf_set = jmp_buf_set, + .jmp_buf_longjmp = jmp_buf_longjmp, +}; + From patchwork Thu Sep 24 07:13:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370384 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=16puw/zW; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=UESaZ7Dk; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmYx678sz9sTl for ; Thu, 24 Sep 2020 17:16:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=sMUCAftsQvqtmu9/ZfGwhxaa6mlwp1qQnvchv841ht4=; b=16puw/zWxdaIdSXGr9+2BFVaq ccRxrjk5jlR+CUFACxseHF2mVUyxuAxHKICTDtBre0ju+nJSZZtkSrEFQuz+3l4m0BsFsri1ybhHB n/C/hlXpstvJfm8PlCWeRgfYYhIky2FnDZ2XSoma3AsNMEiYcuYPUh+PeebwpeONIaz69X/HXUDMM zT9jNOIS3p1w0Y4cqUxxLKRS5J75wh9ySpHwgmFDSz64wvMHvxU7UlAVRlMyPcAQiis0WAHPsb1PE GbDPjSvv+HZpfkiZdqIIr+Hi0BvyWJpy9YgVFk1S41e4tXQOVXohEnFt+2yDlfFexqIfB20jX6gR7 wpSPZP2hg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLUY-0003v2-Bz; Thu, 24 Sep 2020 07:16:34 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLUU-0003t7-B1 for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:16:32 +0000 Received: by mail-pf1-x42d.google.com with SMTP id x22so1318117pfo.12 for ; Thu, 24 Sep 2020 00:16:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LiuoON0vA+8EvA5WeEv/es1B+giSpzDkr4atmJEqcWI=; b=UESaZ7DkkCWW4IGQh4ND4brK0hO0ylnzH9wrogPxBGSatoDbqyRXp09d3uWMaoc0JE MqUKq8u0nILK97q7oWCu4Xk7IMt+Wz/+17p/a+L1HpiYCdE2WK16wIEGHVeyy2Jyfb/j ZKITkaO6Bp/6eO1X+hiJBUe4RGu3uUexgeH0tfSwjEa0SljTb32xCpEyPAFYBYovfSqX 8l/GfApUrnKBgUeu5Ru1SRmBz+Rp+X66SA1AlNv8hZxwkcSriVpFzjfkHv2pHyN68nGt JRLTF2NY0m7aJQdVJg3/wS4I3MaxCvv0JS7TasdsUjR7XkJ/LEZo7KzsQaZqS+rpLxap pK8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LiuoON0vA+8EvA5WeEv/es1B+giSpzDkr4atmJEqcWI=; b=swmeMg/mpvV734DVPuGsPxCW7HY8RIi5IofyWA2xxTRwb/YI7eduSDv0kEs4bvCMQd 6x6hDCqr8jv2fF0pVz0u/O4869yEj/TeX3M5ri8Uma/VL1eQBwgOTXuqE8Ns3mGA0lfg qS5KC8yFHDy88/d6ghHtdtrevrMX4XLS2TSMmzgNpHqsVfrJjRumgdkXEKbYM2gzuzZk On08dfPWpKV6whuWNEewq7JQVbH4yuzdsyz7YoPCff3LMISZ1MQsEtQhk7H9qOIafymE JFa/3qBRSBv3DH8EQ9b3lV1pjorRnmFg2mpqcB8P9+tv3QHFr5zwxJ7x+eTiGD3/XGKT BB/w== X-Gm-Message-State: AOAM533w3E9Nw1NXTIOhJUt7ZnCtDewgX6NC4+leiBxlXIRwzUE7Phs4 jEIM6NtUMlJKfcLIugqf5fA= X-Google-Smtp-Source: ABdhPJz64MFdJFlyp8I/NIjkR0KUeQfu2DYFHt27O96bCWuhmwn5oQQnRIGINUnC7dW3wLNyND77Rw== X-Received: by 2002:a63:4923:: with SMTP id w35mr2783821pga.368.1600931787758; Thu, 24 Sep 2020 00:16:27 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id b10sm1766547pgm.64.2020.09.24.00.16.26 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:16:27 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id B36A42037C2107; Thu, 24 Sep 2020 16:16:24 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 20/21] um: host: add test programs Date: Thu, 24 Sep 2020 16:13:00 +0900 Message-Id: X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031630_390075_EB51E105 X-CRM114-Status: GOOD ( 26.76 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42d listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add a simple LKL test application (boot) that starts the kernel and performs simple tests that minimally exercise the LKL API. Signed-off-by: Hajime Tazaki Signed-off-by: Octavian Purdila --- 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 diff --git a/tools/um/Makefile b/tools/um/Makefile index a93e060b1f89..20de2e4c162f 100644 --- a/tools/um/Makefile +++ b/tools/um/Makefile @@ -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 diff --git a/tools/um/Targets b/tools/um/Targets index 4e1f0f4d81a3..2bb90381843c 100644 --- a/tools/um/Targets +++ b/tools/um/Targets @@ -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 diff --git a/tools/um/tests/Build b/tools/um/tests/Build new file mode 100644 index 000000000000..26a607f90dc8 --- /dev/null +++ b/tools/um/tests/Build @@ -0,0 +1 @@ +boot-y += boot.o test.o diff --git a/tools/um/tests/boot.c b/tools/um/tests/boot.c new file mode 100644 index 000000000000..45b9a7276de7 --- /dev/null +++ b/tools/um/tests/boot.c @@ -0,0 +1,393 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#if defined(__FreeBSD__) +#include +#include +#elif __linux +#include +#include +#elif __MINGW32__ +#include +#endif + +#include "test.h" + +#ifndef __MINGW32__ +#define sleep_ns 87654321 +int lkl_test_nanosleep(void) +{ + struct lkl_timespec ts = { + .tv_sec = 0, + .tv_nsec = sleep_ns, + }; + struct timespec start, stop; + long delta; + long ret; + + clock_gettime(CLOCK_MONOTONIC, &start); + ret = lkl_sys_nanosleep((struct __lkl__kernel_timespec *)&ts, NULL); + clock_gettime(CLOCK_MONOTONIC, &stop); + + delta = 1e9*(stop.tv_sec - start.tv_sec) + + (stop.tv_nsec - start.tv_nsec); + + lkl_test_logf("sleep %ld, expected sleep %d\n", delta, sleep_ns); + + if (ret == 0 && delta > sleep_ns * 0.9) + return TEST_SUCCESS; + + return TEST_FAILURE; +} +#endif + +LKL_TEST_CALL(getpid, lkl_sys_getpid, 1) + +void check_latency(long (*f)(void), long *min, long *max, long *avg) +{ + int i; + struct timespec start, stop; + unsigned long long sum = 0; + static const int count = 20; + long delta; + + *min = 1000000000; + *max = -1; + + for (i = 0; i < count; i++) { + clock_gettime(CLOCK_MONOTONIC, &start); + f(); + clock_gettime(CLOCK_MONOTONIC, &stop); + + delta = 1e9*(stop.tv_sec - start.tv_sec) + + (stop.tv_nsec - start.tv_nsec); + + if (*min > delta) + *min = delta; + if (*max < delta) + *max = delta; + sum += delta; + } + *avg = sum / count; +} + +static long native_getpid(void) +{ +#ifdef __MINGW32__ + GetCurrentProcessId(); +#else + getpid(); +#endif + return 0; +} + +int lkl_test_syscall_latency(void) +{ + long min, max, avg; + + lkl_test_logf("avg/min/max: "); + + check_latency(lkl_sys_getpid, &min, &max, &avg); + + lkl_test_logf("lkl:%ld/%ld/%ld ", avg, min, max); + + check_latency(native_getpid, &min, &max, &avg); + + lkl_test_logf("native:%ld/%ld/%ld\n", avg, min, max); + + return TEST_SUCCESS; +} + +#define access_rights 0721 + +LKL_TEST_CALL(creat, lkl_sys_creat, 3, "/file", access_rights) +LKL_TEST_CALL(close, lkl_sys_close, 0, 0); +LKL_TEST_CALL(failopen, lkl_sys_open, -LKL_ENOENT, "/file2", 0, 0); +LKL_TEST_CALL(umask, lkl_sys_umask, 022, 0777); +LKL_TEST_CALL(umask2, lkl_sys_umask, 0777, 0); +LKL_TEST_CALL(open, lkl_sys_open, 0, "/file", LKL_O_RDWR, 0); +static const char wrbuf[] = "test"; +LKL_TEST_CALL(write, lkl_sys_write, sizeof(wrbuf), 0, wrbuf, sizeof(wrbuf)); +LKL_TEST_CALL(lseek_cur, lkl_sys_lseek, sizeof(wrbuf), 0, 0, LKL_SEEK_CUR); +LKL_TEST_CALL(lseek_end, lkl_sys_lseek, sizeof(wrbuf), 0, 0, LKL_SEEK_END); +LKL_TEST_CALL(lseek_set, lkl_sys_lseek, 0, 0, 0, LKL_SEEK_SET); + +int lkl_test_read(void) +{ + char buf[10] = { 0, }; + long ret; + + ret = lkl_sys_read(0, buf, sizeof(buf)); + + lkl_test_logf("lkl_sys_read=%ld buf=%s\n", ret, buf); + + if (ret == sizeof(wrbuf) && !strcmp(wrbuf, buf)) + return TEST_SUCCESS; + + return TEST_FAILURE; +} + +int lkl_test_fstat(void) +{ + struct lkl_stat stat; + long ret; + + ret = lkl_sys_fstat(0, (void *)&stat); + + lkl_test_logf("lkl_sys_fstat=%ld mode=%o size=%ld\n", ret, stat.st_mode, + stat.st_size); + + if (ret == 0 && stat.st_size == sizeof(wrbuf) && + stat.st_mode == (access_rights | LKL_S_IFREG)) + return TEST_SUCCESS; + + return TEST_FAILURE; +} + +LKL_TEST_CALL(mkdir, lkl_sys_mkdir, 0, "/proc", access_rights) + +int lkl_test_stat(void) +{ + struct lkl_stat stat; + long ret; + + ret = lkl_sys_stat("/proc", (void *)&stat); + + lkl_test_logf("lkl_sys_stat(\"/proc\")=%ld mode=%o\n", ret, + stat.st_mode); + + if (ret == 0 && stat.st_mode == (access_rights | LKL_S_IFDIR)) + return TEST_SUCCESS; + + return TEST_FAILURE; +} + +static int lkl_test_pipe2(void) +{ + int pipe_fds[2]; + int READ_IDX = 0, WRITE_IDX = 1; + static const char msg[] = "Hello world!"; + char str[20]; + int msg_len_bytes = strlen(msg) + 1; + int cmp_res; + long ret; + + ret = lkl_sys_pipe2(pipe_fds, LKL_O_NONBLOCK); + if (ret) { + lkl_test_logf("pipe2: %s\n", lkl_strerror(ret)); + return TEST_FAILURE; + } + + ret = lkl_sys_write(pipe_fds[WRITE_IDX], msg, msg_len_bytes); + if (ret != msg_len_bytes) { + if (ret < 0) + lkl_test_logf("write error: %s\n", lkl_strerror(ret)); + else + lkl_test_logf("short write: %ld\n", ret); + return TEST_FAILURE; + } + + ret = lkl_sys_read(pipe_fds[READ_IDX], str, msg_len_bytes); + if (ret != msg_len_bytes) { + if (ret < 0) + lkl_test_logf("read error: %s\n", lkl_strerror(ret)); + else + lkl_test_logf("short read: %ld\n", ret); + return TEST_FAILURE; + } + + cmp_res = memcmp(msg, str, msg_len_bytes); + if (cmp_res) { + lkl_test_logf("memcmp failed: %d\n", cmp_res); + return TEST_FAILURE; + } + + ret = lkl_sys_close(pipe_fds[0]); + if (ret) { + lkl_test_logf("close error: %s\n", lkl_strerror(ret)); + return TEST_FAILURE; + } + + ret = lkl_sys_close(pipe_fds[1]); + if (ret) { + lkl_test_logf("close error: %s\n", lkl_strerror(ret)); + return TEST_FAILURE; + } + + return TEST_SUCCESS; +} + +static int lkl_test_epoll(void) +{ + int epoll_fd, pipe_fds[2]; + int READ_IDX = 0, WRITE_IDX = 1; + struct lkl_epoll_event wait_on, read_result; + static const char msg[] = "Hello world!"; + long ret; + + memset(&wait_on, 0, sizeof(wait_on)); + memset(&read_result, 0, sizeof(read_result)); + + ret = lkl_sys_pipe2(pipe_fds, LKL_O_NONBLOCK); + if (ret) { + lkl_test_logf("pipe2 error: %s\n", lkl_strerror(ret)); + return TEST_FAILURE; + } + + epoll_fd = lkl_sys_epoll_create(1); + if (epoll_fd < 0) { + lkl_test_logf("epoll_create error: %s\n", lkl_strerror(ret)); + return TEST_FAILURE; + } + + wait_on.events = LKL_POLLIN | LKL_POLLOUT; + wait_on.data = pipe_fds[READ_IDX]; + + ret = lkl_sys_epoll_ctl(epoll_fd, LKL_EPOLL_CTL_ADD, pipe_fds[READ_IDX], + &wait_on); + if (ret < 0) { + lkl_test_logf("epoll_ctl error: %s\n", lkl_strerror(ret)); + return TEST_FAILURE; + } + + /* Shouldn't be ready before we have written something */ + ret = lkl_sys_epoll_wait(epoll_fd, &read_result, 1, 0); + if (ret != 0) { + if (ret < 0) + lkl_test_logf("epoll_wait error: %s\n", + lkl_strerror(ret)); + else + lkl_test_logf("epoll_wait: bad event: 0x%lx\n", ret); + return TEST_FAILURE; + } + + ret = lkl_sys_write(pipe_fds[WRITE_IDX], msg, strlen(msg) + 1); + if (ret < 0) { + lkl_test_logf("write error: %s\n", lkl_strerror(ret)); + return TEST_FAILURE; + } + + /* We expect exactly 1 fd to be ready immediately */ + ret = lkl_sys_epoll_wait(epoll_fd, &read_result, 1, 0); + if (ret != 1) { + if (ret < 0) + lkl_test_logf("epoll_wait error: %s\n", + lkl_strerror(ret)); + else + lkl_test_logf("epoll_wait: bad ev no %ld\n", ret); + return TEST_FAILURE; + } + + /* Already tested reading from pipe2 so no need to do it + * here + */ + + return TEST_SUCCESS; +} + +LKL_TEST_CALL(chdir_proc, lkl_sys_chdir, 0, "proc"); + +static int dir_fd; + +static int lkl_test_open_cwd(void) +{ + dir_fd = lkl_sys_open(".", LKL_O_RDONLY | LKL_O_DIRECTORY, 0); + if (dir_fd < 0) { + lkl_test_logf("failed to open current directory: %s\n", + lkl_strerror(dir_fd)); + return TEST_FAILURE; + } + + return TEST_SUCCESS; +} + +/* column where to insert a line break for the list file tests below. */ +#define COL_LINE_BREAK 70 + +static int lkl_test_getdents64(void) +{ + long ret; + char buf[1024], *pos; + struct lkl_linux_dirent64 *de; + int wr; + + de = (struct lkl_linux_dirent64 *)buf; + ret = lkl_sys_getdents64(dir_fd, de, sizeof(buf)); + + wr = lkl_test_logf("%d ", dir_fd); + + if (ret < 0) + return TEST_FAILURE; + + for (pos = buf; pos - buf < ret; pos += de->d_reclen) { + de = (struct lkl_linux_dirent64 *)pos; + + wr += lkl_test_logf("%s ", de->d_name); + if (wr >= COL_LINE_BREAK) { + lkl_test_logf("\n"); + wr = 0; + } + } + + return TEST_SUCCESS; +} + +LKL_TEST_CALL(close_dir_fd, lkl_sys_close, 0, dir_fd); +LKL_TEST_CALL(chdir_root, lkl_sys_chdir, 0, "/"); +LKL_TEST_CALL(mount_fs_proc, lkl_sys_mount, 0, "none", "/proc", "proc", 0, + NULL); +LKL_TEST_CALL(umount_fs_proc, lkl_sys_umount, 0, "/proc", 0); + +LKL_TEST_CALL(start_kernel, lkl_start_kernel, 0, &lkl_host_ops, + "mem=16M loglevel=8"); +LKL_TEST_CALL(stop_kernel, lkl_sys_halt, 0); + +struct lkl_test tests[] = { + LKL_TEST(start_kernel), + LKL_TEST(getpid), + LKL_TEST(syscall_latency), + LKL_TEST(umask), + LKL_TEST(umask2), + LKL_TEST(creat), + LKL_TEST(close), + LKL_TEST(failopen), + LKL_TEST(open), + LKL_TEST(write), + LKL_TEST(lseek_cur), + LKL_TEST(lseek_end), + LKL_TEST(lseek_set), + LKL_TEST(read), + LKL_TEST(fstat), + LKL_TEST(mkdir), + LKL_TEST(stat), +#ifndef __MINGW32__ + LKL_TEST(nanosleep), +#endif + LKL_TEST(pipe2), + LKL_TEST(epoll), + LKL_TEST(mount_fs_proc), + LKL_TEST(chdir_proc), + LKL_TEST(open_cwd), + LKL_TEST(getdents64), + LKL_TEST(close_dir_fd), + LKL_TEST(chdir_root), + LKL_TEST(umount_fs_proc), + LKL_TEST(stop_kernel), +}; + +int main(int argc, const char **argv) +{ + lkl_host_ops.print = lkl_test_log; + + return lkl_test_run(tests, sizeof(tests)/sizeof(struct lkl_test), + "boot"); +} diff --git a/tools/um/tests/boot.sh b/tools/um/tests/boot.sh new file mode 100755 index 000000000000..d985c04b0ac1 --- /dev/null +++ b/tools/um/tests/boot.sh @@ -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 diff --git a/tools/um/tests/run.py b/tools/um/tests/run.py new file mode 100755 index 000000000000..c96ede90b6ad --- /dev/null +++ b/tools/um/tests/run.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: GPL-2.0 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License +# +# Author: Octavian Purdila +# + +from __future__ import print_function + +import argparse +import os +import subprocess +import sys +import tap13 +import xml.etree.ElementTree as ET + +from junit_xml import TestSuite, TestCase + + +class Reporter(tap13.Reporter): + def start(self, obj): + if type(obj) is tap13.Test: + if obj.result == "*": + end='\r' + else: + end='\n' + print(" TEST %-8s %.50s" % + (obj.result, obj.description + " " + obj.comment), end=end) + + elif type(obj) is tap13.Suite: + if obj.tests_planned == 0: + status = "skip" + else: + status = "" + print(" SUITE %-8s %s" % (status, obj.name)) + + def end(self, obj): + if type(obj) is tap13.Test: + if obj.result != "ok": + try: + print(obj.yaml["log"], end='') + except: + None + + +mydir=os.path.dirname(os.path.realpath(__file__)) + +tests = [ + 'boot.sh', +] + +parser = argparse.ArgumentParser(description='LKL test runner') +parser.add_argument('tests', nargs='?', action='append', + help='tests to run %s' % tests) +parser.add_argument('--junit-dir', + help='directory where to store the juni suites') +parser.add_argument('--gdb', action='store_true', default=False, + help='run simple tests under gdb; implies --pass-through') +parser.add_argument('--pass-through', action='store_true', default=False, + help='run the test without interpeting the test output') +parser.add_argument('--valgrind', action='store_true', default=False, + help='run simple tests under valgrind') + +args = parser.parse_args() +if args.tests == [None]: + args.tests = tests + +if args.gdb: + args.pass_through=True + os.environ['GDB']="yes" + +if args.valgrind: + os.environ['VALGRIND']="yes" + +tap = tap13.Parser(Reporter()) + +os.environ['PATH'] += ":" + mydir + +exit_code = 0 + +for t in args.tests: + if not t: + continue + if args.pass_through: + print(t) + if subprocess.call(t, shell=True) != 0: + exit_code = 1 + else: + p = subprocess.Popen(t, shell=True, stdout=subprocess.PIPE) + tap.parse(p.stdout) + +if args.pass_through: + sys.exit(exit_code) + +suites_count = 0 +tests_total = 0 +tests_not_ok = 0 +tests_ok = 0 +tests_skip = 0 +val_errs = 0 +val_fails = 0 +val_skips = 0 + +for s in tap.run.suites: + + junit_tests = [] + suites_count += 1 + + for t in s.tests: + try: + secs = t.yaml["time_us"] / 1000000.0 + except: + secs = 0 + try: + log = t.yaml['log'] + except: + log = "" + + jt = TestCase(t.description, elapsed_sec=secs, stdout=log) + if t.result == 'skip': + jt.add_skipped_info(output=log) + elif t.result == 'not ok': + jt.add_error_info(output=log) + + junit_tests.append(jt) + + tests_total += 1 + if t.result == "ok": + tests_ok += 1 + elif t.result == "not ok": + tests_not_ok += 1 + exit_code = 1 + elif t.result == "skip": + tests_skip += 1 + + if args.junit_dir: + js = TestSuite(s.name, junit_tests) + with open(os.path.join(args.junit_dir, os.path.basename(s.name) + '.xml'), 'w') as f: + js.to_file(f, [js]) + + if os.getenv('VALGRIND') is not None: + val_xml = 'valgrind-%s.xml' % os.path.basename(s.name).replace(' ','-') + # skipped tests don't generate xml file + if os.path.exists(val_xml) is False: + continue + + cmd = 'mv %s %s' % (val_xml, args.junit_dir) + subprocess.call(cmd, shell=True, ) + + cmd = mydir + '/valgrind2xunit.py ' + val_xml + subprocess.call(cmd, shell=True, cwd=args.junit_dir) + + # count valgrind results + doc = ET.parse(os.path.join(args.junit_dir, 'valgrind-%s_xunit.xml' \ + % (os.path.basename(s.name).replace(' ','-')))) + ts = doc.getroot() + val_errs += int(ts.get('errors')) + val_fails += int(ts.get('failures')) + val_skips += int(ts.get('skip')) + +print("Summary: %d suites run, %d tests, %d ok, %d not ok, %d skipped" % + (suites_count, tests_total, tests_ok, tests_not_ok, tests_skip)) + +if os.getenv('VALGRIND') is not None: + print(" valgrind (memcheck): %d failures, %d skipped" % (val_fails, val_skips)) + if val_errs or val_fails: + exit_code = 1 + +sys.exit(exit_code) diff --git a/tools/um/tests/tap13.py b/tools/um/tests/tap13.py new file mode 100644 index 000000000000..65c73cda7ca1 --- /dev/null +++ b/tools/um/tests/tap13.py @@ -0,0 +1,209 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: GPL-2.0 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License +# +# Author: Octavian Purdila +# +# Based on TAP13: +# +# Copyright 2013, Red Hat, Inc. +# Author: Josef Skladanka +# +from __future__ import print_function + +import re +import sys +import yamlish + + +class Reporter(object): + + def start(self, obj): + None + + def end(self, obj): + None + + +class Test(object): + def __init__(self, reporter, result, id, description=None, directive=None, + comment=None): + self.reporter = reporter + self.result = result + if directive: + self.result = directive.lower() + if id: + self.id = int(id) + else: + self.id = None + if description: + self.description = description + else: + self.description = "" + if comment: + self.comment = "# " + comment + else: + self.comment = "" + self.yaml = None + self._yaml_buffer = None + self.diagnostics = [] + + self.reporter.start(self) + + def end(self): + if not self.yaml: + self.yaml = yamlish.load(self._yaml_buffer) + self.reporter.end(self) + + +class Suite(object): + def __init__(self, reporter, start, end, explanation): + self.reporter = reporter + self.tests = [] + self.name = explanation + self.tests_planned = int(end) + + self.__tests_counter = 0 + self.__tests_base = 0 + + self.reporter.start(self) + + def newTest(self, args): + try: + self.tests[-1].end() + except IndexError: + None + + if 'id' not in args or not args['id']: + args['id'] = self.__tests_counter + else: + args['id'] = int(args['id']) + self.__tests_base + + if args['id'] < self.__tests_counter: + print("error: bad test id %d, fixing it" % (args['id'])) + args['id'] = self.__tests_counter + # according to TAP13 specs, missing tests must be handled as 'not ok' + # here we add the missing tests in sequence + while args['id'] > (self.__tests_counter + 1): + comment = 'test %d not present' % self.__tests_counter + self.tests.append(Test(self.reporter, 'not ok', + self.__tests_counter, comment=comment)) + self.__tests_counter += 1 + + if args['id'] == self.__tests_counter: + if args['directive']: + self.test().result = args['directive'].lower() + else: + self.test().result = args['result'] + self.reporter.start(self.test()) + else: + self.tests.append(Test(self.reporter, **args)) + self.__tests_counter += 1 + + def test(self): + return self.tests[-1] + + def end(self, name, planned): + if name == self.name: + self.tests_planned += int(planned) + self.__tests_base = self.__tests_counter + return False + try: + self.test().end() + except IndexError: + None + if len(self.tests) != self.tests_planned: + for i in range(len(self.tests), self.tests_planned): + self.tests.append(Test(self.reporter, 'not ok', i+1, + comment='test not present')) + return True + + +class Run(object): + + def __init__(self, reporter): + self.reporter = reporter + self.suites = [] + + def suite(self): + return self.suites[-1] + + def test(self): + return self.suites[-1].tests[-1] + + def newSuite(self, args): + new = False + try: + if self.suite().end(args['explanation'], args['end']): + new = True + except IndexError: + new = True + if new: + self.suites.append(Suite(self.reporter, **args)) + + def newTest(self, args): + self.suite().newTest(args) + + +class Parser(object): + RE_PLAN = re.compile(r"^\s*(?P\d+)\.\.(?P\d+)\s*(#\s*(?P.*))?\s*$") + RE_TEST_LINE = re.compile(r"^\s*(?P(not\s+)?ok|[*]+)\s*(?P\d+)?\s*(?P[^#]+)?\s*(#\s*(?PTODO|SKIP)?\s*(?P.+)?)?\s*$", re.IGNORECASE) + RE_EXPLANATION = re.compile(r"^\s*#\s*(?P.+)?\s*$") + RE_YAMLISH_START = re.compile(r"^\s*---.*$") + RE_YAMLISH_END = re.compile(r"^\s*\.\.\.\s*$") + + def __init__(self, reporter): + self.seek_test = False + self.in_test = False + self.in_yaml = False + self.run = Run(reporter) + + def parse(self, source): + # to avoid input buffering + while True: + line = source.readline() + if not line: + break + + if self.in_yaml: + if Parser.RE_YAMLISH_END.match(line): + self.run.test()._yaml_buffer.append(line.strip()) + self.in_yaml = False + else: + self.run.test()._yaml_buffer.append(line.rstrip()) + continue + + line = line.strip() + + if self.in_test: + if Parser.RE_EXPLANATION.match(line): + self.run.test().diagnostics.append(line) + continue + if Parser.RE_YAMLISH_START.match(line): + self.run.test()._yaml_buffer = [line.strip()] + self.in_yaml = True + continue + + m = Parser.RE_PLAN.match(line) + if m: + self.seek_test = True + args = m.groupdict() + self.run.newSuite(args) + continue + + if self.seek_test: + m = Parser.RE_TEST_LINE.match(line) + if m: + args = m.groupdict() + self.run.newTest(args) + self.in_test = True + continue + + print(line) + try: + self.run.suite().end(None, 0) + except IndexError: + None diff --git a/tools/um/tests/test.c b/tools/um/tests/test.c new file mode 100644 index 000000000000..37ea21901f99 --- /dev/null +++ b/tools/um/tests/test.c @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include + +#include "test.h" + +/* circular log buffer */ + +static char log_buf[0x10000]; +static char *head = log_buf, *tail = log_buf; + +static inline void advance(char **ptr) +{ + if ((unsigned int)(*ptr - log_buf) >= sizeof(log_buf)) + *ptr = log_buf; + else + *ptr = *ptr + 1; +} + +static void log_char(char c) +{ + *tail = c; + advance(&tail); + if (tail == head) + advance(&head); +} + +static void print_log(void) +{ + char last; + + printf(" log: |\n"); + last = '\n'; + while (head != tail) { + if (last == '\n') + printf(" "); + last = *head; + putchar(last); + advance(&head); + } + if (last != '\n') + putchar('\n'); +} + +int lkl_test_run(const struct lkl_test *tests, int nr, const char *fmt, ...) +{ + int i, ret, status = TEST_SUCCESS; + clock_t start, stop; + char name[1024]; + va_list args; + + va_start(args, fmt); + vsnprintf(name, sizeof(name), fmt, args); + va_end(args); + + printf("1..%d # %s\n", nr, name); + for (i = 1; i <= nr; i++) { + const struct lkl_test *t = &tests[i-1]; + unsigned long delta_us; + + printf("* %d %s\n", i, t->name); + fflush(stdout); + + start = clock(); + + ret = t->fn(t->arg1, t->arg2, t->arg3); + + stop = clock(); + + switch (ret) { + case TEST_SUCCESS: + printf("ok %d %s\n", i, t->name); + break; + case TEST_SKIP: + printf("ok %d %s # SKIP\n", i, t->name); + break; + case TEST_BAILOUT: + status = TEST_BAILOUT; + /* fall through; */ + case TEST_FAILURE: + default: + if (status != TEST_BAILOUT) + status = TEST_FAILURE; + printf("not ok %d %s\n", i, t->name); + } + + printf(" ---\n"); + delta_us = (stop - start) * 1000000 / CLOCKS_PER_SEC; + printf(" time_us: %ld\n", delta_us); + print_log(); + printf(" ...\n"); + + if (status == TEST_BAILOUT) { + printf("Bail out!\n"); + return TEST_FAILURE; + } + + fflush(stdout); + } + + return status; +} + + +void lkl_test_log(const char *str, int len) +{ + while (len--) + log_char(*(str++)); +} + +int lkl_test_logf(const char *fmt, ...) +{ + char tmp[1024], *c; + va_list args; + unsigned int n; + + va_start(args, fmt); + n = vsnprintf(tmp, sizeof(tmp), fmt, args); + va_end(args); + + for (c = tmp; *c != 0; c++) + log_char(*c); + + return n > sizeof(tmp) ? sizeof(tmp) : n; +} diff --git a/tools/um/tests/test.h b/tools/um/tests/test.h new file mode 100644 index 000000000000..f63ad6d419cb --- /dev/null +++ b/tools/um/tests/test.h @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LKL_TEST_H +#define _LKL_TEST_H + +#define TEST_SUCCESS 0 +#define TEST_FAILURE 1 +#define TEST_SKIP 2 +#define TEST_TODO 3 +#define TEST_BAILOUT 4 + +struct lkl_test { + const char *name; + int (*fn)(); + void *arg1, *arg2, *arg3; +}; + +/** + * Simple wrapper to initialize a test entry. + * @name - test name, it assume test function is named test_@name + * @vargs - arguments to be passed to the function + */ +#define LKL_TEST(name, ...) { #name, lkl_test_##name, __VA_ARGS__ } + +/** + * lkl_test_run - run a test suite + * + * @tests - the list of tests to run + * @nr - number of tests + * @fmt - format string to be used for suite name + */ +int lkl_test_run(const struct lkl_test *tests, int nr, const char *fmt, ...); + +/** + * lkl_test_log - store a string in the test log buffer + * @str - the string to log (can be non-NULL terminated) + * @len - the string length + */ +void lkl_test_log(const char *str, int len); + +/** + * lkl_test_logf - printf like function to store into the test log buffer + * @fmt - printf format string + * @vargs - arguments to the format string + */ +int lkl_test_logf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); + +/** + * LKL_TEST_CALL - create a test function as for a LKL call + * + * The test function will be named lkl_test_@name and will return + * TEST_SUCCESS if the called functions returns @expect. Otherwise + * will return TEST_FAILUIRE. + * + * @name - test name; must be unique because it is part of the the + * test function; the test function will be named + * @call - function to call + * @expect - expected return value for success + * @args - arguments to pass to the LKL call + */ +#define LKL_TEST_CALL(name, call, expect, ...) \ + static int lkl_test_##name(void) \ + { \ + long ret; \ + \ + ret = call(__VA_ARGS__); \ + lkl_test_logf("%s(%s) = %ld %s\n", #call, #__VA_ARGS__, \ + ret, ret < 0 ? lkl_strerror(ret) : ""); \ + return (ret == expect) ? TEST_SUCCESS : TEST_FAILURE; \ + } + + +#endif /* _LKL_TEST_H */ diff --git a/tools/um/tests/test.sh b/tools/um/tests/test.sh new file mode 100644 index 000000000000..31b7de5c06f7 --- /dev/null +++ b/tools/um/tests/test.sh @@ -0,0 +1,181 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +script_dir=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd) +basedir=$(cd $script_dir/..; pwd) +base_objdir=$(cd ${OUTPUT}/; pwd) + +TEST_SUCCESS=0 +TEST_FAILURE=1 +TEST_SKIP=113 +TEST_TODO=114 +TEST_BAILOUT=115 + +print_log() +{ + echo " log: |" + while read line; do + echo " $line" + done < $1 +} + +export_vars() +{ + if [ -z "$var_file" ]; then + return + fi + + for i in $@; do + echo "$i=${!i}" >> $var_file + done +} + +lkl_test_run() +{ + log_file=$(mktemp) + export var_file=$(mktemp) + + tid=$1 && shift && tname=$@ + + echo "* $tid $tname" + + start=$(date '+%s%9N') + # run in a separate shell to avoid -e terminating us + $@ 2>&1 | strings >$log_file + exit=${PIPESTATUS[0]} + stop=$(date '+%s%9N') + + case $exit in + $TEST_SUCCESS) + echo "ok $tid $tname" + ;; + $TEST_SKIP) + echo "ok $tid $tname # SKIP" + ;; + $TEST_BAILOUT) + echo "not ok $tid $tname" + echo "Bail out!" + ;; + $TEST_FAILURE|*) + echo "not ok $tid $tname" + ;; + esac + + delta=$(((stop-start)/1000)) + + echo " ---" + echo " time_us: $delta" + print_log $log_file + echo -e " ..." + + rm $log_file + . $var_file + rm $var_file + + return $exit +} + +lkl_test_plan() +{ + echo "1..$1 # $2" + export suite_name="${2// /\-}" +} + +lkl_test_exec() +{ + local SUDO="" + local WRAPPER="" + + if [ "$1" = "sudo" ]; then + SUDO=sudo + shift + fi + + local file=$1 + shift + + if [ -n "$LKL_HOST_CONFIG_NT" ]; then + file=$file.exe + fi + + file=${OUTPUT}/tests/$(basename $file) + + if file $file | grep ARM; then + WRAPPER="qemu-arm-static" + elif file $file | grep "FreeBSD" ; then + ssh_copy "$file" $BSD_WDIR + if [ -n "$SUDO" ]; then + SUDO="" + fi + WRAPPER="$MYSSH $SU" + # ssh will mess up with pipes ('|') so, escape the pipe char. + args="${@//\|/\\\|}" + set - $BSD_WDIR/$(basename $file) $args + file="" + elif [ -n "$GDB" ]; then + WRAPPER="gdb" + args="$@" + set - -ex "run $args" -ex quit $file + file="" + elif [ -n "$VALGRIND" ]; then + WRAPPER="valgrind --suppressions=$script_dir/valgrind.supp \ + --leak-check=full --show-leak-kinds=all --xml=yes \ + --xml-file=valgrind-$suite_name.xml" + fi + + $SUDO $WRAPPER $file "$@" +} + +lkl_test_cmd() +{ + local WRAPPER="" + + if [ -z "$QUIET" ]; then + SHOPTS="-x" + fi + + if [ -n "$LKL_HOST_CONFIG_BSD" ]; then + WRAPPER="$MYSSH $SU" + fi + + echo "$@" | $WRAPPER sh $SHOPTS +} + +# XXX: $MYSSH and $MYSCP are defined in a circleci docker image. +# see the definitions in lkl/lkl-docker:circleci/freebsd11/Dockerfile +ssh_push() +{ + while [ -n "$1" ]; do + if [[ "$1" = *.sh ]]; then + type="script" + else + type="file" + fi + + dir=$(dirname $1) + $MYSSH mkdir -p $BSD_WDIR/$dir + + $MYSCP -P 7722 -r $basedir/$1 root@localhost:$BSD_WDIR/$dir + if [ "$type" = "script" ]; then + $MYSSH chmod a+x $BSD_WDIR/$1 + fi + + shift + done +} + +ssh_copy() +{ + $MYSCP -P 7722 -r $1 root@localhost:$2 +} + +lkl_test_bsd_cleanup() +{ + $MYSSH rm -rf $BSD_WDIR +} + +if [ -n "$LKL_HOST_CONFIG_BSD" ]; then + trap lkl_test_bsd_cleanup EXIT + export BSD_WDIR=/root/lkl + $MYSSH mkdir -p $BSD_WDIR +fi From patchwork Thu Sep 24 07:13:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370385 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=FQRFsBNv; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=nVfHjrNr; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmZ41yYSz9sTh for ; Thu, 24 Sep 2020 17:16:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3xfOUkGgP+4roSk1Ir2eUrfiv3/PjuxJq8qXIL7EJ/g=; b=FQRFsBNv0Aa1v5DJgXQlEH35k FpkABsnsulKyQqueyfxh9/vSgBO2jfHytN2Vhfz4NQXVKxtuTulEffIOtikSAiaxMiYkaEgwv5CMa 6Ct/+5vphIeLchzhTzasklGwI0EFV6bXdyXZB0+RDY6o3YYunxEH8yX6KYmYW7rv6rqB/H4dom4ST ruKylOndVd/2aL5fISyNJG4gWwiD18fvLyBMUc3j7Me0qHRE2yow7OmVSLMF7pSi+/uodcAsn+Yms b/DAahSExK9C2ShGLuGtMpQkZphyhLKaQsmDED+v73GF9PndJqVd2BnWqCAmXqT2oFUtTIbpLsthY MwWE7aZEA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLUf-0003xN-1V; Thu, 24 Sep 2020 07:16:41 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLUX-0003u8-Fq for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:16:38 +0000 Received: by mail-pl1-x641.google.com with SMTP id u4so1203840plr.4 for ; Thu, 24 Sep 2020 00:16:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jFiwvxSxFVjh+fcWhICN8jVHXShLs8UY/LxMMYu6LmY=; b=nVfHjrNrsFSfuE3cNyDVU7o3I0p5peYgJ/wiVki8+rtu8o3Ct0Aw+1G1RBkWM45x2B +VhLL1ikba+IIwYD/LTppu5gWrYIL/t05KYHCJ0LLwbrZ8CIzNMvZYN5BaZUxWzAilU9 XUzk/BpgXrpCQhpo1n0UmzLispyqgpxwg3MU3NP6JSrKCjexTkbeD/x7nyRf4G5J0bc2 /1R5sAryD4iMPblBhbsUMXVdXiUKqtkK/3j96OtvHwg2aF2cXlhhOiBuj/fmNYGTpsDw 6kg4/CCkSRM+ByFDCR98MGvkP7jx4e7PBQ/AeeQSdg9deoM+Z3ji+JGTB3y7CFDOs3Ky EWkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jFiwvxSxFVjh+fcWhICN8jVHXShLs8UY/LxMMYu6LmY=; b=oNKWQVhdjJ6McPZ1EUbD6QxvchxPcKy6CrQBdx+Dw+gPeSTV4iMIX6NVcUx6vI+aSe Yzp/wRUPhGtZlVmno4p4SFK8K61JvFMpVf48xMOFBIaY1tmgse16WmTqLXPpgoaz2TF5 QglggTrmaqBRV0p07HXAc2BCUq2QPrCJyHS+cC1cvJ4Ll7thYh6W76TrmuagTAnlZnNz IYW3Z/PfJTqLbyMfp5XRk1WbLXTwRTKS7iuHwDT6cDJKXi/Zlt0lrzyWZZMPCR21gip4 v8CO0gVXZi0lEyb1BxZ6ueCd9qJRgdjRXtPkDwyn9yP2wf+DCGrv+gDsrTGfhrJ47uMn bgjg== X-Gm-Message-State: AOAM532cCi0H4dCWJv1as9E5/xogh94KwzZ+LOesareSpqTCWyUvWP2Y xIxSTbZRo0d/yk2DjnnvGrb7NUKCmQoUIA== X-Google-Smtp-Source: ABdhPJwPv2m9Wa7oTCkqn8SMmQN5J+DKkjRF+wKVG1mofRrG1i/HLVaOBjO7T3klAUAbM2t7C/PC7w== X-Received: by 2002:a17:90a:5894:: with SMTP id j20mr2789882pji.109.1600931791396; Thu, 24 Sep 2020 00:16:31 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id bj2sm1369846pjb.20.2020.09.24.00.16.30 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:16:30 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id E00AF2037C210A; Thu, 24 Sep 2020 16:16:28 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 21/21] um: nommu: add block device support of UML Date: Thu, 24 Sep 2020 16:13:01 +0900 Message-Id: X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031633_901203_310BAD25 X-CRM114-Status: GOOD ( 32.47 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:641 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This commit adds block device support for nommu mode, and also added several host utilities to run a simple test program (tools/um/test/disk.c) successfully. Signed-off-by: Hajime Tazaki --- 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 diff --git a/arch/um/include/asm/xor.h b/arch/um/include/asm/xor.h index 36b33d62a35d..a5ea458a1ae9 100644 --- a/arch/um/include/asm/xor.h +++ b/arch/um/include/asm/xor.h @@ -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) diff --git a/arch/um/include/shared/as-layout.h b/arch/um/include/shared/as-layout.h index 5f286ef2721b..4423437a5ace 100644 --- a/arch/um/include/shared/as-layout.h +++ b/arch/um/include/shared/as-layout.h @@ -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 *); diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c index e2cb76c03b25..da6e06cf2808 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c @@ -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 diff --git a/arch/um/nommu/include/uapi/asm/host_ops.h b/arch/um/nommu/include/uapi/asm/host_ops.h index 0811494c080c..1b2507502969 100644 --- a/arch/um/nommu/include/uapi/asm/host_ops.h +++ b/arch/um/nommu/include/uapi/asm/host_ops.h @@ -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); diff --git a/arch/um/nommu/include/uapi/asm/unistd.h b/arch/um/nommu/include/uapi/asm/unistd.h index 1762ebb829f5..320762099a62 100644 --- a/arch/um/nommu/include/uapi/asm/unistd.h +++ b/arch/um/nommu/include/uapi/asm/unistd.h @@ -3,6 +3,8 @@ #define __UM_NOMMU_UAPI_UNISTD_H #define __ARCH_WANT_NEW_STAT +#define __ARCH_WANT_SET_GET_RLIMIT + #include #if __BITS_PER_LONG == 64 diff --git a/arch/um/nommu/um/Kconfig b/arch/um/nommu/um/Kconfig index 20b3eaccb6f0..c6a3f472fe75 100644 --- a/arch/um/nommu/um/Kconfig +++ b/arch/um/nommu/um/Kconfig @@ -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 diff --git a/arch/um/nommu/um/setup.c b/arch/um/nommu/um/setup.c index 922188690139..d71d61979ad6 100644 --- a/arch/um/nommu/um/setup.c +++ b/arch/um/nommu/um/setup.c @@ -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; diff --git a/tools/um/Targets b/tools/um/Targets index 2bb90381843c..f5f8ec4b9dbb 100644 --- a/tools/um/Targets +++ b/tools/um/Targets @@ -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 diff --git a/tools/um/include/lkl.h b/tools/um/include/lkl.h index 707e01b64a70..4a9d874bfbf0 100644 --- a/tools/um/include/lkl.h +++ b/tools/um/include/lkl.h @@ -113,6 +113,16 @@ static inline long lkl_sys_creat(const char *file, int mode) } #endif +#ifdef __lkl__NR_faccessat +/** + * lkl_sys_access - wrapper for lkl_sys_faccessat + */ +static inline long lkl_sys_access(const char *file, int mode) +{ + return lkl_sys_faccessat(LKL_AT_FDCWD, file, mode); +} +#endif + #ifdef __lkl__NR_mkdirat /** * lkl_sys_mkdir - wrapper for lkl_sys_mkdirat @@ -123,6 +133,36 @@ static inline long lkl_sys_mkdir(const char *path, mode_t mode) } #endif +#ifdef __lkl__NR_unlinkat +/** + * lkl_sys_rmdir - wrapper for lkl_sys_unlinkrat + */ +static inline long lkl_sys_rmdir(const char *path) +{ + return lkl_sys_unlinkat(LKL_AT_FDCWD, path, LKL_AT_REMOVEDIR); +} +#endif + +#ifdef __lkl__NR_unlinkat +/** + * lkl_sys_unlink - wrapper for lkl_sys_unlinkat + */ +static inline long lkl_sys_unlink(const char *path) +{ + return lkl_sys_unlinkat(LKL_AT_FDCWD, path, 0); +} +#endif + +#ifdef __lkl__NR_mknodat +/** + * lkl_sys_mknod - wrapper for lkl_sys_mknodat + */ +static inline long lkl_sys_mknod(const char *path, mode_t mode, dev_t dev) +{ + return lkl_sys_mknodat(LKL_AT_FDCWD, path, mode, dev); +} +#endif + #ifdef __lkl__NR_epoll_create1 /** * lkl_sys_epoll_create - wrapper for lkl_sys_epoll_create1 @@ -144,6 +184,172 @@ static inline long lkl_sys_epoll_wait(int fd, struct lkl_epoll_event *ev, } #endif +/** + * struct lkl_dev_blk_ops - block device host operations, defined in lkl_host.h. + */ +struct lkl_dev_blk_ops; + +/** + * lkl_disk - host disk handle + * + * @dev - a pointer to private information for this disk backend + * @fd - a POSIX file descriptor that can be used by preadv/pwritev + * @handle - an NT file handle that can be used by ReadFile/WriteFile + */ +struct lkl_disk { + void *dev; + union { + int fd; + void *handle; + }; + struct lkl_dev_blk_ops *ops; +}; + +/** + * lkl_disk_add - add a new disk + * + * @disk - the host disk handle + * @returns a disk id (0 is valid) or a strictly negative value in case of error + */ +int lkl_disk_add(struct lkl_disk *disk); + +/** + * lkl_disk_remove - remove a disk + * + * This function makes a cleanup of the @disk's private information + * that was initialized by lkl_disk_add before. + * + * @disk - the host disk handle + */ +int lkl_disk_remove(struct lkl_disk disk); + +/** + * lkl_encode_dev_from_sysfs_blkdev - extract device id from sysfs + * + * This function returns the device id for the given sysfs dev node. + * The content of the node has to be in the form 'MAJOR:MINOR'. + * Also, this function expects an absolute path which means that sysfs + * already has to be mounted at the given path + * + * @sysfs_path - absolute path to the sysfs dev node + * @pdevid - pointer to memory where dev id will be returned + * @returns - 0 on success, a negative value on error + */ +int lkl_encode_dev_from_sysfs(const char *sysfs_path, uint32_t *pdevid); + +/** + * lkl_mount_dev - mount a disk + * + * This functions creates a device file for the given disk, creates a mount + * point and mounts the device over the mount point. + * + * @disk_id - the disk id identifying the disk to be mounted + * @part - disk partition or zero for full disk + * @fs_type - filesystem type + * @flags - mount flags + * @opts - additional filesystem specific mount options + * @mnt_str - a string that will be filled by this function with the path where + * the filesystem has been mounted + * @mnt_str_len - size of mnt_str + * @returns - 0 on success, a negative value on error + */ +long lkl_mount_dev(unsigned int disk_id, unsigned int part, const char *fs_type, + int flags, const char *opts, + char *mnt_str, unsigned int mnt_str_len); + +/** + * lkl_umount_dev - umount a disk + * + * This functions umounts the given disks and removes the device file and the + * mount point. + * + * @disk_id - the disk id identifying the disk to be mounted + * @part - disk partition or zero for full disk + * @flags - umount flags + * @timeout_ms - timeout to wait for the kernel to flush closed files so that + * umount can succeed + * @returns - 0 on success, a negative value on error + */ +long lkl_umount_dev(unsigned int disk_id, unsigned int part, int flags, + long timeout_ms); + +/** + * lkl_umount_timeout - umount filesystem with timeout + * + * @path - the path to unmount + * @flags - umount flags + * @timeout_ms - timeout to wait for the kernel to flush closed files so that + * umount can succeed + * @returns - 0 on success, a negative value on error + */ +long lkl_umount_timeout(char *path, int flags, long timeout_ms); + +/** + * lkl_opendir - open a directory + * + * @path - directory path + * @err - pointer to store the error in case of failure + * @returns - a handle to be used when calling lkl_readdir + */ +struct lkl_dir *lkl_opendir(const char *path, int *err); + +/** + * lkl_fdopendir - open a directory + * + * @fd - file descriptor + * @err - pointer to store the error in case of failure + * @returns - a handle to be used when calling lkl_readdir + */ +struct lkl_dir *lkl_fdopendir(int fd, int *err); + +/** + * lkl_rewinddir - reset directory stream + * + * @dir - the directory handler as returned by lkl_opendir + */ +void lkl_rewinddir(struct lkl_dir *dir); + +/** + * lkl_closedir - close the directory + * + * @dir - the directory handler as returned by lkl_opendir + */ +int lkl_closedir(struct lkl_dir *dir); + +/** + * lkl_readdir - get the next available entry of the directory + * + * @dir - the directory handler as returned by lkl_opendir + * @returns - a lkl_dirent64 entry or NULL if the end of the directory stream is + * reached or if an error occurred; check lkl_errdir() to distinguish between + * errors or end of the directory stream + */ +struct lkl_linux_dirent64 *lkl_readdir(struct lkl_dir *dir); + +/** + * lkl_errdir - checks if an error occurred during the last lkl_readdir call + * + * @dir - the directory handler as returned by lkl_opendir + * @returns - 0 if no error occurred, or a negative value otherwise + */ +int lkl_errdir(struct lkl_dir *dir); + +/** + * lkl_dirfd - gets the file descriptor associated with the directory handle + * + * @dir - the directory handle as returned by lkl_opendir + * @returns - a positive value,which is the LKL file descriptor associated with + * the directory handle, or a negative value otherwise + */ +int lkl_dirfd(struct lkl_dir *dir); + +/** + * lkl_mount_fs - mount a file system type like proc, sys + * @fstype - file system type. e.g. proc, sys + * @returns - 0 on success. 1 if it's already mounted. negative on failure. + */ +int lkl_mount_fs(char *fstype); + #ifdef __cplusplus } #endif diff --git a/tools/um/include/lkl_host.h b/tools/um/include/lkl_host.h index 85e80eb4ad0d..12dd95616e43 100644 --- a/tools/um/include/lkl_host.h +++ b/tools/um/include/lkl_host.h @@ -10,6 +10,7 @@ extern "C" { #include extern struct lkl_host_operations lkl_host_ops; +extern char lkl_um_devs[4096]; /** * lkl_printf - print a message via the host print operation diff --git a/tools/um/lib/Build b/tools/um/lib/Build index dddff26a3b4e..29491b40746c 100644 --- a/tools/um/lib/Build +++ b/tools/um/lib/Build @@ -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 diff --git a/tools/um/lib/fs.c b/tools/um/lib/fs.c new file mode 100644 index 000000000000..948aac9730c2 --- /dev/null +++ b/tools/um/lib/fs.c @@ -0,0 +1,461 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include + +#define MAX_FSTYPE_LEN 50 + +static struct lkl_disk *lkl_disks[16]; +static int registered_blk_dev_idx; + +static int lkl_disk_um_add(struct lkl_disk *disk, const char *blkparams) +{ + /* concat strings */ + snprintf(lkl_um_devs + strlen(lkl_um_devs), sizeof(lkl_um_devs), + " ubd%d=%s", registered_blk_dev_idx, blkparams); + + return registered_blk_dev_idx++; +} + +int lkl_disk_add(struct lkl_disk *disk) +{ + int ret = -1; + + ret = lkl_disk_um_add(disk, disk->dev); + + lkl_disks[ret] = disk; + + return ret; +} + +int lkl_disk_remove(struct lkl_disk disk) +{ + /* FIXME */ + return 0; +} + +int lkl_mount_fs(char *fstype) +{ + char dir[MAX_FSTYPE_LEN+2] = "/"; + int flags = 0, ret = 0; + + strncat(dir, fstype, MAX_FSTYPE_LEN); + + /* Create with regular umask */ + ret = lkl_sys_mkdir(dir, 0xff); + if (ret && ret != -LKL_EEXIST) { + lkl_perror("mount_fs mkdir", ret); + return ret; + } + + /* We have no use for nonzero flags right now */ + ret = lkl_sys_mount("none", dir, fstype, flags, NULL); + if (ret && ret != -LKL_EBUSY) { + lkl_sys_rmdir(dir); + return ret; + } + + if (ret == -LKL_EBUSY) + return 1; + return 0; +} + +static uint32_t new_encode_dev(unsigned int major, unsigned int minor) +{ + return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12); +} + +static int startswith(const char *str, const char *pre) +{ + return strncmp(pre, str, strlen(pre)) == 0; +} + +static int get_node_with_prefix(const char *path, const char *prefix, + char *result, unsigned int result_len) +{ + struct lkl_dir *dir = NULL; + struct lkl_linux_dirent64 *dirent; + int ret; + + dir = lkl_opendir(path, &ret); + if (!dir) + return ret; + + ret = -LKL_ENOENT; + + while ((dirent = lkl_readdir(dir))) { + if (startswith(dirent->d_name, prefix)) { + if (strlen(dirent->d_name) + 1 > result_len) { + ret = -LKL_ENOMEM; + break; + } + memcpy(result, dirent->d_name, strlen(dirent->d_name)); + result[strlen(dirent->d_name)] = '\0'; + ret = 0; + break; + } + } + + lkl_closedir(dir); + + return ret; +} + +int lkl_encode_dev_from_sysfs(const char *sysfs_path, uint32_t *pdevid) +{ + int ret; + long fd; + int major, minor; + char buf[16] = { 0, }; + char *bufptr; + + fd = lkl_sys_open(sysfs_path, LKL_O_RDONLY, 0); + if (fd < 0) + return fd; + + ret = lkl_sys_read(fd, buf, sizeof(buf)); + if (ret < 0) + goto out_close; + + if (ret == sizeof(buf)) { + ret = -LKL_ENOBUFS; + goto out_close; + } + + bufptr = strchr(buf, ':'); + if (bufptr == NULL) { + ret = -LKL_EINVAL; + goto out_close; + } + bufptr[0] = '\0'; + bufptr++; + + major = atoi(buf); + minor = atoi(bufptr); + + *pdevid = new_encode_dev(major, minor); + ret = 0; + +out_close: + lkl_sys_close(fd); + + return ret; +} + +#define SYSFS_DEV_UMBLK_CMDLINE_PATH \ + "/sysfs/devices/platform/uml-blkdev.%d" + +struct abuf { + char *mem, *ptr; + unsigned int len; +}; + +static int snprintf_append(struct abuf *buf, const char *fmt, ...) +{ + int ret; + va_list args; + + if (!buf->ptr) + buf->ptr = buf->mem; + + va_start(args, fmt); + ret = vsnprintf(buf->ptr, buf->len - (buf->ptr - buf->mem), fmt, args); + va_end(args); + + if (ret < 0 || (ret >= (int)(buf->len - (buf->ptr - buf->mem)))) + return -LKL_ENOMEM; + + buf->ptr += ret; + + return 0; +} + +static int __lkl_get_blkdev(int disk_id, unsigned int part, uint32_t *pdevid, + const char *sysfs_path_fmt, const char *drv_prefix, + const char *disk_prefix) +{ + char sysfs_path[LKL_PATH_MAX]; + char drv_name[LKL_PATH_MAX]; + char disk_name[LKL_PATH_MAX]; + struct abuf sysfs_path_buf = { + .mem = sysfs_path, + .len = sizeof(sysfs_path), + }; + int ret; + + if (disk_id < 0) + return -LKL_EINVAL; + + ret = lkl_mount_fs("sysfs"); + if (ret < 0) + return ret; + + ret = snprintf_append(&sysfs_path_buf, sysfs_path_fmt, disk_id); + if (ret) + return ret; + + ret = get_node_with_prefix(sysfs_path, drv_prefix, drv_name, + sizeof(drv_name)); + if (ret) + return ret; + + ret = snprintf_append(&sysfs_path_buf, "/%s/block", drv_name); + if (ret) + return ret; + + ret = get_node_with_prefix(sysfs_path, disk_prefix, disk_name, + sizeof(disk_name)); + if (ret) + return ret; + + if (!part) + ret = snprintf_append(&sysfs_path_buf, "/%s/dev", disk_name); + else + ret = snprintf_append(&sysfs_path_buf, "/%s/%s%d/dev", + disk_name, disk_name, part); + if (ret) + return ret; + + return lkl_encode_dev_from_sysfs(sysfs_path, pdevid); +} + +int lkl_get_blkdev(int disk_id, unsigned int part, uint32_t *pdevid) +{ + char *fmt; + + fmt = SYSFS_DEV_UMBLK_CMDLINE_PATH; + return __lkl_get_blkdev(disk_id, part, pdevid, fmt, "", "ubd"); +} + +long lkl_mount_dev(unsigned int disk_id, unsigned int part, + const char *fs_type, int flags, + const char *data, char *mnt_str, unsigned int mnt_str_len) +{ + char dev_str[] = { "/dev/xxxxxxxx" }; + unsigned int dev; + int err; + char _data[4096]; /* FIXME: PAGE_SIZE is not exported by LKL */ + + if (mnt_str_len < sizeof(dev_str)) + return -LKL_ENOMEM; + + err = lkl_get_blkdev(disk_id, part, &dev); + if (err < 0) + return err; + + snprintf(dev_str, sizeof(dev_str), "/dev/%08x", dev); + snprintf(mnt_str, mnt_str_len, "/mnt/%08x", dev); + + err = lkl_sys_access("/dev", LKL_S_IRWXO); + if (err < 0) { + if (err == -LKL_ENOENT) + err = lkl_sys_mkdir("/dev", 0700); + if (err < 0) + return err; + } + + err = lkl_sys_mknod(dev_str, LKL_S_IFBLK | 0600, dev); + if (err < 0) + return err; + + err = lkl_sys_access("/mnt", LKL_S_IRWXO); + if (err < 0) { + if (err == -LKL_ENOENT) + err = lkl_sys_mkdir("/mnt", 0700); + if (err < 0) + return err; + } + + err = lkl_sys_mkdir(mnt_str, 0700); + if (err < 0) { + lkl_sys_unlink(dev_str); + return err; + } + + /* kernel always copies a full page */ + if (data) { + strncpy(_data, data, sizeof(_data)); + _data[sizeof(_data) - 1] = 0; + } else { + _data[0] = 0; + } + + err = lkl_sys_mount(dev_str, mnt_str, (char *)fs_type, flags, _data); + if (err < 0) { + lkl_sys_unlink(dev_str); + lkl_sys_rmdir(mnt_str); + return err; + } + + return 0; +} + +long lkl_umount_timeout(char *path, int flags, long timeout_ms) +{ + long incr = 10000000; /* 10 ms */ + struct lkl_timespec ts = { + .tv_sec = 0, + .tv_nsec = incr, + }; + long err; + + do { + err = lkl_sys_umount(path, flags); + if (err == -LKL_EBUSY) { + lkl_sys_nanosleep((struct __lkl__kernel_timespec *)&ts, + NULL); + timeout_ms -= incr / 1000000; + } + } while (err == -LKL_EBUSY && timeout_ms > 0); + + return err; +} + +long lkl_umount_dev(unsigned int disk_id, unsigned int part, int flags, + long timeout_ms) +{ + char dev_str[] = { "/dev/xxxxxxxx" }; + char mnt_str[] = { "/mnt/xxxxxxxx" }; + unsigned int dev; + int err; + + err = lkl_get_blkdev(disk_id, part, &dev); + if (err < 0) + return err; + + snprintf(dev_str, sizeof(dev_str), "/dev/%08x", dev); + snprintf(mnt_str, sizeof(mnt_str), "/mnt/%08x", dev); + + err = lkl_umount_timeout(mnt_str, flags, timeout_ms); + if (err) + return err; + + err = lkl_sys_unlink(dev_str); + if (err) + return err; + + return lkl_sys_rmdir(mnt_str); +} + +struct lkl_dir { + int fd; + char buf[1024]; + char *pos; + int len; +}; + +static struct lkl_dir *lkl_dir_alloc(int *err) +{ + struct lkl_dir *dir = lkl_host_ops.mem_alloc(sizeof(struct lkl_dir)); + + if (!dir) { + *err = -LKL_ENOMEM; + return NULL; + } + + dir->len = 0; + dir->pos = NULL; + + return dir; +} + +struct lkl_dir *lkl_opendir(const char *path, int *err) +{ + struct lkl_dir *dir = lkl_dir_alloc(err); + + if (!dir) { + *err = -LKL_ENOMEM; + return NULL; + } + + dir->fd = lkl_sys_open(path, LKL_O_RDONLY | LKL_O_DIRECTORY, 0); + if (dir->fd < 0) { + *err = dir->fd; + lkl_host_ops.mem_free(dir); + return NULL; + } + + *err = 0; + + return dir; +} + +struct lkl_dir *lkl_fdopendir(int fd, int *err) +{ + struct lkl_dir *dir = lkl_dir_alloc(err); + + if (!dir) + return NULL; + + dir->fd = fd; + + return dir; +} + +void lkl_rewinddir(struct lkl_dir *dir) +{ + lkl_sys_lseek(dir->fd, 0, LKL_SEEK_SET); + dir->len = 0; + dir->pos = NULL; +} + +int lkl_closedir(struct lkl_dir *dir) +{ + int ret; + + ret = lkl_sys_close(dir->fd); + lkl_host_ops.mem_free(dir); + + return ret; +} + +struct lkl_linux_dirent64 *lkl_readdir(struct lkl_dir *dir) +{ + struct lkl_linux_dirent64 *de; + + if (dir->len < 0) + return NULL; + + if (!dir->pos || dir->pos - dir->buf >= dir->len) + goto read_buf; + +return_de: + de = (struct lkl_linux_dirent64 *)dir->pos; + dir->pos += de->d_reclen; + + return de; + +read_buf: + dir->pos = NULL; + de = (struct lkl_linux_dirent64 *)dir->buf; + dir->len = lkl_sys_getdents64(dir->fd, de, sizeof(dir->buf)); + if (dir->len <= 0) + return NULL; + + dir->pos = dir->buf; + goto return_de; +} + +int lkl_errdir(struct lkl_dir *dir) +{ + if (dir->len >= 0) + return 0; + + return dir->len; +} + +int lkl_dirfd(struct lkl_dir *dir) +{ + return dir->fd; +} + +int lkl_set_fd_limit(unsigned int fd_limit) +{ + struct lkl_rlimit rlim = { + .rlim_cur = fd_limit, + .rlim_max = fd_limit, + }; + return lkl_sys_setrlimit(LKL_RLIMIT_NOFILE, &rlim); +} diff --git a/tools/um/lib/posix-host.c b/tools/um/lib/posix-host.c index b6b5b2902254..8fd88031bf2b 100644 --- a/tools/um/lib/posix-host.c +++ b/tools/um/lib/posix-host.c @@ -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, diff --git a/tools/um/lib/utils.c b/tools/um/lib/utils.c index 4930479a8a35..ac65cd744a14 100644 --- a/tools/um/lib/utils.c +++ b/tools/um/lib/utils.c @@ -4,6 +4,9 @@ #include #include +/* XXX: find a better place */ +char lkl_um_devs[4096]; + static const char * const lkl_err_strings[] = { "Success", "Operation not permitted", diff --git a/tools/um/tests/Build b/tools/um/tests/Build index 26a607f90dc8..b62919cadc50 100644 --- a/tools/um/tests/Build +++ b/tools/um/tests/Build @@ -1 +1,2 @@ boot-y += boot.o test.o +disk-y += disk.o test.o cla.o diff --git a/tools/um/tests/cla.c b/tools/um/tests/cla.c new file mode 100644 index 000000000000..694e3a3822be --- /dev/null +++ b/tools/um/tests/cla.c @@ -0,0 +1,159 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#ifdef __MINGW32__ +#include +#else +#include +#include +#include +#endif + +#include "cla.h" + +static int cl_arg_parse_bool(struct cl_arg *arg, const char *value) +{ + *((int *)arg->store) = 1; + return 0; +} + +static int cl_arg_parse_str(struct cl_arg *arg, const char *value) +{ + *((const char **)arg->store) = value; + return 0; +} + +static int cl_arg_parse_int(struct cl_arg *arg, const char *value) +{ + errno = 0; + *((int *)arg->store) = strtol(value, NULL, 0); + return errno == 0; +} + +static int cl_arg_parse_str_set(struct cl_arg *arg, const char *value) +{ + const char **set = arg->set; + int i; + + for (i = 0; set[i] != NULL; i++) { + if (strcmp(set[i], value) == 0) { + *((int *)arg->store) = i; + return 0; + } + } + + return (-1); +} + +static int cl_arg_parse_ipv4(struct cl_arg *arg, const char *value) +{ + unsigned int addr; + + if (!value) + return (-1); + + addr = inet_addr(value); + if (addr == INADDR_NONE) + return (-1); + *((unsigned int *)arg->store) = addr; + return 0; +} + +static cl_arg_parser_t parsers[] = { + [CL_ARG_BOOL] = cl_arg_parse_bool, + [CL_ARG_INT] = cl_arg_parse_int, + [CL_ARG_STR] = cl_arg_parse_str, + [CL_ARG_STR_SET] = cl_arg_parse_str_set, + [CL_ARG_IPV4] = cl_arg_parse_ipv4, +}; + +static struct cl_arg *find_short_arg(char name, struct cl_arg *args) +{ + struct cl_arg *arg; + + for (arg = args; arg->short_name != 0; arg++) { + if (arg->short_name == name) + return arg; + } + + return NULL; +} + +static struct cl_arg *find_long_arg(const char *name, struct cl_arg *args) +{ + struct cl_arg *arg; + + for (arg = args; arg->long_name; arg++) { + if (strcmp(arg->long_name, name) == 0) + return arg; + } + + return NULL; +} + +static void print_help(struct cl_arg *args) +{ + struct cl_arg *arg; + + fprintf(stderr, "usage:\n"); + for (arg = args; arg->long_name; arg++) { + fprintf(stderr, "-%c, --%-20s %s", arg->short_name, + arg->long_name, arg->help); + if (arg->type == CL_ARG_STR_SET) { + const char **set = arg->set; + + fprintf(stderr, " [ "); + while (*set != NULL) + fprintf(stderr, "%s ", *(set++)); + fprintf(stderr, "]"); + } + fprintf(stderr, "\n"); + } +} + +int cla_parse_args(int argc, const char **argv, struct cl_arg *args) +{ + int i; + + for (i = 1; i < argc; i++) { + struct cl_arg *arg = NULL; + cl_arg_parser_t parser; + + if (argv[i][0] == '-') { + if (argv[i][1] != '-') + arg = find_short_arg(argv[i][1], args); + else + arg = find_long_arg(&argv[i][2], args); + } + + if (!arg) { + fprintf(stderr, "unknown option '%s'\n", argv[i]); + print_help(args); + return (-1); + } + + if (arg->type == CL_ARG_USER || arg->type >= CL_ARG_END) + parser = arg->parser; + else + parser = parsers[arg->type]; + + if (!parser) { + fprintf(stderr, "can't parse --'%s'/-'%c'\n", + arg->long_name, args->short_name); + return (-1); + } + + if (parser(arg, argv[i + 1]) < 0) { + fprintf(stderr, "can't parse '%s'\n", argv[i]); + print_help(args); + return (-1); + } + + if (arg->has_arg) + i++; + } + + return 0; +} diff --git a/tools/um/tests/cla.h b/tools/um/tests/cla.h new file mode 100644 index 000000000000..3d879233681f --- /dev/null +++ b/tools/um/tests/cla.h @@ -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 */ diff --git a/tools/um/tests/disk.c b/tools/um/tests/disk.c new file mode 100644 index 000000000000..325934935e6a --- /dev/null +++ b/tools/um/tests/disk.c @@ -0,0 +1,168 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "test.h" +#include "cla.h" + +static struct { + int printk; + const char *disk; + const char *fstype; + int partition; +} cla; + +struct cl_arg args[] = { + {"disk", 'd', "disk file to use", 1, CL_ARG_STR, &cla.disk}, + {"partition", 'P', "partition to mount", 1, CL_ARG_INT, &cla.partition}, + {"type", 't', "filesystem type", 1, CL_ARG_STR, &cla.fstype}, + {0}, +}; + + +static struct lkl_disk disk; +static int disk_id = -1; + +int lkl_test_disk_add(void) +{ + disk.fd = open(cla.disk, O_RDWR); + if (disk.fd < 0) + goto out_unlink; + + disk.ops = NULL; + disk.dev = (char *)cla.disk; + + disk_id = lkl_disk_add(&disk); + if (disk_id < 0) + goto out_close; + + goto out; + +out_close: + close(disk.fd); + +out_unlink: + unlink(cla.disk); + +out: + lkl_test_logf("disk fd/handle %x disk_id %d", disk.fd, disk_id); + + if (disk_id >= 0) + return TEST_SUCCESS; + + return TEST_FAILURE; +} + +int lkl_test_disk_remove(void) +{ + int ret; + + ret = lkl_disk_remove(disk); + + close(disk.fd); + + if (ret == 0) + return TEST_SUCCESS; + + return TEST_FAILURE; +} + + +static char mnt_point[32]; + +LKL_TEST_CALL(mount_dev, lkl_mount_dev, 0, disk_id, cla.partition, cla.fstype, + 0, NULL, mnt_point, sizeof(mnt_point)) + +static int lkl_test_umount_dev(void) +{ + long ret, ret2; + + ret = lkl_sys_chdir("/"); + + ret2 = lkl_umount_dev(disk_id, cla.partition, 0, 1000); + + lkl_test_logf("%ld %ld", ret, ret2); + + if (!ret && !ret2) + return TEST_SUCCESS; + + return TEST_FAILURE; +} + +struct lkl_dir *dir; + +static int lkl_test_opendir(void) +{ + int err; + + dir = lkl_opendir(mnt_point, &err); + + lkl_test_logf("lkl_opedir(%s) = %d %s\n", mnt_point, err, + lkl_strerror(err)); + + if (err == 0) + return TEST_SUCCESS; + + return TEST_FAILURE; +} + +static int lkl_test_readdir(void) +{ + struct lkl_linux_dirent64 *de = lkl_readdir(dir); + int wr = 0; + + while (de) { + wr += lkl_test_logf("%s ", de->d_name); + if (wr >= 70) { + lkl_test_logf("\n"); + wr = 0; + break; + } + de = lkl_readdir(dir); + } + + if (lkl_errdir(dir) == 0) + return TEST_SUCCESS; + + return TEST_FAILURE; +} + +LKL_TEST_CALL(closedir, lkl_closedir, 0, dir); +LKL_TEST_CALL(chdir_mnt_point, lkl_sys_chdir, 0, mnt_point); +LKL_TEST_CALL(start_kernel, lkl_start_kernel, 0, &lkl_host_ops, + "mem=16M loglevel=8"); +LKL_TEST_CALL(stop_kernel, lkl_sys_halt, 0); + +struct lkl_test tests[] = { + LKL_TEST(disk_add), + LKL_TEST(start_kernel), + LKL_TEST(mount_dev), + LKL_TEST(chdir_mnt_point), + LKL_TEST(opendir), + LKL_TEST(readdir), + LKL_TEST(closedir), + LKL_TEST(umount_dev), + LKL_TEST(stop_kernel), + LKL_TEST(disk_remove), + +}; + +int main(int argc, const char **argv) +{ + if (cla_parse_args(argc, argv, args) < 0) + return (-1); + + lkl_host_ops.print = lkl_test_log; + + return lkl_test_run(tests, sizeof(tests)/sizeof(struct lkl_test), + "disk %s", cla.fstype); +} diff --git a/tools/um/tests/disk.sh b/tools/um/tests/disk.sh new file mode 100755 index 000000000000..e2ec6cf69d4b --- /dev/null +++ b/tools/um/tests/disk.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +script_dir=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd) + +source $script_dir/test.sh + +function prepfs() +{ + set -e + + file=`mktemp` + + dd if=/dev/zero of=$file bs=1024 count=204800 + + yes | mkfs.$1 $file + + if ! [ -z $ANDROID_WDIR ]; then + adb shell mkdir -p $ANDROID_WDIR + adb push $file $ANDROID_WDIR + rm $file + file=$ANDROID_WDIR/$(basename $file) + fi + if ! [ -z $BSD_WDIR ]; then + $MYSSH mkdir -p $BSD_WDIR + ssh_copy $file $BSD_WDIR + rm $file + file=$BSD_WDIR/$(basename $file) + fi + + export_vars file +} + +function cleanfs() +{ + set -e + + if ! [ -z $ANDROID_WDIR ]; then + adb shell rm $1 + adb shell rm $ANDROID_WDIR/disk + elif ! [ -z $BSD_WDIR ]; then + $MYSSH rm $1 + $MYSSH rm $BSD_WDIR/disk + else + rm $1 + fi +} + +if [ "$1" = "-t" ]; then + shift + fstype=$1 + shift +fi + +if [ -z "$fstype" ]; then + fstype="ext4" +fi + +if [ -z $(which mkfs.$fstype) ]; then + lkl_test_plan 0 "disk $fstype" + echo "no mkfs.$fstype command" + exit 0 +fi + +lkl_test_plan 1 "disk $fstype" +lkl_test_run 1 prepfs $fstype +lkl_test_exec $script_dir/disk -d $file -t $fstype $@ +lkl_test_plan 1 "disk $fstype" +lkl_test_run 1 cleanfs $file + diff --git a/tools/um/tests/run.py b/tools/um/tests/run.py index c96ede90b6ad..97d6dedc217c 100755 --- a/tools/um/tests/run.py +++ b/tools/um/tests/run.py @@ -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')