public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Hangbin Liu <liuhangbin@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>, netdev@vger.kernel.org
Cc: Jay Vosburgh <j.vosburgh@gmail.com>,
	Veaceslav Falico <vfalico@gmail.com>,
	Andy Gospodarek <andy@greyhouse.net>,
	"David S . Miller" <davem@davemloft.net>,
	Richard Cochran <richardcochran@gmail.com>,
	Heiner Kallweit <hkallweit1@gmail.com>
Subject: Re: [PATCHv3 net-next 1/2] net_tstamp: add new flag HWTSTAMP_FLAG_BONDED_PHC_INDEX
Date: Tue, 28 Dec 2021 15:01:13 +0800	[thread overview]
Message-ID: <Ycq2Ofad9UHur0qE@Laptop-X1> (raw)
In-Reply-To: <20211210085959.2023644-2-liuhangbin@gmail.com>

Hi Jakub,

When implement the user space support for this feature. I realized that
we can't use the new flag directly as the user space tool needs to have
backward compatibility. Because run the new tool with this flag enabled
on old kernel will get -EINVAL error. And we also could not use #ifdef
directly as HWTSTAMP_FLAG_BONDED_PHC_INDEX is a enum.

Do you think if we could add a #define in linux/net_tstamp.h like

#define HWTSTAMP_FLAGS_SUPPORT 1

So that the user space tool could use it like

#ifdef HWTSTAMP_FLAGS_SUPPORT
       cfg->flags = HWTSTAMP_FLAG_BONDED_PHC_INDEX;
#endif

Thanks
Hangbin

On Fri, Dec 10, 2021 at 04:59:58PM +0800, Hangbin Liu wrote:
> Since commit 94dd016ae538 ("bond: pass get_ts_info and SIOC[SG]HWTSTAMP
> ioctl to active device") the user could get bond active interface's
> PHC index directly. But when there is a failover, the bond active
> interface will change, thus the PHC index is also changed. This may
> break the user's program if they did not update the PHC timely.
> 
> This patch adds a new hwtstamp_config flag HWTSTAMP_FLAG_BONDED_PHC_INDEX.
> When the user wants to get the bond active interface's PHC, they need to
> add this flag and be aware the PHC index may be changed.
> 
> With the new flag. All flag checks in current drivers are removed. Only
> the checking in net_hwtstamp_validate() is kept.
> 
> Suggested-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> 
> ---
> v3: Use bitwise test to check the flags validation
> v2: Keep the flag validation check in net_hwtstamp_validate()
>     Rename the flag to HWTSTAMP_FLAG_BONDED_PHC_INDEX

[...]

> diff --git a/include/uapi/linux/net_tstamp.h b/include/uapi/linux/net_tstamp.h
> index fcc61c73a666..e258e52cfd1f 100644
> --- a/include/uapi/linux/net_tstamp.h
> +++ b/include/uapi/linux/net_tstamp.h
> @@ -62,7 +62,7 @@ struct so_timestamping {
>  /**
>   * struct hwtstamp_config - %SIOCGHWTSTAMP and %SIOCSHWTSTAMP parameter
>   *
> - * @flags:	no flags defined right now, must be zero for %SIOCSHWTSTAMP
> + * @flags:	one of HWTSTAMP_FLAG_*
>   * @tx_type:	one of HWTSTAMP_TX_*
>   * @rx_filter:	one of HWTSTAMP_FILTER_*
>   *
> @@ -78,6 +78,20 @@ struct hwtstamp_config {
>  	int rx_filter;
>  };
>  
> +/* possible values for hwtstamp_config->flags */
> +enum hwtstamp_flags {
> +	/*
> +	 * With this flag, the user could get bond active interface's
> +	 * PHC index. Note this PHC index is not stable as when there
> +	 * is a failover, the bond active interface will be changed, so
> +	 * will be the PHC index.
> +	 */
> +	HWTSTAMP_FLAG_BONDED_PHC_INDEX = (1<<0),
> +
> +	HWTSTAMP_FLAG_LAST = HWTSTAMP_FLAG_BONDED_PHC_INDEX,
> +	HWTSTAMP_FLAG_MASK = (HWTSTAMP_FLAG_LAST - 1) | HWTSTAMP_FLAG_LAST
> +};
> +
>  /* possible values for hwtstamp_config->tx_type */
>  enum hwtstamp_tx_types {
>  	/*
> diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
> index 1d309a666932..1b807d119da5 100644
> --- a/net/core/dev_ioctl.c
> +++ b/net/core/dev_ioctl.c
> @@ -192,7 +192,7 @@ static int net_hwtstamp_validate(struct ifreq *ifr)
>  	if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
>  		return -EFAULT;
>  
> -	if (cfg.flags) /* reserved for future extensions */
> +	if (cfg.flags & ~HWTSTAMP_FLAG_MASK)
>  		return -EINVAL;
>  
>  	tx_type = cfg.tx_type;
> -- 
> 2.31.1
> 

  reply	other threads:[~2021-12-28  7:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-10  8:59 [PATCHv3 net-next 0/2] net: add new hwtstamp flag HWTSTAMP_FLAG_BONDED_PHC_INDEX Hangbin Liu
2021-12-10  8:59 ` [PATCHv3 net-next 1/2] net_tstamp: add new " Hangbin Liu
2021-12-28  7:01   ` Hangbin Liu [this message]
2021-12-28 15:15     ` Jakub Kicinski
2021-12-28 16:00       ` Richard Cochran
2021-12-28 16:17         ` Jakub Kicinski
2021-12-29  2:03           ` Richard Cochran
2021-12-29  3:50             ` Hangbin Liu
2021-12-10  8:59 ` [PATCHv3 net-next 2/2] Bonding: force user to add HWTSTAMP_FLAG_BONDED_PHC_INDEX when get/set HWTSTAMP Hangbin Liu
2021-12-14 12:40 ` [PATCHv3 net-next 0/2] net: add new hwtstamp flag HWTSTAMP_FLAG_BONDED_PHC_INDEX 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=Ycq2Ofad9UHur0qE@Laptop-X1 \
    --to=liuhangbin@gmail.com \
    --cc=andy@greyhouse.net \
    --cc=davem@davemloft.net \
    --cc=hkallweit1@gmail.com \
    --cc=j.vosburgh@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=vfalico@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