Received: by 10.192.165.148 with SMTP id m20csp4165506imm; Mon, 30 Apr 2018 13:01:50 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqiLzeumabbFuQREAjLUm6v2YU0OqKq86Y65G0Fhwet6imZvseZnLERMoTEEIwG9jc629+K X-Received: by 2002:a63:78cf:: with SMTP id t198-v6mr11071918pgc.382.1525118510869; Mon, 30 Apr 2018 13:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525118510; cv=none; d=google.com; s=arc-20160816; b=wAJntK/jSdc85liqeMjLoXWkKWvDJE/Wsz+taRYIvvBRa3yhyoGIvrhycLTiAwryJp 5hhZnDS5myX7x3OdZ8jxNuiPNuSa0kOCeIMy3mzQE7XB0ReQcKrQ6eKYXXir/0RhSSwF VIzl4uwLhSHWDKpQJP663PLj3QH/Bu3EvPAdvuguevwMiOu9pmcCL0ml7EsVHWH0t89v bXbqtDxloSgT1w94mSOcjOOR39lci2WkMvpEZx1JSJ/c0n9c3ahvjO7ABy4KEuo0Bydd 4DMm4QcPwTGS0MgfmejsefM7IjkIeVQpGjkQdGlr3kfhWAQM6nGrfKMTE1uBI5BRIUoO MWGg== 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=qZA9aSe+4hpuEhCknpBZd1ZVFOlL65Mj7AQ2WDZQ6IE=; b=HjCS9uJmys6WyJQBLL4IiEjyVwfiGme3k+XyKQRihU/QwfucJDsS//9VSKz6o+NdLa jPMqllja0GQ3Eub15g06DoeKHy+77P73r8i5NqD98eEAdTF6auK4DBaMiECLu2bfd8K4 05nSm+Rh9VrYF97yDlRdW/tyvbxYktL8eonGqNWjRUVIxgLMEo/nTSD61ivQgs3YoUMb ZfOZcDGV4NvhlBbGxdLFwH8xmm8uBVx+lQHacFTn6zX+o2p+SFZstEhcjPBiNxl9uzfv z+b1gQX78UPD8t/OJ3ZuA8bUx7fvHhPXEYUPtoH1WZLZE1Tex58fDSNVBwWwYEkA7esO ZBKA== 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 o189si7979950pfo.20.2018.04.30.13.01.36; Mon, 30 Apr 2018 13:01:50 -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 S932215AbeD3T1l (ORCPT + 99 others); Mon, 30 Apr 2018 15:27:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:34430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755263AbeD3T1j (ORCPT ); Mon, 30 Apr 2018 15:27:39 -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 775BB22DCC; Mon, 30 Apr 2018 19:27:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 775BB22DCC 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.14 79/91] rtc: opal: Fix OPAL RTC driver OPAL_BUSY loops Date: Mon, 30 Apr 2018 12:25:01 -0700 Message-Id: <20180430184008.416390019@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184004.216234025@linuxfoundation.org> References: <20180430184004.216234025@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.14-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;