Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] drm/amdgpu: skipped NPA VM unmap in amdgpu_ualink_unmap_all_npa_addr() --
commit b97443989d15a388f71900159633c07744fbba8b Author: bob <[email protected]> drm/amdgpu: use the per-remote UALink generation count in Source-Alias mode This commit uses the remote importer's own generation_count rather than importer_entries[0].generation_count when checking connection state and handling connection resets during UALink export cleanup in Source-Alias mode. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c > index d025b4183b296..1546c5d5c6758 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c [ ... ] > @@ -2695,7 +2699,7 @@ static void amdgpu_ualink_send_tlb_shootdown(struct > amdgpu_device *adev, > u32 accel_id = adev->ualink.info->ppod.accel_id; > struct amdgpu_ualink_importer_entry *imp_entry; > u64 npa_addr, size; > - u32 remote_acc_id; > + u32 remote_acc_id, gen_count; > int r; > > size = amdgpu_bo_ngpu_pages(exp_xa_node->bo); > @@ -2712,9 +2716,13 @@ static void amdgpu_ualink_send_tlb_shootdown(struct > amdgpu_device *adev, > > npa_addr = STRIP_NPA(imp_entry->npa_addr); > npa_addr = GENERATE_NPA(npa_addr, accel_id); > + /* The generation count is per remote, also in Source-Alias > + * mode where imp_entry is the shared importer_entries[0]. > + */ > + gen_count = > exp_xa_node->importer_entries[remote_acc_id].generation_count; > > if (!amdgpu_ualink_check_conn_ready(adev, remote_acc_id, > - imp_entry->generation_count)) { > + gen_count)) { > clear_bit(remote_acc_id, > exp_xa_node->importers_bitmap); > continue; > @@ -2737,7 +2745,7 @@ static void amdgpu_ualink_send_tlb_shootdown(struct > amdgpu_device *adev, > */ > amdgpu_ualink_handle_connection_reset(adev, > remote_acc_id, > AMDGPU_UALINK_CONN_NOT_READY, > - imp_entry->generation_count); > + gen_count); > } > } > } > @@ -2755,7 +2763,7 @@ static void amdgpu_ualink_unmap_all_npa_addr(struct > amdgpu_device *adev, > struct dma_fence *fence = NULL; > struct drm_exec exec; > u64 npa_addr, size; > - u32 remote_acc_id; > + u32 remote_acc_id, gen_count; > int r; > > size = amdgpu_bo_ngpu_pages(exp_xa_node->bo); > @@ -2774,9 +2782,13 @@ static void amdgpu_ualink_unmap_all_npa_addr(struct > amdgpu_device *adev, > else > imp_entry = > &exp_xa_node->importer_entries[remote_acc_id]; > npa_addr = imp_entry->npa_addr; > + /* The generation count is per remote, also in Source-Alias > + * mode where imp_entry is the shared importer_entries[0]. > + */ > + gen_count = > exp_xa_node->importer_entries[remote_acc_id].generation_count; > > if (!amdgpu_ualink_check_conn_ready(adev, remote_acc_id, > - imp_entry->generation_count)) { > + gen_count)) { > clear_bit(remote_acc_id, > exp_xa_node->importers_bitmap); > continue; [Severity: High] Can this leave stale valid PTEs in adev->ualink.npa_vm pointing to freed VRAM pages when an importer fails TLB shootdown or reconnects? Before queuing amdgpu_ualink_exp_cleanup_worker(), amdgpu_ualink_revoke_exported_memory() unlinks every imp_entry->list from adev->ualink.exp_handles_list, so a later connection reset cannot find or unmap exp_xa_node via amdgpu_ualink_cleanup_exp_xa_entries(). In Source-Alias mode when accelerator 0 had not imported the handle, imp_entry->generation_count was previously 0, so amdgpu_ualink_handle_connection_reset() did not match the established connection's non-zero generation and amdgpu_ualink_check_conn_ready() treated 0 as a wildcard and still unmapped the shared NPA range. With gen_count set to the remote's generation, a failed amdgpu_ualink_remote_shootdown() marks conn_state[remote_acc_id] as AMDGPU_UALINK_CONN_NOT_READY (or a prior reconnect mismatches gen_count and clears remote_acc_id from exp_xa_node->importers_bitmap). When amdgpu_ualink_unmap_all_npa_addr() then runs, no importer passes amdgpu_ualink_check_conn_ready(), so amdgpu_vm_update_range() is skipped. amdgpu_ualink_exp_cleanup_worker() still unpins and unreferences exp_xa_node->bo and calls amdgpu_ualink_free_all_npa_va() with orig_importers_bitmap, freeing the BO and the NPA VA range while the PTEs (with PTE.X = 1 set by amdgpu_ualink_force_retry_rpcs()) remain mapped in adev->ualink.npa_vm. Unmapping the local NPA VM mappings unconditionally for all allocated NPA ranges, regardless of remote connection state, would avoid leaving stale PTEs behind. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/20261203-fix-u5-amdgpu-ualink-alias-gencount-v1-1-a2e17004b...@tuta.io?part=1
