Skip to contentSkip to conversation

vdpa/mlx5: set_features should allow reset to zero

PATCH In review Si-Wei Liu 5 participants 91 messages Feb 19, 2021 – Dec 17, 2021

Subsystems (4)
lore
Share & tools
lore

Si-Wei Liu

author
#0 lore raw

PATCH 1/1 vdpa/mlx5: set_features should allow reset to zero

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set. Rejecting reset to 0 prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -14
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev)
 	return mvdev->mlx_features;
 }
 
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 features)
-{
-	if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-
 static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
 {
 	int err;
@@ -1558,18 +1550,13 @@ static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
 {
 	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
 	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-	int err;
 
 	print_features(mvdev, features, true);
 
-	err = verify_min_features(mvdev, features);
-	if (err)
-		return err;
-
 	ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
 	ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
 	ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-	return err;
+	return 0;
 }
 
 static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)
Signature · 6 lines
1.8.3.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#1 lore raw
Quoted 28 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set. Rejecting reset to 0 prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev)
 	return mvdev->mlx_features;

drivers/vdpa/mlx5/net/mlx5_vnet.c static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev) · line 1500

Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
 }
 
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 features)
-{
-	if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-

But what if VIRTIO_F_ACCESS_PLATFORM is not offerred? This does not support such cases.

Maybe we should call verify_min_features() from mlx5_vdpa_set_status() just before attempting to call setup_driver().

Quoted 26 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -6
 static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
 {
 	int err;
@@ -1558,18 +1550,13 @@ static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
 {
 	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
 	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-	int err;
 
 	print_features(mvdev, features, true);
 
-	err = verify_min_features(mvdev, features);
-	if (err)
-		return err;
-
 	ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
 	ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
 	ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-	return err;
+	return 0;
 }
 
 static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)
Signature · 1 line
1.8.3.1
#2 lore raw
Quoted 31 lines · Eli Cohen
Quoted 30 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set. Rejecting reset to 0 prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev)
 	return mvdev->mlx_features;
 }
 
Quoted 11 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev) · line 1500

Quoted 8 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 features)
-{
-	if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-

But what if VIRTIO_F_ACCESS_PLATFORM is not offerred? This does not support such cases.

Did you mean "catch such cases" rather than "support"?

Quoted 25 lines

Maybe we should call verify_min_features() from mlx5_vdpa_set_status() just before attempting to call setup_driver().

Quoted 22 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -6
 static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
 {
 	int err;
@@ -1558,18 +1550,13 @@ static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
 {
 	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
 	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-	int err;
 
 	print_features(mvdev, features, true);
 
-	err = verify_min_features(mvdev, features);
-	if (err)
-		return err;
-
 	ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
 	ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
 	ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-	return err;
+	return 0;
 }
 
Quoted 4 lines
Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
 static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)
Signature · 1 line
1.8.3.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#3 lore raw
Quoted 44 lines · Michael S. Tsirkin
Quoted 31 lines · Eli Cohen
Quoted 30 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set. Rejecting reset to 0 prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev)
 	return mvdev->mlx_features;
 }
 
Quoted 11 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev) · line 1500

Quoted 8 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 features)
-{
-	if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-

But what if VIRTIO_F_ACCESS_PLATFORM is not offerred? This does not support such cases.

Quoted 2 lines

Did you mean "catch such cases" rather than "support"?

Actually I meant this driver/device does not support such cases.

Quoted 31 lines
Quoted 30 lines

Maybe we should call verify_min_features() from mlx5_vdpa_set_status() just before attempting to call setup_driver().

Quoted 26 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -6
 static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
 {
 	int err;
@@ -1558,18 +1550,13 @@ static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
 {
 	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
 	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-	int err;
 
 	print_features(mvdev, features, true);
 
-	err = verify_min_features(mvdev, features);
-	if (err)
-		return err;
-
 	ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
 	ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
 	ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-	return err;
+	return 0;
 }
 
 static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)
Signature · 1 line
1.8.3.1
#4 lore raw
Quoted 45 lines · Eli Cohen
Quoted 44 lines · Michael S. Tsirkin
Quoted 42 lines · Eli Cohen
Quoted 28 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set. Rejecting reset to 0 prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev)
 	return mvdev->mlx_features;

drivers/vdpa/mlx5/net/mlx5_vnet.c static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev) · line 1500

Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
 }
 
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 features)
-{
-	if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-

But what if VIRTIO_F_ACCESS_PLATFORM is not offerred? This does not support such cases.

Quoted 4 lines
Quoted 2 lines

Did you mean "catch such cases" rather than "support"?

Actually I meant this driver/device does not support such cases.

Well the removed code merely failed without VIRTIO_F_ACCESS_PLATFORM it didn't actually try to support anything ...

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines

Maybe we should call verify_min_features() from mlx5_vdpa_set_status() just before attempting to call setup_driver().

Quoted 22 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -6
 static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
 {
 	int err;
@@ -1558,18 +1550,13 @@ static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
 {
 	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
 	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-	int err;
 
 	print_features(mvdev, features, true);
 
-	err = verify_min_features(mvdev, features);
-	if (err)
-		return err;
-
 	ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
 	ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
 	ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-	return err;
+	return 0;
 }
 
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
 static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)
Signature · 1 line
1.8.3.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#5 lore raw
Quoted 44 lines · Michael S. Tsirkin
Quoted 43 lines · Eli Cohen
Quoted 42 lines · Michael S. Tsirkin
Quoted 41 lines · Eli Cohen
Quoted 28 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set. Rejecting reset to 0 prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
  1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev)
  	return mvdev->mlx_features;

drivers/vdpa/mlx5/net/mlx5_vnet.c static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev) · line 1500

Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
  }
 
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 features)
-{
-	if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-

But what if VIRTIO_F_ACCESS_PLATFORM is not offerred? This does not support such cases.

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

Did you mean "catch such cases" rather than "support"?

Actually I meant this driver/device does not support such cases.

Well the removed code merely failed without VIRTIO_F_ACCESS_PLATFORM it didn't actually try to support anything ...

I think it's used to catch the driver that doesn't support ACCESS_PLATFORM?

Thanks

Quoted 1 line

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#6 lore raw
Quoted 47 lines · Jason Wang
Quoted 45 lines · Michael S. Tsirkin
Quoted 44 lines · Eli Cohen
Quoted 43 lines · Michael S. Tsirkin
Quoted 32 lines · Eli Cohen
Quoted 31 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set. Rejecting reset to 0 prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
  1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -2
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev)
  	return mvdev->mlx_features;
  }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 features)
-{
Quoted 8 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev) · line 1500

Quoted 6 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -6
-	if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-

But what if VIRTIO_F_ACCESS_PLATFORM is not offerred? This does not support such cases.

Did you mean "catch such cases" rather than "support"?

Quoted 9 lines
Quoted 3 lines
Quoted 1 line

Actually I meant this driver/device does not support such cases.

Well the removed code merely failed without VIRTIO_F_ACCESS_PLATFORM it didn't actually try to support anything ...

I think it's used to catch the driver that doesn't support ACCESS_PLATFORM?

Thanks

That is why I asked whether Eli meant catch.

Signature · 6 lines
MST

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#7 lore raw
In reply to Si-Wei Liu
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use. "

Do we really want to workaround this?

Thanks

Quoted 41 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
  1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -11
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev)
  	return mvdev->mlx_features;
  }
 
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 features)
-{
-	if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-
  static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
  {
  	int err;
@@ -1558,18 +1550,13 @@ static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
  {
  	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
  	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-	int err;
 
  	print_features(mvdev, features, true);
 
-	err = verify_min_features(mvdev, features);
-	if (err)

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features) · line 1562

Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -3
-		return err;
-
  	ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
  	ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
  	ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-	return err;
+	return 0;
  }
 
  static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#8 lore raw
Quoted 19 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

Quoted 8 lines

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set.
This field specifies the maximum MTU for the driver to use.
"

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

so accessing config space before FEATURES_OK is a spec violation, right?

Quoted 40 lines
Quoted 40 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
  1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -12
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev)
  	return mvdev->mlx_features;
  }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 features)
-{
-	if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-
  static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
  {
  	int err;
@@ -1558,18 +1550,13 @@ static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
  {
  	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
  	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-	int err;
  	print_features(mvdev, features, true);
-	err = verify_min_features(mvdev, features);
-	if (err)
-		return err;
Quoted 8 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features) · line 1562

Quoted 8 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -2
-
  	ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
  	ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
  	ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-	return err;
+	return 0;
  }
  static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#9 lore raw
Quoted 43 lines · Michael S. Tsirkin
Quoted 17 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

Quoted 8 lines

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set.
This field specifies the maximum MTU for the driver to use.
"

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 1 line

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since commit fe36cbe067). But it's not technically related to this patch.

-Siwei

Quoted 41 lines
Quoted 41 lines
Quoted 41 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
---
   drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
   1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -12
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev)
   	return mvdev->mlx_features;
   }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 features)
-{
-	if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-
   static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
   {
   	int err;
@@ -1558,18 +1550,13 @@ static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
   {
   	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
   	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-	int err;
   	print_features(mvdev, features, true);
-	err = verify_min_features(mvdev, features);
-	if (err)
-		return err;
Quoted 8 lines
Quoted 8 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features) · line 1562

Quoted 8 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -2
-
   	ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
   	ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
   	ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-	return err;
+	return 0;
   }
   static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#10 lore raw
Quoted 46 lines · Si-Wei Liu
Quoted 43 lines · Michael S. Tsirkin
Quoted 17 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

Quoted 8 lines

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set.
This field specifies the maximum MTU for the driver to use.
"

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 6 lines
Quoted 1 line

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since commit fe36cbe067). But it's not technically related to this patch.

-Siwei

I think it's a bug to read config space in validate, we should move it to virtnet_probe().

Thanks

Quoted 45 lines
Quoted 45 lines
Quoted 45 lines
Quoted 45 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")

---
   drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------

   1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64 mlx5_vdpa_get_features(struct 
 vdpa_device *vdev)
        return mvdev->mlx_features;
    }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 
 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
    static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
    {

       int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -4
@@ -1558,18 +1550,13 @@ static int mlx5_vdpa_set_features(struct 
 vdpa_device *vdev, u64 features)
    {
        struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
        struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-    int err;
        print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features) · line 1562

Quoted 8 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -2
-
        ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
        ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
        ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
    }
    static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#11 lore raw
Quoted 64 lines · Jason Wang
Quoted 62 lines · Si-Wei Liu
Quoted 51 lines · Michael S. Tsirkin
Quoted 23 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 1 line

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since commit fe36cbe067). But it's not technically related to this patch.

Quoted 7 lines
Quoted 1 line

-Siwei

I think it's a bug to read config space in validate, we should move it to virtnet_probe().

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec. So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Quoted 53 lines
Quoted 53 lines
Quoted 53 lines
Quoted 53 lines
Quoted 53 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
   drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------

   1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
        return mvdev->mlx_features;
    }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
    static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
    {

       int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
   {
       struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); -    int err;
       print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
       ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
       ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

       ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
   }
   static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#12 lore raw
Quoted 64 lines · Michael S. Tsirkin
Quoted 63 lines · Jason Wang
Quoted 61 lines · Si-Wei Liu
Quoted 50 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 1 line

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since commit fe36cbe067). But it's not technically related to this patch.

-Siwei

Quoted 7 lines
Quoted 4 lines

I think it's a bug to read config space in validate, we should move it to virtnet_probe().

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec. So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

-Siwie

Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
    drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
    1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
        return mvdev->mlx_features;
    }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
    static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
    {

       int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
   {
       struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-    int err;
       print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
       ndev->mvdev.actual_features = features &
ndev->mvdev.mlx_features;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

       ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu); ndev->config.status |= cpu_to_mlx5vdpa16(mvdev,
VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
   }
   static void mlx5_vdpa_set_config_cb(struct vdpa_device
*vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#13 lore raw
Quoted 67 lines · Si-Wei Liu
Quoted 64 lines · Michael S. Tsirkin
Quoted 63 lines · Jason Wang
Quoted 61 lines · Si-Wei Liu
Quoted 50 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 1 line

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since commit fe36cbe067). But it's not technically related to this patch.

-Siwei

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

I think it's a bug to read config space in validate, we should move it to virtnet_probe().

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec. So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

I agree. My understanding is that all vDPA must be modern device (since VIRITO_F_ACCESS_PLATFORM is mandated) instead of transitional device.

Thanks

Quoted 52 lines

-Siwie

Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
    drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------

    1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
         return mvdev->mlx_features;
     }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
     static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
     {

        int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
    {
        struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); -    int err;
        print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
        ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

        ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu); ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
    }
    static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#14 lore raw
Quoted 86 lines · Jason Wang
Quoted 74 lines · Si-Wei Liu
Quoted 71 lines · Michael S. Tsirkin
Quoted 70 lines · Jason Wang
Quoted 58 lines · Si-Wei Liu
Quoted 51 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 2 lines

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Quoted 6 lines

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since
commit fe36cbe067). But it's not technically related to this patch.

-Siwei

I think it's a bug to read config space in validate, we should move it to
virtnet_probe().

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec.
So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

Quoted 4 lines

I agree. My understanding is that all vDPA must be modern device (since VIRITO_F_ACCESS_PLATFORM is mandated) instead of transitional device.

Thanks

Well mlx5 has some code to handle legacy guests ... Eli, could you comment? Is that support unused right now?

Quoted 54 lines
Quoted 54 lines

-Siwie

Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
    drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------

    1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
         return mvdev->mlx_features;
     }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
     static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
     {

        int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
    {
        struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); -    int err;
        print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
        ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
        ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

        ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
    }
    static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#15 lore raw
Quoted 82 lines · Michael S. Tsirkin
Quoted 81 lines · Jason Wang
Quoted 79 lines · Si-Wei Liu
Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Jason Wang
Quoted 57 lines · Si-Wei Liu
Quoted 51 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 2 lines

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Quoted 6 lines

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since
commit fe36cbe067). But it's not technically related to this patch.

-Siwei

I think it's a bug to read config space in validate, we should move it to
virtnet_probe().

Quoted 5 lines
Quoted 1 line

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec.
So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

Quoted 5 lines
Quoted 4 lines

I agree. My understanding is that all vDPA must be modern device (since VIRITO_F_ACCESS_PLATFORM is mandated) instead of transitional device.

Thanks

Well mlx5 has some code to handle legacy guests ...

My understanding is that, even if mlx5 is modern device it can still suppot legacy guests since the device saw by guest is emulated by Qemu. Qemu can just present a transitional device to guest, but negotiate VIRTIO_F_ACCESS_PLATFORM. (Actually this is what has been done now).

Thanks

Quoted 53 lines

Eli, could you comment? Is that support unused right now?

Quoted 50 lines
Quoted 50 lines

-Siwie

Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
     drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
     1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
         return mvdev->mlx_features;
     }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
     static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
     {

        int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
    {
        struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-    int err;
        print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
        ndev->mvdev.actual_features = features &
ndev->mvdev.mlx_features;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

        ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu); ndev->config.status |= cpu_to_mlx5vdpa16(mvdev,
VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
    }
    static void mlx5_vdpa_set_config_cb(struct vdpa_device
*vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#16 lore raw
In reply to Michael S. Tsirkin
Quoted 87 lines · Michael S. Tsirkin
Quoted 86 lines · Jason Wang
Quoted 82 lines · Si-Wei Liu
Quoted 71 lines · Michael S. Tsirkin
Quoted 70 lines · Jason Wang
Quoted 58 lines · Si-Wei Liu
Quoted 51 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 2 lines

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Quoted 6 lines

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since
commit fe36cbe067). But it's not technically related to this patch.

-Siwei

I think it's a bug to read config space in validate, we should move it to
virtnet_probe().

Quoted 5 lines
Quoted 1 line

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec.
So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

Quoted 8 lines
Quoted 4 lines

I agree. My understanding is that all vDPA must be modern device (since VIRITO_F_ACCESS_PLATFORM is mandated) instead of transitional device.

Thanks

Well mlx5 has some code to handle legacy guests ... Eli, could you comment? Is that support unused right now?

If you mean support for version 1.0, well the knob is there but it's not set in the firmware I use. Note sure if we will support this.

Quoted 64 lines
Quoted 63 lines
Quoted 63 lines

-Siwie

Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
    drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------

    1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
         return mvdev->mlx_features;
     }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
     static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
     {

        int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
    {
        struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); -    int err;
        print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
        ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
        ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu); ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
    }
    static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)

#17 lore raw
Quoted 91 lines · Eli Cohen
Quoted 90 lines · Michael S. Tsirkin
Quoted 89 lines · Jason Wang
Quoted 74 lines · Si-Wei Liu
Quoted 71 lines · Michael S. Tsirkin
Quoted 70 lines · Jason Wang
Quoted 58 lines · Si-Wei Liu
Quoted 51 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 2 lines

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Quoted 6 lines

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since
commit fe36cbe067). But it's not technically related to this patch.

-Siwei

I think it's a bug to read config space in validate, we should move it to
virtnet_probe().

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec.
So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

I agree. My understanding is that all vDPA must be modern device (since VIRITO_F_ACCESS_PLATFORM is mandated) instead of transitional device.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Thanks

Well mlx5 has some code to handle legacy guests ... Eli, could you comment? Is that support unused right now?

If you mean support for version 1.0, well the knob is there but it's not set in the firmware I use. Note sure if we will support this.

Hmm you mean it's legacy only right now?
Well at some point you will want advanced goodies like RSS and all that is gated on 1.0 ;)

Quoted 56 lines
Quoted 56 lines
Quoted 56 lines
Quoted 56 lines

-Siwie

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
    drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------

    1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
         return mvdev->mlx_features;
     }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
     static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
     {

        int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
    {
        struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); -    int err;
        print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
        ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
        ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu); ndev->config.status |= cpu_to_mlx5vdpa16(mvdev,

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
    }
    static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#18 lore raw
Quoted 88 lines · Michael S. Tsirkin
Quoted 87 lines · Eli Cohen
Quoted 86 lines · Michael S. Tsirkin
Quoted 85 lines · Jason Wang
Quoted 71 lines · Si-Wei Liu
Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Jason Wang
Quoted 57 lines · Si-Wei Liu
Quoted 51 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 2 lines

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Quoted 6 lines

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since
commit fe36cbe067). But it's not technically related to this patch.

-Siwei

I think it's a bug to read config space in validate, we should move it to
virtnet_probe().

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec.
So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

I agree. My understanding is that all vDPA must be modern device (since VIRITO_F_ACCESS_PLATFORM is mandated) instead of transitional device.

Thanks

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Well mlx5 has some code to handle legacy guests ... Eli, could you comment? Is that support unused right now?

If you mean support for version 1.0, well the knob is there but it's not set in the firmware I use. Note sure if we will support this.

Hmm you mean it's legacy only right now?
Well at some point you will want advanced goodies like RSS and all that is gated on 1.0 ;)

So if my understanding is correct the device/firmware is legacy but require VIRTIO_F_ACCESS_PLATFORM semanic? Looks like a spec violation?

Thanks

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines

-Siwie

Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
     drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
     1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
         return mvdev->mlx_features;
     }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
     static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
     {

        int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
    {
        struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-    int err;
        print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
        ndev->mvdev.actual_features = features &
ndev->mvdev.mlx_features;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

        ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu); ndev->config.status |= cpu_to_mlx5vdpa16(mvdev,
VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
    }
    static void mlx5_vdpa_set_config_cb(struct vdpa_device
*vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#19 lore raw
Quoted 100 lines · Jason Wang
Quoted 88 lines · Michael S. Tsirkin
Quoted 87 lines · Eli Cohen
Quoted 86 lines · Michael S. Tsirkin
Quoted 85 lines · Jason Wang
Quoted 71 lines · Si-Wei Liu
Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Jason Wang
Quoted 57 lines · Si-Wei Liu
Quoted 51 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 2 lines

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Quoted 6 lines

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since
commit fe36cbe067). But it's not technically related to this patch.

-Siwei

I think it's a bug to read config space in validate, we should move it to
virtnet_probe().

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec.
So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

I agree. My understanding is that all vDPA must be modern device (since VIRITO_F_ACCESS_PLATFORM is mandated) instead of transitional device.

Thanks

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Well mlx5 has some code to handle legacy guests ... Eli, could you comment? Is that support unused right now?

If you mean support for version 1.0, well the knob is there but it's not set in the firmware I use. Note sure if we will support this.

Hmm you mean it's legacy only right now?
Well at some point you will want advanced goodies like RSS and all that is gated on 1.0 ;)

Quoted 4 lines

So if my understanding is correct the device/firmware is legacy but require VIRTIO_F_ACCESS_PLATFORM semanic? Looks like a spec violation?

Thanks

Legacy mode description is the spec is non-normative. As such as long as guests work, they work ;)

Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines

-Siwie

Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
     drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
     1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
         return mvdev->mlx_features;
     }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
     static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
     {

        int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
    {
        struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-    int err;
        print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
        ndev->mvdev.actual_features = features &
ndev->mvdev.mlx_features;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

        ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu); ndev->config.status |= cpu_to_mlx5vdpa16(mvdev,
VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
    }
    static void mlx5_vdpa_set_config_cb(struct vdpa_device
*vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#20 lore raw
Quoted 94 lines · Michael S. Tsirkin
Quoted 93 lines · Jason Wang
Quoted 91 lines · Michael S. Tsirkin
Quoted 90 lines · Eli Cohen
Quoted 89 lines · Michael S. Tsirkin
Quoted 77 lines · Jason Wang
Quoted 76 lines · Si-Wei Liu
Quoted 74 lines · Michael S. Tsirkin
Quoted 63 lines · Jason Wang
Quoted 62 lines · Si-Wei Liu
Quoted 51 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked
for legacy") made an exception for legacy guests to reset
features to 0, when config space is accessed before features
are set. We should relieve the verify_min_features() check
and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access
config space before features are set. For instance, when
feature VIRTIO_NET_F_MTU is advertised some modern driver
will try to access and validate the MTU present in the config
space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 2 lines

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since
commit fe36cbe067). But it's not technically related to this patch.

Quoted 6 lines
Quoted 1 line

-Siwei

I think it's a bug to read config space in validate, we should move it to
virtnet_probe().

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec.
So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Quoted 8 lines
Quoted 3 lines

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

I agree. My understanding is that all vDPA must be modern device (since VIRITO_F_ACCESS_PLATFORM is mandated) instead of transitional device.

Thanks

Well mlx5 has some code to handle legacy guests ... Eli, could you comment? Is that support unused right now?

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

If you mean support for version 1.0, well the knob is there but it's not set in the firmware I use. Note sure if we will support this.

Hmm you mean it's legacy only right now?
Well at some point you will want advanced goodies like RSS and all that is gated on 1.0 ;)

Guys sorry, I checked again, the firmware capability is set and so is VIRTIO_F_VERSION_1.

Quoted 70 lines
Quoted 5 lines

So if my understanding is correct the device/firmware is legacy but require VIRTIO_F_ACCESS_PLATFORM semanic? Looks like a spec violation?

Thanks

Legacy mode description is the spec is non-normative. As such as long as guests work, they work ;)

Quoted 60 lines
Quoted 60 lines
Quoted 60 lines
Quoted 60 lines
Quoted 60 lines
Quoted 60 lines

-Siwie

Quoted 56 lines
Quoted 56 lines
Quoted 56 lines
Quoted 56 lines
Quoted 56 lines
Quoted 56 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load
for the very first config space access, rendering issues like
guest showing inaccurate MTU value, or failure to reject
out-of-range MTU.

Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for
supported mlx5 devices")
Signed-off-by: Si-Wei Liu <[email protected]>
---
    drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
    1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c
b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 7c1f789..540dd67 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -1490,14 +1490,6 @@ static u64
mlx5_vdpa_get_features(struct vdpa_device *vdev)
        return mvdev->mlx_features;
    }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
    static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
    {
        int err;
@@ -1558,18 +1550,13 @@ static int
mlx5_vdpa_set_features(struct vdpa_device *vdev, u64
features)
    {
        struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
        struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-    int err;
        print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
        ndev->mvdev.actual_features = features &
ndev->mvdev.mlx_features;
        ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
        ndev->config.status |= cpu_to_mlx5vdpa16(mvdev,
VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
    }
    static void mlx5_vdpa_set_config_cb(struct vdpa_device
*vdev, struct vdpa_callback *cb)

#21 lore raw
In reply to Jason Wang
Quoted 95 lines · Jason Wang
Quoted 93 lines · Michael S. Tsirkin
Quoted 92 lines · Eli Cohen
Quoted 82 lines · Michael S. Tsirkin
Quoted 81 lines · Jason Wang
Quoted 79 lines · Si-Wei Liu
Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Jason Wang
Quoted 57 lines · Si-Wei Liu
Quoted 51 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 2 lines

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Quoted 6 lines

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since
commit fe36cbe067). But it's not technically related to this patch.

-Siwei

I think it's a bug to read config space in validate, we should move it to
virtnet_probe().

Quoted 5 lines
Quoted 1 line

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec.
So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

Quoted 7 lines
Quoted 4 lines

I agree. My understanding is that all vDPA must be modern device (since VIRITO_F_ACCESS_PLATFORM is mandated) instead of transitional device.

Thanks

Well mlx5 has some code to handle legacy guests ... Eli, could you comment? Is that support unused right now?

If you mean support for version 1.0, well the knob is there but it's not set in the firmware I use. Note sure if we will support this.

Quoted 8 lines
Quoted 3 lines

Hmm you mean it's legacy only right now?
Well at some point you will want advanced goodies like RSS and all that is gated on 1.0 ;)

So if my understanding is correct the device/firmware is legacy but require VIRTIO_F_ACCESS_PLATFORM semanic? Looks like a spec violation?

I am checking this with some folks here.

Quoted 63 lines

Thanks

Quoted 59 lines
Quoted 59 lines
Quoted 59 lines
Quoted 59 lines
Quoted 59 lines

-Siwie

Quoted 56 lines
Quoted 56 lines
Quoted 56 lines
Quoted 56 lines
Quoted 56 lines
Quoted 56 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
     drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
     1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
         return mvdev->mlx_features;
     }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
     static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
     {

        int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
    {
        struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-    int err;
        print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
        ndev->mvdev.actual_features = features &
ndev->mvdev.mlx_features;
        ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu); ndev->config.status |= cpu_to_mlx5vdpa16(mvdev,
VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
    }
    static void mlx5_vdpa_set_config_cb(struct vdpa_device
*vdev, struct vdpa_callback *cb)

#22 lore raw
In reply to Si-Wei Liu
Quoted 71 lines · Si-Wei Liu
Quoted 68 lines · Michael S. Tsirkin
Quoted 67 lines · Jason Wang
Quoted 53 lines · Si-Wei Liu
Quoted 50 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 1 line

so accessing config space before FEATURES_OK is a spec violation, right?

Quoted 8 lines

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since commit fe36cbe067). But it's not technically related to this patch.

-Siwei

I think it's a bug to read config space in validate, we should move it to virtnet_probe().

Thanks

Quoted 8 lines
Quoted 3 lines

I take it back, reading but not writing seems to be explicitly allowed by spec. So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

