Received: by 10.223.185.116 with SMTP id b49csp6351423wrg; Wed, 28 Feb 2018 08:02:01 -0800 (PST) X-Google-Smtp-Source: AH8x226n4+W9rUh5guBaTklpSM5/R4d/vxX+gqdZsb52Gv3+JQ3eZIrdjAnMO35DsiotgpP0YwSW X-Received: by 10.99.39.131 with SMTP id n125mr14562978pgn.292.1519833720983; Wed, 28 Feb 2018 08:02:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519833720; cv=none; d=google.com; s=arc-20160816; b=zH4MHJGeKkFrHdO8Ms2YMRX7pYP+ItnIe3MEau4F9X41V3KAgv3NCSC1ey7yOkkMgH vO2+a5SGQWvwHFETKnNLfSDG5526ERI+yAp7XYyTZIDl5zO1FP0x3UzWrY9XBKyW7ORy dXyinR0+97Pe3Xtc4ez7LHqh9esb6n5SFmTNs20jjb833qAKWD3Xvbk4aucoc5HRcTRE +zpYcrrUIeyQtnT3IrQusgia1p6SfunmsBpUmHHJu2xutnjs2SYRB9vcxyjkx40DrETs 4X/IcGyoAAKCKODTo1tafMl8roU6g3VH/ncuL2RZiV/VLOXqDNjLRIpf1pLrGDS3arTr 9awA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=C1bGcVnqo6iOqjqEQjNneaCpl5eSwxp0zOFVMNK1fq4=; b=QnfJ7Zkr1sUHq8dYfWaWpClBX/RgA238RQ/7V9N/oP/JNfx6KGS4Fr1QHtGGUdIMUg Mb4Wb7aZHELyiaGGQppcBUszFyXtQwmcPzrVJA9O2hPPHwSfcSQvymAQc5BPA2kN187k xMXZqQrxohwrRGYK/2TtYayMhPx/gzbBlp94D4zr6F1nA609I7L2Nt/4EhZNRLZGGxr8 Rb8tTpJq5LKfTcE11wfYMtAcF8YCE2BuaVKqEuhFwrd6skEZUBjOp2B8NrFtR6g0yr52 rchybbSMNrizMdkqoEjxOP5Dlg/oWaUPAKNJSEVcdkmJsiy5z+XYAfuneRm0cvBk/V+c o+HA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d23-v6si1476350pli.384.2018.02.28.08.01.44; Wed, 28 Feb 2018 08:02:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933049AbeB1QAr (ORCPT + 99 others); Wed, 28 Feb 2018 11:00:47 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34681 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932458AbeB1QAn (ORCPT ); Wed, 28 Feb 2018 11:00:43 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Yr-0006Xi-OA; Wed, 28 Feb 2018 15:22:29 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yh-0000A8-UI; Wed, 28 Feb 2018 15:22:19 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Sebastian Siewior" , "Thomas Gleixner" , "Anna-Maria Gleixner" , "Frederic Weisbecker" , "Peter Zijlstra" , "Sebastian Siewior" , "Paul McKenney" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 147/254] nohz: Prevent a timer interrupt storm in tick_nohz_stop_sched_tick() In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Gleixner commit 5d62c183f9e9df1deeea0906d099a94e8a43047a upstream. The conditions in irq_exit() to invoke tick_nohz_irq_exit() which subsequently invokes tick_nohz_stop_sched_tick() are: if ((idle_cpu(cpu) && !need_resched()) || tick_nohz_full_cpu(cpu)) If need_resched() is not set, but a timer softirq is pending then this is an indication that the softirq code punted and delegated the execution to softirqd. need_resched() is not true because the current interrupted task takes precedence over softirqd. Invoking tick_nohz_irq_exit() in this case can cause an endless loop of timer interrupts because the timer wheel contains an expired timer, but softirqs are not yet executed. So it returns an immediate expiry request, which causes the timer to fire immediately again. Lather, rinse and repeat.... Prevent that by adding a check for a pending timer soft interrupt to the conditions in tick_nohz_stop_sched_tick() which avoid calling get_next_timer_interrupt(). That keeps the tick sched timer on the tick and prevents a repetitive programming of an already expired timer. Reported-by: Sebastian Siewior Signed-off-by: Thomas Gleixner Acked-by: Frederic Weisbecker Cc: Peter Zijlstra Cc: Paul McKenney Cc: Anna-Maria Gleixner Cc: Sebastian Siewior Link: https://lkml.kernel.org/r/alpine.DEB.2.20.1712272156050.2431@nanos [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- kernel/time/tick-sched.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -527,6 +527,11 @@ u64 get_cpu_iowait_time_us(int cpu, u64 } EXPORT_SYMBOL_GPL(get_cpu_iowait_time_us); +static inline bool local_timer_softirq_pending(void) +{ + return local_softirq_pending() & TIMER_SOFTIRQ; +} + static ktime_t tick_nohz_stop_sched_tick(struct tick_sched *ts, ktime_t now, int cpu) { @@ -545,8 +550,18 @@ static ktime_t tick_nohz_stop_sched_tick last_jiffies = jiffies; } while (read_seqretry(&jiffies_lock, seq)); - if (rcu_needs_cpu(cpu, &rcu_delta_jiffies) || - arch_needs_cpu(cpu) || irq_work_needs_cpu()) { + /* + * Keep the periodic tick, when RCU, architecture or irq_work + * requests it. + * Aside of that check whether the local timer softirq is + * pending. If so its a bad idea to call get_next_timer_interrupt() + * because there is an already expired timer, so it will request + * immeditate expiry, which rearms the hardware timer with a + * minimal delta which brings us back to this place + * immediately. Lather, rinse and repeat... + */ + if (rcu_needs_cpu(cpu, &rcu_delta_jiffies) || arch_needs_cpu(cpu) || + irq_work_needs_cpu() || local_timer_softirq_pending()) { next_jiffies = last_jiffies + 1; delta_jiffies = 1; } else {