Linux Documentation
 help / color / mirror / Atom feed
From: Kory Maincent <kory.maincent@bootlin.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: Florian Fainelli <florian.fainelli@broadcom.com>,
	Broadcom internal kernel review list
	<bcm-kernel-feedback-list@broadcom.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Richard Cochran <richardcochran@gmail.com>,
	Radu Pirea <radu-nicolae.pirea@oss.nxp.com>,
	Jay Vosburgh <j.vosburgh@gmail.com>,
	Andy Gospodarek <andy@greyhouse.net>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Claudiu Beznea <claudiu.beznea@tuxon.dev>,
	Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Horatiu Vultur <horatiu.vultur@microchip.com>,
	UNGLinuxDriver@microchip.com, Simon Horman <horms@kernel.org>,
	Vladimir Oltean <vladimir.oltean@nxp.com>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-doc@vger.kernel.org,
	Maxime Chevallier <maxime.chevallier@bootlin.com>,
	Rahul Rameshbabu <rrameshbabu@nvidia.com>
Subject: Re: [PATCH net-next v15 13/14] net: ethtool: tsinfo: Add support for hwtstamp provider and get/set hwtstamp config
Date: Fri, 21 Jun 2024 10:54:08 +0200	[thread overview]
Message-ID: <20240621105408.6dda7a0e@kmaincent-XPS-13-7390> (raw)
In-Reply-To: <20240617184331.0ddfd08e@kernel.org>

On Mon, 17 Jun 2024 18:43:31 -0700
Jakub Kicinski <kuba@kernel.org> wrote:

Thanks for your review!

> On Wed, 12 Jun 2024 17:04:13 +0200 Kory Maincent wrote:
> > Enhance 'get' command to retrieve tsinfo of hwtstamp providers within a
> > network topology and read current hwtstamp configuration.
> > 
> > Introduce support for ETHTOOL_MSG_TSINFO_SET ethtool netlink socket to
> > configure hwtstamp of a PHC provider. Note that simultaneous hwtstamp
> > isn't supported; configuring a new one disables the previous setting.
> > 
> > Also, add support for a specific dump command to retrieve all hwtstamp
> > providers within the network topology, with added functionality for
> > filtered dump to target a single interface.  
> 
> Could you split this up, a little bit? It's rather large for a core
> change.

Ok I will do so.
 
> >  Desired behavior is passed into the kernel and to a specific device by
> > -calling ioctl(SIOCSHWTSTAMP) with a pointer to a struct ifreq whose
> > -ifr_data points to a struct hwtstamp_config. The tx_type and
> > -rx_filter are hints to the driver what it is expected to do. If
> > -the requested fine-grained filtering for incoming packets is not
> > +calling the tsinfo netlink socket ETHTOOL_MSG_TSINFO_SET.
> > +The ETHTOOL_A_TSINFO_TX_TYPES, ETHTOOL_A_TSINFO_RX_FILTERS and
> > +ETHTOOL_A_TSINFO_HWTSTAMP_FLAGS netlink attributes are then used to set the
> > +struct hwtstamp_config accordingly.  
> 
> nit: EHTOOL_A* defines in `` `` quotes?

Ack.