-Siwie

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
    drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
    1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
        return mvdev->mlx_features;
    }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
    static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
    {

       int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
   {
       struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-    int err;
       print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
       ndev->mvdev.actual_features = features &
ndev->mvdev.mlx_features;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

       ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu); ndev->config.status |= cpu_to_mlx5vdpa16(mvdev,
VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
   }
   static void mlx5_vdpa_set_config_cb(struct vdpa_device
*vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#23 lore raw
Quoted 72 lines · Michael S. Tsirkin
Quoted 71 lines · Si-Wei Liu
Quoted 69 lines · Michael S. Tsirkin
Quoted 60 lines · Jason Wang
Quoted 59 lines · Si-Wei Liu
Quoted 50 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 1 line

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since commit fe36cbe067). But it's not technically related to this patch.

Quoted 5 lines
Quoted 1 line

-Siwei

I think it's a bug to read config space in validate, we should move it to virtnet_probe().

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec. So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Quoted 7 lines
Quoted 5 lines

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

-Siwie

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

I'm not sure I get this, how can we know if there's a legacy driver before set_features()?

And I wonder what will hapeen if we just revert the set_features(0)?

Thanks

Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
     drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
     1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
         return mvdev->mlx_features;
     }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
     static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
     {

       int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
   {
       struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-    int err;
       print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
       ndev->mvdev.actual_features = features &
ndev->mvdev.mlx_features;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

       ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu); ndev->config.status |= cpu_to_mlx5vdpa16(mvdev,
VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
   }
   static void mlx5_vdpa_set_config_cb(struct vdpa_device
*vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#24 lore raw
Quoted 78 lines · Jason Wang
Quoted 76 lines · Michael S. Tsirkin
Quoted 75 lines · Si-Wei Liu
Quoted 61 lines · Michael S. Tsirkin
Quoted 60 lines · Jason Wang
Quoted 59 lines · Si-Wei Liu
Quoted 50 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 1 line

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since commit fe36cbe067). But it's not technically related to this patch.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

-Siwei

I think it's a bug to read config space in validate, we should move it to virtnet_probe().

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec. So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

-Siwie

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

I'm not sure I get this, how can we know if there's a legacy driver before set_features()?

qemu knows for sure. It does not communicate this information to the kernel right now unfortunately.

Quoted 55 lines

And I wonder what will hapeen if we just revert the set_features(0)?

Thanks

Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
     drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
     1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
         return mvdev->mlx_features;
     }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
     static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
     {

       int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
   {
       struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-    int err;
       print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
       ndev->mvdev.actual_features = features &
ndev->mvdev.mlx_features;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

       ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu); ndev->config.status |= cpu_to_mlx5vdpa16(mvdev,
VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
   }
   static void mlx5_vdpa_set_config_cb(struct vdpa_device
*vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#25 lore raw
Quoted 77 lines · Michael S. Tsirkin
Quoted 76 lines · Jason Wang
Quoted 75 lines · Michael S. Tsirkin
Quoted 74 lines · Si-Wei Liu
Quoted 61 lines · Michael S. Tsirkin
Quoted 60 lines · Jason Wang
Quoted 59 lines · Si-Wei Liu
Quoted 50 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 1 line

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since commit fe36cbe067). But it's not technically related to this patch.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

-Siwei

I think it's a bug to read config space in validate, we should move it to virtnet_probe().

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec. So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

-Siwie

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

I'm not sure I get this, how can we know if there's a legacy driver before set_features()?

qemu knows for sure. It does not communicate this information to the kernel right now unfortunately.

I may miss something, but I still don't get how the new ioctl is supposed to work.

Thanks

Quoted 55 lines
Quoted 55 lines

And I wonder what will hapeen if we just revert the set_features(0)?

Thanks

Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
      drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
      1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
          return mvdev->mlx_features;
      }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
      static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
      {
          int err;
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)

      {
          struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
          struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-    int err;
          print_features(mvdev, features, true);

-    err = verify_min_features(mvdev, features); -    if (err)
-        return err;
-
       ndev->mvdev.actual_features = features &
ndev->mvdev.mlx_features;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
          ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
          ndev->config.status |= cpu_to_mlx5vdpa16(mvdev,

VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
   }
   static void mlx5_vdpa_set_config_cb(struct vdpa_device
*vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#26 lore raw
Quoted 85 lines · Jason Wang
Quoted 83 lines · Michael S. Tsirkin
Quoted 82 lines · Jason Wang
Quoted 71 lines · Michael S. Tsirkin
Quoted 70 lines · Si-Wei Liu
Quoted 69 lines · Michael S. Tsirkin
Quoted 60 lines · Jason Wang
Quoted 59 lines · Si-Wei Liu
Quoted 50 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 1 line

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since commit fe36cbe067). But it's not technically related to this patch.

Quoted 5 lines
Quoted 1 line

-Siwei

I think it's a bug to read config space in validate, we should move it to virtnet_probe().

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec. So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Quoted 7 lines
Quoted 5 lines

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

-Siwie

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

I'm not sure I get this, how can we know if there's a legacy driver before set_features()?

Quoted 8 lines
Quoted 2 lines

qemu knows for sure. It does not communicate this information to the kernel right now unfortunately.

I may miss something, but I still don't get how the new ioctl is supposed to work.

Thanks

Basically on first guest access QEMU would tell kernel whether
guest is using the legacy or the modern interface.
E.g. virtio_pci_config_read/virtio_pci_config_write will call ioctl(ENABLE_LEGACY, 1) while virtio_pci_common_read will call ioctl(ENABLE_LEGACY, 0)

Or maybe we just add GET_CONFIG_MODERN and GET_CONFIG_LEGACY and call the correct ioctl ... there are many ways to build this API.

Quoted 56 lines
Quoted 56 lines
Quoted 56 lines

And I wonder what will hapeen if we just revert the set_features(0)?

Thanks

Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
      drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
      1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
          return mvdev->mlx_features;
      }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
      static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
      {
          int err;
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)

      {
          struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
          struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-    int err;
          print_features(mvdev, features, true);

-    err = verify_min_features(mvdev, features); -    if (err)
-        return err;
-
       ndev->mvdev.actual_features = features &
ndev->mvdev.mlx_features;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
          ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
          ndev->config.status |= cpu_to_mlx5vdpa16(mvdev,

VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
   }
   static void mlx5_vdpa_set_config_cb(struct vdpa_device
*vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#27 lore raw
Quoted 89 lines · Michael S. Tsirkin
Quoted 88 lines · Jason Wang
Quoted 77 lines · Michael S. Tsirkin
Quoted 76 lines · Jason Wang
Quoted 75 lines · Michael S. Tsirkin
Quoted 74 lines · Si-Wei Liu
Quoted 61 lines · Michael S. Tsirkin
Quoted 60 lines · Jason Wang
Quoted 59 lines · Si-Wei Liu
Quoted 50 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 1 line

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since commit fe36cbe067). But it's not technically related to this patch.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

-Siwei

I think it's a bug to read config space in validate, we should move it to virtnet_probe().

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec. So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

-Siwie

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh:(

I'm not sure I get this, how can we know if there's a legacy driver before set_features()?

qemu knows for sure. It does not communicate this information to the kernel right now unfortunately.

I may miss something, but I still don't get how the new ioctl is supposed to work.

Quoted 6 lines
Quoted 1 line

Thanks

Basically on first guest access QEMU would tell kernel whether
guest is using the legacy or the modern interface.
E.g. virtio_pci_config_read/virtio_pci_config_write will call ioctl(ENABLE_LEGACY, 1) while virtio_pci_common_read will call ioctl(ENABLE_LEGACY, 0)

But this trick work only for PCI I think?

Thanks

Quoted 4 lines

Or maybe we just add GET_CONFIG_MODERN and GET_CONFIG_LEGACY and call the correct ioctl ... there are many ways to build this API.

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#28 lore raw
Quoted 9 lines · Jason Wang

Basically on first guest access QEMU would tell kernel whether
guest is using the legacy or the modern interface.
E.g. virtio_pci_config_read/virtio_pci_config_write will call ioctl(ENABLE_LEGACY, 1) while virtio_pci_common_read will call ioctl(ENABLE_LEGACY, 0)

But this trick work only for PCI I think?

Thanks

ccw has a revision it can check. mmio does not have transitional devices at all.

Signature · 6 lines
MST

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#29 lore raw
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Jason Wang

Basically on first guest access QEMU would tell kernel whether
guest is using the legacy or the modern interface.
E.g. virtio_pci_config_read/virtio_pci_config_write will call ioctl(ENABLE_LEGACY, 1) while virtio_pci_common_read will call ioctl(ENABLE_LEGACY, 0)

Quoted 5 lines
Quoted 3 lines

But this trick work only for PCI I think?

Thanks

ccw has a revision it can check. mmio does not have transitional devices at all.

Ok, then we can do the workaround in the qemu, isn't it?

Thanks

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#30 lore raw
Quoted 11 lines · Jason Wang
Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Jason Wang

Basically on first guest access QEMU would tell kernel whether
guest is using the legacy or the modern interface.
E.g. virtio_pci_config_read/virtio_pci_config_write will call ioctl(ENABLE_LEGACY, 1) while virtio_pci_common_read will call ioctl(ENABLE_LEGACY, 0)

But this trick work only for PCI I think?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Thanks

ccw has a revision it can check. mmio does not have transitional devices at all.

Ok, then we can do the workaround in the qemu, isn't it?

Thanks

which one do you mean?

Signature · 6 lines
MST

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#31 lore raw
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Jason Wang

Basically on first guest access QEMU would tell kernel whether
guest is using the legacy or the modern interface.
E.g. virtio_pci_config_read/virtio_pci_config_write will call ioctl(ENABLE_LEGACY, 1) while virtio_pci_common_read will call ioctl(ENABLE_LEGACY, 0)

But this trick work only for PCI I think?

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Thanks

ccw has a revision it can check. mmio does not have transitional devices at all.

Ok, then we can do the workaround in the qemu, isn't it?

Thanks

which one do you mean?

I meant the workaround that is done by 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy").

Thanks

Quoted 1 line

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#32 lore raw
In reply to Michael S. Tsirkin
Quoted 72 lines · Michael S. Tsirkin
Quoted 71 lines · Si-Wei Liu
Quoted 69 lines · Michael S. Tsirkin
Quoted 60 lines · Jason Wang
Quoted 59 lines · Si-Wei Liu
Quoted 50 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 1 line

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since commit fe36cbe067). But it's not technically related to this patch.

Quoted 5 lines
Quoted 1 line

-Siwei

I think it's a bug to read config space in validate, we should move it to virtnet_probe().

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec. So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Quoted 7 lines
Quoted 5 lines

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

-Siwie

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use case there will be for kernel to leverage such info directly? Is there a case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

One of the reason I asked is if this ioctl becomes a mandate for vhost-vdpa kernel. QEMU would reject initialize vhost-vdpa if doesn't see this ioctl coming?

If it's optional, suppose the kernel may need it only when it becomes necessary?

Thanks,
-Siwei

Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for

supported mlx5 devices")

---
     drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
     1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -8
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64
 mlx5_vdpa_get_features(struct vdpa_device *vdev)
         return mvdev->mlx_features;
     }
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev,
 u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
     static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
     {

       int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1558,18 +1550,13 @@ static int

mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
   {
       struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-    int err;
       print_features(mvdev, features, true);
-    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
       ndev->mvdev.actual_features = features &
ndev->mvdev.mlx_features;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

       ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu); ndev->config.status |= cpu_to_mlx5vdpa16(mvdev,
VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
   }
   static void mlx5_vdpa_set_config_cb(struct vdpa_device
*vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#33 lore raw

Hi Michael,

Are you okay to live without this ioctl for now? I think QEMU is the one that needs to be fixed and will have to be made legacy guest aware. I think the kernel can just honor the feature negotiation result done by QEMU and do as what's told to.Will you agree?

If it's fine, I would proceed to reverting commit fe36cbe067 and related code in question from the kernel.

Thanks,
-Siwei

Quoted 10 lines · Si-Wei Liu
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use case there will be for kernel to leverage such info directly? Is there a case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

One of the reason I asked is if this ioctl becomes a mandate for vhost-vdpa kernel. QEMU would reject initialize vhost-vdpa if doesn't see this ioctl coming?

If it's optional, suppose the kernel may need it only when it becomes necessary?

Thanks,
-Siwei

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#34 lore raw
In reply to Si-Wei Liu

Hi Michael,

Are you okay to live without this ioctl for now? I think QEMU is the one that needs to be fixed and will have to be made legacy guest aware. I think the kernel can just honor the feature negotiation result done by QEMU and do as what's told to.Will you agree?

If it's fine, I would proceed to reverting commit fe36cbe067 and related code in question from the kernel.

Thanks,
-Siwei

Quoted 10 lines · Si-Wei Liu
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use case there will be for kernel to leverage such info directly? Is there a case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

One of the reason I asked is if this ioctl becomes a mandate for vhost-vdpa kernel. QEMU would reject initialize vhost-vdpa if doesn't see this ioctl coming?

If it's optional, suppose the kernel may need it only when it becomes necessary?

Thanks,
-Siwei

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#35 lore raw
Quoted 8 lines · Si-Wei Liu

Hi Michael,

Are you okay to live without this ioctl for now? I think QEMU is the one that needs to be fixed and will have to be made legacy guest aware. I think the kernel can just honor the feature negotiation result done by QEMU and do as what's told to.Will you agree?

Quoted 5 lines

If it's fine, I would proceed to reverting commit fe36cbe067 and related code in question from the kernel.

Thanks,
-Siwei

Not really, I don't see why that's a good idea. fe36cbe067 is the code checking MTU before FEATURES_OK. Spec explicitly allows that.

Signature · 6 lines
MST

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
author
#36 lore raw
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Si-Wei Liu

Hi Michael,

Are you okay to live without this ioctl for now? I think QEMU is the one that needs to be fixed and will have to be made legacy guest aware. I think the kernel can just honor the feature negotiation result done by QEMU and do as what's told to.Will you agree?

Quoted 9 lines
Quoted 5 lines

If it's fine, I would proceed to reverting commit fe36cbe067 and related code in question from the kernel.

Thanks,
-Siwei

Not really, I don't see why that's a good idea. fe36cbe067 is the code checking MTU before FEATURES_OK. Spec explicitly allows that.

Alright, but what I meant was this commit
452639a64ad8 ("vdpa: make sure set_features is invoked for legacy").

But I got why you need it in another email (for BE host/guest).

-Siwei
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#37 lore raw
In reply to Si-Wei Liu
Quoted 82 lines · Si-Wei Liu
Quoted 72 lines · Michael S. Tsirkin
Quoted 71 lines · Si-Wei Liu
Quoted 69 lines · Michael S. Tsirkin
Quoted 60 lines · Jason Wang
Quoted 59 lines · Si-Wei Liu
Quoted 50 lines · Michael S. Tsirkin
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is
set.
This field specifies the maximum MTU for the driver to use. "

Quoted 3 lines

Do we really want to workaround this?

Thanks

And also:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 1 line

so accessing config space before FEATURES_OK is a spec violation, right?

It is, but it's not relevant to what this commit tries to address. I thought the legacy guest still needs to be supported.

Having said, a separate patch has to be posted to fix the guest driver issue where this discrepancy is introduced to virtnet_validate() (since commit fe36cbe067). But it's not technically related to this patch.

Quoted 5 lines
Quoted 1 line

-Siwei

I think it's a bug to read config space in validate, we should move it to virtnet_probe().

Thanks

I take it back, reading but not writing seems to be explicitly allowed by spec. So our way to detect a legacy guest is bogus, need to think what is the best way to handle this.

Quoted 7 lines
Quoted 5 lines

Then maybe revert commit fe36cbe067 and friends, and have QEMU detect legacy guest? Supposedly only config space write access needs to be guarded before setting FEATURES_OK.

-Siwie

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Quoted 8 lines

Well, although I think adding an ioctl is doable, may I know what the use case there will be for kernel to leverage such info directly? Is there a case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

One of the reason I asked is if this ioctl becomes a mandate for vhost-vdpa kernel. QEMU would reject initialize vhost-vdpa if doesn't see this ioctl coming?

Only on BE hosts or guests I think. With LE host and guest legacy and modern behave the same so ioctl isn't needed.

Quoted 5 lines

If it's optional, suppose the kernel may need it only when it becomes necessary?

Thanks,
-Siwei

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#38 lore raw
In reply to Si-Wei Liu
Quoted 6 lines · Si-Wei Liu
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use case there will be for kernel to leverage such info directly? Is there a case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Signature · 6 lines
MST

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#39 lore raw
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Si-Wei Liu
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use case there will be for kernel to leverage such info directly? Is there a case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other stuffs that is presented by vhost-vDPA is not expected to be accessed by guest directly. Qemu can do the endian conversion when necessary in this case?

Thanks

Quoted 1 line

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#40 lore raw
Quoted 23 lines · Jason Wang
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Si-Wei Liu
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use case there will be for kernel to leverage such info directly? Is there a case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

Quoted 7 lines

So qemu can still present the legacy device since the config space or other stuffs that is presented by vhost-vDPA is not expected to be accessed by guest directly. Qemu can do the endian conversion when necessary in this case?

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns. I note that any hardware implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Signature · 6 lines
MST

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#41 lore raw
Quoted 27 lines · Michael S. Tsirkin
Quoted 26 lines · Jason Wang
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Si-Wei Liu
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use case there will be for kernel to leverage such info directly? Is there a case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other stuffs that is presented by vhost-vDPA is not expected to be accessed by guest directly. Qemu can do the endian conversion when necessary in this case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

Quoted 2 lines

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#42 lore raw

vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at https://ozlabs.org/~rusty/virtio-spec/virtio-0.9.5.pdf. Though I'm not sure if there's request/need to support wilder legacy virtio versions earlier beyond.

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

        /*
         * Config accesses aren't supposed to trigger before features are set.
         * If it does happen we assume a legacy guest.
         */
        if (!vdev->features_valid)
                vdpa_set_features(vdev, 0);
        ops->get_config(vdev, offset, buf, len);

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

Quoted 53 lines · Jason Wang
Quoted 27 lines · Michael S. Tsirkin
Quoted 26 lines · Jason Wang
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Si-Wei Liu
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use case there will be for kernel to leverage such info directly? Is there a case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other stuffs that is presented by vhost-vDPA is not expected to be accessed by guest directly. Qemu can do the endian conversion when necessary in this case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

  I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

Quoted 2 lines
#43 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at
https://ozlabs.org/~rusty/virtio-spec/virtio-0.9.5.pdf. Though I'm not sure if there's request/need to support wilder legacy virtio versions earlier beyond.

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

Quoted 14 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

        /*
         * Config accesses aren't supposed to trigger before features are set.
         * If it does happen we assume a legacy guest.
         */
        if (!vdev->features_valid)
                vdpa_set_features(vdev, 0); ops->get_config(vdev, offset, buf, len);

Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 60 lines · Jason Wang
Quoted 59 lines · Michael S. Tsirkin
Quoted 33 lines · Jason Wang
Quoted 32 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use
case there will be for kernel to leverage such info directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

  I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

Quoted 2 lines
#44 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 13 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at
https://ozlabs.org/~rusty/virtio-spec/virtio-0.9.5.pdf. Though I'm not sure if there's request/need to support wilder legacy virtio versions earlier beyond.

Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

That's one way, other than the config access before setting features, we need to deal with other stuffs:

1) VIRTIO_F_ORDER_PLATFORM
2) there could be a parent device that only support 1.0 device

And a lot of other stuff summarized in spec 7.4 which seems not an easy task. Various vDPA parent drivers were written under the assumption that only modern devices are supported.

Thanks

Quoted 15 lines
Quoted 15 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

         * If it does happen we assume a legacy guest.
         */
        if (!vdev->features_valid)
                vdpa_set_features(vdev, 0);
        ops->get_config(vdev, offset, buf, len);
Quoted 71 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 60 lines · Jason Wang
Quoted 59 lines · Michael S. Tsirkin
Quoted 33 lines · Jason Wang
Quoted 32 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use
case there will be for kernel to leverage such info directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

Quoted 2 lines

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#45 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 22 lines · Jason Wang
Quoted 13 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at
https://ozlabs.org/~rusty/virtio-spec/virtio-0.9.5.pdf. Though I'm not sure if there's request/need to support wilder legacy virtio versions earlier beyond.

Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

That's one way, other than the config access before setting features, we need to deal with other stuffs:

Quoted 8 lines

1) VIRTIO_F_ORDER_PLATFORM
2) there could be a parent device that only support 1.0 device

And a lot of other stuff summarized in spec 7.4 which seems not an easy task. Various vDPA parent drivers were written under the assumption that only modern devices are supported.

Thanks

Limiting things to x86 will likely address most issues though, won't it?

Quoted 86 lines
Quoted 86 lines
Quoted 15 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

         * If it does happen we assume a legacy guest.
         */
        if (!vdev->features_valid)
                vdpa_set_features(vdev, 0);
        ops->get_config(vdev, offset, buf, len);
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 60 lines · Jason Wang
Quoted 59 lines · Michael S. Tsirkin
Quoted 33 lines · Jason Wang
Quoted 32 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use
case there will be for kernel to leverage such info directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

Quoted 2 lines
#46 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 27 lines · Michael S. Tsirkin
Quoted 25 lines · Jason Wang
Quoted 13 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at
https://ozlabs.org/~rusty/virtio-spec/virtio-0.9.5.pdf. Though I'm not sure if there's request/need to support wilder legacy virtio versions earlier beyond.

Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

That's one way, other than the config access before setting features, we need to deal with other stuffs:

1) VIRTIO_F_ORDER_PLATFORM
2) there could be a parent device that only support 1.0 device

Quoted 7 lines
Quoted 5 lines

And a lot of other stuff summarized in spec 7.4 which seems not an easy task. Various vDPA parent drivers were written under the assumption that only modern devices are supported.

Thanks

Limiting things to x86 will likely address most issues though, won't it?

For the ordering, yes. But it means we need to introduce a config option for legacy logic?

And we need to deal with, as you said in another thread, kick before DRIVER_OK:

E.g we had thing like this:

        if ((status & VIRTIO_CONFIG_S_DRIVER_OK) &&
            !(status_old & VIRTIO_CONFIG_S_DRIVER_OK)) {
                ret = ifcvf_request_irq(adapter);
                if (ret) {

Similar issues could be found in other parents.

We also need to consider whether we should encourage the vendor to implement the logic.

I think we can try and see how hard it is.

Thanks

Quoted 88 lines
Quoted 87 lines
Quoted 87 lines
Quoted 16 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

         * If it does happen we assume a legacy guest.
         */
        if (!vdev->features_valid)
                vdpa_set_features(vdev, 0);
        ops->get_config(vdev, offset, buf, len);
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 60 lines · Jason Wang
Quoted 59 lines · Michael S. Tsirkin
Quoted 33 lines · Jason Wang
Quoted 32 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use
case there will be for kernel to leverage such info directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

Quoted 2 lines
#47 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 40 lines · Jason Wang
Quoted 27 lines · Michael S. Tsirkin
Quoted 25 lines · Jason Wang
Quoted 13 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at
https://ozlabs.org/~rusty/virtio-spec/virtio-0.9.5.pdf. Though I'm not sure if there's request/need to support wilder legacy virtio versions earlier beyond.

Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

That's one way, other than the config access before setting features, we need to deal with other stuffs:

1) VIRTIO_F_ORDER_PLATFORM
2) there could be a parent device that only support 1.0 device

Quoted 7 lines
Quoted 5 lines

And a lot of other stuff summarized in spec 7.4 which seems not an easy task. Various vDPA parent drivers were written under the assumption that only modern devices are supported.

Thanks

Limiting things to x86 will likely address most issues though, won't it?

For the ordering, yes. But it means we need to introduce a config option for legacy logic?
And we need to deal with, as you said in another thread, kick before DRIVER_OK:

Quoted 8 lines

E.g we had thing like this:

        if ((status & VIRTIO_CONFIG_S_DRIVER_OK) &&
            !(status_old & VIRTIO_CONFIG_S_DRIVER_OK)) {
                ret = ifcvf_request_irq(adapter);
                if (ret) {

Similar issues could be found in other parents.

The driver ok thing is mostly an issue for block where it expects to access the disk directly during probe.

Quoted 6 lines

We also need to consider whether we should encourage the vendor to implement the logic.

I think we can try and see how hard it is.

Thanks

Right. My point exactly.

Quoted 88 lines
Quoted 88 lines
Quoted 87 lines
Quoted 87 lines
Quoted 16 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

         * If it does happen we assume a legacy guest.
         */
        if (!vdev->features_valid)
                vdpa_set_features(vdev, 0);
        ops->get_config(vdev, offset, buf, len);
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 60 lines · Jason Wang
Quoted 59 lines · Michael S. Tsirkin
Quoted 33 lines · Jason Wang
Quoted 32 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use
case there will be for kernel to leverage such info directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

Quoted 2 lines
author
#48 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

In reply to Jason Wang
Quoted 16 lines · Jason Wang
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!f64RqPFbYWWTGBgfWLzjlpJR_89WgX9KQTTz2vd-9UvMufMzqEbsajs8dxSfg0G8$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.
Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

Quoted 5 lines

That's one way, other than the config access before setting features, we need to deal with other stuffs:

1) VIRTIO_F_ORDER_PLATFORM
2) there could be a parent device that only support 1.0 device

We do want to involve vendor's support for a legacy (or transitional) device datapath. Otherwise it'd be too difficult to emulate/translate in software/QEMU. The above two might not be an issue if the vendor claims 0.95 support in virtqueue and ring layout, plus limiting to x86 support (LE with weak ordering) seems to simplify a lot of these requirements. I don't think emulating a legacy device model on top of a 1.0 vdpa parent for the dataplane would be a good idea, either.

Quoted 4 lines

And a lot of other stuff summarized in spec 7.4 which seems not an easy task. Various vDPA parent drivers were written under the assumption that only modern devices are supported.

If some of these vDPA vendors do provide the 0.95 support, especially on the datapath and ring layout that well satisfies a transitional device model defined in section 7.4, I guess we can scope the initial support to these vendor drivers and x86 only. Let me know if I miss something else.

Thanks,
-Siwei

Quoted 80 lines

Thanks

Quoted 77 lines
Quoted 14 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

          * If it does happen we assume a legacy guest.
          */
         if (!vdev->features_valid)
                 vdpa_set_features(vdev, 0);
         ops->get_config(vdev, offset, buf, len);
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 54 lines · Jason Wang
Quoted 53 lines · Michael S. Tsirkin
Quoted 32 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use
case there will be for kernel to leverage such info directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

Quoted 1 line

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#49 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

In reply to Michael S. Tsirkin
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.
Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out. I checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

Quoted 15 lines
Quoted 15 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

        /*
         * Config accesses aren't supposed to trigger before features are
set.
         * If it does happen we assume a legacy guest.
         */
        if (!vdev->features_valid)
                vdpa_set_features(vdev, 0); ops->get_config(vdev, offset, buf, len);

Quoted 7 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure. Or are you suggesting limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Thanks,
-Siwei

Quoted 49 lines
Quoted 49 lines · Jason Wang
Quoted 47 lines · Michael S. Tsirkin
Quoted 32 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use
case there will be for kernel to leverage such info directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

  I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Yes.

Thanks

Quoted 1 line

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#50 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 15 lines · Si-Wei Liu
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.
Quoted 6 lines
Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Note that thought I try to mandate 1.0 device when writing the codes but the core vdpa doesn't mandate it, and we've already had one parent which is based on the 0.95 spec which is the eni_vdpa:

1) it depends on X86 (so no endian and ordering issues)
2) it has various subtle things like it can't work well without mrg_rxbuf features negotiated since the device assumes a fixed vnet header length.
3) it can only be used by legacy drivers in the guest (no VERSION_1 since the device mandates a 4096 alignment which doesn't comply with 1.0)

So it's a proof of 0.95 parent support in the vDPA core.

And we had a modern only parent, that is the vp_vdpa parent (though it's not hard to add legacy support).

So for all the other vendors, assuming it has full support for transitional devices for x86. As discussed, we need to handle:

1) config access before features
2) kick before driver_ok

Anything else? If not, it looks easier to do them in the userspace. The only advantages for doing it in the kernel is to make it work for virtio-vdpa. But virito-vdpa doesn't need transitional devices.

Quoted 6 lines

I
checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

The code doesn't have such an assumption or anything I missed? Or you meant the vhost-vdpa that tries to talk with the IOMMU layer directly, it should be ok since host IOMMU is hidden from guest anyway.

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

          * If it does happen we assume a legacy guest.
          */
         if (!vdev->features_valid)
                 vdpa_set_features(vdev, 0);
         ops->get_config(vdev, offset, buf, len);

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

Quoted 7 lines
Quoted 3 lines

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure.

I think this is what a transitional device is expected to work.

Thanks

Quoted 63 lines

Or are you suggesting
limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Thanks,
-Siwei

Quoted 55 lines
Quoted 55 lines · Jason Wang
Quoted 53 lines · Michael S. Tsirkin
Quoted 32 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use
case there will be for kernel to leverage such info directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

Quoted 1 line
#51 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

In reply to Si-Wei Liu
Quoted 14 lines · Si-Wei Liu
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.
Quoted 6 lines
Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Note a subtle difference: what matters is that guest, not host is x86. Matters for emulators which might reorder memory accesses. I guess this enforcement belongs in QEMU then?

Quoted 29 lines

I
checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

Quoted 15 lines
Quoted 15 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

        /*
         * Config accesses aren't supposed to trigger before features are
set.
         * If it does happen we assume a legacy guest.
         */
        if (!vdev->features_valid)
                vdpa_set_features(vdev, 0); ops->get_config(vdev, offset, buf, len);

Quoted 7 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 8 lines

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure. Or are you suggesting limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Thanks,
-Siwei

I don't know for sure. Take a look at the work Halil was doing to try and support transitional devices with BE guests.

