From: Ce Sun cesun102@amd.com
[ Upstream commit 907813e5d7cadfeafab12467d748705a5309efb0 ]
Correct the counts of nr_banks and nr_errors
Signed-off-by: Ce Sun cesun102@amd.com Reviewed-by: Yang Wang kevinyang.wang@amd.com Reviewed-by: Hawking Zhang Hawking.Zhang@amd.com Signed-off-by: Alex Deucher alexander.deucher@amd.com Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
YES
- Fix scope: Corrects internal counters in AMDGPU ACA error accounting; minimal, localized change confined to `drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c`. - Bug 1 (nr_banks undercount after free): `aca_banks_release()` now decrements `nr_banks` as it removes/frees each node, keeping the count consistent with the list length; see `drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c:79`. Without this, after freeing the list the `nr_banks` field could remain stale (non-zero), misleading any subsequent logic that inspects the struct after release (even if current users mostly recreate the struct). - Bug 2 (nr_errors negative/miscount): `new_bank_error()` now increments `aerr->nr_errors` when a new error is appended to the list, matching the existing decrement in `aca_bank_error_remove()`; see `drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c:242` (increment) and `drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c:276` (decrement). Previously, errors would be removed and counted down without ever counting up, driving `nr_errors` negative and breaking basic accounting. - Concurrency correctness: Both the increment and decrement of `nr_errors` are performed while holding `aerr->lock` (add/remove paths already take the mutex), so the fix is thread-safe and consistent with existing synchronization. - Call flow correctness: The ACA error cache is drained in `aca_log_aca_error()` which removes each entry (and thus decrements the counter) under the same lock; see `drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c:540-556`. With the fix, `nr_errors` returns to zero after logging, as intended. - User-visible impact: Prevents incorrect/negative error counts in ACA error accounting and avoids stale bank counts after release. This improves reliability of error reporting/diagnostics (including CPER- related reporting that relies on bank collections; e.g., the deferred UE path passes `de_banks.nr_banks` to CPER generation at `drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c:445`). - Risk assessment: Very low. No API/ABI changes, no architectural changes, only adjusts counters to mirror existing list mutations. Logic paths remain the same; locking is preserved. - Stable criteria fit: This is a small, targeted bug fix correcting internal state; no features added; low regression risk; affects correctness of error accounting in a driver subsystem.
Given the above, this commit is a good candidate for backporting to stable trees.
drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c index d1e431818212d..9b31804491500 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c @@ -76,6 +76,7 @@ static void aca_banks_release(struct aca_banks *banks) list_for_each_entry_safe(node, tmp, &banks->list, node) { list_del(&node->node); kvfree(node); + banks->nr_banks--; } }
@@ -238,6 +239,7 @@ static struct aca_bank_error *new_bank_error(struct aca_error *aerr, struct aca_
mutex_lock(&aerr->lock); list_add_tail(&bank_error->node, &aerr->list); + aerr->nr_errors++; mutex_unlock(&aerr->lock);
return bank_error;