public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Michal Kubiak <michal.kubiak@intel.com>
To: Vlad Dogaru <vdogaru@nvidia.com>
Cc: Tariq Toukan <tariqt@nvidia.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	"Eric Dumazet" <edumazet@google.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"Gal Pressman" <gal@nvidia.com>,
	Leon Romanovsky <leonro@nvidia.com>,
	"Saeed Mahameed" <saeedm@nvidia.com>,
	Leon Romanovsky <leon@kernel.org>, <netdev@vger.kernel.org>,
	<linux-rdma@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Moshe Shemesh <moshe@nvidia.com>, Mark Bloch <mbloch@nvidia.com>,
	Yevgeny Kliteynik <kliteyn@nvidia.com>
Subject: Re: [PATCH net-next 11/12] net/mlx5: HWS, Free unused action STE tables
Date: Fri, 11 Apr 2025 13:22:46 +0200	[thread overview]
Message-ID: <Z/j7hl8JHZj0Q4Bu@localhost.localdomain> (raw)
In-Reply-To: <Z_gL6fvuYUmD4oPS@nvidia.com>

On Thu, Apr 10, 2025 at 08:20:25PM +0200, Vlad Dogaru wrote:
> On Thu, Apr 10, 2025 at 07:28:18PM +0200, Michal Kubiak wrote:
> > On Tue, Apr 08, 2025 at 05:00:55PM +0300, Tariq Toukan wrote:
> > > From: Vlad Dogaru <vdogaru@nvidia.com>
> > > 
> > > Periodically check for unused action STE tables and free their
> > > associated resources. In order to do this safely, add a per-queue lock
> > > to synchronize the garbage collect work with regular operations on
> > > steering rules.
> > > 
> > > Signed-off-by: Vlad Dogaru <vdogaru@nvidia.com>
> > > Reviewed-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
> > > Reviewed-by: Mark Bloch <mbloch@nvidia.com>
> > > Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
> > > ---
> > >  .../mlx5/core/steering/hws/action_ste_pool.c  | 88 ++++++++++++++++++-
> > >  .../mlx5/core/steering/hws/action_ste_pool.h  | 11 +++
> > >  .../mellanox/mlx5/core/steering/hws/context.h |  1 +
> > >  3 files changed, 96 insertions(+), 4 deletions(-)
> > 
> > [...]
> > 
> > > +
> > > +static void hws_action_ste_pool_cleanup(struct work_struct *work)
> > > +{
> > > +	enum mlx5hws_pool_optimize opt;
> > > +	struct mlx5hws_context *ctx;
> > > +	LIST_HEAD(cleanup);
> > > +	int i;
> > > +
> > > +	ctx = container_of(work, struct mlx5hws_context,
> > > +			   action_ste_cleanup.work);
> > > +
> > > +	for (i = 0; i < ctx->queues; i++) {
> > > +		struct mlx5hws_action_ste_pool *p = &ctx->action_ste_pool[i];
> > > +
> > > +		mutex_lock(&p->lock);
> > > +		for (opt = MLX5HWS_POOL_OPTIMIZE_NONE;
> > > +		     opt < MLX5HWS_POOL_OPTIMIZE_MAX; opt++)
> > > +			hws_action_ste_pool_element_collect_stale(
> > > +				&p->elems[opt], &cleanup);
> > > +		mutex_unlock(&p->lock);
> > > +	}
> > 
> > As I understand, in the loop above all unused items are being collected
> > to remove them at the end of the function, using `hws_action_ste_table_cleanup_list()`.
> > 
> > I noticed that only the collecting of elements is protected with the mutex.
> > So I have a question: is it possible that in a very short period of time
> > (between `mutex_unlock()` and `hws_action_ste_table_cleanup_list()` calls),
> > the cleanup list can somehow be invalidated (by changing the STE state
> > in another thread)?
> 
> An action_ste_table is either:
> (a) in an action_ste_pool (indirectly, via a pool element); or
> (b) in a cleanup list.
> 
> In situation (a), both the table's last_used timestamp and its offsets
> are protected by the parent pool's mutex. The table can only be accessed
> through its parent pool.
> 
> In situation (b), the table can only be accessed by its parent list, and
> the only thing we do with it is free it.
> 
> There is only one transition, from state (a) to state (b), never the
> other way around. This transition is done under the parent pool's mutex.
> 
> We only move tables to the cleanup list when all of their elements are
> available, so there is no risk of a `chunk_free` call accessing a table
> that's on a cleanup list: there are no chunks left to free.
> 
> I think this is airtight, but I'm happy to explore possible scenarios if
> you have any in mind.
> 
> Thank you for the detailed review,
> Vlad


Hi Vlad,

Thanks for your detailed explanation!
I was under the mistaken assumption that the `cleanup` list only had
some sort of reference to actual data. Now I see that the function
`hws_action_ste_pool_element_collect_stale` moves the real STE data
from one list to another, so only that function call should be protected
by the mutex.
Perhaps, I should have inspected the implementation of
`hws_action_ste_pool_element_collect_stale()` more closely. :-)