Quoted 55 lines
Quoted 55 lines
Quoted 55 lines · Jason Wang
Quoted 53 lines · Michael S. Tsirkin
Quoted 32 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use
case there will be for kernel to leverage such info directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

  I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

Quoted 1 line
author
#52 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Si-Wei Liu
Quoted 15 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

Quoted 5 lines
Quoted 2 lines

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Note a subtle difference: what matters is that guest, not host is x86. Matters for emulators which might reorder memory accesses. I guess this enforcement belongs in QEMU then?

Right, I mean to get started, the initial guest driver support and the corresponding QEMU support for transitional vdpa backend can be limited to x86 guest/host only. Since the config space is emulated in QEMU, I suppose it's not hard to enforce in QEMU. QEMU can drive GET_LEGACY, GET_ENDIAN et al ioctls in advance to get the capability from the individual vendor driver. For that, we need another negotiation protocol similar to vhost_user's protocol_features between the vdpa kernel and QEMU, way before the guest driver is ever probed and its feature negotiation kicks in. Not sure we need a GET_MEMORY_ORDER ioctl call from the device, but we can assume weak ordering for legacy at this point (x86 only)?

Quoted 35 lines
Quoted 35 lines

I
checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

Quoted 14 lines
Quoted 14 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

        /*
         * Config accesses aren't supposed to trigger before features are
set.
         * If it does happen we assume a legacy guest.
         */
        if (!vdev->features_valid)
                vdpa_set_features(vdev, 0); ops->get_config(vdev, offset, buf, len);

Quoted 7 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure. Or are you suggesting limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Quoted 5 lines
Quoted 2 lines

Thanks,
-Siwei

I don't know for sure. Take a look at the work Halil was doing to try and support transitional devices with BE guests.

Hmmm, we can have those endianness ioctls defined but the initial QEMU implementation can be started to support x86 guest/host with little endian and weak memory ordering first. The real trick is to detect legacy guest - I am not sure if it's feasible to shift all the legacy detection work to QEMU, or the kernel has to be part of the detection (e.g. the kick before DRIVER_OK thing we have to duplicate the tracking effort in QEMU) as well. Let me take a further look and get back.

Meanwhile, I'll check internally to see if a legacy only model would work. Thanks.

Thanks,
-Siwei

Quoted 45 lines
Quoted 45 lines
Quoted 45 lines
Quoted 45 lines · Jason Wang
Quoted 42 lines · Michael S. Tsirkin
Quoted 32 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use
case there will be for kernel to leverage such info directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

  I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#53 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 24 lines · Si-Wei Liu
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Si-Wei Liu
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.
Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Quoted 7 lines
Quoted 3 lines

Note a subtle difference: what matters is that guest, not host is x86. Matters for emulators which might reorder memory accesses. I guess this enforcement belongs in QEMU then?

Right, I mean to get started, the initial guest driver support and the corresponding QEMU support for transitional vdpa backend can be limited to x86 guest/host only. Since the config space is emulated in QEMU, I suppose it's not hard to enforce in QEMU.

It's more than just config space, most devices have headers before the buffer.

Quoted 8 lines

QEMU can drive GET_LEGACY,
GET_ENDIAN et al ioctls in advance to get the capability from the individual vendor driver. For that, we need another negotiation protocol similar to vhost_user's protocol_features between the vdpa kernel and QEMU, way before the guest driver is ever probed and its feature negotiation kicks in. Not sure we need a GET_MEMORY_ORDER ioctl call from the device, but we can assume weak ordering for legacy at this point (x86 only)?

I'm lost here, we have get_features() so:

1) VERSION_1 means the device uses LE if provided, otherwise natvie
2) ORDER_PLATFORM means device requires platform ordering

Any reason for having a new API for this?

Quoted 41 lines
Quoted 36 lines
Quoted 36 lines

I
checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

Quoted 14 lines
Quoted 14 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

           * If it does happen we assume a legacy guest.
           */
          if (!vdev->features_valid)
                  vdpa_set_features(vdev, 0);
          ops->get_config(vdev, offset, buf, len);
Quoted 7 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure. Or are you suggesting limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Quoted 5 lines
Quoted 2 lines

Thanks,
-Siwei

I don't know for sure. Take a look at the work Halil was doing to try and support transitional devices with BE guests.

Quoted 7 lines

Hmmm, we can have those endianness ioctls defined but the initial QEMU implementation can be started to support x86 guest/host with little endian and weak memory ordering first. The real trick is to detect legacy guest - I am not sure if it's feasible to shift all the legacy detection work to QEMU, or the kernel has to be part of the detection (e.g. the kick before DRIVER_OK thing we have to duplicate the tracking effort in QEMU) as well. Let me take a further look and get back.

Michael may think differently but I think doing this in Qemu is much easier.

Thanks

Quoted 62 lines

Meanwhile, I'll check internally to see if a legacy only model would work. Thanks.

Thanks,
-Siwei

Quoted 53 lines
Quoted 53 lines
Quoted 53 lines
Quoted 53 lines · Jason Wang
Quoted 50 lines · Michael S. Tsirkin
Quoted 32 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use
case there will be for kernel to leverage such info directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

author
#54 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 23 lines · Jason Wang
Quoted 22 lines · Si-Wei Liu
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Si-Wei Liu
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.
Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Note a subtle difference: what matters is that guest, not host is x86. Matters for emulators which might reorder memory accesses. I guess this enforcement belongs in QEMU then?

Right, I mean to get started, the initial guest driver support and the corresponding QEMU support for transitional vdpa backend can be limited to x86 guest/host only. Since the config space is emulated in QEMU, I suppose it's not hard to enforce in QEMU.

It's more than just config space, most devices have headers before the buffer.

The ordering in datapath (data VQs) would have to rely on vendor's support. Since ORDER_PLATFORM is pretty new (v1.1), I guess vdpa h/w vendor nowadays can/should well support the case when ORDER_PLATFORM is not acked by the driver (actually this feature is filtered out by the QEMU vhost-vdpa driver today), even with v1.0 spec conforming and modern only vDPA device. The control VQ is implemented in software in the kernel, which can be easily accommodated/fixed when needed.

Quoted 10 lines
Quoted 9 lines

QEMU can drive GET_LEGACY,
GET_ENDIAN et al ioctls in advance to get the capability from the individual vendor driver. For that, we need another negotiation protocol similar to vhost_user's protocol_features between the vdpa kernel and QEMU, way before the guest driver is ever probed and its feature negotiation kicks in. Not sure we need a GET_MEMORY_ORDER ioctl call from the device, but we can assume weak ordering for legacy at this point (x86 only)?

I'm lost here, we have get_features() so:

I assume here you refer to get_device_features() that Eli just changed the name.

Quoted 5 lines

1) VERSION_1 means the device uses LE if provided, otherwise natvie
2) ORDER_PLATFORM means device requires platform ordering

Any reason for having a new API for this?

Are you going to enforce all vDPA hardware vendors to support the transitional model for legacy guest? meaning guest not acknowledging VERSION_1 would use the legacy interfaces captured in the spec section 7.4 (regarding ring layout, native endianness, message framing, vq alignment of 4096, 32bit feature, no features_ok bit in status, IO port interface i.e. all the things) instead? Noted we don't yet have a set_device_features() that allows the vdpa device to tell whether it is operating in transitional or modern-only mode. For software virtio, all support for the legacy part in a transitional model has been built up there already, however, it's not easy for vDPA vendors to implement all the requirements for an all-or-nothing legacy guest support (big endian guest for example). To these vendors, the legacy support within a transitional model is more of feature to them and it's best to leave some flexibility for them to implement partial support for legacy. That in turn calls out the need for a vhost-user protocol feature like negotiation API that can prohibit those unsupported guest setups to as early as backend_init before launching the VM.

Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 29 lines

I
checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

Quoted 14 lines
Quoted 14 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

            * If it does happen we assume a legacy guest.
            */
           if (!vdev->features_valid)
                   vdpa_set_features(vdev, 0);
           ops->get_config(vdev, offset, buf, len);
Quoted 7 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 8 lines

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure. Or are you suggesting limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Thanks,
-Siwei

I don't know for sure. Take a look at the work Halil was doing to try and support transitional devices with BE guests.

Quoted 8 lines
Quoted 7 lines

Hmmm, we can have those endianness ioctls defined but the initial QEMU implementation can be started to support x86 guest/host with little endian and weak memory ordering first. The real trick is to detect legacy guest - I am not sure if it's feasible to shift all the legacy detection work to QEMU, or the kernel has to be part of the detection (e.g. the kick before DRIVER_OK thing we have to duplicate the tracking effort in QEMU) as well. Let me take a further look and get back.

Michael may think differently but I think doing this in Qemu is much easier.

I think the key is whether we position emulating legacy interfaces in QEMU doing translation on top of a v1.0 modern-only device in the kernel, or we allow vdpa core (or you can say vhost-vdpa) and vendor driver to support a transitional model in the kernel that is able to work for both v0.95 and v1.0 drivers, with some slight aid from QEMU for detecting/emulation/shadowing (for e.g CVQ, I/O port relay). I guess for the former we still rely on vendor for a performant data vqs implementation, leaving the question to what it may end up eventually in the kernel is effectively the latter).

Thanks,
-Siwei

Quoted 64 lines

Thanks

Quoted 59 lines

Meanwhile, I'll check internally to see if a legacy only model would work. Thanks.

Thanks,
-Siwei

Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines · Jason Wang
Quoted 50 lines · Michael S. Tsirkin
Quoted 32 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use
case there will be for kernel to leverage such info directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

#55 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 59 lines · Si-Wei Liu
Quoted 23 lines · Jason Wang
Quoted 22 lines · Si-Wei Liu
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Si-Wei Liu
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.
Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Note a subtle difference: what matters is that guest, not host is x86. Matters for emulators which might reorder memory accesses. I guess this enforcement belongs in QEMU then?

Right, I mean to get started, the initial guest driver support and the corresponding QEMU support for transitional vdpa backend can be limited to x86 guest/host only. Since the config space is emulated in QEMU, I suppose it's not hard to enforce in QEMU.

It's more than just config space, most devices have headers before the buffer.

The ordering in datapath (data VQs) would have to rely on vendor's support. Since ORDER_PLATFORM is pretty new (v1.1), I guess vdpa h/w vendor nowadays can/should well support the case when ORDER_PLATFORM is not acked by the driver (actually this feature is filtered out by the QEMU vhost-vdpa driver today), even with v1.0 spec conforming and modern only vDPA device. The control VQ is implemented in software in the kernel, which can be easily accommodated/fixed when needed.

Quoted 10 lines
Quoted 9 lines

QEMU can drive GET_LEGACY,
GET_ENDIAN et al ioctls in advance to get the capability from the individual vendor driver. For that, we need another negotiation protocol similar to vhost_user's protocol_features between the vdpa kernel and QEMU, way before the guest driver is ever probed and its feature negotiation kicks in. Not sure we need a GET_MEMORY_ORDER ioctl call from the device, but we can assume weak ordering for legacy at this point (x86 only)?

I'm lost here, we have get_features() so:

I assume here you refer to get_device_features() that Eli just changed the name.

Quoted 5 lines

1) VERSION_1 means the device uses LE if provided, otherwise natvie
2) ORDER_PLATFORM means device requires platform ordering

Any reason for having a new API for this?

Quoted 16 lines

Are you going to enforce all vDPA hardware vendors to support the transitional model for legacy guest? meaning guest not acknowledging VERSION_1 would use the legacy interfaces captured in the spec section 7.4 (regarding ring layout, native endianness, message framing, vq alignment of 4096, 32bit feature, no features_ok bit in status, IO port interface i.e. all the things) instead? Noted we don't yet have a set_device_features() that allows the vdpa device to tell whether it is operating in transitional or modern-only mode. For software virtio, all support for the legacy part in a transitional model has been built up there already, however, it's not easy for vDPA vendors to implement all the requirements for an all-or-nothing legacy guest support (big endian guest for example). To these vendors, the legacy support within a transitional model is more of feature to them and it's best to leave some flexibility for them to implement partial support for legacy. That in turn calls out the need for a vhost-user protocol feature like negotiation API that can prohibit those unsupported guest setups to as early as backend_init before launching the VM.

Right. Of note is the fact that it's a spec bug which I hope yet to fix, though due to existing guest code the fix won't be complete.

WRT ioctls, One thing we can do though is abuse set_features where it's called by QEMU early on with just the VERSION_1 bit set, to distinguish between legacy and modern interface. This before config space accesses and FEATURES_OK.

Halil has been working on this, pls take a look and maybe help him out.

Quoted 58 lines
Quoted 40 lines
Quoted 40 lines
Quoted 40 lines
Quoted 30 lines

I
checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

Quoted 14 lines
Quoted 14 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

            * If it does happen we assume a legacy guest.
            */
           if (!vdev->features_valid)
                   vdpa_set_features(vdev, 0);
           ops->get_config(vdev, offset, buf, len);
Quoted 7 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 8 lines

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure. Or are you suggesting limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Thanks,
-Siwei

I don't know for sure. Take a look at the work Halil was doing to try and support transitional devices with BE guests.

Quoted 8 lines
Quoted 7 lines

Hmmm, we can have those endianness ioctls defined but the initial QEMU implementation can be started to support x86 guest/host with little endian and weak memory ordering first. The real trick is to detect legacy guest - I am not sure if it's feasible to shift all the legacy detection work to QEMU, or the kernel has to be part of the detection (e.g. the kick before DRIVER_OK thing we have to duplicate the tracking effort in QEMU) as well. Let me take a further look and get back.

Michael may think differently but I think doing this in Qemu is much easier.

I think the key is whether we position emulating legacy interfaces in QEMU doing translation on top of a v1.0 modern-only device in the kernel, or we allow vdpa core (or you can say vhost-vdpa) and vendor driver to support a transitional model in the kernel that is able to work for both v0.95 and v1.0 drivers, with some slight aid from QEMU for detecting/emulation/shadowing (for e.g CVQ, I/O port relay). I guess for the former we still rely on vendor for a performant data vqs implementation, leaving the question to what it may end up eventually in the kernel is effectively the latter).

Quoted 2 lines

Thanks,
-Siwei

My suggestion is post the kernel patches, and we can evaluate how much work they are.

Quoted 64 lines
Quoted 64 lines

Thanks

Quoted 59 lines

Meanwhile, I'll check internally to see if a legacy only model would work. Thanks.

Thanks,
-Siwei

Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines · Jason Wang
Quoted 50 lines · Michael S. Tsirkin
Quoted 32 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify
the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use
case there will be for kernel to leverage such info directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

author
#56 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 72 lines · Michael S. Tsirkin
Quoted 55 lines · Si-Wei Liu
Quoted 22 lines · Jason Wang
Quoted 21 lines · Si-Wei Liu
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Si-Wei Liu
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.
Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Note a subtle difference: what matters is that guest, not host is x86. Matters for emulators which might reorder memory accesses. I guess this enforcement belongs in QEMU then?

Right, I mean to get started, the initial guest driver support and the corresponding QEMU support for transitional vdpa backend can be limited to x86 guest/host only. Since the config space is emulated in QEMU, I suppose it's not hard to enforce in QEMU.

It's more than just config space, most devices have headers before the buffer.

The ordering in datapath (data VQs) would have to rely on vendor's support. Since ORDER_PLATFORM is pretty new (v1.1), I guess vdpa h/w vendor nowadays can/should well support the case when ORDER_PLATFORM is not acked by the driver (actually this feature is filtered out by the QEMU vhost-vdpa driver today), even with v1.0 spec conforming and modern only vDPA device. The control VQ is implemented in software in the kernel, which can be easily accommodated/fixed when needed.

Quoted 9 lines
Quoted 8 lines

QEMU can drive GET_LEGACY,
GET_ENDIAN et al ioctls in advance to get the capability from the individual vendor driver. For that, we need another negotiation protocol similar to vhost_user's protocol_features between the vdpa kernel and QEMU, way before the guest driver is ever probed and its feature negotiation kicks in. Not sure we need a GET_MEMORY_ORDER ioctl call from the device, but we can assume weak ordering for legacy at this point (x86 only)?

I'm lost here, we have get_features() so:

I assume here you refer to get_device_features() that Eli just changed the name.

Quoted 4 lines

1) VERSION_1 means the device uses LE if provided, otherwise natvie
2) ORDER_PLATFORM means device requires platform ordering

Any reason for having a new API for this?

Quoted 16 lines

Are you going to enforce all vDPA hardware vendors to support the transitional model for legacy guest? meaning guest not acknowledging VERSION_1 would use the legacy interfaces captured in the spec section 7.4 (regarding ring layout, native endianness, message framing, vq alignment of 4096, 32bit feature, no features_ok bit in status, IO port interface i.e. all the things) instead? Noted we don't yet have a set_device_features() that allows the vdpa device to tell whether it is operating in transitional or modern-only mode. For software virtio, all support for the legacy part in a transitional model has been built up there already, however, it's not easy for vDPA vendors to implement all the requirements for an all-or-nothing legacy guest support (big endian guest for example). To these vendors, the legacy support within a transitional model is more of feature to them and it's best to leave some flexibility for them to implement partial support for legacy. That in turn calls out the need for a vhost-user protocol feature like negotiation API that can prohibit those unsupported guest setups to as early as backend_init before launching the VM.

Quoted 3 lines

Right. Of note is the fact that it's a spec bug which I hope yet to fix, though due to existing guest code the fix won't be complete.

I thought at one point you pointed out to me that the spec does allow config space read before claiming features_ok, and only config write before features_ok is prohibited. I haven't read up the full thread of Halil's VERSION_1 for transitional big endian device yet, but what is the spec bug you hope to fix?

Quoted 7 lines

WRT ioctls, One thing we can do though is abuse set_features where it's called by QEMU early on with just the VERSION_1 bit set, to distinguish between legacy and modern interface. This before config space accesses and FEATURES_OK.

Halil has been working on this, pls take a look and maybe help him out.

Interesting thread, am reading now and see how I may leverage or help there.

Quoted 56 lines
Quoted 56 lines
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 28 lines

I
checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

Quoted 14 lines
Quoted 14 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

             * If it does happen we assume a legacy guest.
             */
            if (!vdev->features_valid)
                    vdpa_set_features(vdev, 0);
            ops->get_config(vdev, offset, buf, len);
Quoted 7 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 8 lines

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure. Or are you suggesting limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Thanks,
-Siwei

I don't know for sure. Take a look at the work Halil was doing to try and support transitional devices with BE guests.

Quoted 8 lines
Quoted 7 lines

Hmmm, we can have those endianness ioctls defined but the initial QEMU implementation can be started to support x86 guest/host with little endian and weak memory ordering first. The real trick is to detect legacy guest - I am not sure if it's feasible to shift all the legacy detection work to QEMU, or the kernel has to be part of the detection (e.g. the kick before DRIVER_OK thing we have to duplicate the tracking effort in QEMU) as well. Let me take a further look and get back.

Michael may think differently but I think doing this in Qemu is much easier.

I think the key is whether we position emulating legacy interfaces in QEMU doing translation on top of a v1.0 modern-only device in the kernel, or we allow vdpa core (or you can say vhost-vdpa) and vendor driver to support a transitional model in the kernel that is able to work for both v0.95 and v1.0 drivers, with some slight aid from QEMU for detecting/emulation/shadowing (for e.g CVQ, I/O port relay). I guess for the former we still rely on vendor for a performant data vqs implementation, leaving the question to what it may end up eventually in the kernel is effectively the latter).

Quoted 5 lines
Quoted 2 lines

Thanks,
-Siwei

My suggestion is post the kernel patches, and we can evaluate how much work they are.

Thanks for the feedback. I will take some read then get back, probably after the winter break. Stay tuned.

Thanks,
-Siwei

Quoted 63 lines
Quoted 63 lines
Quoted 63 lines

Thanks

Quoted 58 lines

Meanwhile, I'll check internally to see if a legacy only model would work. Thanks.

Thanks,
-Siwei

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines · Jason Wang
Quoted 50 lines · Michael S. Tsirkin
Quoted 32 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines

Detecting it isn't enough though, we will need a new ioctl to notify
the kernel that it's a legacy guest. Ugh :(
Well, although I think adding an ioctl is doable, may I
know what the use
case there will be for kernel to leverage such info
directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed
differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

#57 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 54 lines · Si-Wei Liu
Quoted 50 lines · Michael S. Tsirkin
Quoted 49 lines · Si-Wei Liu
Quoted 22 lines · Jason Wang
Quoted 21 lines · Si-Wei Liu
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Si-Wei Liu
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.
Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Note a subtle difference: what matters is that guest, not host is x86. Matters for emulators which might reorder memory accesses. I guess this enforcement belongs in QEMU then?

Right, I mean to get started, the initial guest driver support and the corresponding QEMU support for transitional vdpa backend can be limited to x86 guest/host only. Since the config space is emulated in QEMU, I suppose it's not hard to enforce in QEMU.

It's more than just config space, most devices have headers before the buffer.

The ordering in datapath (data VQs) would have to rely on vendor's support. Since ORDER_PLATFORM is pretty new (v1.1), I guess vdpa h/w vendor nowadays can/should well support the case when ORDER_PLATFORM is not acked by the driver (actually this feature is filtered out by the QEMU vhost-vdpa driver today), even with v1.0 spec conforming and modern only vDPA device. The control VQ is implemented in software in the kernel, which can be easily accommodated/fixed when needed.

Quoted 9 lines
Quoted 8 lines

QEMU can drive GET_LEGACY,
GET_ENDIAN et al ioctls in advance to get the capability from the individual vendor driver. For that, we need another negotiation protocol similar to vhost_user's protocol_features between the vdpa kernel and QEMU, way before the guest driver is ever probed and its feature negotiation kicks in. Not sure we need a GET_MEMORY_ORDER ioctl call from the device, but we can assume weak ordering for legacy at this point (x86 only)?

I'm lost here, we have get_features() so:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

I assume here you refer to get_device_features() that Eli just changed the name.

Quoted 4 lines

1) VERSION_1 means the device uses LE if provided, otherwise natvie
2) ORDER_PLATFORM means device requires platform ordering

Any reason for having a new API for this?

Are you going to enforce all vDPA hardware vendors to support the transitional model for legacy guest?

Do we really have other choices?

I suspect the legacy device is never implemented by any vendor:

1) no virtio way to detect host endian
2) bypass IOMMU with translated requests
3) PIO port

Yes we have enp_vdpa, but it's more like a "transitional device" for legacy only guests.

Quoted 5 lines

meaning guest not acknowledging

Quoted 4 lines
Quoted 4 lines

VERSION_1 would use the legacy interfaces captured in the spec section 7.4 (regarding ring layout, native endianness, message framing, vq alignment of 4096, 32bit feature, no features_ok bit in status, IO port interface i.e. all the things) instead?

Note that we only care about the datapath, control path is mediated anyhow.

So feature_ok and IO port isn't an issue. The rest looks like a must for the hardware.

Quoted 3 lines

Noted we don't yet have a set_device_features()

Quoted 2 lines
Quoted 2 lines

that allows the vdpa device to tell whether it is operating in transitional or modern-only mode.

So the device feature should be provisioned via the netlink protocol. And what we want is not "set_device_feature()" but "set_device_mandatory_feautre()", then the parent can choose to fail the negotiation when VERSION_1 is not negotiated. Qemu then knows for sure it talks to a transitional device or modern only device.

Thanks

Quoted 158 lines

For software virtio, all support for the legacy part in

Quoted 11 lines
Quoted 8 lines

a transitional model has been built up there already, however, it's not easy for vDPA vendors to implement all the requirements for an all-or-nothing legacy guest support (big endian guest for example). To these vendors, the legacy support within a transitional model is more of feature to them and it's best to leave some flexibility for them to implement partial support for legacy. That in turn calls out the need for a vhost-user protocol feature like negotiation API that can prohibit those unsupported guest setups to as early as backend_init before launching the VM.

Right. Of note is the fact that it's a spec bug which I hope yet to fix, though due to existing guest code the fix won't be complete.

I thought at one point you pointed out to me that the spec does allow config space read before claiming features_ok, and only config write before features_ok is prohibited. I haven't read up the full thread of Halil's VERSION_1 for transitional big endian device yet, but what is the spec bug you hope to fix?

Quoted 7 lines

WRT ioctls, One thing we can do though is abuse set_features where it's called by QEMU early on with just the VERSION_1 bit set, to distinguish between legacy and modern interface. This before config space accesses and FEATURES_OK.

Halil has been working on this, pls take a look and maybe help him out.

Interesting thread, am reading now and see how I may leverage or help there.

Quoted 56 lines
Quoted 56 lines
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 28 lines

I
checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

Quoted 14 lines
Quoted 14 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

             * If it does happen we assume a legacy guest.
             */
            if (!vdev->features_valid)
                    vdpa_set_features(vdev, 0);
            ops->get_config(vdev, offset, buf, len);
Quoted 7 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 8 lines

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure. Or are you suggesting limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Thanks,
-Siwei

I don't know for sure. Take a look at the work Halil was doing to try and support transitional devices with BE guests.

Quoted 8 lines
Quoted 7 lines

Hmmm, we can have those endianness ioctls defined but the initial QEMU implementation can be started to support x86 guest/host with little endian and weak memory ordering first. The real trick is to detect legacy guest - I am not sure if it's feasible to shift all the legacy detection work to QEMU, or the kernel has to be part of the detection (e.g. the kick before DRIVER_OK thing we have to duplicate the tracking effort in QEMU) as well. Let me take a further look and get back.

Michael may think differently but I think doing this in Qemu is much easier.

I think the key is whether we position emulating legacy interfaces in QEMU doing translation on top of a v1.0 modern-only device in the kernel, or we allow vdpa core (or you can say vhost-vdpa) and vendor driver to support a transitional model in the kernel that is able to work for both v0.95 and v1.0 drivers, with some slight aid from QEMU for detecting/emulation/shadowing (for e.g CVQ, I/O port relay). I guess for the former we still rely on vendor for a performant data vqs implementation, leaving the question to what it may end up eventually in the kernel is effectively the latter).

Quoted 5 lines
Quoted 2 lines

Thanks,
-Siwei

My suggestion is post the kernel patches, and we can evaluate how much work they are.

Thanks for the feedback. I will take some read then get back, probably after the winter break. Stay tuned.

Thanks,
-Siwei

Quoted 63 lines
Quoted 63 lines
Quoted 63 lines

Thanks

Quoted 58 lines

Meanwhile, I'll check internally to see if a legacy only model would work. Thanks.

Thanks,
-Siwei

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines · Jason Wang
Quoted 50 lines · Michael S. Tsirkin
Quoted 32 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 15 lines · Si-Wei Liu

Detecting it isn't enough though, we will need a new ioctl to notify
the kernel that it's a legacy guest. Ugh :(
Well, although I think adding an ioctl is doable, may I
know what the use
case there will be for kernel to leverage such info
directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed
differentiation (legacy v.s. modern) needed?
BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)
#define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

author
#58 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 57 lines · Jason Wang
Quoted 56 lines · Si-Wei Liu
Quoted 53 lines · Michael S. Tsirkin
Quoted 52 lines · Si-Wei Liu
Quoted 21 lines · Jason Wang
Quoted 20 lines · Si-Wei Liu
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Si-Wei Liu
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.
Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Note a subtle difference: what matters is that guest, not host is x86. Matters for emulators which might reorder memory accesses. I guess this enforcement belongs in QEMU then?

Right, I mean to get started, the initial guest driver support and the corresponding QEMU support for transitional vdpa backend can be limited to x86 guest/host only. Since the config space is emulated in QEMU, I suppose it's not hard to enforce in QEMU.

It's more than just config space, most devices have headers before the buffer.

The ordering in datapath (data VQs) would have to rely on vendor's support. Since ORDER_PLATFORM is pretty new (v1.1), I guess vdpa h/w vendor nowadays can/should well support the case when ORDER_PLATFORM is not acked by the driver (actually this feature is filtered out by the QEMU vhost-vdpa driver today), even with v1.0 spec conforming and modern only vDPA device. The control VQ is implemented in software in the kernel, which can be easily accommodated/fixed when needed.

Quoted 9 lines
Quoted 8 lines

QEMU can drive GET_LEGACY,
GET_ENDIAN et al ioctls in advance to get the capability from the individual vendor driver. For that, we need another negotiation protocol similar to vhost_user's protocol_features between the vdpa kernel and QEMU, way before the guest driver is ever probed and its feature negotiation kicks in. Not sure we need a GET_MEMORY_ORDER ioctl call from the device, but we can assume weak ordering for legacy at this point (x86 only)?

I'm lost here, we have get_features() so:

I assume here you refer to get_device_features() that Eli just changed the name.

