From patchwork Thu Jul 26 15:21:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bert Kenward X-Patchwork-Id: 949772 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=solarflare.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41bwmx4qdgz9ryl for ; Fri, 27 Jul 2018 01:21:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731600AbeGZQjK (ORCPT ); Thu, 26 Jul 2018 12:39:10 -0400 Received: from dispatch1-us1.ppe-hosted.com ([148.163.129.52]:42030 "EHLO dispatch1-us1.ppe-hosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729801AbeGZQjK (ORCPT ); Thu, 26 Jul 2018 12:39:10 -0400 X-Virus-Scanned: Proofpoint Essentials engine Received: from webmail.solarflare.com (uk.solarflare.com [193.34.186.16]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1-us4.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTPS id A740C800061; Thu, 26 Jul 2018 15:21:49 +0000 (UTC) Received: from hgk-desktop.uk.solarflarecom.com (10.17.20.82) by ukex01.SolarFlarecom.com (10.17.10.4) with Microsoft SMTP Server (TLS) id 15.0.1044.25; Thu, 26 Jul 2018 16:21:32 +0100 From: Bert Kenward Subject: [PATCH] pci/vpd: Ensure VPD is checked before timeout To: Bjorn Helgaas , Message-ID: <66bbf8b3-bab9-1860-12c9-1c187ddc4201@solarflare.com> Date: Thu, 26 Jul 2018 16:21:29 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [10.17.20.82] X-ClientProxiedBy: ocex03.SolarFlarecom.com (10.20.40.36) To ukex01.SolarFlarecom.com (10.17.10.4) X-TM-AS-Product-Ver: SMEX-12.5.0.1300-8.5.1010-23992.003 X-TM-AS-Result: No-4.946300-8.000000-10 X-TMASE-MatchedRID: EzeqGrx38Dkr7JS62M1xTGwjJ4TFeU1uTJDl9FKHbrkKogmGusPLb9S7 0vL0CFXhBt/jAbPrLFakV7miV6Ja8QEhgxBPPgRp4bl1FkKDELd9LQinZ4QefL6qvLNjDYTwKtP QnDJkGkcqtq5d3cxkNcAkKAddMS6a88FGs3CZRl43JiFefT4CtjVcaGByIGpZz/lNg6l1CwrPk2 304YPC8H91x9J1Bu611NJCBQhhpQI7N8pzQpHsxS8FtR5boksWq8Ly7Mpz16LAQfeifHuX0tX0i +Joi1w+B5vrys83c8JDDKa3G4nrLQ== X-TM-AS-User-Approved-Sender: Yes X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--4.946300-8.000000 X-TMASE-Version: SMEX-12.5.0.1300-8.5.1010-23992.003 X-MDID: 1532618510-i2USjgoBlmvS Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org We check the timeout before we check the VPD access completion bit. On a very heavily loaded system this can cause VPD access to timeout. We should check the completion bit before checking the timeout. Signed-off-by: Bert Kenward --- drivers/pci/vpd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 8617565ba561..4963c2e2bd4c 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -146,7 +146,7 @@ static int pci_vpd_wait(struct pci_dev *dev) if (!vpd->busy) return 0; - while (time_before(jiffies, timeout)) { + do { ret = pci_user_read_config_word(dev, vpd->cap + PCI_VPD_ADDR, &status); if (ret < 0) @@ -160,10 +160,13 @@ static int pci_vpd_wait(struct pci_dev *dev) if (fatal_signal_pending(current)) return -EINTR; + if (time_after(jiffies, timeout)) + break; + usleep_range(10, max_sleep); if (max_sleep < 1024) max_sleep *= 2; - } + } while (true); pci_warn(dev, "VPD access failed. This is likely a firmware bug on this device. Contact the card vendor for a firmware update\n"); return -ETIMEDOUT;