linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/14 v4] PCI: Remove '*val = 0' from pcie_capability_read_*()
@ 2020-07-14 11:04 Saheed Olayemi Bolarinwa
  2020-07-14 11:04 ` [PATCH 1/14 v4] IB/hfi1: Check the return value of pcie_capability_read_*() Saheed Olayemi Bolarinwa
  2020-07-14 15:49 ` [PATCH 0/14 v4] PCI: Remove '*val = 0' from pcie_capability_read_*() Bjorn Helgaas
  0 siblings, 2 replies; 3+ messages in thread
From: Saheed Olayemi Bolarinwa @ 2020-07-14 11:04 UTC (permalink / raw)
  To: helgaas
  Cc: Bolarinwa Olayemi Saheed, bjorn, skhan, linux-pci,
	linux-kernel-mentees, linux-kernel, Mike Marciniszyn,
	Dennis Dalessandro, Doug Ledford, Jason Gunthorpe, linux-rdma

From: Bolarinwa Olayemi Saheed <refactormyself@gmail.com>

v4 CHANGES:
- Remove unnecessary boolean conversion
- fix bugs introduced by previous version in PATCH 11/14

v3 CHANGES:
- Split previous PATCH 6/13 into two : PATCH 6/14 and PATCH 7/14
- Fix commit message of PATCH 5/14
- Update Patch numbering and Commit messages
- Add 'Acked by Greg KH' to PATCH 2/14
- Add PATCH version

v2 CHANGES:
- Fix missing comma, causing the email cc error
- Fix typos and numbering errors in commit messages
- Add commit message to 13/13
- Add two more patches: PATCH 3/13 and PATCH 4/13

MERGING:
Patch 7/14 depends on Patch 6/14. However Patch 6/14 has no dependency.
Please, merge PATCH 7/14 only after Patch 6/14.
Patch 14/14 depend on all preceeding patchs. Except for Patch 6/14 and
Patch 7/14, all other patches are independent of one another. Hence,
please merge Patch 14/14 only after other patches in this series have
been merged.


PATCH 6/14:
Make the function set status to "Power On" by default and only set to
Set "Power Off" only if pcie_capability_read_word() is successful and
(slot_ctrl & PCI_EXP_SLTCTL_PCC) == PCI_EXP_SLTCTL_PWR_OFF. 

PATCH 1/14 to 13/14:
Check the return value of pcie_capability_read_*() to ensure success or
confirm failure. While maintaining these functions, this ensures that the
changes in PATCH 14/14 does not introduce any bug. 

PATCH 14/14:
There are several reasons why a PCI capability read may fail whether the
device is present or not. If this happens, pcie_capability_read_*() will
return -EINVAL/PCIBIOS_BAD_REGISTER_NUMBER or PCIBIOS_DEVICE_NOT_FOUND
and *val is set to 0.

This behaviour if further ensured by this code inside
pcie_capability_read_*()

 ret = pci_read_config_dword(dev, pci_pcie_cap(dev) + pos, val);
 /*
  * Reset *val to 0 if pci_read_config_dword() fails, it may
  * have been written as 0xFFFFFFFF if hardware error happens
  * during pci_read_config_dword().
  */
 if (ret)
	 *val = 0;
 return ret;

a) Since all pci_generic_config_read() does is read a register value,
it may return success after reading a ~0 which *may* have been fabricated
by the PCI host bridge due to a read timeout. Hence pci_read_config_*() 
will return success with a fabricated ~0 in *val, indicating a problem.
In this case, the assumed behaviour of  pcie_capability_read_*() will be
wrong. To avoid error slipping through, more checks are necessary.

b) pci_read_config_*() will return PCIBIOS_DEVICE_NOT_FOUND only if 
dev->error_state = pci_channel_io_perm_failure (i.e. 
pci_dev_is_disconnected()) or if pci_generic_config_read() can't find the
device. In both cases *val is initially set to ~0 but as shown in the code
above pcie_capability_read_*() resets it back to 0. Even with this effort,
drivers still have to perform validation checks more so if 0 is a valid
value.

Most drivers only consider the case (b) and in some cases, there is the 
expectation that on timeout *val has a fabricated value of ~0, which *may*
not always be true as explained in (a).

In any case, checks need to be done to validate the value read and maybe
confirm which error has occurred. It is better left to the drivers to do.

Check the return value of pcie_capability_read_dword() to ensure success
and avoid bug as a result of Patch 14/14.
Remove the reset of *val to 0 when pci_read_config_*() fails.


