From: Leon Romanovsky <leon@kernel.org>
To: Yonatan Nachum <ynachum@amazon.com>
Cc: jgg@nvidia.com, linux-rdma@vger.kernel.org, mrgolin@amazon.com,
sleybo@amazon.com, matua@amazon.com, gal.pressman@linux.dev,
Firas Jahjah <firasj@amazon.com>
Subject: Re: [PATCH for-next v2 2/2] RDMA/efa: Add AH cache handling on create and destroy AH
Date: Tue, 19 May 2026 16:38:57 +0300 [thread overview]
Message-ID: <20260519133857.GW33515@unreal> (raw)
In-Reply-To: <20260512061121.2177521-3-ynachum@amazon.com>
On Tue, May 12, 2026 at 06:11:21AM +0000, Yonatan Nachum wrote:
> On create AH, first check if the AH cache entry already exists and if
> so, returns the already stored AH number. If the entry doesn't exist,
> the driver creates it and calls the device to create the AH. A per-entry
> mutex serializes concurrent device commands on the same AH cache entry,
> ensuring only one thread issues the device create while others wait and
> reuse the result. If the device create fails, the entry remains
> uninitialized so subsequent threads calls can create the AH.
>
> On destroy AH, the refcount is checked and if it's the last reference,
> the driver issues the device destroy command while holding the entry
> mutex. The entry remains in the hashtable during destroy to allow
> concurrent create threads to find it and wait on the entry mutex,
> preventing create-before-destroy races on the device. After the device
> destroy completes, the entry is either recycled if new users arrived or
> removed and freed.
>
> Reviewed-by: Firas Jahjah <firasj@amazon.com>
> Reviewed-by: Michael Margolin <mrgolin@amazon.com>
> Signed-off-by: Yonatan Nachum <ynachum@amazon.com>
> ---
> drivers/infiniband/hw/efa/efa_ah_cache.c | 124 +++++++++++++++++++++++
> drivers/infiniband/hw/efa/efa_ah_cache.h | 5 +
> drivers/infiniband/hw/efa/efa_com_cmd.c | 27 +++++
> drivers/infiniband/hw/efa/efa_com_cmd.h | 1 +
> drivers/infiniband/hw/efa/efa_verbs.c | 9 +-
> 5 files changed, 162 insertions(+), 4 deletions(-)
<...>
> +
> +/**
> + * efa_ah_cache_put - Release the final reference to an AH cache entry
> + * @ah_cache: AH cache
> + * @entry: AH cache entry
> + *
> + * Decrement the refcount. If it reaches zero, the entry is removed from the
> + * hashtable and freed. Otherwise, the entry is kept for reuse.
> + *
> + * Called after the device destroy completes or on a failed create to release
> + * the caller's reference.
> + */
> +void efa_ah_cache_put(struct efa_ah_cache *ah_cache, struct efa_ah_cache_entry *entry)
> +{
> + mutex_lock(&ah_cache->lock);
> + if (!refcount_dec_and_test(&entry->refcount)) {
> + mutex_unlock(&ah_cache->lock);
> + return;
> + }
> +
> + rhashtable_remove_fast(&ah_cache->hashtable, &entry->linkage, ah_cache_params);
> + mutex_unlock(&ah_cache->lock);
> +
> + mutex_destroy(&entry->lock);
> + kvfree(entry);
> +}
This pattern looks very similar to kref_put_mutex().
Thanks
next prev parent reply other threads:[~2026-05-19 13:39 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 6:11 [PATCH for-next v2 0/2] RDMA/efa: Add AH cache for AH reuse Yonatan Nachum
2026-05-12 6:11 ` [PATCH for-next v2 1/2] RDMA/efa: Add initialization of AH cache rhashtable Yonatan Nachum
2026-05-14 5:12 ` Zhu Yanjun
2026-05-14 10:02 ` Yonatan Nachum
2026-05-15 5:09 ` Zhu Yanjun
2026-05-17 7:06 ` Yonatan Nachum
2026-05-19 13:07 ` Leon Romanovsky
2026-05-20 6:53 ` Yonatan Nachum
2026-05-12 6:11 ` [PATCH for-next v2 2/2] RDMA/efa: Add AH cache handling on create and destroy AH Yonatan Nachum
2026-05-19 13:38 ` Leon Romanovsky [this message]
2026-05-20 7:03 ` Yonatan Nachum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260519133857.GW33515@unreal \
--to=leon@kernel.org \
--cc=firasj@amazon.com \
--cc=gal.pressman@linux.dev \
--cc=jgg@nvidia.com \
--cc=linux-rdma@vger.kernel.org \
--cc=matua@amazon.com \
--cc=mrgolin@amazon.com \
--cc=sleybo@amazon.com \
--cc=ynachum@amazon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox