From patchwork Mon May 6 12:39:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 1095813 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sipsolutions.net Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jwQjaMAc"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44yMl94Np5z9sB8 for ; Mon, 6 May 2019 22:40:05 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=Srvu3xH6gXaerspK3BGYpmXyU3vKq8GhIXz6JM7j91g=; b=jwQjaMAcWSCkbopXl1+a1L2j++ iwGk06+hQKho3bWooPrQBGWWNgvDNbc0iBnzQJYsQ5YSBqHVP8q2X+NajCm3tLrBYs69oAxEjZ8iP Avcx74789NokwXzrfL6Gnz3u3SXEc8BTfchUO6MhvgSc9OfHLSjwx/IKEm0CMi68Bc3/ifNbh+8TW azd8gezZnkbcXy//+OS9z8PXSlO8juJhVF02tEXBEJEVDJSl2PFr1mOUmyRzh0XDgWRXjA0dGS9ds mcDYw2NRr/a0sXx0bKa12KpisSb/jEk/OGB03uXTfyiQgoBAq+IayLUPXH/NkI+yZs2tI7jwVG8ZT AgyIKm7A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hNcuR-0002hO-JQ; Mon, 06 May 2019 12:39:55 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:191:4433::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hNcuL-0002eD-7G for linux-um@lists.infradead.org; Mon, 06 May 2019 12:39:52 +0000 Received: by sipsolutions.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1hNcuF-00058d-Qz; Mon, 06 May 2019 14:39:44 +0200 From: Johannes Berg To: linux-um@lists.infradead.org Subject: [PATCH v2 1/5] arch: um: Fix IRQ controller regression on console read Date: Mon, 6 May 2019 14:39:35 +0200 Message-Id: <20190506123939.21091-2-johannes@sipsolutions.net> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190506123939.21091-1-johannes@sipsolutions.net> References: <20190506123939.21091-1-johannes@sipsolutions.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190506_053949_285340_42BE563C X-CRM114-Status: GOOD ( 14.29 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: j@w1.fi MIME-Version: 1.0 Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Jouni Malinen The conversion of UML to use epoll based IRQ controller claimed that clone_one_chan() can safely call um_free_irq() while starting to ignore the delay_free_irq parameter that explicitly noted that the IRQ cannot be freed because this is being called from chan_interrupt(). This resulted in free_irq() getting called in interrupt context ("Trying to free IRQ 6 from IRQ context!"). Fix this by restoring previously used delay_free_irq processing. Fixes: ff6a17989c08 ("Epoll based IRQ controller") Signed-off-by: Jouni Malinen Signed-off-by: Johannes Berg --- arch/um/drivers/chan_kern.c | 52 +++++++++++++++++++++++++++++++------ arch/um/kernel/irq.c | 4 +++ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/arch/um/drivers/chan_kern.c b/arch/um/drivers/chan_kern.c index a4e64edb8f38..749d2bf59599 100644 --- a/arch/um/drivers/chan_kern.c +++ b/arch/um/drivers/chan_kern.c @@ -171,19 +171,55 @@ int enable_chan(struct line *line) return err; } +/* Items are added in IRQ context, when free_irq can't be called, and + * removed in process context, when it can. + * This handles interrupt sources which disappear, and which need to + * be permanently disabled. This is discovered in IRQ context, but + * the freeing of the IRQ must be done later. + */ +static DEFINE_SPINLOCK(irqs_to_free_lock); +static LIST_HEAD(irqs_to_free); + +void free_irqs(void) +{ + struct chan *chan; + LIST_HEAD(list); + struct list_head *ele; + unsigned long flags; + + spin_lock_irqsave(&irqs_to_free_lock, flags); + list_splice_init(&irqs_to_free, &list); + spin_unlock_irqrestore(&irqs_to_free_lock, flags); + + list_for_each(ele, &list) { + chan = list_entry(ele, struct chan, free_list); + + if (chan->input && chan->enabled) + um_free_irq(chan->line->driver->read_irq, chan); + if (chan->output && chan->enabled) + um_free_irq(chan->line->driver->write_irq, chan); + chan->enabled = 0; + } +} + static void close_one_chan(struct chan *chan, int delay_free_irq) { + unsigned long flags; + if (!chan->opened) return; - /* we can safely call free now - it will be marked - * as free and freed once the IRQ stopped processing - */ - if (chan->input && chan->enabled) - um_free_irq(chan->line->driver->read_irq, chan); - if (chan->output && chan->enabled) - um_free_irq(chan->line->driver->write_irq, chan); - chan->enabled = 0; + if (delay_free_irq) { + spin_lock_irqsave(&irqs_to_free_lock, flags); + list_add(&chan->free_list, &irqs_to_free); + spin_unlock_irqrestore(&irqs_to_free_lock, flags); + } else { + if (chan->input && chan->enabled) + um_free_irq(chan->line->driver->read_irq, chan); + if (chan->output && chan->enabled) + um_free_irq(chan->line->driver->write_irq, chan); + chan->enabled = 0; + } if (chan->ops->close != NULL) (*chan->ops->close)(chan->fd, chan->data); diff --git a/arch/um/kernel/irq.c b/arch/um/kernel/irq.c index f4874b7ec503..52444be9f162 100644 --- a/arch/um/kernel/irq.c +++ b/arch/um/kernel/irq.c @@ -21,6 +21,8 @@ #include +extern void free_irqs(void); + /* When epoll triggers we do not know why it did so * we can also have different IRQs for read and write. * This is why we keep a small irq_fd array for each fd - @@ -100,6 +102,8 @@ void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs) } } } + + free_irqs(); } static int assign_epoll_events_to_irq(struct irq_entry *irq_entry) From patchwork Mon May 6 12:39:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 1095812 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sipsolutions.net Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BsETrMuN"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44yMl873lcz9sBV for ; Mon, 6 May 2019 22:40:04 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=xlw2qkF8RvGB2bc0w3wgWcNmlvks6oeSzmmKeeAfF1o=; b=BsETrMuNqnHThrbfmXN/s/kx80 Xp+V+e0p/lipTCfx7LDdlj+E0pwNEdcVUrodEuizyeaErvhw8nuopuyH50EgE5m1GHAnEuLGDkWU3 IW9tysd4EPob0DyZIt6ycItfTFGBKIPFzi5ZIa214l6EgVxp+TJkeKU4nc4SZ7znHPlE3hE0UHhUn /eRUOmQTNrvAkkrlsizAnPDsAAtEuN+ZoIDQGYVli9kjtMG/Z07001VNdY9j9kYBQ9Rpcc+ePA1mC YtCgJw/b7klPS0KGvsrtfjqOokXY2jTFIpgKZavBbKdy8VaE/fPdxJfvSapoqkdm0Y0/HFcS5BXiH VijeW0Dg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hNcuR-0002hE-EB; Mon, 06 May 2019 12:39:55 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:191:4433::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hNcuL-0002eF-7M for linux-um@lists.infradead.org; Mon, 06 May 2019 12:39:52 +0000 Received: by sipsolutions.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1hNcuG-00058d-6L; Mon, 06 May 2019 14:39:44 +0200 From: Johannes Berg To: linux-um@lists.infradead.org Subject: [PATCH v2 2/5] arch: um: use cpu_possible_mask to avoid warning Date: Mon, 6 May 2019 14:39:36 +0200 Message-Id: <20190506123939.21091-3-johannes@sipsolutions.net> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190506123939.21091-1-johannes@sipsolutions.net> References: <20190506123939.21091-1-johannes@sipsolutions.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190506_053949_285661_E19305A4 X-CRM114-Status: GOOD ( 10.11 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: j@w1.fi, Johannes Berg MIME-Version: 1.0 Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Johannes Berg Using cpu_all_mask in a struct clock_event_device leads to a warning from clockevents_register_device(), fix this. Signed-off-by: Johannes Berg --- arch/um/kernel/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/um/kernel/time.c b/arch/um/kernel/time.c index 052de4c8acb2..0c572a48158e 100644 --- a/arch/um/kernel/time.c +++ b/arch/um/kernel/time.c @@ -56,7 +56,7 @@ static int itimer_one_shot(struct clock_event_device *evt) static struct clock_event_device timer_clockevent = { .name = "posix-timer", .rating = 250, - .cpumask = cpu_all_mask, + .cpumask = cpu_possible_mask, .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, .set_state_shutdown = itimer_shutdown, From patchwork Mon May 6 12:39:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 1095810 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sipsolutions.net Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Gtrog/AN"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44yMl70N9Dz9s9y for ; Mon, 6 May 2019 22:40:03 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=jLePEk2EwyxeHPZCwxR3q9OBh9r6uLPdZVcfkmFMP8s=; b=Gtrog/ANZN7dZnBAK++S4vwh4z 9fN84bu3CdGKCiFRQFEguQPjiojS3p8HVAx18Fpwf6WBQAG/R2IzSlIUMdSQDAYsSKTZgui5NBhYW w/VQzYNrpChFO7DTZ3cymwLtFgqLY+et2IItx70TkBSYhQR6/0/hPfgvEnnjKTnZisFQq8dyjiFBt FSBri6mHJTk/LnMLzARg9znDiEGKxD8tHPpxHBPuCMYrkZpZcOiJYoTmnL/2OJk2d/i8f/lLA/vXO nPz5IRDVZa83rRlpD1CKWHKQl4QVI38/wnLzNLiBZsN/7F7arOe4Bi9RUvJol/DBGtY/7lsKkVp5D J0BR28/w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hNcuP-0002gf-3z; Mon, 06 May 2019 12:39:53 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:191:4433::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hNcuL-0002eN-7L for linux-um@lists.infradead.org; Mon, 06 May 2019 12:39:50 +0000 Received: by sipsolutions.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1hNcuG-00058d-Gz; Mon, 06 May 2019 14:39:44 +0200 From: Johannes Berg To: linux-um@lists.infradead.org Subject: [PATCH v2 3/5] arch: um: fix os_timer_one_shot() Date: Mon, 6 May 2019 14:39:37 +0200 Message-Id: <20190506123939.21091-4-johannes@sipsolutions.net> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190506123939.21091-1-johannes@sipsolutions.net> References: <20190506123939.21091-1-johannes@sipsolutions.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190506_053949_279141_B0780B8E X-CRM114-Status: UNSURE ( 8.18 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: j@w1.fi, Johannes Berg MIME-Version: 1.0 Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Johannes Berg os_timer_one_shot() gets passed a value "unsigned long delta", so must not have an "int ticks" as that actually ends up being -1, and thus triggering a timer over and over again. Signed-off-by: Johannes Berg --- arch/um/include/shared/os.h | 2 +- arch/um/os-Linux/time.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index ebf23012a59b..d579adcb2690 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -252,7 +252,7 @@ extern void os_warn(const char *fmt, ...) extern void os_idle_sleep(unsigned long long nsecs); extern int os_timer_create(void* timer); extern int os_timer_set_interval(void* timer, void* its); -extern int os_timer_one_shot(int ticks); +extern int os_timer_one_shot(unsigned long ticks); extern long long os_timer_disable(void); extern long os_timer_remain(void* timer); extern void uml_idle_timer(void); diff --git a/arch/um/os-Linux/time.c b/arch/um/os-Linux/time.c index 0e39b9978729..b28cc35da21f 100644 --- a/arch/um/os-Linux/time.c +++ b/arch/um/os-Linux/time.c @@ -113,7 +113,7 @@ long os_timer_remain(void* timer) return its.it_value.tv_nsec; } -int os_timer_one_shot(int ticks) +int os_timer_one_shot(unsigned long ticks) { struct itimerspec its; unsigned long long nsec; From patchwork Mon May 6 12:39:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 1095815 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sipsolutions.net Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="phH+3bBa"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44yMlC6pnlz9s9N for ; Mon, 6 May 2019 22:40:07 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=HamRNsN0TQe/xHwUVvoD81kNdtQlc9b4niCEg26/s1A=; b=phH+3bBaq1xYdn1iOiPXWyfONn 7LCbVkor2baM/5cOaLdBHGNVpc0lOcLiroKrPM9ITfDRh1n5wqh6/mEj9/J3/vqFzWb/p5lluTX6Z QCFCBJRE7MVKGshRLw1en21SMLWZAkW3ckONWMKp6fku+0A+/2PgeajapOlMfg8fpaJuY9ddrXsAr aNox6TPWUKa+tHYzRF1mEW9zlVIP1ZQDO/kgA01smrkK4gYXfqsuR5Dj/3oLtZzAiGRPxiSKB+ovR GceAtlUcFVbapvI5D4hX/9YhvMLQMm2xcmJgg1IItqcVj/m0rTK7WQqrofXtY2xTvOmF8SG+42jLB 81V1QwoA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hNcuR-0002hw-VW; Mon, 06 May 2019 12:39:55 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:191:4433::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hNcuL-0002ed-7K for linux-um@lists.infradead.org; Mon, 06 May 2019 12:39:52 +0000 Received: by sipsolutions.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1hNcuG-00058d-P7; Mon, 06 May 2019 14:39:44 +0200 From: Johannes Berg To: linux-um@lists.infradead.org Subject: [PATCH v2 4/5] arch: um: timer code cleanup Date: Mon, 6 May 2019 14:39:38 +0200 Message-Id: <20190506123939.21091-5-johannes@sipsolutions.net> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190506123939.21091-1-johannes@sipsolutions.net> References: <20190506123939.21091-1-johannes@sipsolutions.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190506_053949_284749_3C8F372A X-CRM114-Status: GOOD ( 16.56 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: j@w1.fi, Johannes Berg MIME-Version: 1.0 Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Johannes Berg There are some unused functions, and some others that have unused arguments; clean up the timer code a bit. Signed-off-by: Johannes Berg --- arch/um/include/shared/os.h | 8 +-- arch/um/kernel/time.c | 4 +- arch/um/os-Linux/time.c | 119 ++++++++---------------------------- 3 files changed, 31 insertions(+), 100 deletions(-) diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index d579adcb2690..449e71edefaa 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -250,15 +250,13 @@ extern void os_warn(const char *fmt, ...) /* time.c */ extern void os_idle_sleep(unsigned long long nsecs); -extern int os_timer_create(void* timer); -extern int os_timer_set_interval(void* timer, void* its); +extern int os_timer_create(void); +extern int os_timer_set_interval(void); extern int os_timer_one_shot(unsigned long ticks); -extern long long os_timer_disable(void); -extern long os_timer_remain(void* timer); +extern void os_timer_disable(void); extern void uml_idle_timer(void); extern long long os_persistent_clock_emulation(void); extern long long os_nsecs(void); -extern long long os_vnsecs(void); /* skas/mem.c */ extern long run_syscall_stub(struct mm_id * mm_idp, diff --git a/arch/um/kernel/time.c b/arch/um/kernel/time.c index 0c572a48158e..3898119f773e 100644 --- a/arch/um/kernel/time.c +++ b/arch/um/kernel/time.c @@ -37,7 +37,7 @@ static int itimer_shutdown(struct clock_event_device *evt) static int itimer_set_periodic(struct clock_event_device *evt) { - os_timer_set_interval(NULL, NULL); + os_timer_set_interval(); return 0; } @@ -107,7 +107,7 @@ static void __init um_timer_setup(void) printk(KERN_ERR "register_timer : request_irq failed - " "errno = %d\n", -err); - err = os_timer_create(NULL); + err = os_timer_create(); if (err != 0) { printk(KERN_ERR "creation of timer failed - errno = %d\n", -err); return; diff --git a/arch/um/os-Linux/time.c b/arch/um/os-Linux/time.c index b28cc35da21f..ea720149f5b8 100644 --- a/arch/um/os-Linux/time.c +++ b/arch/um/os-Linux/time.c @@ -26,11 +26,11 @@ static inline long long timeval_to_ns(const struct timeval *tv) static inline long long timespec_to_ns(const struct timespec *ts) { - return ((long long) ts->tv_sec * UM_NSEC_PER_SEC) + - ts->tv_nsec; + return ((long long) ts->tv_sec * UM_NSEC_PER_SEC) + ts->tv_nsec; } -long long os_persistent_clock_emulation (void) { +long long os_persistent_clock_emulation(void) +{ struct timespec realtime_tp; clock_gettime(CLOCK_REALTIME, &realtime_tp); @@ -40,94 +40,45 @@ long long os_persistent_clock_emulation (void) { /** * os_timer_create() - create an new posix (interval) timer */ -int os_timer_create(void* timer) { - - timer_t* t = timer; - - if(t == NULL) { - t = &event_high_res_timer; - } +int os_timer_create(void) +{ + timer_t *t = &event_high_res_timer; - if (timer_create( - CLOCK_MONOTONIC, - NULL, - t) == -1) { + if (timer_create(CLOCK_MONOTONIC, NULL, t) == -1) return -1; - } + return 0; } -int os_timer_set_interval(void* timer, void* i) +int os_timer_set_interval(void) { struct itimerspec its; unsigned long long nsec; - timer_t* t = timer; - struct itimerspec* its_in = i; - - if(t == NULL) { - t = &event_high_res_timer; - } nsec = UM_NSEC_PER_SEC / UM_HZ; - if(its_in != NULL) { - its.it_value.tv_sec = its_in->it_value.tv_sec; - its.it_value.tv_nsec = its_in->it_value.tv_nsec; - } else { - its.it_value.tv_sec = 0; - its.it_value.tv_nsec = nsec; - } + its.it_value.tv_sec = 0; + its.it_value.tv_nsec = nsec; its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = nsec; - if(timer_settime(*t, 0, &its, NULL) == -1) { + if (timer_settime(event_high_res_timer, 0, &its, NULL) == -1) return -errno; - } return 0; } -/** - * os_timer_remain() - returns the remaining nano seconds of the given interval - * timer - * Because this is the remaining time of an interval timer, which correspondends - * to HZ, this value can never be bigger than one second. Just - * the nanosecond part of the timer is returned. - * The returned time is relative to the start time of the interval timer. - * Return an negative value in an error case. - */ -long os_timer_remain(void* timer) -{ - struct itimerspec its; - timer_t* t = timer; - - if(t == NULL) { - t = &event_high_res_timer; - } - - if(timer_gettime(t, &its) == -1) { - return -errno; - } - - return its.it_value.tv_nsec; -} - int os_timer_one_shot(unsigned long ticks) { - struct itimerspec its; - unsigned long long nsec; - unsigned long sec; + unsigned long long nsec = ticks + 1; + struct itimerspec its = { + .it_value.tv_sec = nsec / UM_NSEC_PER_SEC, + .it_value.tv_nsec = nsec % UM_NSEC_PER_SEC, - nsec = (ticks + 1); - sec = nsec / UM_NSEC_PER_SEC; - nsec = nsec % UM_NSEC_PER_SEC; - - its.it_value.tv_sec = nsec / UM_NSEC_PER_SEC; - its.it_value.tv_nsec = nsec; - - its.it_interval.tv_sec = 0; - its.it_interval.tv_nsec = 0; // we cheat here + .it_interval.tv_sec = 0, + .it_interval.tv_nsec = 0, // we cheat here + }; timer_settime(event_high_res_timer, 0, &its, NULL); return 0; @@ -135,24 +86,13 @@ int os_timer_one_shot(unsigned long ticks) /** * os_timer_disable() - disable the posix (interval) timer - * Returns the remaining interval timer time in nanoseconds */ -long long os_timer_disable(void) +void os_timer_disable(void) { struct itimerspec its; memset(&its, 0, sizeof(struct itimerspec)); - timer_settime(event_high_res_timer, 0, &its, &its); - - return its.it_value.tv_sec * UM_NSEC_PER_SEC + its.it_value.tv_nsec; -} - -long long os_vnsecs(void) -{ - struct timespec ts; - - clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&ts); - return timespec_to_ns(&ts); + timer_settime(event_high_res_timer, 0, &its, NULL); } long long os_nsecs(void) @@ -169,21 +109,14 @@ long long os_nsecs(void) */ void os_idle_sleep(unsigned long long nsecs) { - struct timespec ts; - - if (nsecs <= 0) { - return; - } - - ts = ((struct timespec) { - .tv_sec = nsecs / UM_NSEC_PER_SEC, - .tv_nsec = nsecs % UM_NSEC_PER_SEC - }); + struct timespec ts = { + .tv_sec = nsecs / UM_NSEC_PER_SEC, + .tv_nsec = nsecs % UM_NSEC_PER_SEC + }; /* * Relay the signal if clock_nanosleep is interrupted. */ - if (clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL)) { + if (clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL)) deliver_alarm(); - } } From patchwork Mon May 6 12:39:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 1095814 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sipsolutions.net Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Ymriow88"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44yMlC5xxlz9s7T for ; Mon, 6 May 2019 22:40:07 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=ukElA6tVXPrNeRA0lvuKkyKLF3GYyDy8xoceT4sUFhI=; b=Ymriow88XDsYDsqZwmn+rUGRIn RG6eFlQYmCt8vlwYYAQT6A/cz7Z/8JnSA9P6AHuCiU2K9CYIkD4Lr5GcRHL+P9GWbRE7QMkQlD5B+ nCHgixeiz/9oDi1Ip8pv5c8awGoaN1Ed4cyH8AGq5G3TyPnNKbEimr7g8NykQySB3knF6ko74JQSL ZlEEYVOFxfi2jjIiKRWjDYSnZAZ80FObtkwa4n/YMTLewx5PA5XLGpsgVF41R9GL/cwYrT/OFJXSt c8EX8z2QgpDgL1TTw/wC4ihtaaLNWOsALum6uNRrHgO7Xoq3meLcQi4PFw68kZ0x7iKjJLew2FXr2 Q2PUiRYA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hNcuR-0002hd-PQ; Mon, 06 May 2019 12:39:55 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:191:4433::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hNcuL-0002ee-7I for linux-um@lists.infradead.org; Mon, 06 May 2019 12:39:52 +0000 Received: by sipsolutions.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1hNcuH-00058d-4Q; Mon, 06 May 2019 14:39:45 +0200 From: Johannes Berg To: linux-um@lists.infradead.org Subject: [PATCH v2 5/5] arch: um: support virtual time Date: Mon, 6 May 2019 14:39:39 +0200 Message-Id: <20190506123939.21091-6-johannes@sipsolutions.net> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190506123939.21091-1-johannes@sipsolutions.net> References: <20190506123939.21091-1-johannes@sipsolutions.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190506_053949_290718_BDDA11F2 X-CRM114-Status: GOOD ( 18.03 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: j@w1.fi, Johannes Berg MIME-Version: 1.0 Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Johannes Berg Sometimes it can be useful to run with virtual time inside the UML instance, for example for testing. For example, some tests for the wireless subsystem and userspace are based on hwsim, a virtual wireless adapter. Some tests can take a long time to run because they e.g. wait for 120 seconds to elapse for some regulatory checks. This obviously goes faster if it need not actually wait that long, but time inside the test environment just "bumps up" when there's nothing to do. Add a mode - CONFIG_UML_VIRTUAL_TIME_SUPPORT - to support such behavior; it needs to be enabled with the "virtual-time" option passed to the UML invocation. With this enabled, the test mentioned above goes from a runtime of about 130 seconds (with startup overhead and all) to being CPU bound and finishing in 16 seconds (on my slow laptop). Signed-off-by: Johannes Berg --- arch/um/Kconfig | 17 ++++++++++ arch/um/include/shared/os.h | 14 ++++++++ arch/um/kernel/time.c | 13 +++++++ arch/um/os-Linux/time.c | 68 ++++++++++++++++++++++++++++++++++++- 4 files changed, 111 insertions(+), 1 deletion(-) diff --git a/arch/um/Kconfig b/arch/um/Kconfig index ec9711d068b7..71ff7ef3aa0c 100644 --- a/arch/um/Kconfig +++ b/arch/um/Kconfig @@ -180,6 +180,23 @@ config SECCOMP If unsure, say Y. +config UML_VIRTUAL_TIME_SUPPORT + bool + prompt "Support virtual time (e.g. for test execution)" + help + Enable this option to support virtual time inside the UML instance, + which means that whenever there's nothing to do it just skips time + forward rather than waiting for any real time to elapse. + + Note that this changes behaviour a bit - used CPU time may not always + cause the virtual time to increase unless enough CPU was consumed to + advance the tick (HZ). + + Note that to enable the virtual time, you also need to pass + "virtual-time" on the command-line. + + It is safe to say Y, but you probably don't need this, so say N. + endmenu source "arch/um/drivers/Kconfig" diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index 449e71edefaa..a891a5665704 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -257,6 +257,20 @@ extern void os_timer_disable(void); extern void uml_idle_timer(void); extern long long os_persistent_clock_emulation(void); extern long long os_nsecs(void); +#ifdef CONFIG_UML_VIRTUAL_TIME_SUPPORT +extern unsigned long long virtual_time; +extern unsigned long long timer_expiry; +int os_setup_virtual_time(char *str); +static inline void os_set_virtual_time_to_timer(void) +{ + /* ignored if virtual time isn't enabled */ + virtual_time = timer_expiry; +} +#else +static inline void os_set_virtual_time_to_timer(void) +{ +} +#endif /* skas/mem.c */ extern long run_syscall_stub(struct mm_id * mm_idp, diff --git a/arch/um/kernel/time.c b/arch/um/kernel/time.c index 3898119f773e..0ceb7c540d60 100644 --- a/arch/um/kernel/time.c +++ b/arch/um/kernel/time.c @@ -19,11 +19,14 @@ #include #include #include +#include void timer_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs) { unsigned long flags; + os_set_virtual_time_to_timer(); + local_irq_save(flags); do_IRQ(TIMER_IRQ, regs); local_irq_restore(flags); @@ -134,3 +137,13 @@ void __init time_init(void) timer_set_signal_handler(); late_time_init = um_timer_setup; } + +#ifdef CONFIG_UML_VIRTUAL_TIME_SUPPORT +__setup("virtual-time", os_setup_virtual_time); +__uml_help(os_setup_virtual_time, +"virtual-time\n" +" Run the system in virtual time mode, i.e. bump time\n" +" forward when there's nothing to do, rather than waiting\n" +" for real time to elapse. Useful for test execution.\n\n" +); +#endif diff --git a/arch/um/os-Linux/time.c b/arch/um/os-Linux/time.c index ea720149f5b8..d37ee59cb936 100644 --- a/arch/um/os-Linux/time.c +++ b/arch/um/os-Linux/time.c @@ -15,8 +15,27 @@ #include #include #include +#include static timer_t event_high_res_timer = 0; +#ifdef CONFIG_UML_VIRTUAL_TIME_SUPPORT +unsigned long long virtual_time; +unsigned long long timer_expiry; +static enum { + TMR_DIS, + TMR_ONE, + TMR_INT, +} timer_mode; +static bool virtual_time_enabled; + +int os_setup_virtual_time(char *str) +{ + virtual_time_enabled = true; + return 1; +} +#else +#define virtual_time_enabled false +#endif static inline long long timeval_to_ns(const struct timeval *tv) { @@ -66,6 +85,11 @@ int os_timer_set_interval(void) if (timer_settime(event_high_res_timer, 0, &its, NULL) == -1) return -errno; +#ifdef CONFIG_UML_VIRTUAL_TIME_SUPPORT + timer_mode = TMR_INT; + timer_expiry = virtual_time + nsec; +#endif + return 0; } @@ -81,6 +105,10 @@ int os_timer_one_shot(unsigned long ticks) }; timer_settime(event_high_res_timer, 0, &its, NULL); +#ifdef CONFIG_UML_VIRTUAL_TIME_SUPPORT + timer_mode = TMR_ONE; + timer_expiry = virtual_time + nsec; +#endif return 0; } @@ -93,12 +121,20 @@ void os_timer_disable(void) memset(&its, 0, sizeof(struct itimerspec)); timer_settime(event_high_res_timer, 0, &its, NULL); +#ifdef CONFIG_UML_VIRTUAL_TIME_SUPPORT + timer_mode = TMR_DIS; +#endif } long long os_nsecs(void) { struct timespec ts; +#ifdef CONFIG_UML_VIRTUAL_TIME_SUPPORT + if (virtual_time_enabled) + return virtual_time; +#endif + clock_gettime(CLOCK_MONOTONIC,&ts); return timespec_to_ns(&ts); } @@ -109,6 +145,10 @@ long long os_nsecs(void) */ void os_idle_sleep(unsigned long long nsecs) { +#ifdef CONFIG_UML_VIRTUAL_TIME_SUPPORT + unsigned long long next = virtual_time + nsecs; + struct itimerspec stop = {}, cfg; +#endif struct timespec ts = { .tv_sec = nsecs / UM_NSEC_PER_SEC, .tv_nsec = nsecs % UM_NSEC_PER_SEC @@ -117,6 +157,32 @@ void os_idle_sleep(unsigned long long nsecs) /* * Relay the signal if clock_nanosleep is interrupted. */ - if (clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL)) + if (!virtual_time_enabled) { + if (clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL)) + deliver_alarm(); + return; + } + +#ifdef CONFIG_UML_VIRTUAL_TIME_SUPPORT + timer_settime(event_high_res_timer, 0, &stop, &cfg); + + if (timer_mode != TMR_DIS && timer_expiry < next) { + if (timer_mode == TMR_ONE) + timer_mode = TMR_DIS; + /* virtual_time will be adjusted in timer_handler() */ deliver_alarm(); + return; + } + + virtual_time = next; + + if (timer_mode != TMR_DIS) { + unsigned long long remaining = timer_expiry - virtual_time; + + cfg.it_value.tv_sec = remaining / UM_NSEC_PER_SEC; + cfg.it_value.tv_nsec = remaining % UM_NSEC_PER_SEC; + + timer_settime(event_high_res_timer, 0, &cfg, NULL); + } +#endif }