Received: by 10.223.185.116 with SMTP id b49csp933402wrg; Wed, 21 Feb 2018 09:14:48 -0800 (PST) X-Google-Smtp-Source: AH8x2248PRyM9sDCyWbnEnEwzFWKOsQnRqk2M8S2sWrjpbbfT2rqsXVhLyks6ug2p1u/rg0/H5WI X-Received: by 2002:a17:902:6b89:: with SMTP id p9-v6mr3802158plk.377.1519233288220; Wed, 21 Feb 2018 09:14:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519233288; cv=none; d=google.com; s=arc-20160816; b=zoPq4hoV4gUZU2c8B1k1x8McSWcgWatMPQlMMO9O0Cbf8gWdlgtYz6IH1dXHGmekEv t+4fYNqAEFAyMDU9Pvm1cCvdG46hVz1mlV0M/m/SX1z+/ZjmZo+B8CZJp5x9xW2oySUG bX7BelFU/kL+KG9C4cuHkxf3VzwxZU/SzgtOqEAsBJW/FkkgGiZkQvR/j8Qo5+9AoGZm y0Teg5cKfDI7ANYjY6WBRvuuuzI9thCw9JQl0u3lMZ5euemMqt1RvikFvk/45L8Fi6uL 9z30Xg+AtEdwzwtLHAcWJya4UUxw7W+ePnpZ8PUtbr/ks070oHFP7ee6Yt34lfG1WM/O HvHw== 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=DX+Tw0N4flZShYDmAePoSsHrM5GNZu/IjEjVtzRib3Q=; b=yLdnQ1iQSIXimorZG1WMO5jl9l2k7BCokjAF6ThClwRayg5De5wR+RERXtKQLGdi1P mDDPdXHMADYG5Dg7y25m/yIacm1D1hnj6hl+2tTwcezmX3mtSLH115I3A6AuldGNBiSO IBwsDm9yumLSx+vPjBP++Mc47mj52dtUxqjvGg/mnZmD6dBAUBTpnszgj9CjCjrzSJgO 9vSj2cnbrqt1/vFOKZ0wz14hlFdg4IxOpBfWNl3KredmLtIy1Zjqbie1qfE3MikWj8HR 1sKWhhPlsmV9PDNNLaGKVIQ25W8h7UJEJRsMRYJw4GhZy5oVFjxghCS7HBLwxgmLJqyk 7/7A== 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 m9si2766598pgp.542.2018.02.21.09.14.33; Wed, 21 Feb 2018 09:14:48 -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 S934041AbeBUMy1 (ORCPT + 99 others); Wed, 21 Feb 2018 07:54:27 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34008 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932466AbeBUMy0 (ORCPT ); Wed, 21 Feb 2018 07:54:26 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5BB0C1143; Wed, 21 Feb 2018 12:54:25 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stewart Smith , Michael Ellerman Subject: [PATCH 4.9 04/77] rtc-opal: Fix handling of firmware error codes, prevent busy loops Date: Wed, 21 Feb 2018 13:48:13 +0100 Message-Id: <20180221124432.350707446@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124432.172390020@linuxfoundation.org> References: <20180221124432.172390020@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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stewart Smith commit 5b8b58063029f02da573120ef4dc9079822e3cda upstream. According to the OPAL docs: skiboot-5.2.5/doc/opal-api/opal-rtc-read-3.txt skiboot-5.2.5/doc/opal-api/opal-rtc-write-4.txt OPAL_HARDWARE may be returned from OPAL_RTC_READ or OPAL_RTC_WRITE and this indicates either a transient or permanent error. Prior to this patch, Linux was not dealing with OPAL_HARDWARE being a permanent error particularly well, in that you could end up in a busy loop. This was not too hard to trigger on an AMI BMC based OpenPOWER machine doing a continuous "ipmitool mc reset cold" to the BMC, the result of that being that we'd get stuck in an infinite loop in opal_get_rtc_time(). We now retry a few times before returning the error higher up the stack. Fixes: 16b1d26e77b1 ("rtc/tpo: Driver to support rtc and wakeup on PowerNV platform") Cc: stable@vger.kernel.org # v3.19+ Signed-off-by: Stewart Smith Signed-off-by: Michael Ellerman Signed-off-by: Greg Kroah-Hartman --- drivers/rtc/rtc-opal.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/drivers/rtc/rtc-opal.c +++ b/drivers/rtc/rtc-opal.c @@ -58,6 +58,7 @@ static void tm_to_opal(struct rtc_time * static int opal_get_rtc_time(struct device *dev, struct rtc_time *tm) { long rc = OPAL_BUSY; + int retries = 10; u32 y_m_d; u64 h_m_s_ms; __be32 __y_m_d; @@ -67,8 +68,11 @@ static int opal_get_rtc_time(struct devi rc = opal_rtc_read(&__y_m_d, &__h_m_s_ms); if (rc == OPAL_BUSY_EVENT) opal_poll_events(NULL); - else + else if (retries-- && (rc == OPAL_HARDWARE + || rc == OPAL_INTERNAL_ERROR)) msleep(10); + else if (rc != OPAL_BUSY && rc != OPAL_BUSY_EVENT) + break; } if (rc != OPAL_SUCCESS) @@ -84,6 +88,7 @@ static int opal_get_rtc_time(struct devi static int opal_set_rtc_time(struct device *dev, struct rtc_time *tm) { long rc = OPAL_BUSY; + int retries = 10; u32 y_m_d = 0; u64 h_m_s_ms = 0; @@ -92,8 +97,11 @@ static int opal_set_rtc_time(struct devi rc = opal_rtc_write(y_m_d, h_m_s_ms); if (rc == OPAL_BUSY_EVENT) opal_poll_events(NULL); - else + else if (retries-- && (rc == OPAL_HARDWARE + || rc == OPAL_INTERNAL_ERROR)) msleep(10); + else if (rc != OPAL_BUSY && rc != OPAL_BUSY_EVENT) + break; } return rc == OPAL_SUCCESS ? 0 : -EIO;