Quoted 3 lines

1) VERSION_1 means the device uses LE if provided, otherwise natvie
2) ORDER_PLATFORM means device requires platform ordering

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

Any reason for having a new API for this?

Are you going to enforce all vDPA hardware vendors to support the transitional model for legacy guest?

Do we really have other choices?

I suspect the legacy device is never implemented by any vendor:

1) no virtio way to detect host endian

This is even true for transitional device that is conforming to the spec, right? The transport specific way to detect host endian is still being discussed and the spec revision is not finalized yet so far as I see. Why this suddenly becomes a requirement/blocker for h/w vendors to implement the transitional model? Even if the spec is out, this is pretty new and I suspect not all vendor would follow right away. I hope the software framework can be tolerant with h/w vendors not supporting host endianess (BE specifically) or not detecting it if they would like to support a transitional device for legacy.

Quoted 7 lines

2) bypass IOMMU with translated requests
3) PIO port

Yes we have enp_vdpa, but it's more like a "transitional device" for legacy only guests.

Quoted 1 line

meaning guest not acknowledging

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

VERSION_1 would use the legacy interfaces captured in the spec section 7.4 (regarding ring layout, native endianness, message framing, vq alignment of 4096, 32bit feature, no features_ok bit in status, IO port interface i.e. all the things) instead?

Note that we only care about the datapath, control path is mediated anyhow.

So feature_ok and IO port isn't an issue. The rest looks like a must for the hardware.

H/W vendors can opt out not implementing transitional interfaces at all which limits itself a modern only device. Set endianess detection (via transport specific means) aside, for vendors that wishes to support transitional device with legacy interface, is it a hard stop to drop supporting BE host if everything else is there? The spec today doesn't define virtio specific means to detect host memory ordering or device memory coherency, will it yet become a stopper another day for h/w vendor to support more platforms?

Quoted 5 lines
Quoted 4 lines

Noted we don't yet have a set_device_features()

Quoted 2 lines
Quoted 2 lines

that allows the vdpa device to tell whether it is operating in transitional or modern-only mode.

So the device feature should be provisioned via the netlink protocol.

Such netlink interface will only be used to limit feature exposure, right? i.e. you can limit a transitional supporting vendor driver to offering modern-only interface, but you never want to make a modern-only vendor driver to support transitional (I'm not sure if it's a good idea to support all the translation in software, esp. for datapath).

Quoted 3 lines

And what we want is not "set_device_feature()" but "set_device_mandatory_feautre()", then the parent can choose to fail the negotiation when VERSION_1 is not negotiated.

This assumes the transport specific detection of BE host is in place, right? I am not clear who initiates the set_device_mandatory_feautre() call, QEMU during guest feature negotiation, or admin user setting it ahead via netlink?

Thanks,
-Siwei

Quoted 159 lines

Qemu then knows for
sure it talks to a transitional device or modern only device.

Thanks

Quoted 154 lines

For software virtio, all support for the legacy part in

Quoted 11 lines
Quoted 8 lines

a transitional model has been built up there already, however, it's not easy for vDPA vendors to implement all the requirements for an all-or-nothing legacy guest support (big endian guest for example). To these vendors, the legacy support within a transitional model is more of feature to them and it's best to leave some flexibility for them to implement partial support for legacy. That in turn calls out the need for a vhost-user protocol feature like negotiation API that can prohibit those unsupported guest setups to as early as backend_init before launching the VM.

Right. Of note is the fact that it's a spec bug which I hope yet to fix, though due to existing guest code the fix won't be complete.

I thought at one point you pointed out to me that the spec does allow config space read before claiming features_ok, and only config write before features_ok is prohibited. I haven't read up the full thread of Halil's VERSION_1 for transitional big endian device yet, but what is the spec bug you hope to fix?

Quoted 6 lines

WRT ioctls, One thing we can do though is abuse set_features where it's called by QEMU early on with just the VERSION_1 bit set, to distinguish between legacy and modern interface. This before config space accesses and FEATURES_OK.

Halil has been working on this, pls take a look and maybe help him out.

Interesting thread, am reading now and see how I may leverage or help there.

Quoted 56 lines
Quoted 56 lines
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 28 lines

I
checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

Quoted 14 lines
Quoted 14 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

              * If it does happen we assume a legacy guest.
              */
             if (!vdev->features_valid)
                     vdpa_set_features(vdev, 0);
             ops->get_config(vdev, offset, buf, len);
Quoted 7 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 8 lines

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure. Or are you suggesting limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Thanks,
-Siwei

I don't know for sure. Take a look at the work Halil was doing to try and support transitional devices with BE guests.

Quoted 8 lines
Quoted 7 lines

Hmmm, we can have those endianness ioctls defined but the initial QEMU implementation can be started to support x86 guest/host with little endian and weak memory ordering first. The real trick is to detect legacy guest - I am not sure if it's feasible to shift all the legacy detection work to QEMU, or the kernel has to be part of the detection (e.g. the kick before DRIVER_OK thing we have to duplicate the tracking effort in QEMU) as well. Let me take a further look and get back.

Michael may think differently but I think doing this in Qemu is much easier.

I think the key is whether we position emulating legacy interfaces in QEMU doing translation on top of a v1.0 modern-only device in the kernel, or we allow vdpa core (or you can say vhost-vdpa) and vendor driver to support a transitional model in the kernel that is able to work for both v0.95 and v1.0 drivers, with some slight aid from QEMU for detecting/emulation/shadowing (for e.g CVQ, I/O port relay). I guess for the former we still rely on vendor for a performant data vqs implementation, leaving the question to what it may end up eventually in the kernel is effectively the latter).

Quoted 4 lines
Quoted 2 lines

Thanks,
-Siwei

My suggestion is post the kernel patches, and we can evaluate how much work they are.

Thanks for the feedback. I will take some read then get back, probably after the winter break. Stay tuned.

Thanks,
-Siwei

Quoted 62 lines
Quoted 62 lines
Quoted 62 lines

Thanks

Quoted 58 lines

Meanwhile, I'll check internally to see if a legacy only model would work. Thanks.

Thanks,
-Siwei

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines · Jason Wang
Quoted 50 lines · Michael S. Tsirkin
Quoted 32 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin

On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
Detecting it isn't enough though, we will need a new ioctl to notify
the kernel that it's a legacy guest. Ugh :(
Well, although I think adding an ioctl is doable, may I
know what the use
case there will be for kernel to leverage such info
directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed
differentiation (legacy v.s. modern) needed?
BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)
#define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...
Actually, I wonder whether it's good time to just not support
legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config
space or other
stuffs that is presented by vhost-vDPA is not expected to be
accessed by
guest directly. Qemu can do the endian conversion when necessary
in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

#59 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 64 lines · Si-Wei Liu
Quoted 60 lines · Jason Wang
Quoted 59 lines · Si-Wei Liu
Quoted 56 lines · Michael S. Tsirkin
Quoted 55 lines · Si-Wei Liu
Quoted 21 lines · Jason Wang
Quoted 20 lines · Si-Wei Liu
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Si-Wei Liu
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.
Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Note a subtle difference: what matters is that guest, not host is x86. Matters for emulators which might reorder memory accesses. I guess this enforcement belongs in QEMU then?

Right, I mean to get started, the initial guest driver support and the corresponding QEMU support for transitional vdpa backend can be limited to x86 guest/host only. Since the config space is emulated in QEMU, I suppose it's not hard to enforce in QEMU.

It's more than just config space, most devices have headers before the buffer.

The ordering in datapath (data VQs) would have to rely on vendor's support. Since ORDER_PLATFORM is pretty new (v1.1), I guess vdpa h/w vendor nowadays can/should well support the case when ORDER_PLATFORM is not acked by the driver (actually this feature is filtered out by the QEMU vhost-vdpa driver today), even with v1.0 spec conforming and modern only vDPA device. The control VQ is implemented in software in the kernel, which can be easily accommodated/fixed when needed.

Quoted 9 lines
Quoted 8 lines

QEMU can drive GET_LEGACY,
GET_ENDIAN et al ioctls in advance to get the capability from the individual vendor driver. For that, we need another negotiation protocol similar to vhost_user's protocol_features between the vdpa kernel and QEMU, way before the guest driver is ever probed and its feature negotiation kicks in. Not sure we need a GET_MEMORY_ORDER ioctl call from the device, but we can assume weak ordering for legacy at this point (x86 only)?

I'm lost here, we have get_features() so:

I assume here you refer to get_device_features() that Eli just changed the name.

Quoted 4 lines

1) VERSION_1 means the device uses LE if provided, otherwise natvie
2) ORDER_PLATFORM means device requires platform ordering

Any reason for having a new API for this?

Are you going to enforce all vDPA hardware vendors to support the transitional model for legacy guest?

Quoted 7 lines
Quoted 5 lines

Do we really have other choices?

I suspect the legacy device is never implemented by any vendor:

1) no virtio way to detect host endian

This is even true for transitional device that is conforming to the spec, right?

For hardware, yes.

Quoted 4 lines

The transport specific way to detect host endian is still being discussed and the spec revision is not finalized yet so far as I see. Why this suddenly becomes a requirement/blocker for h/w vendors to implement the transitional model?

It's not a sudden blocker, the problem has existed since day 0 if I was not wrong. That's why the problem looks a little bit complicated and why it would be much simpler if we stick to modern devices.

Quoted 5 lines

Even if the spec is out, this is
pretty new and I suspect not all vendor would follow right away. I hope the software framework can be tolerant with h/w vendors not supporting host endianess (BE specifically) or not detecting it if they would like to support a transitional device for legacy.

Well, if we know we don't want to support the BE host it would be fine.

Quoted 16 lines
Quoted 8 lines

2) bypass IOMMU with translated requests
3) PIO port

Yes we have enp_vdpa, but it's more like a "transitional device" for legacy only guests.

Quoted 1 line

meaning guest not acknowledging

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

VERSION_1 would use the legacy interfaces captured in the spec section 7.4 (regarding ring layout, native endianness, message framing, vq alignment of 4096, 32bit feature, no features_ok bit in status, IO port interface i.e. all the things) instead?

Note that we only care about the datapath, control path is mediated anyhow.

So feature_ok and IO port isn't an issue. The rest looks like a must for the hardware.

Quoted 7 lines

H/W vendors can opt out not implementing transitional interfaces at all which limits itself a modern only device. Set endianess detection (via transport specific means) aside, for vendors that wishes to support transitional device with legacy interface, is it a hard stop to drop supporting BE host if everything else is there? The spec today doesn't define virtio specific means to detect host memory ordering or device memory coherency,

Any reason that we need to care about memory coherency at the virtio level. I'd expect it's the task of transport.

Quoted 2 lines

will it yet become a stopper another day for h/w
vendor to support more platforms?

Let's differentiate virtio from vdpa here. For virtio, there's no way to add any feature for legacy devices. We can only add memory features detecting for modern devices.

But for vDPA, we can introduce any API that can help vendors to present a transitional device. But we can force those APIs since it's too late to do that. So transitional devices support is optional for sure.

Quoted 9 lines
Quoted 6 lines
Quoted 5 lines

Noted we don't yet have a set_device_features()

Quoted 2 lines
Quoted 2 lines

that allows the vdpa device to tell whether it is operating in transitional or modern-only mode.

So the device feature should be provisioned via the netlink protocol.

Such netlink interface will only be used to limit feature exposure, right? i.e. you can limit a transitional supporting vendor driver to offering modern-only interface,

There's no way for the management to force a feature, like VERSION_1 via the current protocol.

Quoted 3 lines

but you never want to make a modern-only
vendor driver to support transitional (I'm not sure if it's a good idea to support all the translation in software, esp. for datapath).

You may hit this problem for sure, you can't force all vendors to support transitional devices especially considering spec said legacy is optional. We don't want to end up with a userspace code that can only work for some specific vendors.

Quoted 5 lines
Quoted 3 lines

And what we want is not "set_device_feature()" but "set_device_mandatory_feautre()", then the parent can choose to fail the negotiation when VERSION_1 is not negotiated.

This assumes the transport specific detection of BE host is in place, right?

Again, the point is, we can not assume such detection works for all of the vendors. And assume BE detection is ready, we still need this for modern devices, isn't it?

Quoted 3 lines

I am not clear who initiates the set_device_mandatory_feautre() call, QEMU during guest feature negotiation, or admin user setting it ahead via netlink?

Netlink, actually, the spec needs to be extended as well, we saw similar requests in the past. E.g there could be a device that works in a packed layout only.

Thanks

Quoted 164 lines

Thanks,
-Siwei

Quoted 159 lines

Qemu then knows for
sure it talks to a transitional device or modern only device.

Thanks

Quoted 154 lines

For software virtio, all support for the legacy part in

Quoted 11 lines
Quoted 8 lines

a transitional model has been built up there already, however, it's not easy for vDPA vendors to implement all the requirements for an all-or-nothing legacy guest support (big endian guest for example). To these vendors, the legacy support within a transitional model is more of feature to them and it's best to leave some flexibility for them to implement partial support for legacy. That in turn calls out the need for a vhost-user protocol feature like negotiation API that can prohibit those unsupported guest setups to as early as backend_init before launching the VM.

Right. Of note is the fact that it's a spec bug which I hope yet to fix, though due to existing guest code the fix won't be complete.

I thought at one point you pointed out to me that the spec does allow config space read before claiming features_ok, and only config write before features_ok is prohibited. I haven't read up the full thread of Halil's VERSION_1 for transitional big endian device yet, but what is the spec bug you hope to fix?

Quoted 6 lines

WRT ioctls, One thing we can do though is abuse set_features where it's called by QEMU early on with just the VERSION_1 bit set, to distinguish between legacy and modern interface. This before config space accesses and FEATURES_OK.

Halil has been working on this, pls take a look and maybe help him out.

Interesting thread, am reading now and see how I may leverage or help there.

Quoted 56 lines
Quoted 56 lines
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 28 lines

I
checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

Quoted 14 lines
Quoted 14 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

              * If it does happen we assume a legacy guest.
              */
             if (!vdev->features_valid)
                     vdpa_set_features(vdev, 0);
             ops->get_config(vdev, offset, buf, len);
Quoted 7 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 8 lines

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure. Or are you suggesting limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Thanks,
-Siwei

I don't know for sure. Take a look at the work Halil was doing to try and support transitional devices with BE guests.

Quoted 8 lines
Quoted 7 lines

Hmmm, we can have those endianness ioctls defined but the initial QEMU implementation can be started to support x86 guest/host with little endian and weak memory ordering first. The real trick is to detect legacy guest - I am not sure if it's feasible to shift all the legacy detection work to QEMU, or the kernel has to be part of the detection (e.g. the kick before DRIVER_OK thing we have to duplicate the tracking effort in QEMU) as well. Let me take a further look and get back.

Michael may think differently but I think doing this in Qemu is much easier.

I think the key is whether we position emulating legacy interfaces in QEMU doing translation on top of a v1.0 modern-only device in the kernel, or we allow vdpa core (or you can say vhost-vdpa) and vendor driver to support a transitional model in the kernel that is able to work for both v0.95 and v1.0 drivers, with some slight aid from QEMU for detecting/emulation/shadowing (for e.g CVQ, I/O port relay). I guess for the former we still rely on vendor for a performant data vqs implementation, leaving the question to what it may end up eventually in the kernel is effectively the latter).

Quoted 4 lines
Quoted 2 lines

Thanks,
-Siwei

My suggestion is post the kernel patches, and we can evaluate how much work they are.

Thanks for the feedback. I will take some read then get back, probably after the winter break. Stay tuned.

Thanks,
-Siwei

Quoted 62 lines
Quoted 62 lines
Quoted 62 lines

Thanks

Quoted 58 lines

Meanwhile, I'll check internally to see if a legacy only model would work. Thanks.

Thanks,
-Siwei

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines · Jason Wang
Quoted 50 lines · Michael S. Tsirkin
Quoted 38 lines · Jason Wang

On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
Detecting it isn't enough though, we will need a new ioctl to notify
the kernel that it's a legacy guest. Ugh :(
Well, although I think adding an ioctl is doable, may I
know what the use
case there will be for kernel to leverage such info
directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed
differentiation (legacy v.s. modern) needed?
BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)
#define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...
Actually, I wonder whether it's good time to just not support
legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config
space or other
stuffs that is presented by vhost-vDPA is not expected to be
accessed by
guest directly. Qemu can do the endian conversion when necessary
in this
case?

Thanks

Overall I would be fine with this approach but we need to avoid breaking
working userspace, qemu releases with vdpa support are out there and
seem to work for people. Any changes need to take that into account
and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with
strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

#60 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 84 lines · Jason Wang
Quoted 64 lines · Si-Wei Liu
Quoted 60 lines · Jason Wang
Quoted 59 lines · Si-Wei Liu
Quoted 56 lines · Michael S. Tsirkin
Quoted 55 lines · Si-Wei Liu
Quoted 21 lines · Jason Wang
Quoted 20 lines · Si-Wei Liu
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Si-Wei Liu
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.
Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Note a subtle difference: what matters is that guest, not host is x86. Matters for emulators which might reorder memory accesses. I guess this enforcement belongs in QEMU then?

Right, I mean to get started, the initial guest driver support and the corresponding QEMU support for transitional vdpa backend can be limited to x86 guest/host only. Since the config space is emulated in QEMU, I suppose it's not hard to enforce in QEMU.

It's more than just config space, most devices have headers before the buffer.

The ordering in datapath (data VQs) would have to rely on vendor's support. Since ORDER_PLATFORM is pretty new (v1.1), I guess vdpa h/w vendor nowadays can/should well support the case when ORDER_PLATFORM is not acked by the driver (actually this feature is filtered out by the QEMU vhost-vdpa driver today), even with v1.0 spec conforming and modern only vDPA device. The control VQ is implemented in software in the kernel, which can be easily accommodated/fixed when needed.

Quoted 9 lines
Quoted 8 lines

QEMU can drive GET_LEGACY,
GET_ENDIAN et al ioctls in advance to get the capability from the individual vendor driver. For that, we need another negotiation protocol similar to vhost_user's protocol_features between the vdpa kernel and QEMU, way before the guest driver is ever probed and its feature negotiation kicks in. Not sure we need a GET_MEMORY_ORDER ioctl call from the device, but we can assume weak ordering for legacy at this point (x86 only)?

I'm lost here, we have get_features() so:

I assume here you refer to get_device_features() that Eli just changed the name.

Quoted 4 lines

1) VERSION_1 means the device uses LE if provided, otherwise natvie
2) ORDER_PLATFORM means device requires platform ordering

Any reason for having a new API for this?

Are you going to enforce all vDPA hardware vendors to support the transitional model for legacy guest?

Quoted 7 lines
Quoted 5 lines

Do we really have other choices?

I suspect the legacy device is never implemented by any vendor:

1) no virtio way to detect host endian

This is even true for transitional device that is conforming to the spec, right?

For hardware, yes.

Quoted 4 lines

The transport specific way to detect host endian is still being discussed and the spec revision is not finalized yet so far as I see. Why this suddenly becomes a requirement/blocker for h/w vendors to implement the transitional model?

It's not a sudden blocker, the problem has existed since day 0 if I was not wrong. That's why the problem looks a little bit complicated and why it would be much simpler if we stick to modern devices.

Quoted 7 lines
Quoted 5 lines

Even if the spec is out, this is
pretty new and I suspect not all vendor would follow right away. I hope the software framework can be tolerant with h/w vendors not supporting host endianess (BE specifically) or not detecting it if they would like to support a transitional device for legacy.

Well, if we know we don't want to support the BE host it would be fine.

I think you guys mean guest not host here. Same for memory ordering etc. What matters is whether guest has barriers etc.

Quoted 245 lines
Quoted 16 lines
Quoted 8 lines

2) bypass IOMMU with translated requests
3) PIO port

Yes we have enp_vdpa, but it's more like a "transitional device" for legacy only guests.

Quoted 1 line

meaning guest not acknowledging

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

VERSION_1 would use the legacy interfaces captured in the spec section 7.4 (regarding ring layout, native endianness, message framing, vq alignment of 4096, 32bit feature, no features_ok bit in status, IO port interface i.e. all the things) instead?

Note that we only care about the datapath, control path is mediated anyhow.

So feature_ok and IO port isn't an issue. The rest looks like a must for the hardware.

Quoted 7 lines

H/W vendors can opt out not implementing transitional interfaces at all which limits itself a modern only device. Set endianess detection (via transport specific means) aside, for vendors that wishes to support transitional device with legacy interface, is it a hard stop to drop supporting BE host if everything else is there? The spec today doesn't define virtio specific means to detect host memory ordering or device memory coherency,

Any reason that we need to care about memory coherency at the virtio level. I'd expect it's the task of transport.

Quoted 2 lines

will it yet become a stopper another day for h/w
vendor to support more platforms?

Let's differentiate virtio from vdpa here. For virtio, there's no way to add any feature for legacy devices. We can only add memory features detecting for modern devices.

But for vDPA, we can introduce any API that can help vendors to present a transitional device. But we can force those APIs since it's too late to do that. So transitional devices support is optional for sure.

Quoted 9 lines
Quoted 6 lines
Quoted 5 lines

Noted we don't yet have a set_device_features()

Quoted 2 lines
Quoted 2 lines

that allows the vdpa device to tell whether it is operating in transitional or modern-only mode.

So the device feature should be provisioned via the netlink protocol.

Such netlink interface will only be used to limit feature exposure, right? i.e. you can limit a transitional supporting vendor driver to offering modern-only interface,

There's no way for the management to force a feature, like VERSION_1 via the current protocol.

Quoted 3 lines

but you never want to make a modern-only
vendor driver to support transitional (I'm not sure if it's a good idea to support all the translation in software, esp. for datapath).

You may hit this problem for sure, you can't force all vendors to support transitional devices especially considering spec said legacy is optional. We don't want to end up with a userspace code that can only work for some specific vendors.

Quoted 5 lines
Quoted 3 lines

And what we want is not "set_device_feature()" but "set_device_mandatory_feautre()", then the parent can choose to fail the negotiation when VERSION_1 is not negotiated.

This assumes the transport specific detection of BE host is in place, right?

Again, the point is, we can not assume such detection works for all of the vendors. And assume BE detection is ready, we still need this for modern devices, isn't it?

Quoted 3 lines

I am not clear who initiates the set_device_mandatory_feautre() call, QEMU during guest feature negotiation, or admin user setting it ahead via netlink?

Netlink, actually, the spec needs to be extended as well, we saw similar requests in the past. E.g there could be a device that works in a packed layout only.

Thanks

Quoted 164 lines

Thanks,
-Siwei

Quoted 159 lines

Qemu then knows for
sure it talks to a transitional device or modern only device.

Thanks

Quoted 154 lines

For software virtio, all support for the legacy part in

Quoted 11 lines
Quoted 8 lines

a transitional model has been built up there already, however, it's not easy for vDPA vendors to implement all the requirements for an all-or-nothing legacy guest support (big endian guest for example). To these vendors, the legacy support within a transitional model is more of feature to them and it's best to leave some flexibility for them to implement partial support for legacy. That in turn calls out the need for a vhost-user protocol feature like negotiation API that can prohibit those unsupported guest setups to as early as backend_init before launching the VM.

Right. Of note is the fact that it's a spec bug which I hope yet to fix, though due to existing guest code the fix won't be complete.

I thought at one point you pointed out to me that the spec does allow config space read before claiming features_ok, and only config write before features_ok is prohibited. I haven't read up the full thread of Halil's VERSION_1 for transitional big endian device yet, but what is the spec bug you hope to fix?

Quoted 6 lines

WRT ioctls, One thing we can do though is abuse set_features where it's called by QEMU early on with just the VERSION_1 bit set, to distinguish between legacy and modern interface. This before config space accesses and FEATURES_OK.

Halil has been working on this, pls take a look and maybe help him out.

Interesting thread, am reading now and see how I may leverage or help there.

Quoted 56 lines
Quoted 56 lines
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 28 lines

I
checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

Quoted 14 lines
Quoted 14 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

              * If it does happen we assume a legacy guest.
              */
             if (!vdev->features_valid)
                     vdpa_set_features(vdev, 0);
             ops->get_config(vdev, offset, buf, len);
Quoted 7 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 8 lines

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure. Or are you suggesting limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Thanks,
-Siwei

I don't know for sure. Take a look at the work Halil was doing to try and support transitional devices with BE guests.

Quoted 8 lines
Quoted 7 lines

Hmmm, we can have those endianness ioctls defined but the initial QEMU implementation can be started to support x86 guest/host with little endian and weak memory ordering first. The real trick is to detect legacy guest - I am not sure if it's feasible to shift all the legacy detection work to QEMU, or the kernel has to be part of the detection (e.g. the kick before DRIVER_OK thing we have to duplicate the tracking effort in QEMU) as well. Let me take a further look and get back.

Michael may think differently but I think doing this in Qemu is much easier.

I think the key is whether we position emulating legacy interfaces in QEMU doing translation on top of a v1.0 modern-only device in the kernel, or we allow vdpa core (or you can say vhost-vdpa) and vendor driver to support a transitional model in the kernel that is able to work for both v0.95 and v1.0 drivers, with some slight aid from QEMU for detecting/emulation/shadowing (for e.g CVQ, I/O port relay). I guess for the former we still rely on vendor for a performant data vqs implementation, leaving the question to what it may end up eventually in the kernel is effectively the latter).

Quoted 4 lines
Quoted 2 lines

Thanks,
-Siwei

My suggestion is post the kernel patches, and we can evaluate how much work they are.

Thanks for the feedback. I will take some read then get back, probably after the winter break. Stay tuned.

Thanks,
-Siwei

Quoted 62 lines
Quoted 62 lines
Quoted 62 lines

Thanks

Quoted 58 lines

Meanwhile, I'll check internally to see if a legacy only model would work. Thanks.

Thanks,
-Siwei

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines · Jason Wang
Quoted 50 lines · Michael S. Tsirkin

On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
Detecting it isn't enough though, we will need a new ioctl to notify
the kernel that it's a legacy guest. Ugh :(
Well, although I think adding an ioctl is doable, may I
know what the use
case there will be for kernel to leverage such info
directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed
differentiation (legacy v.s. modern) needed?
BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)
#define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...
Actually, I wonder whether it's good time to just not support
legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config
space or other
stuffs that is presented by vhost-vDPA is not expected to be
accessed by
guest directly. Qemu can do the endian conversion when necessary
in this
case?

Thanks

Overall I would be fine with this approach but we need to avoid breaking
working userspace, qemu releases with vdpa support are out there and
seem to work for people. Any changes need to take that into account
and document compatibility concerns.
Agree, let me check.

I note that any hardware
implementation is already broken for legacy except on platforms with
strong ordering which might be helpful in reducing the scope.
Yes.

Thanks

#61 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 92 lines · Michael S. Tsirkin
Quoted 90 lines · Jason Wang
Quoted 64 lines · Si-Wei Liu
Quoted 60 lines · Jason Wang
Quoted 59 lines · Si-Wei Liu
Quoted 56 lines · Michael S. Tsirkin
Quoted 55 lines · Si-Wei Liu
Quoted 21 lines · Jason Wang
Quoted 20 lines · Si-Wei Liu
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Si-Wei Liu
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion
it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the
support will be completely dropped from the table, is my understanding
correct? Actually we're interested in supporting virtio v0.95 guest for x86,
which is backed by the spec at
https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.

Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Note a subtle difference: what matters is that guest, not host is x86. Matters for emulators which might reorder memory accesses. I guess this enforcement belongs in QEMU then?

Right, I mean to get started, the initial guest driver support and the corresponding QEMU support for transitional vdpa backend can be limited to x86 guest/host only. Since the config space is emulated in QEMU, I suppose it's not hard to enforce in QEMU.

It's more than just config space, most devices have headers before the buffer.

The ordering in datapath (data VQs) would have to rely on vendor's support. Since ORDER_PLATFORM is pretty new (v1.1), I guess vdpa h/w vendor nowadays can/should well support the case when ORDER_PLATFORM is not acked by the driver (actually this feature is filtered out by the QEMU vhost-vdpa driver today), even with v1.0 spec conforming and modern only vDPA device. The control VQ is implemented in software in the kernel, which can be easily accommodated/fixed when needed.

Quoted 9 lines
Quoted 8 lines

QEMU can drive GET_LEGACY,
GET_ENDIAN et al ioctls in advance to get the capability from the individual vendor driver. For that, we need another negotiation protocol similar to vhost_user's protocol_features between the vdpa kernel and QEMU, way before the guest driver is ever probed and its feature negotiation kicks in. Not sure we need a GET_MEMORY_ORDER ioctl call from the device, but we can assume weak ordering for legacy at this point (x86 only)?