Bolarinwa Olayemi Saheed (14):
  IB/hfi1: Check the return value of pcie_capability_read_*()
  misc: rtsx: Check the return value of pcie_capability_read_*()
  ath9k: Check the return value of pcie_capability_read_*()
  iwlegacy: Check the return value of pcie_capability_read_*()
  PCI: pciehp: Check the return value of pcie_capability_read_*()
  PCI: pciehp: Make "Power On" the default 
  PCI: pciehp: Check the return value of pcie_capability_read_*()
  PCI/ACPI: Check the return value of pcie_capability_read_*()
  PCI: pciehp: Check the return value of pcie_capability_read_*()
  PCI: Check the return value of pcie_capability_read_*()
  PCI/PM: Check return value of pcie_capability_read_*()
  PCI/AER: Check the return value of pcie_capability_read_*()
  PCI/ASPM: Check the return value of pcie_capability_read_*()
  PCI: Remove '*val = 0' from pcie_capability_read_*()

 drivers/net/wireless/ath/ath9k/pci.c         | 5 +++--
 drivers/net/wireless/intel/iwlegacy/common.c | 4 ++--
 drivers/infiniband/hw/hfi1/aspm.c | 7 ++++---
 drivers/misc/cardreader/rts5227.c | 5 +++--
 drivers/misc/cardreader/rts5249.c | 5 +++--
 drivers/misc/cardreader/rts5260.c | 5 +++--
 drivers/misc/cardreader/rts5261.c | 5 +++--
 drivers/pci/pcie/aer.c  |  5 +++--
 drivers/pci/pcie/aspm.c | 33 +++++++++++++++++----------------
 drivers/pci/hotplug/pciehp_hpc.c | 47 ++++++++++++++++----------------
 drivers/pci/pci-acpi.c           | 10 ++++---
 drivers/pci/probe.c              | 29 ++++++++++++--------
 drivers/pci/access.c | 14 --------------
 13 files changed, 87 insertions(+), 87 deletions(-)

-- 
2.18.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/14 v4] IB/hfi1: Check the return value of pcie_capability_read_*()
  2020-07-14 11:04 [PATCH 0/14 v4] PCI: Remove '*val = 0' from pcie_capability_read_*() Saheed Olayemi Bolarinwa
@ 2020-07-14 11:04 ` Saheed Olayemi Bolarinwa
  2020-07-14 15:49 ` [PATCH 0/14 v4] PCI: Remove '*val = 0' from pcie_capability_read_*() Bjorn Helgaas
  1 sibling, 0 replies; 3+ messages in thread
From: Saheed Olayemi Bolarinwa @ 2020-07-14 11:04 UTC (permalink / raw)
  To: helgaas, Mike Marciniszyn, Dennis Dalessandro, Doug Ledford,
	Jason Gunthorpe
  Cc: Bolarinwa Olayemi Saheed, bjorn, skhan, linux-rdma,
	linux-kernel-mentees, linux-kernel

From: Bolarinwa Olayemi Saheed <refactormyself@gmail.com>

On failure pcie_capability_read_dword() sets it's last parameter,
val to 0. In this case dn and up will be 0, so aspm_hw_l1_supported()
will return false.
However, with Patch 14/14, it is possible that val is set to ~0 on
failure. This would introduce a bug because (x & x) == (~0 & x). So with
dn and up being 0x02, a true value is return when the read has actually
failed.

This bug can be avoided if the return value of pcie_capability_read_dword
is checked to confirm success. The behaviour of the function remains
intact.

Check the return value of pcie_capability_read_dword() to ensure success.

Suggested-by: Bjorn Helgaas <bjorn@helgaas.com>
Signed-off-by: Bolarinwa Olayemi Saheed <refactormyself@gmail.com>
---
v4 changes:
Remove unnecessary boolean conversion.

 drivers/infiniband/hw/hfi1/aspm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/hw/hfi1/aspm.c b/drivers/infiniband/hw/hfi1/aspm.c
index a3c53be4072c..80d0b3edd983 100644
--- a/drivers/infiniband/hw/hfi1/aspm.c
+++ b/drivers/infiniband/hw/hfi1/aspm.c
@@ -24,6 +24,7 @@ static bool aspm_hw_l1_supported(struct hfi1_devdata *dd)
 {
 	struct pci_dev *parent = dd->pcidev->bus->self;
 	u32 up, dn;
+	int ret_up, ret_dn;
 
 	/*
 	 * If the driver does not have access to the upstream component,
@@ -32,14 +33,14 @@ static bool aspm_hw_l1_supported(struct hfi1_devdata *dd)
 	if (!parent)
 		return false;
 
-	pcie_capability_read_dword(dd->pcidev, PCI_EXP_LNKCAP, &dn);
+	ret_dn = pcie_capability_read_dword(dd->pcidev, PCI_EXP_LNKCAP, &dn);
 	dn = ASPM_L1_SUPPORTED(dn);
 
-	pcie_capability_read_dword(parent, PCI_EXP_LNKCAP, &up);
+	ret_up = pcie_capability_read_dword(parent, PCI_EXP_LNKCAP, &up);
 	up = ASPM_L1_SUPPORTED(up);
 
 	/* ASPM works on A-step but is reported as not supported */
-	return (!!dn || is_ax(dd)) && !!up;
+	return ret_dn && ret_up && (dn || is_ax(dd)) && up;
 }
 
 /* Set L1 entrance latency for slower entry to L1 */
