patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
To: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Cc: Juho Snellman <jsnell@iki.fi>, Yaron Illouz <yaroni@radcom.com>,
	dpdk stable <stable@dpdk.org>
Subject: [dpdk-stable] patch 'net/virtio: fix multiple process support' has been queued to stable release 16.11.1
Date: Wed, 15 Feb 2017 14:26:47 +0800	[thread overview]
Message-ID: <1487140012-13314-35-git-send-email-yuanhan.liu@linux.intel.com> (raw)
In-Reply-To: <1487140012-13314-1-git-send-email-yuanhan.liu@linux.intel.com>

Hi,

FYI, your patch has been queued to stable release 16.11.1

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable
yet. It will be pushed if I get no objections before 02/18/17.
So please shout if anyone has objections.

Thanks.

	--yliu

---
>From f936571d05c297167ee29cf2f34e14668cbced89 Mon Sep 17 00:00:00 2001
From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Date: Fri, 6 Jan 2017 18:16:19 +0800
Subject: [PATCH] net/virtio: fix multiple process support

[ backported from upstream commit 6d890f8ab51295045a53f41c4d2654bb1f01cf38 ]

The introduce of virtio 1.0 support brings yet another set of ops, badly,
it's not handled correctly, that it breaks the multiple process support.

The issue is the data/function pointer may vary from different processes,
and the old used to do one time set (for primary process only). That
said, the function pointer the secondary process saw is actually from the
primary process space. Accessing it could likely result to a crash.

Kudos to the last patches, we now be able to maintain those info that may
vary among different process locally, meaning every process could have its
own copy for each of them, with the correct value set. And this is what
this patch does:

- remap the PCI (IO port for legacy device and memory map for modern
  device)

- set vtpci_ops correctly

After that, multiple process would work like a charm. (At least, it
passed my fuzzy test)

Fixes: b8f04520ad71 ("virtio: use PCI ioport API")
Fixes: d5bbeefca826 ("virtio: introduce PCI implementation structure")
Fixes: 6ba1f63b5ab0 ("virtio: support specification 1.0")

Reported-by: Juho Snellman <jsnell@iki.fi>
Reported-by: Yaron Illouz <yaroni@radcom.com>
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 doc/guides/nics/features/virtio.ini     |  1 +
 drivers/net/virtio/virtio_ethdev.c      | 50 +++++++++++++++++++++++++++++++++
 drivers/net/virtio/virtio_pci.c         |  4 +--
 drivers/net/virtio/virtio_pci.h         |  4 +++
 drivers/net/virtio/virtio_user_ethdev.c |  2 +-
 5 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/doc/guides/nics/features/virtio.ini b/doc/guides/nics/features/virtio.ini
index 41830c1..1d996c6 100644
--- a/doc/guides/nics/features/virtio.ini
+++ b/doc/guides/nics/features/virtio.ini
@@ -14,6 +14,7 @@ Multicast MAC filter = Y
 VLAN filter          = Y
 Basic stats          = Y
 Stats per queue      = Y
+Multiprocess aware   = Y
 BSD nic_uio          = Y
 Linux UIO            = Y
 Linux VFIO           = Y
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index fd0ffc2..6e5c5d6 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1291,6 +1291,49 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 }
 
 /*
+ * Remap the PCI device again (IO port map for legacy device and
+ * memory map for modern device), so that the secondary process
+ * could have the PCI initiated correctly.
+ */
+static int
+virtio_remap_pci(struct rte_pci_device *pci_dev, struct virtio_hw *hw)
+{
+	if (hw->modern) {
+		/*
+		 * We don't have to re-parse the PCI config space, since
+		 * rte_eal_pci_map_device() makes sure the mapped address
+		 * in secondary process would equal to the one mapped in
+		 * the primary process: error will be returned if that
+		 * requirement is not met.
+		 *
+		 * That said, we could simply reuse all cap pointers
+		 * (such as dev_cfg, common_cfg, etc.) parsed from the
+		 * primary process, which is stored in shared memory.
+		 */
+		if (rte_eal_pci_map_device(pci_dev)) {
+			PMD_INIT_LOG(DEBUG, "failed to map pci device!");
+			return -1;
+		}
+	} else {
+		if (rte_eal_pci_ioport_map(pci_dev, 0, VTPCI_IO(hw)) < 0)
+			return -1;
+	}
+
+	return 0;
+}
+
+static void
+virtio_set_vtpci_ops(struct virtio_hw *hw)
+{
+	if (hw->virtio_user_dev)
+		VTPCI_OPS(hw) = &virtio_user_ops;
+	else if (hw->modern)
+		VTPCI_OPS(hw) = &modern_ops;
+	else
+		VTPCI_OPS(hw) = &legacy_ops;
+}
+
+/*
  * This function is based on probe() function in virtio_pci.c
  * It returns 0 on success.
  */
