* [PATCH 0/2] Fix wrong failure check on pcie_capability_read_*() @ 2020-06-19 20:12 refactormyself 2020-06-19 20:12 ` [PATCH 1/2] PCI/PME: " refactormyself 2020-06-19 20:12 ` [PATCH 2/2] PCI: pciehp: " refactormyself 0 siblings, 2 replies; 5+ messages in thread From: refactormyself @ 2020-06-19 20:12 UTC (permalink / raw) To: helgaas Cc: Bolarinwa Olayemi Saheed, bjorn, linux-pci, skhan, linux-kernel-mentees, linux-kernel From: Bolarinwa Olayemi Saheed <refactormyself@gmail.com> 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. Bolarinwa Olayemi Saheed (2): PCI/PME: Fix wrong failure check on pcie_capability_read_*() PCI: pciehp: Fix wrong failure check on pcie_capability_read_*() drivers/pci/hotplug/pciehp_hpc.c | 10 +++++----- drivers/pci/pcie/pme.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) -- 2.18.2 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] PCI/PME: Fix wrong failure check on pcie_capability_read_*() 2020-06-19 20:12 [PATCH 0/2] Fix wrong failure check on pcie_capability_read_*() refactormyself @ 2020-06-19 20:12 ` refactormyself 2020-06-19 20:12 ` [PATCH 2/2] PCI: pciehp: " refactormyself 1 sibling, 0 replies; 5+ messages in thread From: refactormyself @ 2020-06-19 20:12 UTC (permalink / raw) To: helgaas Cc: Bolarinwa Olayemi Saheed, bjorn, linux-pci, skhan, linux-kernel-mentees, linux-kernel From: Bolarinwa Olayemi Saheed <refactormyself@gmail.com> On failure, pcie_capabiility_read_*() will set rtsta to 0 and not ~0. This bug fix checks for the proper value. Signed-off-by: Bolarinwa Olayemi Saheed <refactormyself@gmail.com> --- drivers/pci/pcie/pme.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pcie/pme.c b/drivers/pci/pcie/pme.c index 6a32970bb731..1d1d06f06335 100644 --- a/drivers/pci/pcie/pme.c +++ b/drivers/pci/pcie/pme.c @@ -224,7 +224,7 @@ static void pcie_pme_work_fn(struct work_struct *work) break; pcie_capability_read_dword(port, PCI_EXP_RTSTA, &rtsta); - if (rtsta == (u32) ~0) + if (rtsta == (u32)0) break; if (rtsta & PCI_EXP_RTSTA_PME) { @@ -274,7 +274,7 @@ static irqreturn_t pcie_pme_irq(int irq, void *context) spin_lock_irqsave(&data->lock, flags); pcie_capability_read_dword(port, PCI_EXP_RTSTA, &rtsta); - if (rtsta == (u32) ~0 || !(rtsta & PCI_EXP_RTSTA_PME)) { + if (rtsta == (u32)0 || !(rtsta & PCI_EXP_RTSTA_PME)) { spin_unlock_irqrestore(&data->lock, flags); return IRQ_NONE; } -- 2.18.2 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] PCI: pciehp: Fix wrong failure check on pcie_capability_read_*() 2020-06-19 20:12 [PATCH 0/2] Fix wrong failure check on pcie_capability_read_*() refactormyself 2020-06-19 20:12 ` [PATCH 1/2] PCI/PME: " refactormyself @ 2020-06-19 20:12 ` refactormyself 2020-06-20 9:09 ` Lukas Wunner 1 sibling, 1 reply; 5+ messages in thread From: refactormyself @ 2020-06-19 20:12 UTC (permalink / raw) To: helgaas Cc: Bolarinwa Olayemi Saheed, bjorn, linux-pci, skhan, linux-kernel-mentees, linux-kernel From: Bolarinwa Olayemi Saheed <refactormyself@gmail.com> 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. Signed-off-by: Bolarinwa Olayemi Saheed <refactormyself@gmail.com> --- 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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] PCI: pciehp: Fix wrong failure check on pcie_capability_read_*() 2020-06-19 20:12 ` [PATCH 2/2] PCI: pciehp: " refactormyself @ 2020-06-20 9:09 ` Lukas Wunner 2020-06-26 19:14 ` Bjorn Helgaas 0 siblings, 1 reply; 5+ messages in thread From: Lukas Wunner @ 2020-06-20 9:09 UTC (permalink / raw) To: refactormyself Cc: helgaas, linux-pci, skhan, linux-kernel-mentees, linux-kernel 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. Thanks, Lukas > > Signed-off-by: Bolarinwa Olayemi Saheed <refactormyself@gmail.com> > --- > 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] PCI: pciehp: Fix wrong failure check on pcie_capability_read_*() 2020-06-20 9:09 ` Lukas Wunner @ 2020-06-26 19:14 ` Bjorn Helgaas 0 siblings, 0 replies; 5+ messages in thread From: Bjorn Helgaas @ 2020-06-26 19:14 UTC (permalink / raw) To: Lukas Wunner Cc: refactormyself, linux-pci, skhan, linux-kernel-mentees, linux-kernel 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 <refactormyself@gmail.com> > > --- > > 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-06-26 19:14 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-06-19 20:12 [PATCH 0/2] Fix wrong failure check on pcie_capability_read_*() refactormyself 2020-06-19 20:12 ` [PATCH 1/2] PCI/PME: " refactormyself 2020-06-19 20:12 ` [PATCH 2/2] PCI: pciehp: " refactormyself 2020-06-20 9:09 ` Lukas Wunner 2020-06-26 19:14 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).