-- 
2.18.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 0/14 v4] PCI: Remove '*val = 0' from pcie_capability_read_*()
  2020-07-14 11:04 [PATCH 0/14 v4] PCI: Remove '*val = 0' from pcie_capability_read_*() Saheed Olayemi Bolarinwa
  2020-07-14 11:04 ` [PATCH 1/14 v4] IB/hfi1: Check the return value of pcie_capability_read_*() Saheed Olayemi Bolarinwa
@ 2020-07-14 15:49 ` Bjorn Helgaas
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2020-07-14 15:49 UTC (permalink / raw)
  To: Saheed Olayemi Bolarinwa
  Cc: bjorn, skhan, linux-pci, linux-kernel-mentees, linux-kernel,
	Mike Marciniszyn, Dennis Dalessandro, Doug Ledford,
	Jason Gunthorpe, linux-rdma

On Tue, Jul 14, 2020 at 01:04:42PM +0200, Saheed Olayemi Bolarinwa wrote:
> From: Bolarinwa Olayemi Saheed <refactormyself@gmail.com>
> ...

> Bolarinwa Olayemi Saheed (14):
>   IB/hfi1: Check the return value of pcie_capability_read_*()
>   misc: rtsx: Check the return value of pcie_capability_read_*()
>   ath9k: Check the return value of pcie_capability_read_*()
>   iwlegacy: Check the return value of pcie_capability_read_*()
>   PCI: pciehp: Check the return value of pcie_capability_read_*()
>   PCI: pciehp: Make "Power On" the default 
>   PCI: pciehp: Check the return value of pcie_capability_read_*()
>   PCI/ACPI: Check the return value of pcie_capability_read_*()
>   PCI: pciehp: Check the return value of pcie_capability_read_*()
>   PCI: Check the return value of pcie_capability_read_*()
>   PCI/PM: Check return value of pcie_capability_read_*()
>   PCI/AER: Check the return value of pcie_capability_read_*()
>   PCI/ASPM: Check the return value of pcie_capability_read_*()
>   PCI: Remove '*val = 0' from pcie_capability_read_*()

1) Let's slow down on posting patches.  We need time to think and have
a conversation about where we're going, and waking up to dozens of new
patches every day doesn't help.

2) This series claims to have 14 patches, but only 3 made it to the
list.  I don't know if the others were rejected for too many folks in
the cc: list or what.  If you only updated these 3, we will still want
the full set of 14 posted because it's too hard to collect 11 things
from v3 and 3 things from v4, etc.

  $ b4 am -om/ 20200714110445.32605-1-refactormyself@gmail.com
  Looking up https://lore.kernel.org/r/20200714110445.32605-1-refactormyself%40gmail.com
  Grabbing thread from lore.kernel.org/linux-kernel-mentees
  Analyzing 4 messages in the thread
  ---
  Thread incomplete, attempting to backfill
  Grabbing thread from lore.kernel.org/linux-rdma
  Grabbing thread from lore.kernel.org/lkml
  Grabbing thread from lore.kernel.org/linux-pci
  ---
  Writing m/v4_20200714_refactormyself_pci_remove_val_0_from_pcie_capability_read.mbx
    [PATCH 1/14 v4] IB/hfi1: Check the return value of pcie_capability_read_*()
    ERROR: missing [2/14]!
    ERROR: missing [3/14]!
    ERROR: missing [4/14]!
    ERROR: missing [5/14]!
    ERROR: missing [6/14]!
    ERROR: missing [7/14]!
    ERROR: missing [8/14]!
    ERROR: missing [9/14]!
    [PATCH 10/14 v4] PCI: Check return value of pcie_capability_read_*()
    [PATCH 11/14 v4] PCI/PM: Check return value of pcie_capability_read_*()
    ERROR: missing [12/14]!
    ERROR: missing [13/14]!
    ERROR: missing [14/14]!
  ---
  Total patches: 3
  ---
  WARNING: Thread incomplete!
  Cover: m/v4_20200714_refactormyself_pci_remove_val_0_from_pcie_capability_read.cover
   Link: https://lore.kernel.org/r/20200714110445.32605-1-refactormyself@gmail.com
   Base: not found
	 git am m/v4_20200714_refactormyself_pci_remove_val_0_from_pcie_capability_read.mbx


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-14 15:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-14 11:04 [PATCH 0/14 v4] PCI: Remove '*val = 0' from pcie_capability_read_*() Saheed Olayemi Bolarinwa
2020-07-14 11:04 ` [PATCH 1/14 v4] IB/hfi1: Check the return value of pcie_capability_read_*() Saheed Olayemi Bolarinwa
2020-07-14 15:49 ` [PATCH 0/14 v4] PCI: Remove '*val = 0' from pcie_capability_read_*() 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).