netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] net: define new hwtstamp flag and return it to userspace
@ 2021-12-29  8:09 Hangbin Liu
  2021-12-29  8:09 ` [PATCH net-next 1/2] net_tstamp: define new flag HWTSTAMP_FLAG_BONDED_PHC_INDEX Hangbin Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Hangbin Liu @ 2021-12-29  8:09 UTC (permalink / raw)
  To: netdev
  Cc: Jay Vosburgh, Veaceslav Falico, Andy Gospodarek,
	David S . Miller, Jakub Kicinski, Richard Cochran,
	Heiner Kallweit, Hangbin Liu

This patchset defined the new hwtstamp flag HWTSTAMP_FLAG_BONDED_PHC_INDEX
to make userspace program build pass with old kernel header by settting ifdef.

Let's also return the flag when do SIOC[G/S]HWTSTAMP to let userspace know
that it's necessary for a given netdev.

Hangbin Liu (2):
  net_tstamp: define new flag HWTSTAMP_FLAG_BONDED_PHC_INDEX
  Bonding: return HWTSTAMP_FLAG_BONDED_PHC_INDEX to notify user space

 drivers/net/bonding/bond_main.c | 42 ++++++++++++++++++++-------------
 include/uapi/linux/net_tstamp.h |  1 +
 2 files changed, 27 insertions(+), 16 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net-next 1/2] net_tstamp: define new flag HWTSTAMP_FLAG_BONDED_PHC_INDEX
  2021-12-29  8:09 [PATCH net-next 0/2] net: define new hwtstamp flag and return it to userspace Hangbin Liu
@ 2021-12-29  8:09 ` Hangbin Liu
  2021-12-29 14:23   ` Richard Cochran
  2021-12-29  8:09 ` [PATCH net-next 2/2] Bonding: return HWTSTAMP_FLAG_BONDED_PHC_INDEX to notify user space Hangbin Liu
  2021-12-29 22:20 ` [PATCH net-next 0/2] net: define new hwtstamp flag and return it to userspace patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Hangbin Liu @ 2021-12-29  8:09 UTC (permalink / raw)
  To: netdev
  Cc: Jay Vosburgh, Veaceslav Falico, Andy Gospodarek,
	David S . Miller, Jakub Kicinski, Richard Cochran,
	Heiner Kallweit, Hangbin Liu

As we defined the new hwtstamp_config flag HWTSTAMP_FLAG_BONDED_PHC_INDEX
as enum, it's not easy for userspace program to check if the flag is
supported when build.

Let's define the new flag so user space could build it on old kernel with
ifdef check.

Fixes: 9c9211a3fc7a ("net_tstamp: add new flag HWTSTAMP_FLAG_BONDED_PHC_INDEX")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 include/uapi/linux/net_tstamp.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/net_tstamp.h b/include/uapi/linux/net_tstamp.h
index e258e52cfd1f..55501e5e7ac8 100644
--- a/include/uapi/linux/net_tstamp.h
+++ b/include/uapi/linux/net_tstamp.h
@@ -87,6 +87,7 @@ enum hwtstamp_flags {
 	 * will be the PHC index.
 	 */
 	HWTSTAMP_FLAG_BONDED_PHC_INDEX = (1<<0),
+#define HWTSTAMP_FLAG_BONDED_PHC_INDEX	HWTSTAMP_FLAG_BONDED_PHC_INDEX
 
 	HWTSTAMP_FLAG_LAST = HWTSTAMP_FLAG_BONDED_PHC_INDEX,
 	HWTSTAMP_FLAG_MASK = (HWTSTAMP_FLAG_LAST - 1) | HWTSTAMP_FLAG_LAST
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 2/2] Bonding: return HWTSTAMP_FLAG_BONDED_PHC_INDEX to notify user space
  2021-12-29  8:09 [PATCH net-next 0/2] net: define new hwtstamp flag and return it to userspace Hangbin Liu
  2021-12-29  8:09 ` [PATCH net-next 1/2] net_tstamp: define new flag HWTSTAMP_FLAG_BONDED_PHC_INDEX Hangbin Liu