I'm lost here, we have get_features() so:

I assume here you refer to get_device_features() that Eli just changed the name.

Quoted 4 lines

1) VERSION_1 means the device uses LE if provided, otherwise natvie
2) ORDER_PLATFORM means device requires platform ordering

Any reason for having a new API for this?

Are you going to enforce all vDPA hardware vendors to support the transitional model for legacy guest?

Quoted 7 lines
Quoted 5 lines

Do we really have other choices?

I suspect the legacy device is never implemented by any vendor:

1) no virtio way to detect host endian

This is even true for transitional device that is conforming to the spec, right?

For hardware, yes.

Quoted 4 lines

The transport specific way to detect host endian is still being discussed and the spec revision is not finalized yet so far as I see. Why this suddenly becomes a requirement/blocker for h/w vendors to implement the transitional model?

It's not a sudden blocker, the problem has existed since day 0 if I was not wrong. That's why the problem looks a little bit complicated and why it would be much simpler if we stick to modern devices.

Quoted 5 lines

Even if the spec is out, this is
pretty new and I suspect not all vendor would follow right away. I hope the software framework can be tolerant with h/w vendors not supporting host endianess (BE specifically) or not detecting it if they would like to support a transitional device for legacy.

Quoted 5 lines
Quoted 1 line

Well, if we know we don't want to support the BE host it would be fine.

I think you guys mean guest not host here. Same for memory ordering etc. What matters is whether guest has barriers etc.

Yes.

Thanks

#62 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

In reply to Si-Wei Liu
Quoted 75 lines · Si-Wei Liu
Quoted 72 lines · Michael S. Tsirkin
Quoted 71 lines · Si-Wei Liu
Quoted 22 lines · Jason Wang
Quoted 21 lines · Si-Wei Liu
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Si-Wei Liu
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.
Quoted 4 lines

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Note a subtle difference: what matters is that guest, not host is x86. Matters for emulators which might reorder memory accesses. I guess this enforcement belongs in QEMU then?

Right, I mean to get started, the initial guest driver support and the corresponding QEMU support for transitional vdpa backend can be limited to x86 guest/host only. Since the config space is emulated in QEMU, I suppose it's not hard to enforce in QEMU.

It's more than just config space, most devices have headers before the buffer.

The ordering in datapath (data VQs) would have to rely on vendor's support. Since ORDER_PLATFORM is pretty new (v1.1), I guess vdpa h/w vendor nowadays can/should well support the case when ORDER_PLATFORM is not acked by the driver (actually this feature is filtered out by the QEMU vhost-vdpa driver today), even with v1.0 spec conforming and modern only vDPA device. The control VQ is implemented in software in the kernel, which can be easily accommodated/fixed when needed.

Quoted 9 lines
Quoted 8 lines

QEMU can drive GET_LEGACY,
GET_ENDIAN et al ioctls in advance to get the capability from the individual vendor driver. For that, we need another negotiation protocol similar to vhost_user's protocol_features between the vdpa kernel and QEMU, way before the guest driver is ever probed and its feature negotiation kicks in. Not sure we need a GET_MEMORY_ORDER ioctl call from the device, but we can assume weak ordering for legacy at this point (x86 only)?

I'm lost here, we have get_features() so:

I assume here you refer to get_device_features() that Eli just changed the name.

Quoted 4 lines

1) VERSION_1 means the device uses LE if provided, otherwise natvie
2) ORDER_PLATFORM means device requires platform ordering

Any reason for having a new API for this?

Are you going to enforce all vDPA hardware vendors to support the transitional model for legacy guest? meaning guest not acknowledging VERSION_1 would use the legacy interfaces captured in the spec section 7.4 (regarding ring layout, native endianness, message framing, vq alignment of 4096, 32bit feature, no features_ok bit in status, IO port interface i.e. all the things) instead? Noted we don't yet have a set_device_features() that allows the vdpa device to tell whether it is operating in transitional or modern-only mode. For software virtio, all support for the legacy part in a transitional model has been built up there already, however, it's not easy for vDPA vendors to implement all the requirements for an all-or-nothing legacy guest support (big endian guest for example). To these vendors, the legacy support within a transitional model is more of feature to them and it's best to leave some flexibility for them to implement partial support for legacy. That in turn calls out the need for a vhost-user protocol feature like negotiation API that can prohibit those unsupported guest setups to as early as backend_init before launching the VM.

Quoted 8 lines
Quoted 3 lines

Right. Of note is the fact that it's a spec bug which I hope yet to fix, though due to existing guest code the fix won't be complete.

I thought at one point you pointed out to me that the spec does allow config space read before claiming features_ok, and only config write before features_ok is prohibited. I haven't read up the full thread of Halil's VERSION_1 for transitional big endian device yet, but what is the spec bug you hope to fix?

Allowing config space reads before features_ok seemed useful years ago but in practice is only causing bugs and complicating device design.

Quoted 140 lines
Quoted 8 lines

WRT ioctls, One thing we can do though is abuse set_features where it's called by QEMU early on with just the VERSION_1 bit set, to distinguish between legacy and modern interface. This before config space accesses and FEATURES_OK.

Halil has been working on this, pls take a look and maybe help him out.

Interesting thread, am reading now and see how I may leverage or help there.

Quoted 56 lines
Quoted 56 lines
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 28 lines

I
checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

Quoted 14 lines
Quoted 14 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

             * If it does happen we assume a legacy guest.
             */
            if (!vdev->features_valid)
                    vdpa_set_features(vdev, 0);
            ops->get_config(vdev, offset, buf, len);
Quoted 7 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 8 lines

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure. Or are you suggesting limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Thanks,
-Siwei

I don't know for sure. Take a look at the work Halil was doing to try and support transitional devices with BE guests.

Quoted 8 lines
Quoted 7 lines

Hmmm, we can have those endianness ioctls defined but the initial QEMU implementation can be started to support x86 guest/host with little endian and weak memory ordering first. The real trick is to detect legacy guest - I am not sure if it's feasible to shift all the legacy detection work to QEMU, or the kernel has to be part of the detection (e.g. the kick before DRIVER_OK thing we have to duplicate the tracking effort in QEMU) as well. Let me take a further look and get back.

Michael may think differently but I think doing this in Qemu is much easier.

I think the key is whether we position emulating legacy interfaces in QEMU doing translation on top of a v1.0 modern-only device in the kernel, or we allow vdpa core (or you can say vhost-vdpa) and vendor driver to support a transitional model in the kernel that is able to work for both v0.95 and v1.0 drivers, with some slight aid from QEMU for detecting/emulation/shadowing (for e.g CVQ, I/O port relay). I guess for the former we still rely on vendor for a performant data vqs implementation, leaving the question to what it may end up eventually in the kernel is effectively the latter).

Quoted 5 lines
Quoted 2 lines

Thanks,
-Siwei

My suggestion is post the kernel patches, and we can evaluate how much work they are.

Thanks for the feedback. I will take some read then get back, probably after the winter break. Stay tuned.

Thanks,
-Siwei

Quoted 63 lines
Quoted 63 lines
Quoted 63 lines

Thanks

Quoted 58 lines

Meanwhile, I'll check internally to see if a legacy only model would work. Thanks.

Thanks,
-Siwei

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines · Jason Wang
Quoted 50 lines · Michael S. Tsirkin
Quoted 32 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 15 lines · Si-Wei Liu

Detecting it isn't enough though, we will need a new ioctl to notify
the kernel that it's a legacy guest. Ugh :(
Well, although I think adding an ioctl is doable, may I
know what the use
case there will be for kernel to leverage such info
directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed
differentiation (legacy v.s. modern) needed?
BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)
#define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

#63 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

In reply to Si-Wei Liu
Quoted 34 lines · Si-Wei Liu
Quoted 30 lines · Jason Wang
Quoted 29 lines · Si-Wei Liu
Quoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Si-Wei Liu
Quoted 15 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

Quoted 5 lines
Quoted 2 lines

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Note a subtle difference: what matters is that guest, not host is x86. Matters for emulators which might reorder memory accesses. I guess this enforcement belongs in QEMU then?

Right, I mean to get started, the initial guest driver support and the corresponding QEMU support for transitional vdpa backend can be limited to x86 guest/host only. Since the config space is emulated in QEMU, I suppose it's not hard to enforce in QEMU.

Quoted 7 lines
Quoted 1 line

It's more than just config space, most devices have headers before the buffer.

The ordering in datapath (data VQs) would have to rely on vendor's support. Since ORDER_PLATFORM is pretty new (v1.1), I guess vdpa h/w vendor nowadays can/should well support the case when ORDER_PLATFORM is not acked by the driver (actually this feature is filtered out by the QEMU vhost-vdpa driver today), even with v1.0 spec conforming and modern only vDPA device.

That's a bug that needs to be fixed.

Quoted 86 lines

The control VQ is implemented in software in the kernel, which can be easily accommodated/fixed when needed.

Quoted 10 lines
Quoted 9 lines

QEMU can drive GET_LEGACY,
GET_ENDIAN et al ioctls in advance to get the capability from the individual vendor driver. For that, we need another negotiation protocol similar to vhost_user's protocol_features between the vdpa kernel and QEMU, way before the guest driver is ever probed and its feature negotiation kicks in. Not sure we need a GET_MEMORY_ORDER ioctl call from the device, but we can assume weak ordering for legacy at this point (x86 only)?

I'm lost here, we have get_features() so:

I assume here you refer to get_device_features() that Eli just changed the name.

Quoted 5 lines

1) VERSION_1 means the device uses LE if provided, otherwise natvie
2) ORDER_PLATFORM means device requires platform ordering

Any reason for having a new API for this?

Are you going to enforce all vDPA hardware vendors to support the transitional model for legacy guest? meaning guest not acknowledging VERSION_1 would use the legacy interfaces captured in the spec section 7.4 (regarding ring layout, native endianness, message framing, vq alignment of 4096, 32bit feature, no features_ok bit in status, IO port interface i.e. all the things) instead? Noted we don't yet have a set_device_features() that allows the vdpa device to tell whether it is operating in transitional or modern-only mode. For software virtio, all support for the legacy part in a transitional model has been built up there already, however, it's not easy for vDPA vendors to implement all the requirements for an all-or-nothing legacy guest support (big endian guest for example). To these vendors, the legacy support within a transitional model is more of feature to them and it's best to leave some flexibility for them to implement partial support for legacy. That in turn calls out the need for a vhost-user protocol feature like negotiation API that can prohibit those unsupported guest setups to as early as backend_init before launching the VM.

Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 29 lines

I
checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

Quoted 14 lines
Quoted 14 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

            * If it does happen we assume a legacy guest.
            */
           if (!vdev->features_valid)
                   vdpa_set_features(vdev, 0);
           ops->get_config(vdev, offset, buf, len);
Quoted 7 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 8 lines

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure. Or are you suggesting limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Thanks,
-Siwei

I don't know for sure. Take a look at the work Halil was doing to try and support transitional devices with BE guests.

Quoted 8 lines
Quoted 7 lines

Hmmm, we can have those endianness ioctls defined but the initial QEMU implementation can be started to support x86 guest/host with little endian and weak memory ordering first. The real trick is to detect legacy guest - I am not sure if it's feasible to shift all the legacy detection work to QEMU, or the kernel has to be part of the detection (e.g. the kick before DRIVER_OK thing we have to duplicate the tracking effort in QEMU) as well. Let me take a further look and get back.

Michael may think differently but I think doing this in Qemu is much easier.

Quoted 9 lines

I think the key is whether we position emulating legacy interfaces in QEMU doing translation on top of a v1.0 modern-only device in the kernel, or we allow vdpa core (or you can say vhost-vdpa) and vendor driver to support a transitional model in the kernel that is able to work for both v0.95 and v1.0 drivers, with some slight aid from QEMU for detecting/emulation/shadowing (for e.g CVQ, I/O port relay). I guess for the former we still rely on vendor for a performant data vqs implementation, leaving the question to what it may end up eventually in the kernel is effectively the latter).

I think we can do the legacy interface emulation on top of the shadow VQ. And we know it works for sure. But I agree, it would be much easier if we depend on the vendor to implement a transitional device.

So assuming we depend on the vendor, I don't see anything that is strictly needed in the kernel, the kick or config access before DRIVER_OK can all be handled easily in Qemu unless I miss something. The only value to do that in the kernel is that it can work for virtio-vdpa, but modern only virito-vpda is sufficient; we don't need any legacy stuff for that.

Thanks

Quoted 69 lines

Thanks,
-Siwei

Quoted 64 lines

Thanks

Quoted 59 lines

Meanwhile, I'll check internally to see if a legacy only model would work. Thanks.

Thanks,
-Siwei

Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines · Jason Wang
Quoted 50 lines · Michael S. Tsirkin
Quoted 32 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines
Quoted 2 lines

Detecting it isn't enough though, we will need a new ioctl to notify
the kernel that it's a legacy guest. Ugh :(

Well, although I think adding an ioctl is doable, may I know what the use
case there will be for kernel to leverage such info directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

author
#64 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 134 lines · Jason Wang
Quoted 32 lines · Si-Wei Liu
Quoted 29 lines · Jason Wang
Quoted 28 lines · Si-Wei Liu
Quoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Si-Wei Liu
Quoted 15 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

Quoted 5 lines
Quoted 2 lines

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Note a subtle difference: what matters is that guest, not host is x86. Matters for emulators which might reorder memory accesses. I guess this enforcement belongs in QEMU then?

Right, I mean to get started, the initial guest driver support and the corresponding QEMU support for transitional vdpa backend can be limited to x86 guest/host only. Since the config space is emulated in QEMU, I suppose it's not hard to enforce in QEMU.

Quoted 7 lines
Quoted 1 line

It's more than just config space, most devices have headers before the buffer.

The ordering in datapath (data VQs) would have to rely on vendor's support. Since ORDER_PLATFORM is pretty new (v1.1), I guess vdpa h/w vendor nowadays can/should well support the case when ORDER_PLATFORM is not acked by the driver (actually this feature is filtered out by the QEMU vhost-vdpa driver today), even with v1.0 spec conforming and modern only vDPA device.

That's a bug that needs to be fixed.

Quoted 83 lines

The control VQ is implemented in software in the kernel, which can be easily accommodated/fixed when needed.

Quoted 9 lines
Quoted 8 lines

QEMU can drive GET_LEGACY,
GET_ENDIAN et al ioctls in advance to get the capability from the individual vendor driver. For that, we need another negotiation protocol similar to vhost_user's protocol_features between the vdpa kernel and QEMU, way before the guest driver is ever probed and its feature negotiation kicks in. Not sure we need a GET_MEMORY_ORDER ioctl call from the device, but we can assume weak ordering for legacy at this point (x86 only)?

I'm lost here, we have get_features() so:

I assume here you refer to get_device_features() that Eli just changed the name.

Quoted 4 lines

1) VERSION_1 means the device uses LE if provided, otherwise natvie
2) ORDER_PLATFORM means device requires platform ordering

Any reason for having a new API for this?

Are you going to enforce all vDPA hardware vendors to support the transitional model for legacy guest? meaning guest not acknowledging VERSION_1 would use the legacy interfaces captured in the spec section 7.4 (regarding ring layout, native endianness, message framing, vq alignment of 4096, 32bit feature, no features_ok bit in status, IO port interface i.e. all the things) instead? Noted we don't yet have a set_device_features() that allows the vdpa device to tell whether it is operating in transitional or modern-only mode. For software virtio, all support for the legacy part in a transitional model has been built up there already, however, it's not easy for vDPA vendors to implement all the requirements for an all-or-nothing legacy guest support (big endian guest for example). To these vendors, the legacy support within a transitional model is more of feature to them and it's best to leave some flexibility for them to implement partial support for legacy. That in turn calls out the need for a vhost-user protocol feature like negotiation API that can prohibit those unsupported guest setups to as early as backend_init before launching the VM.

Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 28 lines

I
checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

Quoted 14 lines
Quoted 14 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

             * If it does happen we assume a legacy guest.
             */
            if (!vdev->features_valid)
                    vdpa_set_features(vdev, 0);
            ops->get_config(vdev, offset, buf, len);
Quoted 7 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 8 lines

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure. Or are you suggesting limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Thanks,
-Siwei

I don't know for sure. Take a look at the work Halil was doing to try and support transitional devices with BE guests.

Quoted 8 lines
Quoted 7 lines

Hmmm, we can have those endianness ioctls defined but the initial QEMU implementation can be started to support x86 guest/host with little endian and weak memory ordering first. The real trick is to detect legacy guest - I am not sure if it's feasible to shift all the legacy detection work to QEMU, or the kernel has to be part of the detection (e.g. the kick before DRIVER_OK thing we have to duplicate the tracking effort in QEMU) as well. Let me take a further look and get back.

Michael may think differently but I think doing this in Qemu is much easier.

Quoted 9 lines

I think the key is whether we position emulating legacy interfaces in QEMU doing translation on top of a v1.0 modern-only device in the kernel, or we allow vdpa core (or you can say vhost-vdpa) and vendor driver to support a transitional model in the kernel that is able to work for both v0.95 and v1.0 drivers, with some slight aid from QEMU for detecting/emulation/shadowing (for e.g CVQ, I/O port relay). I guess for the former we still rely on vendor for a performant data vqs implementation, leaving the question to what it may end up eventually in the kernel is effectively the latter).

Quoted 3 lines

I think we can do the legacy interface emulation on top of the shadow VQ. And we know it works for sure. But I agree, it would be much easier if we depend on the vendor to implement a transitional device.

First I am not sure if there's a convincing case for users to deploy vDPA with shadow (data) VQ against the pure software based backend. Please enlighten me if there is.

For us, the point to deploy vDPA for legacy guest is the acceleration (what "A" stands for in "vDPA") part of it so that we can leverage the hardware potential if at all possible. Not sure how the shadow VQ implementation can easily deal with datapath acceleration without losing too much performance?

Quoted 3 lines

So assuming we depend on the vendor, I don't see anything that is strictly needed in the kernel, the kick or config access before DRIVER_OK can all be handled easily in Qemu unless I miss something.

Right, that's what I think too it's not quite a lot of work in the kernel if vendor device offers the aid/support for transitional. The kernel only provides the abstraction of device model (transitional or modern-only), while vendor driver may implement early platform feature discovery and apply legacy specific quirks (unsupported endianness, mismatched page size, unsupported host memory ordering model) that the device can't adapt to. I don't say we have to depend on the vendor, but the point is that we must assume fully spec compliant transitional support (the datapath in particular) from the vendor to get started, as I guess it's probably the main motivation for users to deploy it - acceleration of legacy guest workload without exhausting host computing resource. Even if we get started with shadow VQ to mediate and translate the datapath, eventually it may evolve towards leveraging datapath offload to hardware if acceleration is the only convincing use case for legacy support.

Thanks,
-Siwei

Quoted 71 lines

The only value to do that in the kernel is that it can work for virtio-vdpa, but modern only virito-vpda is sufficient; we don't need any legacy stuff for that.

Thanks

Quoted 65 lines

Thanks,
-Siwei

Quoted 62 lines

Thanks

Quoted 58 lines

Meanwhile, I'll check internally to see if a legacy only model would work. Thanks.

Thanks,
-Siwei

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines · Jason Wang
Quoted 50 lines · Michael S. Tsirkin
Quoted 32 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 9 lines · Si-Wei Liu
Quoted 8 lines

Detecting it isn't enough though, we will need a new ioctl to notify
the kernel that it's a legacy guest. Ugh :(
Well, although I think adding an ioctl is doable, may I
know what the use
case there will be for kernel to leverage such info
directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed
differentiation (legacy v.s. modern) needed?

Quoted 6 lines

BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int) #define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

#65 lore raw

Re: vdpa legacy guest support (was Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero)

Quoted 138 lines · Si-Wei Liu
Quoted 134 lines · Jason Wang
Quoted 32 lines · Si-Wei Liu
Quoted 29 lines · Jason Wang
Quoted 28 lines · Si-Wei Liu
Quoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Si-Wei Liu
Quoted 15 lines · Michael S. Tsirkin
Quoted 10 lines · Si-Wei Liu

Sorry for reviving this ancient thread. I was kinda lost for the conclusion it ended up with. I have the following questions,

1. legacy guest support: from the past conversations it doesn't seem the support will be completely dropped from the table, is my understanding correct? Actually we're interested in supporting virtio v0.95 guest for x86, which is backed by the spec at

https://urldefense.com/v3/__https://ozlabs.org/*rusty/virtio-spec/virtio-0.9.5.pdf__;fg!!ACWV5N9M2RV99hQ!dTKmzJwwRsFM7BtSuTDu1cNly5n4XCotH0WYmidzGqHSXt40i7ZU43UcNg7GYxZg$ . Though I'm not sure
if there's request/need to support wilder legacy virtio versions earlier
beyond.

I personally feel it's less work to add in kernel than try to work around it in userspace. Jason feels differently. Maybe post the patches and this will prove to Jason it's not too terrible?

Quoted 5 lines
Quoted 2 lines

I suppose if the vdpa vendor does support 0.95 in the datapath and ring layout level and is limited to x86 only, there should be easy way out.

Note a subtle difference: what matters is that guest, not host is x86. Matters for emulators which might reorder memory accesses. I guess this enforcement belongs in QEMU then?

Right, I mean to get started, the initial guest driver support and the corresponding QEMU support for transitional vdpa backend can be limited to x86 guest/host only. Since the config space is emulated in QEMU, I suppose it's not hard to enforce in QEMU.

Quoted 7 lines
Quoted 1 line

It's more than just config space, most devices have headers before the buffer.

The ordering in datapath (data VQs) would have to rely on vendor's support. Since ORDER_PLATFORM is pretty new (v1.1), I guess vdpa h/w vendor nowadays can/should well support the case when ORDER_PLATFORM is not acked by the driver (actually this feature is filtered out by the QEMU vhost-vdpa driver today), even with v1.0 spec conforming and modern only vDPA device.

That's a bug that needs to be fixed.

Quoted 92 lines

The control VQ is implemented in software in the kernel, which can be easily accommodated/fixed when needed.

Quoted 9 lines
Quoted 8 lines

QEMU can drive GET_LEGACY,
GET_ENDIAN et al ioctls in advance to get the capability from the individual vendor driver. For that, we need another negotiation protocol similar to vhost_user's protocol_features between the vdpa kernel and QEMU, way before the guest driver is ever probed and its feature negotiation kicks in. Not sure we need a GET_MEMORY_ORDER ioctl call from the device, but we can assume weak ordering for legacy at this point (x86 only)?

I'm lost here, we have get_features() so:

I assume here you refer to get_device_features() that Eli just changed the name.

Quoted 4 lines

1) VERSION_1 means the device uses LE if provided, otherwise natvie
2) ORDER_PLATFORM means device requires platform ordering

Any reason for having a new API for this?

Are you going to enforce all vDPA hardware vendors to support the transitional model for legacy guest? meaning guest not acknowledging VERSION_1 would use the legacy interfaces captured in the spec section 7.4 (regarding ring layout, native endianness, message framing, vq alignment of 4096, 32bit feature, no features_ok bit in status, IO port interface i.e. all the things) instead? Noted we don't yet have a set_device_features() that allows the vdpa device to tell whether it is operating in transitional or modern-only mode. For software virtio, all support for the legacy part in a transitional model has been built up there already, however, it's not easy for vDPA vendors to implement all the requirements for an all-or-nothing legacy guest support (big endian guest for example). To these vendors, the legacy support within a transitional model is more of feature to them and it's best to leave some flexibility for them to implement partial support for legacy. That in turn calls out the need for a vhost-user protocol feature like negotiation API that can prohibit those unsupported guest setups to as early as backend_init before launching the VM.

Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 28 lines

I
checked with Eli and other Mellanox/NVDIA folks for hardware/firmware level 0.95 support, it seems all the ingredient had been there already dated back to the DPDK days. The only major thing limiting is in the vDPA software that the current vdpa core has the assumption around VIRTIO_F_ACCESS_PLATFORM for a few DMA setup ops, which is virtio 1.0 only.

Quoted 14 lines
Quoted 14 lines

2. suppose some form of legacy guest support needs to be there, how do we deal with the bogus assumption below in vdpa_get_config() in the short term? It looks one of the intuitive fix is to move the vdpa_set_features call out of vdpa_get_config() to vdpa_set_config().

/*
* Config accesses aren't supposed to trigger before features are
set.

             * If it does happen we assume a legacy guest.
             */
            if (!vdev->features_valid)
                    vdpa_set_features(vdev, 0);
            ops->get_config(vdev, offset, buf, len);
Quoted 7 lines
Quoted 4 lines

I can post a patch to fix 2) if there's consensus already reached.

Thanks,
-Siwei

I'm not sure how important it is to change that. In any case it only affects transitional devices, right? Legacy only should not care ...

Quoted 8 lines

Yes I'd like to distinguish legacy driver (suppose it is 0.95) against the modern one in a transitional device model rather than being legacy only. That way a v0.95 and v1.0 supporting vdpa parent can support both types of guests without having to reconfigure. Or are you suggesting limit to legacy only at the time of vdpa creation would simplify the implementation a lot?

Thanks,
-Siwei

I don't know for sure. Take a look at the work Halil was doing to try and support transitional devices with BE guests.

Quoted 8 lines
Quoted 7 lines

Hmmm, we can have those endianness ioctls defined but the initial QEMU implementation can be started to support x86 guest/host with little endian and weak memory ordering first. The real trick is to detect legacy guest - I am not sure if it's feasible to shift all the legacy detection work to QEMU, or the kernel has to be part of the detection (e.g. the kick before DRIVER_OK thing we have to duplicate the tracking effort in QEMU) as well. Let me take a further look and get back.

Michael may think differently but I think doing this in Qemu is much easier.

I think the key is whether we position emulating legacy interfaces in QEMU doing translation on top of a v1.0 modern-only device in the kernel, or we allow vdpa core (or you can say vhost-vdpa) and vendor driver to support a transitional model in the kernel that is able to work for both v0.95 and v1.0 drivers, with some slight aid from QEMU for detecting/emulation/shadowing (for e.g CVQ, I/O port relay). I guess for the former we still rely on vendor for a performant data vqs implementation, leaving the question to what it may end up eventually in the kernel is effectively the latter).

Quoted 6 lines
Quoted 3 lines

I think we can do the legacy interface emulation on top of the shadow VQ. And we know it works for sure. But I agree, it would be much easier if we depend on the vendor to implement a transitional device.

First I am not sure if there's a convincing case for users to deploy vDPA with shadow (data) VQ against the pure software based backend. Please enlighten me if there is.

The problem is shadow VQ is the only solution that can works for all the cases.

Quoted 6 lines

For us, the point to deploy vDPA for legacy guest is the acceleration (what "A" stands for in "vDPA") part of it so that we can leverage the hardware potential if at all possible. Not sure how the shadow VQ implementation can easily deal with datapath acceleration without losing too much performance?

It's not easy, shadow VQ will lose performance for sure.

Quoted 4 lines
Quoted 4 lines

So assuming we depend on the vendor, I don't see anything that is strictly needed in the kernel, the kick or config access before DRIVER_OK can all be handled easily in Qemu unless I miss something.

Quoted 15 lines

Right, that's what I think too it's not quite a lot of work in the kernel if vendor device offers the aid/support for transitional. The kernel only provides the abstraction of device model (transitional or modern-only), while vendor driver may implement early platform feature discovery and apply legacy specific quirks (unsupported endianness, mismatched page size, unsupported host memory ordering model) that the device can't adapt to. I don't say we have to depend on the vendor, but the point is that we must assume fully spec compliant transitional support (the datapath in particular) from the vendor to get started, as I guess it's probably the main motivation for users to deploy it - acceleration of legacy guest workload without exhausting host computing resource. Even if we get started with shadow VQ to mediate and translate the datapath, eventually it may evolve towards leveraging datapath offload to hardware if acceleration is the only convincing use case for legacy support.

Yes, so as discussed, I don't object the idea, kernel patches are more than welcomed.

Thanks

Quoted 75 lines

Thanks,
-Siwei

Quoted 71 lines

The only value to do that in the kernel is that it can work for virtio-vdpa, but modern only virito-vpda is sufficient; we don't need any legacy stuff for that.

Thanks

Quoted 65 lines

Thanks,
-Siwei

Quoted 62 lines

Thanks

Quoted 58 lines

Meanwhile, I'll check internally to see if a legacy only model would work. Thanks.

