|WARNING| [v2] common/cnxk: use one interrupt handle per vector
dpdklab at iol.unh.edu
dpdklab at iol.unh.edu
Tue Nov 10 18:22:27 CET 2026
Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/172807
_AI Code Review_
=== Patch Review: series.patch (via Claude) ===
Review date: 2026-11-10
# DPDK Patch Review
## ERRORS
**Error 1: Unsafe list removal in unregister path**
Line 303-304 (and repeated at 332-333):
```c
plt_spinlock_lock(&plt_irq_vec_lock);
irq_vec = irq_vec_find(intr_handle, vec);
plt_spinlock_unlock(&plt_irq_vec_lock);
```
The lock is released between finding the entry and using it.
Another thread could remove this entry from the list or free it between unlock and the subsequent access at line 307 (`if (irq_vec == NULL)`).
This is a use-after-free and race condition.
**Fix:** Hold the lock until after all operations on `irq_vec` are complete, or use reference counting.
```c
plt_spinlock_lock(&plt_irq_vec_lock);
irq_vec = irq_vec_find(intr_handle, vec);
if (irq_vec == NULL) {
if (plt_intr_efds_index_get(intr_handle, vec) != -1)
plt_err("Error unregistering MSI-X vec %d cb, not registered", vec);
plt_spinlock_unlock(&plt_irq_vec_lock);
return;
}
if (irq_vec->cb != cb || irq_vec->data != data) {
plt_err("MSI-X vec %d registered with a different callback", vec);
plt_spinlock_unlock(&plt_irq_vec_lock);
return;
}
TAILQ_REMOVE(&plt_irq_vec_list, irq_vec, next);
plt_spinlock_unlock(&plt_irq_vec_lock);
/* Now safe to operate on irq_vec outside the lock */
do {
rc = plt_intr_callback_unregister(irq_vec->handle, cb, data);
/* ... */
} while (rc == -EAGAIN && retries--);
/* ... */
irq_vec_free(irq_vec);
```
---
**Error 2: Resource leak on `plt_intr_type_set()` failure**
Line 239-242:
```c
if (plt_intr_type_set(irq_vec->handle, plt_intr_type_get(intr_handle))) {
rc = -EINVAL;
goto free_vec;
}
```
The eventfd `fd` was set into `irq_vec->handle` at line 231, but if `plt_intr_type_set()` fails, the `goto free_vec` path calls `irq_vec_free()` which calls `plt_intr_fd_close()`.
However, the fd was never closed before being set into the handle, so if `plt_intr_fd_close()` does not close it (or if it does but the error path is taken before that), the fd leaks.
**Fix:** Ensure `irq_vec_free()` always closes the fd, or close it explicitly on this error path before jumping to `free_vec`.
Since `irq_vec_free()` calls `plt_intr_fd_close()`, verify that function actually closes the fd.
If it does not, add an explicit `close(fd)` before the goto.
---
**Error 3: Missing unregister of callback on partial failure**
Line 261-264:
```c
rc = plt_intr_efds_index_set(intr_handle, vec, fd);
if (rc) {
plt_intr_callback_unregister(irq_vec->handle, cb, data);
goto remove_vec;
}
```
The callback unregister is present, but if `irq_config()` (line 278) fails, the callback is not unregistered.
After line 259, if any subsequent step fails, the callback remains registered, leaking the callback and causing a dangling reference to `data`.
**Fix:** Add a cleanup label that unregisters the callback before `remove_vec` and use it for all failures after line 259.
```c
rc = plt_intr_efds_index_set(intr_handle, vec, fd);
if (rc)
goto unreg_cb;
nb_efd = (vec > (uint32_t)plt_intr_nb_efd_get(intr_handle)) ?
vec : (uint32_t)plt_intr_nb_efd_get(intr_handle);
/* ... */
/* Enable MSIX vectors to VFIO */
rc = irq_config(intr_handle, vec);
if (rc)
goto unreg_cb;
return 0;
unreg_cb:
plt_intr_callback_unregister(irq_vec->handle, cb, data);
remove_vec:
plt_spinlock_lock(&plt_irq_vec_lock);
TAILQ_REMOVE(&plt_irq_vec_list, irq_vec, next);
plt_spinlock_unlock(&plt_irq_vec_lock);
free_vec:
irq_vec_free(irq_vec);
return rc;
```
---
**Error 4: Eventfd leaked on `plt_intr_fd_set()` failure**
Line 231-235:
```c
if (plt_intr_fd_set(irq_vec->handle, fd)) {
close(fd);
rc = -EINVAL;
goto free_vec;
}
```
The `close(fd)` is present, so this is actually correct.
However, verify that `plt_intr_fd_close(irq_vec->handle)` in `irq_vec_free()` does not attempt to close the fd again if `plt_intr_fd_set()` failed.
If `plt_intr_fd_set()` leaves the handle's fd unset on failure, the double-close is avoided.
If it sets the fd before failing, the `close(fd)` followed by `plt_intr_fd_close()` in `irq_vec_free()` would double-close.
**Fix:** Confirm `plt_intr_fd_set()` behavior.
If it sets the fd before failing, remove the explicit `close(fd)` and rely on `irq_vec_free()`.
---
## WARNINGS
**Warning 1: Missing release notes**
A bug fix that changes interrupt registration behavior and fixes a mailbox timeout should be documented in the current release notes under `doc/guides/rel_notes/release_26_11.rst` (or whatever the current release is).
The patch description mentions mailbox failures and probe timeouts, which are user-visible impacts.
**Suggested action:** Add a "Fixed Issues" entry in the release notes describing the interrupt registration fix.
---
**Warning 2: Potential spinlock held across user callback**
Line 319-326 in `plt_irq_unregister()`:
```c
do {
rc = plt_intr_callback_unregister(irq_vec->handle, cb, data);
/* Retry only if -EAGAIN */
if (rc != -EAGAIN)
break;
plt_delay_ms(1);
retries--;
} while (retries);
```
If the lock were held here (it is not after the fix in Error 1), the retry loop with `plt_delay_ms()` would hold the spinlock for up to 5ms, blocking all other interrupt operations.
After applying the fix in Error 1, the lock is released before this loop, so this is acceptable.
**No action needed** after Error 1 is fixed.
---
## INFO
**Info 1: Variable initialization**
Line 289:
```c
uint8_t retries = 5; /* 5 ms */
```
The initialization to 5 is meaningful (retry count), so this is correct.
---
**Info 2: Consistent error messages**
Line 245:
```c
plt_err("Vector:0x%x irq already registered", vec);
```
Line 308:
```c
plt_err("Error unregistering MSI-X vec %d cb, not registered", vec);
```
The format specifiers differ (`0x%x` vs `%d`), and the message style is inconsistent.
For consistency, use `0x%x` for both or document the reason for the difference.
**Suggested action:** Use `vec:0x%x` consistently in both error messages for uniform formatting.
---
Review-Result: ERROR
More information about the test-report
mailing list