@ 2021-12-29  8:09 ` Hangbin Liu
  2021-12-29 14:23   ` Richard Cochran
  2021-12-29 22:20 ` [PATCH net-next 0/2] net: define new hwtstamp flag and return it to userspace patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Hangbin Liu @ 2021-12-29  8:09 UTC (permalink / raw)
  To: netdev
  Cc: Jay Vosburgh, Veaceslav Falico, Andy Gospodarek,
	David S . Miller, Jakub Kicinski, Richard Cochran,
	Heiner Kallweit, Hangbin Liu

If the userspace program is distributed in binary form (distro package),
there is no way to know on which kernel versions it will run.

Let's only check if the flag was set when do SIOCSHWTSTAMP. And return
hwtstamp_config with flag HWTSTAMP_FLAG_BONDED_PHC_INDEX to notify
userspace whether the new feature is supported or not.

Suggested-by: Jakub Kicinski <kuba@kernel.org>
Fixes: 085d61000845 ("Bonding: force user to add HWTSTAMP_FLAG_BONDED_PHC_INDEX when get/set HWTSTAMP")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 drivers/net/bonding/bond_main.c | 42 ++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index b60e22f6394a..1bb8fa9fd3aa 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -4124,28 +4124,38 @@ static int bond_eth_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cm
 
 		break;
 	case SIOCSHWTSTAMP:
-	case SIOCGHWTSTAMP:
 		if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
 			return -EFAULT;
 
-		if (cfg.flags & HWTSTAMP_FLAG_BONDED_PHC_INDEX) {
-			rcu_read_lock();
-			real_dev = bond_option_active_slave_get_rcu(bond);
-			rcu_read_unlock();
-			if (real_dev) {
-				strscpy_pad(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
-				ifrr.ifr_ifru = ifr->ifr_ifru;
+		if (!(cfg.flags & HWTSTAMP_FLAG_BONDED_PHC_INDEX))
+			return -EOPNOTSUPP;
 
-				ops = real_dev->netdev_ops;
-				if (netif_device_present(real_dev) && ops->ndo_eth_ioctl) {
-					res = ops->ndo_eth_ioctl(real_dev, &ifrr, cmd);
+		fallthrough;
+	case SIOCGHWTSTAMP:
+		rcu_read_lock();
+		real_dev = bond_option_active_slave_get_rcu(bond);
+		rcu_read_unlock();
+		if (!real_dev)
+			return -EOPNOTSUPP;
 
-					if (!res)
-						ifr->ifr_ifru = ifrr.ifr_ifru;
+		strscpy_pad(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
+		ifrr.ifr_ifru = ifr->ifr_ifru;
 
-					return res;
-				}
-			}
+		ops = real_dev->netdev_ops;
+		if (netif_device_present(real_dev) && ops->ndo_eth_ioctl) {
+			res = ops->ndo_eth_ioctl(real_dev, &ifrr, cmd);
+			if (res)
+				return res;
+
+			ifr->ifr_ifru = ifrr.ifr_ifru;
+			if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
+				return -EFAULT;
+
+			/* Set the BOND_PHC_INDEX flag to notify user space */
+			cfg.flags |= HWTSTAMP_FLAG_BONDED_PHC_INDEX;
+
+			return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ?
+				-EFAULT : 0;
 		}
 		fallthrough;
 	default:
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 1/2] net_tstamp: define new flag HWTSTAMP_FLAG_BONDED_PHC_INDEX
  2021-12-29  8:09 ` [PATCH net-next 1/2] net_tstamp: define new flag HWTSTAMP_FLAG_BONDED_PHC_INDEX Hangbin Liu
@ 2021-12-29 14:23   ` Richard Cochran
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Cochran @ 2021-12-29 14:23 UTC (permalink / raw)
  To: Hangbin Liu
  Cc: netdev, Jay Vosburgh, Veaceslav Falico, Andy Gospodarek,
	David S . Miller, Jakub Kicinski, Heiner Kallweit

On Wed, Dec 29, 2021 at 04:09:37PM +0800, Hangbin Liu wrote:
> As we defined the new hwtstamp_config flag HWTSTAMP_FLAG_BONDED_PHC_INDEX
> as enum, it's not easy for userspace program to check if the flag is
> supported when build.
> 
> Let's define the new flag so user space could build it on old kernel with
> ifdef check.
> 
> Fixes: 9c9211a3fc7a ("net_tstamp: add new flag HWTSTAMP_FLAG_BONDED_PHC_INDEX")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>

Acked-by: Richard Cochran <richardcochran@gmail.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 2/2] Bonding: return HWTSTAMP_FLAG_BONDED_PHC_INDEX to notify user space
  2021-12-29  8:09 ` [PATCH net-next 2/2] Bonding: return HWTSTAMP_FLAG_BONDED_PHC_INDEX to notify user space Hangbin Liu
