Return-Path: Received: from mail-sn1nam02on0133.outbound.protection.outlook.com ([104.47.36.133]:15072 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032452AbeCAPfi (ORCPT ); Thu, 1 Mar 2018 10:35:38 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Stewart Smith , Michael Ellerman , Sasha Levin Subject: [added to the 4.1 stable tree] rtc-opal: Fix handling of firmware error codes, prevent busy loops Date: Thu, 1 Mar 2018 15:26:26 +0000 Message-ID: <20180301152116.1486-365-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Stewart Smith This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 5b8b58063029f02da573120ef4dc9079822e3cda ] 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: Sasha Levin --- drivers/rtc/rtc-opal.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/rtc-opal.c b/drivers/rtc/rtc-opal.c index 7061dcae2b09..482af0dda0b0 100644 --- a/drivers/rtc/rtc-opal.c +++ b/drivers/rtc/rtc-opal.c @@ -58,6 +58,7 @@ static void tm_to_opal(struct rtc_time *tm, u32 *y_m_d, u= 64 *h_m_s_ms) static int opal_get_rtc_time(struct device *dev, struct rtc_time *tm) { long rc =3D OPAL_BUSY; + int retries =3D 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 device *dev, struct = rtc_time *tm) rc =3D opal_rtc_read(&__y_m_d, &__h_m_s_ms); if (rc =3D=3D OPAL_BUSY_EVENT) opal_poll_events(NULL); - else + else if (retries-- && (rc =3D=3D OPAL_HARDWARE + || rc =3D=3D OPAL_INTERNAL_ERROR)) msleep(10); + else if (rc !=3D OPAL_BUSY && rc !=3D OPAL_BUSY_EVENT) + break; } =20 if (rc !=3D OPAL_SUCCESS) @@ -84,6 +88,7 @@ static int opal_get_rtc_time(struct device *dev, struct r= tc_time *tm) static int opal_set_rtc_time(struct device *dev, struct rtc_time *tm) { long rc =3D OPAL_BUSY; + int retries =3D 10; u32 y_m_d =3D 0; u64 h_m_s_ms =3D 0; =20 @@ -92,8 +97,11 @@ static int opal_set_rtc_time(struct device *dev, struct = rtc_time *tm) rc =3D opal_rtc_write(y_m_d, h_m_s_ms); if (rc =3D=3D OPAL_BUSY_EVENT) opal_poll_events(NULL); - else + else if (retries-- && (rc =3D=3D OPAL_HARDWARE + || rc =3D=3D OPAL_INTERNAL_ERROR)) msleep(10); + else if (rc !=3D OPAL_BUSY && rc !=3D OPAL_BUSY_EVENT) + break; } =20 return rc =3D=3D OPAL_SUCCESS ? 0 : -EIO; --=20 2.14.1