Re: [PATCH] RDMA/mthca: Free the AV table index if kmalloc fails in create_ah
From: Leon Romanovsky
Date: Thu Nov 26 2026 - 04:08:44 EST
On Mon, Nov 23, 2026 at 12:43:23AM +0000, Suyuan Wang via B4 Relay wrote:
> From: Suyuan Wang <stevewong@xxxxxxxxxxx>
>
> When an address handle can be stored in HCA memory, mthca_create_ah()
> first takes an index from the AV table and then allocates a temporary
> AV buffer:
>
> index = mthca_alloc(&dev->av_table.alloc);
> ...
> av = kmalloc_obj(*av, GFP_ATOMIC);
> if (!av)
> goto on_hca_fail;
>
> If the allocation fails, the code falls back to the PCI pool and
> ah->type stays MTHCA_AH_PCI_POOL. mthca_destroy_ah() then frees the
> pool entry but never the AV table index, so the index is lost for
> good. The allocation is GFP_ATOMIC, so it can fail under memory
> pressure, and repeated failures can exhaust the free on-HCA AV indices
> until no new on-HCA address handle can be created.
>
> Return the index to the allocator before falling back.
>
> Found with a static analysis tool and checked by hand.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@xxxxxxxxxxxxxxx
> Co-developed-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
> Signed-off-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
> Signed-off-by: Suyuan Wang <stevewong@xxxxxxxxxxx>
> ---
> Compile tested on x86_64 (W=1). I don't have the hardware.
This code is old and unmaintained, so let's drop this patch. We can
revisit it if someone with the hardware steps forward to test it.
Thanks
> ---
> drivers/infiniband/hw/mthca/mthca_av.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)