> 
> > +		if (hwtstamp && ptp_clock_phydev(hwtstamp->ptp) == phydev)
> > {
> > +			rcu_assign_pointer(dev->hwtstamp, NULL);
> > +			synchronize_rcu();
> >  			kfree(hwtstamp);  
> 
> Could you add an rcu_head to this struct and use kfree_rcu()
> similarly later use an rcu call to do the dismantle?
> synchronize_rcu() can be slow.

Ack. I might need to use call_rcu() as I have to call ptp_clock_put also before
the kfree.
 
> > +const struct nla_policy ethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_MAX + 1]
> > = { [ETHTOOL_A_TSINFO_HEADER]		=
> >  		NLA_POLICY_NESTED(ethnl_header_policy_stats),
> > +	[ETHTOOL_A_TSINFO_GHWTSTAMP] =
> > +		NLA_POLICY_MAX(NLA_U8, 1),  
> 
> I think this can be an NLA_FLAG, but TBH I'm also confused about 
> the semantics. Can you explain what it does from user perspective?

As I described it in the documentation it replaces SIOCGHWTSTAMP:
"Any process can read the actual configuration by requesting tsinfo netlink
socket ETHTOOL_MSG_TSINFO_GET with ETHTOOL_MSG_TSINFO_GHWTSTAMP netlink
attribute set.

The legacy usage is to pass this structure to ioctl(SIOCGHWTSTAMP) in the       
same way as the ioctl(SIOCSHWTSTAMP).  However, this has not been implemented   
in all drivers."

The aim is to get rid of ioctls.

Indeed NLA_FLAG is the right type I should use.
 
> > +	[ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER] =
> > +		NLA_POLICY_NESTED(ethnl_tsinfo_hwtstamp_provider_policy),
> >  };
> >  
> > +static int tsinfo_parse_hwtstamp_provider(const struct nlattr *nest,
> > +					  struct hwtst_provider *hwtst,
> > +					  struct netlink_ext_ack *extack,
> > +					  bool *mod)
> > +{
> > +	struct nlattr
> > *tb[ARRAY_SIZE(ethnl_tsinfo_hwtstamp_provider_policy)];  
> 
> Could you find a more sensible name for this policy?

I am not a naming expert but "hwtstamp_provider" is the struct name I have used
to describe hwtstamp index + qualifier and the prefix of the netlink nested
attribute, so IMHO it fits well.
Have you another proposition to clarify what you would expect?
 
> > +	int ret;
> > +
> > +	ret = nla_parse_nested(tb,
> > +
> > ARRAY_SIZE(ethnl_tsinfo_hwtstamp_provider_policy) - 1,
> > +			       nest,
> > +			       ethnl_tsinfo_hwtstamp_provider_policy,
> > extack);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	if (NL_REQ_ATTR_CHECK(extack, nest, tb,
> > ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER_INDEX) ||
> > +	    NL_REQ_ATTR_CHECK(extack, nest, tb,
> > ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER_QUALIFIER))  
> 
> nit: wrap at 80 chars, if you can, please

Yes indeed, thanks!

> >  	struct tsinfo_reply_data *data = TSINFO_REPDATA(reply_base);
> > +	struct tsinfo_req_info *req = TSINFO_REQINFO(req_base);
> >  	struct net_device *dev = reply_base->dev;
> >  	int ret;
> >  
> >  	ret = ethnl_ops_begin(dev);
> >  	if (ret < 0)
> >  		return ret;
> > +
> > +	if (req->get_hwtstamp) {
> > +		struct kernel_hwtstamp_config cfg = {};
> > +
> > +		if (!dev->netdev_ops->ndo_hwtstamp_get) {
> > +			ret = -EOPNOTSUPP;
> > +			goto out;
> > +		}
> > +
> > +		ret = dev_get_hwtstamp_phylib(dev, &cfg);
> > +		data->hwtst_config.tx_type = BIT(cfg.tx_type);
> > +		data->hwtst_config.rx_filter = BIT(cfg.rx_filter);
> > +		data->hwtst_config.flags = BIT(cfg.flags);
> > +		goto out;  
> 
> This is wrong AFAICT, everything up to this point was a nit pick ;)
> Please take a look at 89e281ebff72e6, I think you're reintroducing a
> form of the same bug. If ETHTOOL_FLAG_STATS was set, you gotta run stats
> init.
> 
> Perhaps you can move the stats getting up, and turn this code into if
> / else if / else, without the goto.

Indeed thanks for spotting the issue.

> > +
> > +	if (ret == -EMSGSIZE && skb->len)
> > +		return skb->len;
> > +	return ret;  
> 
> You can just return ret without the if converting to skb->len
> af_netlink will handle the EMSGSIZE errors in the same way.

Alright, thanks.

Regards,
-- 
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

  reply	other threads:[~2024-06-21  8:54 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-12 15:04 [PATCH net-next v15 00/14] net: Make timestamping selectable Kory Maincent
2024-06-12 15:04 ` [PATCH net-next v15 01/14] net_tstamp: Add TIMESTAMPING SOFTWARE and HARDWARE mask Kory Maincent
2024-06-12 15:04 ` [PATCH net-next v15 02/14] net: Move dev_set_hwtstamp_phylib to net/core/dev.h Kory Maincent
2024-06-18  1:26   ` Jakub Kicinski
2024-06-12 15:04 ` [PATCH net-next v15 03/14] net: Make dev_get_hwtstamp_phylib accessible Kory Maincent
2024-06-12 15:04 ` [PATCH net-next v15 04/14] net: Make net_hwtstamp_validate accessible Kory Maincent
2024-06-18  1:26   ` Jakub Kicinski
2024-06-12 15:04 ` [PATCH net-next v15 05/14] net: Change the API of PHY default timestamp to MAC Kory Maincent
2024-06-12 15:04 ` [PATCH net-next v15 06/14] net: net_tstamp: Add unspec field to hwtstamp_source enumeration Kory Maincent
2024-06-12 15:04 ` [PATCH net-next v15 07/14] net: Add struct kernel_ethtool_ts_info Kory Maincent
2024-06-14 14:02   ` Paolo Abeni
2024-06-14 17:46     ` Russell King (Oracle)
2024-06-12 15:04 ` [PATCH net-next v15 08/14] ptp: Add phc source and helpers to register specific PTP clock or get information Kory Maincent
2024-06-12 15:04 ` [PATCH net-next v15 09/14] net: Add the possibility to support a selected hwtstamp in netdevice Kory Maincent
2024-06-12 15:04 ` [PATCH net-next v15 10/14] net: netdevsim: ptp_mock: Convert to netdev_ptp_clock_register Kory Maincent
2024-06-12 15:04 ` [PATCH net-next v15 11/14] net: macb: " Kory Maincent
2024-06-12 15:04 ` [PATCH net-next v15 12/14] net: ptp: Move ptp_clock_index() to builtin symbol Kory Maincent
2024-06-12 15:04 ` [PATCH net-next v15 13/14] net: ethtool: tsinfo: Add support for hwtstamp provider and get/set hwtstamp config Kory Maincent
2024-06-18  1:43   ` Jakub Kicinski
2024-06-21  8:54     ` Kory Maincent [this message]
2024-06-21 15:56       ` Jakub Kicinski
2024-06-21 16:25         ` Kory Maincent
2024-06-12 15:04 ` [PATCH net-next v15 14/14] netlink: specs: tsinfo: Enhance netlink attributes and add a set command Kory Maincent
2024-06-18  1:50 ` [PATCH net-next v15 00/14] net: Make timestamping selectable patchwork-bot+netdevbpf

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=20240621105408.6dda7a0e@kmaincent-XPS-13-7390 \
    --to=kory.maincent@bootlin.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=andy@greyhouse.net \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=hkallweit1@gmail.com \
    --cc=horatiu.vultur@microchip.com \
    --cc=horms@kernel.org \
    --cc=j.vosburgh@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=maxime.chevallier@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=pabeni@redhat.com \
    --cc=radu-nicolae.pirea@oss.nxp.com \
    --cc=richardcochran@gmail.com \
    --cc=rrameshbabu@nvidia.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=vladimir.oltean@nxp.com \
    --cc=willemdebruijn.kernel@gmail.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