cxl/pci: Fix the incorrect check of pci_config_read/write*() returns
Dave Jiang
maintainerv2 cover cxl/pci: Fix the incorrect check of pci_config_read/write*() returns
v2:
- Fixed up additional bits (Alison)
- Fix up fixes tag (Alison)
The patches are inspired by comments from Richard Cheng WRT pci config accessors return PCIBIOS errors that are positive integers rather than negative errnos. I went and audited the cxl PCI code and found a few locations that need to be fixed. There are other locations that may trigger issues, but at this point we'll fix them as they happen.
Dave Jiang (2):
cxl/pci: Fix the incorrect check of pci_read_config_word() return cxl/pci: Convert PCIBIOS errors to errno on DVSEC config accesses
drivers/cxl/core/pci.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
base-commit: e43ffb69e0438cddd72aaa30898b4dc446f664f8
Signature · 1 line
2.54.0
Dave Jiang
maintainerPATCH v2 1/2 cxl/pci: Fix the incorrect check of pci_read_config_word() return
pci_read_config_word() returns PCIBIOS_* status on error which are positive values. The check should be for non-zero values to indicate error. Fix cxl_set_mem_enable() to check for non-zero return value instead of negative value.
While fixing this, also convert the error to negative errno value when returning on error path.
--- drivers/cxl/core/pci.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/cxl/core/pci.c +4 -4
@@ -187,8 +187,8 @@ static int cxl_set_mem_enable(struct cxl_dev_state *cxlds, u16 val)int rc; rc =pci_read_config_word (pdev, d +PCI_DVSEC_CXL_CTRL , &ctrl); -if (rc <0 ) -return rc; +if (rc) +return pcibios_err_to_errno (rc);if ((ctrl &PCI_DVSEC_CXL_MEM_ENABLE ) == val)return 1 ;
@@ -196,8 +196,8 @@ static int cxl_set_mem_enable(struct cxl_dev_state *cxlds, u16 val) ctrl |= val; rc =pci_write_config_word (pdev, d +PCI_DVSEC_CXL_CTRL , ctrl); -if (rc <0 ) -return rc; +if (rc) +return pcibios_err_to_errno (rc);return 0 ; }
Signature · 1 line
2.54.0
Dave Jiang
maintainerPATCH v2 2/2 cxl/pci: Convert PCIBIOS errors to errno on DVSEC config accesses
In reply to Dave JiangPCI config space accessors return positive PCIBIOS_* status codes on failure that are positive integers. Several DVSEC accesses in the CXL core propagated these raw values to callers that test for failure against less than 0. Thus silently misinterpret the return value as success.
Convert the postive error values to negative errno values so the checks are correct on error paths.
While the chances of a config access failure are low, fix for correctness and to avoid confusion in the future when more DVSEC accesses are added.
---
v2:
- Fixup cxl_dvsec_mem_range_active() and cxl_awai_media_ready(). (Alison)
- Fix fixes tag (Alison)
--- drivers/cxl/core/pci.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/cxl/core/pci.c +9 -9
@@ -89,7 +89,7 @@ static int cxl_dvsec_mem_range_valid(struct cxl_dev_state *cxlds, int id) d +PCI_DVSEC_CXL_RANGE_SIZE_LOW (id), &temp);if (rc) -return rc; +return pcibios_err_to_errno (rc); valid =FIELD_GET (PCI_DVSEC_CXL_MEM_INFO_VALID , temp);if (valid)
@@ -123,7 +123,7 @@ static int cxl_dvsec_mem_range_active(struct cxl_dev_state *cxlds, int id) rc =pci_read_config_dword ( pdev, d +PCI_DVSEC_CXL_RANGE_SIZE_LOW (id), &temp);if (rc) -return rc; +return pcibios_err_to_errno (rc); active =FIELD_GET (PCI_DVSEC_CXL_MEM_ACTIVE , temp);if (active)
@@ -156,7 +156,7 @@ int cxl_await_media_ready(struct cxl_dev_state *cxlds) rc =pci_read_config_word (pdev, d +PCI_DVSEC_CXL_CAP , &cap);if (rc) -return rc; +return pcibios_err_to_errno (rc); hdm_count =FIELD_GET (PCI_DVSEC_CXL_HDM_COUNT , cap);for (i =0 ; i < hdm_count; i++) {
@@ -275,7 +275,7 @@ int cxl_dvsec_rr_decode(struct cxl_dev_state *cxlds, rc =pci_read_config_word (pdev, d +PCI_DVSEC_CXL_CAP , &cap);if (rc) -return rc; +return pcibios_err_to_errno (rc);if (!(cap &PCI_DVSEC_CXL_MEM_CAPABLE )) {dev_dbg (dev,"Not MEM Capable\n" );
@@ -299,7 +299,7 @@ int cxl_dvsec_rr_decode(struct cxl_dev_state *cxlds,*/ rc =pci_read_config_word (pdev, d +PCI_DVSEC_CXL_CTRL , &ctrl);if (rc) -return rc; +return pcibios_err_to_errno (rc); info->mem_enabled =FIELD_GET (PCI_DVSEC_CXL_MEM_ENABLE , ctrl);if (!info->mem_enabled)
@@ -316,14 +316,14 @@ int cxl_dvsec_rr_decode(struct cxl_dev_state *cxlds, rc =pci_read_config_dword ( pdev, d +PCI_DVSEC_CXL_RANGE_SIZE_HIGH (i), &temp);if (rc) -return rc; +return pcibios_err_to_errno (rc); size = (u64 )temp <<32 ; rc =pci_read_config_dword ( pdev, d +PCI_DVSEC_CXL_RANGE_SIZE_LOW (i), &temp);if (rc) -return rc; +return pcibios_err_to_errno (rc); size |= temp &PCI_DVSEC_CXL_MEM_SIZE_LOW ;if (!size) {
@@ -333,14 +333,14 @@ int cxl_dvsec_rr_decode(struct cxl_dev_state *cxlds, rc =pci_read_config_dword ( pdev, d +PCI_DVSEC_CXL_RANGE_BASE_HIGH (i), &temp);if (rc) -return rc; +return pcibios_err_to_errno (rc); base = (u64 )temp <<32 ; rc =pci_read_config_dword ( pdev, d +PCI_DVSEC_CXL_RANGE_BASE_LOW (i), &temp);if (rc) -return rc; +return pcibios_err_to_errno (rc); base |= temp &PCI_DVSEC_CXL_MEM_BASE_LOW ;
Signature · 1 line
2.54.0
Re: [PATCH v2 2/2] cxl/pci: Convert PCIBIOS errors to errno on DVSEC config accesses
Quoted 6 lines · Dave Jiang
PCI config space accessors return positive PCIBIOS_* status codes on failure that are positive integers. Several DVSEC accesses in the CXL core propagated these raw values to callers that test for failure against less than 0. Thus silently misinterpret the return value as success.
Convert the postive error values to negative errno values so the checks
positive
Quoted 5 lines
are correct on error paths.
While the chances of a config access failure are low, fix for correctness and to avoid confusion in the future when more DVSEC accesses are added.
Quoted 15 lines · Dave Jiang
v2:
- Fixed up additional bits (Alison)
- Fix up fixes tag (Alison)The patches are inspired by comments from Richard Cheng WRT pci config accessors return PCIBIOS errors that are positive integers rather than negative errnos. I went and audited the cxl PCI code and found a few locations that need to be fixed. There are other locations that may trigger issues, but at this point we'll fix them as they happen.
Dave Jiang (2):
cxl/pci: Fix the incorrect check ofpci_read_config_word()return cxl/pci: Convert PCIBIOS errors to errno on DVSEC config accesses
Quoted 5 lines
drivers/cxl/core/pci.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)base-commit:
e43ffb69e0438cddd72aaa30898b4dc446f664f8
merged to cxl/next
66782cfa008526aa60e02762