Received: by 10.192.165.148 with SMTP id m20csp4182153imm; Mon, 30 Apr 2018 13:21:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpdzDd6ZqP6r23TEzcAAFXCKeFVZNlwNBXWVIxn3CiKvHvPONuF2/45pvI169tSBUIuWPwU X-Received: by 2002:a17:902:bc88:: with SMTP id bb8-v6mr2236629plb.175.1525119680559; Mon, 30 Apr 2018 13:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525119680; cv=none; d=google.com; s=arc-20160816; b=USfeJzxRmVOySTVK2xuPdwcgd2CiFv2juSWiJwpuHKhKkCXlSHXDEOaQTJ8tVSh1Ou h3sGDmLbUav0MFd1MtqAHZRNePyDzyK2z0nVtYNUqfe+XvoIkf2+eTcye6Ln2PZ7JcbD dNqAqksNeCoSeETyU3ySSmqSKTxoW6d7u0fXrBuXdOvLyW0U9yi+5wdr8qnDESCupSR3 +ZLjYg9M+Xfm+CFko3vmPXhlU9L5xbFAKsLj4sPzZnLeSGVhqJgII5HfB4hsyTY9M0t7 Awdt2b9WSZGOjpEUz1+IGVIsLEHOerWCWEjKlAHdW6DCJdCIkY6qBRW9bIC1pOxTd4wE aS/A== 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:dmarc-filter :arc-authentication-results; bh=xU07u9rcJF9kv9Y9+olcsCZCoiLRtsRWpMhGsDLzb5M=; b=gYmE2wH3hdQJ5rDGEIYOnQoZc3IQ0f1UInLyrLQHPFDqYeJeP5HAMnYx6TL0v/pam+ DH3aBrcnYxCnvGpFmLscKLaHClZ7EYdcbsL2ID601kTE1ft8m9svjFTeFu1gd2Hjzxr4 px7ORo8OYJCbo9nmCt0HBvValgZr0ZC8QSCNFfbZZNoKJahAAeWsEP0IV1Qq8s1M5LCK aaHI1dv2Qs7kvP5WK9DCql5y3NmBSVHdprsRC2trgEn+u5KxL9mCVHsyf8m7D3tJAML9 iO5GgN1z36HztoZrJv2ZmCCVhWvsgaTcJK0SxKHonRCaoe0YNRnqGFX9bcUzMNFZk149 3SvQ== 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 a61-v6si8028783pla.271.2018.04.30.13.21.06; Mon, 30 Apr 2018 13:21:20 -0700 (PDT) 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 S1755780AbeD3UU6 (ORCPT + 99 others); Mon, 30 Apr 2018 16:20:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:60782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755746AbeD3T0p (ORCPT ); Mon, 30 Apr 2018 15:26:45 -0400 Received: from localhost (unknown [104.132.1.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7BC6A22E02; Mon, 30 Apr 2018 19:26:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BC6A22E02 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicholas Piggin , Alexandre Belloni , Michael Ellerman Subject: [PATCH 4.9 54/61] rtc: opal: Fix OPAL RTC driver OPAL_BUSY loops Date: Mon, 30 Apr 2018 12:24:57 -0700 Message-Id: <20180430183955.893665304@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430183951.312721450@linuxfoundation.org> References: <20180430183951.312721450@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: Nicholas Piggin commit 682e6b4da5cbe8e9a53f979a58c2a9d7dc997175 upstream. The OPAL RTC driver does not sleep in case it gets OPAL_BUSY or OPAL_BUSY_EVENT from firmware, which causes large scheduling latencies, up to 50 seconds have been observed here when RTC stops responding (BMC reboot can do it). Fix this by converting it to the standard form OPAL_BUSY loop that sleeps. Fixes: 628daa8d5abf ("powerpc/powernv: Add RTC and NVRAM support plus RTAS fallbacks") Cc: stable@vger.kernel.org # v3.2+ Signed-off-by: Nicholas Piggin Acked-by: Alexandre Belloni Signed-off-by: Michael Ellerman Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/platforms/powernv/opal-rtc.c | 8 ++++-- drivers/rtc/rtc-opal.c | 37 ++++++++++++++++++------------ 2 files changed, 28 insertions(+), 17 deletions(-) --- a/arch/powerpc/platforms/powernv/opal-rtc.c +++ b/arch/powerpc/platforms/powernv/opal-rtc.c @@ -48,10 +48,12 @@ unsigned long __init opal_get_boot_time( while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { rc = opal_rtc_read(&__y_m_d, &__h_m_s_ms); - if (rc == OPAL_BUSY_EVENT) + if (rc == OPAL_BUSY_EVENT) { + mdelay(OPAL_BUSY_DELAY_MS); opal_poll_events(NULL); - else if (rc == OPAL_BUSY) - mdelay(10); + } else if (rc == OPAL_BUSY) { + mdelay(OPAL_BUSY_DELAY_MS); + } } if (rc != OPAL_SUCCESS) return 0; --- a/drivers/rtc/rtc-opal.c +++ b/drivers/rtc/rtc-opal.c @@ -57,7 +57,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; + s64 rc = OPAL_BUSY; int retries = 10; u32 y_m_d; u64 h_m_s_ms; @@ -66,13 +66,17 @@ static int opal_get_rtc_time(struct devi while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { rc = opal_rtc_read(&__y_m_d, &__h_m_s_ms); - if (rc == OPAL_BUSY_EVENT) + if (rc == OPAL_BUSY_EVENT) { + msleep(OPAL_BUSY_DELAY_MS); opal_poll_events(NULL); - else if (retries-- && (rc == OPAL_HARDWARE - || rc == OPAL_INTERNAL_ERROR)) - msleep(10); - else if (rc != OPAL_BUSY && rc != OPAL_BUSY_EVENT) - break; + } else if (rc == OPAL_BUSY) { + msleep(OPAL_BUSY_DELAY_MS); + } else if (rc == OPAL_HARDWARE || rc == OPAL_INTERNAL_ERROR) { + if (retries--) { + msleep(10); /* Wait 10ms before retry */ + rc = OPAL_BUSY; /* go around again */ + } + } } if (rc != OPAL_SUCCESS) @@ -87,21 +91,26 @@ 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; + s64 rc = OPAL_BUSY; int retries = 10; u32 y_m_d = 0; u64 h_m_s_ms = 0; tm_to_opal(tm, &y_m_d, &h_m_s_ms); + while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { rc = opal_rtc_write(y_m_d, h_m_s_ms); - if (rc == OPAL_BUSY_EVENT) + if (rc == OPAL_BUSY_EVENT) { + msleep(OPAL_BUSY_DELAY_MS); opal_poll_events(NULL); - else if (retries-- && (rc == OPAL_HARDWARE - || rc == OPAL_INTERNAL_ERROR)) - msleep(10); - else if (rc != OPAL_BUSY && rc != OPAL_BUSY_EVENT) - break; + } else if (rc == OPAL_BUSY) { + msleep(OPAL_BUSY_DELAY_MS); + } else if (rc == OPAL_HARDWARE || rc == OPAL_INTERNAL_ERROR) { + if (retries--) { + msleep(10); /* Wait 10ms before retry */ + rc = OPAL_BUSY; /* go around again */ + } + } } return rc == OPAL_SUCCESS ? 0 : -EIO;