Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3220292ybl; Sun, 1 Sep 2019 08:40:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5or0+TQsCkxU1wS4mj1oEXHInNliFzy+daTNu2BcPv+DJDpCldIeo3cApnZfN3tVES3/9 X-Received: by 2002:a63:484d:: with SMTP id x13mr21339440pgk.122.1567352422253; Sun, 01 Sep 2019 08:40:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567352422; cv=none; d=google.com; s=arc-20160816; b=Ddn8Y3po/TAVD6rMByS+rO178BAkFsaBexpkQ+kEwsNytGelcedhwGgOUOAOnC3bFv QPrFCjkZmxidHsUYaSIvrPMKby+KQkCkqrkYZffLO0w1Amr/6sWW705/fR4hJaPFYYOG MKHMYbmVlhG2ZYsZpsrZflcbEvugPIkiqSGPkDCA4WjqXd5LoFlze89gzXdiRr74otxz VkKqvUkftX5y7iN9qb594f8zJrM9CVPkejYaNe/+5+s43/FIfMScQPt+WXEF+WR2cIGs 2popLqUS4yKymd+kug91c8nRn3smuYllCXB68Oxyx6W/dQjGP8hSWGACKsSAomJv06DK VmZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=J4/Ockjg5uBi5u+myxueJ8OzbByM74uGm8JCd7teVVU=; b=MeAhpQ+yBAvrBw19FaeTLBwFn7mFvL299XZujOlfoxsrHjLvavlAWfN4a0KL1Cp2/K louErUg0LKvhb7T3JFEP6aEkLIFC2ELTrcjQYnDE1fnKI7RKamC8tQW5h2UUgqaC9SOt Ivrh0p0XwOfGcX7OZGuy8rLiLU5PF3qF6TSZoOKkx3L6yQzMNUSu/13dMgTvXiJ8PuMK eAU/bjUwT14eoFZgsLgl+Sdi4BIv5ErKaayPWyJBAvDGcg4UBWA54L1LeHTvPY2V62FK /FZlyazhVJNYySzO5eXnLb4Gs6ZMyLd0h/63nKGrDDMciS//yqd5x645TdwnpIOketL8 tsrg== 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 q16si12872758pfl.234.2019.09.01.08.40.06; Sun, 01 Sep 2019 08:40:22 -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 S1728935AbfIAOOO (ORCPT + 99 others); Sun, 1 Sep 2019 10:14:14 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:35295 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728772AbfIAOOO (ORCPT ); Sun, 1 Sep 2019 10:14:14 -0400 Received: from localhost (unknown [88.190.179.123]) (Authenticated sender: repk@triplefau.lt) by relay11.mail.gandi.net (Postfix) with ESMTPSA id BD80E100005; Sun, 1 Sep 2019 14:14:10 +0000 (UTC) From: Remi Pommarel To: Thomas Petazzoni , Lorenzo Pieralisi , Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Remi Pommarel Subject: [PATCH] PCI: aardvark: Don't rely on jiffies while holding spinlock Date: Sun, 1 Sep 2019 16:23:03 +0200 Message-Id: <20190901142303.27815-1-repk@triplefau.lt> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org advk_pcie_wait_pio() can be called while holding a spinlock (from pci_bus_read_config_dword()), then depends on jiffies in order to timeout while polling on PIO state registers. In the case the PIO transaction failed, the timeout will never happen and will also cause the cpu to stall. This decrements a variable and wait instead of using jiffies. Signed-off-by: Remi Pommarel --- drivers/pci/controller/pci-aardvark.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index fc0fe4d4de49..1fa6d04ad7aa 100644 --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -175,7 +175,8 @@ (PCIE_CONF_BUS(bus) | PCIE_CONF_DEV(PCI_SLOT(devfn)) | \ PCIE_CONF_FUNC(PCI_FUNC(devfn)) | PCIE_CONF_REG(where)) -#define PIO_TIMEOUT_MS 1 +#define PIO_RETRY_CNT 10 +#define PIO_RETRY_DELAY 100 /* 100 us*/ #define LINK_WAIT_MAX_RETRIES 10 #define LINK_WAIT_USLEEP_MIN 90000 @@ -383,17 +384,16 @@ static void advk_pcie_check_pio_status(struct advk_pcie *pcie) static int advk_pcie_wait_pio(struct advk_pcie *pcie) { struct device *dev = &pcie->pdev->dev; - unsigned long timeout; + size_t i; - timeout = jiffies + msecs_to_jiffies(PIO_TIMEOUT_MS); - - while (time_before(jiffies, timeout)) { + for (i = 0; i < PIO_RETRY_CNT; ++i) { u32 start, isr; start = advk_readl(pcie, PIO_START); isr = advk_readl(pcie, PIO_ISR); if (!start && isr) return 0; + udelay(PIO_RETRY_DELAY); } dev_err(dev, "config read/write timed out\n"); -- 2.20.1