mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Petr Machata <petrm@nvidia.com>
To: Wentao Liang <vulab@iscas.ac.cn>
Cc: <andrew+netdev@lunn.ch>, <davem@davemloft.net>,
	<edumazet@google.com>, <idosch@nvidia.com>, <kuba@kernel.org>,
	<linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>,
	<pabeni@redhat.com>, <petrm@nvidia.com>, <stable@vger.kernel.org>
Subject: Re: [PATCH] mlxsw: spectrum_flower: Fix port range register leak
Date: Fri, 18 Sep 2026 18:39:32 +0200	[thread overview]
Message-ID: <87pkyawm2j.fsf@pmachata.org> (raw)
In-Reply-To: <20260917113236.2149095-1-vulab@iscas.ac.cn> (Wentao Liang's message of "Thu, 17 Sep 2026 11:32:36 +0000")

Wentao Liang <vulab@iscas.ac.cn> writes:

> mlxsw_sp_flower_parse_ports_range() acquires the source port range
> register before the destination one.  If the destination lookup then
> fails, the source register reference is left behind in a partially
> filled rule info, and callers that pass a stack allocated rule info
> never release it.  Release the source register before returning the
> error so that the reference is not leaked.

I think this is fixing the wrong issue in fact.

This does fix something, namely the issue of trying to add a new tc
chain filter with both src_port and dst_port ranges in a situation where
only one resource is left. Before the fix, we end up with full resource
allocation even as the offload fails, because the register for the
src_port range is not released. After the fix, the src_port register is
correctly released.

But look:

# tc qdisc add dev swp1 ingress
# tc chain add dev swp1 ingress chain 90 protocol ip flower ip_proto udp src_port 100-9000 dst_port 200-9000
# devlink -j resource show pci/0000:06:00.0  | jq '.resources.[][] | select(.name == "port_range_registers") | .occ'
2
# tc chain del dev swp1 ingress chain 90
# devlink -j resource show pci/0000:06:00.0  | jq '.resources.[][] | select(.name == "port_range_registers") | .occ'
2

So it's much more broken than just this cleanup path edge case.
(Notably, 'tc filter' cleans up properly, it is really just 'tc
template' that triggers it.)

I.e. let's not have this.


I think this is the fix that we need, and it fixes the cleanup path
issue as well.

modified   drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
@@ -862,14 +862,24 @@ int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,
 	memset(&rulei, 0, sizeof(rulei));
 	err = mlxsw_sp_flower_parse(mlxsw_sp, block, &rulei, f);
 	if (err)
-		return err;
+		goto out;
+
 	ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block,
 					   f->common.chain_index,
 					   MLXSW_SP_ACL_PROFILE_FLOWER,
 					   &rulei.values.elusage);
 
 	/* keep the reference to the ruleset */
-	return PTR_ERR_OR_ZERO(ruleset);
+	err = PTR_ERR_OR_ZERO(ruleset);
+
+out:
+	if (rulei.src_port_range_reg_valid)
+		mlxsw_sp_port_range_reg_put(mlxsw_sp,
+					    rulei.src_port_range_reg_index);
+	if (rulei.dst_port_range_reg_valid)
+		mlxsw_sp_port_range_reg_put(mlxsw_sp,
+					    rulei.dst_port_range_reg_index);
+	return err;
 }
 
 void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,

The template parser just needs to figure out which keys are used (the
rulei.values.elusage), it doesn't need to allocate any registers, but it
neglects to make the appropriate cleanups.

I'll test the above fix some more and send it sometime next week.

> Fixes: fe22f7410527 ("mlxsw: spectrum_flower: Add ability to match on port ranges")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>  drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
> index 353fd9ca89a6..4cad6c46b07e 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
> @@ -486,8 +486,14 @@ mlxsw_sp_flower_parse_ports_range(struct mlxsw_sp *mlxsw_sp,
>  
>  		err = mlxsw_sp_port_range_reg_get(mlxsw_sp, &range,
>  						  f->common.extack, &prr_index);
> -		if (err)
> +		if (err) {
> +			if (rulei->src_port_range_reg_valid) {
> +				mlxsw_sp_port_range_reg_put(mlxsw_sp,
> +							    rulei->src_port_range_reg_index);
> +				rulei->src_port_range_reg_valid = false;
> +			}
>  			return err;
> +		}
>  
>  		rulei->dst_port_range_reg_index = prr_index;
>  		rulei->dst_port_range_reg_valid = true;

      reply	other threads:[~2026-09-18 16:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 11:32 Wentao Liang
2026-09-18 16:39 ` Petr Machata [this message]

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=87pkyawm2j.fsf@pmachata.org \
    --to=petrm@nvidia.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=vulab@iscas.ac.cn \
    /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®