@ 2021-12-29 14:23   ` Richard Cochran
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Cochran @ 2021-12-29 14:23 UTC (permalink / raw)
  To: Hangbin Liu
  Cc: netdev, Jay Vosburgh, Veaceslav Falico, Andy Gospodarek,
	David S . Miller, Jakub Kicinski, Heiner Kallweit

On Wed, Dec 29, 2021 at 04:09:38PM +0800, Hangbin Liu wrote:
> If the userspace program is distributed in binary form (distro package),
> there is no way to know on which kernel versions it will run.
> 
> Let's only check if the flag was set when do SIOCSHWTSTAMP. And return
> hwtstamp_config with flag HWTSTAMP_FLAG_BONDED_PHC_INDEX to notify
> userspace whether the new feature is supported or not.
> 
> Suggested-by: Jakub Kicinski <kuba@kernel.org>
> Fixes: 085d61000845 ("Bonding: force user to add HWTSTAMP_FLAG_BONDED_PHC_INDEX when get/set HWTSTAMP")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>

Acked-by: Richard Cochran <richardcochran@gmail.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 0/2] net: define new hwtstamp flag and return it to userspace
  2021-12-29  8:09 [PATCH net-next 0/2] net: define new hwtstamp flag and return it to userspace Hangbin Liu
  2021-12-29  8:09 ` [PATCH net-next 1/2] net_tstamp: define new flag HWTSTAMP_FLAG_BONDED_PHC_INDEX Hangbin Liu
  2021-12-29  8:09 ` [PATCH net-next 2/2] Bonding: return HWTSTAMP_FLAG_BONDED_PHC_INDEX to notify user space Hangbin Liu
@ 2021-12-29 22:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-12-29 22:20 UTC (permalink / raw)
  To: Hangbin Liu
  Cc: netdev, j.vosburgh, vfalico, andy, davem, kuba, richardcochran,
	hkallweit1

Hello:

This series was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 29 Dec 2021 16:09:36 +0800 you wrote:
> This patchset defined the new hwtstamp flag HWTSTAMP_FLAG_BONDED_PHC_INDEX
> to make userspace program build pass with old kernel header by settting ifdef.
> 
> Let's also return the flag when do SIOC[G/S]HWTSTAMP to let userspace know
> that it's necessary for a given netdev.
> 
> Hangbin Liu (2):
>   net_tstamp: define new flag HWTSTAMP_FLAG_BONDED_PHC_INDEX
>   Bonding: return HWTSTAMP_FLAG_BONDED_PHC_INDEX to notify user space
> 
> [...]

Here is the summary with links:
  - [net-next,1/2] net_tstamp: define new flag HWTSTAMP_FLAG_BONDED_PHC_INDEX
    https://git.kernel.org/netdev/net-next/c/1bb412d46ca9
  - [net-next,2/2] Bonding: return HWTSTAMP_FLAG_BONDED_PHC_INDEX to notify user space
    https://git.kernel.org/netdev/net-next/c/cfe355c56e3a

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-12-29 22:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-29  8:09 [PATCH net-next 0/2] net: define new hwtstamp flag and return it to userspace Hangbin Liu
2021-12-29  8:09 ` [PATCH net-next 1/2] net_tstamp: define new flag HWTSTAMP_FLAG_BONDED_PHC_INDEX Hangbin Liu
2021-12-29 14:23   ` Richard Cochran
2021-12-29  8:09 ` [PATCH net-next 2/2] Bonding: return HWTSTAMP_FLAG_BONDED_PHC_INDEX to notify user space Hangbin Liu
2021-12-29 14:23   ` Richard Cochran
2021-12-29 22:20 ` [PATCH net-next 0/2] net: define new hwtstamp flag and return it to userspace patchwork-bot+netdevbpf

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).