Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp817011ybt; Fri, 26 Jun 2020 12:15:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWvGZyJ9tOMbfWdMqJwwtBhpP5TEW4o+xjkVtqaLDaBjUBHOCWj6vGpHOUz8wccEZ2G0LR X-Received: by 2002:a17:906:fcc7:: with SMTP id qx7mr4018304ejb.182.1593198923532; Fri, 26 Jun 2020 12:15:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593198923; cv=none; d=google.com; s=arc-20160816; b=IRnOK5r6N8MeaBwKJiEu3DHRKn989R3j2vWQpoA0HmFhM1lZHWdqQ25Hevs2pSCjYd 38W99j5BiRCo+WsSSGmm7ltiOrwPnyc/wClIYK+DscBKBqthy1RjpCBT4q6SSqJJV6CW Gu0p9C7qkeMWKT2pgcjVRcQZOV5Aph2Oxm26jePiZX8+PPuH+D/3wWOsUWi+Lt7aSYXF MWStBbIQhpZ4ZjZOlme08+EXk0uZtGEb9MLXnu4jxGfb/BOKKzDsCvc94LMn14W8Hyja hyDTvMQTrlaqJqqtbqGwa51Ut1hHrk9773Y0WvgbIvQLCBQ2+a7zxZNY64N1jaBinGNr ZY2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=fhQE+X2xdEyppMlrybRM+w5hyIgrMOHHRpU+S0iWqPw=; b=InHw4eGHjGKL8oAxN8hjLjKJMiy/5nZaNblAtnvdW9tnzKBa/oWSyN4my8+sS25VfJ 5SHyyTKfUVsKdh8Gz2sMDgKm6EbYsyU3UY57ZqzWAxfWNDYWv6MWFJd0vYDwu/KOx/MB 1Ta/GkSsz05k62SN8WIew7lIMhXuMjOzO6kCfL5owYvPI12yvEUdB78lI4kuMYP1r1hB wszCQ83QHDsnqk04uqgRbJYz2ilHcxBwC1pMn7wB5I3mCOfJu2U6ahuAS9wxMzuY1Eq7 GOVDN8yj8dEZM5msCjQBRZC1vBpLVJVOIIX59v2tScUQkkUdsXuiVgyxbjpwtFMPE+DB Ed9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cvleF0Ud; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cy13si12839544edb.388.2020.06.26.12.14.38; Fri, 26 Jun 2020 12:15:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cvleF0Ud; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725816AbgFZTOY (ORCPT + 99 others); Fri, 26 Jun 2020 15:14:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:60176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725275AbgFZTOY (ORCPT ); Fri, 26 Jun 2020 15:14:24 -0400 Received: from localhost (mobile-166-170-222-206.mycingular.net [166.170.222.206]) (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 311D3206A1; Fri, 26 Jun 2020 19:14:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593198863; bh=z2oF+alcajhjxoNUuykiKixvNasruwuFGTQMBcBskD0=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=cvleF0UdnEtliTWMUd/EQkLaX5l7SVtigqGUCDB5YsAXJBr/9xo9IBRtfT1DSQuvA Bu56ZM0JGSAEM9Qw9Pxql4eRma9YpwgfVZexqcN72JvG/RS3HBuqIgMDI2eLlXqiIh /W0oL64GDhIozpKiRgk2+Z8MEBHmyucoUdZcf//M= Date: Fri, 26 Jun 2020 14:14:21 -0500 From: Bjorn Helgaas To: Lukas Wunner Cc: refactormyself@gmail.com, linux-pci@vger.kernel.org, skhan@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] PCI: pciehp: Fix wrong failure check on pcie_capability_read_*() Message-ID: <20200626191421.GA2924609@bjorn-Precision-5520> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200620090936.3khh3gj46pnojnrw@wunner.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jun 20, 2020 at 11:09:36AM +0200, Lukas Wunner wrote: > On Fri, Jun 19, 2020 at 10:12:19PM +0200, refactormyself@gmail.com wrote: > > On failure, pcie_capabiility_read_*() will set the status value, > > its last parameter to 0 and not ~0. > > This bug fix checks for the proper value. > > If a config space read times out, the PCIe controller fabricates > an "all ones" response. The code is checking for such a timeout, > not for an error. Hence the code is fine. In the typical case, the pci_read_config_word() done by pcie_capability_read_word() will not return an error, so if the read times out, we should see slot_status == ~0. But if it's possible to set dev->error_state == pci_channel_io_perm_failure, pci_read_config_word() will return an error because pci_dev_is_disconnected(), so slot_status would be 0. There are a dozen or so places that set dev->error_state. It doesn't look *likely* that any of them would cause this, but it doesn't instill confidence. It would be a lot nicer if we didn't have to worry about both the 0 and ~0 cases. I keep coming back to the idea of removing the "*val = 0" code from pcie_capability_read_word() so we wouldn't have that special case. In any case, this particular patch doesn't seem like quite the right fix, so I'll drop it. > > Signed-off-by: Bolarinwa Olayemi Saheed > > --- > > drivers/pci/hotplug/pciehp_hpc.c | 10 +++++----- > > 1 file changed, 5 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c > > index 53433b37e181..c1a67054948a 100644 > > --- a/drivers/pci/hotplug/pciehp_hpc.c > > +++ b/drivers/pci/hotplug/pciehp_hpc.c > > @@ -89,7 +89,7 @@ static int pcie_poll_cmd(struct controller *ctrl, int timeout) > > > > do { > > pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status); > > - if (slot_status == (u16) ~0) { > > + if (slot_status == (u16)0) { > > ctrl_info(ctrl, "%s: no response from device\n", > > __func__); > > return 0; > > @@ -165,7 +165,7 @@ static void pcie_do_write_cmd(struct controller *ctrl, u16 cmd, > > pcie_wait_cmd(ctrl); > > > > pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, &slot_ctrl); > > - if (slot_ctrl == (u16) ~0) { > > + if (slot_ctrl == (u16)0) { > > ctrl_info(ctrl, "%s: no response from device\n", __func__); > > goto out; > > } > > @@ -236,7 +236,7 @@ int pciehp_check_link_active(struct controller *ctrl) > > int ret; > > > > ret = pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status); > > - if (ret == PCIBIOS_DEVICE_NOT_FOUND || lnk_status == (u16)~0) > > + if (ret == PCIBIOS_DEVICE_NOT_FOUND || lnk_status == (u16)0) > > return -ENODEV; > > > > ret = !!(lnk_status & PCI_EXP_LNKSTA_DLLLA); > > @@ -440,7 +440,7 @@ int pciehp_card_present(struct controller *ctrl) > > int ret; > > > > ret = pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status); > > - if (ret == PCIBIOS_DEVICE_NOT_FOUND || slot_status == (u16)~0) > > + if (ret == PCIBIOS_DEVICE_NOT_FOUND || slot_status == (u16)0) > > return -ENODEV; > > > > return !!(slot_status & PCI_EXP_SLTSTA_PDS); > > @@ -592,7 +592,7 @@ static irqreturn_t pciehp_isr(int irq, void *dev_id) > > > > read_status: > > pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &status); > > - if (status == (u16) ~0) { > > + if (status == (u16)0) { > > ctrl_info(ctrl, "%s: no response from device\n", __func__); > > if (parent) > > pm_runtime_put(parent); > > -- > > 2.18.2