cxl/pci: Get AER capability address from RCRB only for RCH dport
PATCH 1/1 cxl/pci: Get AER capability address from RCRB only for RCH dport
cxl_setup_parent_dport() needs to get RCH dport AER capability address from RCRB to disable AER interrupt. The function does not check if dport is RCH dport, it will get a wrong pci_host_bridge structure by dport_dev in VH case because dport_dev points to a pci device(RP or switch DSP) rather than a pci host bridge device.
Besides, cxl_setup_parent_dport() can exit simply if a RCH dport in the RCH topology created by cxl-test, in the case, the RCH dport's dport_dev is a platform device, and RCH dport with an available RCRB and AER Capability is not supported yet.
--- drivers/cxl/core/pci.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/cxl/core/pci.c +10 -4
@@ -4,6 +4,7 @@#include <linux/io-64-nonatomic-lo-hi.h> #include <linux/device.h> #include <linux/delay.h> +#include <linux/platform_device.h> #include <linux/pci.h> #include <linux/pci-doe.h> #include <linux/aer.h>
@@ -834,11 +835,16 @@ static void cxl_disable_rch_root_ints(struct cxl_dport *dport)void cxl_setup_parent_dport (struct device *host,struct cxl_dport *dport) {struct device *dport_dev = dport->dport_dev; -struct pci_host_bridge *host_bridge; - host_bridge =to_pci_host_bridge (dport_dev); -if (host_bridge->native_aer) - dport->rcrb.aer_cap =cxl_rcrb_to_aer (dport_dev, dport->rcrb.base); +if (dev_is_platform (dport_dev)) +return ; + +if (dport->rch) { +struct pci_host_bridge *host_bridge =to_pci_host_bridge (dport_dev); + +if (host_bridge->native_aer) + dport->rcrb.aer_cap =cxl_rcrb_to_aer (dport_dev, dport->rcrb.base); + } dport->reg_map.host = host;cxl_dport_map_regs (dport);
Signature · 1 line
2.40.1
Alison Schofield
maintainerQuoted 5 lines · Li Ming
cxl_setup_parent_dport()needs to get RCH dport AER capability address from RCRB to disable AER interrupt. The function does not check if dport is RCH dport, it will get a wrongpci_host_bridgestructure bydport_devin VH case becausedport_devpoints to a pci device(RP or switch DSP) rather than a pci host bridge device.
Ming,
Please add that this leads to a page fault. (from off-list chat)
Quoted 25 lines
Besides,
cxl_setup_parent_dport()can exit simply if a RCH dport in the RCH topology created by cxl-test, in the case, the RCH dport'sdport_devis a platform device, and RCH dport with an available RCRB and AER Capability is not supported yet.Fixes f05fd10d138d ("cxl/pci: Add RCH downstream port AER register discovery")Signed-off-by Li Ming <[email protected]>--- drivers/cxl/core/pci.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)drivers/cxl/core/pci.c +1
-0@@ -4,6 +4,7 @@#include <linux/io-64-nonatomic-lo-hi.h> #include <linux/device.h> #include <linux/delay.h> +#include <linux/platform_device.h> #include <linux/pci.h> #include <linux/pci-doe.h> #include <linux/aer.h>
drivers/cxl/core/pci.c static void cxl_disable_rch_root_ints(struct cxl_dport *dport) · line 840
Quoted 10 lines
drivers/cxl/core/pci.c +2
-4@@ -834,11 +835,16 @@ static void cxl_disable_rch_root_ints(struct cxl_dport *dport)void cxl_setup_parent_dport (struct device *host,struct cxl_dport *dport) {struct device *dport_dev = dport->dport_dev; -struct pci_host_bridge *host_bridge; - host_bridge =to_pci_host_bridge (dport_dev); -if (host_bridge->native_aer) - dport->rcrb.aer_cap =cxl_rcrb_to_aer (dport_dev, dport->rcrb.base); +if (dev_is_platform (dport_dev)) +return ;
The above, dev_is_plaform(), is the cxl-test only case - right? I'm wondering if we need to mock something differently in cxl-test because it is unusual to have a cxl-test special case in the driver.
Let's see what others say.
--Alison
Quoted 14 lines
drivers/cxl/core/pci.c +7
-0+ +if (dport->rch) { +struct pci_host_bridge *host_bridge =to_pci_host_bridge (dport_dev); + +if (host_bridge->native_aer) + dport->rcrb.aer_cap =cxl_rcrb_to_aer (dport_dev, dport->rcrb.base); + } dport->reg_map.host = host;cxl_dport_map_regs (dport);Signature · 1 line
2.40.1
Quoted 9 lines · Alison Schofield
Quoted 5 lines · Li Ming
cxl_setup_parent_dport()needs to get RCH dport AER capability address from RCRB to disable AER interrupt. The function does not check if dport is RCH dport, it will get a wrongpci_host_bridgestructure bydport_devin VH case becausedport_devpoints to a pci device(RP or switch DSP) rather than a pci host bridge device.Ming,
Please add that this leads to a page fault. (from off-list chat)
Sure, will do it.
Quoted 30 lines
Quoted 30 lines
Besides,
cxl_setup_parent_dport()can exit simply if a RCH dport in the RCH topology created by cxl-test, in the case, the RCH dport'sdport_devis a platform device, and RCH dport with an available RCRB and AER Capability is not supported yet.Fixes f05fd10d138d ("cxl/pci: Add RCH downstream port AER register discovery")Signed-off-by Li Ming <[email protected]>--- drivers/cxl/core/pci.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)drivers/cxl/core/pci.c +1
-1@@ -4,6 +4,7 @@#include <linux/io-64-nonatomic-lo-hi.h> #include <linux/device.h> #include <linux/delay.h> +#include <linux/platform_device.h> #include <linux/pci.h> #include <linux/pci-doe.h> #include <linux/aer.h> @@ -834,11 +835,16 @@ static void cxl_disable_rch_root_ints(struct cxl_dport *dport)void cxl_setup_parent_dport (struct device *host,struct cxl_dport *dport) {struct device *dport_dev = dport->dport_dev; -struct pci_host_bridge *host_bridge;
Quoted 6 lines
drivers/cxl/core/pci.c static void cxl_disable_rch_root_ints(struct cxl_dport *dport) · line 840
Quoted 5 lines
drivers/cxl/core/pci.c +2
-3- host_bridge =to_pci_host_bridge (dport_dev); -if (host_bridge->native_aer) - dport->rcrb.aer_cap =cxl_rcrb_to_aer (dport_dev, dport->rcrb.base); +if (dev_is_platform (dport_dev)) +return ;The above,
dev_is_plaform(), is the cxl-test only case - right?
Thanks for review.
Right, only dports created by cxl-test using platform_device as dport->dport_dev.
Quoted 2 lines
I'm wondering if we need to mock something differently in cxl-test because it is unusual to have a cxl-test special case in the driver.
Make sense, what do you think if I implement a mock function like mock_cxl_setup_parent_dport() for the case? The mock function can check if the dport is created by cxl-test then skip it.
Ming
Quoted 21 lines
Let's see what others say.
--Alison
Quoted 14 lines
drivers/cxl/core/pci.c +7
-0+ +if (dport->rch) { +struct pci_host_bridge *host_bridge =to_pci_host_bridge (dport_dev); + +if (host_bridge->native_aer) + dport->rcrb.aer_cap =cxl_rcrb_to_aer (dport_dev, dport->rcrb.base); + } dport->reg_map.host = host;cxl_dport_map_regs (dport);Signature · 1 line
2.40.1
Alison Schofield
maintainerQuoted 53 lines · On Thu, Aug 08, 2024 at 09:26:23AM +0800, Li, Ming4 wrote:
Quoted 9 lines · Alison Schofield
Quoted 5 lines · Li Ming
cxl_setup_parent_dport()needs to get RCH dport AER capability address from RCRB to disable AER interrupt. The function does not check if dport is RCH dport, it will get a wrongpci_host_bridgestructure bydport_devin VH case becausedport_devpoints to a pci device(RP or switch DSP) rather than a pci host bridge device.Ming,
Please add that this leads to a page fault. (from off-list chat)
Sure, will do it.
Quoted 30 lines
Quoted 30 lines
Besides,
cxl_setup_parent_dport()can exit simply if a RCH dport in the RCH topology created by cxl-test, in the case, the RCH dport'sdport_devis a platform device, and RCH dport with an available RCRB and AER Capability is not supported yet.Fixes f05fd10d138d ("cxl/pci: Add RCH downstream port AER register discovery")Signed-off-by Li Ming <[email protected]>--- drivers/cxl/core/pci.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)drivers/cxl/core/pci.c +1
-1@@ -4,6 +4,7 @@#include <linux/io-64-nonatomic-lo-hi.h> #include <linux/device.h> #include <linux/delay.h> +#include <linux/platform_device.h> #include <linux/pci.h> #include <linux/pci-doe.h> #include <linux/aer.h> @@ -834,11 +835,16 @@ static void cxl_disable_rch_root_ints(struct cxl_dport *dport)void cxl_setup_parent_dport (struct device *host,struct cxl_dport *dport) {struct device *dport_dev = dport->dport_dev; -struct pci_host_bridge *host_bridge;Quoted 6 lines
drivers/cxl/core/pci.c static void cxl_disable_rch_root_ints(struct cxl_dport *dport) · line 840
Quoted 5 lines
drivers/cxl/core/pci.c +2
-3- host_bridge =to_pci_host_bridge (dport_dev); -if (host_bridge->native_aer) - dport->rcrb.aer_cap =cxl_rcrb_to_aer (dport_dev, dport->rcrb.base); +if (dev_is_platform (dport_dev)) +return ;The above,
dev_is_plaform(), is the cxl-test only case - right?Thanks for review.
Quoted 8 lines
Right, only dports created by cxl-test using
platform_deviceasdport->dport_dev.Quoted 2 lines
I'm wondering if we need to mock something differently in cxl-test because it is unusual to have a cxl-test special case in the driver.
Make sense, what do you think if I implement a mock function like
mock_cxl_setup_parent_dport()for the case? The mock function can check if the dport is created by cxl-test then skip it.
Sounds good to me :)
Quoted 25 lines
Ming
Quoted 21 lines
Let's see what others say.
--Alison
Quoted 14 lines
drivers/cxl/core/pci.c +7
-0+ +if (dport->rch) { +struct pci_host_bridge *host_bridge =to_pci_host_bridge (dport_dev); + +if (host_bridge->native_aer) + dport->rcrb.aer_cap =cxl_rcrb_to_aer (dport_dev, dport->rcrb.base); + } dport->reg_map.host = host;cxl_dport_map_regs (dport);Signature · 1 line
2.40.1
Hi Ming and all,
I met "BUG: slab-out-of-bounds in cxl_setup_parent_dport" problem in v6.10 kernel in cxl-test qemu environment:
https://lore.kernel.org/linux-cxl/[email protected]/T/#u
And this patch could fix this problem.
Best Regards,
Thanks!
Quoted 53 lines · Li Ming
cxl_setup_parent_dport()needs to get RCH dport AER capability address from RCRB to disable AER interrupt. The function does not check if dport is RCH dport, it will get a wrongpci_host_bridgestructure bydport_devin VH case becausedport_devpoints to a pci device(RP or switch DSP) rather than a pci host bridge device.Besides,
cxl_setup_parent_dport()can exit simply if a RCH dport in the RCH topology created by cxl-test, in the case, the RCH dport'sdport_devis a platform device, and RCH dport with an available RCRB and AER Capability is not supported yet.Fixes f05fd10d138d ("cxl/pci: Add RCH downstream port AER register discovery")Signed-off-by Li Ming <[email protected]>--- drivers/cxl/core/pci.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)drivers/cxl/core/pci.c +10
-4@@ -4,6 +4,7 @@#include <linux/io-64-nonatomic-lo-hi.h> #include <linux/device.h> #include <linux/delay.h> +#include <linux/platform_device.h> #include <linux/pci.h> #include <linux/pci-doe.h> #include <linux/aer.h> @@ -834,11 +835,16 @@ static void cxl_disable_rch_root_ints(struct cxl_dport *dport)void cxl_setup_parent_dport (struct device *host,struct cxl_dport *dport) {struct device *dport_dev = dport->dport_dev; -struct pci_host_bridge *host_bridge; - host_bridge =to_pci_host_bridge (dport_dev); -if (host_bridge->native_aer) - dport->rcrb.aer_cap =cxl_rcrb_to_aer (dport_dev, dport->rcrb.base); +if (dev_is_platform (dport_dev)) +return ; + +if (dport->rch) { +struct pci_host_bridge *host_bridge =to_pci_host_bridge (dport_dev); + +if (host_bridge->native_aer) + dport->rcrb.aer_cap =cxl_rcrb_to_aer (dport_dev, dport->rcrb.base); + } dport->reg_map.host = host;cxl_dport_map_regs (dport);Signature · 1 line
2.40.1