Skip to content

Commit

Permalink
net/netvsc: allocate contiguous physical memory for RNDIS
Browse files Browse the repository at this point in the history
[ upstream commit b8c3c62 ]

When sending data, netvsc assumes the tx_rndis buffer is contiguous and
calculates physical addresses based on this assumption.

Use memzone to allocate tx_rndis so it's guaranteed that this buffer is
physically contiguous.

Signed-off-by: Long Li <longli@microsoft.com>
  • Loading branch information
longlimsft authored and bluca committed Nov 9, 2020
1 parent e30d958 commit e896b66
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 12 additions & 11 deletions drivers/net/netvsc/hn_rxtx.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,15 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
PMD_INIT_LOG(DEBUG, "TX descriptor pool %s n=%u size=%zu",
name, nb_desc, sizeof(struct hn_txdesc));

txq->tx_rndis = rte_calloc("hn_txq_rndis", nb_desc,
HN_RNDIS_PKT_ALIGNED, RTE_CACHE_LINE_SIZE);
if (txq->tx_rndis == NULL)
txq->tx_rndis_mz = rte_memzone_reserve_aligned(name,
nb_desc * HN_RNDIS_PKT_ALIGNED, rte_socket_id(),
RTE_MEMZONE_IOVA_CONTIG, HN_RNDIS_PKT_ALIGNED);
if (!txq->tx_rndis_mz) {
err = -rte_errno;
goto error;
}
txq->tx_rndis = txq->tx_rndis_mz->addr;
txq->tx_rndis_iova = txq->tx_rndis_mz->iova;

txq->txdesc_pool = rte_mempool_create(name, nb_desc,
sizeof(struct hn_txdesc),
Expand Down Expand Up @@ -315,7 +320,7 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
error:
if (txq->txdesc_pool)
rte_mempool_free(txq->txdesc_pool);
rte_free(txq->tx_rndis);
rte_memzone_free(txq->tx_rndis_mz);
rte_free(txq);
return err;
}
Expand Down Expand Up @@ -357,7 +362,7 @@ hn_dev_tx_queue_release(void *arg)
if (txq->txdesc_pool)
rte_mempool_free(txq->txdesc_pool);

rte_free(txq->tx_rndis);
rte_memzone_free(txq->tx_rndis_mz);
rte_free(txq);
}

Expand Down Expand Up @@ -1356,12 +1361,8 @@ static int hn_xmit_sg(struct hn_tx_queue *txq,
hn_rndis_dump(txd->rndis_pkt);

/* pass IOVA of rndis header in first segment */
addr = rte_malloc_virt2iova(txq->tx_rndis);
if (unlikely(addr == RTE_BAD_IOVA)) {
PMD_DRV_LOG(ERR, "RNDIS transmit can not get iova");
return -EINVAL;
}
addr = addr + ((char *)txd->rndis_pkt - (char *)txq->tx_rndis);
addr = txq->tx_rndis_iova +
((char *)txd->rndis_pkt - (char *)txq->tx_rndis);

sg[0].page = addr / PAGE_SIZE;
sg[0].ofs = addr & PAGE_MASK;
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/netvsc/hn_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ struct hn_tx_queue {
uint16_t queue_id;
uint32_t free_thresh;
struct rte_mempool *txdesc_pool;
const struct rte_memzone *tx_rndis_mz;
void *tx_rndis;
rte_iova_t tx_rndis_iova;

/* Applied packet transmission aggregation limits. */
uint32_t agg_szmax;
Expand Down

0 comments on commit e896b66

Please sign in to comment.