cxl/ras: Fix match_memdev_by_parent() pointer type mismatch
Subsystems (2)
PATCH 1/1 cxl/ras: Fix match_memdev_by_parent() pointer type mismatch
bus_find_device() passes its data argument directly to the match function as a const void *. match_memdev_by_parent() compares dev->parent against this pointer:
dev->parent == uport
cxlmd->dev.parent is set in cxl_memdev_alloc() as:
dev->parent = cxlds->dev; /* cxlds->dev == &pdev->dev */
So cxlmd->dev.parent holds a struct device * pointing to &pdev->dev. However, bus_find_device() is called with pdev (struct pci_dev *) rather than &pdev->dev (struct device *). Since struct pci_dev does not begin with struct device, the two pointer values differ, causing the comparison to always evaluate false.
As a result, cxl_cper_handle_prot_err() silently drops every CPER error report for CXL endpoint devices -- bus_find_device() always returns NULL and the function returns early without emitting any kernel trace event.
Fix by passing &pdev->dev instead of pdev.
--- drivers/cxl/core/ras.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cxl/core/ras.c +1 -2
@@ -94,8 +94,7 @@ void cxl_cper_handle_prot_err(struct cxl_cper_prot_err_work_data *data)if (!pdev->dev.driver)return ; - struct device *mem_dev __free(put_device) = bus_find_device( - &cxl_bus_type,NULL , pdev, match_memdev_by_parent); + struct device *mem_dev __free(put_device) = bus_find_device(&cxl_bus_type, NULL, &pdev->dev, match_memdev_by_parent);if (!mem_dev)return ;
Signature · 1 line
2.34.1
Quoted 21 lines · Terry Bowman
bus_find_device()passes its data argument directly to the match function as a const void *.match_memdev_by_parent()comparesdev->parentagainst this pointer:dev->parent == uport
cxlmd->dev.parentis set incxl_memdev_alloc()as:dev->parent = cxlds->dev; /* cxlds->dev == &pdev->dev */So
cxlmd->dev.parentholds a struct device * pointing to&pdev->dev. However,bus_find_device()is called with pdev (structpci_dev*) rather than&pdev->dev(struct device *). Since structpci_devdoes not begin with struct device, the two pointer values differ, causing the comparison to always evaluate false.As a result,
cxl_cper_handle_prot_err()silently drops every CPER error report for CXL endpoint devices --bus_find_device()always returns NULL and the function returns early without emitting any kernel trace event.
Quoted 5 lines
Fix by passing
&pdev->devinstead of pdev.Fixes 3c70ec71abda ("cxl/ras: Fix CPER handler device confusion")Reported-by Sashiko <[email protected]>Signed-off-by Terry Bowman <[email protected]>
Probably good to keep the original line wrapping. I can fix that on apply.
Quoted 18 lines
--- drivers/cxl/core/ras.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/cxl/core/ras.c +1
-2@@ -94,8 +94,7 @@ void cxl_cper_handle_prot_err(struct cxl_cper_prot_err_work_data *data)if (!pdev->dev.driver)return ; - struct device *mem_dev __free(put_device) = bus_find_device( - &cxl_bus_type,NULL , pdev, match_memdev_by_parent); + struct device *mem_dev __free(put_device) = bus_find_device(&cxl_bus_type, NULL, &pdev->dev, match_memdev_by_parent);if (!mem_dev)return ;
Alison Schofield
maintainerQuoted 21 lines · Terry Bowman
bus_find_device()passes its data argument directly to the match function as a const void *.match_memdev_by_parent()comparesdev->parentagainst this pointer:dev->parent == uport
cxlmd->dev.parentis set incxl_memdev_alloc()as:dev->parent = cxlds->dev; /* cxlds->dev == &pdev->dev */So
cxlmd->dev.parentholds a struct device * pointing to&pdev->dev. However,bus_find_device()is called with pdev (structpci_dev*) rather than&pdev->dev(struct device *). Since structpci_devdoes not begin with struct device, the two pointer values differ, causing the comparison to always evaluate false.As a result,
cxl_cper_handle_prot_err()silently drops every CPER error report for CXL endpoint devices --bus_find_device()always returns NULL and the function returns early without emitting any kernel trace event.
Quoted 5 lines
Fix by passing
&pdev->devinstead of pdev.Fixes 3c70ec71abda ("cxl/ras: Fix CPER handler device confusion")Reported-by Sashiko <[email protected]>Signed-off-by Terry Bowman <[email protected]>
Hi Terry,
The commit log is burying the lead- no endpoint errors reported.
There is no need for the full struct layout analysis in the changelog. The important part in the functional regression and the pointer mismatch as root cause.
Please reframe the commit message along the lines of background, problem, cause, fix, and validation. Something like-
CXL endpoint CPER protocol errors are processed by ...
Following commit 3c70ec71abda, endpoint CPER protocol errors are silently dropped and no trace events are emitted. This happens because bus_find_device() is called with the wrong pointer type, so the memdev parent match never succeeds.
Fix it by ...
How do we know it works now?
-- Alison
Quoted 21 lines
--- drivers/cxl/core/ras.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/cxl/core/ras.c +1
-2@@ -94,8 +94,7 @@ void cxl_cper_handle_prot_err(struct cxl_cper_prot_err_work_data *data)if (!pdev->dev.driver)return ; - struct device *mem_dev __free(put_device) = bus_find_device( - &cxl_bus_type,NULL , pdev, match_memdev_by_parent); + struct device *mem_dev __free(put_device) = bus_find_device(&cxl_bus_type, NULL, &pdev->dev, match_memdev_by_parent);if (!mem_dev)return ;Signature · 1 line
2.34.1
Quoted 39 lines · Alison Schofield
Quoted 21 lines · Terry Bowman
bus_find_device()passes its data argument directly to the match function as a const void *.match_memdev_by_parent()comparesdev->parentagainst this pointer:dev->parent == uport
cxlmd->dev.parentis set incxl_memdev_alloc()as:dev->parent = cxlds->dev; /* cxlds->dev == &pdev->dev */So
cxlmd->dev.parentholds a struct device * pointing to&pdev->dev. However,bus_find_device()is called with pdev (structpci_dev*) rather than&pdev->dev(struct device *). Since structpci_devdoes not begin with struct device, the two pointer values differ, causing the comparison to always evaluate false.As a result,
cxl_cper_handle_prot_err()silently drops every CPER error report for CXL endpoint devices --bus_find_device()always returns NULL and the function returns early without emitting any kernel trace event.Quoted 5 lines
Fix by passing
&pdev->devinstead of pdev.Fixes 3c70ec71abda ("cxl/ras: Fix CPER handler device confusion")Reported-by Sashiko <[email protected]>Signed-off-by Terry Bowman <[email protected]>Hi Terry,
The commit log is burying the lead- no endpoint errors reported.
There is no need for the full struct layout analysis in the changelog. The important part in the functional regression and the pointer mismatch as root cause.
Please reframe the commit message along the lines of background, problem, cause, fix, and validation. Something like-
Quoted 9 lines
CXL endpoint CPER protocol errors are processed by ...
Following commit
3c70ec71abda, endpoint CPER protocol errors are silently dropped and no trace events are emitted. This happens becausebus_find_device()is called with the wrong pointer type, so the memdev parent match never succeeds.Fix it by ...
Ok.
Quoted 6 lines
How do we know it works now?
-- Alison
I have not tested this patch yet.
- Terry
Quoted 23 lines
Quoted 23 lines
--- drivers/cxl/core/ras.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/cxl/core/ras.c +1
-2@@ -94,8 +94,7 @@ void cxl_cper_handle_prot_err(struct cxl_cper_prot_err_work_data *data)if (!pdev->dev.driver)return ; - struct device *mem_dev __free(put_device) = bus_find_device( - &cxl_bus_type,NULL , pdev, match_memdev_by_parent); + struct device *mem_dev __free(put_device) = bus_find_device(&cxl_bus_type, NULL, &pdev->dev, match_memdev_by_parent);if (!mem_dev)return ;Signature · 1 line
2.34.1
Alison Schofield
maintainerQuoted 53 lines · Terry
Quoted 39 lines · Alison Schofield
Quoted 21 lines · Terry Bowman
bus_find_device()passes its data argument directly to the match function as a const void *.match_memdev_by_parent()comparesdev->parentagainst this pointer:dev->parent == uport
cxlmd->dev.parentis set incxl_memdev_alloc()as:dev->parent = cxlds->dev; /* cxlds->dev == &pdev->dev */So
cxlmd->dev.parentholds a struct device * pointing to&pdev->dev. However,bus_find_device()is called with pdev (structpci_dev*) rather than&pdev->dev(struct device *). Since structpci_devdoes not begin with struct device, the two pointer values differ, causing the comparison to always evaluate false.As a result,
cxl_cper_handle_prot_err()silently drops every CPER error report for CXL endpoint devices --bus_find_device()always returns NULL and the function returns early without emitting any kernel trace event.Quoted 5 lines
Fix by passing
&pdev->devinstead of pdev.Fixes 3c70ec71abda ("cxl/ras: Fix CPER handler device confusion")Reported-by Sashiko <[email protected]>Signed-off-by Terry Bowman <[email protected]>Hi Terry,
The commit log is burying the lead- no endpoint errors reported.
There is no need for the full struct layout analysis in the changelog. The important part in the functional regression and the pointer mismatch as root cause.
Please reframe the commit message along the lines of background, problem, cause, fix, and validation. Something like-
Quoted 9 lines
CXL endpoint CPER protocol errors are processed by ...
Following commit
3c70ec71abda, endpoint CPER protocol errors are silently dropped and no trace events are emitted. This happens becausebus_find_device()is called with the wrong pointer type, so the memdev parent match never succeeds.Fix it by ...
Ok.
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
How do we know it works now?
-- Alison
I have not tested this patch yet.
I am intentionally being a pest on the commit message, however I am not intentionally being a pest on the testing of this patch, because it is obviously wrong code and obvious that the errors cannot be reported unless this is fixed.
I was just after confirmation that we now see the errors once again, and it's not something else that is broken.
--Alison
Quoted 27 lines
- Terry
Quoted 23 lines
Quoted 23 lines
--- drivers/cxl/core/ras.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/cxl/core/ras.c +1
-2@@ -94,8 +94,7 @@ void cxl_cper_handle_prot_err(struct cxl_cper_prot_err_work_data *data)if (!pdev->dev.driver)return ; - struct device *mem_dev __free(put_device) = bus_find_device( - &cxl_bus_type,NULL , pdev, match_memdev_by_parent); + struct device *mem_dev __free(put_device) = bus_find_device(&cxl_bus_type, NULL, &pdev->dev, match_memdev_by_parent);if (!mem_dev)return ;Signature · 1 line
2.34.1