@@ -1308,6 +1351,13 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->tx_pkt_burst = &virtio_xmit_pkts;
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
+		if (!hw->virtio_user_dev) {
+			ret = virtio_remap_pci(eth_dev->pci_dev, hw);
+			if (ret)
+				return ret;
+		}
+
+		virtio_set_vtpci_ops(hw);
 		if (hw->use_simple_rxtx) {
 			eth_dev->tx_pkt_burst = virtio_xmit_pkts_simple;
 			eth_dev->rx_pkt_burst = virtio_recv_pkts_vec;
diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c
index 7903e29..8d5355c 100644
--- a/drivers/net/virtio/virtio_pci.c
+++ b/drivers/net/virtio/virtio_pci.c
@@ -304,7 +304,7 @@ legacy_virtio_resource_init(struct rte_pci_device *pci_dev,
 	return 0;
 }
 
-static const struct virtio_pci_ops legacy_ops = {
+const struct virtio_pci_ops legacy_ops = {
 	.read_dev_cfg	= legacy_read_dev_config,
 	.write_dev_cfg	= legacy_write_dev_config,
 	.reset		= legacy_reset,
@@ -520,7 +520,7 @@ modern_notify_queue(struct virtio_hw *hw __rte_unused, struct virtqueue *vq)
 	io_write16(1, vq->notify_addr);
 }
 
-static const struct virtio_pci_ops modern_ops = {
+const struct virtio_pci_ops modern_ops = {
 	.read_dev_cfg	= modern_read_dev_config,
 	.write_dev_cfg	= modern_write_dev_config,
 	.reset		= modern_reset,
diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h
index 6b9aecf..511a1c8 100644
--- a/drivers/net/virtio/virtio_pci.h
+++ b/drivers/net/virtio/virtio_pci.h
@@ -333,4 +333,8 @@ uint8_t vtpci_isr(struct virtio_hw *);
 
 uint16_t vtpci_irq_config(struct virtio_hw *, uint16_t);
 
+extern const struct virtio_pci_ops legacy_ops;
+extern const struct virtio_pci_ops modern_ops;
+extern const struct virtio_pci_ops virtio_user_ops;
+
 #endif /* _VIRTIO_PCI_H_ */
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index d69d8fa..013600e 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -216,7 +216,7 @@ virtio_user_notify_queue(struct virtio_hw *hw, struct virtqueue *vq)
 			    strerror(errno));
 }
 
-static const struct virtio_pci_ops virtio_user_ops = {
+const struct virtio_pci_ops virtio_user_ops = {
 	.read_dev_cfg	= virtio_user_read_dev_config,
 	.write_dev_cfg	= virtio_user_write_dev_config,
 	.reset		= virtio_user_reset,
-- 
1.9.0

  parent reply	other threads:[~2017-02-15  6:25 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-15  6:26 [dpdk-stable] patch 'devargs: reset driver name pointer on parsing failure' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'vhost: fix dead loop in enqueue path' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'vhost: fix long stall of negotiation' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'vhost: do not GSO when no header is present' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/virtio: fix performance regression due to TSO' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/virtio: optimize header reset on any layout' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/i40e: fix Rx checksum flag' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/mlx5: fix memory leak when parsing device params' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/qede/base: fix FreeBSD build' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/i40e: fix deletion of all macvlan filters' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/bnx2x: fix Rx mode configuration' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/cxgbe/base: initialize variable before reading EEPROM' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/i40e: fix checksum flag in x86 vector Rx' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/i40e: fix crash in close' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'vfio: fix file descriptor leak in multi-process' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'sched: fix crash when freeing port' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/enic: fix memory leak with oversized Tx packets' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/ena: fix setting host attributes' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/i40e: fix ethertype filter on X722' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/i40evf: fix reporting of imissed packets' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/i40e: fix link update delay' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/enic: fix hardcoding of some flow director masks' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/ixgbe: fix received packets number for ARM' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/ixgbe: fix received packets number for ARM NEON' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/i40e: fix TC bandwidth definition' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'drivers/crypto: fix different auth/cipher keys' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'examples/l2fwd-crypto: fix overflow' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'examples/l2fwd-crypto: fix padding' " Yuanhan Liu
2017-02-16  8:01   ` Yuanhan Liu
2017-02-16  9:10     ` De Lara Guarch, Pablo
2017-02-17  7:44       ` Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'vhost: allow many vhost-user ports' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'mempool: fix stack handler dequeue' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'ethdev: fix port data mismatched in multiple process model' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/virtio: fix wrong Rx/Tx method for secondary process' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/virtio: store PCI operators pointer locally' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/virtio: store IO port info " Yuanhan Liu
2017-02-15  6:26 ` Yuanhan Liu [this message]
2017-02-15  6:26 ` [dpdk-stable] patch 'net/virtio: fix build without virtio-user' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/virtio: fix crash when number of virtio devices > 1' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'usertools: fix active interface detection when binding' " Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/vhost: fix unix socket not removed as closing' " Yuanhan Liu
2017-02-15  7:22   ` Tan, Jianfeng
2017-02-15  7:28     ` Yuanhan Liu
2017-02-15  6:26 ` [dpdk-stable] patch 'net/ixgbevf: fix max packet length' " Yuanhan Liu

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=1487140012-13314-35-git-send-email-yuanhan.liu@linux.intel.com \
    --to=yuanhan.liu@linux.intel.com \
    --cc=jsnell@iki.fi \
    --cc=stable@dpdk.org \
    --cc=yaroni@radcom.com \
    /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).