netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Stanislav Fomichev <sdf@fomichev.me>
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
	pabeni@redhat.com, Saeed Mahameed <saeed@kernel.org>
Subject: Re: [PATCH net-next 02/11] net: hold netdev instance lock during ndo_setup_tc
Date: Tue, 11 Feb 2025 18:20:16 -0800	[thread overview]
Message-ID: <20250211182016.305f1c77@kernel.org> (raw)
In-Reply-To: <20250210192043.439074-3-sdf@fomichev.me>

On Mon, 10 Feb 2025 11:20:34 -0800 Stanislav Fomichev wrote:
> Introduce new dev_setup_tc that handles the details and call it from
> all qdiscs/classifiers. The instance lock is still applied only to
> the drivers that implement shaper API so only iavf is affected.

> +int dev_setup_tc(struct net_device *dev, enum tc_setup_type type,
> +		 void *type_data)
> +{
> +	const struct net_device_ops *ops = dev->netdev_ops;
> +
> +	ASSERT_RTNL();
> +
> +	if (tc_can_offload(dev) && ops->ndo_setup_tc) {
> +		int ret = -ENODEV;
> +
> +		if (netif_device_present(dev)) {
> +			netdev_lock_ops(dev);
> +			ret = ops->ndo_setup_tc(dev, type, type_data);
> +			netdev_unlock_ops(dev);
> +		}
> +
> +		return ret;
> +	}
> +
> +	return -EOPNOTSUPP;

Why the indent? IMHO this would be cleaner:

	if (!tc_can_offload || !ops...
		return -ENOPNOTSUPP;
	if (!netif_device_present(dev))
		return -ENODEV:

	netdev_lock_ops(dev);
	...

> diff --git a/net/dsa/user.c b/net/dsa/user.c
> index 291ab1b4acc4..f2ac7662e4cc 100644
> --- a/net/dsa/user.c
> +++ b/net/dsa/user.c
> @@ -1729,10 +1729,7 @@ static int dsa_user_setup_ft_block(struct dsa_switch *ds, int port,
>  {
>  	struct net_device *conduit = dsa_port_to_conduit(dsa_to_port(ds, port));
>  
> -	if (!conduit->netdev_ops->ndo_setup_tc)
> -		return -EOPNOTSUPP;
> -
> -	return conduit->netdev_ops->ndo_setup_tc(conduit, TC_SETUP_FT, type_data);
> +	return dev_setup_tc(conduit, TC_SETUP_FT, type_data);

The netfilter / flow table offloads don't seem to test tc_can_offload(),
should we make that part of the check optional in dev_setup_tc() ?
Add a bool argument to ignore  tc_can_offload() ?

> @@ -855,10 +853,7 @@ void qdisc_offload_graft_helper(struct net_device *dev, struct Qdisc *sch,
>  	bool any_qdisc_is_offloaded;
>  	int err;
>  
> -	if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc)
> -		return;
> -
> -	err = dev->netdev_ops->ndo_setup_tc(dev, type, type_data);
> +	err = dev_setup_tc(dev, type, type_data);

Probably need to handle -EOPNOTSUPP here now?

>  	/* Don't report error if the graft is part of destroy operation. */
>  	if (!err || !new || new == &noop_qdisc)

> -	err = ops->ndo_setup_tc(dev, TC_SETUP_QDISC_CBS, &cbs);
> +	err = dev_setup_tc(dev, TC_SETUP_QDISC_CBS, &cbs);
>  	if (err < 0)
>  		pr_warn("Couldn't disable CBS offload for queue %d\n",
>  			cbs.queue);
> @@ -294,7 +289,7 @@ static int cbs_enable_offload(struct net_device *dev, struct cbs_sched_data *q,
>  	cbs.idleslope = opt->idleslope;
>  	cbs.sendslope = opt->sendslope;
>  
> -	err = ops->ndo_setup_tc(dev, TC_SETUP_QDISC_CBS, &cbs);
> +	err = dev_setup_tc(dev, TC_SETUP_QDISC_CBS, &cbs);

$ for f in $(git grep --files-with-matches TC_SETUP_QDISC_CBS -- drivers/ ); do \
	d=$(dirname $f); \
	git grep HW_TC -- $d || echo No match in $d; \
done

No match in drivers/net/dsa/microchip
No match in drivers/net/dsa/ocelot
No match in drivers/net/dsa/sja1105
drivers/net/ethernet/freescale/enetc/enetc_pf.c:        if (changed & NETIF_F_HW_TC) {
drivers/net/ethernet/freescale/enetc/enetc_pf.c:                err = enetc_set_psfp(ndev, !!(features & NETIF_F_HW_TC));
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c:         ndev->features |= NETIF_F_HW_TC;
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c:         ndev->hw_features |= NETIF_F_HW_TC;
drivers/net/ethernet/intel/igb/igb_main.c:              netdev->features |= NETIF_F_HW_TC;
drivers/net/ethernet/intel/igc/igc_main.c:      netdev->features |= NETIF_F_HW_TC;
drivers/net/ethernet/microchip/lan966x/lan966x_main.c:                   NETIF_F_HW_TC;
drivers/net/ethernet/microchip/lan966x/lan966x_main.c:  dev->hw_features |= NETIF_F_HW_TC;
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:              ndev->hw_features |= NETIF_F_HW_TC;
drivers/net/ethernet/ti/am65-cpsw-nuss.c:                                 NETIF_F_HW_TC;
drivers/net/ethernet/ti/cpsw_new.c:                               NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_TC;


Looks like some the these qdiscs will need to ignore the features too :(

  reply	other threads:[~2025-02-12  2:20 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-10 19:20 [PATCH net-next 00/11] net: Hold netdev instance lock during ndo operations Stanislav Fomichev
2025-02-10 19:20 ` [PATCH net-next 01/11] net: hold netdev instance lock during ndo_open/ndo_stop Stanislav Fomichev
2025-02-12  2:06   ` Jakub Kicinski
2025-02-10 19:20 ` [PATCH net-next 02/11] net: hold netdev instance lock during ndo_setup_tc Stanislav Fomichev
2025-02-12  2:20   ` Jakub Kicinski [this message]
2025-02-12  3:48     ` Stanislav Fomichev
2025-02-12  3:57       ` Jakub Kicinski
2025-02-10 19:20 ` [PATCH net-next 03/11] net: hold netdev instance lock during queue operations Stanislav Fomichev
2025-02-12  2:21   ` Jakub Kicinski
2025-02-10 19:20 ` [PATCH net-next 04/11] net: hold netdev instance lock during rtnetlink operations Stanislav Fomichev
2025-02-11 15:06   ` kernel test robot
2025-02-11 16:32     ` Stanislav Fomichev
2025-02-12  2:33   ` Jakub Kicinski
2025-02-10 19:20 ` [PATCH net-next 05/11] net: hold netdev instance lock during ioctl operations Stanislav Fomichev
2025-02-10 19:20 ` [PATCH net-next 06/11] net: hold netdev instance lock during sysfs operations Stanislav Fomichev
2025-02-10 19:20 ` [PATCH net-next 07/11] net: hold netdev instance lock during ndo_bpf Stanislav Fomichev
2025-02-10 19:20 ` [PATCH net-next 08/11] net: ethtool: try to protect all callback with netdev instance lock Stanislav Fomichev
2025-02-10 19:20 ` [PATCH net-next 09/11] net: dummy: add dummy shaper API Stanislav Fomichev
2025-02-11 10:41   ` kernel test robot
2025-02-11 15:29   ` kernel test robot
2025-02-10 19:20 ` [PATCH net-next 10/11] docs: net: document new locking reality Stanislav Fomichev
2025-02-10 19:20 ` [PATCH net-next 11/11] eth: bnxt: remove most dependencies on RTNL Stanislav Fomichev

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=20250211182016.305f1c77@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeed@kernel.org \
    --cc=sdf@fomichev.me \
    /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;
as well as URLs for NNTP newsgroup(s).