From patchwork Thu Sep 24 07:12:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 1370379 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=cFbeEuzq; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=WE0nx41N; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxmY30nyCz9sTQ for ; Thu, 24 Sep 2020 17:15:51 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=rGGK3gRIBSsq/0XWrtQ1bgOOZVuKTwvtFJqX2LSZyd8=; b=cFbeEuzq3SEAUbAficn0OlBJ2 PHA5FzHd9hfQN+dhKeCZJHXo1MW2iycnST3NE0p/FM07EekDO7NoLjSTa8ywZ3PEDh31PBMVDSYWF 3GavWrC5Wcde7zipy8pl/wbVCtQALwffsBgyaOe07nGBI0YGN7Wj1NLC+1FqKWcrSE1Tf1oOENvyO f8jyryDX6xIp8tj0B2LZiBqnYEhNh6zKZYzi8E1d07XMJyp+Ro+6PxbFcR7J4DmPV8oKSqXLcrzV1 yoSSbCnn9j1JD2E4unJf0U43Rx/PM2rgbkpdU5KX8Nj/ZyvnXB/z9Z1yZBaUDC2H2izQEj+wMMzHw KqlpWBoVw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLTn-0003eS-Tv; Thu, 24 Sep 2020 07:15:47 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLLTl-0003dJ-Dm for linux-um@lists.infradead.org; Thu, 24 Sep 2020 07:15:46 +0000 Received: by mail-pf1-x444.google.com with SMTP id o20so1317855pfp.11 for ; Thu, 24 Sep 2020 00:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=imyNk/pfD/Crh/h3JilzWEWmXyUrqyB5bMwtrpzuDLg=; b=WE0nx41N26rnHl186xWg/PAGD2ArGQgS5Xc3YlKMmbP4nDDcuGJZ5UcAK5fXa9K9xm rIi9uaLtfGxHy0yqMapS2KVfs0CAnezmrtOEgJKz06hQ5nxUR67cPe7LISJL4xxTbASC w0YgOBTf6GCNQBAwrPcegcev7kogxSd5s/iPx5v7eZQdtE6pzLL49h3dbDcytYDtqFPm yx33ExwZ2/XgLeWKO8vFDnqliI/AnmU4He8PxHS9dQxRrCL53xW2NUxc1NcOIdHsEm+b Ic+CWlwhccfmHbvDSLdIm84oGNOLawD+YASVIaNRK1jhtbCz5DqjeguqCPz3uwUbHlZR omaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=imyNk/pfD/Crh/h3JilzWEWmXyUrqyB5bMwtrpzuDLg=; b=kWg9jtkhb2watAIHDJOPVBOxPkNsStcyfxiAv/fFXur4PvvB7pVrBNac6a3ZYkC22g 5I2m8arzK5rImtrimtxBbRweEWBOAYgYZc2vsANBzh34Ym4hRelxI2bIlFAnXLYLbGwB MFWi94Dvs+YXbeSGcz/LgN0VWFud6b4KDyJ7e23ZYIw5NNJ4icR3dLVbXV7UJRX7TLMo TRgtWljJMSaJtU4WmhJbFSpP4QxFLcluSrQ4VJ4TF34Ki4nBGpLr+BXpyGmAqJQ3ndFN qbOTs90zeG7Owhdla3wtecJAEDa9fFE7QkU/BewRQbVx9W/t39S9MUqDLkBf3YeBoYn+ xepA== X-Gm-Message-State: AOAM532s3NN040IZWEFnowzvwien3ijYI0lLNQL0jzLHC4W3fzdTXnox z8dZxETbme1Kw3bFNNiIiBo= X-Google-Smtp-Source: ABdhPJzFfcms7QZG3J3BosBrXJB8/VT20RwNmsl8TcTNp0i82LyTcqwG7Ll+GJZ2XO2dz4SVTE1wAw== X-Received: by 2002:aa7:9409:0:b029:142:2501:3989 with SMTP id x9-20020aa794090000b029014225013989mr3380219pfo.78.1600931743490; Thu, 24 Sep 2020 00:15:43 -0700 (PDT) Received: from earth-mac.local (219x123x138x129.ap219.ftth.ucom.ne.jp. [219.123.138.129]) by smtp.gmail.com with ESMTPSA id bx22sm1439120pjb.23.2020.09.24.00.15.42 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Sep 2020 00:15:42 -0700 (PDT) Received: by earth-mac.local (Postfix, from userid 501) id 398F22037C20D0; Thu, 24 Sep 2020 16:15:40 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com Subject: [RFC v6 15/21] um: nommu: integrate with irq infrastructure of UML Date: Thu, 24 Sep 2020 16:12:55 +0900 Message-Id: <7ec39a8cb91902ff2cdb22f9143f3449f9f9d009.1600922529.git.thehajime@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200924_031545_516505_C067B619 X-CRM114-Status: GOOD ( 19.65 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:444 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tavi.purdila@gmail.com, linux-kernel-library@freelists.org, linux-arch@vger.kernel.org, Hajime Tazaki , retrage01@gmail.com Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org In order to cooperate with UML's irq infrastructure and nommu threads based on host threads, irq handlers shall synchronize the our scheduler which is controlled by struct lkl_cpu. To do that, the irq infra notifies its entry of handlers by obtaining cpu access of thread scheduler (lkl_cpu_try_run_irq) and its release (lkl_cpu_put). In additon to that, in order to stick the signal handler's thread to the one of the idle thread, several required configurations of (thread's) signal mask are added: otherwise handlers running on arbitrary thread cannot obtain cpu access and immediately fall into pending interrupt which may slow down the delivery of signals. Signed-off-by: Hajime Tazaki --- arch/um/include/shared/os.h | 1 + arch/um/kernel/irq.c | 13 +++++++++++++ arch/um/kernel/time.c | 2 ++ arch/um/nommu/include/asm/cpu.h | 3 +++ arch/um/nommu/um/cpu.c | 17 ++++++++++++++--- arch/um/nommu/um/setup.c | 5 +++++ arch/um/nommu/um/threads.c | 3 +++ tools/um/uml/signal.c | 12 ++++++++++-- 8 files changed, 51 insertions(+), 5 deletions(-) diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index f467d28fc0b4..0da3ce22e16f 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -241,6 +241,7 @@ extern int set_signals(int enable); extern int set_signals_trace(int enable); extern int os_is_signal_stack(void); extern void deliver_alarm(void); +extern void set_pending_signals(int sig); /* util.c */ extern void stack_protections(unsigned long address); diff --git a/arch/um/kernel/irq.c b/arch/um/kernel/irq.c index 3577118bb4a5..4ce7f5fef7f8 100644 --- a/arch/um/kernel/irq.c +++ b/arch/um/kernel/irq.c @@ -19,6 +19,7 @@ #include #include #include +#include extern void free_irqs(void); @@ -541,6 +542,11 @@ unsigned long to_irq_stack(unsigned long *mask_out) unsigned long mask, old; int nested; +#ifndef CONFIG_MMU + if (!nommu_irq_enter(ffs(*mask_out) - 1)) + return 1; +#endif + mask = xchg(&pending_mask, *mask_out); if (mask != 0) { /* @@ -557,6 +563,10 @@ unsigned long to_irq_stack(unsigned long *mask_out) old |= mask; mask = xchg(&pending_mask, old); } while (mask != old); + +#ifndef CONFIG_MMU + nommu_irq_exit(); +#endif return 1; } @@ -594,6 +604,9 @@ unsigned long from_irq_stack(int nested) *to = *ti; mask = xchg(&pending_mask, 0); +#ifndef CONFIG_MMU + nommu_irq_exit(); +#endif return mask & ~1; } diff --git a/arch/um/kernel/time.c b/arch/um/kernel/time.c index 25eaa6a0c658..9e141fe8fe27 100644 --- a/arch/um/kernel/time.c +++ b/arch/um/kernel/time.c @@ -597,11 +597,13 @@ static struct clock_event_device timer_clockevent = { static irqreturn_t um_timer(int irq, void *dev) { +#ifdef CONFIG_MMU if (get_current()->mm != NULL) { /* userspace - relay signal, results in correct userspace timers */ os_alarm_process(get_current()->mm->context.id.u.pid); } +#endif (*timer_clockevent.event_handler)(&timer_clockevent); diff --git a/arch/um/nommu/include/asm/cpu.h b/arch/um/nommu/include/asm/cpu.h index c101c078ef21..c52a78c77bea 100644 --- a/arch/um/nommu/include/asm/cpu.h +++ b/arch/um/nommu/include/asm/cpu.h @@ -10,4 +10,7 @@ void lkl_cpu_wait_shutdown(void); void lkl_cpu_change_owner(lkl_thread_t owner); void lkl_cpu_set_irqs_pending(void); +void nommu_irq_exit(void); +int nommu_irq_enter(int sig); + #endif diff --git a/arch/um/nommu/um/cpu.c b/arch/um/nommu/um/cpu.c index 9986a3f8c5dd..75d8bdc1847e 100644 --- a/arch/um/nommu/um/cpu.c +++ b/arch/um/nommu/um/cpu.c @@ -8,15 +8,16 @@ #include #include #include +#include void run_irqs(void) { - panic("unimplemented %s", __func__); + unblock_signals(); } -int set_irq_pending(int irq) +void set_irq_pending(int sig) { - panic("unimplemented %s", __func__); + set_pending_signals(sig); } /* @@ -174,6 +175,16 @@ int lkl_cpu_try_run_irq(int irq) return ret; } +int nommu_irq_enter(int sig) +{ + return lkl_cpu_try_run_irq(sig); +} + +void nommu_irq_exit(void) +{ + return lkl_cpu_put(); +} + static void lkl_cpu_shutdown(void) { __sync_fetch_and_add(&cpu.shutdown_gate, MAX_THREADS); diff --git a/arch/um/nommu/um/setup.c b/arch/um/nommu/um/setup.c index eaa74d771f73..922188690139 100644 --- a/arch/um/nommu/um/setup.c +++ b/arch/um/nommu/um/setup.c @@ -36,6 +36,8 @@ static void __init *lkl_run_kernel(void *arg) panic_blink = lkl_panic_blink; + /* signal should be received at this thread (main and idle threads) */ + init_new_thread_signals(); threads_init(); lkl_cpu_get(); start_kernel(); @@ -58,6 +60,9 @@ int __init lkl_start_kernel(struct lkl_host_operations *ops, if (ret) goto out_free_init_sem; + change_sig(SIGALRM, 0); + change_sig(SIGIO, 0); + ret = lkl_ops->thread_create(lkl_run_kernel, NULL); if (!ret) { ret = -ENOMEM; diff --git a/arch/um/nommu/um/threads.c b/arch/um/nommu/um/threads.c index 3e70eccc191a..df96057100fd 100644 --- a/arch/um/nommu/um/threads.c +++ b/arch/um/nommu/um/threads.c @@ -151,6 +151,9 @@ static void *thread_bootstrap(void *_tba) int (*f)(void *) = tba->f; void *arg = tba->arg; + change_sig(SIGALRM, 0); + change_sig(SIGIO, 0); + lkl_ops->sem_down(ti->task->thread.arch.sched_sem); kfree(tba); if (ti->task->thread.prev_sched) diff --git a/tools/um/uml/signal.c b/tools/um/uml/signal.c index b58bc68cbe64..2b5c98de21cd 100644 --- a/tools/um/uml/signal.c +++ b/tools/um/uml/signal.c @@ -218,8 +218,8 @@ void set_handler(int sig) sigemptyset(&sig_mask); sigaddset(&sig_mask, sig); - if (sigprocmask(SIG_UNBLOCK, &sig_mask, NULL) < 0) - panic("sigprocmask failed - errno = %d\n", errno); + if (pthread_sigmask(SIG_UNBLOCK, &sig_mask, NULL) < 0) + panic("pthread_sigmask failed - errno = %d\n", errno); } int change_sig(int signal, int on) @@ -355,3 +355,11 @@ int os_is_signal_stack(void) return ss.ss_flags & SS_ONSTACK; } + +void set_pending_signals(int sig) +{ + if (sig == SIGIO) + signals_pending |= SIGIO_MASK; + else if (sig == SIGALRM) + signals_pending |= SIGALRM_MASK; +}