Thanks,
Reviewed-by: Michal Kubiak <michal.kubiak@intel.com>

PS. I saw your V2 - will take a look.






  reply	other threads:[~2025-04-11 11:23 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-08 14:00 [PATCH net-next 00/12] net/mlx5: HWS, Refactor action STE handling Tariq Toukan
2025-04-08 14:00 ` [PATCH net-next 01/12] net/mlx5: HWS, Fix matcher action template attach Tariq Toukan
2025-04-09 15:21   ` Michal Kubiak
2025-04-09 15:56     ` Vlad Dogaru
2025-04-09 16:00       ` Michal Kubiak
2025-04-08 14:00 ` [PATCH net-next 02/12] net/mlx5: HWS, Remove unused element array Tariq Toukan
2025-04-09 15:50   ` Michal Kubiak
2025-04-08 14:00 ` [PATCH net-next 03/12] net/mlx5: HWS, Make pool single resource Tariq Toukan
2025-04-09 20:04   ` Michal Kubiak
2025-04-08 14:00 ` [PATCH net-next 04/12] net/mlx5: HWS, Refactor pool implementation Tariq Toukan
2025-04-09 21:24   ` Michal Kubiak
2025-04-08 14:00 ` [PATCH net-next 05/12] net/mlx5: HWS, Cleanup after pool refactoring Tariq Toukan
2025-04-09 21:23   ` Michal Kubiak
2025-04-10  9:39     ` Vlad Dogaru
2025-04-08 14:00 ` [PATCH net-next 06/12] net/mlx5: HWS, Add fullness tracking to pool Tariq Toukan
2025-04-10 11:38   ` Michal Kubiak
2025-04-08 14:00 ` [PATCH net-next 07/12] net/mlx5: HWS, Fix pool size optimization Tariq Toukan
2025-04-10 12:21   ` Michal Kubiak
2025-04-10 15:45     ` Vlad Dogaru
2025-04-08 14:00 ` [PATCH net-next 08/12] net/mlx5: HWS, Implement action STE pool Tariq Toukan
2025-04-10 15:09   ` Michal Kubiak
2025-04-08 14:00 ` [PATCH net-next 09/12] net/mlx5: HWS, Use the new " Tariq Toukan
2025-04-10 16:48   ` Michal Kubiak
2025-04-08 14:00 ` [PATCH net-next 10/12] net/mlx5: HWS, Cleanup matcher action STE table Tariq Toukan
2025-04-10 17:01   ` Michal Kubiak
2025-04-10 18:45     ` Vlad Dogaru
2025-04-08 14:00 ` [PATCH net-next 11/12] net/mlx5: HWS, Free unused action STE tables Tariq Toukan
2025-04-10 17:28   ` Michal Kubiak
2025-04-10 18:20     ` Vlad Dogaru
2025-04-11 11:22       ` Michal Kubiak [this message]
2025-04-08 14:00 ` [PATCH net-next 12/12] net/mlx5: HWS, Export action STE tables to debugfs Tariq Toukan
2025-04-10 17:06   ` Michal Kubiak

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=Z/j7hl8JHZj0Q4Bu@localhost.localdomain \
    --to=michal.kubiak@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gal@nvidia.com \
    --cc=kliteyn@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=leonro@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=moshe@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.com \
    --cc=vdogaru@nvidia.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