Thanks,
-Siwei

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines · Jason Wang
Quoted 50 lines · Michael S. Tsirkin
Quoted 32 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 15 lines · Si-Wei Liu

Detecting it isn't enough though, we will need a new ioctl to notify
the kernel that it's a legacy guest. Ugh :(
Well, although I think adding an ioctl is doable, may I
know what the use
case there will be for kernel to leverage such info
directly? Is there a
case QEMU can't do with dedicate ioctls later if there's indeed
differentiation (legacy v.s. modern) needed?
BTW a good API could be

#define VHOST_SET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)
#define VHOST_GET_ENDIAN _IOW(VHOST_VIRTIO, ?, int)

we did it per vring but maybe that was a mistake ...

Actually, I wonder whether it's good time to just not support legacy driver
for vDPA. Consider:

1) It's definition is no-normative
2) A lot of budren of codes

So qemu can still present the legacy device since the config space or other
stuffs that is presented by vhost-vDPA is not expected to be accessed by
guest directly. Qemu can do the endian conversion when necessary in this
case?

Quoted 6 lines
Quoted 2 lines

Thanks

Overall I would be fine with this approach but we need to avoid breaking working userspace, qemu releases with vdpa support are out there and seem to work for people. Any changes need to take that into account and document compatibility concerns.

Agree, let me check.

Quoted 3 lines

I note that any hardware
implementation is already broken for legacy except on platforms with strong ordering which might be helpful in reducing the scope.

Yes.

Thanks

author
#66 lore raw
In reply to Jason Wang
Quoted 15 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

Quoted 8 lines

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use. "

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

-Siwei

Quoted 45 lines

Thanks

Quoted 41 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")

---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------

  1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -7
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64 mlx5_vdpa_get_features(struct 
 vdpa_device *vdev)
       return mvdev->mlx_features;
   }
   -static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
   static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
   {

      int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -3
@@ -1558,18 +1550,13 @@ static int mlx5_vdpa_set_features(struct 
 vdpa_device *vdev, u64 features)
   {
       struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
       struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-    int err;
         print_features(mvdev, features, true);
   -    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
Quoted 9 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features) · line 1562

Quoted 8 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -2
-
       ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
       ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
       ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
   }
     static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#67 lore raw
Quoted 20 lines · Si-Wei Liu
Quoted 17 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

Quoted 8 lines
Quoted 6 lines

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use. "

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

Yes, but the problem is we can't detect whether or not it's an legacy guest (e.g feature is not set).

Quoted 2 lines

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable.

Since from vhost-vDPA point of view the driver is Qemu, it means we need make qemu vhost-vDPA driver spec complaint.

E.g how about:

1) revert 452639a64ad8 and fix Qemu? In Qemu, during vhost-vDPA initialization, do a minial config sync by neogitating minimal features (e.g just VIRTIO_F_ACCESS_PLATFORM). When FEATURE_OK is not set from guest, we can only allow it to access the config space that is emulated by Qemu?

Then

Quoted 1 line

Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

2) Fix the virtio driver bug.

Or a quick workaround is to set (VIRTIO_F_ACCESS_PLATFORM instead of 0) in this case.

Thanks

Quoted 58 lines

-Siwei

Quoted 54 lines

Thanks

Quoted 49 lines

Rejecting reset to 0
prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")

---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------

  1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -7
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64 mlx5_vdpa_get_features(struct 
 vdpa_device *vdev)
       return mvdev->mlx_features;
   }
   -static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 features)
-{
-    if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-        return -EOPNOTSUPP;
-
-    return 0;
-}
-
   static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
   {

      int err;

drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -5
@@ -1558,18 +1550,13 @@ static int mlx5_vdpa_set_features(struct 
 vdpa_device *vdev, u64 features)
   {
       struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
       struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-    int err;
         print_features(mvdev, features, true);
   -    err = verify_min_features(mvdev, features);
-    if (err)
-        return err;
-
       ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
       ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
       ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-    return err;
+    return 0;
   }
     static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#68 lore raw
In reply to Si-Wei Liu
Quoted 27 lines · Si-Wei Liu
Quoted 24 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use.
"

Quoted 8 lines
Quoted 1 line

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

Oh you are right:

static int virtnet_validate(struct virtio_device *vdev)

{
        if (!vdev->config->get) {
                dev_err(&vdev->dev, "%s failure: config access disabled\n",
                        __func__);
                return -EINVAL;
        }

        if (!virtnet_validate_features(vdev))
                return -EINVAL;

        if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                int mtu = virtio_cread16(vdev,
                                         offsetof(struct virtio_net_config,
                                                  mtu));
                if (mtu < MIN_MTU)
                        __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);
        }

        return 0;
}

And the spec says:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Item 4 on the list explicitly allows reading config space before FEATURES_OK.

I conclude that VIRTIO_NET_F_MTU is set means "set in device features".

Generally it is worth going over feature dependent config fields and checking whether they should be present when device feature is set or when feature bit has been negotiated, and making this clear.

Signature · 6 lines
MST


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
#69 lore raw
Quoted 36 lines · Michael S. Tsirkin
Quoted 24 lines · Si-Wei Liu
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use.
"

Quoted 7 lines
Quoted 1 line

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

Oh you are right:

static int virtnet_validate(struct virtio_device *vdev)

Quoted 16 lines
{
         if (!vdev->config->get) {
                 dev_err(&vdev->dev, "%s failure: config access disabled\n",
                         __func__);
                 return -EINVAL;
         }

         if (!virtnet_validate_features(vdev))
                 return -EINVAL;

         if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                 int mtu = virtio_cread16(vdev,
                                          offsetof(struct virtio_net_config,
                                                   mtu));
                 if (mtu < MIN_MTU)
                         __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);

I wonder why not simply fail here?

Quoted 23 lines
         }

         return 0;
}

And the spec says:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 4 lines

Item 4 on the list explicitly allows reading config space before FEATURES_OK.

I conclude that VIRTIO_NET_F_MTU is set means "set in device features".

So this probably need some clarification. "is set" is used many times in the spec that has different implications.

Thanks

Quoted 5 lines

Generally it is worth going over feature dependent config fields and checking whether they should be present when device feature is set or when feature bit has been negotiated, and making this clear.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#70 lore raw
Quoted 56 lines · Jason Wang
Quoted 36 lines · Michael S. Tsirkin
Quoted 24 lines · Si-Wei Liu
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use.
"

Quoted 7 lines
Quoted 1 line

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

Oh you are right:

static int virtnet_validate(struct virtio_device *vdev)

Quoted 16 lines
{
         if (!vdev->config->get) {
                 dev_err(&vdev->dev, "%s failure: config access disabled\n",
                         __func__);
                 return -EINVAL;
         }

         if (!virtnet_validate_features(vdev))
                 return -EINVAL;

         if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                 int mtu = virtio_cread16(vdev,
                                          offsetof(struct virtio_net_config,
                                                   mtu));
                 if (mtu < MIN_MTU)
                         __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);
Quoted 1 line

I wonder why not simply fail here?

Back in 2016 it went like this:

	On Thu, Jun 02, 2016 at 05:10:59PM -0400, Aaron Conole wrote:
	> +     if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
	> +             dev->mtu = virtio_cread16(vdev,
	> +                                       offsetof(struct virtio_net_config,
	> +                                                mtu));
	> +     }
	> +
	>       if (vi->any_header_sg)
	>               dev->needed_headroom = vi->hdr_len;
	> 

	One comment though: I think we should validate the mtu.
	If it's invalid, clear VIRTIO_NET_F_MTU and ignore.

Too late at this point :)

I guess it's a way to tell device "I can not live with this MTU", device can fail FEATURES_OK if it wants to. MIN_MTU
is an internal linux thing and at the time I felt it's better to try to make progress.

Quoted 27 lines
Quoted 27 lines
         }

         return 0;
}

And the spec says:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Item 4 on the list explicitly allows reading config space before FEATURES_OK.

Quoted 14 lines
Quoted 1 line

I conclude that VIRTIO_NET_F_MTU is set means "set in device features".

So this probably need some clarification. "is set" is used many times in the spec that has different implications.

Thanks

Quoted 5 lines

Generally it is worth going over feature dependent config fields and checking whether they should be present when device feature is set or when feature bit has been negotiated, and making this clear.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#71 lore raw
Quoted 71 lines · Michael S. Tsirkin
Quoted 45 lines · Jason Wang
Quoted 44 lines · Michael S. Tsirkin
Quoted 22 lines · Si-Wei Liu
Quoted 21 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use.
"

Quoted 7 lines
Quoted 1 line

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

Oh you are right:

static int virtnet_validate(struct virtio_device *vdev)

{
          if (!vdev->config->get) {
                  dev_err(&vdev->dev, "%s failure: config access disabled\n",
                          __func__);
                  return -EINVAL;
          }

          if (!virtnet_validate_features(vdev))
                  return -EINVAL;
Quoted 8 lines
Quoted 6 lines
          if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                  int mtu = virtio_cread16(vdev,
                                           offsetof(struct virtio_net_config,
                                                    mtu));
                  if (mtu < MIN_MTU)
                          __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);

I wonder why not simply fail here?

Back in 2016 it went like this:

	On Thu, Jun 02, 2016 at 05:10:59PM -0400, Aaron Conole wrote:
	> +     if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
	> +             dev->mtu = virtio_cread16(vdev,
	> +                                       offsetof(struct virtio_net_config,
	> +                                                mtu));
	> +     }
	> +
	>       if (vi->any_header_sg)
	>               dev->needed_headroom = vi->hdr_len;
	>

	One comment though: I think we should validate the mtu.
	If it's invalid, clear VIRTIO_NET_F_MTU and ignore.
Quoted 6 lines

Too late at this point :)

I guess it's a way to tell device "I can not live with this MTU", device can fail FEATURES_OK if it wants to. MIN_MTU
is an internal linux thing and at the time I felt it's better to try to make progress.

What if e.g the device advertise a large MTU. E.g 64K here? In that case, the driver can not live either. Clearing MTU won't help here.

Thanks

Quoted 33 lines
Quoted 33 lines
Quoted 25 lines

          }

          return 0;
}

And the spec says:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 4 lines

Item 4 on the list explicitly allows reading config space before FEATURES_OK.

I conclude that VIRTIO_NET_F_MTU is set means "set in device features".

So this probably need some clarification. "is set" is used many times in the spec that has different implications.

Quoted 7 lines
Quoted 7 lines

Thanks

Quoted 4 lines

Generally it is worth going over feature dependent config fields and checking whether they should be present when device feature is set or when feature bit has been negotiated, and making this clear.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#72 lore raw
Quoted 75 lines · Jason Wang
Quoted 73 lines · Michael S. Tsirkin
Quoted 45 lines · Jason Wang
Quoted 44 lines · Michael S. Tsirkin
Quoted 22 lines · Si-Wei Liu
Quoted 21 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use.
"

Quoted 7 lines
Quoted 1 line

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

Oh  you are right:

static int virtnet_validate(struct virtio_device *vdev)
{
          if (!vdev->config->get) {
                  dev_err(&vdev->dev, "%s failure: config access disabled\n", __func__);
                  return -EINVAL;
          }

          if (!virtnet_validate_features(vdev))
                  return -EINVAL;

Quoted 8 lines
Quoted 6 lines

          if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                  int mtu = virtio_cread16(vdev,
                                           offsetof(struct virtio_net_config, mtu));
                  if (mtu < MIN_MTU)
                          __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);

I wonder why not simply fail here?

Back in 2016 it went like this:

    On Thu, Jun 02, 2016 at 05:10:59PM -0400, Aaron Conole wrote:
    > +     if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
    > +             dev->mtu = virtio_cread16(vdev,
    > +                                       offsetof(struct virtio_net_config, > +                                                mtu));
    > +     }
    > +
    >       if (vi->any_header_sg)
    >               dev->needed_headroom = vi->hdr_len;
    >

    One comment though: I think we should validate the mtu. If it's invalid, clear VIRTIO_NET_F_MTU and ignore.

Too late at this point :)

Quoted 7 lines
Quoted 4 lines

I guess it's a way to tell device "I can not live with this MTU", device can fail FEATURES_OK if it wants to. MIN_MTU
is an internal linux thing and at the time I felt it's better to try to make progress.

What if e.g the device advertise a large MTU. E.g 64K here?

Ok, consider we use add_recvbuf_small() when neither GSO nor mrg_rxbuf. This means we should fail the probing if MTU is greater than 1500 in this case.

Thanks

Quoted 46 lines

In that case, the driver can not live either. Clearing MTU won't help here.

Thanks

Quoted 40 lines
Quoted 40 lines
Quoted 25 lines

          }

          return 0;
}

And the spec says:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 4 lines

Item 4 on the list explicitly allows reading config space before FEATURES_OK.

I conclude that VIRTIO_NET_F_MTU is set means "set in device features".

So this probably need some clarification. "is set" is used many times in the spec that has different implications.

Thanks

Quoted 4 lines

Generally it is worth going over feature dependent config fields and checking whether they should be present when device feature is set or when feature bit has been negotiated, and making this clear.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#73 lore raw
In reply to Jason Wang
Quoted 55 lines · On Tue, 23 Feb 2021 17:46:20 +0800 Jason Wang <[email protected]> wrote:
Quoted 36 lines · Michael S. Tsirkin
Quoted 24 lines · Si-Wei Liu
Quoted 22 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use.
"

Quoted 7 lines
Quoted 1 line

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

Oh you are right:

static int virtnet_validate(struct virtio_device *vdev)

Quoted 16 lines
{
         if (!vdev->config->get) {
                 dev_err(&vdev->dev, "%s failure: config access disabled\n",
                         __func__);
                 return -EINVAL;
         }

         if (!virtnet_validate_features(vdev))
                 return -EINVAL;

         if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                 int mtu = virtio_cread16(vdev,
                                          offsetof(struct virtio_net_config,
                                                   mtu));
                 if (mtu < MIN_MTU)
                         __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);  
Quoted 1 line

I wonder why not simply fail here?

I think both failing or not accepting the feature can be argued to make
sense: "the device presented us with a mtu size that does not make sense" would point to failing, "we cannot work with the mtu size that the device presented us" would point to not negotiating the feature.

Quoted 25 lines
Quoted 25 lines

         }

         return 0;
}

And the spec says:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 8 lines
Quoted 4 lines

Item 4 on the list explicitly allows reading config space before FEATURES_OK.

I conclude that VIRTIO_NET_F_MTU is set means "set in device features".

So this probably need some clarification. "is set" is used many times in the spec that has different implications.

Before FEATURES_OK is set by the driver, I guess it means "the device has offered the feature"; during normal usage, it means "the feature has been negotiated". (This is a bit fuzzy for legacy mode.)

Should we add a wording clarification to the spec?

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#74 lore raw
Quoted 88 lines · Cornelia Huck
Quoted 45 lines · On Tue, 23 Feb 2021 17:46:20 +0800 Jason Wang <[email protected]> wrote:
Quoted 44 lines · Michael S. Tsirkin
Quoted 22 lines · Si-Wei Liu
Quoted 21 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use.
"

Quoted 7 lines
Quoted 1 line

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

Oh you are right:

static int virtnet_validate(struct virtio_device *vdev)

{
          if (!vdev->config->get) {
                  dev_err(&vdev->dev, "%s failure: config access disabled\n",
                          __func__);
                  return -EINVAL;
          }

          if (!virtnet_validate_features(vdev))
                  return -EINVAL;
Quoted 8 lines
Quoted 6 lines
          if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                  int mtu = virtio_cread16(vdev,
                                           offsetof(struct virtio_net_config,
                                                    mtu));
                  if (mtu < MIN_MTU)
                          __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);

I wonder why not simply fail here?

I think both failing or not accepting the feature can be argued to make
sense: "the device presented us with a mtu size that does not make sense" would point to failing, "we cannot work with the mtu size that the device presented us" would point to not negotiating the feature.

Quoted 27 lines
Quoted 27 lines
          }

          return 0;
}

And the spec says:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Item 4 on the list explicitly allows reading config space before FEATURES_OK.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I conclude that VIRTIO_NET_F_MTU is set means "set in device features".

So this probably need some clarification. "is set" is used many times in the spec that has different implications.

Before FEATURES_OK is set by the driver, I guess it means "the device has offered the feature";

For me this part is ok since it clarify that it's the driver that set the bit.

Quoted 2 lines

during normal usage, it means "the feature
has been negotiated".

/?

It looks to me the feature negotiation is done only after device set FEATURES_OK, or FEATURES_OK could be read from device status?

Quoted 1 line

(This is a bit fuzzy for legacy mode.)

The problem is the MTU description for example:

"The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set."

It looks to me need to use "if VIRTIO_NET_F_MTU is set by device". Otherwise readers (at least for me), may think the MTU is only valid if driver set the bit.

Quoted 2 lines

Should we add a wording clarification to the spec?

I think so.

Thanks

Quoted 1 line

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#75 lore raw
Quoted 102 lines · On Tue, 23 Feb 2021 18:31:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 88 lines · Cornelia Huck
Quoted 45 lines · On Tue, 23 Feb 2021 17:46:20 +0800 Jason Wang <[email protected]> wrote:
Quoted 44 lines · Michael S. Tsirkin
Quoted 22 lines · Si-Wei Liu
Quoted 21 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use.
"

Quoted 7 lines
Quoted 1 line

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

Oh you are right:

static int virtnet_validate(struct virtio_device *vdev)

{
          if (!vdev->config->get) {
                  dev_err(&vdev->dev, "%s failure: config access disabled\n",
                          __func__);
                  return -EINVAL;
          }

          if (!virtnet_validate_features(vdev))
                  return -EINVAL;
Quoted 8 lines
Quoted 6 lines
          if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                  int mtu = virtio_cread16(vdev,
                                           offsetof(struct virtio_net_config,
                                                    mtu));
                  if (mtu < MIN_MTU)
                          __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);  

I wonder why not simply fail here?

I think both failing or not accepting the feature can be argued to make
sense: "the device presented us with a mtu size that does not make sense" would point to failing, "we cannot work with the mtu size that the device presented us" would point to not negotiating the feature.

Quoted 27 lines
Quoted 27 lines
 
          }

          return 0;
}

And the spec says:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Item 4 on the list explicitly allows reading config space before FEATURES_OK.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I conclude that VIRTIO_NET_F_MTU is set means "set in device features".

So this probably need some clarification. "is set" is used many times in the spec that has different implications.

Before FEATURES_OK is set by the driver, I guess it means "the device has offered the feature";

For me this part is ok since it clarify that it's the driver that set the bit.

Quoted 7 lines
Quoted 2 lines

during normal usage, it means "the feature
has been negotiated".

/?

It looks to me the feature negotiation is done only after device set FEATURES_OK, or FEATURES_OK could be read from device status?

I'd consider feature negotiation done when the driver reads FEATURES_OK back from the status.

Quoted 3 lines
Quoted 3 lines

(This is a bit fuzzy for legacy mode.)

...because legacy does not have FEATURES_OK.

Quoted 8 lines

The problem is the MTU description for example:

"The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set."

It looks to me need to use "if VIRTIO_NET_F_MTU is set by device".

"offered by the device"? I don't think it should 'disappear' from the config space if the driver won't use it. (Same for other config space fields that are tied to feature bits.)

Quoted 2 lines

Otherwise readers (at least for me), may think the MTU is only valid if driver set the bit.

I think it would still be 'valid' in the sense that it exists and has some value in there filled in by the device, but a driver reading it without negotiating the feature would be buggy. (Like in the kernel code above; the kernel not liking the value does not make the field invalid.)

Maybe a statement covering everything would be:

"The following driver-read-only field mtu only exists if the device offers VIRTIO_NET_F_MTU and may be read by the driver during feature negotiation and after VIRTIO_NET_F_MTU has been successfully negotiated."

Quoted 7 lines
Quoted 4 lines

Should we add a wording clarification to the spec?

I think so.

Some clarification would be needed for each field that depends on a feature; that would be quite verbose. Maybe we can get away with a clarifying statement?

"Some config space fields may depend on a certain feature. In that case, the field exits if the device has offered the corresponding feature, and may be read by the driver during feature negotiation, and accessed by the driver after the feature has been successfully negotiated. A shorthand for this is a statement that a field only exists if a certain feature bit is set."

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#76 lore raw
Quoted 102 lines · Cornelia Huck
Quoted 99 lines · On Tue, 23 Feb 2021 18:31:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 84 lines · Cornelia Huck
Quoted 45 lines · On Tue, 23 Feb 2021 17:46:20 +0800 Jason Wang <[email protected]> wrote:
Quoted 44 lines · Michael S. Tsirkin
Quoted 22 lines · Si-Wei Liu
Quoted 21 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use.
"

Quoted 7 lines
Quoted 1 line

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

Oh you are right:

static int virtnet_validate(struct virtio_device *vdev)

{
           if (!vdev->config->get) {
                   dev_err(&vdev->dev, "%s failure: config access disabled\n",
                           __func__);
                   return -EINVAL;
           }

           if (!virtnet_validate_features(vdev))
                   return -EINVAL;
Quoted 7 lines
Quoted 6 lines
           if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                   int mtu = virtio_cread16(vdev,
                                            offsetof(struct virtio_net_config,
                                                     mtu));
                   if (mtu < MIN_MTU)
                           __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);

I wonder why not simply fail here?

I think both failing or not accepting the feature can be argued to make
sense: "the device presented us with a mtu size that does not make sense" would point to failing, "we cannot work with the mtu size that the device presented us" would point to not negotiating the feature.

Quoted 24 lines
Quoted 24 lines
  
           }

           return 0;
}

And the spec says:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Item 4 on the list explicitly allows reading config space before FEATURES_OK.

I conclude that VIRTIO_NET_F_MTU is set means "set in device features".

So this probably need some clarification. "is set" is used many times in the spec that has different implications.

Before FEATURES_OK is set by the driver, I guess it means "the device has offered the feature";

For me this part is ok since it clarify that it's the driver that set the bit.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

during normal usage, it means "the feature
has been negotiated".

/?

It looks to me the feature negotiation is done only after device set FEATURES_OK, or FEATURES_OK could be read from device status?

I'd consider feature negotiation done when the driver reads FEATURES_OK back from the status.

I agree.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

(This is a bit fuzzy for legacy mode.)

...because legacy does not have FEATURES_OK.

Quoted 3 lines

The problem is the MTU description for example:

Quoted 7 lines
Quoted 4 lines

"The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set."

It looks to me need to use "if VIRTIO_NET_F_MTU is set by device".

"offered by the device"? I don't think it should 'disappear' from the config space if the driver won't use it. (Same for other config space fields that are tied to feature bits.)

But what happens if e.g device doesn't offer VIRTIO_NET_F_MTU? It looks to according to the spec there will be no mtu field.

And a more interesting case is VIRTIO_NET_F_MQ is not offered but VIRTIO_NET_F_MTU offered. To me, it means we don't have max_virtqueue_pairs but it's not how the driver is wrote today.

Quoted 8 lines
Quoted 3 lines

Otherwise readers (at least for me), may think the MTU is only valid if driver set the bit.

I think it would still be 'valid' in the sense that it exists and has some value in there filled in by the device, but a driver reading it without negotiating the feature would be buggy. (Like in the kernel code above; the kernel not liking the value does not make the field invalid.)

See Michael's reply, the spec allows read the config before setting features.

Quoted 11 lines

Maybe a statement covering everything would be:

"The following driver-read-only field mtu only exists if the device offers VIRTIO_NET_F_MTU and may be read by the driver during feature negotiation and after VIRTIO_NET_F_MTU has been successfully negotiated."

Quoted 3 lines
Quoted 2 lines

Should we add a wording clarification to the spec?

Quoted 8 lines
Quoted 1 line

I think so.

Some clarification would be needed for each field that depends on a feature; that would be quite verbose. Maybe we can get away with a clarifying statement?

"Some config space fields may depend on a certain feature. In that case, the field exits if the device has offered the corresponding feature,

So this implies for !VIRTIO_NET_F_MQ && VIRTIO_NET_F_MTU, the config will look like:

struct virtio_net_config {
        u8 mac[6];
        le16 status;
        le16 mtu;
};

Quoted 4 lines

and may be read by the driver during feature negotiation, and
accessed by the driver after the feature has been successfully negotiated. A shorthand for this is a statement that a field only exists if a certain feature bit is set."

I'm not sure using "shorthand" is good for the spec, at least we can limit the its scope only to the configuration space part.

Thanks

Quoted 1 line

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#77 lore raw
Quoted 127 lines · On Wed, 24 Feb 2021 17:29:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 102 lines · Cornelia Huck
Quoted 99 lines · On Tue, 23 Feb 2021 18:31:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 84 lines · Cornelia Huck
Quoted 45 lines · On Tue, 23 Feb 2021 17:46:20 +0800 Jason Wang <[email protected]> wrote:
Quoted 44 lines · Michael S. Tsirkin
Quoted 22 lines · Si-Wei Liu
Quoted 21 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use.
"

Quoted 7 lines
Quoted 1 line

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

Oh you are right:

static int virtnet_validate(struct virtio_device *vdev)

{
           if (!vdev->config->get) {
                   dev_err(&vdev->dev, "%s failure: config access disabled\n",
                           __func__);
                   return -EINVAL;
           }

           if (!virtnet_validate_features(vdev))
                   return -EINVAL;
Quoted 7 lines
Quoted 6 lines
           if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                   int mtu = virtio_cread16(vdev,
                                            offsetof(struct virtio_net_config,
                                                     mtu));
                   if (mtu < MIN_MTU)
                           __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);  

I wonder why not simply fail here?

I think both failing or not accepting the feature can be argued to make
sense: "the device presented us with a mtu size that does not make sense" would point to failing, "we cannot work with the mtu size that the device presented us" would point to not negotiating the feature.

Quoted 24 lines
Quoted 24 lines
    
           }

           return 0;
}

And the spec says:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Item 4 on the list explicitly allows reading config space before FEATURES_OK.

I conclude that VIRTIO_NET_F_MTU is set means "set in device features".

So this probably need some clarification. "is set" is used many times in the spec that has different implications.

Before FEATURES_OK is set by the driver, I guess it means "the device has offered the feature";

For me this part is ok since it clarify that it's the driver that set the bit.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

during normal usage, it means "the feature
has been negotiated".

/?

It looks to me the feature negotiation is done only after device set FEATURES_OK, or FEATURES_OK could be read from device status?

I'd consider feature negotiation done when the driver reads FEATURES_OK back from the status.

I agree.

Quoted 11 lines
Quoted 3 lines
Quoted 3 lines

(This is a bit fuzzy for legacy mode.)

...because legacy does not have FEATURES_OK.

Quoted 6 lines

The problem is the MTU description for example:

"The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set."

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

It looks to me need to use "if VIRTIO_NET_F_MTU is set by device".

"offered by the device"? I don't think it should 'disappear' from the config space if the driver won't use it. (Same for other config space fields that are tied to feature bits.)

But what happens if e.g device doesn't offer VIRTIO_NET_F_MTU? It looks to according to the spec there will be no mtu field.

I think so, yes.

Quoted 4 lines

And a more interesting case is VIRTIO_NET_F_MQ is not offered but VIRTIO_NET_F_MTU offered. To me, it means we don't have max_virtqueue_pairs but it's not how the driver is wrote today.

That would be a bug, but it seems to me that the virtio-net driver reads max_virtqueue_pairs conditionally and handles absence of the feature correctly?

Quoted 12 lines
Quoted 10 lines
Quoted 5 lines

Otherwise readers (at least for me), may think the MTU is only valid if driver set the bit.

I think it would still be 'valid' in the sense that it exists and has some value in there filled in by the device, but a driver reading it without negotiating the feature would be buggy. (Like in the kernel code above; the kernel not liking the value does not make the field invalid.)

Quoted 2 lines

See Michael's reply, the spec allows read the config before setting features.

Yes, the period prior to finishing negotiation is obviously special.

Quoted 23 lines
Quoted 13 lines

Maybe a statement covering everything would be:

"The following driver-read-only field mtu only exists if the device offers VIRTIO_NET_F_MTU and may be read by the driver during feature negotiation and after VIRTIO_NET_F_MTU has been successfully negotiated."

Quoted 3 lines
Quoted 2 lines

Should we add a wording clarification to the spec?

Quoted 8 lines
Quoted 1 line

I think so.

Some clarification would be needed for each field that depends on a feature; that would be quite verbose. Maybe we can get away with a clarifying statement?

"Some config space fields may depend on a certain feature. In that case, the field exits if the device has offered the corresponding feature,

Quoted 9 lines

So this implies for !VIRTIO_NET_F_MQ && VIRTIO_NET_F_MTU, the config will look like:

struct virtio_net_config {
        u8 mac[6];
        le16 status;
        le16 mtu;
};

