| 934e9d13 | 24-Jan-2025 |
Christian Bruel <[email protected]> |
PCI: endpoint: pci-epf-test: Fix double free that causes kernel to oops
Fix a kernel oops found while testing the stm32_pcie Endpoint driver with handling of PERST# deassertion:
During EP initializ
PCI: endpoint: pci-epf-test: Fix double free that causes kernel to oops
Fix a kernel oops found while testing the stm32_pcie Endpoint driver with handling of PERST# deassertion:
During EP initialization, pci_epf_test_alloc_space() allocates all BARs, which are further freed if epc_set_bar() fails (for instance, due to no free inbound window).
However, when pci_epc_set_bar() fails, the error path:
pci_epc_set_bar() -> pci_epf_free_space()
does not clear the previous assignment to epf_test->reg[bar].
Then, if the host reboots, the PERST# deassertion restarts the BAR allocation sequence with the same allocation failure (no free inbound window), creating a double free situation since epf_test->reg[bar] was deallocated and is still non-NULL.
Thus, make sure that pci_epf_alloc_space() and pci_epf_free_space() invocations are symmetric, and as such, set epf_test->reg[bar] to NULL when memory is freed.
Reviewed-by: Niklas Cassel <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Christian Bruel <[email protected]> Link: https://lore.kernel.org/r/[email protected] [kwilczynski: commit log] Signed-off-by: Krzysztof Wilczyński <[email protected]>
show more ...
|
| 8a02612f | 03-Dec-2024 |
Niklas Cassel <[email protected]> |
PCI: endpoint: pci-epf-test: Add support for capabilities
The test BAR is on the EP side is allocated using pci_epf_alloc_space(), which allocates the backing memory using dma_alloc_coherent(), whic
PCI: endpoint: pci-epf-test: Add support for capabilities
The test BAR is on the EP side is allocated using pci_epf_alloc_space(), which allocates the backing memory using dma_alloc_coherent(), which will return zeroed memory regardless of __GFP_ZERO was set or not.
This means that running a new version of pci-endpoint-test.c (host side) with an old version of pci-epf-test.c (EP side) will not see any capabilities being set (as intended), so this is backwards compatible.
Additionally, the EP side always allocates at least 128 bytes for the test BAR (excluding the MSI-X table), this means that adding another register at offset 0x30 is still within the 128 available bytes.
For now, we only add the CAP_UNALIGNED_ACCESS capability.
Set CAP_UNALIGNED_ACCESS if the EPC driver can handle any address (because it implements the .align_addr callback).
Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Niklas Cassel <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Reviewed-by: Frank Li <[email protected]>
show more ...
|
| 235c2b19 | 16-Jan-2025 |
Manivannan Sadhasivam <[email protected]> |
PCI: endpoint: pci-epf-test: Fix check for DMA MEMCPY test
Currently, if DMA MEMCPY test is requested by the host, and if the endpoint DMA controller supports DMA_PRIVATE, the test will fail. This i
PCI: endpoint: pci-epf-test: Fix check for DMA MEMCPY test
Currently, if DMA MEMCPY test is requested by the host, and if the endpoint DMA controller supports DMA_PRIVATE, the test will fail. This is not correct since there is no check for DMA_MEMCPY capability and the DMA controller can support both DMA_PRIVATE and DMA_MEMCPY.
Fix the check and also reword the error message.
Link: https://lore.kernel.org/r/[email protected] Fixes: 8353813c88ef ("PCI: endpoint: Enable DMA tests for endpoints with DMA capabilities") Reported-by: Niklas Cassel <[email protected]> Closes: https://lore.kernel.org/linux-pci/Z3QtEihbiKIGogWA@ryzen Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Tested-by: Niklas Cassel <[email protected]> Reviewed-by: Niklas Cassel <[email protected]>
show more ...
|
| 5089b3d8 | 05-Nov-2024 |
Zhongqiu Han <[email protected]> |
PCI: endpoint: epf-mhi: Avoid NULL dereference if DT lacks 'mmio'
If platform_get_resource_byname() fails and returns NULL because DT lacks an 'mmio' property for the MHI endpoint, dereferencing res
PCI: endpoint: epf-mhi: Avoid NULL dereference if DT lacks 'mmio'
If platform_get_resource_byname() fails and returns NULL because DT lacks an 'mmio' property for the MHI endpoint, dereferencing res->start will cause a NULL pointer access. Add a check to prevent it.
Fixes: 1bf5f25324f7 ("PCI: endpoint: Add PCI Endpoint function driver for MHI bus") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Zhongqiu Han <[email protected]> [kwilczynski: error message update per the review feedback] Signed-off-by: Krzysztof Wilczyński <[email protected]> [bhelgaas: commit log] Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Niklas Cassel <[email protected]>
show more ...
|
| 9b80bdb1 | 04-Nov-2024 |
Wang Jiang <[email protected]> |
PCI: endpoint: Remove surplus return statement from pci_epf_test_clean_dma_chan()
Remove a surplus return statement from the void function that has been added in the commit commit 8353813c88ef ("PCI
PCI: endpoint: Remove surplus return statement from pci_epf_test_clean_dma_chan()
Remove a surplus return statement from the void function that has been added in the commit commit 8353813c88ef ("PCI: endpoint: Enable DMA tests for endpoints with DMA capabilities").
Especially, as an empty return statements at the end of a void functions serve little purpose.
This fixes the following checkpatch.pl script warning:
WARNING: void function return statements are not generally useful #296: FILE: drivers/pci/endpoint/functions/pci-epf-test.c:296: + return; +}
Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wang Jiang <[email protected]> [kwilczynski: commit log] Signed-off-by: Krzysztof Wilczyński <[email protected]>
show more ...
|
| 6bba3c0a | 10-Jun-2024 |
Dan Carpenter <[email protected]> |
PCI: endpoint: Fix error handling in epf_ntb_epc_cleanup()
There are two issues related to epf_ntb_epc_cleanup():
1) It should call epf_ntb_config_sspad_bar_clear() 2) The epf_ntb_bind() functi
PCI: endpoint: Fix error handling in epf_ntb_epc_cleanup()
There are two issues related to epf_ntb_epc_cleanup():
1) It should call epf_ntb_config_sspad_bar_clear() 2) The epf_ntb_bind() function should call epf_ntb_epc_cleanup() to cleanup.
I also changed the ordering a bit. Unwinding should be done in the mirror order from how they are allocated.
Fixes: e35f56bb0330 ("PCI: endpoint: Support NTB transfer between RC and EP") Link: https://lore.kernel.org/linux-pci/[email protected] Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]>
show more ...
|
| 8e0f5a96 | 10-Jun-2024 |
Dan Carpenter <[email protected]> |
PCI: endpoint: Clean up error handling in vpci_scan_bus()
Smatch complains about inconsistent NULL checking in vpci_scan_bus():
drivers/pci/endpoint/functions/pci-epf-vntb.c:1024 vpci_scan_bus(
PCI: endpoint: Clean up error handling in vpci_scan_bus()
Smatch complains about inconsistent NULL checking in vpci_scan_bus():
drivers/pci/endpoint/functions/pci-epf-vntb.c:1024 vpci_scan_bus() error: we previously assumed 'vpci_bus' could be null (see line 1021)
Instead of printing an error message and then crashing we should return an error code and clean up.
Also the NULL check is reversed so it prints an error for success instead of failure.
Fixes: e35f56bb0330 ("PCI: endpoint: Support NTB transfer between RC and EP") Link: https://lore.kernel.org/linux-pci/[email protected] Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]>
show more ...
|
| 473b2cf9 | 06-Jun-2024 |
Manivannan Sadhasivam <[email protected]> |
PCI: endpoint: Introduce 'epc_deinit' event and notify the EPF drivers
As like the 'epc_init' event, that is used to signal the EPF drivers about the EPC initialization, let's introduce 'epc_deinit'
PCI: endpoint: Introduce 'epc_deinit' event and notify the EPF drivers
As like the 'epc_init' event, that is used to signal the EPF drivers about the EPC initialization, let's introduce 'epc_deinit' event that is used to signal EPC deinitialization.
The EPC deinitialization applies only when any sort of fundamental reset is supported by the endpoint controller as per the PCIe spec.
Reference: PCIe r6.0, sec 4.2.5.9.1 and 6.6.1.
Currently, some EPC drivers like pcie-qcom-ep and pcie-tegra194 support PERST# as the fundamental reset. So the 'deinit' event will be notified to the EPF drivers when PERST# assert happens in the above mentioned EPC drivers.
The EPF drivers, on receiving the event through the epc_deinit() callback should reset the EPF state machine and also cleanup any configuration that got affected by the fundamental reset like BAR, DMA etc...
This change also warrants skipping the cleanups in unbind() if already done in epc_deinit().
Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Reviewed-by: Niklas Cassel <[email protected]> Reviewed-by: Siddharth Vadapalli <[email protected]> Reviewed-by: Frank Li <[email protected]>
show more ...
|
| cfc2d4c5 | 30-Apr-2024 |
Manivannan Sadhasivam <[email protected]> |
PCI: endpoint: pci-epf-test: Handle Link Down event
Per PCIe r6.0, sec 5.2, a Link Down event can happen under any of the following circumstances:
1. Fundamental/Hot reset 2. Link disable trans
PCI: endpoint: pci-epf-test: Handle Link Down event
Per PCIe r6.0, sec 5.2, a Link Down event can happen under any of the following circumstances:
1. Fundamental/Hot reset 2. Link disable transmission by upstream component 3. Moving from L2/L3 to L0
When the event happens, the EPC driver capable of detecting it may pass the notification to the EPF driver through link_down() callback in 'struct pci_epc_event_ops'.
While the PCIe spec has not defined the actual behavior of the endpoint when the Link Down event happens, we may assume that at least the ongoing transactions need to be stopped as the link won't be active, so cancel the command handler work in the callback implementation pci_epf_test_link_down(). The work will be started again in pci_epf_test_link_up() once the link comes back again.
Link: https://lore.kernel.org/linux-pci/[email protected] Tested-by: Niklas Cassel <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> [bhelgaas: update spec citation] Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Niklas Cassel <[email protected]>
show more ...
|
| 60bd3e03 | 30-Apr-2024 |
Manivannan Sadhasivam <[email protected]> |
PCI: endpoint: pci-epf-{mhi/test}: Move DMA initialization to EPC init callback
To maintain uniformity across EPF drivers, move DMA initialization to EPC init callback. This will also allow us to de
PCI: endpoint: pci-epf-{mhi/test}: Move DMA initialization to EPC init callback
To maintain uniformity across EPF drivers, move DMA initialization to EPC init callback. This will also allow us to deinit DMA during PERST# assert in the further commits.
For EPC drivers without PERST#, DMA deinit will only happen during driver unbind.
Link: https://lore.kernel.org/linux-pci/[email protected] Tested-by: Niklas Cassel <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Niklas Cassel <[email protected]>
show more ...
|
| 942ceba0 | 30-Apr-2024 |
Manivannan Sadhasivam <[email protected]> |
PCI: endpoint: pci-epf-test: Refactor pci_epf_test_unbind() function
Move the pci_epc_clear_bar() and pci_epf_free_space() code to respective helper functions. This allows reusing the helpers in fut
PCI: endpoint: pci-epf-test: Refactor pci_epf_test_unbind() function
Move the pci_epc_clear_bar() and pci_epf_free_space() code to respective helper functions. This allows reusing the helpers in future commits.
This also requires moving the pci_epf_test_unbind() definition below pci_epf_test_bind() to avoid forward declaration of the above helpers.
No functional change.
Link: https://lore.kernel.org/linux-pci/[email protected] Tested-by: Niklas Cassel <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Niklas Cassel <[email protected]>
show more ...
|
| 6859e4f2 | 18-Apr-2024 |
Manivannan Sadhasivam <[email protected]> |
PCI: endpoint: pci-epf-test: Use 'msix_capable' flag directly in pci_epf_test_alloc_space()
Instead of using a local variable to cache the 'msix_capable' flag, use it directly to simplify the code.
PCI: endpoint: pci-epf-test: Use 'msix_capable' flag directly in pci_epf_test_alloc_space()
Instead of using a local variable to cache the 'msix_capable' flag, use it directly to simplify the code.
Suggested-by: Niklas Cassel <[email protected]> Link: https://lore.kernel.org/linux-pci/[email protected] Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Frank Li <[email protected]> Reviewed-by: Niklas Cassel <[email protected]>
show more ...
|
| 597ac0fa | 20-Mar-2024 |
Niklas Cassel <[email protected]> |
PCI: endpoint: pci-epf-test: Clean up pci_epf_test_unbind()
Clean up pci_epf_test_unbind() by using a continue if we did not allocate memory for the BAR index. This reduces the indentation level by
PCI: endpoint: pci-epf-test: Clean up pci_epf_test_unbind()
Clean up pci_epf_test_unbind() by using a continue if we did not allocate memory for the BAR index. This reduces the indentation level by one.
This makes pci_epf_test_unbind() more similar to pci_epf_test_set_bar().
Link: https://lore.kernel.org/linux-pci/[email protected] Signed-off-by: Niklas Cassel <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]>
show more ...
|
| e49eab94 | 20-Mar-2024 |
Niklas Cassel <[email protected]> |
PCI: endpoint: pci-epf-test: Simplify pci_epf_test_set_bar() loop
Simplify the loop in pci_epf_test_set_bar(). If we allocated memory for the BAR, we need to call set_bar() for that BAR, if we did n
PCI: endpoint: pci-epf-test: Simplify pci_epf_test_set_bar() loop
Simplify the loop in pci_epf_test_set_bar(). If we allocated memory for the BAR, we need to call set_bar() for that BAR, if we did not allocated memory for that BAR, we need to skip. It is as simple as that. This also matches the logic in pci_epf_test_unbind().
A 64-bit BAR will still only be one allocation, with the BAR succeeding the 64-bit BAR being null.
While at it, remove the misleading comment. A EPC .set_bar() callback should never change the epf_bar->flags. (E.g. to set a 64-bit BAR if we requested a 32-bit BAR.)
A .set_bar() callback should do what we request it to do. If it can't satisfy the request, it should return an error.
If platform has a specific requirement, e.g. that a certain BAR has to be a 64-bit BAR, then it should specify that by setting the .only_64bit flag for that specific BAR in epc_features->bar[], such that pci_epf_alloc_space() will return a epf_bar with the 64-bit flag set. (Such that .set_bar() will receive a request to set a 64-bit BAR.)
Link: https://lore.kernel.org/linux-pci/[email protected] Signed-off-by: Niklas Cassel <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]>
show more ...
|