[dpdk-dev,v2] net/tap: fix invalid queue file descriptor

Message ID 20170130205445.7527-1-ferruh.yigit@intel.com
State Accepted, archived
Headers show

Checks

Context Check Description
ci/Intel compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Ferruh Yigit Jan. 30, 2017, 8:54 p.m.
From: Keith Wiles <keith.wiles@intel.com>

Rx and Tx queues share the common tap file descriptor, but save this
value separately.

Setting up Rx/Tx queue sets up both queues, release_queue close the
tap file but update file descriptor only for that queue.

This makes other queue's file descriptor invalid.

As a workaround, prevent release_queue callback to be called by default.

This is done by separating Rx/Tx setup functions, so that each only
setup its own queue, this prevents rte_eth_rx/tx_queue_setup() calling
release_queue before setup_queue.

Signed-off-by: Keith Wiles <keith.wiles@intel.com>
Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 drivers/net/tap/rte_eth_tap.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

Comments

Wiles, Keith Jan. 30, 2017, 8:57 p.m. | #1
> On Jan 30, 2017, at 2:54 PM, Yigit, Ferruh <ferruh.yigit@intel.com> wrote:
> 
> From: Keith Wiles <keith.wiles@intel.com>
> 
> Rx and Tx queues share the common tap file descriptor, but save this
> value separately.
> 
> Setting up Rx/Tx queue sets up both queues, release_queue close the
> tap file but update file descriptor only for that queue.
> 
> This makes other queue's file descriptor invalid.
> 
> As a workaround, prevent release_queue callback to be called by default.
> 
> This is done by separating Rx/Tx setup functions, so that each only
> setup its own queue, this prevents rte_eth_rx/tx_queue_setup() calling
> release_queue before setup_queue.
> 
> Signed-off-by: Keith Wiles <keith.wiles@intel.com>
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>

Acked-by: Keith Wiles <keith.wiles@intel.com>

> ---
> drivers/net/tap/rte_eth_tap.c | 26 ++++++++++++++++++++++----
> 1 file changed, 22 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
> index c0afc2d..91f63f5 100644
> --- a/drivers/net/tap/rte_eth_tap.c
> +++ b/drivers/net/tap/rte_eth_tap.c
> @@ -428,8 +428,6 @@ tap_setup_queue(struct rte_eth_dev *dev,
> 			}
> 		}
> 	}
> -	dev->data->rx_queues[qid] = rx;
> -	dev->data->tx_queues[qid] = tx;
> 
> 	rx->fd = fd;
> 	tx->fd = fd;
> @@ -438,6 +436,26 @@ tap_setup_queue(struct rte_eth_dev *dev,
> }
> 
> static int
> +rx_setup_queue(struct rte_eth_dev *dev,
> +		struct pmd_internals *internals,
> +		uint16_t qid)
> +{
> +	dev->data->rx_queues[qid] = &internals->rxq[qid];
> +
> +	return tap_setup_queue(dev, internals, qid);
> +}
> +
> +static int
> +tx_setup_queue(struct rte_eth_dev *dev,
> +		struct pmd_internals *internals,
> +		uint16_t qid)
> +{
> +	dev->data->tx_queues[qid] = &internals->txq[qid];
> +
> +	return tap_setup_queue(dev, internals, qid);
> +}
> +
> +static int
> tap_rx_queue_setup(struct rte_eth_dev *dev,
> 		   uint16_t rx_queue_id,
> 		   uint16_t nb_rx_desc __rte_unused,
> @@ -469,7 +487,7 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
> 		return -ENOMEM;
> 	}
> 
> -	fd = tap_setup_queue(dev, internals, rx_queue_id);
> +	fd = rx_setup_queue(dev, internals, rx_queue_id);
> 	if (fd == -1)
> 		return -1;
> 
> @@ -493,7 +511,7 @@ tap_tx_queue_setup(struct rte_eth_dev *dev,
> 	if (tx_queue_id >= internals->nb_queues)
> 		return -1;
> 
> -	ret = tap_setup_queue(dev, internals, tx_queue_id);
> +	ret = tx_setup_queue(dev, internals, tx_queue_id);
> 	if (ret == -1)
> 		return -1;
> 
> -- 
> 2.9.3
> 

Regards,
Keith
Ferruh Yigit Jan. 30, 2017, 9:23 p.m. | #2
On 1/30/2017 8:57 PM, Wiles, Keith wrote:
> 
>> On Jan 30, 2017, at 2:54 PM, Yigit, Ferruh <ferruh.yigit@intel.com> wrote:
>>
>> From: Keith Wiles <keith.wiles@intel.com>
>>
>> Rx and Tx queues share the common tap file descriptor, but save this
>> value separately.
>>
>> Setting up Rx/Tx queue sets up both queues, release_queue close the
>> tap file but update file descriptor only for that queue.
>>
>> This makes other queue's file descriptor invalid.
>>
>> As a workaround, prevent release_queue callback to be called by default.
>>
>> This is done by separating Rx/Tx setup functions, so that each only
>> setup its own queue, this prevents rte_eth_rx/tx_queue_setup() calling
>> release_queue before setup_queue.
>>
>> Signed-off-by: Keith Wiles <keith.wiles@intel.com>
>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>

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

(Just a reminder, defect still exists when app call
rte_eth_rx/tx_queue_setup() multiple times)

Patch

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index c0afc2d..91f63f5 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -428,8 +428,6 @@  tap_setup_queue(struct rte_eth_dev *dev,
 			}
 		}
 	}
-	dev->data->rx_queues[qid] = rx;
-	dev->data->tx_queues[qid] = tx;
 
 	rx->fd = fd;
 	tx->fd = fd;
@@ -438,6 +436,26 @@  tap_setup_queue(struct rte_eth_dev *dev,
 }
 
 static int
+rx_setup_queue(struct rte_eth_dev *dev,
+		struct pmd_internals *internals,
+		uint16_t qid)
+{
+	dev->data->rx_queues[qid] = &internals->rxq[qid];
+
+	return tap_setup_queue(dev, internals, qid);
+}
+
+static int
+tx_setup_queue(struct rte_eth_dev *dev,
+		struct pmd_internals *internals,
+		uint16_t qid)
+{
+	dev->data->tx_queues[qid] = &internals->txq[qid];
+
+	return tap_setup_queue(dev, internals, qid);
+}
+
+static int
 tap_rx_queue_setup(struct rte_eth_dev *dev,
 		   uint16_t rx_queue_id,
 		   uint16_t nb_rx_desc __rte_unused,
@@ -469,7 +487,7 @@  tap_rx_queue_setup(struct rte_eth_dev *dev,
 		return -ENOMEM;
 	}
 
-	fd = tap_setup_queue(dev, internals, rx_queue_id);
+	fd = rx_setup_queue(dev, internals, rx_queue_id);
 	if (fd == -1)
 		return -1;
 
@@ -493,7 +511,7 @@  tap_tx_queue_setup(struct rte_eth_dev *dev,
 	if (tx_queue_id >= internals->nb_queues)
 		return -1;
 
-	ret = tap_setup_queue(dev, internals, tx_queue_id);
+	ret = tx_setup_queue(dev, internals, tx_queue_id);
 	if (ret == -1)
 		return -1;