Received: by 10.223.185.116 with SMTP id b49csp830290wrg; Sat, 10 Feb 2018 21:26:25 -0800 (PST) X-Google-Smtp-Source: AH8x224lbb3Y57vKumAAZStcJTkyUYjkres9nrcm3q0fiJ/0I2G9O8uFd6zi+qLZlJ+EO/SKFp5T X-Received: by 2002:a17:902:61:: with SMTP id 88-v6mr7441667pla.428.1518326785385; Sat, 10 Feb 2018 21:26:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518326785; cv=none; d=google.com; s=arc-20160816; b=dnA8zZArrYdvNTrXzDPPTsBhYdyjIQBwyW0rNqgW7EB+0IbRkCtLHCHxpIXXKXt9XZ mgzI6M1plDhS0bXUI0xfrD4AjWLPkHdz6F6MS7AcrE7IexrXSmIrr6Kvnn76xMIi0hUS LW2eUYO3foCQzieH1USz3RFb83zpn59tLOekZDkTGD6HUcB8hsXb6H9uX4Z/ChZ/8lo1 7i2DLQiGxLwXYho2ISi0DpgKFLnnNUG+V+Ajtu+ise6mBBP6AlMVp8/lHA10i3HxBQfw 1NQDE6elkSDPOJ1cz/TjSRQt8Q3L5ojqlyy5OxKtMAuXIN+mo3FNsDVu2wZ2UlcXsZO6 rxbg== 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=/iyqHlqqvLdOXKMEj6CC33yyRE9EInCDg5fTG6ECJuk=; b=Acl/fJpbABp4RZ6E8rRQj58xIpiuelGUVKKZ+EgQu2zKCECKPNOhxmi7WdvafqQwPC xXaaN9mkSQRrQ8wYiiydDovqOlr3EAHyp2ZlKtvufdIjAxMpH0sW4ceprt/BtPBNp+dX vSpnlPsVVaTkmb9nlBfk16hbjiuYNBUdfYppRcbpecqDOrKWNo73EjgIv8HDsl3CRcxe ZYnVDND1lHtCo16xRW2wr4o/xPbVdo+xbBXaKj7C5p8e6V6iQj4aZX7prukos2P6awxO UgOQkyMJDxkfXN+HPExZOy6iMQGbO87Dse9kLzfvSRVUqWXaLNdaElhv1YKjOYnhqZ5w UHcQ== 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 g33-v6si4098323plb.251.2018.02.10.21.26.11; Sat, 10 Feb 2018 21:26:25 -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 S1754202AbeBKFYN (ORCPT + 99 others); Sun, 11 Feb 2018 00:24:13 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41319 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752449AbeBKEdk (ORCPT ); Sat, 10 Feb 2018 23:33:40 -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 1ekjKc-0002hC-5e; Sun, 11 Feb 2018 04:33:38 +0000 Received: from ben by deadeye with local (Exim 4.90) (envelope-from ) id 1ekjKW-0004Ra-WB; Sun, 11 Feb 2018 04:33:33 +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, "Colin Ian King" , "Alexandre Belloni" Date: Sun, 11 Feb 2018 04:20:06 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.2 02/79] rtc: interface: ignore expired timers when enqueuing new timers 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.2.99-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Colin Ian King commit 2b2f5ff00f63847d95adad6289bd8b05f5983dd5 upstream. This patch fixes a RTC wakealarm issue, namely, the event fires during hibernate and is not cleared from the list, causing hwclock to block. The current enqueuing does not trigger an alarm if any expired timers already exist on the timerqueue. This can occur when a RTC wake alarm is used to wake a machine out of hibernate and the resumed state has old expired timers that have not been removed from the timer queue. This fix skips over any expired timers and triggers an alarm if there are no pending timers on the timerqueue. Note that the skipped expired timer will get reaped later on, so there is no need to clean it up immediately. The issue can be reproduced by putting a machine into hibernate and waking it with the RTC wakealarm. Running the example RTC test program from tools/testing/selftests/timers/rtctest.c after the hibernate will block indefinitely. With the fix, it no longer blocks after the hibernate resume. BugLink: http://bugs.launchpad.net/bugs/1333569 Signed-off-by: Colin Ian King Signed-off-by: Alexandre Belloni Signed-off-by: Ben Hutchings --- drivers/rtc/interface.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -749,9 +749,23 @@ EXPORT_SYMBOL_GPL(rtc_irq_set_freq); */ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer) { + struct timerqueue_node *next = timerqueue_getnext(&rtc->timerqueue); + struct rtc_time tm; + ktime_t now; + timer->enabled = 1; + __rtc_read_time(rtc, &tm); + now = rtc_tm_to_ktime(tm); + + /* Skip over expired timers */ + while (next) { + if (next->expires.tv64 >= now.tv64) + break; + next = timerqueue_iterate_next(next); + } + timerqueue_add(&rtc->timerqueue, &timer->node); - if (&timer->node == timerqueue_getnext(&rtc->timerqueue)) { + if (!next) { struct rtc_wkalrm alarm; int err; alarm.time = rtc_ktime_to_tm(timer->node.expires);