From patchwork Wed Jan 20 02:27:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1428972 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; 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=GO4HwP7H; 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=MwW23UXh; 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 4DL8Zy4vsCz9sB4 for ; Wed, 20 Jan 2021 13:28:26 +1100 (AEDT) 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=BjegoRiyrvhESNH3IsIcY63oJ9nUuB5PlFGmO46PuRc=; b=GO4HwP7HlduumJ4LY10Xg2lTE d9vGa9lY5X8mypp7mtC4KJzcPnMCHjmBLU+UdRmV89SNCRllwCS2n7dFKrAlXVjkfupMfb8JxW6Ti Z8JDtp/ktO/J0Jxk8nXQ/cKj/s/xbnxuEMtuMmglaUcobX4PK/eaNxQ2cHFgd/Bc0FpvfJ8W4wkJB FyFbW+w2o6le7e5rGf+cd1vu83BtvOBRSmbz+ZKpUcGL3kxyKLAbcN74W0rdpD4uvVLpHJOK4dlzZ tr6FYjmnLAYpF/7tkNZC/iyDVfuY/fIbqeWS/9B8C0OzZAARTOUnynCgvuHj/C/U849FyUF2hiKXS E8mX1+3Vg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l23EI-0002BF-Ln; Wed, 20 Jan 2021 02:28:18 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l23EG-0002Ae-DT for linux-um@lists.infradead.org; Wed, 20 Jan 2021 02:28:17 +0000 Received: by mail-pl1-x634.google.com with SMTP id s15so11672825plr.9 for ; Tue, 19 Jan 2021 18:28:15 -0800 (PST) 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=KiYNYYWvR1DJ04Q8n+7+P7GfYD0bpMl9iyFLMdV2/U8=; b=MwW23UXhK95+qUbX9dKv+ny1LuKuI4qFPwTURdiuT62X9trzLAgh/4LmQ0r5pdmUPG RtukuKiTkAuwM5pSdQqZnioy2UpKgzhmv9d+mCM4Q8pcpvcuBjI8jDCsQxy87/QLYAW/ ipp858VpPl6KcLcTiPFjqJtK1pCsmFA+2q0bCP84ENrFhQ5Qw7jU+Saw9HESJSPPaKmL 1ERPNCtLM5sXlq6z9CPBMUPliU4tkCPhc2n3BoHy1HUGnAGk/ywVWJc1SVL+hobIL9y5 MtqQqNpZPZtSPu+muE6YezsjaaILjbA5eNME2yha6Vx2Dn1WRce4hPgdyppEw9gAuhpn izeg== 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=KiYNYYWvR1DJ04Q8n+7+P7GfYD0bpMl9iyFLMdV2/U8=; b=Z31Ey4BjSLJW2rXJORpWoJdK+ElCMxbRxPx7+YJWyaz08guK9D9CcOh8YhVAuuI/RI hbMx9WJu5e7RtsboZOERKYPhZhEoOiBk/HevvQPX4H8xQTJntHCsLZr2i17dMu+wMao0 jlKm8BOhuDQlHLiPZ5hxCcedmCecPavUn7nftuNIRqWjFje1sLN/EfwR7dW4+eIAgJsG zmcb2OQqsDrdJteSbO0NgnMtCNdDXgWlSMzBdqAy4Xj1ieTQDe4VrLm8DleDTLPdWv1z 1e6Cy2oKHUnNHPQYnnZnMF86ZBfOiJSKbrZQaiAi8iY4VynriiVSa7Sd3APzaz8YNCV+ iwyA== X-Gm-Message-State: AOAM533j4OAHy5h6VYM9cvgvGVG7rpO86y6n7+0m/qTLf8whxoxGq1+5 C9NRG5YIj/d+kPQAaX3s9wU= X-Google-Smtp-Source: ABdhPJxE8H83ThS9Wn2cH3rWKo/mN8mYdvteY84tmYodgeeMN+KLSe78SZ3Ijxln0HklRRfdbKYzRA== X-Received: by 2002:a17:90a:3846:: with SMTP id l6mr2922345pjf.21.1611109694121; Tue, 19 Jan 2021 18:28:14 -0800 (PST) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id y67sm382433pfb.211.2021.01.19.18.28.13 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Jan 2021 18:28:13 -0800 (PST) Received: by earth-mac.local (Postfix, from userid 501) id 6310920442D2F5; Wed, 20 Jan 2021 11:28:10 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v8 04/20] um: implement os_initcalls and os_exitcalls Date: Wed, 20 Jan 2021 11:27:09 +0900 Message-Id: <7a16b13b232b2be9daf424dcd4d14ec8c43a5225.1611103406.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-20210119_212816_478257_2C914CF5 X-CRM114-Status: GOOD ( 14.07 ) 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:634 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, tavi.purdila@gmail.com, Octavian Purdila , retrage01@gmail.com, linux-kernel-library@freelists.org, thehajime@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Octavian Purdila This patch implements the init and exit calls for host code. It uses the automatic __start_
and __stop_
variables that are defined by gcc / ld when using custom sections. Note that this patch should be merged with "um: move arch/um/os-Linux dir to tools/um" but for now it is separate to make the review easier. Signed-off-by: Octavian Purdila --- arch/um/include/shared/init.h | 14 ++++---------- arch/um/kernel/reboot.c | 5 +++++ arch/um/kernel/um_arch.c | 11 +++++++++++ tools/um/uml/util.c | 26 ++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/arch/um/include/shared/init.h b/arch/um/include/shared/init.h index fa2d3138d497..0d6de61c0f37 100644 --- a/arch/um/include/shared/init.h +++ b/arch/um/include/shared/init.h @@ -114,19 +114,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 31d356b1ffd8..dfc6194b5ac7 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c @@ -444,3 +444,14 @@ static int init_pm_wake_signal(void) late_initcall(init_pm_wake_signal); #endif + +int __weak os_initcalls(void) +{ + return 0; +} + +int __init run_os_initcalls(void) +{ + return os_initcalls(); +} +early_initcall(run_os_initcalls); diff --git a/tools/um/uml/util.c b/tools/um/uml/util.c index 07327425d06e..8a3382c47f98 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)) + (*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)) + (*call)(); + + return 0; +}