Netdev List
 help / color / mirror / Atom feed
From: Jianbo Liu <jianbol@nvidia.com>
To: netdev-bot+sashiko@kernel.org, tariqt@nvidia.com
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, netdev@vger.kernel.org, pabeni@redhat.com,
	willemb@google.com, parri.andrea@gmail.com, borisp@nvidia.com,
	cratiu@nvidia.com, eedmunds@nvidia.com, gal@nvidia.com,
	jmassar@nvidia.com, kuniyu@google.com, leon@kernel.org,
	linux-rdma@vger.kernel.org, mbloch@nvidia.com,
	phaddad@nvidia.com, raeds@nvidia.com, saeedm@nvidia.com,
	horms@kernel.org, sridhar.samudrala@intel.com,
	steffen.klassert@secunet.com
Subject: Re: [PATCH net 02/10] net/mlx5e: Stop counting packets dropped by IPsec RX SA rules
Date: Mon, 30 Nov 2026 14:57:44 +0800	[thread overview]
Message-ID: <494cee79-f1a2-4e3a-809e-8375f1cdd9da@nvidia.com> (raw)
In-Reply-To: <179581872594.3135.1501113897778355076@kernel.org>



On 11/28/2026 6:32 AM, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
> 
> Critical: 0 · High: 0 · Medium: 1 · Low: 0
> 
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
> 
> - [Medium] In rx_add_rule()
>    (drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c), the…
> 
> --
> 
> net/mlx5e: Stop counting packets dropped by IPsec RX SA rules
> 
> This patch removes the COUNT action and the counter destination from the
> RX SA rule used when attrs->drop is set. Packets dropped in hardware are
> then no longer added to x->curlft.packets for packet offload. The goal is
> to match crypto offload accounting, and the rule keeps CRYPTO_DECRYPT so
> ESN state keeps updating.
> 
>> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c
>> index 502d89a18f9ec..0facc54771558 100644
>> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c
>> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c
> 
> [ ... ]
> 
>> @@ -2103,17 +2102,24 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
>>  	flow_act.crypto.type = MLX5_FLOW_CONTEXT_ENCRYPT_DECRYPT_TYPE_IPSEC;
>>  	flow_act.crypto.obj_id = sa_entry->ipsec_obj_id;
>>  	flow_act.flags |= FLOW_ACT_NO_APPEND;
>> -	flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_CRYPTO_DECRYPT |
>> -			   MLX5_FLOW_CONTEXT_ACTION_COUNT;
>> -	if (attrs->drop)
>> +	/* Keep decrypting packets even when dropped, to allow ESN state
>> +	 * updates.
>> +	 */
>> +	flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_CRYPTO_DECRYPT;
>> +	if (attrs->drop) {
>>  		flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_DROP;
>> -	else
>> -		flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
>> -	dest[0].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
>> -	dest[0].ft = rx->ft.status;
>> -	dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
>> -	dest[1].counter = counter;
>> -	rule = mlx5_add_flow_rules(rx->ft.sa, spec, &flow_act, dest, 2);
>> +		rule = mlx5_add_flow_rules(rx->ft.sa, spec, &flow_act, NULL, 0);
> 
> [Severity: Medium]
> Could this cause x->curlft.packets to drift away from the hardware ASO
> packet-lifetime counter for packet offload RX SAs?
> 
> The drop rule still decrypts against sa_entry->ipsec_obj_id, so the ASO
> context for that object keeps being processed. For any finite packet limit,
> mlx5e_ipsec_packet_setup() in ipsec_offload.c arms the lifetime counter in
> the same ASO context without checking the direction:
> 
> 	if (attrs->lft.hard_packet_limit != XFRM_INF) {
> 		MLX5_SET(ipsec_aso, aso_ctx, remove_flow_pkt_cnt,
> 			 attrs->lft.hard_packet_limit);
> 		MLX5_SET(ipsec_aso, aso_ctx, hard_lft_arm, 1);
> 		MLX5_SET(ipsec_aso, aso_ctx, remove_flow_enable, 1);
> 	}
> 
> x->curlft.packets, however, is derived only from the SA rule flow counter
> in mlx5e_xfrm_update_stats():
> 
> 	mlx5_fc_query_cached(ipsec_rule->fc, &bytes, &packets, &lastuse);
> 	success_packets = packets - auth_packets - trailer_packets - replay_packets;
> 	x->curlft.packets += success_packets;
> 
> Before this patch, both counts included packets received in the drop
> state. After it, only the hardware counter would, assuming the device
> decrements remove_flow_pkt_cnt for packets that are decrypted and then
> dropped by the same FTE. The code does not show whether the device does
> this. Keeping DECRYPT so the ASO state keeps updating suggests that it
> might.
> 
> If so, when the hardware soft lifetime event fires,
> mlx5e_ipsec_handle_limits() checks curlft once and marks the soft limit
> as handled:
> 
> 		sa_entry->limits.soft_limit_hit = true;
> 		/* Notify about soft limit */
> 		xfrm_state_check_expire(sa_entry->x);
> 
> At that point curlft can be short by the number of packets received while
> attrs->drop was set. The soft expiry (rekey) would then be missed on this
> path.
> 
> In the final round, attrs->lft.soft_packet_limit is set to XFRM_INF, so
> mlx5e_ipsec_handle_event() no longer calls mlx5e_ipsec_handle_limits(). Since
> remove_flow_enable is set, can the hardware retire the SA while the xfrm
> state is still valid, and drop traffic until curlft catches up?
> 

The hardware can get to its hard limit that many packets early. On
ConnectX-7, the SA rule counter still counts the packets that the
hardware drops after that, so curlft gets to the soft and the hard
limit as well, that many packets later.
mlx5e_ipsec_handle_sw_limits() checks both against curlft every
second, as long as it is still running.

> The software poller mlx5e_ipsec_handle_sw_limits() returns early without
> requeueing whenever attrs.drop is set. So the catch-up might also not happen.

It seems an existing problem, which needs a fix of its own.

> 
> The commit message says:
> 
>      Remove the count action and counter destination from the drop rule
>      so these dropped packets stay out of the lifetime, matching crypto
>      offload accounting.
> 
> Crypto offload does not arm the ASO lifetime counter. Is it intended that
> the hardware lifetime for packet offload RX SAs still counts these drops
> while curlft no longer does?
> 

Yes. A drop without decrypt would stop the ESN updates of the SA while 
it is in the drop state.

>> +	} else {
>> +		struct mlx5_flow_destination dest[2];
>> +
>> +		flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
>> +				   MLX5_FLOW_CONTEXT_ACTION_COUNT;
>> +		dest[0].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
>> +		dest[0].ft = rx->ft.status;
>> +		dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
>> +		dest[1].counter = counter;
>> +		rule = mlx5_add_flow_rules(rx->ft.sa, spec, &flow_act, dest, 2);
>> +	}
> 
> [ ... ]
> 


  reply	other threads:[~2026-11-30  6:58 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 21:56 [PATCH net 00/10] net/mlx5e: Fix IPsec SA races and neighbour handling Tariq Toukan
2026-11-26 21:56 ` [PATCH net 01/10] net/mlx5e: Initialize IPsec XArrays with XA_FLAGS_LOCK_BH Tariq Toukan
2026-11-27 22:32   ` netdev-bot+sashiko
2026-11-26 21:56 ` [PATCH net 02/10] net/mlx5e: Stop counting packets dropped by IPsec RX SA rules Tariq Toukan
2026-11-27 22:32   ` netdev-bot+sashiko
2026-11-30  6:57     ` Jianbo Liu [this message]
2026-11-26 21:56 ` [PATCH net 03/10] net/mlx5e: Fix IPsec SA modify/stats update race Tariq Toukan
2026-11-27 22:32   ` netdev-bot+sashiko
2026-11-30  7:14     ` Jianbo Liu
2026-11-26 21:56 ` [PATCH net 04/10] net/mlx5e: Drain pending hardware event work before freeing IPsec SA Tariq Toukan
2026-11-27 22:32   ` netdev-bot+sashiko
2026-11-26 21:56 ` [PATCH net 05/10] net/mlx5e: Drop IPsec tunnel traffic if the neigh cannot be created Tariq Toukan
2026-11-27 22:32   ` netdev-bot+sashiko
2026-11-26 21:56 ` [PATCH net 06/10] net/mlx5e: Fix IPv6 neighbour fallback for IPsec tunnels Tariq Toukan
2026-11-26 21:56 ` [PATCH net 07/10] net/mlx5e: Copy back only replay_esn after an IPsec ESN update Tariq Toukan
2026-11-26 21:56 ` [PATCH net 08/10] net/mlx5e: Validate neighbour events before updating IPsec SAs Tariq Toukan
2026-11-27 22:32   ` netdev-bot+sashiko
2026-11-26 21:56 ` [PATCH net 09/10] net/mlx5e: Serialize IPsec netevent MAC snapshots Tariq Toukan
2026-11-26 21:56 ` [PATCH net 10/10] net/mlx5e: Create IPsec flow counters once per SA Tariq Toukan
2026-11-27 22:32   ` netdev-bot+sashiko

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=494cee79-f1a2-4e3a-809e-8375f1cdd9da@nvidia.com \
    --to=jianbol@nvidia.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=borisp@nvidia.com \
    --cc=cratiu@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=eedmunds@nvidia.com \
    --cc=gal@nvidia.com \
    --cc=horms@kernel.org \
    --cc=jmassar@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=parri.andrea@gmail.com \
    --cc=phaddad@nvidia.com \
    --cc=raeds@nvidia.com \
    --cc=saeedm@nvidia.com \
    --cc=sridhar.samudrala@intel.com \
    --cc=steffen.klassert@secunet.com \
    --cc=tariqt@nvidia.com \
    --cc=willemb@google.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