Subject: Re: [PATCH net-next v2] ethtool: linkstate: add a statistic for PHY down events

From: Jakub Kicinski <[email-masked]>
Date: Fri, 28 Oct 2022 09:20:47 -0700

On Fri, 28 Oct 2022 14:18:11 +0200 Andrew Lunn wrote:
> > @@ -67,6 +67,7 @@ static void phy_link_down(struct phy_device *phydev)
> >  {
> >  	phydev->phy_link_change(phydev, false);
> >  	phy_led_trigger_change_speed(phydev);
> > +	WRITE_ONCE(phydev->link_down_events, phydev->link_down_events + 1);  
> 
> I'm not sure the WRITE_ONCE adds much value. Many systems using PHYLIB
> are 32 bit, and i don't think WRITE_ONCE will make that 64 bit write
> atomic on 32 bit systems. And as Florian pointed out, you have bigger
> problems if you manged to overflow a u32 into a u64.
> 
> > @@ -723,6 +724,8 @@ struct phy_device {
> >  
> >  	int pma_extable;
> >  
> > +	unsigned int link_down_events;  
> 
> And here is unsigned int, not u64? Or u32? It would be good to be
> consistent.

I made it 32b on the phylib side so that WRITE_ONCE() was sufficient 
to ensure atomic writes.

Do you have a preference for it being 64b vs 32b at the uAPI level?
I was leaning slightly towards making both 32b in v3..

> > --- a/include/uapi/linux/ethtool_netlink.h
> > +++ b/include/uapi/linux/ethtool_netlink.h
> > @@ -262,6 +262,8 @@ enum {
> >  	ETHTOOL_A_LINKSTATE_SQI_MAX,		/* u32 */
> >  	ETHTOOL_A_LINKSTATE_EXT_STATE,		/* u8 */
> >  	ETHTOOL_A_LINKSTATE_EXT_SUBSTATE,	/* u8 */
> > +	ETHTOOL_A_LINKSTATE_PAD,
> > +	ETHTOOL_A_LINKSTATE_EXT_DOWN_CNT,	/* u64 */  
> 
> What is the PAD for?

64b values have to be padded in netlink to ensure alignment.