I agree.

Quoted 9 lines
Quoted 5 lines

and may be read by the driver during feature negotiation, and
accessed by the driver after the feature has been successfully negotiated. A shorthand for this is a statement that a field only exists if a certain feature bit is set."

I'm not sure using "shorthand" is good for the spec, at least we can limit the its scope only to the configuration space part.

Maybe "a shorthand expression"?

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#78 lore raw
Quoted 134 lines · Cornelia Huck
Quoted 124 lines · On Wed, 24 Feb 2021 17:29:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 101 lines · Cornelia Huck
Quoted 98 lines · On Tue, 23 Feb 2021 18:31:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 84 lines · Cornelia Huck
Quoted 45 lines · On Tue, 23 Feb 2021 17:46:20 +0800 Jason Wang <[email protected]> wrote:
Quoted 44 lines · Michael S. Tsirkin
Quoted 22 lines · Si-Wei Liu
Quoted 21 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use.
"

Quoted 7 lines
Quoted 1 line

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

Oh you are right:

static int virtnet_validate(struct virtio_device *vdev)

{
            if (!vdev->config->get) {
                    dev_err(&vdev->dev, "%s failure: config access disabled\n",
                            __func__);
                    return -EINVAL;
            }

            if (!virtnet_validate_features(vdev))
                    return -EINVAL;
Quoted 7 lines
Quoted 6 lines
            if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                    int mtu = virtio_cread16(vdev,
                                             offsetof(struct virtio_net_config,
                                                      mtu));
                    if (mtu < MIN_MTU)
                            __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);

I wonder why not simply fail here?

I think both failing or not accepting the feature can be argued to make
sense: "the device presented us with a mtu size that does not make sense" would point to failing, "we cannot work with the mtu size that the device presented us" would point to not negotiating the feature.

Quoted 24 lines
Quoted 24 lines
     
            }

            return 0;
}

And the spec says:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Item 4 on the list explicitly allows reading config space before FEATURES_OK.

I conclude that VIRTIO_NET_F_MTU is set means "set in device features".

So this probably need some clarification. "is set" is used many times in the spec that has different implications.

Before FEATURES_OK is set by the driver, I guess it means "the device has offered the feature";

For me this part is ok since it clarify that it's the driver that set the bit.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

during normal usage, it means "the feature
has been negotiated".

/?

It looks to me the feature negotiation is done only after device set FEATURES_OK, or FEATURES_OK could be read from device status?

I'd consider feature negotiation done when the driver reads FEATURES_OK back from the status.

I agree.

Quoted 10 lines
Quoted 3 lines
Quoted 3 lines

(This is a bit fuzzy for legacy mode.)

...because legacy does not have FEATURES_OK.

Quoted 5 lines

The problem is the MTU description for example:

"The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set."

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

It looks to me need to use "if VIRTIO_NET_F_MTU is set by device".

"offered by the device"? I don't think it should 'disappear' from the config space if the driver won't use it. (Same for other config space fields that are tied to feature bits.)

But what happens if e.g device doesn't offer VIRTIO_NET_F_MTU? It looks to according to the spec there will be no mtu field.

Quoted 8 lines

I think so, yes.

Quoted 3 lines

And a more interesting case is VIRTIO_NET_F_MQ is not offered but VIRTIO_NET_F_MTU offered. To me, it means we don't have max_virtqueue_pairs but it's not how the driver is wrote today.

That would be a bug, but it seems to me that the virtio-net driver reads max_virtqueue_pairs conditionally and handles absence of the feature correctly?

Yes, see the avove codes:

        if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                int mtu = virtio_cread16(vdev,
                                         offsetof(struct virtio_net_config, mtu));
                if (mtu < MIN_MTU)
                        __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU); }

So it's probably too late to fix the driver.

Quoted 37 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Otherwise readers (at least for me), may think the MTU is only valid if driver set the bit.

Quoted 8 lines
Quoted 5 lines

I think it would still be 'valid' in the sense that it exists and has some value in there filled in by the device, but a driver reading it without negotiating the feature would be buggy. (Like in the kernel code above; the kernel not liking the value does not make the field invalid.)

See Michael's reply, the spec allows read the config before setting features.

Yes, the period prior to finishing negotiation is obviously special.

Quoted 22 lines
Quoted 10 lines

Maybe a statement covering everything would be:

"The following driver-read-only field mtu only exists if the device offers VIRTIO_NET_F_MTU and may be read by the driver during feature negotiation and after VIRTIO_NET_F_MTU has been successfully negotiated."

Quoted 2 lines
Quoted 2 lines

Should we add a wording clarification to the spec?

Quoted 8 lines
Quoted 1 line

I think so.

Some clarification would be needed for each field that depends on a feature; that would be quite verbose. Maybe we can get away with a clarifying statement?

"Some config space fields may depend on a certain feature. In that case, the field exits if the device has offered the corresponding feature,

So this implies for !VIRTIO_NET_F_MQ && VIRTIO_NET_F_MTU, the config will look like:

Quoted 7 lines
Quoted 6 lines

struct virtio_net_config {
        u8 mac[6];
        le16 status;
        le16 mtu;
};

I agree.

So consider it's probably too late to fix the driver which assumes some field are always persent, it looks to me need fix the spec do declare the fields are always existing instead.

Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

and may be read by the driver during feature negotiation, and
accessed by the driver after the feature has been successfully negotiated. A shorthand for this is a statement that a field only exists if a certain feature bit is set."

I'm not sure using "shorthand" is good for the spec, at least we can limit the its scope only to the configuration space part.

Maybe "a shorthand expression"?

So the questions is should we use this for all over the spec or it will be only used in this speicifc part (device configuration).

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#79 lore raw
Quoted 32 lines · On Thu, 25 Feb 2021 12:36:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 19 lines · Cornelia Huck
Quoted 9 lines · On Wed, 24 Feb 2021 17:29:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 8 lines · Cornelia Huck
Quoted 5 lines · On Tue, 23 Feb 2021 18:31:07 +0800 Jason Wang <[email protected]> wrote:

The problem is the MTU description for example:

"The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set."

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

It looks to me need to use "if VIRTIO_NET_F_MTU is set by device".

"offered by the device"? I don't think it should 'disappear' from the config space if the driver won't use it. (Same for other config space fields that are tied to feature bits.)

But what happens if e.g device doesn't offer VIRTIO_NET_F_MTU? It looks to according to the spec there will be no mtu field.

Quoted 8 lines

I think so, yes.

Quoted 3 lines

And a more interesting case is VIRTIO_NET_F_MQ is not offered but VIRTIO_NET_F_MTU offered. To me, it means we don't have max_virtqueue_pairs but it's not how the driver is wrote today.

That would be a bug, but it seems to me that the virtio-net driver reads max_virtqueue_pairs conditionally and handles absence of the feature correctly?

Yes, see the avove codes:

Quoted 8 lines

        if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                int mtu = virtio_cread16(vdev,
                                         offsetof(struct virtio_net_config, mtu));
                if (mtu < MIN_MTU)
                        __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU); }

Ouch, you're right. The virtio_cread accessors all operate on offsets into a structure, it's just more obvious here.

Quoted 1 line

So it's probably too late to fix the driver.

It is never too late to fix a driver :)

It seems involved, though. We'd need different config space structures based upon which set of features has been negotiated. It's not too bad when features build upon each other and add fields at the end (this should be fine right now, if the code remembered to check for the feature), but can become ugly if an in-between field depends upon a feature.

I guess we've been lucky that it seems to be an extremely uncommon configuration.

Quoted 45 lines
Quoted 45 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Otherwise readers (at least for me), may think the MTU is only valid if driver set the bit.

Quoted 8 lines
Quoted 5 lines

I think it would still be 'valid' in the sense that it exists and has some value in there filled in by the device, but a driver reading it without negotiating the feature would be buggy. (Like in the kernel code above; the kernel not liking the value does not make the field invalid.)

See Michael's reply, the spec allows read the config before setting features.

Yes, the period prior to finishing negotiation is obviously special.

Quoted 28 lines
Quoted 10 lines

Maybe a statement covering everything would be:

"The following driver-read-only field mtu only exists if the device offers VIRTIO_NET_F_MTU and may be read by the driver during feature negotiation and after VIRTIO_NET_F_MTU has been successfully negotiated."

Quoted 2 lines
Quoted 2 lines

Should we add a wording clarification to the spec?

Quoted 8 lines
Quoted 1 line

I think so.

Some clarification would be needed for each field that depends on a feature; that would be quite verbose. Maybe we can get away with a clarifying statement?

"Some config space fields may depend on a certain feature. In that case, the field exits if the device has offered the corresponding feature,

So this implies for !VIRTIO_NET_F_MQ && VIRTIO_NET_F_MTU, the config will look like:

struct virtio_net_config {
        u8 mac[6];
        le16 status;
        le16 mtu;
};

Quoted 6 lines
Quoted 1 line

I agree.

So consider it's probably too late to fix the driver which assumes some field are always persent, it looks to me need fix the spec do declare the fields are always existing instead.

The problem with that is that it has been in the spec already, and a compliant device that did not provide the fields without the features would suddenly become non-compliant...

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

and may be read by the driver during feature negotiation, and
accessed by the driver after the feature has been successfully negotiated. A shorthand for this is a statement that a field only exists if a certain feature bit is set."

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

I'm not sure using "shorthand" is good for the spec, at least we can limit the its scope only to the configuration space part.

Maybe "a shorthand expression"?

So the questions is should we use this for all over the spec or it will be only used in this speicifc part (device configuration).

For command structures and the like, "feature is set" should always mean "feature has been negotiated"; I think config space is special because the driver can read it before feature negotiation is finished, so device configuration is probably the proper place for it.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#80 lore raw
In reply to Jason Wang
Quoted 148 lines · Jason Wang
Quoted 126 lines · Cornelia Huck
Quoted 116 lines · On Wed, 24 Feb 2021 17:29:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 96 lines · Cornelia Huck
Quoted 94 lines · On Tue, 23 Feb 2021 18:31:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 81 lines · Cornelia Huck
Quoted 45 lines · On Tue, 23 Feb 2021 17:46:20 +0800 Jason Wang <[email protected]> wrote:
Quoted 44 lines · Michael S. Tsirkin
Quoted 22 lines · Si-Wei Liu
Quoted 21 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use.
"

Quoted 7 lines
Quoted 1 line

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

Oh you are right:

static int virtnet_validate(struct virtio_device *vdev)

{
            if (!vdev->config->get) {
                    dev_err(&vdev->dev, "%s failure: config access disabled\n",
                            __func__);
                    return -EINVAL;
            }

            if (!virtnet_validate_features(vdev))
                    return -EINVAL;
Quoted 7 lines
Quoted 6 lines
            if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                    int mtu = virtio_cread16(vdev,
                                             offsetof(struct virtio_net_config,
                                                      mtu));
                    if (mtu < MIN_MTU)
                            __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);

I wonder why not simply fail here?

I think both failing or not accepting the feature can be argued to make
sense: "the device presented us with a mtu size that does not make sense" would point to failing, "we cannot work with the mtu size that the device presented us" would point to not negotiating the feature.

Quoted 23 lines
Quoted 23 lines
            }

            return 0;
}

And the spec says:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Item 4 on the list explicitly allows reading config space before FEATURES_OK.

I conclude that VIRTIO_NET_F_MTU is set means "set in device features".

So this probably need some clarification. "is set" is used many times in the spec that has different implications.

Before FEATURES_OK is set by the driver, I guess it means "the device has offered the feature";

For me this part is ok since it clarify that it's the driver that set the bit.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

during normal usage, it means "the feature
has been negotiated".

/?

It looks to me the feature negotiation is done only after device set FEATURES_OK, or FEATURES_OK could be read from device status?

I'd consider feature negotiation done when the driver reads FEATURES_OK back from the status.

I agree.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

(This is a bit fuzzy for legacy mode.)

...because legacy does not have FEATURES_OK.

Quoted 5 lines

The problem is the MTU description for example:

"The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set."

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

It looks to me need to use "if VIRTIO_NET_F_MTU is set by device".

"offered by the device"? I don't think it should 'disappear' from the config space if the driver won't use it. (Same for other config space fields that are tied to feature bits.)

But what happens if e.g device doesn't offer VIRTIO_NET_F_MTU? It looks to according to the spec there will be no mtu field.

Quoted 8 lines

I think so, yes.

Quoted 3 lines

And a more interesting case is VIRTIO_NET_F_MQ is not offered but VIRTIO_NET_F_MTU offered. To me, it means we don't have max_virtqueue_pairs but it's not how the driver is wrote today.

That would be a bug, but it seems to me that the virtio-net driver reads max_virtqueue_pairs conditionally and handles absence of the feature correctly?

Yes, see the avove codes:

        if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                int mtu = virtio_cread16(vdev,
                                         offsetof(struct virtio_net_config, mtu));
                if (mtu < MIN_MTU)
                        __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU); }

Quoted 2 lines

So it's probably too late to fix the driver.

Confused. What is wrong with the above? It never reads the field unless the feature has been offered by device.

Quoted 56 lines
Quoted 34 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Otherwise readers (at least for me), may think the MTU is only valid if driver set the bit.

Quoted 8 lines
Quoted 5 lines

I think it would still be 'valid' in the sense that it exists and has some value in there filled in by the device, but a driver reading it without negotiating the feature would be buggy. (Like in the kernel code above; the kernel not liking the value does not make the field invalid.)

See Michael's reply, the spec allows read the config before setting features.

Yes, the period prior to finishing negotiation is obviously special.

Quoted 20 lines
Quoted 8 lines

Maybe a statement covering everything would be:

"The following driver-read-only field mtu only exists if the device offers VIRTIO_NET_F_MTU and may be read by the driver during feature negotiation and after VIRTIO_NET_F_MTU has been successfully negotiated."

Quoted 1 line
Quoted 1 line

Should we add a wording clarification to the spec?

Quoted 8 lines
Quoted 1 line

I think so.

Some clarification would be needed for each field that depends on a feature; that would be quite verbose. Maybe we can get away with a clarifying statement?

"Some config space fields may depend on a certain feature. In that case, the field exits if the device has offered the corresponding feature,

So this implies for !VIRTIO_NET_F_MQ && VIRTIO_NET_F_MTU, the config will look like:

Quoted 7 lines
Quoted 6 lines

struct virtio_net_config {
        u8 mac[6];
        le16 status;
        le16 mtu;
};

I agree.

So consider it's probably too late to fix the driver which assumes some field are always persent, it looks to me need fix the spec do declare the fields are always existing instead.

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

and may be read by the driver during feature negotiation, and
accessed by the driver after the feature has been successfully negotiated. A shorthand for this is a statement that a field only exists if a certain feature bit is set."

I'm not sure using "shorthand" is good for the spec, at least we can limit the its scope only to the configuration space part.

Quoted 8 lines
Quoted 1 line

Maybe "a shorthand expression"?

So the questions is should we use this for all over the spec or it will be only used in this speicifc part (device configuration).

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#81 lore raw
Quoted 145 lines · Michael S. Tsirkin
Quoted 144 lines · Jason Wang
Quoted 124 lines · Cornelia Huck
Quoted 115 lines · On Wed, 24 Feb 2021 17:29:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 96 lines · Cornelia Huck
Quoted 94 lines · On Tue, 23 Feb 2021 18:31:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 81 lines · Cornelia Huck
Quoted 45 lines · On Tue, 23 Feb 2021 17:46:20 +0800 Jason Wang <[email protected]> wrote:
Quoted 44 lines · Michael S. Tsirkin
Quoted 22 lines · Si-Wei Liu
Quoted 21 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use.
"

Quoted 7 lines
Quoted 1 line

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

Oh you are right:

static int virtnet_validate(struct virtio_device *vdev)

{
             if (!vdev->config->get) {
                     dev_err(&vdev->dev, "%s failure: config access disabled\n",
                             __func__);
                     return -EINVAL;
             }

             if (!virtnet_validate_features(vdev))
                     return -EINVAL;
Quoted 7 lines
Quoted 6 lines
             if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                     int mtu = virtio_cread16(vdev,
                                              offsetof(struct virtio_net_config,
                                                       mtu));
                     if (mtu < MIN_MTU)
                             __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);

I wonder why not simply fail here?

I think both failing or not accepting the feature can be argued to make
sense: "the device presented us with a mtu size that does not make sense" would point to failing, "we cannot work with the mtu size that the device presented us" would point to not negotiating the feature.

Quoted 23 lines
Quoted 23 lines
             }

             return 0;
}

And the spec says:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Item 4 on the list explicitly allows reading config space before FEATURES_OK.

I conclude that VIRTIO_NET_F_MTU is set means "set in device features".

So this probably need some clarification. "is set" is used many times in the spec that has different implications.

Before FEATURES_OK is set by the driver, I guess it means "the device has offered the feature";

For me this part is ok since it clarify that it's the driver that set the bit.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

during normal usage, it means "the feature
has been negotiated".

/?

It looks to me the feature negotiation is done only after device set FEATURES_OK, or FEATURES_OK could be read from device status?

I'd consider feature negotiation done when the driver reads FEATURES_OK back from the status.

I agree.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

(This is a bit fuzzy for legacy mode.)

...because legacy does not have FEATURES_OK.

Quoted 5 lines

The problem is the MTU description for example:

"The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set."

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

It looks to me need to use "if VIRTIO_NET_F_MTU is set by device".

"offered by the device"? I don't think it should 'disappear' from the config space if the driver won't use it. (Same for other config space fields that are tied to feature bits.)

But what happens if e.g device doesn't offer VIRTIO_NET_F_MTU? It looks to according to the spec there will be no mtu field.

Quoted 8 lines

I think so, yes.

Quoted 3 lines

And a more interesting case is VIRTIO_NET_F_MQ is not offered but VIRTIO_NET_F_MTU offered. To me, it means we don't have max_virtqueue_pairs but it's not how the driver is wrote today.

That would be a bug, but it seems to me that the virtio-net driver reads max_virtqueue_pairs conditionally and handles absence of the feature correctly?

Yes, see the avove codes:

        if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                int mtu = virtio_cread16(vdev,
                                         offsetof(struct virtio_net_config, mtu));
                if (mtu < MIN_MTU)
                        __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU); }

Quoted 4 lines
Quoted 2 lines

So it's probably too late to fix the driver.

Confused. What is wrong with the above? It never reads the field unless the feature has been offered by device.

So the spec said:

"

The following driver-read-only field, max_virtqueue_pairs only exists if VIRTIO_NET_F_MQ is set.

"

If I read this correctly, there will be no max_virtqueue_pairs field if the VIRTIO_NET_F_MQ is not offered by device? If yes the offsetof() violates what spec said.

Thanks

Quoted 50 lines
Quoted 50 lines
Quoted 31 lines
Quoted 11 lines
Quoted 9 lines
Quoted 4 lines

Otherwise readers (at least for me), may think the MTU is only valid if driver set the bit.

I think it would still be 'valid' in the sense that it exists and has some value in there filled in by the device, but a driver reading it without negotiating the feature would be buggy. (Like in the kernel code above; the kernel not liking the value does not make the field invalid.)

See Michael's reply, the spec allows read the config before setting features.

Yes, the period prior to finishing negotiation is obviously special.

Quoted 18 lines
Quoted 7 lines

Maybe a statement covering everything would be:

"The following driver-read-only field mtu only exists if the device offers VIRTIO_NET_F_MTU and may be read by the driver during feature negotiation and after VIRTIO_NET_F_MTU has been successfully negotiated."

Quoted 1 line
Quoted 1 line

Should we add a wording clarification to the spec?

Quoted 8 lines
Quoted 1 line

I think so.

Some clarification would be needed for each field that depends on a feature; that would be quite verbose. Maybe we can get away with a clarifying statement?

"Some config space fields may depend on a certain feature. In that case, the field exits if the device has offered the corresponding feature,

So this implies for !VIRTIO_NET_F_MQ && VIRTIO_NET_F_MTU, the config will look like:

Quoted 7 lines
Quoted 6 lines
struct virtio_net_config {
           u8 mac[6];
           le16 status;
           le16 mtu;
};

I agree.

So consider it's probably too late to fix the driver which assumes some field are always persent, it looks to me need fix the spec do declare the fields are always existing instead.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

and may be read by the driver during feature negotiation, and
accessed by the driver after the feature has been successfully negotiated. A shorthand for this is a statement that a field only exists if a certain feature bit is set."

I'm not sure using "shorthand" is good for the spec, at least we can limit the its scope only to the configuration space part.

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

Maybe "a shorthand expression"?

So the questions is should we use this for all over the spec or it will be only used in this speicifc part (device configuration).

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#82 lore raw
Quoted 160 lines · Jason Wang
Quoted 145 lines · Michael S. Tsirkin
Quoted 144 lines · Jason Wang
Quoted 124 lines · Cornelia Huck
Quoted 115 lines · On Wed, 24 Feb 2021 17:29:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 96 lines · Cornelia Huck
Quoted 94 lines · On Tue, 23 Feb 2021 18:31:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 81 lines · Cornelia Huck
Quoted 45 lines · On Tue, 23 Feb 2021 17:46:20 +0800 Jason Wang <[email protected]> wrote:
Quoted 44 lines · Michael S. Tsirkin
Quoted 22 lines · Si-Wei Liu
Quoted 21 lines · Jason Wang
Quoted 11 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked
for legacy") made an exception for legacy guests to reset
features to 0, when config space is accessed before features
are set. We should relieve the verify_min_features() check
and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access
config space before features are set. For instance, when
feature VIRTIO_NET_F_MTU is advertised some modern driver
will try to access and validate the MTU present in the config
space before virtio features are set.

This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the driver to use.
"

Quoted 7 lines
Quoted 1 line

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

Oh you are right:

static int virtnet_validate(struct virtio_device *vdev)

{
             if (!vdev->config->get) {
                     dev_err(&vdev->dev, "%s failure: config access disabled\n",
                             __func__);
                     return -EINVAL;
             }

             if (!virtnet_validate_features(vdev))
                     return -EINVAL;
Quoted 7 lines
Quoted 6 lines
             if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                     int mtu = virtio_cread16(vdev,
                                              offsetof(struct virtio_net_config,
                                                       mtu));
                     if (mtu < MIN_MTU)
                             __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);

I wonder why not simply fail here?

I think both failing or not accepting the feature can be argued to make
sense: "the device presented us with a mtu size that does not make sense" would point to failing, "we cannot work with the mtu size that the device presented us" would point to not negotiating the feature.

Quoted 23 lines
Quoted 23 lines
             }

             return 0;
}

And the spec says:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Item 4 on the list explicitly allows reading config space before FEATURES_OK.

I conclude that VIRTIO_NET_F_MTU is set means "set in device features".

So this probably need some clarification. "is set" is used many times in the spec that has different implications.

Before FEATURES_OK is set by the driver, I guess it means "the device has offered the feature";

For me this part is ok since it clarify that it's the driver that set the bit.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

during normal usage, it means "the feature
has been negotiated".

/?

It looks to me the feature negotiation is done only after device set FEATURES_OK, or FEATURES_OK could be read from device status?

I'd consider feature negotiation done when the driver reads FEATURES_OK back from the status.

I agree.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

(This is a bit fuzzy for legacy mode.)

...because legacy does not have FEATURES_OK.

Quoted 5 lines

The problem is the MTU description for example:

"The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set."

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

It looks to me need to use "if VIRTIO_NET_F_MTU is set by device".

"offered by the device"? I don't think it should 'disappear' from the config space if the driver won't use it. (Same for other config space fields that are tied to feature bits.)

But what happens if e.g device doesn't offer VIRTIO_NET_F_MTU? It looks to according to the spec there will be no mtu field.

Quoted 8 lines

I think so, yes.

Quoted 3 lines

And a more interesting case is VIRTIO_NET_F_MQ is not offered but VIRTIO_NET_F_MTU offered. To me, it means we don't have max_virtqueue_pairs but it's not how the driver is wrote today.

That would be a bug, but it seems to me that the virtio-net driver reads max_virtqueue_pairs conditionally and handles absence of the feature correctly?

Yes, see the avove codes:

        if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                int mtu = virtio_cread16(vdev,
                                         offsetof(struct virtio_net_config, mtu));
                if (mtu < MIN_MTU)
                        __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU); }

Quoted 4 lines
Quoted 2 lines

So it's probably too late to fix the driver.

Confused. What is wrong with the above? It never reads the field unless the feature has been offered by device.

So the spec said:

"

The following driver-read-only field, max_virtqueue_pairs only exists if VIRTIO_NET_F_MQ is set.

Quoted 7 lines

"

If I read this correctly, there will be no max_virtqueue_pairs field if the VIRTIO_NET_F_MQ is not offered by device? If yes the offsetof() violates what spec said.

Thanks

I think that's a misunderstanding. This text was never intended to imply that field offsets change beased on feature bits. We had this pain with legacy and we never wanted to go back there.

This merely implies that without VIRTIO_NET_F_MQ the field should not be accessed. Exists in the sense "is accessible to driver".

Let's just clarify that in the spec, job done.

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 32 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Otherwise readers (at least for me), may think the MTU is only valid if driver set the bit.

Quoted 7 lines
Quoted 5 lines

I think it would still be 'valid' in the sense that it exists and has some value in there filled in by the device, but a driver reading it without negotiating the feature would be buggy. (Like in the kernel code above; the kernel not liking the value does not make the field invalid.)

See Michael's reply, the spec allows read the config before setting features.

Yes, the period prior to finishing negotiation is obviously special.

Quoted 18 lines
Quoted 7 lines

Maybe a statement covering everything would be:

"The following driver-read-only field mtu only exists if the device offers VIRTIO_NET_F_MTU and may be read by the driver during feature negotiation and after VIRTIO_NET_F_MTU has been successfully negotiated."

Quoted 1 line
Quoted 1 line

Should we add a wording clarification to the spec?

Quoted 8 lines
Quoted 1 line

I think so.

Some clarification would be needed for each field that depends on a feature; that would be quite verbose. Maybe we can get away with a clarifying statement?

"Some config space fields may depend on a certain feature. In that case, the field exits if the device has offered the corresponding feature,

So this implies for !VIRTIO_NET_F_MQ && VIRTIO_NET_F_MTU, the config will look like:

Quoted 7 lines
Quoted 6 lines
struct virtio_net_config {
           u8 mac[6];
           le16 status;
           le16 mtu;
};

I agree.

So consider it's probably too late to fix the driver which assumes some field are always persent, it looks to me need fix the spec do declare the fields are always existing instead.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

and may be read by the driver during feature negotiation, and
accessed by the driver after the feature has been successfully negotiated. A shorthand for this is a statement that a field only exists if a certain feature bit is set."

I'm not sure using "shorthand" is good for the spec, at least we can limit the its scope only to the configuration space part.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line

Maybe "a shorthand expression"?

So the questions is should we use this for all over the spec or it will be only used in this speicifc part (device configuration).

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#83 lore raw
Quoted 165 lines · Michael S. Tsirkin
Quoted 157 lines · Jason Wang
Quoted 144 lines · Michael S. Tsirkin
Quoted 143 lines · Jason Wang
Quoted 124 lines · Cornelia Huck
Quoted 115 lines · On Wed, 24 Feb 2021 17:29:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 96 lines · Cornelia Huck
Quoted 94 lines · On Tue, 23 Feb 2021 18:31:07 +0800 Jason Wang <[email protected]> wrote:
Quoted 81 lines · Cornelia Huck
Quoted 45 lines · On Tue, 23 Feb 2021 17:46:20 +0800 Jason Wang <[email protected]> wrote:
Quoted 44 lines · Michael S. Tsirkin
Quoted 22 lines · Si-Wei Liu
Quoted 21 lines · Jason Wang

On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
Commit 452639a64ad8 ("vdpa: make sure set_features is invoked
for legacy") made an exception for legacy guests to reset
features to 0, when config space is accessed before features
are set. We should relieve the verify_min_features() check
and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access
config space before features are set. For instance, when
feature VIRTIO_NET_F_MTU is advertised some modern driver
will try to access and validate the MTU present in the config
space before virtio features are set.
This looks like a spec violation:

"

The following driver-read-only field, mtu only exists if
VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the
driver to use.
"

Quoted 7 lines
Quoted 1 line

Do we really want to workaround this?

Isn't the commit 452639a64ad8 itself is a workaround for legacy guest?

I think the point is, since there's legacy guest we'd have to support, this host side workaround is unavoidable. Although I agree the violating driver should be fixed (yes, it's in today's upstream kernel which exists for a while now).

Oh you are right:

static int virtnet_validate(struct virtio_device *vdev)

{
              if (!vdev->config->get) {
                      dev_err(&vdev->dev, "%s failure: config access disabled\n",
                              __func__);
                      return -EINVAL;
              }

              if (!virtnet_validate_features(vdev))
                      return -EINVAL;
Quoted 7 lines
Quoted 6 lines
              if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                      int mtu = virtio_cread16(vdev,
                                               offsetof(struct virtio_net_config,
                                                        mtu));
                      if (mtu < MIN_MTU)
                              __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);

I wonder why not simply fail here?

I think both failing or not accepting the feature can be argued to make
sense: "the device presented us with a mtu size that does not make sense" would point to failing, "we cannot work with the mtu size that the device presented us" would point to not negotiating the feature.

Quoted 23 lines
Quoted 23 lines
              }

              return 0;
}

