From: "Wiles, Keith" <keith.wiles@intel.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: "dev@dpdk.org" <dev@dpdk.org>, "hfli@netitest.com" <hfli@netitest.com>
Subject: Re: [dpdk-dev] [PATCH 5/6] net/tap: let kernel choose tun device name
Date: Fri, 11 Jan 2019 19:43:09 +0000 [thread overview]
Message-ID: <34BDCAAA-A72E-4B9A-8C43-860CEC756588@intel.com> (raw)
In-Reply-To: <20190111180659.5972-6-stephen@networkplumber.org>
> On Jan 11, 2019, at 12:06 PM, Stephen Hemminger <stephen@networkplumber.org> wrote:
>
> Assigning tun and tap index in DPDK tap device driver is racy and
> fails if used with primary/secondary process model. Instead, use the
> kernel feature of device wildcarding where if a name with %d is used
> the kernel will fill in the next available device.
>
> Reported-by: hfli@netitest.com
> Fixes: 02f96a0a82d1 ("net/tap: add TUN/TAP device PMD")
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> drivers/net/tap/rte_eth_tap.c | 32 ++++++++++++++++----------------
> 1 file changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
> index 50d6729cb609..b836c1ae3d4e 100644
> --- a/drivers/net/tap/rte_eth_tap.c
> +++ b/drivers/net/tap/rte_eth_tap.c
> @@ -79,9 +79,6 @@ static const char *valid_arguments[] = {
> NULL
> };
>
> -static unsigned int tap_unit;
> -static unsigned int tun_unit;
> -
> static char tuntap_name[8];
>
> static volatile uint32_t tap_trigger; /* Rx trigger */
> @@ -151,8 +148,6 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive)
> IFF_TAP : IFF_TUN | IFF_POINTOPOINT;
> strlcpy(ifr.ifr_name, pmd->name, IFNAMSIZ);
>
> - TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name);
> -
> fd = open(TUN_TAP_DEV_PATH, O_RDWR);
> if (fd < 0) {
> TAP_LOG(ERR, "Unable to create %s interface", tuntap_name);
> @@ -186,6 +181,13 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive)
> goto error;
> }
>
> + /*
> + * Name passed to kernel might be wildcard like dtun%d
> + * and need to find the resulting device.
> + */
> + TAP_LOG(DEBUG, "Device name is '%s'", ifr.ifr_name);
> + strlcpy(pmd->name, ifr.ifr_name, RTE_ETH_NAME_MAX_LEN);
> +
> if (is_keepalive) {
> /*
> * Detach the TUN/TAP keep-alive queue
> @@ -1756,6 +1758,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
> TAP_LOG(ERR, "Unable to create %s interface", tuntap_name);
> goto error_exit;
> }
> + TAP_LOG(INFO, "allocated %s", pmd->name);
Is this one required to be INFO as you wanted to reduce log clutter? I am ok with it, but thought I would ask.
>
> ifr.ifr_mtu = dev->data->mtu;
> if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0)
> @@ -1917,8 +1920,8 @@ set_interface_name(const char *key __rte_unused,
> }
> strlcpy(name, value, RTE_ETH_NAME_MAX_LEN);
> } else {
> - snprintf(name, RTE_ETH_NAME_MAX_LEN, "%s%d",
> - DEFAULT_TAP_NAME, tun_unit - 1);
> + snprintf(name, RTE_ETH_NAME_MAX_LEN, "%s%%d",
> + DEFAULT_TAP_NAME);
I guess a short comment would be nice for the reader to know that this is a kernel feature syntax.
> }
> return 0;
> }
> @@ -2031,8 +2034,8 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
> return 0;
> }
>
> - snprintf(tun_name, sizeof(tun_name), "%s%u",
> - DEFAULT_TUN_NAME, tun_unit++);
> + snprintf(tun_name, sizeof(tun_name), "%s%%d",
> + DEFAULT_TUN_NAME);
Same here.
>
> if (params && (params[0] != '\0')) {
> TAP_LOG(DEBUG, "parameters (%s)", params);
> @@ -2052,17 +2055,15 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
> }
> pmd_link.link_speed = ETH_SPEED_NUM_10G;
>
> - TAP_LOG(DEBUG, "Initializing pmd_tun for %s as %s",
> - name, tun_name);
> + TAP_LOG(DEBUG, "Initializing pmd_tun for %s", name);
>
> ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0,
> - ETH_TUNTAP_TYPE_TUN);
> + ETH_TUNTAP_TYPE_TUN);
>
> leave:
> if (ret == -1) {
> TAP_LOG(ERR, "Failed to create pmd for %s as %s",
> name, tun_name);
> - tun_unit--; /* Restore the unit number */
> }
> rte_kvargs_free(kvlist);
>
> @@ -2218,8 +2219,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
> }
>
> speed = ETH_SPEED_NUM_10G;
> - snprintf(tap_name, sizeof(tap_name), "%s%u",
> - DEFAULT_TAP_NAME, tap_unit++);
> + snprintf(tap_name, sizeof(tap_name),
> + "%s%%d", DEFAULT_TAP_NAME);
> memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
>
> if (params && (params[0] != '\0')) {
> @@ -2282,7 +2283,6 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
> rte_mp_action_unregister(TAP_MP_KEY);
> tap_devices_count--;
> }
> - tap_unit--; /* Restore the unit number */
> }
> rte_kvargs_free(kvlist);
>
> --
> 2.20.1
>
Regards,
Keith
next prev parent reply other threads:[~2019-01-11 19:43 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-11 18:06 [dpdk-dev] [PATCH 0/6] net/tap: fixes and cleanups Stephen Hemminger
2019-01-11 18:06 ` [dpdk-dev] [PATCH 1/6] net/tap: use strlcpy for interface name Stephen Hemminger
2019-01-11 18:06 ` [dpdk-dev] [PATCH 2/6] net/tap: allow full length names Stephen Hemminger
2019-01-11 19:32 ` Wiles, Keith
2019-01-11 19:48 ` Stephen Hemminger
2019-01-11 19:49 ` Wiles, Keith
2019-01-11 18:06 ` [dpdk-dev] [PATCH 3/6] net/tap: check interface name in kvargs Stephen Hemminger
2019-01-11 19:37 ` Wiles, Keith
2019-01-11 19:49 ` Stephen Hemminger
2019-01-11 19:50 ` Wiles, Keith
2019-01-15 2:01 ` Thomas Monjalon
2019-01-11 22:20 ` Luse, Paul E
2019-01-11 18:06 ` [dpdk-dev] [PATCH 4/6] net/tap: lower the priority of log messages Stephen Hemminger
2019-01-11 18:06 ` [dpdk-dev] [PATCH 5/6] net/tap: let kernel choose tun device name Stephen Hemminger
2019-01-11 19:43 ` Wiles, Keith [this message]
2019-01-11 18:06 ` [dpdk-dev] [PATCH 6/6] net/tap: get rid of global tuntap_name Stephen Hemminger
2019-01-11 19:47 ` [dpdk-dev] [PATCH 0/6] net/tap: fixes and cleanups Wiles, Keith
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 " Stephen Hemminger
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 1/7] net/tap: use strlcpy for interface name Stephen Hemminger
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 2/7] net/tap: allow full length names Stephen Hemminger
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 3/7] net/tap: check interface name in kvargs Stephen Hemminger
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 4/7] net/tap: lower the priority of log messages Stephen Hemminger
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 5/7] net/tap: let kernel choose tun device name Stephen Hemminger
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 6/7] net/tap: get rid of global tuntap_name Stephen Hemminger
2019-01-11 20:35 ` [dpdk-dev] [PATCH v2 7/7] net/tap: don't print pointer in info message Stephen Hemminger
2019-01-14 14:10 ` Ferruh Yigit
2019-01-14 15:07 ` Wiles, Keith
2019-01-14 14:10 ` [dpdk-dev] [PATCH v2 0/6] net/tap: fixes and cleanups Ferruh Yigit
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=34BDCAAA-A72E-4B9A-8C43-860CEC756588@intel.com \
--to=keith.wiles@intel.com \
--cc=dev@dpdk.org \
--cc=hfli@netitest.com \
--cc=stephen@networkplumber.org \
/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;
as well as URLs for NNTP newsgroup(s).