[dpdk-dev] net/virtio-user: fix recognize physical devices

Message ID 1492741689-40422-1-git-send-email-jianfeng.tan@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Yuanhan Liu
Headers

Checks

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

Commit Message

Jianfeng Tan April 21, 2017, 2:28 a.m. UTC
  Segfault happens when using virtio-user after commit 7f0a669e7b04
("ethdev: add allocation helper for virtual drivers").

It's due to we use ethdev->device to recognize physical devices,
but after above commit, this field is also filled for virtual
devices. Then we obtain the wrong pci_dev pointer and accessing
its field when copying pci info results in segfault.

To fix it, we use hw->virtio_user_dev to differentiate physical
devices from virtual devices.

Fixes: 6a7c0dfcdf40 ("net/virtio: do not depend on PCI device of ethdev")

Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 drivers/net/virtio/virtio_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Yuanhan Liu April 26, 2017, 1:26 a.m. UTC | #1
On Fri, Apr 21, 2017 at 02:28:09AM +0000, Jianfeng Tan wrote:
> Segfault happens when using virtio-user after commit 7f0a669e7b04
> ("ethdev: add allocation helper for virtual drivers").
> 
> It's due to we use ethdev->device to recognize physical devices,
> but after above commit, this field is also filled for virtual
> devices. Then we obtain the wrong pci_dev pointer and accessing
> its field when copying pci info results in segfault.
> 
> To fix it, we use hw->virtio_user_dev to differentiate physical
> devices from virtual devices.
> 
> Fixes: 6a7c0dfcdf40 ("net/virtio: do not depend on PCI device of ethdev")
> 
> Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>

Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>

	--yliu
  
Yuanhan Liu April 28, 2017, 4:49 a.m. UTC | #2
On Fri, Apr 21, 2017 at 02:28:09AM +0000, Jianfeng Tan wrote:
> Segfault happens when using virtio-user after commit 7f0a669e7b04
> ("ethdev: add allocation helper for virtual drivers").
> 
> It's due to we use ethdev->device to recognize physical devices,
> but after above commit, this field is also filled for virtual
> devices. Then we obtain the wrong pci_dev pointer and accessing
> its field when copying pci info results in segfault.
> 
> To fix it, we use hw->virtio_user_dev to differentiate physical
> devices from virtual devices.
> 
> Fixes: 6a7c0dfcdf40 ("net/virtio: do not depend on PCI device of ethdev")
> 
> Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>

Applied to dpdk-next-virtio.

Thanks.

	--yliu
  

Patch

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index e6c57b3..3d712bd 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1348,7 +1348,7 @@  virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	if (virtio_negotiate_features(hw, req_features) < 0)
 		return -1;
 
-	if (eth_dev->device) {
+	if (!hw->virtio_user_dev) {
 		pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
 		rte_eth_copy_pci_info(eth_dev, pci_dev);
 	}