And the spec says:

The driver MUST follow this sequence to initialize a device:
1. Reset the device.
2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device.
3. Set the DRIVER status bit: the guest OS knows how to drive the device.
4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration fields to check that it can support the device before accepting it.
5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.
6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable.
7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device’s virtio configuration space, and population of virtqueues.
8. Set the DRIVER_OK status bit. At this point the device is “live”.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Item 4 on the list explicitly allows reading config space before FEATURES_OK.

I conclude that VIRTIO_NET_F_MTU is set means "set in device features".

So this probably need some clarification. "is set" is used many times in the spec that has different implications.

Before FEATURES_OK is set by the driver, I guess it means "the device has offered the feature";

For me this part is ok since it clarify that it's the driver that set the bit.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

during normal usage, it means "the feature
has been negotiated".

/?

It looks to me the feature negotiation is done only after device set FEATURES_OK, or FEATURES_OK could be read from device status?

I'd consider feature negotiation done when the driver reads FEATURES_OK back from the status.

I agree.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

(This is a bit fuzzy for legacy mode.)

...because legacy does not have FEATURES_OK.

Quoted 5 lines

The problem is the MTU description for example:

"The following driver-read-only field, mtu only exists if VIRTIO_NET_F_MTU is set."

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

It looks to me need to use "if VIRTIO_NET_F_MTU is set by device".

"offered by the device"? I don't think it should 'disappear' from the config space if the driver won't use it. (Same for other config space fields that are tied to feature bits.)

But what happens if e.g device doesn't offer VIRTIO_NET_F_MTU? It looks to according to the spec there will be no mtu field.

Quoted 8 lines

I think so, yes.

Quoted 3 lines

And a more interesting case is VIRTIO_NET_F_MQ is not offered but VIRTIO_NET_F_MTU offered. To me, it means we don't have max_virtqueue_pairs but it's not how the driver is wrote today.

That would be a bug, but it seems to me that the virtio-net driver reads max_virtqueue_pairs conditionally and handles absence of the feature correctly?

Yes, see the avove codes:

          if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
                  int mtu = virtio_cread16(vdev,
                                           offsetof(struct virtio_net_config,
                                                    mtu));
                  if (mtu < MIN_MTU)
                          __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);
          }
Quoted 4 lines
Quoted 2 lines

So it's probably too late to fix the driver.

Confused. What is wrong with the above? It never reads the field unless the feature has been offered by device.

So the spec said:

"

The following driver-read-only field, max_virtqueue_pairs only exists if VIRTIO_NET_F_MQ is set.

Quoted 7 lines

"

If I read this correctly, there will be no max_virtqueue_pairs field if the VIRTIO_NET_F_MQ is not offered by device? If yes the offsetof() violates what spec said.

Thanks

Quoted 8 lines

I think that's a misunderstanding. This text was never intended to imply that field offsets change beased on feature bits. We had this pain with legacy and we never wanted to go back there.

This merely implies that without VIRTIO_NET_F_MQ the field should not be accessed. Exists in the sense "is accessible to driver".

Let's just clarify that in the spec, job done.

Ok, agree. That will make things more eaiser.

Thanks

Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 34 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Otherwise readers (at least for me), may think the MTU is only valid if driver set the bit.

Quoted 7 lines
Quoted 5 lines

I think it would still be 'valid' in the sense that it exists and has some value in there filled in by the device, but a driver reading it without negotiating the feature would be buggy. (Like in the kernel code above; the kernel not liking the value does not make the field invalid.)

See Michael's reply, the spec allows read the config before setting features.

Yes, the period prior to finishing negotiation is obviously special.

Quoted 18 lines
Quoted 7 lines

Maybe a statement covering everything would be:

"The following driver-read-only field mtu only exists if the device offers VIRTIO_NET_F_MTU and may be read by the driver during feature negotiation and after VIRTIO_NET_F_MTU has been successfully negotiated."

Quoted 1 line
Quoted 1 line

Should we add a wording clarification to the spec?

Quoted 8 lines
Quoted 1 line

I think so.

Some clarification would be needed for each field that depends on a feature; that would be quite verbose. Maybe we can get away with a clarifying statement?

"Some config space fields may depend on a certain feature. In that case, the field exits if the device has offered the corresponding feature,

So this implies for !VIRTIO_NET_F_MQ && VIRTIO_NET_F_MTU, the config will look like:

Quoted 7 lines
Quoted 6 lines
struct virtio_net_config {
            u8 mac[6];
            le16 status;
            le16 mtu;
};

I agree.

So consider it's probably too late to fix the driver which assumes some field are always persent, it looks to me need fix the spec do declare the fields are always existing instead.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

and may be read by the driver during feature negotiation, and
accessed by the driver after the feature has been successfully negotiated. A shorthand for this is a statement that a field only exists if a certain feature bit is set."

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

I'm not sure using "shorthand" is good for the spec, at least we can limit the its scope only to the configuration space part.

Maybe "a shorthand expression"?

So the questions is should we use this for all over the spec or it will be only used in this speicifc part (device configuration).

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#84 lore raw
Quoted 25 lines · On Mon, 1 Mar 2021 11:51:08 +0800 Jason Wang <[email protected]> wrote:
Quoted 24 lines · Michael S. Tsirkin
Quoted 12 lines · Jason Wang
Quoted 2 lines · Michael S. Tsirkin

Confused. What is wrong with the above? It never reads the field unless the feature has been offered by device.

So the spec said:

"

The following driver-read-only field, max_virtqueue_pairs only exists if VIRTIO_NET_F_MQ is set.

Quoted 7 lines

"

If I read this correctly, there will be no max_virtqueue_pairs field if the VIRTIO_NET_F_MQ is not offered by device? If yes the offsetof() violates what spec said.

Thanks

I think that's a misunderstanding. This text was never intended to imply that field offsets change beased on feature bits. We had this pain with legacy and we never wanted to go back there.

Quoted 7 lines
Quoted 4 lines

This merely implies that without VIRTIO_NET_F_MQ the field should not be accessed. Exists in the sense "is accessible to driver".

Let's just clarify that in the spec, job done.

Ok, agree. That will make things more eaiser.

Yes, that makes much more sense.

What about adding the following to the "Basic Facilities of a Virtio Device/Device Configuration Space" section of the spec:

"If an optional configuration field does not exist, the corresponding space is still present, but reserved."

(Do we need to specify what a device needs to do if the driver tries to access a non-existing field? We cannot really make assumptions about config space accesses; virtio-ccw can just copy a chunk of config space that contains non-existing fields... I guess the device could ignore writes and return zeroes on read?)

I've opened https://github.com/oasis-tcs/virtio-spec/issues/98 for the spec issues.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#85 lore raw
Quoted 31 lines · Cornelia Huck
Quoted 28 lines · On Mon, 1 Mar 2021 11:51:08 +0800 Jason Wang <[email protected]> wrote:
Quoted 26 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Quoted 2 lines · Michael S. Tsirkin

Confused. What is wrong with the above? It never reads the field unless the feature has been offered by device.

So the spec said:

"

The following driver-read-only field, max_virtqueue_pairs only exists if VIRTIO_NET_F_MQ is set.

Quoted 7 lines

"

If I read this correctly, there will be no max_virtqueue_pairs field if the VIRTIO_NET_F_MQ is not offered by device? If yes the offsetof() violates what spec said.

Thanks

I think that's a misunderstanding. This text was never intended to imply that field offsets change beased on feature bits. We had this pain with legacy and we never wanted to go back there.

This merely implies that without VIRTIO_NET_F_MQ the field should not be accessed. Exists in the sense "is accessible to driver".

Let's just clarify that in the spec, job done.

Quoted 8 lines
Quoted 1 line

Ok, agree. That will make things more eaiser.

Yes, that makes much more sense.

What about adding the following to the "Basic Facilities of a Virtio Device/Device Configuration Space" section of the spec:

"If an optional configuration field does not exist, the corresponding space is still present, but reserved."

This became interesting after re-reading some of the qemu codes.

E.g in virtio-net.c we had:

*static VirtIOFeature feature_sizes[] = {
    {.flags = 1ULL << VIRTIO_NET_F_MAC,
     .end = endof(struct virtio_net_config, mac)},
    {.flags = 1ULL << VIRTIO_NET_F_STATUS,
     .end = endof(struct virtio_net_config, status)},
    {.flags = 1ULL << VIRTIO_NET_F_MQ,
     .end = endof(struct virtio_net_config, max_virtqueue_pairs)}, {.flags = 1ULL << VIRTIO_NET_F_MTU,
     .end = endof(struct virtio_net_config, mtu)},
    {.flags = 1ULL << VIRTIO_NET_F_SPEED_DUPLEX,
     .end = endof(struct virtio_net_config, duplex)},
    {.flags = (1ULL << VIRTIO_NET_F_RSS) | (1ULL << VIRTIO_NET_F_HASH_REPORT), .end = endof(struct virtio_net_config, supported_hash_types)}, {}
};*

*It has a implict dependency chain. E.g MTU doesn't presnet if DUPLEX/RSS is not offered ... *

Quoted 5 lines

(Do we need to specify what a device needs to do if the driver tries to access a non-existing field? We cannot really make assumptions about config space accesses; virtio-ccw can just copy a chunk of config space that contains non-existing fields...

Right, it looks to me ccw doesn't depends on config len which is kind of interesting. I think the answer depends on the implementation of both transport and device:

Let's take virtio-net-pci as an example, it fills status unconditionally in virtio_net_set_config() even if VIRTIO_NET_F_STATUS is not negotiated. So with the above feature_sizes:

1) if one of the MQ, MTU, DUPLEX or RSS is implemented, driver can still read status in this case
2) if none of the above four is negotied, driver can only read a 0xFF (virtio_config_readb())

Quoted 2 lines

I guess the device could ignore
writes and return zeroes on read?)

So consider the above, it might be too late to fix/clarify that in the spec on the expected behaviour of reading/writing non-exist fields.

Thanks

Quoted 4 lines

I've opened https://github.com/oasis-tcs/virtio-spec/issues/98 for the spec issues.

#86 lore raw
Quoted 63 lines · On Wed, 3 Mar 2021 12:01:01 +0800 Jason Wang <[email protected]> wrote:
Quoted 31 lines · Cornelia Huck
Quoted 28 lines · On Mon, 1 Mar 2021 11:51:08 +0800 Jason Wang <[email protected]> wrote:
Quoted 26 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Quoted 2 lines · Michael S. Tsirkin

Confused. What is wrong with the above? It never reads the field unless the feature has been offered by device.

So the spec said:

"

The following driver-read-only field, max_virtqueue_pairs only exists if VIRTIO_NET_F_MQ is set.

Quoted 7 lines

"

If I read this correctly, there will be no max_virtqueue_pairs field if the VIRTIO_NET_F_MQ is not offered by device? If yes the offsetof() violates what spec said.

Thanks

I think that's a misunderstanding. This text was never intended to imply that field offsets change beased on feature bits. We had this pain with legacy and we never wanted to go back there.

This merely implies that without VIRTIO_NET_F_MQ the field should not be accessed. Exists in the sense "is accessible to driver".

Let's just clarify that in the spec, job done.

Quoted 8 lines
Quoted 1 line

Ok, agree. That will make things more eaiser.

Yes, that makes much more sense.

What about adding the following to the "Basic Facilities of a Virtio Device/Device Configuration Space" section of the spec:

"If an optional configuration field does not exist, the corresponding space is still present, but reserved."

This became interesting after re-reading some of the qemu codes.

E.g in virtio-net.c we had:

*static VirtIOFeature feature_sizes[] = {
    {.flags = 1ULL << VIRTIO_NET_F_MAC,
     .end = endof(struct virtio_net_config, mac)}, {.flags = 1ULL << VIRTIO_NET_F_STATUS,
     .end = endof(struct virtio_net_config, status)}, {.flags = 1ULL << VIRTIO_NET_F_MQ,
     .end = endof(struct virtio_net_config, max_virtqueue_pairs)}, {.flags = 1ULL << VIRTIO_NET_F_MTU,
     .end = endof(struct virtio_net_config, mtu)}, {.flags = 1ULL << VIRTIO_NET_F_SPEED_DUPLEX,
     .end = endof(struct virtio_net_config, duplex)}, {.flags = (1ULL << VIRTIO_NET_F_RSS) | (1ULL <<
VIRTIO_NET_F_HASH_REPORT),
     .end = endof(struct virtio_net_config, supported_hash_types)}, {}
};*

Quoted 3 lines

*It has a implict dependency chain. E.g MTU doesn't presnet if DUPLEX/RSS is not offered ...
*

But I think it covers everything up to the relevant field, no? So MTU is included if we have the feature bit, even if we don't have DUPLEX/RSS.

Given that a config space may be shorter (but must not collapse non-existing fields), maybe a better wording would be:

"If an optional configuration field does not exist, the corresponding space will still be present if it is not at the end of the configuration space (i.e., further configuration fields exist.) This implies that a given field, if it exists, is always at the same offset from the beginning of the configuration space."

Quoted 10 lines
Quoted 5 lines

(Do we need to specify what a device needs to do if the driver tries to access a non-existing field? We cannot really make assumptions about config space accesses; virtio-ccw can just copy a chunk of config space that contains non-existing fields...

Right, it looks to me ccw doesn't depends on config len which is kind of interesting. I think the answer depends on the implementation of both transport and device:

(virtio-ccw is a bit odd, because channel I/O does not have the concept of a config space and I needed to come up with something)

Quoted 11 lines

Let's take virtio-net-pci as an example, it fills status unconditionally in virtio_net_set_config() even if VIRTIO_NET_F_STATUS is not negotiated. So with the above feature_sizes:

1) if one of the MQ, MTU, DUPLEX or RSS is implemented, driver can still read status in this case
2) if none of the above four is negotied, driver can only read a 0xFF (virtio_config_readb())

Quoted 6 lines
Quoted 2 lines

I guess the device could ignore
writes and return zeroes on read?)

So consider the above, it might be too late to fix/clarify that in the spec on the expected behaviour of reading/writing non-exist fields.

We could still advise behaviour via SHOULD, though I'm not sure it adds much at this point in time.

It really feels a bit odd that a driver can still read and write fields for features that it did not negotiate, but I fear we're stuck with it.

Quoted 8 lines

Thanks

Quoted 4 lines

I've opened https://github.com/oasis-tcs/virtio-spec/issues/98 for the spec issues.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#87 lore raw
Quoted 71 lines · Cornelia Huck
Quoted 61 lines · On Wed, 3 Mar 2021 12:01:01 +0800 Jason Wang <[email protected]> wrote:
Quoted 30 lines · Cornelia Huck
Quoted 27 lines · On Mon, 1 Mar 2021 11:51:08 +0800 Jason Wang <[email protected]> wrote:
Quoted 26 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Quoted 2 lines · Michael S. Tsirkin

Confused. What is wrong with the above? It never reads the field unless the feature has been offered by device.

So the spec said:

"

The following driver-read-only field, max_virtqueue_pairs only exists if VIRTIO_NET_F_MQ is set.

Quoted 7 lines

"

If I read this correctly, there will be no max_virtqueue_pairs field if the VIRTIO_NET_F_MQ is not offered by device? If yes the offsetof() violates what spec said.

Thanks

I think that's a misunderstanding. This text was never intended to imply that field offsets change beased on feature bits. We had this pain with legacy and we never wanted to go back there.

This merely implies that without VIRTIO_NET_F_MQ the field should not be accessed. Exists in the sense "is accessible to driver".

Let's just clarify that in the spec, job done.

Quoted 8 lines
Quoted 1 line

Ok, agree. That will make things more eaiser.

Yes, that makes much more sense.

What about adding the following to the "Basic Facilities of a Virtio Device/Device Configuration Space" section of the spec:

"If an optional configuration field does not exist, the corresponding space is still present, but reserved."

This became interesting after re-reading some of the qemu codes.

E.g in virtio-net.c we had:

*static VirtIOFeature feature_sizes[] = {
    {.flags = 1ULL << VIRTIO_NET_F_MAC,
     .end = endof(struct virtio_net_config, mac)}, {.flags = 1ULL << VIRTIO_NET_F_STATUS,
     .end = endof(struct virtio_net_config, status)}, {.flags = 1ULL << VIRTIO_NET_F_MQ,
     .end = endof(struct virtio_net_config, max_virtqueue_pairs)}, {.flags = 1ULL << VIRTIO_NET_F_MTU,
     .end = endof(struct virtio_net_config, mtu)}, {.flags = 1ULL << VIRTIO_NET_F_SPEED_DUPLEX,
     .end = endof(struct virtio_net_config, duplex)}, {.flags = (1ULL << VIRTIO_NET_F_RSS) | (1ULL <<
VIRTIO_NET_F_HASH_REPORT),
     .end = endof(struct virtio_net_config, supported_hash_types)}, {}
};*

Quoted 3 lines

*It has a implict dependency chain. E.g MTU doesn't presnet if DUPLEX/RSS is not offered ...
*

But I think it covers everything up to the relevant field, no? So MTU is included if we have the feature bit, even if we don't have DUPLEX/RSS.

Quoted 6 lines

Given that a config space may be shorter (but must not collapse non-existing fields), maybe a better wording would be:

"If an optional configuration field does not exist, the corresponding space will still be present if it is not at the end of the configuration space (i.e., further configuration fields exist.)

This should work but I think we need to define the end of configuration space first?

Quoted 10 lines

This
implies that a given field, if it exists, is always at the same offset from the beginning of the configuration space."

Quoted 5 lines
Quoted 4 lines

(Do we need to specify what a device needs to do if the driver tries to access a non-existing field? We cannot really make assumptions about config space accesses; virtio-ccw can just copy a chunk of config space that contains non-existing fields...

Quoted 5 lines
Quoted 3 lines

Right, it looks to me ccw doesn't depends on config len which is kind of interesting. I think the answer depends on the implementation of both transport and device:

(virtio-ccw is a bit odd, because channel I/O does not have the concept of a config space and I needed to come up with something)

Ok.

Quoted 14 lines
Quoted 14 lines

Let's take virtio-net-pci as an example, it fills status unconditionally in virtio_net_set_config() even if VIRTIO_NET_F_STATUS is not negotiated. So with the above feature_sizes:

1) if one of the MQ, MTU, DUPLEX or RSS is implemented, driver can still read status in this case
2) if none of the above four is negotied, driver can only read a 0xFF (virtio_config_readb())

Quoted 2 lines

I guess the device could ignore
writes and return zeroes on read?)

Quoted 7 lines
Quoted 2 lines

So consider the above, it might be too late to fix/clarify that in the spec on the expected behaviour of reading/writing non-exist fields.

We could still advise behaviour via SHOULD, though I'm not sure it adds much at this point in time.

It really feels a bit odd that a driver can still read and write fields for features that it did not negotiate, but I fear we're stuck with it.

Yes, since the device (at least virtio-pci) implment thing like this.

Thanks

Quoted 4 lines
Quoted 4 lines

Thanks

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

I've opened https://github.com/oasis-tcs/virtio-spec/issues/98 for the spec issues.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#88 lore raw
Quoted 75 lines · On Thu, 4 Mar 2021 16:24:16 +0800 Jason Wang <[email protected]> wrote:
Quoted 74 lines · Cornelia Huck
Quoted 61 lines · On Wed, 3 Mar 2021 12:01:01 +0800 Jason Wang <[email protected]> wrote:
Quoted 30 lines · Cornelia Huck
Quoted 27 lines · On Mon, 1 Mar 2021 11:51:08 +0800 Jason Wang <[email protected]> wrote:
Quoted 26 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Quoted 2 lines · Michael S. Tsirkin

Confused. What is wrong with the above? It never reads the field unless the feature has been offered by device.

So the spec said:

"

The following driver-read-only field, max_virtqueue_pairs only exists if VIRTIO_NET_F_MQ is set.

Quoted 7 lines

"

If I read this correctly, there will be no max_virtqueue_pairs field if the VIRTIO_NET_F_MQ is not offered by device? If yes the offsetof() violates what spec said.

Thanks

I think that's a misunderstanding. This text was never intended to imply that field offsets change beased on feature bits. We had this pain with legacy and we never wanted to go back there.

This merely implies that without VIRTIO_NET_F_MQ the field should not be accessed. Exists in the sense "is accessible to driver".

Let's just clarify that in the spec, job done.

Quoted 8 lines
Quoted 1 line

Ok, agree. That will make things more eaiser.

Yes, that makes much more sense.

What about adding the following to the "Basic Facilities of a Virtio Device/Device Configuration Space" section of the spec:

"If an optional configuration field does not exist, the corresponding space is still present, but reserved."

This became interesting after re-reading some of the qemu codes.

E.g in virtio-net.c we had:

*static VirtIOFeature feature_sizes[] = {
    {.flags = 1ULL << VIRTIO_NET_F_MAC,
     .end = endof(struct virtio_net_config, mac)}, {.flags = 1ULL << VIRTIO_NET_F_STATUS,
     .end = endof(struct virtio_net_config, status)}, {.flags = 1ULL << VIRTIO_NET_F_MQ,
     .end = endof(struct virtio_net_config, max_virtqueue_pairs)}, {.flags = 1ULL << VIRTIO_NET_F_MTU,
     .end = endof(struct virtio_net_config, mtu)}, {.flags = 1ULL << VIRTIO_NET_F_SPEED_DUPLEX,
     .end = endof(struct virtio_net_config, duplex)}, {.flags = (1ULL << VIRTIO_NET_F_RSS) | (1ULL <<
VIRTIO_NET_F_HASH_REPORT),
     .end = endof(struct virtio_net_config, supported_hash_types)}, {}
};*

Quoted 3 lines

*It has a implict dependency chain. E.g MTU doesn't presnet if DUPLEX/RSS is not offered ...
*

But I think it covers everything up to the relevant field, no? So MTU is included if we have the feature bit, even if we don't have DUPLEX/RSS.

Given that a config space may be shorter (but must not collapse non-existing fields), maybe a better wording would be:

Quoted 7 lines
Quoted 3 lines

"If an optional configuration field does not exist, the corresponding space will still be present if it is not at the end of the configuration space (i.e., further configuration fields exist.)

This should work but I think we need to define the end of configuration space first?

What about sidestepping this:

"...the corresponding space will still be present, unless no further configuration fields exist."

?

Quoted 4 lines
Quoted 4 lines

This
implies that a given field, if it exists, is always at the same offset from the beginning of the configuration space."

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#89 lore raw
Quoted 81 lines · Cornelia Huck
Quoted 78 lines · On Thu, 4 Mar 2021 16:24:16 +0800 Jason Wang <[email protected]> wrote:
Quoted 76 lines · Cornelia Huck
Quoted 60 lines · On Wed, 3 Mar 2021 12:01:01 +0800 Jason Wang <[email protected]> wrote:
Quoted 30 lines · Cornelia Huck
Quoted 27 lines · On Mon, 1 Mar 2021 11:51:08 +0800 Jason Wang <[email protected]> wrote:
Quoted 26 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Quoted 2 lines · Michael S. Tsirkin

Confused. What is wrong with the above? It never reads the field unless the feature has been offered by device.

So the spec said:

"

The following driver-read-only field, max_virtqueue_pairs only exists if VIRTIO_NET_F_MQ is set.

Quoted 7 lines

"

If I read this correctly, there will be no max_virtqueue_pairs field if the VIRTIO_NET_F_MQ is not offered by device? If yes the offsetof() violates what spec said.

Thanks

I think that's a misunderstanding. This text was never intended to imply that field offsets change beased on feature bits. We had this pain with legacy and we never wanted to go back there.

This merely implies that without VIRTIO_NET_F_MQ the field should not be accessed. Exists in the sense "is accessible to driver".

Let's just clarify that in the spec, job done.

Quoted 8 lines
Quoted 1 line

Ok, agree. That will make things more eaiser.

Yes, that makes much more sense.

What about adding the following to the "Basic Facilities of a Virtio Device/Device Configuration Space" section of the spec:

"If an optional configuration field does not exist, the corresponding space is still present, but reserved."

This became interesting after re-reading some of the qemu codes.

E.g in virtio-net.c we had:

*static VirtIOFeature feature_sizes[] = {
    {.flags = 1ULL << VIRTIO_NET_F_MAC,
     .end = endof(struct virtio_net_config, mac)}, {.flags = 1ULL << VIRTIO_NET_F_STATUS,
     .end = endof(struct virtio_net_config, status)}, {.flags = 1ULL << VIRTIO_NET_F_MQ,
     .end = endof(struct virtio_net_config, max_virtqueue_pairs)}, {.flags = 1ULL << VIRTIO_NET_F_MTU,
     .end = endof(struct virtio_net_config, mtu)}, {.flags = 1ULL << VIRTIO_NET_F_SPEED_DUPLEX,
     .end = endof(struct virtio_net_config, duplex)}, {.flags = (1ULL << VIRTIO_NET_F_RSS) | (1ULL <<
VIRTIO_NET_F_HASH_REPORT),
     .end = endof(struct virtio_net_config, supported_hash_types)}, {}
};*

Quoted 3 lines

*It has a implict dependency chain. E.g MTU doesn't presnet if DUPLEX/RSS is not offered ...
*

But I think it covers everything up to the relevant field, no? So MTU is included if we have the feature bit, even if we don't have DUPLEX/RSS.

Given that a config space may be shorter (but must not collapse non-existing fields), maybe a better wording would be:

"If an optional configuration field does not exist, the corresponding space will still be present if it is not at the end of the configuration space (i.e., further configuration fields exist.)

Quoted 8 lines
Quoted 2 lines

This should work but I think we need to define the end of configuration space first?

What about sidestepping this:

"...the corresponding space will still be present, unless no further configuration fields exist."

?

It might work. (I wonder maybe we can give some example in the spec).

Thanks

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

This
implies that a given field, if it exists, is always at the same offset from the beginning of the configuration space."

#90 lore raw
In reply to Si-Wei Liu
Quoted 16 lines · Si-Wei Liu

Commit 452639a64ad8 ("vdpa: make sure set_features is invoked for legacy") made an exception for legacy guests to reset features to 0, when config space is accessed before features are set. We should relieve the verify_min_features() check and allow features reset to 0 for this case.

It's worth noting that not just legacy guests could access config space before features are set. For instance, when feature VIRTIO_NET_F_MTU is advertised some modern driver will try to access and validate the MTU present in the config space before virtio features are set. Rejecting reset to 0 prematurely causes correct MTU and link status unable to load for the very first config space access, rendering issues like guest showing inaccurate MTU value, or failure to reject out-of-range MTU.

Quoted 1 line
Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")

isn't this more

vdpa: make sure set_features is invoked for legacy

Quoted 1 line

I think we at least need to correct the comment in include/linux/vdpa.h then

Instead of "we assume a legacy guest" we'd say something like "call set features in case it's a legacy guest".

Generally it's unfortunate. Need to think about what to do here. Any idea how else we can cleanly detect a legacy guest?

Quoted 13 lines
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -1
index 7c1f789..540dd67 100644
@@ -1490,14 +1490,6 @@ static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev)
 	return mvdev->mlx_features;
 }
 
-static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 features)

drivers/vdpa/mlx5/net/mlx5_vnet.c static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev) · line 1495

Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -7
-{
-	if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-
 static int setup_virtqueues(struct mlx5_vdpa_net *ndev)
 {
 	int err;

Let's just set VIRTIO_F_ACCESS_PLATFORM in core?
Then we don't need to hack mlx5 ...

Quoted 22 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -6
@@ -1558,18 +1550,13 @@ static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
 {
 	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
 	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-	int err;
 
 	print_features(mvdev, features, true);
 
-	err = verify_min_features(mvdev, features);
-	if (err)
-		return err;
-
 	ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
 	ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
 	ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-	return err;
+	return 0;
 }
 
 static void mlx5_vdpa_set_config_cb(struct vdpa_device *vdev, struct vdpa_callback *cb)
Signature · 1 line
1.8.3.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization