From patchwork Thu Jul 2 14:06: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: 1321472 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=kDI1O1Lv; 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=ko71pGwr; 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 49yKgD1mPhz9sTT for ; Fri, 3 Jul 2020 00:07:52 +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=B1efVaaElh4NpHISSzhbclRjAmFIwvPUd9DeLGRHCPQ=; b=kDI1O1Lv/Gg5BKUypU1Qfvj0K eBsv81vbY1E2PZVdvzfl73tLXlyIT+VkKZVPvxLysNOV6oOrA7rTsUuba01b3hUUV+PT4bzQhTWjr NmGVHNRplqpN0iSI8fwgCxPevlN4wc1j4/KmWZPv3kS2nJudJbx7LSY9GegZdnSg6Fezd2V+SW39Z +ErI/+yq0YvUX7xcUl1Xkq2DJTwwnqrBONhH5GnKTWBJEw2W6P4QwV0ahBrD+hgmoljz6sUgUrrQ7 31A2//GSv+OYejyRdkqrjpez1Ean0LvrzDYp3jpZeomdfo2Tg50i4433E3aw3dW7HnN01RfrGFsC/ K5n9W1Www==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzsT-0004wC-4B; Thu, 02 Jul 2020 14:07:49 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzsR-0004vM-7M for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:07:48 +0000 Received: by mail-pl1-x633.google.com with SMTP id bj10so6131965plb.11 for ; Thu, 02 Jul 2020 07:07: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=t2/WNXKzkzoCmlLsQGBnLxqCdFIQCP1a7czNJJbop0A=; b=ko71pGwrhnBLyFSsh3Uy0Wm0S5JazJaQ/Z/2lzQKSo7HlzvGSyRkd1i8fRFJpJL5EQ ah07+qimIlhecdNClhVMzi6R/rFX3BQUC8gFrWB55nVJoD01WkaMjPWXj6H8XfIB8OQd u6mPJ8YCCs0sQsoKuC56cA7+mHPrDumJg7PYpBFnPxaKNjh4uZfm6oKy4LuNkimnB+j1 l0yRqg6xt1otSWBLiKxodVwpoNWEQvbwzRqyaBDATgLpFY/2Q8MLUZeMjVDek2pSxKap FFsbp0mlwfHAA2U5pwQKOxZqI2ZhxI4xQCnNy3jEJ9e0tJjFP0YD4WpGR8bQULMSwI2+ jKtg== 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=t2/WNXKzkzoCmlLsQGBnLxqCdFIQCP1a7czNJJbop0A=; b=KsaLdYKnAAHE45XXWh47wovP3abBb39Z+IoYYiixDTP/93+BNPfbLVqn1IpCPraOox JI+t50WNuFJ83ARZJLDRXUbGFs/iOpgHRpn88vc1NLkRduQHJnKXDSuA3dy3RD/H6Tyo G3maF4DAeUPmYbM0JzFiNYLLZ1E1vtStZfSE4GqfoJn4bI4KHJBQUKQsgGjrw54EhX0A T6Uui0FRDOEqyew9a873O/BmcKuMpSvPDTm8v63w/6JJ7pgOhA1Nlyn+bx66D/b4hrEY dPmXn38ICPAIkRB1QBxEmWliUVMVO3lNkBTFVs9b1t21ewkUJFlUkLnxNeGWNO4Ow+Na Qz/g== X-Gm-Message-State: AOAM530hshhk32cnhah35UOhQd39Ty8QOhvzhDaypsQnVTZAKgS/my/C bG0HSQRGAbflo5xO5ZZ/9Oo= X-Google-Smtp-Source: ABdhPJwsRxTv5tb8PgJC+JhRZ9FUH2ocgBvYUX7cXYe3z7A0HkgTl9hMzlwga+PFMkbY0+dPdBUMVg== X-Received: by 2002:a17:90a:14a5:: with SMTP id k34mr15802192pja.37.1593698863694; Thu, 02 Jul 2020 07:07: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 mw5sm8904054pjb.27.2020.07.02.07.07.42 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:07:43 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 0CBCB202D31CE8; Thu, 2 Jul 2020 23:07:41 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 01/21] um: split build in kernel and host parts Date: Thu, 2 Jul 2020 23:06:55 +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-20200702_100747_314608_C930C0D7 X-CRM114-Status: GOOD ( 22.66 ) 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:633 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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, Octavian Purdila , Octavian Purdila , Akira Moroo , 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 96ab7026b037..a0a9fd3ab96c 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 275f5ffdf6f0..c952ddefcc1c 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 d09ab4afbda4..0bbb626ace81 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -75,36 +75,18 @@ vmlinux_link() strip_debug=-Wl,--strip-debug fi - if [ "${SRCARCH}" != "um" ]; then - objects="--whole-archive \ - ${KBUILD_VMLINUX_OBJS} \ - --no-whole-archive \ - --start-group \ - ${KBUILD_VMLINUX_LIBS} \ - --end-group \ - ${@}" - - ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} \ - ${strip_debug#-Wl,} \ - -o ${output} \ - -T ${lds} ${objects} - else - objects="-Wl,--whole-archive \ - ${KBUILD_VMLINUX_OBJS} \ - -Wl,--no-whole-archive \ - -Wl,--start-group \ - ${KBUILD_VMLINUX_LIBS} \ - -Wl,--end-group \ - ${@}" - - ${CC} ${CFLAGS_vmlinux} \ - ${strip_debug} \ - -o ${output} \ - -Wl,-T,${lds} \ - ${objects} \ - -lutil -lrt -lpthread - rm -f linux - fi + objects="--whole-archive \ + ${KBUILD_VMLINUX_OBJS} \ + --no-whole-archive \ + --start-group \ + ${KBUILD_VMLINUX_LIBS} \ + --end-group \ + ${@}" + + ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} \ + ${strip_debug#-Wl,} \ + -o ${output} \ + -T ${lds} ${objects} } # generate .BTF typeinfo from DWARF 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 Jul 2 14:06: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: 1321473 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=sWNRh8kA; 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=vRUt7S1f; 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 49yKgV5CnGz9sPF for ; Fri, 3 Jul 2020 00:08:06 +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=YRlj9pK7JRTehWWrwTAkt9Vuq6TxNE4XjU1oAxZ7rjk=; b=sWNRh8kAsPEUd+7hHIbeU5Qgq 50w298PxKakSYQ4JAl3eOceFQkaj0sa8MlHrCnJ8bqbO/96w/cU6MEFNmG8N4Q2zhrHqrHIOHmDFi b3aBrZ7LMk45hO8IvQafCtHNUiwsQa23CuLx+Ljp0KbG0pJK+71JQHM34Qloxs6R9QML/PlA1v+AC xYXEfGdn7b62Nxm/JHlb0uQ3mO95l0NEJYsGH3maq5mBgYR0LR3UGlnhlW5ViZeD34alvhmKsjvHg v0lCgr8RLnSMWcC3jJ159UbkjuNC2qBLYGLnbb6Ab8mA80lNTyWVSqSYVKzQfRlvC4awhdA70JUqP E0hfFB7nw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzsh-0004zy-9S; Thu, 02 Jul 2020 14:08:03 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzse-0004xt-AU for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:08:01 +0000 Received: by mail-pf1-x443.google.com with SMTP id j12so12584715pfn.10 for ; Thu, 02 Jul 2020 07:07:59 -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=xasBvkD9zePzp96sFEIPKb2xSB/v1inHzybPvJ7+o4E=; b=vRUt7S1fZ0VIwheb5Q4yZN1ROwCadsjiGfCM9Lv68CssOdOt42H8H7sjOpdK4EISgn j5PF+eF0iM8gFDGZrWPw+yDO8NtocbWITLdKN8Y+PmfScaBUyNurYAFTjzJvyPylxjKr sAFIictSJZk1RdErxDcou4XQNTKXaxdQ77YSnQOvHqG5fFrCu4idf71zTPidpi8vdTuy QgOghZPJy/bVkNZyi1rUD/qVWQAlmbNgcp+h19sBvX3srnuafjb8HuWNoy/Y5QJ1e4Rn 48ttk3SDXQWf7os76SehtrdjRE9nIM8MFo7tJO+zpNCEjVkdJIndRRwW8BF1jEb71tAJ IEnA== 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=xasBvkD9zePzp96sFEIPKb2xSB/v1inHzybPvJ7+o4E=; b=Udd+uH8triHZyHHFs094DBS5tXVWMVIP3/egYg7wfRdfDlpleGz4T/QqJVQOa0AUJh Ly/JV1GwWzgZdrxrWcI042c0JWgYDGDBebZ45cFtPzCTYt69oSi8xTGmRzmeteubeeZy C/wYIbia+z80ZpLnRNFhdyFacZ5+7AWaOwF77ULfF14RzyCgyzLlEOCE/EX6nAioMq2E b2/5joVH2vEI1BARzQZgJPPxJl+TFv8f0NppRlbR1LBbZ0uYdcafU453A1XlPH7yCMg8 lOGmeFjBbD+5n9x8KRk+JKf+lXXfpYm0XKvVv5S1Qm7tUcPdkxTHSaz/8u0KKb+OaQpI vtkw== X-Gm-Message-State: AOAM532mlAOP1lL1ct8sRRiBQc+V3ef2qJFM/+lEtJUEq9u2OcSrEZZI yDlchymtXU8YF1cczR0L3SQ= X-Google-Smtp-Source: ABdhPJw+DD5zO6QG2QGUltLmPfJbGZFVADOvyRxgUGx9pDH+tru9xplZcgr161cC391r5UC2nKiXVg== X-Received: by 2002:a65:60d4:: with SMTP id r20mr21109029pgv.436.1593698877833; Thu, 02 Jul 2020 07:07:57 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id az16sm8057493pjb.7.2020.07.02.07.07.57 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:07:57 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 24764202D31CF2; Thu, 2 Jul 2020 23:07:55 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 02/21] um: add os init and exit calls Date: Thu, 2 Jul 2020 23:06:56 +0900 Message-Id: <6dfffa1f31b783b0ca9e0ef3d42ef48cfa25d233.1593697069.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-20200702_100800_457343_FCC0D480 X-CRM114-Status: GOOD ( 11.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:443 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Octavian Purdila , Akira Moroo 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 0f40eccbd759..78d6042fd2e6 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c @@ -362,3 +362,14 @@ void __init check_bugs(void) void apply_alternatives(struct alt_instr *start, struct alt_instr *end) { } + +int __weak os_initcalls(void) +{ + return 0; +} + +int __init run_os_initcalls(void) +{ + return os_initcalls(); +} +__initcall(run_os_initcalls); From patchwork Thu Jul 2 14:06: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: 1321474 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=E0GzLXBD; 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=KgizOUy1; 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 49yKgd5xmMz9sPF for ; Fri, 3 Jul 2020 00:08: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=wuu1LZ/CsQt7M4NT9xStJbZWXBjdhOzHkTFwBqo/Hns=; b=E0GzLXBD/g65G+/Qxi6uILUtR 2Cd7a5XFksDGQwjbd3vvm6Th8nGjFm3kgVxoxb49mJXPvFCBSJ9Pdkw58vDLTYzoiZI5xKcDJhZou IzQDimmOtRxmUSG4fGxo8pNfQjWcVi0OBxUeb1uXB6Xvcjv+wyKQCV8DbEJPJtFoClHcA/7yXboXP QcLDcY2RA9WR1O7avdYo/ZX0DW0vdfBR2y9KDzPaYRUhcafISH4WksDjvlrch1t3Rw6N/dBWy4SrJ Mv3njCmmx1R0ILIC+3vguN7+jtjujiGBjRtt8BiSUklAuhLnKxrbXjR7vFDa7wnofJnDIw+dNSG5X ctnclAUUQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzso-00051r-NM; Thu, 02 Jul 2020 14:08:10 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzsl-00050l-QT for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:08:08 +0000 Received: by mail-pf1-x442.google.com with SMTP id t11so7732726pfq.11 for ; Thu, 02 Jul 2020 07:08:07 -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=jzAjiZcVoUDzHqaGGazNhx4mgWMRddI0e6cwlG3rIho=; b=KgizOUy1hEjgOc5HZwjn64LSVktixKvk31RnMZJUP7D6qsbfGmQQ7lo1EKCU+JM0nG DjP36bo77WC0tgmSwUD+dh5tC5h/gkii7F+q8YexVAuA2BrJqHK1rKZWM4cdi0LTISmT u2rplxKxuX7ucYpdq615A9v+u6kuZdEhofyh17M7CT78uy4Za5rjB+/Ml07OjmPCQRPU 8gizNXMNW4BoZOpHazZJdrs1IBZxzPLfX3CUVIJAb6CyF/qFiaSrC9GvfGCdNkTt5EbG zewVP8VMOeHwWudLc2yyE09N6XZJwDe3ltdOKCtXt57t9MdqgiQr2UNZfq4cB2C03I/X TbwA== 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=jzAjiZcVoUDzHqaGGazNhx4mgWMRddI0e6cwlG3rIho=; b=JmmT3O7npJWSYirfGwIwtsnQBLqNcXt5YEDO5rKHZcktNsKX5ATNwfd6zwoU2QqfRw 8I+vRMDlezlJ+wlX0QxOpIVJxNnePOXGw6FQbyDXFV2W5/zznuXZjyplt9VgQFyXCxVr jvTIlR7FEFSveR6rtHsEWlWu+i2GBf7jSFi4yfcf1liNEZTFQ+inW2WRIxzjqhR1JbQp E5loM12X0cVFQs37kH+3bm82RBIWuTQmHoxTzyCblVCjDcCo8TXgj6qsUI+06gZovvKC mG4YvKBX8FtVnvXze7r4PXXsEJ0Xm+iGEAF/OkYpsFtxh7HmoDZsW3SqancwT1sA/eh8 pWQg== X-Gm-Message-State: AOAM533RcU32HRmSalJbpSWZeMvsUzbWLOThKqQyAlK08bmbVkhfWD/d rLWmtt6rSnhYuH+qwuJsT3M= X-Google-Smtp-Source: ABdhPJxd2s1UJaxVNkKYkbQ+WCFL6A91Ix7I1JhzTo3fTYkmiXeyPxOSA5+cOIZf0t/cszT1FU6I4A== X-Received: by 2002:aa7:8ad9:: with SMTP id b25mr29021892pfd.248.1593698885287; Thu, 02 Jul 2020 07:08:05 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id w1sm2252974pfc.55.2020.07.02.07.08.04 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:08:04 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id E2028202D31CF4; Thu, 2 Jul 2020 23:08:02 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 03/21] um: move arch/um/os-Linux dir to tools/um/uml Date: Thu, 2 Jul 2020 23:06:57 +0900 Message-Id: <4ccb1c6065149db6445356feec89b4d40b3568eb.1593697069.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-20200702_100807_886145_B89B37C9 X-CRM114-Status: GOOD ( 15.71 ) 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:442 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 | 4 +- .../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, 72 insertions(+), 47 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 c952ddefcc1c..af0cf64c1428 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..15b52328e7aa 100644 --- a/arch/um/include/shared/init.h +++ b/arch/um/include/shared/init.h @@ -41,7 +41,9 @@ typedef int (*initcall_t)(void); typedef void (*exitcall_t)(void); -#include +//#include +#define __used __attribute__((__used__)) +#define __section(S) __attribute__((__section__(#S))) /* 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 Jul 2 14:06: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: 1321475 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=q72fmb5X; 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=YDwkos8L; 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 49yKgw1nlwz9sDX for ; Fri, 3 Jul 2020 00:08: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=IPYyAsuQtzcDqJhz6EcRK6irOrsXliDY5xwBxVmakJ0=; b=q72fmb5XnCJzUfKwI03B4SAib 5S7+sQYTgCvNWikApeMm8tBQLTmBj+hJ4C8zMgB9bHbiAj+l/5AMFIVLKulxHkQIUdkn021qfx5A0 usxa6Yyx4UgtGqY2l8RD7PlAFWCuyoOXRyMOi5nUtHPSMYn/vzyRfIt+e5wl7SvgDxsPnLnDsmiwn PrPCbETBxKy6Q7McgDGSFcjUpruWjhLQjBmvRTgUp/3Mb1mpcxh4vYUNT+st/Elmv+olyB3oHSbxr QRHrh204KQ+xmB+NeoeftKklJ85s/BSeMW0Vypu2MBjaCnWbn7WbBtQjP7D3Vuxk32Q/lCzH1616v vMQ8gR7BA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzt3-00054W-5K; Thu, 02 Jul 2020 14:08:25 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzt1-00053f-43 for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:08:23 +0000 Received: by mail-pg1-x541.google.com with SMTP id p3so13523792pgh.3 for ; Thu, 02 Jul 2020 07:08:22 -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=YDwkos8LleCOmOPe/U0+N+mFT9PRdHKRRV+ZDzhybm0Luk1vRh4AAKodqz0HR6NU5/ ISaX1FvNVlfi33zqZe/LDhMaVihrWbgVjX4UJdNIVe273/CCL/ifIT6gYsolLOylKNa7 LqXlO2/d6oBUjHpL51uVoGirv1dkPYzEGy7199AvDKnWeUj4+sfn4ovyn8Yl/uLcKIFV 0XtnfRP/NZ4Uieg3J9tY7Vt9eHQVTxUuA+a6HZdLSmjQVRGJd55vjvyFdmrGTdl1LEK7 IRVsvs4vJaqGXnmXUgMH/e9C4y4XQ3CLCB7TnP3xq07EvmvJCotY4z4i2m3MxWW2b0qU 5WIA== 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=pAzKDzVJNASuqVWYBM3bu26lqiscHqc8z5PicHdUBKpHSq3H42fBNog4tplL2jPxYQ d02jS3JbaVD0esW2xpnay+xmyh9Hoy4H88gM70eTCPdZ18HzmAGJGPGy+Fi9QLfL2zNi OXSOdghdeoo4tRSj7kZZ0O3ZpNo+uQ+f81RMyCYPWG0s6VoTZ8W8mytoVDT86ODXFjsV mTYvuEbcjeKB3dkGYV6zqimBE9V18CfQXyw26m484CpJIwB5CbQ2koedTAiQoDMziPm6 lRDcf3SqQYussh6bCZbymhQDzmDR8O6/7TgVDORZf5Pf/FqmByK/ZlS4Z7tAgNIMAeb0 VsIw== X-Gm-Message-State: AOAM533g3HHPjbWh3wLdEVU5kTMIeLODbZZTIf2JyJQ7U5/2e4uLSqz6 cDL7oedHkqM6vHq8gISqmgQ= X-Google-Smtp-Source: ABdhPJzE/EVJO1jdczzDxwkpPpM/Qi0clImGr1FMj4cMS9s70OPXQn3No2fW49gU3ld7EikPUthWIg== X-Received: by 2002:a05:6a00:d:: with SMTP id h13mr22984991pfk.288.1593698900573; Thu, 02 Jul 2020 07:08:20 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id y7sm8638061pgk.93.2020.07.02.07.08.19 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:08:20 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 69BEB202D31CF9; Thu, 2 Jul 2020 23:08:17 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 04/21] um: host: implement os_initcalls and os_exitcalls Date: Thu, 2 Jul 2020 23:06:58 +0900 Message-Id: <9e12b717709d74821a1432467e6800d7741e35b9.1593697069.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-20200702_100823_183346_5902D553 X-CRM114-Status: UNSURE ( 9.51 ) 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 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:541 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Octavian Purdila , Akira Moroo 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 Jul 2 14:06: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: 1321476 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=ZmoUoql1; 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=AWzZQvG4; 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 49yKh46wPZz9sTZ for ; Fri, 3 Jul 2020 00:08:36 +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=ZmoUoql1847OC3haIsM3fqTbQ 8CklIT6IqsMzz3bMK+MWBuLJwDVyPbQmVWMEYShcvhgEknfki4v1RNjnNuM1P/Hb9g8ofT0FX4t0A 3qgnKOxwj6UGN64G4ZPA2CfBYAkkQrC07zQGQmsRrxefp4a1YxZ5/nQsnTZbf2m9XqX+XuRwSxsvm x/MtyZBAUIFTCFtsrH9aob70cFGaMFZVE8njinYgG2lOE28yV5HuNXkReWz+p7iJ7EUnoBin3CgvM 55SLnYLRfUsoEKZDjdimgdRQF1zX8IzDl4langbsky2ABVI5F92V0oOPGjkIIl0aCcDC5fM0m0bJy UNiKw9FcQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqztB-00056m-Ge; Thu, 02 Jul 2020 14:08:33 +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 1jqzt8-00055f-Rp for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:08:31 +0000 Received: by mail-pj1-x1042.google.com with SMTP id o22so7530648pjw.2 for ; Thu, 02 Jul 2020 07:08:30 -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=AWzZQvG4MRtry0t1te93bdGkzqH6Xe977oWWeJDN+hq6ZFo9aHG/kpmRoR9KE2spJs Sq1A/j19feHVxP/3G1xWXAn87r7/WutEeik88oHdNiysGTYR5ebFv2HG7z1XIQvH3j54 fv5bLIJOlwue5ckNEksWda2CihqRmqLevQ6JluoVJcI8cwhx6CbOBUYk0IFIvdikBo9F JAOgcsnCu22PAuWkHTmPTR/w9CnrDeSdK9PKXB6IIJ7jm3tV0M7egBXwyAfrbk0VyEV6 71aSPKp95rCE0AeJt9/Xfqcw2LHfTXOfntiMvm4IefmRm+boZJ8tMpKu66WGtwRFBmRa iGlg== 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=JqFTAcTYQCW/ovuxYOEnzLs1mBbFXHRtJkHPfAh7UzFNLyNkCmzd0hAkXY3TZFhNel zK1azbEEXLIG5NRtrKOleVBATL7WRzmBxZy8IqOcTHPOr6gtYkA9LnrdH6FJv4LpkedK +Pn7XSo5EUTFOvDBP1CQsLnOu2OdqMa3uSwaw0rAClxhm9uijhUH3G27p0mz0Pok+9g/ ahaVsyvUUclWywS6RrJ9PMFmvnmWbUlBwiGOQD7+27Vq6r/KlvJZhOUE5aua1RfBEk1f /WIJJJBRhksUfZQLrvsLN7npntMQEEWo1m6puQWa3qZ4a0Eg5J3o6ztMlK7emOmA/yZy ey9g== X-Gm-Message-State: AOAM532TExXdPOQ7UOD3PtvQijT1Eo4JnaNlccpN6EiLlUrgZAxJLkJ3 q2TKRt26A43e/koeSk9TNhoHLNz9ZKo= X-Google-Smtp-Source: ABdhPJwBmwR03hlLcJDgrCbR2OqpECTZdspLy29IZ8k4jwL2ZXaY9xhvAGifD4own8o0Czi1LuAa+Q== X-Received: by 2002:a17:902:778d:: with SMTP id o13mr25750038pll.247.1593698908494; Thu, 02 Jul 2020 07:08:28 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id g26sm6372324pfq.205.2020.07.02.07.08.27 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:08:27 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 94DF9202D31CFC; Thu, 2 Jul 2020 23:08:25 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 05/21] um: move arch/x86/um/os-Linux to tools/um/uml/ Date: Thu, 2 Jul 2020 23:06:59 +0900 Message-Id: <92ac407875bfb718371ef95c40610ec1ed50ff32.1593697069.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-20200702_100830_922140_D61AA067 X-CRM114-Status: GOOD ( 13.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: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_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 Jul 2 14:07: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: 1321477 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=DnFOHiGe; 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=iqPtQYky; 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 49yKhD5rLhz9sTN for ; Fri, 3 Jul 2020 00:08: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=Lhqp4G0aWEiVVpBtYgeYO0nE1CU8FlER5QpY1CWswZw=; b=DnFOHiGe36uYTBVabPx7Kt7mC Yf1sFH694/oZCkm1FEb0rAxnrtH2nph/mGGdPXRnUAWwHhmeI+e0A+dIXZUw9ig4Qo01y+cyLHK7V h5cCvlgyrzPcb/h0ipIjhEiSlpvi4rD/zPumVyarNHPyitPTpLvEBZptqCBExAByr3dyM7PB0t+xI 5Qs50+6VHFRYLNXNrmm7WaL5PJTwSSJT8KXMdOKPVCuqNSNlkpNCpKyIwopmQWMqNpoS/MuobobWw ZhAxDpv26HvUED47eoguKxkmB7KIatv2Xmz8IRuEiqYj+GZmpjPrbi5FNv+43FSSkDOx1tgD/f92o 7Bfi1xLjQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqztI-00058W-St; Thu, 02 Jul 2020 14:08:40 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqztG-00057d-Hi for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:08:39 +0000 Received: by mail-pf1-x443.google.com with SMTP id t11so7733370pfq.11 for ; Thu, 02 Jul 2020 07:08:38 -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=5/87dVOT03QWsWrcTWI8VqWKTuAoiDkqp4zPRvF7J9Y=; b=iqPtQYky7j5nOAsd5/dhtcYRu3lJ8SptOB2u83BR9jWnSnpo+j8QqdJg1lBQSSVyo1 T35WY1Ol02gSIhVqqIFqvXhXRGPGSe09Gu+L4ckWPXlnTbSYKlt9dPo2/tuOQ/AKw7w7 dNGzG0h2AGc9SG6EiJKU4o6NHNisdc4Poemtaj6hdzI/h4lQ8hjm9TRTItCjo/mHSpok RmYf6WQXz+6fBbRC4vpr//rAguQ7a6OlZDxDaSw9uWOiNaTPUMHK5Tww1i/EWiw9MvYw kdo0ruQtJdEMLXxVmB6NGz3JMuEsjXMFM6259RRXtW3/FoOvnJVFQxlcDLesdTU3xZAh nGwA== 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=5/87dVOT03QWsWrcTWI8VqWKTuAoiDkqp4zPRvF7J9Y=; b=n5WERtoxFvuLuqwrl5l03ykAXe52fRXBSW3/QvYP+K2ODBJwYlhhm2kTdIWs0zMf61 lRz5E/TvxKXFLQGg5VFmuUDLiM9c9c/Inm7fkBYWhngXK9uk1mgXKZPw732UrBtq62BF JCeWY8CHivwh7Oa3Ftnd/O9ngzZwKlcV4ZXR/W6ciRzJ+NsKYQkECnLvlH8kU5Qd/VHB a9r0XqPtE+MtSNI3r4uCbtKx01BjYwshvjaeT7wc74XjXMZiD1WReOOSddq6El2FNJ4Z DogAqXbXT+ENQGkwtZ86aUna6ppDiqLYvqRbxTHLpX2SyEBWhLbLVgy4V9Amrw5G0F6U Gkfw== X-Gm-Message-State: AOAM530fWmTMF/bKzNt7L21yH5vbbN8ahzC5+xgzLUPzuUo/5UVVWUww /FkXeXGRIMGD3qM4RPfuJNA= X-Google-Smtp-Source: ABdhPJw3lyQKkNsTs0ctYDmMqIO0TGkhB1e8QJXRWrFLRtw5i+lCuvpRsae03kVDfUt3GzCGBRfr/Q== X-Received: by 2002:a62:7d56:: with SMTP id y83mr28334373pfc.293.1593698916704; Thu, 02 Jul 2020 07:08:36 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id w1sm2253975pfc.55.2020.07.02.07.08.35 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:08:36 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 9CE10202D31D1C; Thu, 2 Jul 2020 23:08:33 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 06/21] scritps: um: suppress warnings if SRCARCH=um Date: Thu, 2 Jul 2020 23:07:00 +0900 Message-Id: <103c87a24c9966f465cdc3c4e4d6519c81cf33d2.1593697069.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-20200702_100839_003759_4D80C1C2 X-CRM114-Status: UNSURE ( 7.17 ) 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 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:443 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh index a07668a5c36b..59966f3b4ebe 100755 --- a/scripts/headers_install.sh +++ b/scripts/headers_install.sh @@ -99,6 +99,9 @@ include/uapi/linux/raw.h:CONFIG_MAX_RAW_DEVS for c in $configs do warn=1 + if [ "$SRCARCH" = "um" ] ; then + break + fi for ignore in $config_leak_ignores do From patchwork Thu Jul 2 14:07: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: 1321478 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=A4V5xt1F; 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=TOKMySl/; 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 49yKhJ50SRz9sTN for ; Fri, 3 Jul 2020 00:08:48 +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=grAaFOoKBcroQqO5nU/K58SdDDjiyJ4JwpKkVQ21ljk=; b=A4V5xt1FREN6aT8lV06EAQBe+ CSKhbdtkVRVx29avipY5Lc1/yvczEi/Bl8+kkz0GJof5x1OF+3rS7uZuofH77CFHJ4yGHk/4pJvdt phhc/sRYd5neL4G3nDlHeWoEMQCFycUuTnv57SSa/vAg8f9E4g5l1MnmztmNnGz3qj9RC5X7Ml3Ae cDkgBtZCnGXZoiuXT2hIZUW7N3SSnXHUj6hzXHkO6otpj39llmU8IsxMFkCHDfUBg1GnH3N89gdEy YHrSRRxztk/Ebi6PaSxLm+W2tbTv8qme2quS5R1p8QeXvDyHYV4dNZQewRayZpAUxeAEyL41dqCl0 kLvWrUFHQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqztN-00059m-Bk; Thu, 02 Jul 2020 14:08:45 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqztK-00058r-TP for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:08:43 +0000 Received: by mail-pf1-x442.google.com with SMTP id u5so12599233pfn.7 for ; Thu, 02 Jul 2020 07:08: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=GmaMOyI4gVFLhkvZqmlbu3s7en5DC1VB33ig6KFywwM=; b=TOKMySl/M3uj9spWbSQtCzFyFN9luVKCupJB6TSsZ86JwtmH7UMBw8WHlZwgfAsCi+ NgRoRwKqVKBnGWKSpDDFlmaNDHYeW77Y9oWBXPzrsRSzoxqj5nwo+tps039WQ43cYXZT IdbVntkZexSxLIFDrbbUwV4Ze17oQDMsGar09LttdaJkEm3+t79HFzYchTczFC8ZNegK YqWFENReq69Ofmu2Sz2SvuhVkKbCvEdrRyQBP+IVfvdtZoSGvoBnLCVh0vluLImz2sbI 5mGEHkpqn1k53ngqv/QiSMAeXiVQPUdKlsxJnCAmyKRfpT0SgDCPpp23SLxc4tHfbFo8 ZBYQ== 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=GmaMOyI4gVFLhkvZqmlbu3s7en5DC1VB33ig6KFywwM=; b=geo9ZxfzAreoY8tdGp/uZsvDswYpbTgvIuz4XbB2AiZwwekJXa6Con6k1ZKRu3LWMC PtDqEygIyjI5r2IOgc2PyE1fApOCteEoH2V7u+eOy3DzwsfBj2ptEHRrBDMQVtzzCm3R cqnQUZjnr1eFj4DDC18mvrfe7WrCJgHrVeMQCj/swualCLZmH6wuhAYVKyM5A2BpiIjb BLTav9hxkYHo9d7EHRWlK4v9l1IdHj+bH2KpHww03lC+YkUxTm3+gs5J9bprdG9/XGQT jbRlZKYZaChelFyMvseOwt4cf+qDY3XAJx2ltT9PwBla6rvK74qr2JO8KeUyANqHVAJ8 yqIg== X-Gm-Message-State: AOAM533hk3h6Nf3HU7CUO1PhnY/+tOSwoUXeXn4wMRH/M+y14TZwb0au LOqz7ioiLQQColkW0BIDzuIw7x+KjME= X-Google-Smtp-Source: ABdhPJzlVgYXgph7rRiCP7qA5lW9hIyQ+spVWF51Lbi4fWlj0gD+8CyahX5l5SnTU4qgwr9MD+X7BQ== X-Received: by 2002:a63:2c4:: with SMTP id 187mr24948972pgc.367.1593698921008; Thu, 02 Jul 2020 07:08:41 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id g140sm8947237pfb.48.2020.07.02.07.08.40 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:08:40 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id AF165202D31D1E; Thu, 2 Jul 2020 23:08:38 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 07/21] um: extend arch_switch_to for alternate SUBARCH Date: Thu, 2 Jul 2020 23:07: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-20200702_100842_966179_96896E23 X-CRM114-Status: GOOD ( 11.48 ) 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:442 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 cbe33af2a880..e5238a42ea17 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -81,7 +81,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) { @@ -89,7 +89,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; } @@ -146,7 +146,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 Jul 2 14:07:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1321479 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=iqO9VSkx; 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=qaQYjGE9; 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 49yKhZ1632z9sPF for ; Fri, 3 Jul 2020 00:09:02 +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=iqO9VSkxD8UtsKJKnlZX9JSok 1Zr7w6/OcjCqIJsCnkHp7MNkyyGjgLLimOuOdaTITAtFlmEljMwqS3Al+sh8EeGYT/UxYRX6MbUDZ c2kI8FBYZW3XPK1TH9dVXIPlFnVuN0Tr4+Ss4JEJGRmq20AeDT2+W5pKs/7elvZiofaNOFDbQCtD+ 2+xm+2rub9L+Ufl1w1Eo49DMUoTtXN8WjkOAQ7LNlqtBvN3RAq2x8hqN516aJCLNOSRptE1faJrSU TvCkndlPgxRgZ9xRo2bQzigCvG1IGFIQo+/YLK8hTJBSWigp6TUaBvk7iumX1k4iqicR0w/ZRTfFs 67pJSqOeg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzta-0005CG-Pz; Thu, 02 Jul 2020 14:08:58 +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 1jqztX-0005B9-RE for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:08:57 +0000 Received: by mail-pl1-x642.google.com with SMTP id x8so10467722plm.10 for ; Thu, 02 Jul 2020 07:08:55 -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=qaQYjGE9GJK30fB1N1z0DEoJiHBV7OgdCafJVylj9pOaeO7VmDkjEVeQchpomnrZYT +Qyx3NhojnkbTuNs9ruem7cc0s26mHvUbTt3p+s75GG1DjMdobqCAN+zlwc1jH4w0cBm kKdxdHMnoWePYH/NtlM3tHtV/wECVTOmJ9jc+bd2q55VKvOqWelZdEwW/FWl4JcPr+HW Wr+ofnuw5SRZkdSbWIVGwwVcEvaDMa/beyX4dP8ikO9+9QSuyKTAcxZSNqngZ94hbSaS 93vdvRfbQtPAcCFCgAb/oo8EKc3mY8qgAMRL0vNr94+2LTbGW/KdO0+YJuu2PtdPV995 fpKw== 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=I1FdooaeKXk84+xPAK9J6pTFzobQEbHcOHrWDc3fAcDULOQGbYyBiKPelOF5vNy31e 31Xc7SIxU/ffmmMyH+awmCK4JzlKVjXHpgL0KLy9LWdFDBQBLSQpNUkB87/zJSiEr/J2 e7QOpo7lEhpBO7dIy9gEnJTz4nPUCvR5VhhEQehF1XNkN9Zq4b1HN4Z84sh2qZ/rqNOb 6Dj2xeASK1x4xdlgmZ4cBXxOa9vOVtogRCE9L7+j44aG/9Kiq/OTJYPjNeBN/NxMHYJk hzi94vRX16tL5GPYBSZP5y0f4TzCy0sernrNmy3pXLZoPOFHQZHtjwZ9VxZBn+0tc5Ny n37Q== X-Gm-Message-State: AOAM532q+WjyymwHtkjifleJ6/99tibx/6OIT+zMJHRlkupp9+IOTx4v EsWCZa4W34rLXAaHvnpgL34= X-Google-Smtp-Source: ABdhPJz+CrKg2Ct6H5K8O5JfBIC7yFoyyGBndDSaj35mJQWG4P4wG6+qolIN2F9YJnx7gHKou5RhXA== X-Received: by 2002:a17:90a:1a42:: with SMTP id 2mr2695943pjl.186.1593698933179; Thu, 02 Jul 2020 07:08:53 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id 9sm8729563pfh.160.2020.07.02.07.08.51 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:08:52 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 39A5D202D31D20; Thu, 2 Jul 2020 23:08:50 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 08/21] um: add nommu mode for UML library mode Date: Thu, 2 Jul 2020 23:07:02 +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-20200702_100855_984674_9B444AC5 X-CRM114-Status: GOOD ( 19.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: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_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 Jul 2 14:07:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1321480 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=oKnmITDf; 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=BjV9ggak; 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 49yKhf2y3rz9sPF for ; Fri, 3 Jul 2020 00:09:06 +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=oKnmITDfAHcT6zkWhYAevUOJf XUocB/KkJE8/w4L2XMr8sDezs4jZsoQDYa/uMpbgNbQ7AHIpO/W1msjaYCRtaFMcyK+ACRpiZyVGq vt2r7VrDRVv8HBGk9a9ZUkkabiFWeOI9YvJ1CpjIFNnerdH1k8vP4gSucMRuxNDI1eig8DsfC22/7 UGiol8FDTZXrsFlqgP1EhJIqZJX0A4MAafbyOJMeyvdfhtZd6ijX314gji4mA90LiByAK3eIVVhgC NxqqBKyECe4HYeUEyEPjbkCq7gvZXkYY2p4km8TN2xNZjZ6NFL6RA5F/J47QgKzcMXg+e1haIOBy2 aQA6TogMg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqztf-0005DX-6o; Thu, 02 Jul 2020 14:09:03 +0000 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqztc-0005CH-Es for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:09:01 +0000 Received: by mail-pj1-x1043.google.com with SMTP id k5so3017426pjg.3 for ; Thu, 02 Jul 2020 07:08:59 -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=BjV9ggak1qS7sx7q9gGxO75x9GkcaqisDOfzuFdC77jOO0bdV1ekcIV8P5Ix1Dl+DU 0f9ZfY3AUy6GGYDUANh0rdiGQmKpyWKrXfJJlJmrq+HwUcmv4z3CbCxkClngJupcWYG7 Aoe9b6spsx6Y2YsTCAJDqQAMnqbFgwraa+IozcweWKM662A/RDJXbdamfEwYT3wpXE/B SzaAExupi+jxiFOKE4Id2mTB+OI/RJK2STlh9VGUhlO+xx41bn26UnwM0IZ8ZTJlzPbz Yt+CvRHqp2g6EvH5ffeKVHmjQwNQrTCVp5iYBMN15Ef5YVyarlexn3TaXS212o5oHkCY 6yRw== 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=SEuQ9s5EUdqt4gujdO6xE+uLzLSZ+RDnnxVzz9mOVbWsKd+izS7UI0snq24+RM7F0T 5ir3mYbEqtQNeyJGZFnmRMcW72FPNEiJ0k/+jB3o2vvl/33e66QqUNlpG9ZNjE8UKScC 1k2Vo8MDKMTzu1DR8tWlP5kcaDUoemQn4otLng6QYmosH4GrDCrqiHKC4JFObq6SoLAn yx/AbU0Znej80WcZw4onapNQpYA08gPF/ZvQ356Q1MnZYzpG325Pgpz9+135M3O+CZeR lgHPj1KIHc2s9m2dKCZ7JM8DossEW4gSdhQnTOYefhWsoBMHfWWIaa3VQWnH069bhj43 ootQ== X-Gm-Message-State: AOAM5302yOnzCmrz1LZ79ubuGbw3ctssh1DZ6FoxiAuhx6Dyk1Am3MbA VRI289AoyeQ6UseFbJyeImv+vL8/lS4= X-Google-Smtp-Source: ABdhPJzeYk5OStImCc6jXwI7wK2f4JubzcH2A4ddZYtKMmjeNqvf4JHDCZgKZ8gbIuX3X5pfsqmeBg== X-Received: by 2002:a17:902:a412:: with SMTP id p18mr26270151plq.341.1593698938073; Thu, 02 Jul 2020 07:08: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 o128sm9313973pfg.127.2020.07.02.07.08.57 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:08:57 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id B14FC202D31D23; Thu, 2 Jul 2020 23:08:55 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 09/21] um: nommu: host interface Date: Thu, 2 Jul 2020 23:07:03 +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-20200702_100900_601527_210365B9 X-CRM114-Status: GOOD ( 11.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:1043 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 Jul 2 14:07:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1321481 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=ALzpL9Nd; 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=hLFus/7z; 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 49yKhm1MHzz9sDX for ; Fri, 3 Jul 2020 00:09:12 +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=lS9/H3nf4TsxF62lBFCXV8K4bpqeSCaRDOxsTswvIRo=; b=ALzpL9NdtB1q12DcexFaj+kKv myO7ch2FxLKVKixfch5PtyLmO1DiwNjOh8j4Dd+TuQCF7lQ4LhO3cdmu32soLUKDNWua7J1BZd/5R 1Ye5RCl9eDz6J2F0qoRkSJujHUxQt2bjJbVOjnjgQ0q5X6l6YflUEshp2HbW7a00knsbDajsGruf4 rrgRYunJEdasLRJaEczK8Hin+nv/ZAM/lxmaVUE4cLMDgUVBQCfdjgwlpmTi3jJPsyE2lfWhFkydX WrR9s5Kikslsw8FYhwWLEQ+EdWb4RNZ1wcqShdr8/zNK8Q7M6J3+OfDOdEes4isthd5jt0Mi698dx O8KPuGLtg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqztk-0005Ex-Jt; Thu, 02 Jul 2020 14:09:08 +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 1jqzti-0005E0-BI for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:09:07 +0000 Received: by mail-pf1-x441.google.com with SMTP id 67so8525313pfg.5 for ; Thu, 02 Jul 2020 07:09: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=VgVDBIYkZ6q2Uri49/PrlfFQ1L4k61q+n+p+bxyis3Q=; b=hLFus/7zJutphXZvzBWUGmYWAMbYcj6hLSh/5sLY9XZdlxtM0+WAfeipWnb4SQZH9b JqikI8PnnpNELLGrxcBvwXjiiS8VGZ7r01u2am2+YwzBRX+sJN/qyK2x9MV2m4yGH5fe Br+S9DHvRTKrEQ7X+q0OBSNhTK5blbtZ+Gm9HoHxxsSnYjCpSqgLxgiGhZoFgtCcuov8 K9OX/s4fJjFrY6awqPNPbIxZiV3QCid1y+7rlfm+Gf6z/q9QnmT6oSwwCBpZa1Y3xTPw zGAtSe/61a8EHkhnVNmGHEr3HIPm2c83TVTUKDnimzGmr7KnE/jb2Z75X5kiOGuGSWCf n2YQ== 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=VgVDBIYkZ6q2Uri49/PrlfFQ1L4k61q+n+p+bxyis3Q=; b=qIUvwjY2M7DO0Gl5Cc6RB30hwTElFXlU0xeSTC8xbqKWkj9MBvwUR2zMzzxUzAWxp1 twE9llQxLsfYKuHEUSZAiOWWGZe/XMyPmZPuMy51Dj+PDYNRzZF7V6PBKF2NtqT14bsA r1/ompeWGgpMtOvG0Tc6k1lumweRzqDHI8oDjRJ00AJUgnbluiX3xTDVbY+E/3FPNGSw D8agIvI7tGKnwV0RlFVK8gn5j0qQDVxg3aDfTGYm9EPA7BVC5C8gir1npMIWhcVpqb2D mJ/CUQYtzLcjGbURIiz9sEwS+OhXp5DReHmbW/to1/b8PsCGT/zoT0C2CFf/xqLiPpZ6 Qe5A== X-Gm-Message-State: AOAM533F81894kMUFpkTsLTpBiqALltd0Kn3b9FlhFCCgEjZdYYtMv+G bQvqPww+aTi+7oaB74OCP8Y= X-Google-Smtp-Source: ABdhPJxbUvFEPKvbGKuXSdfdsKZBPbwZbofHf0ddwpz2+u562+or8S4QKs1kgvF92Dxt9yth09gMBw== X-Received: by 2002:a62:ce48:: with SMTP id y69mr27364091pfg.208.1593698943917; Thu, 02 Jul 2020 07:09: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 y198sm6668616pfg.116.2020.07.02.07.09.02 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:09:03 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 9A9CE202D31D25; Thu, 2 Jul 2020 23:09:01 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 10/21] um: nommu: memory handling Date: Thu, 2 Jul 2020 23:07:04 +0900 Message-Id: <75240f2026a759cc552fccf4e8cfd5454453e50b.1593697069.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-20200702_100906_402469_3ADD0B84 X-CRM114-Status: GOOD ( 24.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:441 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 b4deb1bfbb68..92cc838bb477 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 @@ -74,4 +75,11 @@ extern int init_new_context(struct task_struct *task, struct mm_struct *mm); extern void destroy_context(struct mm_struct *mm); +#else +#include + +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 b5ddf5d98bd5..5c19f6a58ef7 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 @@ -362,4 +364,29 @@ do { \ __flush_tlb_one((vaddr)); \ } while (0) +#else /* CONFIG_MMU */ + +#include +#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 + +/* + * 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..84ce15402f19 --- /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] = (mem_size) >> PAGE_SHIFT; + 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 Jul 2 14:07:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1321482 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=pjiKidAa; 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=hCb1FgxZ; 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 49yKhw3bp2z9sTN for ; Fri, 3 Jul 2020 00:09:20 +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=porwDADwx7v7D+fg3rQpSgFRp66IxOk7EuPIKJsxVQ0=; b=pjiKidAaepNuJtUDJ+NI2fkLh 77rng1pJTXLAtBjFJ6lYmpnngpnXQxr4bjYjsHdll8HiMh9eR1ckiWx6C1VuIWVJ+gzd4ytJlSyyC yQHXBv/sy09v/7F3Fq38etyqCRowNV9Mm6z3mDQoyrt91dl2EtI8pf1RI3VCYTPk5/xsxJPrT/toD xCDhqw8OxJwFv0bJiuWfiTgo1tCUFN0tZQOxxslnKrajkpjzAf/JnShkOdEbAewpJ2hP5o/PpctZX qBBacYcz3nlUHUPyEdBiWf9RXJRNcLG2T7xNAWQnffUOolkQSEqy/cHx8oe0g+zRW3cBBb56Ym3Od sXf8zgSjQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqztt-0005Hj-2p; Thu, 02 Jul 2020 14:09:17 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqztp-0005G4-4b for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:09:14 +0000 Received: by mail-pj1-x1036.google.com with SMTP id o22so7531438pjw.2 for ; Thu, 02 Jul 2020 07:09:12 -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=8TP+2it8qYSzdLs7U3k6S1PfY7sBYWcPr69Hfa0XJtk=; b=hCb1FgxZilTE9fBhETHlvUc0mwZ/10mK4/83l9FuCchEGUevZWr6lq+CWlaz/lvEmQ 7AWEbiBMO5gOzOHUgO8T+wQ/j63EsT1vUFnh9LJrp10gbcVWoGgJgrDw1uZni1mNEaKL l/KmplzKX2xDU7zh8psZOPpvRP+lF4NFSn/m2RrZOK7EzfP0WB4SS1rY6SH9O6qp3Zpz CKkKlsmlTc1s6tfHfWvGo5ibF10Xjzp6GNXFQfJT1GzvZPV7wslKxgHMXCjBxIFxUQZB Yhu7MryMtWwdK7uRabYiFDtX1/zhVn7AQ0sg1OGlu/7+EOrO+oKb2tCMq3eXJYO5Sy4x 5heQ== 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=8TP+2it8qYSzdLs7U3k6S1PfY7sBYWcPr69Hfa0XJtk=; b=olRTm4Vkz37LTFIiYUSJWQlwbuEL28OpemWlFgDLuOQ6s5vtMxI8JKh7P1JyGU5npo Mw0VmgTOB3Sdx7jbc3D2GtqqzRIvpnd6cIVUU3iqGQPT6WXRaPvbNEjamwJqYcm7OKdc ORkDbg85/4/69mN8z0VHsGh4ZBLVIHb7rqdtPsHtoulb4QEWfvX4J+rXZpQAv6eK+/H/ SDVhkzV/7a3t8f80DTa/icJu0Y8ADmuY2Zg7WpGXOdHLebnO9zhXAghU5QYXBu3b3P56 SEOiH1mHXK3wfCB3m8rMOdugUGtJaZ6Bt5m++aplI1NzC/+Ow86LUP6n367ytN3QmMPI uJOg== X-Gm-Message-State: AOAM531Xw2H12LlbktHy6bHm1NRN1obKCd0eLh3kZP8PyumdZxXA9Olv ZoCG5UqelT6dvzvO8zf/LInvpRHQPuY= X-Google-Smtp-Source: ABdhPJz9a2IEOMB5c8mqQE7pnLRHj5GK6wJRgh6UCippprQJ5Pth7Qh4T6Wlmz1tRnreKAyGmmHkwA== X-Received: by 2002:a17:90b:2348:: with SMTP id ms8mr31497268pjb.5.1593698950524; Thu, 02 Jul 2020 07:09:10 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id j16sm8984694pgb.33.2020.07.02.07.09.09 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:09:09 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 111F6202D31D2E; Thu, 2 Jul 2020 23:09:07 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 11/21] um: nommu: kernel thread support Date: Thu, 2 Jul 2020 23:07:05 +0900 Message-Id: <7e7a8b77a972042234a3e08bfa20da4964c55c9f.1593697069.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-20200702_100913_199264_C4A5EF2F X-CRM114-Status: GOOD ( 34.74 ) 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:1036 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 e5238a42ea17..0dafded5947e 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -157,7 +157,8 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long sp, unsigned long arg, struct task_struct * p, unsigned long tls) { void (*handler)(void); - int kthread = current->flags & PF_KTHREAD; + int kthread = current->flags & PF_KTHREAD || + test_ti_thread_flag(current_thread_info(), TIF_HOST_THREAD); int ret = 0; p->thread = (struct thread_struct) INIT_THREAD; @@ -214,10 +215,15 @@ static void um_idle_sleep(void) } } +void __weak subarch_cpu_idle(void) +{ +} + void arch_cpu_idle(void) { cpu_tasks[current_thread_info()->cpu].pid = os_getpid(); um_idle_sleep(); + subarch_cpu_idle(); local_irq_enable(); } 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 Jul 2 14:07:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1321483 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=TRJsi8C/; 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=sXKldrSR; 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 49yKj66sQWz9sTg for ; Fri, 3 Jul 2020 00:09:30 +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=TRJsi8C/+WAd02d2viA7EFkoG iTtRVlH41s5GHRhlbX4/V+3S7FNCqakQzWt+OD8+xZbMYxWVonT/AUGUP8Ji/oU2owVKfBsOlfdrJ 5MlrzuQYevUGehH9HMRms0CaWIESgykFNqUZ7NGcyMc3fNGkR5R3wn+YewRuFHNhF9wk3nz/nl5tc enF2V/F3Np23iYTLO6Vlh3KGkc8lYCh8iYOTv80oS0YtknjZT8Ms6RxTy3cl41og0c52OXbSGEzGi jn1G2jVxVl4VfuAP6uct4QHp1YBbrlrC8vLWSS0LTfc+7JJBoUDCt2FYf4BCXBCEihZyAbA4Ator/ k7LTDg3gw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzu3-0005Kr-Fu; Thu, 02 Jul 2020 14:09:27 +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 1jqzu0-0005JX-9Y for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:09:25 +0000 Received: by mail-pg1-x544.google.com with SMTP id m22so3153156pgv.9 for ; Thu, 02 Jul 2020 07:09: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=wT5jpOPDB0NInqu4SBIEU+dMeRQLws/J0n6IzbaAb/A=; b=sXKldrSRb/lxDuTfQhPsI2OIvNCMPPyMmjF2BAMvLz+8jQIO2T9lONWgqAfVpLV6mP lBaFjgq+NIbScP/nXRPM/wlWdCDBunpiifKHGTVuhQbEBGsSYRJHzUjpTHGBRY0FJcm7 jb13oPoVK6EwiBwD+ztBHzJAiaHEkDfnTxfurnQezOh8twwwleX36prCaqznwDI2A4xN fT0C/IfB2QcFxPcVXpT0ozF/5xXqYnGgL8O10KZ1QWe8ws4Zaw5pRYcegs4J61sREa7u qs7JugCw2y17rlFoHEGeRZKed3k7f+MAYTJRnq1us0rq8xOy+IEDcMPdCChpJeHZdB4m kC3Q== 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=qiCrXl0/jt/rKCo7G1AVW6KV5L9M8XnBwKiKSJd1Ajn7g+3lA+86bhgQ225mhy9JIJ ZacPJvztbfjWn+3lcJcPs2hU6mSONSrdGOyeUezml7oDeMOC4jeJMDOeMu8jpl3HBW3T 4yqpBNoxYw0VpkyYtqVIRQbjadTNrX6GR/P7ZZxJEcE1ujrdQBfUFNyYuGHFosXvwKFb yI7gS0fCTPZx3JWSNE+ugTKTainhJN7gG3P4eX9auXM+a3KJ9FAtaYtKBQmICly/QvAj qOl4Do7UAkwY/YE8fIxWK3/u3UEUWLMd1TokjlsDNGPlIpSOXWfoqz4vuhtkaynHcjaf 3WNw== X-Gm-Message-State: AOAM531RbkuZldQfJWEfxP6V4RAqGq4ERMpuI7C3qCHDhKzmj0w3sw3F BFnLQRPAUrQfaD24Ldq50P8= X-Google-Smtp-Source: ABdhPJxacTFZTHVqPViNI4Ff2QLf+ulpqUN7Djs5GkBStsk7Csli4Zffes2RRioLOpL3h5/pAdH3Aw== X-Received: by 2002:a63:5b07:: with SMTP id p7mr24218517pgb.250.1593698961727; Thu, 02 Jul 2020 07:09: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 t5sm8986680pgl.38.2020.07.02.07.09.20 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:09:21 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 0ADB0202D31D33; Thu, 2 Jul 2020 23:09:19 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 12/21] um: nommu: system call interface and application API Date: Thu, 2 Jul 2020 23:07:06 +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-20200702_100924_369695_E991DA0D X-CRM114-Status: GOOD ( 22.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: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_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 Jul 2 14:07:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1321484 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=fL8Hl+5C; 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=bVz9LuZs; 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 49yKjC1fZ5z9sTZ for ; Fri, 3 Jul 2020 00:09:35 +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=fL8Hl+5CAYwFlHXGRe/2knM2e a9s1NwhIJmvqjULK1oJkRvv/FOaNIx8YfA3wiMYBMva4zOVpm9efqQRyiSm89nwzU8DAWFV2umOal /tP67f46PiNB1ly8hbPXV0wySTxKbJNBlBdkzpxxqcghrCQy2gJw9kukhjIqSMRXwtnZHkg0b2bLS FVxw2hDhvcFXFp2ooSHjoIJYWmAjXhzzgK5TsNBTKr9LhocSWItsiVbq5I4a7A/5hv4K3A/miP/cb 5ochdEm7RN5sTfdffTNE/n5+3aHMchiyrQ0pbc5IBjCRDbsdeTFmloO3sreBmSqrOL2mGa6fxExXm q4ZZPUyRg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzu7-0005My-W9; Thu, 02 Jul 2020 14:09:32 +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 1jqzu5-0005LD-1j for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:09:29 +0000 Received: by mail-pf1-x441.google.com with SMTP id 67so8525778pfg.5 for ; Thu, 02 Jul 2020 07:09: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=dw71STGvxu+fI7O/Zk3vtwTxDzn/GLjAFDhUcWGe5Xc=; b=bVz9LuZsGO/IDD5tx0mwO/GA9wDMH0OssxIpGIIVA6NQvdF9JkfPcMrHxBFcn20srG yl4JGelPaYz8ej+3dImfWOs87fzpGA6PaWzpPICa0vhAJZ/ubZlHr4h2sQlNkhusEG/Y usGyTEEFFk83zaZ4FkYY/ocVsFT4knldB/oMtlC06NmaU4PTGeH0Ntk0VmA7DKJHMS/9 DOrPkGr5rH6TdQ55nepIIk6MxoAXeDj4i8wbtDdRPeydow7DY7jLX7U7iJtW/gsk8CFG 1fcIpuCFUosOvdX+FTSLaPz3vwJrWi8udrm97xEUc2EV86fG4WlfCz6oMYyxGKAvls5F KL1Q== 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=hjFRlsF6IBL5zQDiAukCff8LVsBuU1BP7s1WRplzDmyPt1D23b/ueXnxCVCBqCQUfZ +qN7ifh1u7q5PwgyKtl7TV9jSwo5fCiH0vnx7ks0DXFeQx/NnDaReiCDzjnZwyaFWsIB nBUKOjDpZgQ75NIPsSwie11dw0VQPwaOmtmJsAX5EjZZ0SH1Z7sJ89r3SHu0uzVI9mJX Y9D0aYfw3A7aa0ysNzzITB8HInGLjhgr7OymB8RcCiwxroEHKS9BFUnBd4fBSXDpkzel GEUnHq/12pEiqkI3IgIjsE1Dlx3amwFcywjvpgxLiePc8MfL/nL5SHP7jdysxohSeYmZ nk4w== X-Gm-Message-State: AOAM531JEFsAW2y2yZHN09LtNc1fMLK7ilwZ/GLnEIIspY/SHnyLLm/3 fTPQz7OkFgf1oYJw4AvMdiogAUTvrks= X-Google-Smtp-Source: ABdhPJwxvPuLs5vaKSYTcxvFHtpJ/QsfFEWMOZQe2TS/BVFBxRSZoKUSKJjK95o23Y4MbEituHCO5w== X-Received: by 2002:a62:86cc:: with SMTP id x195mr21929856pfd.39.1593698967137; Thu, 02 Jul 2020 07:09: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 k2sm9168410pgm.11.2020.07.02.07.09.26 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:09:26 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 42200202D31D41; Thu, 2 Jul 2020 23:09:24 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 13/21] um: nommu: basic console support Date: Thu, 2 Jul 2020 23:07:07 +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-20200702_100929_118071_32F7F9DE X-CRM114-Status: GOOD ( 14.85 ) 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:441 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 Jul 2 14:07:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1321486 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=yD0NU6aB; 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=I0hpZO8J; 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 49yKjb1Bl4z9sTN for ; Fri, 3 Jul 2020 00:09:55 +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=XfUDbfX4Uzbhfcp4PxS47/WQXs0MiIeZ4tlw0+p/zg0=; b=yD0NU6aBlcWYiFhmP7mcmHQnE cfCXi/4MQUzkpCtCa7w5Lt/h+jnoodpBv2/jHjMtLkxdo9JC7QDMHthZRD/++++RSklt3z+4ooad9 e7j0aBUzZ3Vj+jdT0xTCNumF4P6v1q+j4ccKJBYTz1wq4TcQhjhFrdDEXN9OQdokWClFYtp8JOuwM dwye3ZygftXVw2OjK6CXZarCssNzSK7BAFLS0DmdjZaG21YHi94u8sVn6O1ee9IrChe5gbtyemeJt Kqb277Kbj5c8TomJOfnjH4+eIHPRBO/sBH9IFmi7zbviPRGLBfe+FFKb/junnwUKrgQGq/jwIlHrF 2wCFlTzTQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzuR-0005Rt-Jv; Thu, 02 Jul 2020 14:09:51 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzuP-0005QG-0O for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:09:49 +0000 Received: by mail-pl1-x644.google.com with SMTP id j4so11366980plk.3 for ; Thu, 02 Jul 2020 07:09:48 -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=mNmV1cP3BxVauRaaBo/eHiB6+hB5AglmloLB9q7cTJc=; b=I0hpZO8J9mRhtT4V5+U0CT8dw9l00PFQZ2GhK283WSQWBUUvWIB870C/PWxRouieeZ I71k06VMFuGi8k6oH6td0ggxJ+E/m1dykZwxbP/oYHbGz2NpxG9KUi75IelxoXo+lvGA UH89CPsj+LP1MSpcdjsSU0On3NC6hzJ68qO6CN/J/J6Clt60S1DM2uoLEF6owc/cfA+c ONElxt2Se3WOC8NkELr0bxOP1grcr/aZ99ayuA0EiJbOinOizU2RXfEILTOmls8lqIar hE9vTosGvvsw2yGfMI1sVXnkiPpZB/JaNjUJQHP/reAANdJjYK1efJtifhdm6LoFL8sJ EG2g== 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=mNmV1cP3BxVauRaaBo/eHiB6+hB5AglmloLB9q7cTJc=; b=QgOPTTUi21v1W4tz4wtF+UudwxsYoQZ/q2biFJgg3hXofV0jk2evReM8dcCMMeMngz qI/AEFjZlY0qXpz6KPkUGNLk9I98Cgp+LEJLQSmtfitXcigF2jiQnLpKV/4MR/dVR+Nk DsMf6XRUkVD/7uk08NUibiqsGEu7ZXF+zVHKqqiec0qY9jPlJTBWg6JAdTgnLq6EY1qL l31gvxjhL3QFfqK1GECRnm4beGJ+eyYZb0IZfWosQFxvJviMu8nvMY+gE4b/VcDjlFQ9 kee0RPC/WFkrHWXdjcc6EetzElbl9/6teAxKpMK5hbLcgVRK/y6LV0f6DfLwXub47ioj 2/PA== X-Gm-Message-State: AOAM530ubh4Zm/DgQb8WXL8TPOacC/6we5iCW5hfS10ejHIdxbePkLSW kvX52WD9zveiT8UMeSRKiSQ= X-Google-Smtp-Source: ABdhPJxiTp208ffv2eSaZZk9buPVr4X7lGuKEw9hvBF5AhGcpWqBDFb/P/lfOZueqbFwxbr+PlFQmA== X-Received: by 2002:a17:90a:f695:: with SMTP id cl21mr33978544pjb.86.1593698986538; Thu, 02 Jul 2020 07:09:46 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id c23sm8501269pfo.32.2020.07.02.07.09.45 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:09:45 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id C8F85202D31D63; Thu, 2 Jul 2020 23:09:35 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 14/21] um: nommu: initialization and cleanup Date: Thu, 2 Jul 2020 23:07:08 +0900 Message-Id: <9463433f1d147f7a951435cab573052c01b8b3c0.1593697069.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-20200702_100949_086280_5FDA80C6 X-CRM114-Status: GOOD ( 23.06 ) 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:644 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 | 161 ++++++++++++++++++++++ tools/um/uml/process.c | 2 + 3 files changed, 177 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..25aa003792d4 --- /dev/null +++ b/arch/um/nommu/um/setup.c @@ -0,0 +1,161 @@ +// 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 = flush_old_exec(bprm); + if (ret) + return ret; + set_personality(PER_LINUX); + setup_new_exec(bprm); + install_exec_creds(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; + + fd = ksys_open("/init", O_CREAT, 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 Jul 2 14:07:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1321485 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=abmR3HrY; 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=pSOAuO5v; 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 49yKjX6fmbz9sTx for ; Fri, 3 Jul 2020 00:09:52 +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=y9+dQG/F+0seij177w1tD6Dei7IogVFBNiHJqmyq2lc=; b=abmR3HrY7vmmjUcmSPcXyiJh7 PzrRa1Tr1v3c7NI65P7HzTHm/duPu6KXv0AqDrN6g1zDeGEWvu43uKnINUSHqf2d20vYFZv8Rsr/F LixHiDd9HyTQf2Y8mMYErMzS0pBIUqqFSs8Q5dS/1KpgO0o/hYxfa9VlTanqaQWCy2mAvlycSGebA P1rqkMERYu6gMie+tDgtCtmX5GaaviUh6msYp1d2Ev3IxvEfH6fVdUK3E6q+Y4hWHLwUKd490du3t s3VxXODqXY5A1FTZU4W7+g2lQyDc48CMuJTD4K7e4611muZ77W8ERj6uYcv3VYNt72kcCzljwy4Kg BeSiUSyow==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzuP-0005RI-Dr; Thu, 02 Jul 2020 14:09:49 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzuN-0005Q0-Jm for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:09:48 +0000 Received: by mail-pf1-x443.google.com with SMTP id b16so12572302pfi.13 for ; Thu, 02 Jul 2020 07:09: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=Fp4eBcz+VBJSUXb94qX9RqU9VqAxnCk3FGCqeGyCOJs=; b=pSOAuO5vkqOstX+po4jzJ3xEK83ec8B861+DTMLDfUTJLOAnXPhw/sF12Q/SlirDWF 2MDpWjK2pgSJGUnQ238g1+hAHKSAkV93wkeYkMt2QTbBrvDEAyfdorGaw+ouaXeP1sni AGohxCnxVMGzXs/BZSa4QUPysQKFHdwLY1XMc2/+cxURockCXuE7Enmtw+Nxe3tnohaL iIEjPCC30T7QDV7wKEyqxTJSYuZzGKtksYVIwXYJAvRury31BYAs+G9sU3pTGPkgzkIV KenVnLpV+SGN8vJJEPipSa3e/yifeUNrnJfdGTqm8WRHTzt8hT8wxkKplz6nSf0NfhQx xqHw== 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=Fp4eBcz+VBJSUXb94qX9RqU9VqAxnCk3FGCqeGyCOJs=; b=cPdelXZzhgDyKQrEvgQiJ/6cfEB7Vl3QPA0atO82AcnV+yhAB7ax/+WA6hBgkBOaxJ +JhMtusrkUir8E16gBRXSwpw0J71E3Ot+f6TlanjXaNGGWiOCWrylJFU0GZLcCKx9zko N/rJjyBq5r4RgtYgmHksW3tUQXNB8ddBaLRNrIJNnHcVJXcI+ITuBscgMy8Bl8Xpl4rZ HX722osiLx/2I9roVggPJsKzhtcJwRyEFM0tq0zQhRXCHXkLuVJohQK0PMdTsYOtK7cm hZVQgjf6Ad/zkA+xCXpuyKu6oXaA489peZ17ObDPFr5QlJfNN3oaUE8oOh/CZWRXFNIi veag== X-Gm-Message-State: AOAM531C2I/rO2Pg7RoqgS1ngyjHNvuT31jr5Nz/iVPxkvkgMXCZDOTl zDAkWLyrhGmcxuT1nwwvbGplz7fUtB8= X-Google-Smtp-Source: ABdhPJw1ZXu0Ak3pc4PAoS5VTV8xN6IZMQekArYiyhk+PW7zC0/0vGgGydzcKMIZE6ydywmrKvG1Rw== X-Received: by 2002:a62:768d:: with SMTP id r135mr3150189pfc.198.1593698985663; Thu, 02 Jul 2020 07:09: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 s22sm8803077pfm.164.2020.07.02.07.09.44 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:09:45 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id DF565202D31D67; Thu, 2 Jul 2020 23:09:42 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 15/21] um: nommu: integrate with irq infrastructure of UML Date: Thu, 2 Jul 2020 23:07:09 +0900 Message-Id: <46164d4abcb2b44e3c8c35205a8a4c4017beae27.1593697069.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-20200702_100947_680059_A753A5DC X-CRM114-Status: GOOD ( 17.36 ) 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:443 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 25aa003792d4..f74baea50bd3 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 Jul 2 14:07:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1321487 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=dYJkTucn; 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=AjPPMx1p; 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 49yKjn2mXsz9sSt for ; Fri, 3 Jul 2020 00:10:05 +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=FSDFJC0nhoHlZXaDcdX6mdzFEzIc51Wbliln9imwCSs=; b=dYJkTucnza15M69lLssNFqNKQ eF7myDoVXPeQhM4qLSR5FFzIUjAAMbo5KoCMMfw6QG1CLsovx0ISBCJBz8qXoVl2JvDThI38L6d8f SUNfhmoCazn77bdxsfCEwYZ3CPb4ZoI/LdYPvcixPq3h2iZT1OIOIOtuTTIg9YjB7yDOtUxlln0mx OrP6ho2ByMyTZJPx9q0XPEkrtbiJK9pv6gtVsXhhQP1vhPpv00eRLOp3ZqlaBRxX/rNFpvFJcF2hp tintRU7PhmAnVmv4NueiM4fE2aU7H57DLIHIgxreLlVAVL3dxRwKG+sS2QTpdv5rRvK76Fg/9ymWu umTI3cFdQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzuc-0005Uk-3p; Thu, 02 Jul 2020 14:10:02 +0000 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzuZ-0005Tn-OK for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:10:00 +0000 Received: by mail-pj1-x1043.google.com with SMTP id k71so8997147pje.0 for ; Thu, 02 Jul 2020 07:09:59 -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=s06eDbFMdTfJuaWKkH/3pip2KM/bwFLmjJ0l8Otw0LQ=; b=AjPPMx1pp/0pkISEaOws0SROcHRbwhc4FqRdr4jbUgmCeWAN5tszMbxaoROoWO4Pq1 5huTPwAK8MAYZttt0jqbpLCE5gjJFpXTVPgDXHBL8HAgLt+qflDv0TY3QUflhLpOyu9q wmaRwy0/BQ0TtGsCtaeIIhpiaTbcbZmIlImlQxcXj68CJxW2rOjqDgH2lee2KJE4XtsV EXk7dYg34qEZbaHWLwhzAptsiCoPrtK/8wE1H2NMxVpdTgCgW6g7SMqa3Qy9BrAhEoAH W0ZT3GI6Uj3Tz0eM8g6tpT5EmnCgh/KH54IqEHk0xpyqar+eAqtg9DjkOdQbgJqJj6k3 L+Dg== 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=s06eDbFMdTfJuaWKkH/3pip2KM/bwFLmjJ0l8Otw0LQ=; b=F2p/tbmmn6x0ONffM9kistfunmpeWPQAhLElMOFn6cLk+93KQECMS9NIBfp3w9bFEL jQSPqM7P6kmslHK956qCLYHtOWcAsj5/Ho4vI9L4om7VLYnXgom6+3TyN7t3UMtGUSwT l8vF9RKjPkxRjiin0RAMKWgM0HBiTaum4xBS0d43MPsTWSXOnJjWrXwkLAAbeE5kzA64 EBulhF3ycXV9KXtzzCQuvIrqzEsrvvlzZyWmMGBkqtNA0kyd38lmOwzR6sAMfYsJAS1r JotGZye5I1P1e93g81mSPGnmXMUG0aybzmsXyxTre5Nxp3hpjM5UgEb1coFEg82a2y14 CO2A== X-Gm-Message-State: AOAM533arGngRUQ5XHGxg1k3vFwEYE5XOlPrC0DIJ//xesiWcdsbIjZc AqF88iH0bRv4kpLqhPyZltU= X-Google-Smtp-Source: ABdhPJyCcj1fyhNcXmRGbU1rM5RT2olrnmQ1on+uMjeHsjtucdHpZKCxacYC5lzzYJNrB90gOaT6DA== X-Received: by 2002:a17:90b:4d06:: with SMTP id mw6mr35295574pjb.190.1593698997826; Thu, 02 Jul 2020 07:09:57 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id a30sm9715503pfr.87.2020.07.02.07.09.56 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:09:57 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 6BE0C202D31D7D; Thu, 2 Jul 2020 23:09:55 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 16/21] um: nommu: plug in the build system Date: Thu, 2 Jul 2020 23:07:10 +0900 Message-Id: <085edc196a41b3a2c895722b7d7fa209a7e23396.1593697069.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-20200702_100959_915808_6DD929DE X-CRM114-Status: GOOD ( 16.24 ) 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:1043 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 a0a9fd3ab96c..300fcc90cff3 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 af0cf64c1428..7e640e65a80e 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 Jul 2 14:07:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1321488 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=E01uv09a; 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=rdLCXj4D; 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 49yKjw64Xjz9sTV for ; Fri, 3 Jul 2020 00:10:12 +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=E01uv09aOlMISUQ5XjfRMZj90 WLLbGtWSzklpqWpm56+1hDpiGgREt7H4qF4ZrG8aUgppnhZZn7WdzDzawJIQ5l8LnK5K3A2s7sToc sje9WmRpG2r+fLd/2frMopUrc/he+OlylKPaUV+LwkAsvMTLxu2EmRYlkuTe5jZDZnm6PRd1zi7sK Xh2Zmv78hnXxxGw+M6v5KjyF+YH2X7yX55zoLJvhCss5xdI5BwIT5oXkssy4exT+Ibw2ScSyjEdbz R3vCDo3kvUM58t8sfTXIgwgv2KpCXlDZ0fz13QbSexLiuloMDALTELurlp21SuDPRoQSvP1D/66F1 g6wJ3zNRw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzuj-0005Wn-Hb; Thu, 02 Jul 2020 14:10:09 +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 1jqzuh-0005Vp-6L for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:10:08 +0000 Received: by mail-pl1-x641.google.com with SMTP id f2so11358737plr.8 for ; Thu, 02 Jul 2020 07:10:06 -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=rdLCXj4DqlbBGPfEeu0fxp0rbywJfXzD/xhv4yNjU6w0S8CIJKcqfX2I3Se3pSJgFx K5SoUFwXS8ODkC+38bYpvj27kfK8JEcGY9WxzXvl36LcYTRkuAml2JCoxTyTXQ58FjYc s9kdxBkRPvzVBVdPucdGDtMy0+JTg+Zi6H0wStZIwFU0tjcgAngC4ayvBtGkOgLLjr8G uahRu6tvDoWToSafeGeyB/lZZYKVN79QwVSvUVcpZfI7qZNBjfW2IwThhFqJuI9cePA2 iWkbRrg2Sbp6pqDc4s1WAfoGwurH3BYdtABXP/DL1IkOc8QpZyFvX+z2U9pjIMPJoBJ2 PjiQ== 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=sv4Xg8EJITi7YppQ5yfE7UhprX1d97jW+uH0yENUQfKsTCjKzqti3eSP/OD355mK7X AtzaikUAFtq6/lE7AcfwiBDErVohxaPPmcymNuYmuq6AqcCCbVW1hrYMAnAL/urTCw9+ WyGKRwnKYZDKDWRo9thva/pI67sx7RC9JaV5Y3NVq1t5oUZvRVBcOewCMzsGBtrM+x0f 9cTrQPxSw3p0dMCE2G46G9MM9nNCZ9zHrr/o/ehjYCWEe5JMMrKIqyVO5FUUFLI/987+ 1a7sQeua5Ku21UUrUtvPUrL57XN8u73Bk2kIfvet0xXitjOCYEuNSGv1kX0jmlGq22dH JiHw== X-Gm-Message-State: AOAM531nibwxc3vUMdOh4yt/Em/bz6I/CF6vQ990SxXyeREYgcoVaFqA eFYtSMGrFTqetUV2nUOVnsc= X-Google-Smtp-Source: ABdhPJyjY+xTMIGEoF/+tIEGDBT1l/Xu7Wvuqe1dt/iBNaBYb0aj7Hm5kbOU2j65R6rF9FnWSjFLIw== X-Received: by 2002:a17:90a:8b09:: with SMTP id y9mr33006359pjn.90.1593699004679; Thu, 02 Jul 2020 07:10:04 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id 7sm9101774pgw.85.2020.07.02.07.10.03 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:10:04 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id AA5D1202D31D7F; Thu, 2 Jul 2020 23:10:01 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 17/21] um: host: add nommu build for ARCH=um Date: Thu, 2 Jul 2020 23:07:11 +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-20200702_101007_283186_4E069C46 X-CRM114-Status: GOOD ( 17.05 ) 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_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 Jul 2 14:07:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1321489 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=IOyhXoyV; 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=VIVHnUqY; 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 49yKk42H0Zz9sTv for ; Fri, 3 Jul 2020 00:10:20 +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=IOyhXoyVlj8ZmLLza8ifbEDwx XeYcJoLCpvrvjyK0KnGKrFXzHboodrapkfhdSjNWNDUlVDNisKlfYwBQI/22Htfj39e50lRKNPsQv 7NBFumb9Xcqwb/rQfe44gF0rKGn5YM5NhjFHbKC3Da8p+INbH0Ht+GyqdzXeRTnJj52ysetesXCky b5IG/BEL6lAulbe/js+xmUIGOlTiMxVzIdv/unDG8vAHzbmpIQwvHOsYqU8fqoekzu+WtH65LUZe1 9tYBEEX0/LpWiMpxqNvgDIEY3O79gsIjlHCTDmfLPjzWglSkFmEJRMJcPMMi2jnwpOi0yl5vubTbp 3ig3IrmGA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzur-0005Yj-0Q; Thu, 02 Jul 2020 14:10:17 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzun-0005Xb-Cl for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:10:14 +0000 Received: by mail-pf1-x42a.google.com with SMTP id j12so12587454pfn.10 for ; Thu, 02 Jul 2020 07:10:12 -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=VIVHnUqYrvv7O/Ctq1E5DxdXqnWXeBucRsN6ZqqGmZJ6xgpsR8MAvsGFiTLktxQs9O fug9UG2UtAze2ZkalbcwJ/c46+jn7uBwS5N/FByRK1Z8GevP0NfKEMfBEWiDgmCu6oF9 4AcUoknJS0H1IR7Z+8D0dFJx4q4ML/PtV8gjT0jT36Oyh9frYkQIlk0Alh+1Pf2meVnT lkM9HT+JpzD6Bx/rLfgnlDRRPBBczjqwRmO2jKqlRFFOuafHWz916oe167UqBzRr8Xpk s/wNGYA6TVyP++O2Pv/JA56p73CBGCkUp8Nqj1vwo4qv77M7zeS3It7i3KmsBTlYiGDo 06yQ== 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=tVVHbKiVUQSd3kDDqxyuny/8MSbe/4hZ1g8qm8+HM65EudVz8y7a1bGcL28T92Uesj lq14TlskPVYcgUETadSKW3UxFMz8msyfdYXMSXYtlUkqqz2JmIdlEtl6muXLixC8rw2H A7NUVI1rTVM/01zdOVeJqF/oL2EK9jLHx61+O4XL1DtiAEgFnEfwdeITWnH1rOCVeOjj L76rf9w895nVKjAYjLBrQIiAoyrfRSAgerRTshlh4tQB3ShjB+ig9Ltd+oTmqThuqdsm A2zeZRz3NF6myDzZylyJzMHiD7ig6N+JH545mrEJ8jAhmJ0cPMw0C7hxSVX0WDsGHOPJ E7Pw== X-Gm-Message-State: AOAM531uTd3zKnxY9C2JjICZ1nqUZCyTsC3dC0DBH+RNrim5UD7MLoQu nW7P69nkcRWw7TsAISfb9OA= X-Google-Smtp-Source: ABdhPJz7U5QvBa+ncu6bSubTqmnhlWnP/aWyvqWvergcpAVltgWUDenIeHxOsd7CKNWl5uAOqR/YZg== X-Received: by 2002:a63:6ca:: with SMTP id 193mr19530263pgg.269.1593699010900; Thu, 02 Jul 2020 07:10:10 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id x1sm8471623pju.3.2020.07.02.07.10.09 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:10:10 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 79028202D31D81; Thu, 2 Jul 2020 23:10:07 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 18/21] um: host: add utilities functions Date: Thu, 2 Jul 2020 23:07:12 +0900 Message-Id: <43793fcbc6809210012dba55859214ca29637bf1.1593697069.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-20200702_101013_470890_EDD2AF94 X-CRM114-Status: GOOD ( 21.95 ) 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_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an 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:42a listed in] [list.dnswl.org] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 Jul 2 14:07:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1321490 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=Qnhq/P2g; 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=LCNpiDJ/; 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 49yKkG5rV7z9sV4 for ; Fri, 3 Jul 2020 00:10:30 +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=Qnhq/P2g1Teptgpz0d877sU9V cv7wrU+RZl5VbFQ5dn5usSq7PJ/kIG7xLysNTHU6W266Py2oNJzsQMIVMXcWfbMby+VFhhLh/q6BC 8pC6Mth9k2MMMIjQIuaQiFFC5pDBRTokEugH0giPoJxb8T+ZjOOm/OwHjaMsDyijYDzEtEU6JXew4 9GwuTi8L1dpKarVMqxF0R5P9Q+EL7z4jiceGzfjn86ORgujbNxrt8EdtJ+G3KRgOj8JtFEPDGcJ6X Lpah+gtlYVg44JpCWKBbmD2gzVsP4XF2ANjfPPbGL6C0hcsQa1BIbnS7m6uhX6MuQwSMVlKMcWv57 p+TG9n2RA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzuw-0005aS-JP; Thu, 02 Jul 2020 14:10:22 +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 1jqzut-0005Z8-8S for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:10:20 +0000 Received: by mail-pj1-x1041.google.com with SMTP id u8so12199744pje.4 for ; Thu, 02 Jul 2020 07:10:18 -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=LCNpiDJ/KaAd0ZPQi4BEkQklasSqb2wlfHVAYZiZPxD79xWaYuPdZj6MU/ZsiMnK0i vCqi+ht36XyfCR7yi/3h6jyYOE3ovSGhUH5YMMgfcod9pwGwYC3ToO953rMApe5cXSuc THqVtBvieyTQoZhWle33ynexoXXXpmFdh8mOh1oRHZTsCB/jmeR/Y0Pjyd3vhEtIxHvG 3vAudIJro98W57x3w0cQnSHNQcbvndvdLboX3EqhEhziXPLia8P9cj9xnqaLYXFvWxow wmD4sJqV/sJniW+iUV82sIqE6aUJb3ZNKbsnDtnRHhRCWn4OYLu6XpsvsIEU5Fb/27XB I9IA== 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=UmEMvXNPZqo4lZbZI3a+F5ZuJSyhC2IPz2gKQaOohfzfFPnZT1NM8CTE6iDho1qTRy TSbjNvXmQa+O2kBo1JBCTDpku1T2FhuR8Gma4UIkpDEiYaN782Yy6mYe8nh/fWX8NmOU isU0mVTYyV171w7+5mo01PoilkaZpGjfg302fuL3Ic5tp5434pX1X3IUWgEbqK4KLzCH Xj8Y3nyPhpEU9A1+1NOzvdUWMT34oBSLxkXBNAeVjrKdVhe6X9twIqy8A5LsMDiUpq0f TeInQW6uvYsO+oUg1OCvirs/zA7RczPjmpqEYXghkbgytKX87sIWE434+z5mexD4sa1w 4N7g== X-Gm-Message-State: AOAM532dCKf7zCgQl6bUuGnWw5ExMtgUaOiH/GCpeR7T6IUcD+wj7F5D 4MO7QDneehZDWkbdrVb5AH4= X-Google-Smtp-Source: ABdhPJxXM7jliXWULuCpyI2wyiKmT3IYgUr98jmEcS4g9J29k9SCWT3wSbwT7U6T5FgKKQUQ3LqyMw== X-Received: by 2002:a17:902:be0e:: with SMTP id r14mr1133877pls.309.1593699016861; Thu, 02 Jul 2020 07:10:16 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id b21sm9225255pfp.172.2020.07.02.07.10.15 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:10:16 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 2A5CE202D31D85; Thu, 2 Jul 2020 23:10:14 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 19/21] um: host: posix host operations Date: Thu, 2 Jul 2020 23:07:13 +0900 Message-Id: <4bfa3679f685f3c0d731f7d95e826f4c7d6bddb6.1593697069.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-20200702_101019_337596_0F2225BB X-CRM114-Status: GOOD ( 18.52 ) 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_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 Jul 2 14:07:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1321491 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=aUfpiJtI; 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=IL2GQRHe; 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 49yKkS3cS1z9sV4 for ; Fri, 3 Jul 2020 00:10:40 +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=aUfpiJtIy1BYsOocMqy1YvQa2 AJZ5KOuOd1nBqg4CH7X7/cXX2ACJh2OBXXufIKBXmAQj9h9svxPeNIsuMIGZC9bLkjiMBcvl+diw9 /IOpGLZXBFOaB0SFvNIswsLptpIAbiDcLsolFtLUEDqrtqoJBjupYRBxiL4MzDZ2EhJOipO9CaSDm g943AZJoD5ySWYUS4JO/0TzYTOIOzcgDGc1I8TG8jPf56JPRCORCCuKCU5lcFvWCLPEEZd9lGEPfn 749zeJztbFMkbaVuNvdzZNBHlfWJ2KWmfuZdcYKcnnOXTNg58/qkoAonaiMl6fCsZzCI5W0PRfgSX 7tZd/9law==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzvB-0005ex-9H; Thu, 02 Jul 2020 14:10:37 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzv8-0005dq-5A for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:10:35 +0000 Received: by mail-pl1-x62a.google.com with SMTP id bj10so6135055plb.11 for ; Thu, 02 Jul 2020 07:10: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=LiuoON0vA+8EvA5WeEv/es1B+giSpzDkr4atmJEqcWI=; b=IL2GQRHecAKsvLJRvJFtoWWQrizjvG6fVSRtQDeVDEbyeHL9Wy4fM4hI07JLBVZmXY gLfTrvIr6ys3zYL3Bg/Wc+IJ2hhrKitD/tid9yFsV+8sb6vja0JH3LqVgVihS9dscR0W ojxb5j3GyiUsKvVeYlyzA0uPMKHlcVEHXIwU9WViVZdtn/RcxuR3vO5btKEd5yJ47XPh jN1sJ0pIC609uhL/tLbtp7Iby7M6qJ6JaESnJy/1SkL6FfEqWjyyrECDMBFeIIsUpeBT /bnZEdsh7e9SsgqLWhjFhCvyLhPGS8U1fHo14SIQ42d5C6TkqG8FRffhTlyc4HuAlL10 +O3A== 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=XeUYnse25g8ngGyZPlFd+YacXDHgPDrM80WTNMhWRvFgna1U7YgXOFCTHRaa6kE9Ty PXDJK53lCF05nyngk6h/0k2T+H/QRstBasdtOIA1fU5ceHoKcFNzUbXq7RCP9Rr7uBYp Gk+UCc1Wx5oiPP8IAHPPatV8td6F0ZMAjWyt9Xw2BYaxBDc/V60sJSbmZCxjZEQFVaCt XDqPxIGU0Q9jHENw3NJcsxg5dBmgNiZma7hzvjQgRBzH9L4C5egvuJPWFrS8xHVlTkO+ OC01mELKRC1pjgDGR00tqJIiHd0odhYvZ9Dw8xRZKxGzRmHJYo1+4gfNhUzd/5STriGa NgMA== X-Gm-Message-State: AOAM533CISjPOj2LdD6UXKq2993SMSRhy80eea9R5fY0Gy+GeHnLNfYg s8fVsiU/CTI9cK/rw2lJBfI= X-Google-Smtp-Source: ABdhPJyOgCC8nQL2lyw+kK4X7brPQrGyI2VTUnK3HVNbWQ/pgUgV46JqDEL+V7cig59C6JY9n3K6OQ== X-Received: by 2002:a17:902:7483:: with SMTP id h3mr22318294pll.114.1593699031219; Thu, 02 Jul 2020 07:10: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 o19sm1131857pjp.9.2020.07.02.07.10.30 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:10:30 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 0A879202D31D88; Thu, 2 Jul 2020 23:10:28 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 20/21] um: host: add test programs Date: Thu, 2 Jul 2020 23:07:14 +0900 Message-Id: <858ec896c4dbd9015c3497f751b1e1a7a2a2b57a.1593697069.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-20200702_101034_232163_F5D57F66 X-CRM114-Status: GOOD ( 24.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:62a listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 Jul 2 14:07:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1321495 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=CmpK+u2u; 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=NaD5Bkqy; 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 49yKkb39GQz9sPF for ; Fri, 3 Jul 2020 00:10:47 +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=dsM4CymrvCDczOTlz+pvRizwbQlMUUZ+FKfL4JMT3Mo=; b=CmpK+u2utdIajjxqyZISUpPjs SW3H5+XfSMF5OBVVZZzQ2Q6bfV8yBFjT/RBsTKWOZzC/kLL5YKy3/u8isG8FXcUIgL7+dDsH3R7Jd pLqdcvcvC46sbcTLwiTGJ/t9dXcg1deNihwUc9YfwHsr9AS/MztIv8mJae98oCEbrclh9BWLXagFz wg7ZmxfPJuJ+GMEI7Hfhjeud++mczVq1H/c66ZtZAznZsCv953lcaWKmaa7k6nF7HRrC3liFS2Ir1 7Q3uhSJYd34Yc3aSehMQJ2EyAk9JzlrdA9jX61nRs6iUvVP9iBkD3rXJDYmgPQHagQ0+spbeLTOE9 +7ys97Wfg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqzvH-0005gp-M7; Thu, 02 Jul 2020 14:10:43 +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 1jqzvB-0005eq-Ir for linux-um@lists.infradead.org; Thu, 02 Jul 2020 14:10:42 +0000 Received: by mail-pl1-x642.google.com with SMTP id bf7so2041059plb.2 for ; Thu, 02 Jul 2020 07:10:37 -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=/jZ9ucJgzaGJcve8HRFfOBpWerNPZMEPqCmMEElR9RU=; b=NaD5BkqyYvLFDn6GNoITIlinCqAz4KdOBUlUnKK5XFK+7P2KPDQZWQQPeZaqoPcT7s 6vgsjF+jljkD9Yo+azElq6MCeDCxAI0y584BkJZ5fTM7tY6rkP+2+sG/MO9v6b817JEN IPxKeiqpJi/07vRdBmym9xWZC5kIR/OABGQyC8gjRWmPwf61aE55bgBBTzF4KzjZGKUu E27CJo9/UGoORSDNuHtD93eRsrfGoCDKru1ZMgL2VLfRdnvEjhT552izxcGYFxZtdscX OoReCHWEuRRQtbTKATtdhEMuIyJyvyNqPZPDGFct0eUlzT8nHF8gQPIfRNDayOhmj/hT K0cw== 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=/jZ9ucJgzaGJcve8HRFfOBpWerNPZMEPqCmMEElR9RU=; b=KBcw+/IlUvjBIJQ5/tMUIe6G0N+WtXiXsaLX4Elnso7uTUf+uZr/+YPJen8bwwCUTQ J96I8KRD1CNDl/BoyTq0Ox3IrumXMAIAvRSbZ0u5YuihZsBBNu6i/zcDzXJbwbJzRwz6 PfCUxSY452owJ/V16wza01g4woMCJTVpyrgIDhT0Fjh5N7881p2wuzgudRpYxH/n5DBv NRsnWwesUI0q+SS3YfutpCSho13DIsSPHRSZOAp/r58ZXwTypxHDFc8Ek73NObBo5gr2 w0BBm5QHrLa1QUFaqFYlIOgzGFIh2kp9fyum7hZM7TohqsS4/idaYs7bTYKc1NSEWWIC SxTQ== X-Gm-Message-State: AOAM532je3Z02tqj6anSs0US3Bw1nwRZqr5lk0wrdIm0VTKfwftQyxHo SUeT6oEQZvCS0IiMEei0O5E= X-Google-Smtp-Source: ABdhPJwdU5ryu3jMiLa0NptKkIlCe5ZzDV+Iff9JbWh347n3CkRJFUOzXISUqAvkUzV4J1vIkS9u5Q== X-Received: by 2002:a17:902:bcc1:: with SMTP id o1mr26159060pls.246.1593699035178; Thu, 02 Jul 2020 07:10:35 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id b4sm8187655pjn.38.2020.07.02.07.10.33 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jul 2020 07:10:34 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 735B6202D31D9B; Thu, 2 Jul 2020 23:10:32 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Subject: [RFC v5 21/21] um: nommu: add block device support of UML Date: Thu, 2 Jul 2020 23:07:15 +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-20200702_101037_897627_5D0DB837 X-CRM114-Status: GOOD ( 29.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: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_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: Octavian Purdila , linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , Akira Moroo 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 78d6042fd2e6..ed0149821518 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c @@ -42,6 +42,11 @@ static void __init add_arg(char *arg) strcat(command_line, arg); } +void __init uml_set_args(char *args) +{ + strcat(command_line, args); +} + /* * These fields are initialized at boot time and not changed. * XXX This structure is used only in the non-SMP case. Maybe this 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 f74baea50bd3..6b49bf7a99fb 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')