mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yevgeny Kliteynik <kliteyn@nvidia.com>
To: Jakub Kicinski <kuba@kernel.org>, Mark Bloch <mbloch@nvidia.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Paolo Abeni <pabeni@redhat.com>,
	Eric Dumazet <edumazet@google.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	Simon Horman <horms@kernel.org>,
	saeedm@nvidia.com, gal@nvidia.com, leonro@nvidia.com,
	tariqt@nvidia.com, Leon Romanovsky <leon@kernel.org>,
	netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-kernel@vger.kernel.org, moshe@nvidia.com,
	Vlad Dogaru <vdogaru@nvidia.com>
Subject: Re: [PATCH net-next v2 7/8] net/mlx5: HWS, Shrink empty matchers
Date: Wed, 25 Jun 2025 17:42:58 +0300	[thread overview]
Message-ID: <594a3f22-57c6-4f97-9464-40ed0e3fcec9@nvidia.com> (raw)
In-Reply-To: <20250624170809.2aac2c69@kernel.org>


On 25-Jun-25 03:08, Jakub Kicinski wrote:
> On Sun, 22 Jun 2025 20:22:25 +0300 Mark Bloch wrote:
>> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc.c
>> index 0a7903cf75e8..b7098c7d2112 100644
>> --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc.c
>> +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc.c
>> @@ -3,6 +3,8 @@
>>   
>>   #include "internal.h"
>>   
>> +static int hws_bwc_matcher_move(struct mlx5hws_bwc_matcher *bwc_matcher);
> 
> Is there a circular dependency? Normally we recommend that people
> reorder code rather that add forward declarations.

Sure, I can rearrange the code. It would, however, mean moving a lot
of code... I think I'll do it in a separate refactoring patch before
this functional one.

>> +static int hws_bwc_rule_cnt_dec_with_shrink(struct mlx5hws_bwc_rule *bwc_rule,
>> +					    u16 bwc_queue_idx)
>> +{
>> +	struct mlx5hws_bwc_matcher *bwc_matcher = bwc_rule->bwc_matcher;
>> +	struct mlx5hws_context *ctx = bwc_matcher->matcher->tbl->ctx;
>> +	struct mutex *queue_lock; /* Protect the queue */
>> +	int ret;
>> +
>> +	hws_bwc_rule_cnt_dec(bwc_rule);
>> +
>> +	if (atomic_read(&bwc_matcher->rx_size.num_of_rules) ||
>> +	    atomic_read(&bwc_matcher->tx_size.num_of_rules))
>> +		return 0;
>> +
>> +	/* Matcher has no more rules - shrink it to save ICM. */
>> +
>> +	queue_lock = hws_bwc_get_queue_lock(ctx, bwc_queue_idx);
>> +	mutex_unlock(queue_lock);
>> +
>> +	hws_bwc_lock_all_queues(ctx);
>> +	ret = hws_bwc_matcher_rehash_shrink(bwc_matcher);
>> +	hws_bwc_unlock_all_queues(ctx);
>> +
>> +	mutex_lock(queue_lock);
> 
> Dropping and re-taking caller-held locks is a bad code smell.
> Please refactor - presumably you want some portion of the condition
> to be under the lock with the dec? return true / false based on that.
> let the caller drop the lock and do the shrink if true was returned
> (directly or with another helper)

There are multiple queues that can function in parallel. Each rule
selects a random queue and immediately locks it. All the further
processing of this rule is done when this lock is held.
Sometimes there is need to do operation that requires full ownership
of the matcher. That is, this rule has to be the only rule that is
being processed. In such case, all the locks should be acquired,
which means that we're facing the 'dining philosophers' scenario.
All the locks should be acquired in the same order: the lock is
freed, and then all the locks are acquired in an orderly manner.
To have all this logic in the same function that acquires the first
lock would mean really complicating the code and breaking the simple
logical flow of the functions.

Thanks for the review!

  reply	other threads:[~2025-06-25 14:43 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-22 17:22 [PATCH net-next v2 0/8] net/mlx5: HWS, Optimize matchers ICM usage Mark Bloch
2025-06-22 17:22 ` [PATCH net-next v2 1/8] net/mlx5: HWS, remove unused create_dest_array parameter Mark Bloch
2025-06-24 18:37   ` Simon Horman
2025-06-22 17:22 ` [PATCH net-next v2 2/8] net/mlx5: HWS, remove incorrect comment Mark Bloch
2025-06-24 18:37   ` Simon Horman
2025-06-22 17:22 ` [PATCH net-next v2 3/8] net/mlx5: HWS, Refactor and export rule skip logic Mark Bloch
2025-06-24 18:38   ` Simon Horman
2025-06-25  0:35     ` Yevgeny Kliteynik
2025-06-25  0:45       ` Jakub Kicinski
2025-06-25 14:42         ` Yevgeny Kliteynik
2025-06-25  9:45       ` Simon Horman
2025-06-25 13:41         ` Yevgeny Kliteynik
2025-06-22 17:22 ` [PATCH net-next v2 4/8] net/mlx5: HWS, Create STEs directly from matcher Mark Bloch
2025-06-24 18:57   ` Simon Horman
2025-06-22 17:22 ` [PATCH net-next v2 5/8] net/mlx5: HWS, Decouple matcher RX and TX sizes Mark Bloch
2025-06-24 18:57   ` Simon Horman
2025-06-22 17:22 ` [PATCH net-next v2 6/8] net/mlx5: HWS, Track matcher sizes individually Mark Bloch
2025-06-22 17:22 ` [PATCH net-next v2 7/8] net/mlx5: HWS, Shrink empty matchers Mark Bloch
2025-06-25  0:08   ` Jakub Kicinski
2025-06-25 14:42     ` Yevgeny Kliteynik [this message]
2025-06-22 17:22 ` [PATCH net-next v2 8/8] net/mlx5: Add HWS as secondary steering mode Mark Bloch
2025-06-22 22:39 ` [PATCH net-next v2 0/8] net/mlx5: HWS, Optimize matchers ICM usage Zhu Yanjun
2025-06-23 12:03   ` Mark Bloch

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=594a3f22-57c6-4f97-9464-40ed0e3fcec9@nvidia.com \
    --to=kliteyn@nvidia.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gal@nvidia.com \
    --cc=horms@kernel.org \
    --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

all inboxes | Powered by JetHome®