From: Christian Bruel christian.bruel@foss.st.com
[ Upstream commit 106fc08b30a2ece49a251b053165a83d41d50fd0 ]
The pci_endpoint_test tests the entire MSI/MSI-X range, which generates false errors on platforms that do not support the whole range.
Skip the test in such cases and report accordingly.
Signed-off-by: Christian Bruel christian.bruel@foss.st.com [mani: reworded description] Signed-off-by: Manivannan Sadhasivam mani@kernel.org Link: https://patch.msgid.link/20250804170916.3212221-4-christian.bruel@foss.st.co... Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
YES
**Why This Fix Matters** - Prevents false test failures: The tests iterate full MSI/MSI-X ranges regardless of what was actually allocated on the device. When a vector index is out of range, the kernel returns -EINVAL, which the old test treated as a failure. - Skips unsupported cases correctly: The new checks treat out-of-range vectors as “not applicable” and mark the test as skipped, which accurately reflects platform capability instead of reporting an error.
**What Changed (Selftests Only)** - In `tools/testing/selftests/pci_endpoint/pci_endpoint_test.c:122` and `:140`, after triggering an IRQ: - MSI loop: `pci_ep_ioctl(PCITEST_MSI, i);` then `if (ret == -EINVAL) SKIP(return, "MSI%d is disabled", i);` (`tools/testing/selftests/pci _endpoint/pci_endpoint_test.c:123`–`:126`) - MSI-X loop: `pci_ep_ioctl(PCITEST_MSIX, i);` then `if (ret == -EINVAL) SKIP(return, "MSI-X%d is disabled", i);` (`tools/testing/se lftests/pci_endpoint/pci_endpoint_test.c:141`–`:144`) - Uses existing kselftest skip mechanism (`SKIP(...)`) which is well- established in the harness (`tools/testing/selftests/kselftest_harness.h:110`–`:134`).
**Why -EINVAL Means “Out of Range” Here** - The endpoint test driver queries the Linux IRQ number for a given vector via `pci_irq_vector(pdev, msi_num - 1)`, and immediately returns that error when negative (`drivers/misc/pci_endpoint_test.c:441`–`:443`). - `pci_irq_vector()` returns -EINVAL precisely when the vector index is out of range/not allocated for the device (`drivers/pci/msi/api.c:311`–`:324`), which happens when the device supports fewer MSI/MSI-X vectors than the upper bound tested (MSI up to 32, MSI-X up to 2048).
**Scope and Risk** - Small, contained change; affects only kselftests (no runtime kernel code). - No API or architectural changes; just improves test correctness by skipping unsupported cases. - Mirrors existing skip behavior already used in the same test suite (e.g., BAR test skips when disabled, `tools/testing/selftests/pci_endpoint/pci_endpoint_test.c:67`–`:70`). - No security impact.
**Stable Backport Criteria** - Fixes a real issue that affects users of stable kernels running selftests (false negatives on platforms with limited MSI/MSI-X vectors). - Minimal risk and fully confined to `tools/testing/selftests`. - Does not introduce new features; aligns with stable policy for test fixes.
Given the above, this is a good candidate for stable backport.
tools/testing/selftests/pci_endpoint/pci_endpoint_test.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/tools/testing/selftests/pci_endpoint/pci_endpoint_test.c b/tools/testing/selftests/pci_endpoint/pci_endpoint_test.c index da0db0e7c9693..cd9075444c32a 100644 --- a/tools/testing/selftests/pci_endpoint/pci_endpoint_test.c +++ b/tools/testing/selftests/pci_endpoint/pci_endpoint_test.c @@ -121,6 +121,8 @@ TEST_F(pci_ep_basic, MSI_TEST)
for (i = 1; i <= 32; i++) { pci_ep_ioctl(PCITEST_MSI, i); + if (ret == -EINVAL) + SKIP(return, "MSI%d is disabled", i); EXPECT_FALSE(ret) TH_LOG("Test failed for MSI%d", i); } } @@ -137,6 +139,8 @@ TEST_F(pci_ep_basic, MSIX_TEST)
for (i = 1; i <= 2048; i++) { pci_ep_ioctl(PCITEST_MSIX, i); + if (ret == -EINVAL) + SKIP(return, "MSI-X%d is disabled", i); EXPECT_FALSE(ret) TH_LOG("Test failed for MSI-X%d", i); } }