Received: by 10.223.185.116 with SMTP id b49csp5500367wrg; Wed, 7 Mar 2018 12:53:39 -0800 (PST) X-Google-Smtp-Source: AG47ELuQwWcLvJhBlaPHsM3TRfIeJ1V772pPuHltXJbK5tnTJFgmTDkzlRxwPhlG3kMXBeXiaErj X-Received: by 10.98.192.74 with SMTP id x71mr23546280pff.21.1520456019502; Wed, 07 Mar 2018 12:53:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520456019; cv=none; d=google.com; s=arc-20160816; b=HLyUwccDNpQvELAF42P6UOjL77xw0V4+hYYKqjgaclvN1nXBgV6OiUkttyiew7PVph RPnMhL8JqyG8VLJ2nvNLVI8b3vmuVuKL2gDnuBLj1pr7sniSuu5tvst9CVeVTV19XH5M tAySqF827XDIPES+E3S5JkMnMkduhiVA2/PYOnIMQzW6HIu2soJBl7fJFnf6DWjh4syG 3JnR7Nk4dP0mEVVBYB0SeCGot/Pn64Vacq5weZr9PsXVklv0h+MaNqTfUwadt0UY4yFh VjLuK7aEJAdYXq49wdwTUgCM9QDbP1MBlsdGan4qxL3k3PEWeVn+Fzr+WcUoW0fZPodd lszQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=NmLXz9TWVlREB/XBud/nVBsZ/1ZbLKQlLecrVLzWbF4=; b=vykE5c8OjQ+1uPqgoOeelBY8BEIr36ximeNZ25h3dduAEvWBRQXrL2IoDX3CpgpBTw stWg3OusZt9ir6wQ/Z6pQZFxrNKP3IL8kD6+yz5QB6g1YuFBjZmrNoxVUZnvmUtNzGOv /z4cVud1njao0OChznx/gySFCT4TxSe7Wd8ViHv4++VzlKRFSgkPnkUJAbZ+RX4HnspS 1N+clKJehs+/11GejZbEdbaSuZj3lyqrpC7RHrjSF9BPaCydnVRpHOkRTY/uQQp2Pm9b 4eBp4ObWYIKuE/ZSzzPP4F1c1/XRDIF8L7f6Rm2QIqbA4TFDWC0gmTRIuCtXYMaHwFnh 9J2w== 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 a8-v6si2198099pli.528.2018.03.07.12.53.25; Wed, 07 Mar 2018 12:53:39 -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 S1754810AbeCGTkX (ORCPT + 99 others); Wed, 7 Mar 2018 14:40:23 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40542 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754778AbeCGTkU (ORCPT ); Wed, 7 Mar 2018 14:40:20 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 587DBFA7; Wed, 7 Mar 2018 19:40:19 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Neeraj Upadhyay , Lingutla Chandrasekhar , Thomas Gleixner , Anna-Maria Gleixner , linux-arm-msm@vger.kernel.org Subject: [PATCH 4.15 023/122] timers: Forward timer base before migrating timers Date: Wed, 7 Mar 2018 11:37:15 -0800 Message-Id: <20180307191732.694358714@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307191729.190879024@linuxfoundation.org> References: <20180307191729.190879024@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lingutla Chandrasekhar commit c52232a49e203a65a6e1a670cd5262f59e9364a0 upstream. On CPU hotunplug the enqueued timers of the unplugged CPU are migrated to a live CPU. This happens from the control thread which initiated the unplug. If the CPU on which the control thread runs came out from a longer idle period then the base clock of that CPU might be stale because the control thread runs prior to any event which forwards the clock. In such a case the timers from the unplugged CPU are queued on the live CPU based on the stale clock which can cause large delays due to increased granularity of the outer timer wheels which are far away from base:;clock. But there is a worse problem than that. The following sequence of events illustrates it: - CPU0 timer1 is queued expires = 59969 and base->clk = 59131. The timer is queued at wheel level 2, with resulting expiry time = 60032 (due to level granularity). - CPU1 enters idle @60007, with next timer expiry @60020. - CPU0 is hotplugged at @60009 - CPU1 exits idle and runs the control thread which migrates the timers from CPU0 timer1 is now queued in level 0 for immediate handling in the next softirq because the requested expiry time 59969 is before CPU1 base->clk 60007 - CPU1 runs code which forwards the base clock which succeeds because the next expiring timer. which was collected at idle entry time is still set to 60020. So it forwards beyond 60007 and therefore misses to expire the migrated timer1. That timer gets expired when the wheel wraps around again, which takes between 63 and 630ms depending on the HZ setting. Address both problems by invoking forward_timer_base() for the control CPUs timer base. All other places, which might run into a similar problem (mod_timer()/add_timer_on()) already invoke forward_timer_base() to avoid that. [ tglx: Massaged comment and changelog ] Fixes: a683f390b93f ("timers: Forward the wheel clock whenever possible") Co-developed-by: Neeraj Upadhyay Signed-off-by: Neeraj Upadhyay Signed-off-by: Lingutla Chandrasekhar Signed-off-by: Thomas Gleixner Cc: Anna-Maria Gleixner Cc: linux-arm-msm@vger.kernel.org Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20180118115022.6368-1-clingutla@codeaurora.org Signed-off-by: Greg Kroah-Hartman --- kernel/time/timer.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1886,6 +1886,12 @@ int timers_dead_cpu(unsigned int cpu) raw_spin_lock_irq(&new_base->lock); raw_spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); + /* + * The current CPUs base clock might be stale. Update it + * before moving the timers over. + */ + forward_timer_base(new_base); + BUG_ON(old_base->running_timer); for (i = 0; i < WHEEL_SIZE; i++)