Skip to contentSkip to conversation

net/tap: fix setting speed by argument

PATCH In review Ferruh Yigit 2 participants 7 messages Sep 18, 2017 – Oct 25, 2017 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 net/tap: fix setting speed by argument

From: Vipin Varghese <[email protected]>

tap speed argument is not working without generating any error.

This patch sets the configured speed during device start.

Fixes 02f96a0a82d1 ("net/tap: add TUN/TAP device PMD")
---
 drivers/net/tap/rte_eth_tap.c | 27 +++++++++++++++++++++++++++
 drivers/net/tap/rte_eth_tap.h |  2 ++
 2 files changed, 29 insertions(+)
drivers/net/tap/rte_eth_tap.c +27 -0
index 01cba0fa1..00dad167f 100644
@@ -545,6 +545,7 @@ tap_ioctl(struct pmd_internals *pmd, unsigned long request,
 	case SIOCGIFHWADDR:
 	case SIOCSIFHWADDR:
 	case SIOCSIFMTU:
+	case SIOCETHTOOL:
 		break;
 	default:
 		RTE_ASSERT(!"unsupported request type: must not happen");
@@ -585,6 +586,32 @@ static int
 tap_dev_start(struct rte_eth_dev *dev)
 {
 	int err;
+	struct ifreq ifr;
+	struct ethtool_cmd edata = {0};
+	struct pmd_internals *pmd = dev->data->dev_private;
+
+	/*set & get speed to device*/
+	edata.speed = pmd_link.link_speed;
+	edata.cmd = ETHTOOL_SSET;
+	ifr.ifr_data = (caddr_t)&edata;
+	if (tap_ioctl(pmd, SIOCETHTOOL, &ifr, 0, LOCAL_ONLY) < 0) {
+		RTE_LOG(WARNING, PMD,
+			"Could not set param speed %d for ifindex for %s.\n",
+				pmd_link.link_speed,
+				pmd->name);
+
+		/* fetch current speed of created device */
+		edata.cmd = ETHTOOL_GSET;
+		ifr.ifr_data = (caddr_t)&edata;
+		if (tap_ioctl(pmd, SIOCETHTOOL, &ifr, 0, LOCAL_ONLY) < 0)
+			return 0;
+
+		pmd_link.link_speed = edata.speed;
+		RTE_LOG(INFO, PMD, "get speed %d for ifindex for %s.\n",
+			pmd_link.link_speed,
+			pmd->name);
+	}
+	dev->data->dev_link = pmd_link;
 
 	err = tap_intr_handle_set(dev, 1);
 	if (err)
drivers/net/tap/rte_eth_tap.h +2 -0
index 928a0454e..3e91db4ae 100644
@@ -40,6 +40,8 @@
 #include <net/if.h>
 
 #include <linux/if_tun.h>
+#include <linux/ethtool.h>
+#include <linux/sockios.h>
 
 #include <rte_ethdev.h>
 #include <rte_ether.h>
Signature · 1 line
2.13.5
#1 lore raw

PATCH 2/2 net/tap: fix unregistering callback with invalid fd

From: Vipin Varghese <[email protected]>

tap_intr_handle_set() called by tap_dev_start(), and if LSC is disabled (dev_conf.intr_conf.lsc == 0), it tries to unregister interrupt callback without checking the interrupt file descriptor.

Fixes c0bddd3a057f ("net/tap: add link status notification")
---
 drivers/net/tap/rte_eth_tap.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/tap/rte_eth_tap.c +4 -3
index 00dad167f..fcfd4215e 100644
@@ -1098,10 +1098,11 @@ tap_intr_handle_set(struct rte_eth_dev *dev, int set)
 
 	/* In any case, disable interrupt if the conf is no longer there. */
 	if (!dev->data->dev_conf.intr_conf.lsc) {
-		if (pmd->intr_handle.fd != -1)
+		if (pmd->intr_handle.fd != -1) {
 			nl_final(pmd->intr_handle.fd);
-		rte_intr_callback_unregister(
-			&pmd->intr_handle, tap_dev_intr_handler, dev);
+			rte_intr_callback_unregister(&pmd->intr_handle,
+				tap_dev_intr_handler, dev);
+		}
 		return 0;
 	}
 	if (set) {
Signature · 1 line
2.13.5
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] net/tap: fix unregistering callback with invalid fd

Looks good.

Best regards,
Pascal

Quoted 33 lines · Ferruh Yigit

From: Vipin Varghese <[email protected]>

tap_intr_handle_set() called by tap_dev_start(), and if LSC is disabled (dev_conf.intr_conf.lsc == 0), it tries to unregister interrupt callback without checking the interrupt file descriptor.

Fixes c0bddd3a057f ("net/tap: add link status notification")
---
 drivers/net/tap/rte_eth_tap.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/tap/rte_eth_tap.c +4 -3
index 00dad167f..fcfd4215e 100644
@@ -1098,10 +1098,11 @@ tap_intr_handle_set(struct rte_eth_dev *dev, int set)
 
 	/* In any case, disable interrupt if the conf is no longer there. */
 	if (!dev->data->dev_conf.intr_conf.lsc) {
-		if (pmd->intr_handle.fd != -1)
+		if (pmd->intr_handle.fd != -1) {
 			nl_final(pmd->intr_handle.fd);
-		rte_intr_callback_unregister(
-			&pmd->intr_handle, tap_dev_intr_handler, dev);
+			rte_intr_callback_unregister(&pmd->intr_handle,
+				tap_dev_intr_handler, dev);
+		}
 		return 0;
 	}
 	if (set) {
author Applied
#3 lore raw

Re: [PATCH 2/2] net/tap: fix unregistering callback with invalid fd

On 9/19/2017 1:46 PM, Pascal Mazon wrote:
<...>

Quoted 7 lines · Ferruh Yigit
Quoted 6 lines

From: Vipin Varghese <[email protected]>

tap_intr_handle_set() called by tap_dev_start(), and if LSC is disabled (dev_conf.intr_conf.lsc == 0), it tries to unregister interrupt callback without checking the interrupt file descriptor.

Quoted 6 lines
Quoted 4 lines
Fixes c0bddd3a057f ("net/tap: add link status notification")

Applied to dpdk-next-net/master, thanks.

#4 lore raw
In reply to Ferruh Yigit

Hi,

The patch looks mainly ok to me.

I'll put some comments inline.

Quoted 3 lines · Ferruh Yigit

From: Vipin Varghese <[email protected]>

tap speed argument is not working without generating any error.

Can you describe the error, paste the log?

Quoted 27 lines

This patch sets the configured speed during device start.

Fixes 02f96a0a82d1 ("net/tap: add TUN/TAP device PMD")
---
 drivers/net/tap/rte_eth_tap.c | 27 +++++++++++++++++++++++++++
 drivers/net/tap/rte_eth_tap.h |  2 ++
 2 files changed, 29 insertions(+)
drivers/net/tap/rte_eth_tap.c +1 -0
index 01cba0fa1..00dad167f 100644
@@ -545,6 +545,7 @@ tap_ioctl(struct pmd_internals *pmd, unsigned long request,
 	case SIOCGIFHWADDR:
 	case SIOCSIFHWADDR:
 	case SIOCSIFMTU:
+	case SIOCETHTOOL:
 		break;
 	default:
 		RTE_ASSERT(!"unsupported request type: must not happen");
@@ -585,6 +586,32 @@ static int
 tap_dev_start(struct rte_eth_dev *dev)
 {

drivers/net/tap/rte_eth_tap.c static int · line 597

Quoted 10 lines
drivers/net/tap/rte_eth_tap.c +9 -0
 	int err;
+	struct ifreq ifr;
+	struct ethtool_cmd edata = {0};
+	struct pmd_internals *pmd = dev->data->dev_private;
+
+	/*set & get speed to device*/
+	edata.speed = pmd_link.link_speed;
+	edata.cmd = ETHTOOL_SSET;
+	ifr.ifr_data = (caddr_t)&edata;
+	if (tap_ioctl(pmd, SIOCETHTOOL, &ifr, 0, LOCAL_ONLY) < 0) {

I think it would be best to also try setting the speed on the remote (tap_ioctl(REMOTE_ONLY)), but continue execution even if that fails.

drivers/net/tap/rte_eth_tap.c static int · line 610

Quoted 13 lines
drivers/net/tap/rte_eth_tap.c +13 -0
+		RTE_LOG(WARNING, PMD,
+			"Could not set param speed %d for ifindex for %s.\n",
+				pmd_link.link_speed,
+				pmd->name);
+
+		/* fetch current speed of created device */
+		edata.cmd = ETHTOOL_GSET;
+		ifr.ifr_data = (caddr_t)&edata;
+		if (tap_ioctl(pmd, SIOCETHTOOL, &ifr, 0, LOCAL_ONLY) < 0)
+			return 0;
+
+		pmd_link.link_speed = edata.speed;
+		RTE_LOG(INFO, PMD, "get speed %d for ifindex for %s.\n",

I would say "got".

Quoted 12 lines
drivers/net/tap/rte_eth_tap.c +4 -0
+			pmd_link.link_speed,
+			pmd->name);
+	}
+	dev->data->dev_link = pmd_link;
 
 	err = tap_intr_handle_set(dev, 1);
 	if (err)
drivers/net/tap/rte_eth_tap.h +0 -0
index 928a0454e..3e91db4ae 100644

drivers/net/tap/rte_eth_tap.h line 47

Quoted 8 lines
drivers/net/tap/rte_eth_tap.h +2 -0
@@ -40,6 +40,8 @@
 #include <net/if.h>
 
 #include <linux/if_tun.h>
+#include <linux/ethtool.h>
+#include <linux/sockios.h>
 
 #include <rte_ethdev.h>
 #include <rte_ether.h>

These includes are only useful inside rte_eth_tap.c, I would put them there only.

#5 lore raw
Quoted 42 lines · Pascal Mazon

Hi,

The patch looks mainly ok to me.

I'll put some comments inline.

Quoted 3 lines · Ferruh Yigit

From: Vipin Varghese <[email protected]>

tap speed argument is not working without generating any error.

Can you describe the error, paste the log?

Quoted 31 lines

This patch sets the configured speed during device start.

Fixes 02f96a0a82d1 ("net/tap: add TUN/TAP device PMD")
---
 drivers/net/tap/rte_eth_tap.c | 27 +++++++++++++++++++++++++++
 drivers/net/tap/rte_eth_tap.h |  2 ++
 2 files changed, 29 insertions(+)
drivers/net/tap/rte_eth_tap.c +4 -0
index 01cba0fa1..00dad167f 100644
@@ -545,6 +545,7 @@ tap_ioctl(struct pmd_internals *pmd, unsigned long request,
 	case SIOCGIFHWADDR:
 	case SIOCSIFHWADDR:
 	case SIOCSIFMTU:
+	case SIOCETHTOOL:
 		break;
 	default:
 		RTE_ASSERT(!"unsupported request type: must not happen");
@@ -585,6 +586,32 @@ static int
 tap_dev_start(struct rte_eth_dev *dev)
 {
 	int err;
+	struct ifreq ifr;
+	struct ethtool_cmd edata = {0};
+	struct pmd_internals *pmd = dev->data->dev_private;
Quoted 8 lines

drivers/net/tap/rte_eth_tap.c static int · line 597

Quoted 6 lines
drivers/net/tap/rte_eth_tap.c +6 -0
+
+	/*set & get speed to device*/
+	edata.speed = pmd_link.link_speed;
+	edata.cmd = ETHTOOL_SSET;
+	ifr.ifr_data = (caddr_t)&edata;
+	if (tap_ioctl(pmd, SIOCETHTOOL, &ifr, 0, LOCAL_ONLY) < 0) {

I think it would be best to also try setting the speed on the remote (tap_ioctl(REMOTE_ONLY)), but continue execution even if that fails.

Hi Pascal,

It looks like this ioctl fails to set tap speed. And as far as I can see speed is hardcoded in kernel [1], do you know if it is possible to set speed of tap interface?

Thanks,
ferruh

[1]
http://elixir.free-electrons.com/linux/v4.13.9/source/drivers/net/tun.c#L2460

Quoted 38 lines

drivers/net/tap/rte_eth_tap.c static int · line 610

Quoted 13 lines
drivers/net/tap/rte_eth_tap.c +13 -0
+		RTE_LOG(WARNING, PMD,
+			"Could not set param speed %d for ifindex for %s.\n",
+				pmd_link.link_speed,
+				pmd->name);
+
+		/* fetch current speed of created device */
+		edata.cmd = ETHTOOL_GSET;
+		ifr.ifr_data = (caddr_t)&edata;
+		if (tap_ioctl(pmd, SIOCETHTOOL, &ifr, 0, LOCAL_ONLY) < 0)
+			return 0;
+
+		pmd_link.link_speed = edata.speed;
+		RTE_LOG(INFO, PMD, "get speed %d for ifindex for %s.\n",

I would say "got".

Quoted 12 lines
drivers/net/tap/rte_eth_tap.c +4 -0
+			pmd_link.link_speed,
+			pmd->name);
+	}
+	dev->data->dev_link = pmd_link;
 
 	err = tap_intr_handle_set(dev, 1);
 	if (err)
drivers/net/tap/rte_eth_tap.h +0 -0
index 928a0454e..3e91db4ae 100644

drivers/net/tap/rte_eth_tap.h line 47

Quoted 8 lines
drivers/net/tap/rte_eth_tap.h +2 -0
@@ -40,6 +40,8 @@
 #include <net/if.h>
 
 #include <linux/if_tun.h>
+#include <linux/ethtool.h>
+#include <linux/sockios.h>
 
 #include <rte_ethdev.h>
 #include <rte_ether.h>

These includes are only useful inside rte_eth_tap.c, I would put them there only.

#6 lore raw
Quoted 56 lines · Ferruh Yigit
Quoted 41 lines · Pascal Mazon

Hi,

The patch looks mainly ok to me.

I'll put some comments inline.

Quoted 3 lines · Ferruh Yigit

From: Vipin Varghese <[email protected]>

tap speed argument is not working without generating any error.

Can you describe the error, paste the log?

Quoted 30 lines

This patch sets the configured speed during device start.

Fixes 02f96a0a82d1 ("net/tap: add TUN/TAP device PMD")
---
 drivers/net/tap/rte_eth_tap.c | 27 +++++++++++++++++++++++++++
 drivers/net/tap/rte_eth_tap.h |  2 ++
 2 files changed, 29 insertions(+)
drivers/net/tap/rte_eth_tap.c +4 -0
index 01cba0fa1..00dad167f 100644
@@ -545,6 +545,7 @@ tap_ioctl(struct pmd_internals *pmd, unsigned long request,
 	case SIOCGIFHWADDR:
 	case SIOCSIFHWADDR:
 	case SIOCSIFMTU:
+	case SIOCETHTOOL:
 		break;
 	default:
 		RTE_ASSERT(!"unsupported request type: must not happen");
@@ -585,6 +586,32 @@ static int
 tap_dev_start(struct rte_eth_dev *dev)
 {
 	int err;
+	struct ifreq ifr;
+	struct ethtool_cmd edata = {0};
+	struct pmd_internals *pmd = dev->data->dev_private;
Quoted 8 lines

drivers/net/tap/rte_eth_tap.c static int · line 597

Quoted 6 lines
drivers/net/tap/rte_eth_tap.c +6 -0
+
+	/*set & get speed to device*/
+	edata.speed = pmd_link.link_speed;
+	edata.cmd = ETHTOOL_SSET;
+	ifr.ifr_data = (caddr_t)&edata;
+	if (tap_ioctl(pmd, SIOCETHTOOL, &ifr, 0, LOCAL_ONLY) < 0) {

I think it would be best to also try setting the speed on the remote (tap_ioctl(REMOTE_ONLY)), but continue execution even if that fails.

Hi Pascal,

It looks like this ioctl fails to set tap speed. And as far as I can see speed is hardcoded in kernel [1], do you know if it is possible to set speed of tap interface?

Quoted 5 lines

Thanks,
ferruh

[1]
http://elixir.free-electrons.com/linux/v4.13.9/source/drivers/net/tun.c#L2460

Hi Ferruh,

I concur with you, it definitely looks like speed is hardcoded in the kernel.
And there is no set_settings() callback defined either, so it won't be possible to set anything using ethtool.

I haven't seen the error and I don't think Vipin Varghese sent a log for that.
I'm still not sure what the patch was fixing; it would be good to have that feedback to improve the patch.

Best regards,
Pascal

Quoted 39 lines
Quoted 39 lines
Quoted 4 lines
drivers/net/tap/rte_eth_tap.c +3 -0
+		RTE_LOG(WARNING, PMD,
+			"Could not set param speed %d for ifindex for %s.\n",
+				pmd_link.link_speed,

drivers/net/tap/rte_eth_tap.c static int · line 610

Quoted 10 lines
drivers/net/tap/rte_eth_tap.c +10 -0
+				pmd->name);
+
+		/* fetch current speed of created device */
+		edata.cmd = ETHTOOL_GSET;
+		ifr.ifr_data = (caddr_t)&edata;
+		if (tap_ioctl(pmd, SIOCETHTOOL, &ifr, 0, LOCAL_ONLY) < 0)
+			return 0;
+
+		pmd_link.link_speed = edata.speed;
+		RTE_LOG(INFO, PMD, "get speed %d for ifindex for %s.\n",

I would say "got".

Quoted 12 lines
drivers/net/tap/rte_eth_tap.c +4 -0
+			pmd_link.link_speed,
+			pmd->name);
+	}
+	dev->data->dev_link = pmd_link;
 
 	err = tap_intr_handle_set(dev, 1);
 	if (err)
drivers/net/tap/rte_eth_tap.h +0 -0
index 928a0454e..3e91db4ae 100644

drivers/net/tap/rte_eth_tap.h line 47

Quoted 8 lines
drivers/net/tap/rte_eth_tap.h +2 -0
@@ -40,6 +40,8 @@
 #include <net/if.h>
 
 #include <linux/if_tun.h>
+#include <linux/ethtool.h>
+#include <linux/sockios.h>
 
 #include <rte_ethdev.h>
 #include <rte_ether.h>

These includes are only useful inside rte_eth_tap.c, I would put them there only.